Skip to main content

createWrapperWithdrawLiquidityInstruction

Withdraws liquidity from a CLMM market and converts the proceeds to base assets in a single atomic operation. This instruction removes the LP position, sells the PT component for SY on the market, and then redeems all SY for the underlying base asset. The caller receives base tokens directly.

Usage

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

const ix = createWrapperWithdrawLiquidityInstruction({
  withdrawer: withdrawerKeypair.publicKey,
  market: new PublicKey("market..."),
  ticks: new PublicKey("ticks..."),
  tokenPtEscrow: new PublicKey("tokenPtEscrow..."),
  tokenSyEscrow: new PublicKey("tokenSyEscrow..."),
  tokenSyWithdrawer: new PublicKey("tokenSyWithdrawer..."),
  tokenPtWithdrawer: new PublicKey("tokenPtWithdrawer..."),
  tokenProgram: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
  marketAddressLookupTable: new PublicKey("lookupTable..."),
  syProgram: new PublicKey("syProgram..."),
  tokenFeeTreasurySy: new PublicKey("tokenFeeTreasurySy..."),
  tokenFeeTreasuryPt: new PublicKey("tokenFeeTreasuryPt..."),
  lpPosition: new PublicKey("lpPosition..."),
  systemProgram: SystemProgram.programId,
  eventAuthority: new PublicKey("eventAuthority..."),
  program: new PublicKey("program..."),
  amountLp: 1_000_000n,
  syConstraint: 600_000n,
  redeemSyAccountsLength: 3,
});

Accounts

NameTypeSignerWritableDescription
withdrawerPublicKeyYesYesWallet withdrawing liquidity
marketPublicKeyNoYesThe CLMM market account
ticksPublicKeyNoYesThe market tick array account
tokenPtEscrowPublicKeyNoYesMarket PT escrow account
tokenSyEscrowPublicKeyNoYesMarket SY escrow account
tokenSyWithdrawerPublicKeyNoYesWithdrawer’s SY token account
tokenPtWithdrawerPublicKeyNoYesWithdrawer’s PT token account
tokenProgramPublicKeyNoNoSPL Token program
marketAddressLookupTablePublicKeyNoNoMarket address lookup table
syProgramPublicKeyNoNoSY program
tokenFeeTreasurySyPublicKeyNoYesSY fee treasury account
tokenFeeTreasuryPtPublicKeyNoYesPT fee treasury account
lpPositionPublicKeyNoYesLP position account
systemProgramPublicKeyNoNoSystem program
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoCLMM program ID

Args

NameTypeDescription
amountLpu64The amount of LP tokens to withdraw
syConstraintu64The maximum amount of SY to use when selling PT
redeemSyAccountsLengthu8The number of CPI remaining accounts used for SY redemption

Returns

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