Skip to main content

createWithdrawLiquidityInstruction

Builds a raw instruction to withdraw liquidity from an LP position and claim accumulated fees. This removes a specified amount of liquidity from the position, returning PT and SY tokens to the owner along with any accrued trading fees.

Usage

import { createWithdrawLiquidityInstruction } from "@exponent-labs/exponent-sdk/client/clmm";
import { PublicKey, SystemProgram } from "@solana/web3.js";

const ix = createWithdrawLiquidityInstruction({
  owner: ownerKeypair.publicKey,
  market: marketAddress,
  lpPosition: lpPositionAccount,
  ticks: ticksAccount,
  tokenPtDst: ownerPtTokenAccount,
  tokenSyDst: ownerSyTokenAccount,
  tokenPtEscrow: marketPtEscrow,
  tokenSyEscrow: marketSyEscrow,
  addressLookupTable: lookupTableAddress,
  tokenProgram: tokenProgramId,
  syProgram: syProgramId,
  systemProgram: SystemProgram.programId,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  liquidityToRemove: 500_000_000n,
  minPtOut: 200_000_000n,
  minSyOut: 200_000_000n,
});

Accounts

NameTypeSignerWritableDescription
ownerPublicKeyYesYesWallet withdrawing liquidity
marketPublicKeyNoYesThe CLMM market account
lpPositionPublicKeyNoYesLP position account
ticksPublicKeyNoYesThe market tick array account
tokenPtDstPublicKeyNoYesOwner’s PT token account
tokenSyDstPublicKeyNoYesOwner’s SY token account
tokenPtEscrowPublicKeyNoYesMarket PT escrow account
tokenSyEscrowPublicKeyNoYesMarket SY escrow account
addressLookupTablePublicKeyNoNoMarket address lookup table
tokenProgramPublicKeyNoNoSPL Token program
syProgramPublicKeyNoNoSY program
systemProgramPublicKeyNoNoSystem program
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoCLMM program ID

Args

NameTypeDescription
liquidityToRemoveu64Amount of LP tokens to withdraw
minPtOutu64Minimum PT tokens to receive
minSyOutu64Minimum SY tokens to receive

Returns

TransactionInstruction — a transaction instruction ready to be added to a transaction.