Skip to main content

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:

  1. Vault is not pausedpaused() returns false
  2. 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:

EventDescription
Deposit(sender, owner, assets, shares)ERC4626 standard deposit event
Transfer(from=0x0, to=receiver, value=shares)ERC20 share mint event

Error Cases

ErrorCause
EnforcedPauseVault is paused
DepositCapExceededDeposit would exceed the vault's deposit cap
ZeroAmountassets is 0, or rounds to 0 shares
StaleNAVNAV is stale — deposits are blocked until the next update
TokenNotAcceptedToken isn't an accepted asset (depositToken)
ERC20InsufficientAllowanceToken allowance too low
ERC20InsufficientBalanceUser has insufficient tokens