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.

This page is based on @meteora-ag/zap-sdk. Use it as the high-level map, then open the package types when you need exact parameter shapes.
import {
  Zap,
  ZAP_PROGRAM_ID,
  estimateDlmmDirectSwap,
  estimateDlmmIndirectSwap,
  estimateDlmmRebalanceSwap,
  getJupiterQuote,
  getJupiterSwapInstruction,
  deriveLedgerAccount,
} from "@meteora-ag/zap-sdk";

Dependencies

PackageUse
@coral-xyz/anchorProgram client, IDL types, and BN.
@solana/web3.jsConnections, public keys, transactions, and account metas.
@solana/spl-tokenToken accounts, ATAs, Token 2022, and wrapped SOL helpers.
@meteora-ag/cp-amm-sdkDAMM v2 state, position derivation, token program flags, and swap quote helpers.
@meteora-ag/dlmmDLMM state, strategies, bin arrays, quotes, and rebalance helpers.
bn.jsInteger token amount inputs and SDK return values.
decimal.jsUI amount conversion, route comparison, and estimate calculations.

Program IDs

ConstantValue
ZAP_PROGRAM_IDzapvX9M3uf5pvy4wRPAbQgdQsM1xmuiFnkfHKPvwMiz
DAMM_V2_PROGRAM_IDcpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG
DLMM_PROGRAM_IDLBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo
JUP_V6_PROGRAM_IDJUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4
MEMO_PROGRAM_IDMemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr

Creating A Client

import { Connection } from "@solana/web3.js";
import { Zap } from "@meteora-ag/zap-sdk";

const connection = new Connection(process.env.RPC_URL!, "confirmed");
const zap = new Zap(connection, {
  jupiterApiUrl: "https://api.jup.ag",
  jupiterApiKey: process.env.JUPITER_API_KEY,
});
Constructor optionTypeDefaultUse
jupiterApiUrlstringhttps://api.jup.agJupiter quote and swap-instruction endpoint base URL.
jupiterApiKeystringEmpty stringOptional API key header for Jupiter requests.

Zap Methods

MethodReturnsUse
constructor(connection, config?)ZapCreate a Zap client with an Anchor Program from the bundled IDL.
getZapInDammV2DirectPoolParams(params)ZapInDammV2DirectPoolParamPrepare DAMM v2 zap-in params when the input mint is token A or token B.
getZapInDammV2IndirectPoolParams(params)ZapInDammV2IndirectPoolParamPrepare DAMM v2 zap-in params when the input mint is neither pool token.
buildZapInDammV2Transaction(params)ZapInDammV2ResponseBuild setup, swap, ledger, zap-in, and cleanup transactions for DAMM v2.
getZapInDlmmDirectParams(params)ZapInDlmmDirectPoolParamPrepare DLMM zap-in params when the input mint is token X or token Y.
getZapInDlmmIndirectParams(params)ZapInDlmmIndirectPoolParamPrepare DLMM zap-in params when the input mint is neither pool token.
buildZapInDlmmTransaction(params)ZapInDlmmResponseBuild setup, swap, ledger, zap-in, and cleanup transactions for a new DLMM position.
rebalanceDlmmPosition(params)RebalanceDlmmPositionResponseBuild a DLMM remove-liquidity, optional swap, ledger, zap-in, and cleanup sequence for an existing position.
zapOut(params)TransactionLow-level generic zap-out builder with caller-supplied payload and account metas.
zapOutThroughJupiter(params)TransactionBuild a zap-out transaction using a Jupiter V6 swap-instruction response.
zapOutThroughDammV2(params)TransactionBuild a zap-out transaction through DAMM v2 swap2.
zapOutThroughDlmm(params)TransactionBuild a zap-out transaction through DLMM swap2.

Zap-In Parameter Builders

