These examples are based on the current ts-client source in the DLMM SDK repository. They focus on transaction construction patterns. For the full method catalog, see the SDK Reference.
Setup
Use cluster: "devnet" for devnet. The SDK defaults to the public DLMM program ID; only pass a custom programId when Meteora has provided a compatible deployment or test harness.
Quote And Swap
The swap flow is:
- Load the pool.
- Fetch bin arrays in the swap direction.
- Quote using current pool state.
- Build the transaction with the quote’s bin arrays and minimum output.
- Sign and send.
Use quote.consumedInAmount when partial fill is enabled. It may be lower than your requested input amount if the pool cannot consume the full input under the quote constraints.
Create A Position And Add Liquidity
For most LP flows, initialize the position and add liquidity in one transaction. The SDK initializes required bin arrays and token accounts when needed.
Use StrategyType.Spot, StrategyType.BidAsk, or StrategyType.Curve depending on the distribution you want. The product-level behavior of these strategies is covered in DLMM Strategies and Use Cases.
Add Liquidity To An Existing Position
For large ranges, use addLiquidityByStrategyChunkable or the multiple-position helpers documented in the SDK Reference.
Fetch User Positions
Use DLMM.getAllLbPairPositionsByUser(connection, user, opt) when you need all DLMM positions for a wallet across pools.
Remove Liquidity, Claim, And Close
removeLiquidity returns one or more transactions because wide positions may need chunking.
bps: 10_000 removes 100% of liquidity. Set shouldClaimAndClose only when the position should claim accrued fees/rewards and close after the remove flow.
Claim Fees And Rewards
Use claimSwapFee, claimAllSwapFee, claimLMReward, claimAllLMRewards, claimAllRewards, or claimAllRewardsByPosition depending on whether you are claiming one position, one reward index, or a wallet-wide set of positions.
Place A Limit Order
Limit orders deposit token X on the ask side and token Y on the bid side. The SDK creates missing bin arrays, initializes bitmap extension accounts when needed, wraps SOL when needed, and builds the place_limit_order instruction.
Before placing a limit order into existing bins, check whether the bins already contain pending limit order liquidity on the opposite side:
Cancel by reading non-empty order bins and passing those bin IDs:
Create A Permissionless V2 Pool
Use createLbPair2 for new permissionless pools. It reads PresetParameter2, supports SPL Token and Token-2022, and derives the pool PDA from the preset and token pair.
Use createCustomizablePermissionlessLbPair2 when the creator must configure activation behavior, base fee parameters, ConcreteFunctionType, or CollectFeeMode.