Skip to main content
Use the commons crate when you need Rust tooling around DLMM.

Install

If your project is in the same workspace as dlmm-sdk, depend on the local crate by path:
The crate uses the generated Anchor client module from the DLMM IDL:

What It Provides

Program ID

The generated dlmm module points at the public DLMM program:
Mainnet and devnet use the same public program ID:

Account Decoding

The generated commons::dlmm module exposes IDL account types such as LbPair, BinArray, BinArrayBitmapExtension, PositionV2, and LimitOrder. Use pod_read_unaligned_skip_disc for zero-copy account layouts that start with the Anchor 8-byte discriminator:
The helper checks that the account data is long enough, skips the discriminator, and reads exactly size_of::<T>() bytes.

PDA Helpers

Use commons::pda helpers instead of duplicating DLMM seeds:
Common derivation helpers:

Bin Arrays

DLMM liquidity is organized in bin arrays. BinArrayExtension gives you the same index and coverage helpers used by the quote code:
For swaps, use get_bin_array_pubkeys_for_swap. It walks the pool bitmap and, when supplied, the bitmap extension:
swap_for_y = true means token X is swapped for token Y. swap_for_y = false means token Y is swapped for token X.

Swap Quotes

The quote functions simulate DLMM swap execution against decoded account state. They support:
  • Current pool status and activation checks.
  • Base and variable fee updates.
  • Bin traversal and bitmap extension lookup.
  • Limit-order liquidity when the pool supports it.
  • Token-2022 transfer fees on input and output mints.

Exact-In

Exact-Out

bin_arrays_by_pubkey is a HashMap<Pubkey, BinArray> keyed by the bin array accounts you fetched for the route. If the quote returns Active bin array not found or Pool out of liquidity, fetch more bin arrays in the swap direction.

Building Swap Instructions

The generated dlmm::client module can build account metas and instruction data. The integration tests in commons/tests/integration/test_swap.rs show the full pattern.
For Token-2022 transfer hooks, populate remaining_accounts_info and append the extra account metas described in the next section.

Token-2022

commons::token_2022 handles two separate concerns: For v2 instructions that may transfer Token-2022 mints, pass the extra account metas after the main accounts and encode the matching RemainingAccountsInfo:
Use ActionType::Reward(index) when building remaining accounts for a reward claim or reward-aware flow.

Position And Limit Order Reads

Use DynamicPosition::parse when you need a backend-friendly view of a position. It combines the base PositionV2 account, dynamic extension bytes, pool state, bin arrays, fee checkpoints, and reward checkpoints.
Use account filters when scanning positions or limit orders:

Testing

The commons crate includes integration tests that load DLMM program fixtures and serialized account data into solana-program-test: Run the commons tests from the SDK repository:

Best Practices