Skip to main content

createTradePtInstruction

Builds a raw instruction to execute an exact-in swap between PT and SY tokens. The swap direction determines whether PT is being bought (SY in, PT out) or sold (PT in, SY out). An optional price limit provides anti-sandwich protection by reverting if the spot price moves beyond the specified threshold.

Usage

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

const ix = createTradePtInstruction({
  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,
  amountIn: 1_000_000_000n,
  swapDirection: { buyPt: {} },
  amountOutConstraint: 900_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
amountInu64Exact amount of input tokens
swapDirectionSwapDirectionDirection of the swap: BuyPt or SellPt
amountOutConstraintu64 (optional)Minimum amount of output tokens to receive
priceSpotLimitf64 (optional)Price limit for anti-sandwich protection

Returns

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