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.

DAMM v1 can be invoked from Anchor programs through the dynamic-amm program crate included in damm-v1-sdk/programs/dynamic-amm. CPI builders must pass the same pool, Dynamic Vault, token, mint, and remaining accounts required by the on-chain instruction.
Prefer the TypeScript SDK or Rust off-chain helpers for ordinary app transactions. Use CPI only when another on-chain program must compose directly with DAMM v1.

Dependency Setup

The local program crate exposes CPI types through its default cpi feature.
[dependencies]
dynamic-amm = { path = "../damm-v1-sdk/programs/dynamic-amm", features = ["cpi"] }
dynamic-vault = { path = "../damm-v1-sdk/programs/dynamic-vault", features = ["cpi"] }
anchor-lang = "0.28.0"
anchor-spl = "0.28.0"
For a published or vendored integration, pin the exact source revision that matches the deployed DAMM v1 IDL you build against.

Source Examples

Public CPI Examples

Meteora’s public CPI examples include DAMM v1 swap, pool initialization, config-based initialization, lock liquidity, claim fee, and tests.
The local damm-v1-sdk/common crate also contains account builders that are useful when preparing CPI or off-chain instruction account sets.

Account Planning

Every DAMM v1 CPI has two account layers:
LayerAccounts
DAMM v1 pool layerpool, pool LP mint, pool-held Dynamic Vault LP token accounts, protocol fee accounts, lock escrow accounts when needed.
Dynamic Vault layera_vault, b_vault, each vault token account, each vault LP mint, Dynamic Vault program.
Use common::dynamic_amm::pda and common::dynamic_vault::pda helpers to derive canonical addresses.

Swap CPI

swap takes in_amount and minimum_out_amount.
AccountRequirement
poolDAMM v1 pool. Must be enabled and active.
user_source_tokenUser source token account. Mint must match token A or token B.
user_destination_tokenUser destination token account. Mint must be the opposite pool token.
a_vault, b_vaultDynamic Vault accounts stored in pool state.
a_token_vault, b_token_vaultToken vault accounts stored in each Dynamic Vault.
a_vault_lp_mint, b_vault_lp_mintDynamic Vault LP mints.
a_vault_lp, b_vault_lpPool-held Dynamic Vault LP token accounts.
protocol_token_feeProtocol fee token account for the input mint.
userSigner and owner of user_source_token.
vault_program, token_programDynamic Vault and SPL Token programs.
Remaining accountsDepeg accounts for LST pools, then optional host fee account for referral routing.
Quote off-chain immediately before invoking CPI. Use the quoted minimum output as minimum_out_amount.

Liquidity CPI

InstructionUseImportant constraints
add_balance_liquidityBalanced deposit.Constant-product pools use balanced liquidity after bootstrap.
add_imbalance_liquidityStable imbalanced deposit.Stable pools only.
remove_balance_liquidityBalanced withdrawal.Allowed even when the pool is disabled.
remove_liquidity_single_sideStable single-sided withdrawal.Stable pools only.
bootstrap_liquidityRe-seed depleted pool.Pool must satisfy depleted-pool checks.
Liquidity instructions need pool LP mint, user token accounts, user pool LP account, both Dynamic Vault accounts, vault token accounts, vault LP mints, and pool-held vault LP token accounts.

Lock CPI

InstructionUseNotes
create_lock_escrowInitialize a lock escrow PDA.PDA seeds are lock_escrow, pool, owner.
lockTransfer LP into the escrow vault.owner can be any signer funding the lock amount.
claim_feeClaim token A/B fees accrued by locked LP.Requires the lock escrow, escrow vault, user LP/token accounts, pool/vault accounts, and vault program.
Lock fee accounting depends on current pool virtual price. Pass fresh vault and LP account data so the instruction can compute the correct fee.

Pool Creation CPI

Pool creation CPI is possible but account-heavy because it initializes the pool, LP mint, pool-held vault LP accounts, protocol fee accounts, payer LP ATA, and LP metadata.
InstructionNotes
initialize_permissionless_poolUses curve default fee and PDA from curve type plus sorted mints.
initialize_permissionless_pool_with_fee_tierAdds the fee-tier seed when the fee differs from the default.
initialize_permissionless_constant_product_pool_with_configUses config PDA, sorted mints, and config-controlled activation.
initialize_customizable_permissionless_constant_product_poolUses CustomizableParams and the pool seed with sorted mints.
For most CPI use cases, initialize pools off-chain first and CPI only into swap, liquidity, or lock flows.

Unsupported Or Restricted CPI Paths

AreaConstraint
Operator zapSource includes explicit CpiDisabled and strict transaction sysvar validation for zap-related protocol fee flows. Treat zap protocol fee as an operator off-chain transaction path.
Admin config and operator creationAdmin signer restrictions apply. These are not ordinary CPI integration flows.
Activation updatesLaunch-pool activation changes are restricted by activation timing windows.
Depeg poolsCPI callers must include the same depeg remaining accounts required by direct transactions.

Common CPI Errors

ErrorLikely cause
InvalidVaultAccountDynamic Vault account or vault token account does not match pool state.
InvalidVaultLpAccountPool-held vault LP token account is wrong.
MismatchedTokenMintUser source/destination, protocol fee, or vault token mint is wrong.
InvalidProtocolFeeAccountProtocol fee token account does not match the input mint’s fee PDA.
PoolDisabledSwap or restricted liquidity operation attempted while pool is disabled.
InvalidActivationPoint / PreActivationSwapStartedLaunch-pool timing constraints are not satisfied.
InvalidRemainingAccountsLen / InvalidRemainingAccountsDepeg, referral, or zap remaining accounts are missing or ordered incorrectly.
ExceededSlippageCPI supplied minimum output or liquidity threshold is too strict for current state.

Checklist

StepAction
1Derive the pool, LP mint, protocol fee account, vault LP accounts, and lock escrow with helper functions.
2Fetch current pool and Dynamic Vault state off-chain for quoting and account validation.
3Include required depeg remaining accounts for LST stable pools.
4Simulate the outer transaction with realistic compute budget and fresh blockhash.
5Reconcile Anchor logs and token transfers after execution.