> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# ERC4626 on Solana: Tokenized Vaults

> Build an ERC4626-style vault on Solana with a program, a PDA-owned token account, and a share mint. Covers the function map, share math, and pitfalls.

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](/developers/docs/core/pda):

```mermaid
flowchart TD
    P["Vault program<br/>Deposit and redeem logic, no state"]
    P -->|controls| P0["Vault state<br/>Share mint address, total assets, bump"]
    P -->|controls| P1["Vault token account<br/>Holds the underlying asset"]
    P -->|controls| P2["Share mint<br/>Mint authority is the vault's PDA"]
```

<div className="sol-mermaid" data-fallback="mermaid" data-mermaid="d1dd6b39541c">
  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/d1dd6b39541c-light.svg" alt="One vault program can serve many vaults. Each vault is a set of accounts." />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/d1dd6b39541c.svg" alt="One vault program can serve many vaults. Each vault is a set of accounts." />

  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/d1dd6b39541c-sm-light.svg" alt="One vault program can serve many vaults. Each vault is a set of accounts." />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/d1dd6b39541c-sm.svg" alt="One vault program can serve many vaults. Each vault is a set of accounts." />
</div>

<p className="sol-caption">One vault program can serve many vaults. Each vault is a set of accounts.</p>

| 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.

| ERC4626 | Solana | How it maps |
| --- | --- | --- |
| `asset()` | The underlying mint address | Read it from the vault token account or the vault state. |
| `totalAssets()` | 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. |
| `totalSupply()` | Share mint supply | Read `supply` from the share mint. |
| `deposit()`, `mint()` | A deposit instruction | Transfer assets into the vault and mint shares to the depositor. An exact-shares `mint` variant rounds the assets up. |
| `withdraw()`, `redeem()` | 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. |
| `convertTo*`, `preview*` | Client-side math or simulation | Compute from the two balances, or simulate the transaction to see exact balance changes before signing. |
| Share token transfers | Token Program transfers | Shares are a regular token. Wallets and other programs handle them like any mint. |
| Redeeming for another owner | 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.

<Steps>
<Step title="User calls deposit">

The transaction lists the user's token accounts, the vault token account, the
share mint, and the vault state.

</Step>
<Step title="Compute shares">

The program reads the share supply and the tracked total assets, then calculates
the shares to mint.

</Step>
<Step title="Transfer assets in">

A CPI moves the assets from the user to the vault. The user's signature
authorizes it.

</Step>
<Step title="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.

</Step>
</Steps>

```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`.

<Steps>
<Step title="User calls redeem">

The transaction lists the same accounts as a deposit.

</Step>
<Step title="Compute assets">

The program calculates the assets owed for the shares.

</Step>
<Step title="Burn shares">

A CPI burns the shares from the user's share account.

</Step>
<Step title="Transfer assets out">

A CPI moves the assets to the user. The PDA signs for the vault token account.

</Step>
</Steps>

## Design differences

<Columns cols={2}>
<Card title="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.

</Card>
<Card title="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.

</Card>
</Columns>

## 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

<Columns cols={3}>
<Card title="ERC20 on Solana" href="/developers/docs/migrate-to-solana/ethereum/standards/erc20">

Review mints, token accounts, and delegates.

</Card>
<Card title="Token CPIs" href="/developers/docs/tokens/advanced/cpi" arrow>

Transfer, mint, and burn from your own program.

</Card>
<Card title="Security checklist" href="/developers/docs/migrate-to-solana/ethereum/complete-guide#security">

Check account and CPI validation before you deploy.

</Card>
</Columns>
