Skip to main content

createSellYtInstruction

Builds a raw instruction to sell YT tokens for SY. This instruction buys PT from the pool, merges the PT and YT back into SY, and returns the net SY to the trader. The process leverages the PT/SY AMM to determine the conversion ratio.

Usage

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

const ix = createSellYtInstruction({
  trader: traderKeypair.publicKey,
  market: marketAddress,
  ticks: ticksAccount,
  tokenYtTrader: traderYtTokenAccount,
  tokenPtTrader: traderPtTokenAccount,
  tokenSyTrader: traderSyTokenAccount,
  tokenSyEscrow: marketSyEscrow,
  tokenPtEscrow: marketPtEscrow,
  tokenYtEscrow: marketYtEscrow,
  addressLookupTable: lookupTableAddress,
  tokenFeeTreasurySy: feeTreasurySyAccount,
  tokenFeeTreasuryPt: feeTreasuryPtAccount,
  tokenProgram: tokenProgramId,
  syProgram: syProgramId,
  exponentCoreProgram: exponentCoreProgramId,
  eventAuthority: eventAuthorityPda,
  program: clmmProgramId,
  ytIn: 1_000_000_000n,
  minSyOut: 900_000_000n,
  priceSpotLimit: 0.95,
});

Accounts

NameTypeSignerWritableDescription
traderPublicKeyYesYesWallet executing the trade
marketPublicKeyNoYesThe CLMM market account
ticksPublicKeyNoYesThe market tick array account
tokenYtTraderPublicKeyNoYesTrader’s YT token account
tokenPtTraderPublicKeyNoYesTrader’s PT token account
tokenSyTraderPublicKeyNoYesTrader’s SY token account
tokenSyEscrowPublicKeyNoYesMarket SY escrow account
tokenPtEscrowPublicKeyNoYesMarket PT escrow account
tokenYtEscrowPublicKeyNoYesMarket YT escrow account
addressLookupTablePublicKeyNoNoMarket address lookup table
tokenFeeTreasurySyPublicKeyNoYesSY fee treasury account
tokenFeeTreasuryPtPublicKeyNoYesPT fee treasury account
tokenProgramPublicKeyNoNoSPL Token program
syProgramPublicKeyNoNoSY program
exponentCoreProgramPublicKeyNoNoExponent core program (for strip/merge CPI)
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoCLMM program ID

Args

NameTypeDescription
ytInu64Amount of YT tokens to sell
minSyOutu64Minimum amount of SY tokens to receive
priceSpotLimitf64 (optional)Price limit for anti-sandwich protection

Returns

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