Skip to main content
The zap IDL exposes ledger helpers plus route-specific zap instructions. Most integrations should use the TypeScript SDK builders because they assemble token accounts, ledger transactions, downstream payloads, bin arrays, and cleanup transactions.

Instruction Index

Ledger Instructions

Zap-in flows use a short-lived ledger to keep token balances consistent across multiple transactions. Use set_ledger_balance for a pool token the user already contributes directly. Use update_ledger_balance_after_swap when a previous swap transaction produced the token.

Zap Out

zap_out is a generic wrapper around a whitelisted downstream swap instruction. Execution:
  1. Validate zap-out parameters and downstream discriminator.
  2. Read the post-action balance from user_token_in_account.
  3. Return without swapping if the balance did not increase.
  4. Compute swap_amount = min(balance_delta * percentage / 100, max_swap_amount).
  5. Overwrite the downstream payload amount at offset_amount_in.
  6. Invoke the downstream swap instruction with the provided remaining accounts.

DAMM v2 Zap In

zap_in_damm_v2 uses ledger balances to add liquidity to an existing DAMM v2 position. Execution:
  1. Calculate liquidity from ledger token A/B amounts after transfer-fee exclusion.
  2. Add liquidity once so any following internal swap can still accrue pool fees to the position.
  3. Update the ledger with the amounts consumed by the first add-liquidity call.
  4. If one side remains, calculate a DAMM v2 swap2 amount for the surplus side and perform the swap through CPI.
  5. Check post_sqrt_price against pre_sqrt_price and max_sqrt_price_change_bps.
  6. Add liquidity again with the newly balanced token amounts.
  7. Update and log remaining ledger balances.
DAMM v2 rate-limited pools can require extra remaining accounts for the internal swap2 CPI. Preserve the remaining-account list generated by the SDK.

DLMM Zap In

DLMM zap-in uses DLMM rebalance_liquidity after constructing an add-liquidity distribution from the selected strategy. For uninitialized positions, Zap derives: The uninitialized position account must have the default owner and empty data, and must not equal owner or rent_payer.

Transaction Sequencing

For zap out, place the upstream action that creates the input token balance before the zap_out instruction in the same transaction or transaction sequence that preserves the pre-balance assumption.