Deposit Flow
Depositing into an Emerald Vault is a standard ERC4626 deposit: approve the vault to spend your tokens, then call deposit().
Prerequisites
Before depositing, verify:
- Vault is not paused —
paused()returnsfalse - Sufficient token balance — you have enough of the underlying asset
Step-by-Step
1. Approve Token Spending
import { erc20Abi } from "viem";
const allowance = await publicClient.readContract({
address: TOKEN_ADDRESS,
abi: erc20Abi,
functionName: "allowance",
args: [userAddress, VAULT_ADDRESS],
});
if (allowance < amount) {
const hash = await walletClient.writeContract({
address: TOKEN_ADDRESS,
abi: erc20Abi,
functionName: "approve",
args: [VAULT_ADDRESS, amount],
});
await publicClient.waitForTransactionReceipt({ hash });
}
2. Deposit
const hash = await walletClient.writeContract({
address: VAULT_ADDRESS,
abi: vaultAbi,
functionName: "deposit",
args: [amount, userAddress, PARTNER_ID], // (assets, receiver, partnerId)
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
Partner attribution
Pass your numeric partnerId to the deposit(assets, receiver, partnerId)
overload to attribute the deposit to you — it emits a ReferralDeposit event the
indexer records. Use 0 (or the 2-arg deposit(assets, receiver)) for no
attribution. The same pattern applies to depositToken(token, assets, receiver, partnerId)
(secondary accepted tokens, e.g. USDT/cbBTC) and depositETH(receiver, partnerId)
(native ETH → the WETH vault).
Events Emitted
A successful deposit emits two events:
| Event | Description |
|---|---|
Deposit(sender, owner, assets, shares) | ERC4626 standard deposit event |
Transfer(from=0x0, to=receiver, value=shares) | ERC20 share mint event |
Error Cases
| Error | Cause |
|---|---|
EnforcedPause | Vault is paused |
DepositCapExceeded | Deposit would exceed the vault's deposit cap |
ZeroAmount | assets is 0, or rounds to 0 shares |
StaleNAV | NAV is stale — deposits are blocked until the next update |
TokenNotAccepted | Token isn't an accepted asset (depositToken) |
ERC20InsufficientAllowance | Token allowance too low |
ERC20InsufficientBalance | User has insufficient tokens |