Transaction Structure
Every orderbook interaction goes throughcreateVaultSyncTransaction, which returns three parts:
| Part | What it contains | Why it’s separate |
|---|---|---|
preInstructions | Any permissionless setup instructions | Must be top-level instructions |
instruction | Squads sync transaction wrapping all vault-signed instructions | Executes with the vault’s smart account as signer |
postInstructions | Any post-operation instructions | Must be top-level instructions |
Trade Directions
TheOrderbookTradeDirection enum specifies the side of the trade:
Post Offer
orderbookAction.postOffer posts a limit order on the orderbook at a specified APY price.
Parameters
| Parameter | Type | Description |
|---|---|---|
orderbook | PublicKey | The orderbook account address |
direction | OrderbookTradeDirection | Trade direction (BUY_PT, SELL_PT, BUY_YT, SELL_YT) |
priceApy | number | Limit price expressed as an APY (e.g., 0.10 for 10%) |
amount | bigint | Amount in native token units |
offerIdx | number | Unique offer index per trader — used for position tracking |
offerOption | OrderbookOfferOption | Optional. "FillOrKill" to require full fill or cancel |
virtualOffer | boolean | Optional. Use virtual offers to share PT/YT liquidity |
expirySeconds | number | Optional. Time-to-live in seconds before the offer auto-cancels |
Market Offer
orderbookAction.marketOffer executes a market order against existing resting offers on the orderbook.
Parameters
| Parameter | Type | Description |
|---|---|---|
orderbook | PublicKey | The orderbook account address |
direction | OrderbookTradeDirection | Trade direction |
maxPriceApy | number | Maximum acceptable APY price |
amount | bigint | Amount to spend in native token units |
minAmountOut | bigint | Minimum output amount — slippage protection |
virtualOffer | boolean | Optional. Use virtual offers |
Remove Offer
orderbookAction.removeOffer cancels an existing limit order on the orderbook.
Parameters
| Parameter | Type | Description |
|---|---|---|
orderbook | PublicKey | The orderbook account address |
offerIdx | number | The offer index to cancel (same index used when posting) |
Withdraw Funds
orderbookAction.withdrawFunds withdraws settled funds from the user escrow on the orderbook back to the vault’s token accounts.
Parameters
| Parameter | Type | Description | |
|---|---|---|---|
orderbook | PublicKey | The orderbook account address | |
ptAmount | `bigint | null` | Optional. PT amount to withdraw — null withdraws the maximum available |
ytAmount | `bigint | null` | Optional. YT amount to withdraw — null withdraws the maximum available |
syAmount | `bigint | null` | Optional. SY amount to withdraw — null withdraws the maximum available |