Skip to main content

createTradePtExactOutInstruction

Buys an exact amount of PT tokens by specifying the desired output amount. This instruction uses createTradePtExactOutInstruction with swapDirection: { buyPt: {} } to purchase a precise quantity of PT from the CLMM market, spending SY tokens as input. The caller specifies the exact PT amount to receive, and an optional maximum SY input constraint can be set for slippage protection.

Usage

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

const ix = createTradePtExactOutInstruction({
  trader: traderKeypair.publicKey,
  market: new PublicKey("market..."),
  ticks: new PublicKey("ticks..."),
  tokenSyTrader: new PublicKey("tokenSyTrader..."),
  tokenPtTrader: new PublicKey("tokenPtTrader..."),
  tokenSyEscrow: new PublicKey("tokenSyEscrow..."),
  tokenPtEscrow: new PublicKey("tokenPtEscrow..."),
  addressLookupTable: new PublicKey("lookupTable..."),
  tokenProgram: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
  syProgram: new PublicKey("syProgram..."),
  tokenFeeTreasurySy: new PublicKey("tokenFeeTreasurySy..."),
  tokenFeeTreasuryPt: new PublicKey("tokenFeeTreasuryPt..."),
  eventAuthority: new PublicKey("eventAuthority..."),
  program: new PublicKey("program..."),
  amountOut: 1_000_000n,
  swapDirection: { buyPt: {} },
  amountInConstraint: 1_100_000n,
  priceSpotLimit: 0.95,
});

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
amountOutu64The exact amount of PT tokens to receive
swapDirectionSwapDirectionSet to { buyPt: {} } to buy PT
amountInConstraintu64 (optional)The maximum amount of SY to spend as slippage protection
priceSpotLimitf64 (optional)The price limit for the trade

Returns

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