Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.meteora.ag/llms.txt

Use this file to discover all available pages before exploring further.

Enable the cpi feature to call Alpha Vault from another Anchor program:
[dependencies]
alpha-vault = { path = "../alpha-vault/programs/alpha-vault", features = ["cpi"] }

CPI Pattern

Anchor generates a CPI module for the program instructions. Account structs use the same names as the instruction contexts in the Alpha Vault source.
use alpha_vault::cpi;
use alpha_vault::cpi::accounts::DepositCtx;
use alpha_vault::program::AlphaVault;
use anchor_lang::prelude::*;

pub fn deposit_into_alpha_vault<'info>(
    ctx: Context<'_, '_, '_, 'info, YourDepositCtx<'info>>,
    max_amount: u64,
) -> Result<()> {
    let cpi_program = ctx.accounts.alpha_vault_program.to_account_info();
    let cpi_accounts = DepositCtx {
        vault: ctx.accounts.vault.to_account_info(),
        pool: ctx.accounts.pool.to_account_info(),
        escrow: ctx.accounts.escrow.to_account_info(),
        source_token: ctx.accounts.source_token.to_account_info(),
        token_vault: ctx.accounts.token_vault.to_account_info(),
        token_mint: ctx.accounts.token_mint.to_account_info(),
        token_program: ctx.accounts.token_program.to_account_info(),
        owner: ctx.accounts.owner.to_account_info(),
    };

    cpi::deposit(CpiContext::new(cpi_program, cpi_accounts), max_amount)
}
Instructions marked with #[event_cpi] require the event-CPI accounts generated by Anchor. If you construct CPI calls manually, include the generated event authority and program accounts expected by the IDL.

Common CPI Calls

CPI callAccount contextParametersNotes
cpi::create_new_escrowCreateNewEscrowCtxNonePermissionless only. Runs during the deposit window.
cpi::create_permissioned_escrowCreatePermissionedEscrowWithMerkleProofCtxmax_cap, proofVerifies wallet cap proof against MerkleRootConfig.
cpi::create_permissioned_escrow_with_authorityCreatePermissionedEscrowWithAuthorityCtxmax_capPayer must equal vault_authority.
cpi::depositDepositCtxmax_amountOwner signer transfers quote into the vault token account.
cpi::withdrawWithdrawCtxamountPro Rata only. Can withdraw deposits or overflow depending on current time point.
cpi::withdraw_remaining_quoteWithdrawRemainingQuoteCtxNoneRuns after the buying window and marks the escrow refunded.
cpi::claim_tokenClaimTokenCtxNoneRuns after start_vesting_point.
cpi::close_escrowCloseEscrowCtxNoneRequires the escrow to be closable.
cpi::fill_dlmmFillDlmmCtxmax_amount, remaining_accounts_infoRequires DLMM bin array and transfer-hook remaining accounts when applicable.
cpi::fill_dynamic_ammFillDynamicAmmCtxmax_amountCalls Dynamic AMM / DAMM v1.
cpi::fill_damm_v2FillDammV2Ctxmax_amountCalls DAMM v2.

Account Requirements

FlowRequired signerImportant accounts
Escrow creation, permissionlesspayervault, pool, escrow PDA, owner, optional treasury fee receiver.
Escrow creation, Merkle proofpayervault, pool, escrow PDA, owner, merkle_root_config, optional treasury fee receiver.
Escrow creation, authoritypayer equal to vault_authorityvault, pool, escrow PDA, owner.
User depositownerOwner quote token source, vault quote token ATA, quote mint, token program.
User withdraw or refundownerUser quote destination, vault quote token ATA, quote mint, token program.
User claimownerUser base destination, vault base token ATA, base mint, token program.
FillcrankerVault quote and base token accounts, connected pool-specific accounts, optional crank whitelist, optional treasury fee receiver.

Remaining Accounts

SituationRemaining accounts
Destination account requires Token 2022 memo transferPass the memo program first for withdraw, withdraw_remaining_quote, or claim_token.
DLMM fill with Token 2022 transfer hooksPass the transfer-hook accounts described by RemainingAccountsInfo, followed by writable bin array accounts.
Dynamic AMM fillNo Alpha Vault-specific remaining accounts are read by the handler.
DAMM v2 fillNo Alpha Vault-specific remaining accounts are read by the handler.

Common CPI Failures

Error areaCPI-side fix
Pool type mismatchCall the fill instruction matching vault.pool_type.
Time window mismatchRead the connected pool timing and vault timing before sending CPI.
Missing treasuryPass the treasury as crank_fee_receiver or escrow_fee_receiver when no valid whitelist removes the fee path.
Permission mode mismatchUse the escrow creation instruction that matches vault.whitelist_mode.
Token 2022 transfer feePass max amounts in raw token units and expect credited amounts to be transfer-fee excluded.

Best Practices

CheckDetail
Prefer generated bindingsUse the local Anchor crate with the cpi feature or generated IDL bindings. Avoid hand-typing account order from memory.
Compare with the SDKBuild the same flow with @meteora-ag/alpha-vault and compare account metas, signers, writable flags, and optional accounts.
Read vault state firstLoad Vault before deciding the flow. Validate vault_mode, whitelist_mode, pool_type, token vaults, mints, and authority from account state.
Respect pool timingRead the connected pool timing before deposits, fills, refunds, and claims. Alpha Vault actions are gated by both vault points and pool pre-activation points.
Keep pool type explicitRoute fills by vault.pool_type: DLMM, Dynamic AMM / DAMM v1, or DAMM v2. Each path has a different account set.
Treat Merkle caps as stateFor Merkle-proof vaults, verify the proof off-chain before sending CPI and use the same max_cap passed to the program.
Plan fee accountsPermissionless escrow creation and non-whitelisted fills can require the Alpha Vault treasury. Permissioned vaults must not charge escrow fees.
Handle once-only actionswithdraw_remaining_quote marks the escrow refunded. Escrow close also depends on claims, refunds, and overflow withdrawals being complete.
Simulate Token 2022 pathsTransfer-fee mints change credited amounts, and memo-required destination accounts need the memo program in remaining accounts. DLMM transfer hooks need matching remaining-account slices.
Test every mode you supportPro Rata and FCFS differ in deposits, withdrawals, caps, overflow behavior, and swappable amounts. Permissionless, Merkle, and authority access also differ.

Testing

Use the local Alpha Vault test suite as a reference for account metas and edge cases:
cd alpha-vault
anchor build
anchor test
Add CPI caller tests that cover at least one successful path and one expected failure path for each vault mode, whitelist mode, and pool type your integration supports.