MethodRequired route inputsImportant controls
getZapInDammV2DirectPoolParamsuser, inputTokenMint, amountIn, pool, positionNftMint, optional DAMM v2 and Jupiter quotesmaxSqrtPriceChangeBps, slippageBps, maxAccounts, maxTransferAmountExtendPercentage
getZapInDammV2IndirectPoolParamsuser, inputTokenMint, amountIn, pool, positionNftMint, optional Jupiter quotes to token A and token BSame DAMM v2 controls plus per-side route estimates
getZapInDlmmDirectParamsuser, lbPair, inputTokenMint, amountIn, directSwapEstimateminDeltaId, maxDeltaId, strategy, favorXInActiveId, maxActiveBinSlippage, singleSided
getZapInDlmmIndirectParamsuser, lbPair, inputTokenMint, amountIn, indirectSwapEstimateSame DLMM controls plus Jupiter route caps

Zap-In Responses

Response typeFields
ZapInDammV2ResponsesetupTransaction?, swapTransactions, ledgerTransaction, zapInTransaction, cleanUpTransaction
ZapInDlmmResponsesetupTransaction?, swapTransactions, ledgerTransaction, zapInTransaction, cleanUpTransaction
RebalanceDlmmPositionResponsesetupTransaction, initBinArrayTransaction?, rebalancePositionTransaction?, swapTransaction?, ledgerTransaction, zapInTransaction, cleanUpTransaction, estimation

Zap-Out Methods

MethodRoute sourceNotes
zapOutCaller-supplied whitelisted payloadLowest-level builder. Use only when you already know the downstream account order and amount offset.
zapOutThroughJupiterJupiter V6 swap-instruction responseBuilds ATAs, calculates reverse amount offset, forwards Jupiter accounts, and unwraps SOL when needed.
zapOutThroughDammV2DAMM v2 pool state and createDammV2SwapPayloadBuilds DAMM v2 remaining accounts and uses amount offset 8.
zapOutThroughDlmmDLMM pair state and createDlmmSwapPayloadBuilds DLMM remaining accounts, including transfer-hook slices when required, and uses amount offset 8.

Estimator Functions

FunctionUse
estimateDlmmDirectSwap(params)Estimate whether and how much to swap when the input mint is token X or token Y. Compares DLMM and Jupiter routes.
estimateDlmmIndirectSwap(params)Estimate split amounts to swap an unrelated input token into token X and/or token Y through Jupiter.
estimateDlmmRebalanceSwap(params)Estimate the swap needed after removing liquidity from an existing DLMM position before zapping back in.

Jupiter Helpers

FunctionUse
getJupiterQuote(inputMint, outputMint, amount, maxAccounts, slippageBps, dynamicSlippage, onlyDirectRoutes, restrictIntermediateTokens, config?)Fetch a Jupiter quote. Returns null when the request fails or the endpoint rejects it.
getJupiterSwapInstruction(userPublicKey, quoteResponse, config?)Fetch Jupiter swap instructions for a quote. Throws when the request fails.
buildJupiterSwapTransaction(user, inputMint, outputMint, amount, maxAccounts, slippageBps, quote?, config?)Build a transaction containing the Jupiter swap instruction. Reuses a supplied quote when provided.

DAMM v2 Helpers

FunctionUse
getDammV2Pool(connection, poolAddress)Fetch a DAMM v2 pool state through @meteora-ag/cp-amm-sdk.
getDammV2RemainingAccounts(poolAddress, user, userInputTokenAccount, userTokenOutAccount, tokenAProgram, tokenBProgram, poolState)Build account metas for DAMM v2 swap2 in zap-out flows.
createDammV2SwapPayload(amountIn, minimumSwapAmountOut)Serialize DAMM v2 swap2 payload data for generic zapOut.
isSingleSidedA(poolState) / isSingleSidedB(poolState)Detect DAMM v2 single-sided pool boundary states.

DLMM Helpers

