Skip to main content

createWrapperSellYtInstruction

Sells YT tokens for base assets in a single atomic operation. This instruction buys PT on the market, merges the PT and YT back into SY, and then redeems the SY for the underlying base asset. The entire flow is executed atomically so the caller receives base tokens directly from their YT position.

Usage

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

const ix = createWrapperSellYtInstruction({
  seller: sellerKeypair.publicKey,
  market: new PublicKey("market..."),
  tokenSyTrader: new PublicKey("tokenSyTrader..."),
  tokenYtTrader: new PublicKey("tokenYtTrader..."),
  tokenPtTrader: new PublicKey("tokenPtTrader..."),
  tokenSyEscrow: new PublicKey("tokenSyEscrow..."),
  tokenYtEscrow: new PublicKey("tokenYtEscrow..."),
  tokenPtEscrow: new PublicKey("tokenPtEscrow..."),
  marketAddressLookupTable: new PublicKey("lookupTable..."),
  tokenProgram: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
  syProgram: new PublicKey("syProgram..."),
  tokenFeeTreasurySy: new PublicKey("tokenFeeTreasurySy..."),
  tokenFeeTreasuryPt: new PublicKey("tokenFeeTreasuryPt..."),
  ticks: new PublicKey("ticks..."),
  exponentCoreProgram: new PublicKey("exponentCoreProgram..."),
  eventAuthority: new PublicKey("eventAuthority..."),
  program: new PublicKey("program..."),
  ytAmount: 1_000_000n,
  minBaseAmount: 950_000n,
  redeemSyAccountsUntil: 3,
});

Accounts

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

Args

NameTypeDescription
ytAmountu64The amount of YT tokens to sell
minBaseAmountu64The minimum amount of base asset to receive
redeemSyAccountsUntilu8The number of CPI remaining accounts used for SY redemption

Returns

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