Skip to main content
The ixWrapperWithdrawFunds instruction withdraws trading balances from your orderbook escrow. When you post an order, tokens enter the escrow. As orders fill, balances shift between token types (e.g., SY becomes YT on a filled BuyYT). After removing unfilled orders, the remaining balances become withdrawable. Use this instruction to transfer PT, YT, and SY from your escrow to your wallet.
Staged interest from YT accrual is not included in these balances. Collect it separately with ixWrapperCollectInterest.

Usage

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

const ix = await orderbook.ixWrapperWithdrawFunds({
  trader: wallet.publicKey,
  mintSy: syMintAddress,
  ptAmount: amount("Some", [500_000_000n]),
  ytAmount: amount("Some", [500_000_000n]),
  syAmount: amount("All"),
});

Required Parameters

ParameterTypeDescription
traderPublicKeyThe trader’s wallet public key
mintSyPublicKeyThe SY token mint address
ptAmountAmountAmount of PT tokens to withdraw
ytAmountAmountAmount of YT tokens to withdraw
syAmountAmountAmount of SY tokens to withdraw

Optional Parameters

ParameterTypeDescription
ptSrcPublicKeyPT token source account
ytSrcPublicKeyYT token source account
sySrcPublicKeySY token source account
tokenBaseTraderPublicKeyBase token account for the trader

Amount Helper

The amount helper from @exponent-labs/exponent-sdk creates the discriminated union used for withdrawal amounts:
import { amount } from "@exponent-labs/exponent-sdk";

// Withdraw all available funds
amount("All")

// Withdraw a specific amount (bigint)
amount("Some", [500_000_000n])

Returns

Returns a TransactionInstruction that executes the withdraw call.

Checking Withdrawable Funds

Before withdrawing, you can check the available balances using getUserBalances:
import { amount } from "@exponent-labs/exponent-sdk";

const balances = orderbook.getUserBalances(wallet.publicKey);

console.log("Withdrawable PT:", balances.pt);
console.log("Withdrawable YT:", balances.yt);
console.log("Withdrawable SY:", balances.sy);

// Withdraw all available funds
const ix = await orderbook.ixWrapperWithdrawFunds({
  trader: wallet.publicKey,
  mintSy: syMintAddress,
  ptAmount: amount("All"),
  ytAmount: amount("All"),
  syAmount: amount("All"),
});