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:
- Validate zap-out parameters and downstream discriminator.
- Read the post-action balance from
user_token_in_account. - Return without swapping if the balance did not increase.
- Compute
swap_amount = min(balance_delta * percentage / 100, max_swap_amount). - Overwrite the downstream payload amount at
offset_amount_in. - 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:
- Calculate liquidity from ledger token A/B amounts after transfer-fee exclusion.
- Add liquidity once so any following internal swap can still accrue pool fees to the position.
- Update the ledger with the amounts consumed by the first add-liquidity call.
- If one side remains, calculate a DAMM v2
swap2amount for the surplus side and perform the swap through CPI. - Check
post_sqrt_priceagainstpre_sqrt_priceandmax_sqrt_price_change_bps. - Add liquidity again with the newly balanced token amounts.
- 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 DLMMrebalance_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.
