Skip to main content
These examples are based on the local damm-v2-sdk examples and tests. They focus on transaction construction patterns. For the full method catalog, see the SDK Reference.

Setup

Use devnet while testing. The DAMM v2 program ID is the same for devnet and mainnet:

Fetch Pool And User Positions

Use getPositionsByUser(user) when you need a wallet-level position view across all pools.

Quote And Swap

The recommended swap flow is:
  1. Fetch the pool state.
  2. Resolve the current activation point.
  3. Quote with getQuote2.
  4. Build the swap with swap2.
  5. Simulate, sign, and send.
Use SwapMode.PartialFill when the swap may consume less than the requested input. Use SwapMode.ExactOut with maximumAmountIn when the output amount is fixed.

Create A Position And Add Liquidity

createPositionAndAddLiquidity creates the position NFT and adds liquidity in one transaction.
For compounding pools, include tokenAAmount, tokenBAmount, and liquidity when calculating liquidity so the quote uses the current pool reserves.

Add Liquidity To An Existing Position

Use getDepositQuote before building the transaction. The quote returns the liquidity delta and the counterpart token amount.

Remove Liquidity And Close A Position

removeAllLiquidityAndClosePosition combines fee claim, full liquidity removal, and position close. It will reject locked positions, so load vesting accounts and the current point first.
Use removeLiquidity when you only want to remove a specific liquidity delta and keep the position open.

Claim Position Fees

claimPositionFee2 is the preferred fee claim helper for new integrations.

Lock Liquidity

Use permanentLockPosition for irreversible locks and lockPosition for vesting schedules.
For scheduled vesting, create a vesting account signer and pass the cliff and period settings:

Initialize And Claim Rewards

initializeAndFundReward creates a reward slot and funds it in one transaction.
Claim rewards by loading the current pool and position state:
Use initializeReward plus fundReward when initialization and funding should be separate admin actions.

Create A Customizable Pool

Customizable pools let the creator set fee behavior, activation behavior, and whether initial liquidity should be locked.
Use createPool instead when you are creating against an existing DAMM v2 config account. Use createCustomPoolWithDynamicConfig when your flow needs to create through a dynamic config account.

Token-2022 Transfer Fee Inputs

For Token-2022 transfer-fee mints, pass mint and epoch data into quote helpers so the SDK can account for transfer fees.