Order Book#
Seesaw's on-chain matching engine pairs buyers and sellers of the same outcome: YES buyers with YES sellers, NO buyers with NO sellers.
Order Book Architecture#
The diagram shows the YES lane. The NO lane has the same shape, with every price quoted in NO's own price space.
Current markets use a tiered deep orderbook, with supported capacities from
64 to 4096 resting orders per side. Prices are in basis points of one stablecoin
unit: 10,000 bps = 1.00 USDT, and valid trading prices live in [1, 9999].
Two Outcome Lanes#
Seesaw keeps one order-book account per market. It has a bid arena and an ask arena, and each arena holds a YES lane and a NO lane. You send an outcome (YES or NO), an intent (BUY or SELL), and a price in that outcome's own price space. The program stores that price unchanged. Clients never convert a NO price to a YES price.
| Your Order | Stored side | Arena | Stored price | Custody at placement |
|---|---|---|---|---|
| Buy YES @ 0.55 | BuyYes 1 | Bid | 5500 (YES) | locks 0.55 USDT per share |
| Sell YES @ 0.60 | SellYes 2 | Ask | 6000 (YES) | escrows 1 YES share per share |
| Buy NO @ 0.45 | BuyNo 3 | Bid | 4500 (NO) | locks 0.45 USDT per share |
| Sell NO @ 0.40 | SellNo 4 | Ask | 4000 (NO) | escrows 1 NO share per share |
Matching stays inside one outcome: BuyYes meets SellYes, and BuyNo
meets SellNo. The YES and NO lanes never cross. A Buy NO @ 0.45 never fills
against a Sell YES, whatever the prices. The two lanes share the account's
capacity, but each lane has its own best bid, best ask, and price-time
priority.
Nothing in the program keeps a YES price and a NO price summing to 1.00. Pair
minting (MintShares) and complete-set merging keep the two linked in value,
so traders can arbitrage a gap between the lanes.
Escrow-Based: Fills Move Real Assets#
Every resting order is fully backed before it can rest:
- A bid (buy) locks its full collateral (
shares × price) in the market vault at placement. - An ask (sell) escrows the actual SPL share tokens in the market's YES or NO escrow PDA at placement.
A fill is therefore an escrow transfer, never a mint: shares move
from the maker's escrow to the taker, and stablecoin moves through the
vault to the seller. New shares come into existence only through
MintShares (pair-minting YES+NO 1:1 against stablecoin) and
WithdrawShares (materializing internal-ledger shares); shares are
also burned by MergeCompleteSet before resolution and by terminal cleanup.
MergeCompleteSet exchanges equal available YES and NO quantities for their complete-set collateral.
See complete sets
and Flow of Funds.
The *WithFreeFunds order variants (0x0E–0x10) place the same orders
against your internal trader-ledger balances — no wallet token transfer
per order, same matching rules.
Order Types#
| Type | Behavior |
|---|---|
| Limit | Match what crosses; rest the remainder on the book at your price |
| PostOnly | Maker only: reject a crossing order by default, or slide one tick when reject_post_only_would_cross = 0 |
| ImmediateOrCancel | Match what's possible now; cancel the remainder — taker only |
IOC protections#
IOC orders may additionally set:
worst_acceptable_price_bps— a hard slippage bound; the program will not fill past it.min_fill_quantity— reject the entire IOC instruction if total fills are below this size.match_limit— caps how many resting orders one instruction visits in one instruction (default and maximum 12); this counts fills, expired skips and self-trade hits. It is a compute-budget control, not the side capacity. Recognized layouts range from 64 through 4096 orders per side; new market activation currently stops at 2048 because of the trader-ledger seat ceiling.
Market-style orders: use IOC#
To "buy at market," submit an IOC order with a generous limit and a
worst_acceptable_price_bps you're comfortable with. Don't submit a
Limit order at an extreme price (e.g. 9900) — Limit and PostOnly orders
must pass the maker price band (±10% around the
midpoint of the order's own outcome lane when that lane is two-sided), so an
extreme resting price is rejected.
IOC orders are exempt from the band because they never rest.
Per-order TTL#
Resting orders may carry max_age_seconds > 0. Once expired, the order
is ignored by matching and becomes reclaimable by anyone via
ReclaimExpiredOrder (0x16) — the refund goes to the maker, and the
caller may take a bounty of 10 bps of the refund (capped at 0.1
stablecoin). The TTL may not outlive the market (expiry ≤ t_end).
Price-Time Priority#
Orders match on price first, then arrival order (FIFO):
Same-price ties break by the order's monotonic order_id (allocation
order), not by timestamp.
Matching Algorithm#
Fills execute at the maker's resting price — price improvement goes to the taker:
incoming = Sell 100 YES @ 0.55 (Limit)
while incoming.quantity > 0:
best_bid = book.best_bid()
if best_bid is None or best_bid.price < incoming.price:
break # nothing crosses
fill_qty = min(incoming.quantity, best_bid.quantity)
execute_fill(price = best_bid.price, quantity = fill_qty)
# maker's escrowed/locked assets move; taker pays the fee
incoming.quantity -= fill_qty
if incoming.quantity > 0:
book.rest_ask(incoming) # Limit only; IOC cancels instead
Tick Size#
Prices must align to the market's tick:
| Parameter | Value |
|---|---|
| Default | 100 bps (0.01 USDT) |
| Range | 1–1000 bps, must divide 10,000 evenly |
| Tunable | UpdateTickSize (0x24, admin) |
Tick Rounding Rules#
- Bids round DOWN to the nearest tick
- Asks round UP to the nearest tick
Both directions are conservative for the order's owner and the book:
Submitted: Buy @ 0.5567, tick 0.01 → Buy @ 0.55 (down)
Submitted: Sell @ 0.5567, tick 0.01 → Sell @ 0.56 (up)
An ask that would round to ≥ 10,000 bps is rejected (there is no valid price at or above 1.00).
Resting-Order Quality Gates#
Two placement-time gates keep the book clean:
- Maker price band — Limit/PostOnly orders must price within ±10% of their own outcome lane's midpoint when that lane is two-sided (static 1%–99% band otherwise). IOC is exempt.
- Minimum resting notional — a remainder too small to be worth
matching is rejected rather than allowed to rest
(
UpdateMinRestingNotional, 0x25).
No Crossed Book Invariant#
Within each outcome lane, the book cannot have best bid ≥ best ask. A YES bid and a NO ask are in different lanes, so their prices are never compared:
If a new order would cross, it immediately executes against resting orders until uncrossed or fully filled.
No Naked Shorts#
You can only sell shares you own (in your wallet or your internal ledger balance):
Alice owns: 50 YES shares
✓ Sell 50 YES @ 0.60 (valid — 50 shares escrowed)
✗ Sell 100 YES @ 0.60 (rejected — insufficient shares)
To bet against YES without owning it:
- Buy NO shares, OR
- Mint a YES+NO pair (
MintShares) and sell the YES
Order Lifecycle#
| State | Meaning |
|---|---|
| Resting | On book, fully backed, awaiting match |
| Partially Filled | Some quantity executed; remainder rests or cancels |
| Fully Filled | Complete execution |
| Cancelled | Owner cancelled; collateral/escrow returned instantly |
| Expired | TTL elapsed; never matched. The next order that touches it (or anyone calling ReclaimExpiredOrder) removes it and returns the maker's backing to the maker's trader-ledger balance or wallet |
Reading the Order Book#
Depth Chart#
Price Bid Size Ask Size Cumulative
─────────────────────────────────────────────
0.65 200 650
0.60 300 450
0.58 150 150
────────── spread ──────────
0.55 100 100
0.54 250 350
0.52 500 850
Key Metrics#
| Metric | Formula | Meaning |
|---|---|---|
| Spread | Best Ask − Best Bid | Cost to cross |
| Mid Price | ⌊(Best Bid + Best Ask)/2⌋ | Fair value estimate |
| Depth | Sum of sizes at level | Liquidity available |
| Imbalance | Bid Vol / Ask Vol | Directional pressure |
For how the app turns book depth into a fill preview (average price, slippage, price impact), see Slippage & Fill Estimation.
Order Book Events#
Every book mutation is recorded on-chain through the program's binary
event recorder (the internal LOG self-CPI), so indexers and UIs can
reconstruct the book deterministically. The order-flow event kinds:
| Event | Emitted when |
|---|---|
OrderPlaced | An order (or its remainder) rests on the book |
OrderFilled / OrderFilledMaker | A fill executes (taker and maker legs) |
OrderCancelled | Owner cancels a resting order |
OrderReclaimed | A TTL-expired order is reclaimed |
OrderEvicted | A resting order is evicted by a better-priced one on a full side |
OrderForceCancelled | Admin emergency cancel (ForceCancelMarketOrders) |
How-to guides#
For task-oriented guidance on using this order book:
- Market makers (quoting both sides, PostOnly, spread capture, inventory management): Market Making
- Takers (fill preview, IOC slippage protection, splitting large orders, fee curve): Placing Orders