Skip to main content

createWithdrawFundsInstruction

Builds a raw instruction to withdraw PT, YT, and/or SY tokens that are held in the orderbook back to the trader’s accounts.

Usage

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

const ix = createWithdrawFundsInstruction(
  {
    trader: wallet.publicKey,
    orderbook: orderbookAddress,
    vault: vaultAddress,
    tokenEscrowYt: orderbookYtEscrow,
    tokenEscrowSy: orderbookSyEscrow,
    tokenEscrowPt: orderbookPtEscrow,
    tokenSyTrader: userSyTokenAccount,
    tokenYtTrader: userYtTokenAccount,
    tokenPtTrader: userPtTokenAccount,
    systemProgram: SYSTEM_PROGRAM_ID,
    tokenProgram: TOKEN_2022_PROGRAM_ID,
    syProgram: syProgramId,
    exponentCore: EXPONENT_CORE_PROGRAM_ID,
    addressLookupTable: vaultLookupTable,
    cpiAccountOrderbook: cpiAccountsOrderbook,
    eventAuthority: eventAuthorityPda,
    program: EXPONENT_ORDERBOOK_PROGRAM_ID,
  },
  {
    ptAmountOptional: amount("All"),
    ytAmountOptional: amount("Some", [500_000n]),
    syAmountOptional: amount("All"),
  }
);

Accounts

NameTypeSignerWritableDescription
traderPublicKeyYesNoThe user withdrawing funds
orderbookPublicKeyNoYesOrderbook account
vaultPublicKeyNoNoVault account
tokenEscrowYtPublicKeyNoYesOrderbook YT escrow account
tokenEscrowSyPublicKeyNoYesOrderbook SY escrow account
tokenEscrowPtPublicKeyNoYesOrderbook PT escrow account
tokenSyTraderPublicKeyNoYesTrader SY token account
tokenYtTraderPublicKeyNoYesTrader YT token account
tokenPtTraderPublicKeyNoYesTrader PT token account
systemProgramPublicKeyNoNoSystem program
tokenProgramPublicKeyNoNoSPL Token 2022 program
syProgramPublicKeyNoNoSY program
exponentCorePublicKeyNoNoExponent Core program
addressLookupTablePublicKeyNoNoVault address lookup table
cpiAccountOrderbookPublicKeyNoNoCPI accounts orderbook
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])

Amount Helper

import { amount } from "@exponent-labs/exponent-sdk/client/orderbook";

amount("All")                // withdraw everything available
amount("Some", [500_000n])   // withdraw a specific amount

Returns

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