Skip to main content

createWrapperWithdrawInstruction

Builds a raw instruction that burns tranche LP shares, withdraws SY, and redeems SY back to base assets.

Usage

import {
  TrancheSide,
  createWrapperWithdrawInstruction,
} from "@exponent-labs/exponent-sdk/client/tranching";

const ix = createWrapperWithdrawInstruction(
  {
    user: wallet.publicKey,
    market: marketAddress,
    returnModelStorage,
    addressLookupTable,
    syProgram,
    syMint,
    tokenLpSrc: userLpTokenAccount,
    tokenSyEscrow,
    tokenDst: userSyTokenAccount,
    mintLp: mintLpSenior,
    tokenProgram,
    eventAuthority,
    program: tranchingProgram,
  },
  {
    trancheSide: TrancheSide.Senior,
    lpAmountIn: 500_000_000n, // raw Senior LP units to burn
    minBaseOut: 0n,           // raw base-token units
    redeemSyAccountsUntil: 0,
  }
);

Accounts

NameTypeSignerWritableDescription
userPublicKeyYesYesWithdrawer
marketPublicKeyNoYesTranching market account
returnModelStoragePublicKeyNoYesReturn model storage account
addressLookupTablePublicKeyNoNoMarket address lookup table
syProgramPublicKeyNoNoLinked SY program
syMintPublicKeyNoYesSY mint
tokenLpSrcPublicKeyNoYesUser LP source account
tokenSyEscrowPublicKeyNoYesMarket SY escrow
tokenDstPublicKeyNoYesUser SY token account used by the wrapper
mintLpPublicKeyNoYesSenior or Junior LP mint
tokenProgramPublicKeyNoNoSPL Token program
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoExponent Tranching program

Args

NameTypeDescription
trancheSideTrancheSideSenior or Junior
lpAmountInu64Selected-tranche LP shares to burn, in raw LP units
minBaseOutu64Minimum base asset output, in raw base-token units
redeemSyAccountsUntilu8Number of remaining accounts used by the SY redeem CPI segment

Remaining accounts

Append remaining accounts in this order:
  1. SY redeem CPI accounts, with length redeemSyAccountsUntil
  2. Tranching getSyState and withdrawSy CPI accounts
Use TranchingMarket.ixWrapperWithdraw to build this ordering automatically.

Returns

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