Skip to main content

createTradePtExactOutInstruction

Builds a raw instruction to execute an exact-out swap to receive a specific amount of PT or SY tokens. Unlike the exact-in variant, this instruction guarantees the output amount and calculates the required input. An optional price limit provides anti-sandwich protection.

Usage

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

const ix = createTradePtExactOutInstruction({
  trader: traderKeypair.publicKey,
  market: marketAddress,
  ticks: ticksAccount,
  tokenSyTrader: traderSyTokenAccount,
  tokenPtTrader: traderPtTokenAccount,
  tokenSyEscrow: marketSyEscrow,
  tokenPtEscrow: marketPtEscrow,
  addressLookupTable: lookupTableAddress,
  tokenProgram: tokenProgramId,
  syProgram: syProgramId,
  tokenFeeTreasurySy: feeTreasurySyAccount,
  tokenFeeTreasuryPt: feeTreasuryPtAccount,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  amountOut: 1_000_000_000n,
  swapDirection: { buyPt: {} },
  amountInConstraint: 1_100_000_000n,
  priceSpotLimit: 1.05,
});

Accounts

NameTypeSignerWritableDescription
traderPublicKeyYesYesWallet executing the trade
marketPublicKeyNoYesThe CLMM market account
ticksPublicKeyNoYesThe market tick array account
tokenSyTraderPublicKeyNoYesTrader’s SY token account
tokenPtTraderPublicKeyNoYesTrader’s PT token account
tokenSyEscrowPublicKeyNoYesMarket SY escrow account
tokenPtEscrowPublicKeyNoYesMarket PT escrow account
addressLookupTablePublicKeyNoNoMarket address lookup table
tokenProgramPublicKeyNoNoSPL Token program
syProgramPublicKeyNoNoSY program
tokenFeeTreasurySyPublicKeyNoYesSY fee treasury account
tokenFeeTreasuryPtPublicKeyNoYesPT fee treasury account
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoCLMM program ID

Args

NameTypeDescription
amountOutu64Exact amount of output tokens desired
swapDirectionSwapDirectionDirection of the swap: BuyPt or SellPt
amountInConstraintu64 (optional)Maximum amount of input tokens to spend
priceSpotLimitf64 (optional)Price limit for anti-sandwich protection

Returns

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