Skip to main content

createWrapperBuyYtInstruction

Builds a raw instruction to buy YT tokens from base assets in a single atomic operation. This instruction handles SY minting from the base asset, stripping SY into PT and YT, and selling excess PT back to the pool — all within a single transaction instruction. This is the most convenient way to acquire YT from a base asset.

Usage

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

const ix = createWrapperBuyYtInstruction({
  buyer: buyerKeypair.publicKey,
  market: marketAddress,
  tokenSyTrader: buyerSyTokenAccount,
  tokenYtTrader: buyerYtTokenAccount,
  tokenPtTrader: buyerPtTokenAccount,
  tokenSyEscrow: marketSyEscrow,
  tokenPtEscrow: marketPtEscrow,
  tokenYtEscrow: marketYtEscrow,
  marketAddressLookupTable: lookupTableAddress,
  tokenProgram: tokenProgramId,
  syProgram: syProgramId,
  systemProgram: SystemProgram.programId,
  tokenFeeTreasurySy: feeTreasurySyAccount,
  tokenFeeTreasuryPt: feeTreasuryPtAccount,
  ticks: ticksAccount,
  exponentCoreProgram: exponentCoreProgramId,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  ytOut: 1_000_000_000n,
  maxBaseAmount: 1_100_000_000n,
  mintSyAccountsLength: 5,
  depositYtAccountsUntil: 3,
});

Accounts

NameTypeSignerWritableDescription
buyerPublicKeyYesYesWallet 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
marketAddressLookupTablePublicKeyNoNoMarket address lookup table
tokenProgramPublicKeyNoNoSPL Token program
syProgramPublicKeyNoNoSY program
systemProgramPublicKeyNoNoSystem program
tokenFeeTreasurySyPublicKeyNoYesSY fee treasury account
tokenFeeTreasuryPtPublicKeyNoYesPT fee treasury account
exponentCoreProgramPublicKeyNoNoExponent core program (for strip/merge CPI)
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoCLMM program ID

Args

NameTypeDescription
ytOutu64Amount of YT tokens to receive
maxBaseAmountu64Maximum amount of base asset to spend
mintSyAccountsLengthu8Number of CPI accounts used for SY minting
depositYtAccountsUntilu8Number of CPI accounts used for YT deposit

Returns

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