The stable integration contract is the published DLMM IDL and the official SDK
behavior. This page is cross-checked against the
lb_clmm source so the
account ordering and remaining-account notes match the on-chain handlers.Program ID
Generated Bindings
Prefer generated CPI bindings from the DLMM IDL. Thelb_clmm handlers use
Anchor accounts, optional accounts, generated instruction args, and #[event_cpi]
on many v2 instructions.
If you use Anchor-generated CPI modules, the handler usually looks like:
invoke / invoke_signed, build the same
instruction data and account metas produced by the generated client.
CPI Instruction Scope
For the fulllb_clmm instruction-family map, see
DLMM Program Instructions. This
page focuses on CPI implementation details for the v2 instructions most
integrations call: swap2, swap_exact_out2, add_liquidity2,
remove_liquidity2, claim_fee2, claim_reward2, and rebalance_liquidity.
New CPI integrations should prefer v2 instructions because they support SPL
Token, Token-2022, dynamic positions, and explicit remaining account metadata.
Event CPI Accounts
Severallb_clmm account structs use #[event_cpi], including Swap2,
AddLiquidity2, RemoveLiquidity2, ClaimFee2, and ClaimReward2. Generated
clients include extra event CPI accounts, commonly:
When you inspect an SDK or generated Rust instruction, keep these accounts in
the exact generated position. If they are missing or moved, Anchor account
deserialization can fail before the DLMM handler reaches your intended logic.
Remaining Accounts Ordering
lb_clmm v2 handlers parse remaining accounts in two phases.
- They consume Token-2022 transfer-hook account groups according to
RemainingAccountsInfo.slices. - They consume the leftover accounts as instruction-specific accounts, usually bin arrays.
src/utils/remaining_accounts_util.rs and calls like:
ctx.remaining_accounts must match the order of
RemainingAccountsInfo.slices.
Instruction Account Notes
Swap2 CPI Shape
This shape mirrorsswap2 on the program.
user account with a PDA, use
CpiContext::new_with_signer and pass your signer seeds. The token account owner
must still match the authority DLMM expects for the transfer.
Token-2022 Transfer Hooks
For Token-2022 mints with transfer hooks, include the extra account metas inctx.remaining_accounts and describe them with RemainingAccountsInfo.slices.
Example ordering for swap2 with token X and token Y transfer hooks:
- Token X transfer-hook accounts.
- Token Y transfer-hook accounts.
- Bin array accounts for the swap route.
TransferHookReferral when the host fee
mint requires hook accounts.
Optional Accounts
Some generated clients represent optional accounts asOption<AccountInfo>.
Others use an explicit placeholder account when constructing raw account metas.
When using generated Anchor CPI bindings, follow the generated optional-account
type. When using raw
Instruction construction, compare against the TypeScript
SDK or commons generated client output for the exact placeholder behavior.
Off-Chain Account Planning
Use the Typescript SDK orcommons crate to plan accounts before calling your CPI program.

