What ERC4626 defines
An ERC4626 vault is an ERC20 contract that holds one underlying token. Depositors receive share tokens, and the ratio of total assets to total shares sets the price of a share. The standard fixes the interface, so aggregators and front ends integrate any vault the same way, whatever strategy runs behind it.
The lifecycle has four entry points: deposit and mint move assets in, and withdraw and redeem move them out. View functions such as convertToShares and previewDeposit let clients compute amounts before they send a transaction.
The accounts behind a Solana vault
An ERC4626 contract is the vault, the custodian, and the share token at once. On Solana, these are separate accounts that one program controls through a PDA:
| Piece | Account | Purpose |
|---|---|---|
| Underlying asset | An existing mint | The token the vault accepts, such as USDC |
| Shares | A new mint with the PDA as mint authority | Tracks proportional ownership of the vault |
| Custody | A token account owned by the PDA | Holds the deposited assets |
| Vault state | A small data account | Stores the share mint, the total assets, the PDA bump, and settings |
| Authority | A PDA derived from the vault state address | Signs transfers out of the vault and share mints |
ERC4626 functions on Solana
State-changing functions become instructions of your program. View functions become account reads on the client.
asset()totalAssets()totalSupply()supply from the share mint.deposit(), mint()mint variant rounds the assets up.withdraw(), redeem()withdraw variant rounds the shares up.convertTo*, preview*Deposit and redeem
A deposit is one instruction that makes two cross-program invocations (CPIs) to the Token Program. The first depositor receives shares one to one. Later depositors receive assets × share supply ÷ total assets. The example computes from the total that the vault tracks in its state, so tokens sent straight to the vault cannot change the share price.
pub fn deposit(ctx: Context<Deposit>, assets: u64) -> Result<()> {
require!(assets > 0, VaultError::ZeroAmount);
// Use the total the vault tracks, not the live token balance, so tokens
// sent straight to the vault cannot change the share price.
let supply = ctx.accounts.share_mint.supply as u128;
let total_assets = ctx.accounts.vault_state.total_assets as u128;
let shares = if supply == 0 {
assets
} else {
// Integer division rounds down, in the vault's favor.
(assets as u128)
.checked_mul(supply)
.and_then(|value| value.checked_div(total_assets))
.and_then(|value| u64::try_from(value).ok())
.ok_or(VaultError::MathOverflow)?
};
require!(shares > 0, VaultError::ZeroShares);
// Move the assets in. The depositor's signature authorizes the transfer.
transfer_checked(
CpiContext::new(
ctx.accounts.token_program.key(),
TransferChecked {
from: ctx.accounts.depositor_token_account.to_account_info(),
mint: ctx.accounts.asset_mint.to_account_info(),
to: ctx.accounts.vault_token_account.to_account_info(),
authority: ctx.accounts.depositor.to_account_info(),
},
),
assets,
ctx.accounts.asset_mint.decimals,
)?;
// Mint shares. This vault's PDA signs as the share mint's authority.
let vault_key = ctx.accounts.vault_state.key();
let signer_seeds: &[&[&[u8]]] = &[&[
b"vault-authority",
vault_key.as_ref(),
&[ctx.accounts.vault_state.authority_bump],
]];
mint_to(
CpiContext::new_with_signer(
ctx.accounts.token_program.key(),
MintTo {
mint: ctx.accounts.share_mint.to_account_info(),
to: ctx.accounts.depositor_share_account.to_account_info(),
authority: ctx.accounts.vault_authority.to_account_info(),
},
signer_seeds,
),
shares,
)?;
let vault_state = &mut ctx.accounts.vault_state;
vault_state.total_assets = vault_state
.total_assets
.checked_add(assets)
.ok_or(VaultError::MathOverflow)?;
Ok(())
}A redeem runs in the opposite direction. The holder receives shares × total assets ÷ share supply.
Design differences
nonReentrant guard to deposit and redeem.Pitfalls to check
Vault bugs are usually math or account-validation bugs. Check each item before you deploy.
u128 with checked operations, return an error on overflow or division by zero, and reject deposits that would mint zero shares.