Skip to main content

createBuyPtInstruction

Builds a raw instruction to buy PT tokens using base assets. This instruction handles SY minting from the base asset internally via remaining accounts, making it a convenience wrapper that combines the mint-SY and buy-PT steps into a single instruction.

Usage

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

const ix = createBuyPtInstruction({
  buyer: buyerKeypair.publicKey,
  market: marketAddress,
  tokenSyTrader: buyerSyTokenAccount,
  tokenPtTrader: buyerPtTokenAccount,
  tokenSyEscrow: marketSyEscrow,
  tokenPtEscrow: marketPtEscrow,
  addressLookupTable: lookupTableAddress,
  tokenProgram: tokenProgramId,
  syProgram: syProgramId,
  ticks: ticksAccount,
  tokenFeeTreasurySy: feeTreasurySyAccount,
  tokenFeeTreasuryPt: feeTreasuryPtAccount,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  minPtAmount: 900_000_000n,
  baseAmount: 1_000_000_000n,
  priceSpotLimit: 1.05,
  mintSyRemAccountsUntil: 5,
});

Accounts

NameTypeSignerWritableDescription
buyerPublicKeyYesYesWallet 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
minPtAmountu64Minimum amount of PT tokens to receive
baseAmountu64Amount of base asset to spend
priceSpotLimitf64 (optional)Price limit for anti-sandwich protection
mintSyRemAccountsUntilu8Number of remaining accounts used for the SY minting CPI

Returns

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