Instructions Reference
Complete reference for all Seesaw protocol instructions.
Instruction Overview
Instruction Discriminators
| # | Instruction | Discriminator |
|---|---|---|
| 0 | initialize_config | 0x00 |
| 1 | create_market | 0x01 |
| 2 | snapshot_start | 0x02 |
| 3 | snapshot_end | 0x03 |
| 4 | place_order | 0x04 |
| 5 | cancel_order | 0x05 |
| 6 | resolve_market | 0x06 |
| 7 | settle_position | 0x07 |
| 8 | close_market | 0x08 |
| 9 | force_close | 0x09 |
initialize_config
One-time protocol initialization.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | config | - | W | Config PDA |
| 1 | authority | S | W | Initial admin |
| 2 | treasury | - | - | Fee recipient |
| 3 | default_settlement_mint | - | - | USDC mint |
| 4 | system_program | - | - | System Program |
Arguments
| Field | Type | Description |
|---|---|---|
| taker_fee_bps | u16 | Taker fee (max 500) |
| maker_rebate_bps | u16 | Maker rebate (<= taker) |
| crank_reward_lamports | u64 | SOL per crank |
| tick_size_bps | u16 | Price tick size |
Compute Units
~5,000 CU
create_market
Create a new market for an epoch.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | market | - | W | Market PDA |
| 1 | orderbook | - | W | Orderbook PDA |
| 2 | vault | - | W | Vault PDA |
| 3 | config | - | - | Protocol config |
| 4 | pyth_feed | - | - | Pyth price feed |
| 5 | settlement_mint | - | - | USDC mint |
| 6 | payer | S | W | Rent payer |
| 7 | system_program | - | - | System Program |
| 8 | token_program | - | - | SPL Token |
Arguments
| Field | Type | Description |
|---|---|---|
| market_id | u64 | Epoch ID |
Compute Units
~25,000 CU
snapshot_start
Capture opening price from Pyth.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | market | - | W | Market PDA |
| 1 | pyth_feed | - | - | Pyth price feed |
| 2 | cranker | S | W | Crank operator |
| 3 | config | - | - | Protocol config |
| 4 | treasury | - | W | Crank reward source |
| 5 | system_program | - | - | System Program |
Arguments
None.
Compute Units
~8,000 CU
Idempotency
Returns success if already captured (no-op).
snapshot_end
Capture closing price from Pyth.
Accounts
Same as snapshot_start.
Arguments
None.
Compute Units
~15,000 CU (includes order cancellation)
Side Effects
- All open orders are cancelled
- Collateral/shares returned to users
place_order
Submit a limit order.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | market | - | W | Market PDA |
| 1 | orderbook | - | W | Orderbook PDA |
| 2 | position | - | W | User position PDA |
| 3 | user_token_account | - | W | User's USDC |
| 4 | vault | - | W | Market vault |
| 5 | user | S | - | Order owner |
| 6 | config | - | - | Protocol config |
| 7 | treasury_token_account | - | W | Fee recipient |
| 8 | token_program | - | - | SPL Token |
| 9 | system_program | - | - | System Program |
Arguments
| Field | Type | Description |
|---|---|---|
| side | u8 | 0=BuyYes, 1=SellYes, 2=BuyNo, 3=SellNo |
| price_bps | u16 | Limit price [1, 9999] |
| quantity | u64 | Share quantity |
| order_type | u8 | 0=Limit, 1=PostOnly, 2=IOC |
Compute Units
~15,000 - 50,000 CU (depends on matching)
cancel_order
Remove an open order.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | market | - | W | Market PDA |
| 1 | orderbook | - | W | Orderbook PDA |
| 2 | position | - | W | User position PDA |
| 3 | user_token_account | - | W | User's USDC |
| 4 | vault | - | W | Market vault |
| 5 | user | S | - | Order owner |
| 6 | token_program | - | - | SPL Token |
Arguments
| Field | Type | Description |
|---|---|---|
| order_id | u64 | Order to cancel |
Compute Units
~8,000 CU
resolve_market
Determine outcome from snapshots.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | market | - | W | Market PDA |
| 1 | cranker | S | W | Crank operator |
| 2 | config | - | - | Protocol config |
| 3 | treasury | - | W | Crank reward source |
| 4 | system_program | - | - | System Program |
Arguments
None.
Compute Units
~6,000 CU
Resolution Logic
if end_price >= start_price:
outcome = UP (1)
else:
outcome = DOWN (2)
settle_position
Distribute winnings to a user.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | market | - | W | Market PDA |
| 1 | position | - | W | Position to settle |
| 2 | user_token_account | - | W | User's USDC |
| 3 | vault | - | W | Market vault |
| 4 | user | - | - | Position owner |
| 5 | cranker | S | W | Crank operator |
| 6 | config | - | - | Protocol config |
| 7 | treasury | - | W | Crank reward source |
| 8 | token_program | - | - | SPL Token |
Arguments
None.
Compute Units
~10,000 CU
Payout Calculation
if outcome == UP:
payout = yes_shares
else:
payout = no_shares
close_market
Reclaim rent after settlement.
Accounts
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 0 | market | - | W | Market (closed) |
| 1 | orderbook | - | W | Orderbook (closed) |
| 2 | vault | - | W | Vault (closed) |
| 3 | vault_authority | - | - | Vault authority |
| 4 | rent_recipient | - | W | Receives rent |
| 5 | cranker | S | W | Crank operator |
| 6 | config | - | - | Protocol config |
| 7 | treasury | - | W | Crank reward source |
| 8 | token_program | - | - | SPL Token |
| 9 | system_program | - | - | System Program |
Arguments
None.
Compute Units
~12,000 CU
Prerequisites
- All positions settled
- Vault empty
- Orderbook empty
force_close
Emergency close expired market.
Accounts
Same as close_market, plus:
| # | Account | Signer | Writable | Description |
|---|---|---|---|---|
| 10 | user_position | - | W | Position to refund |
| 11 | user_token_account | - | W | Refund destination |
Arguments
None.
Compute Units
~15,000 CU per position
Prerequisites
current_time >= t_end + 604800 (7 days)
State Transitions
Error Codes
| Code | Name | Description |
|---|---|---|
| 0x1001 | E_MARKET_NOT_FOUND | Market doesn't exist |
| 0x1002 | E_MARKET_EXISTS | Market already exists |
| 0x1003 | E_INVALID_STATE | Wrong state for operation |
| 0x1004 | E_TRADING_NOT_STARTED | Trading hasn't begun |
| 0x1005 | E_TRADING_ENDED | Trading period over |
| 0x1006 | E_ALREADY_SNAPSHOTTED | Snapshot exists |
| 0x1007 | E_ALREADY_RESOLVED | Already resolved |
| 0x1008 | E_MARKET_NOT_RESOLVED | Not yet resolved |
| 0x100E | E_NOT_OWNER | Not order owner |
| 0x2004 | E_STALE_ORACLE | Oracle price too old |
| 0x2005 | E_INVALID_PRICE | Invalid oracle price |