Skip to main content

createWrapperWithdrawFundsInstruction

Builds a raw instruction that withdraws idle funds (PT, YT, or SY) from the orderbook with automatic SY redemption to the base asset. This combines the withdrawal and SY redemption steps atomically.

Usage

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

const ix = createWrapperWithdrawFundsInstruction(
  {
    trader: wallet.publicKey,
    orderbook: orderbookAddress,
    vault: vaultAddress,
    cpiAccountOrderbook: cpiAccountsOrderbook,
    tokenEscrowYt: orderbookEscrowYt,
    tokenEscrowSy: orderbookEscrowSy,
    tokenEscrowPt: orderbookEscrowPt,
    tokenSyTrader: userSyTokenAccount,
    tokenYtTrader: userYtTokenAccount,
    tokenPtTrader: userPtTokenAccount,
    systemProgram: SystemProgram.programId,
    syProgram: syProgramId,
    tokenProgram: TOKEN_PROGRAM_ID,
    exponentCore: EXPONENT_CORE_PROGRAM_ID,
    addressLookupTable: vaultLookupTable,
    eventAuthority: eventAuthorityPda,
    program: EXPONENT_ORDERBOOK_PROGRAM_ID,
  },
  {
    ptAmountOptional: amount("Some", [100_000n]),
    ytAmountOptional: amount("All"),
    syAmountOptional: amount("All"),
    redeemSyAccountsUntil: 0,
  }
);

Accounts

NameTypeSignerWritableDescription
traderPublicKeyYesNoThe trader withdrawing funds
orderbookPublicKeyNoYesOrderbook account
vaultPublicKeyNoYesVault account
cpiAccountOrderbookPublicKeyNoNoCPI accounts orderbook
tokenEscrowYtPublicKeyNoYesOrderbook YT escrow account
tokenEscrowSyPublicKeyNoYesOrderbook SY escrow account
tokenEscrowPtPublicKeyNoYesOrderbook PT escrow account
tokenSyTraderPublicKeyNoYesTrader’s SY token account
tokenYtTraderPublicKeyNoYesTrader’s YT token account
tokenPtTraderPublicKeyNoYesTrader’s PT token account
systemProgramPublicKeyNoNoSystem program
syProgramPublicKeyNoNoSY program
tokenProgramPublicKeyNoNoSPL Token program
exponentCorePublicKeyNoNoExponent Core program
addressLookupTablePublicKeyNoNoVault address lookup table
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoExponent Orderbook program

Args

NameTypeDescription
ptAmountOptionalAmountPT amount to withdraw: amount("All") or amount("Some", [value])
ytAmountOptionalAmountYT amount to withdraw: amount("All") or amount("Some", [value])
syAmountOptionalAmountSY amount to withdraw: amount("All") or amount("Some", [value])
redeemSyAccountsUntilnumberIndex into remaining accounts for SY redemption CPI accounts

Returns

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