FunctionUse
getLbPairState(connection, lbPair)Fetch a DLMM pair state.
getDlmmRemainingAccounts(connection, lbPair, user, userInputTokenAccount, userTokenOutAccount, tokenXProgram, tokenYProgram, lbPairState)Build DLMM swap remaining accounts and RemainingAccountInfo.
createDlmmSwapPayload(amountIn, minimumSwapAmountOut, remainingAccountsInfo)Serialize DLMM swap2 payload data for generic zapOut.
getBinArrayBitmapExtension(connection, binArray)Decode a bin array bitmap extension account when it exists.
getNextBinArrayIndexWithLiquidity(...)Scan DLMM bitmap state for the next bin array with liquidity.
toProgramStrategyType(strategy)Convert DLMM SDK strategy enum values into Zap IDL enum values.
convertAccountTypeToNumber(accountType)Encode DLMM remaining-account slice account types.

PDA, Token, And Utility Helpers

FunctionUse
deriveLedgerAccount(owner)Derive the Zap user ledger PDA.
deriveDammV2EventAuthority()Derive DAMM v2 event authority.
deriveDammV2PoolAuthority()Derive DAMM v2 pool authority.
deriveDlmmEventAuthority()Derive DLMM event authority.
getOrCreateATAInstruction(connection, tokenMint, owner, payer, allowOwnerOffCurve, tokenProgram)Return an ATA and an idempotent creation instruction.
getTokenProgramFromMint(connection, mint)Detect SPL Token versus Token 2022 from mint ownership, defaulting to SPL Token on lookup failure.
getTokenAccountBalance(connection, tokenAccount)Return a token-account balance string, or "0" when the account lookup fails.
wrapSOLInstruction(from, to, amount, tokenProgram?)Build native SOL wrap instructions.
unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve?)Build a wrapped SOL close-account instruction.
filterOutCloseSplTokenAccountInstructions(instructions)Remove SPL Token CloseAccount instructions from a list.
getExtraAccountMetasForTransferHook(connection, mint)Return Token 2022 transfer-hook extra accounts for a mint.
convertLamportsToUiAmount(amount, decimals) / convertUiAmountToLamports(amount, decimals)Convert between integer and UI decimal amounts.

Constants And Enums

ExportValues or meaning
AMOUNT_IN_DAMM_V2_OFFSET8
AMOUNT_IN_DLMM_OFFSET8
AMOUNT_IN_JUP_V6_REVERSE_OFFSET19
DAMM_V2_SWAP_DISCRIMINATORDAMM v2 swap2 discriminator.
DLMM_SWAP_DISCRIMINATORDLMM swap2 discriminator.
DEFAULT_JUPITER_API_URLhttps://api.jup.ag
ZapInDammV2PoolSwapRouteJupiter, DammV2
SwapExternalTypeswapToA, swapToB, swapToBoth
DlmmDirectSwapQuoteRouteJupiter, Dlmm
DlmmSwapTypeXToY, YToX, NoSwap
DlmmSingleSidedX, Y
AccountsTypeTransfer-hook slice account types used for DLMM remaining accounts.

Core Types

TypeUse
ZapConfigOptional Jupiter API URL and API key.
ZapOutParametersIDL-derived payload fields for zap_out.
ZapOutParamsLow-level generic zap-out builder input.
ZapOutThroughDammV2Params, ZapOutThroughDlmmParams, ZapOutThroughJupiterParamsRoute-specific zap-out builder inputs.
GetZapInDammV2DirectPoolParams, GetZapInDammV2IndirectPoolParamsDAMM v2 zap-in parameter preparation inputs.
GetZapInDlmmDirectParams, GetZapInDlmmIndirectParamsDLMM zap-in parameter preparation inputs.
EstimateDlmmDirectSwapParams, EstimateDlmmIndirectSwapParams, EstimateDlmmRebalanceSwapParamsDLMM estimate inputs.
JupiterQuoteResponse, JupiterSwapInstructionResponseJupiter API response shapes used by helpers.
ZapProgram, ZapTypes, ZapIdlAnchor program type, generated IDL type, and bundled IDL JSON.