Skip to main content

createBuyYtInstruction

Builds a raw instruction to buy YT tokens using SY. This instruction strips SY into PT and YT, then sells the excess PT back to the pool for SY, effectively converting the input SY into YT at the current market rate. The process leverages the PT/SY AMM to determine the conversion ratio.

Usage

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

const ix = createBuyYtInstruction({
  trader: traderKeypair.publicKey,
  market: marketAddress,
  ticks: ticksAccount,
  tokenSyTrader: traderSyTokenAccount,
  tokenYtTrader: traderYtTokenAccount,
  tokenPtTrader: traderPtTokenAccount,
  tokenSyEscrow: marketSyEscrow,
  tokenPtEscrow: marketPtEscrow,
  tokenYtEscrow: marketYtEscrow,
  tokenFeeTreasurySy: feeTreasurySyAccount,
  tokenFeeTreasuryPt: feeTreasuryPtAccount,
  tokenProgram: tokenProgramId,
  addressLookupTable: lookupTableAddress,
  syProgram: syProgramId,
  exponentCoreProgram: exponentCoreProgramId,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  syIn: 1_000_000_000n,
  minYtOut: 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
tokenYtTraderPublicKeyNoYesTrader’s YT token account
tokenPtTraderPublicKeyNoYesTrader’s PT token account
tokenSyEscrowPublicKeyNoYesMarket SY escrow account
tokenPtEscrowPublicKeyNoYesMarket PT escrow account
tokenYtEscrowPublicKeyNoYesMarket YT escrow account
tokenFeeTreasurySyPublicKeyNoYesSY fee treasury account
tokenFeeTreasuryPtPublicKeyNoYesPT fee treasury account
tokenProgramPublicKeyNoNoSPL Token program
addressLookupTablePublicKeyNoNoMarket address lookup table
syProgramPublicKeyNoNoSY program
exponentCoreProgramPublicKeyNoNoExponent core program (for strip/merge CPI)
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoCLMM program ID

Args

NameTypeDescription
syInu64Amount of SY tokens to spend
minYtOutu64Minimum amount of YT tokens to receive
priceSpotLimitf64 (optional)Price limit for anti-sandwich protection

Returns

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