EVM -> Solana

ERC4626 on Solana: Tokenized Vaults

ERC4626 standardizes vaults: deposit an asset, receive shares, and redeem shares for a proportional amount of the asset. Solana has no vault standard. You build the same model from a program, a token account the program controls, and a share mint. This guide shows the pieces and the math.

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:

Vault program
Deposit and redeem logic, no state
controls through a PDA
Vault state
Share mint address, total assets, bump
Vault token account
Holds the underlying asset
Share mint
Mint authority is the vault's PDA
One vault program can serve many vaults. Each vault is a set of accounts.
PieceAccountPurpose
Underlying assetAn existing mintThe token the vault accepts, such as USDC
SharesA new mint with the PDA as mint authorityTracks proportional ownership of the vault
CustodyA token account owned by the PDAHolds the deposited assets
Vault stateA small data accountStores the share mint, the total assets, the PDA bump, and settings
AuthorityA PDA derived from the vault state addressSigns 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.

ERC4626
asset()
Solana
The underlying mint address
Read it from the vault token account or the vault state.
ERC4626
totalAssets()
Solana
Vault state field
Read the total that the program tracks in vault state. The live token balance can be changed by anyone who sends tokens to the vault.
ERC4626
totalSupply()
Solana
Share mint supply
Read supply from the share mint.
ERC4626
deposit(), mint()
Solana
A deposit instruction
Transfer assets into the vault and mint shares to the depositor. An exact-shares mint variant rounds the assets up.
ERC4626
withdraw(), redeem()
Solana
A redeem instruction
Burn the holder's shares and transfer assets out, signed by the PDA. An exact-assets withdraw variant rounds the shares up.
ERC4626
convertTo*, preview*
Solana
Client-side math or simulation
Compute from the two balances, or simulate the transaction to see exact balance changes before signing.
ERC4626
Share token transfers
Solana
Token Program transfers
Shares are a regular token. Wallets and other programs handle them like any mint.
ERC4626
Redeeming for another owner
Solana
A delegate on the share account
The share holder approves a delegate, which then signs the redeem.

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.

01
User calls deposit
The transaction lists the user's token accounts, the vault token account, the share mint, and the vault state.
02
Compute shares
The program reads the share supply and the tracked total assets, then calculates the shares to mint.
03
Transfer assets in
A CPI moves the assets from the user to the vault. The user's signature authorizes it.
04
Mint shares
A CPI mints shares to the user. The PDA signs as mint authority, and the program adds the deposit to the tracked total.
A deposit into the vault.
Rust
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.

01
User calls redeem
The transaction lists the same accounts as a deposit.
02
Compute assets
The program calculates the assets owed for the shares.
03
Burn shares
A CPI burns the shares from the user's share account.
04
Transfer assets out
A CPI moves the assets to the user. The PDA signs for the vault token account.
A redemption from the vault.

Design differences

ERC4626 vault
One contract is the vault and the share token.
Many vaults add a nonReentrant guard to deposit and redeem.
View functions on the contract return previews.
Each vault is a new contract deployment.
Solana vault
The share token is a separate mint that the vault's PDA controls.
The runtime blocks reentrancy from the Token Program back into your program.
Every account is listed up front, so wallets simulate the transaction and show the balance changes.
One program can create any number of vaults as new accounts.

Pitfalls to check

Vault bugs are usually math or account-validation bugs. Check each item before you deploy.

Compute shares before you transfer tokens. Account data you loaded earlier does not update after a CPI unless you reload it.
Round in the vault's favor: round shares down on deposit and assets down on redeem. Exact-output variants round the other way, with shares up on withdraw and assets up on mint.
Track total assets in vault state, as the example does. A vault that reads its live token balance lets an attacker donate tokens to an empty vault and inflate the share price.
Do the math in u128 with checked operations, return an error on overflow or division by zero, and reject deposits that would mint zero shares.
Validate that the vault token account, the share mint, and the PDA seeds match the vault state. Callers choose the accounts they pass in.
Derive the vault's authority PDA from the vault state address. A single PDA shared by every vault would hold authority over all of them.
If the underlying mint uses Token Extensions with transfer fees, the vault receives less than the amount sent. Reload the vault token account after the transfer and credit the difference.

Next steps

ERC4626 on Solana: Tokenized Vaults | Solana