Order Book Design#
Seesaw matches trades through a fully on-chain order book. Two design choices define how it works: every market keeps two outcome lanes, YES and NO, in one book, and that book lives in a single fixed-size account on Solana.
Two outcome lanes in one book#
A binary market has two outcomes. Seesaw gives each outcome its own price-time lane, and stores both lanes in one account. The account has a bid arena and an ask arena, and each arena hosts a YES lane and a NO lane.
Clients send an outcome (YES or NO), an intent (BUY or SELL), and a price in
that outcome's own price space. The program derives one of four stored
custody sides and stores the price unchanged:
| You place | At price | Stored side | Arena | Stored price | Custody at placement |
|---|---|---|---|---|---|
| Buy YES | 6000 YES | BuyYes 1 | Bid | 6000 | locks 0.60 USDT per share |
| Sell YES | 6000 YES | SellYes 2 | Ask | 6000 | escrows 1 YES per share |
| Buy NO | 4000 NO | BuyNo 3 | Bid | 4000 | locks 0.40 USDT per share |
| Sell NO | 4000 NO | SellNo 4 | Ask | 4000 | escrows 1 NO per share |
Within each lane, the standard order-book invariant holds: the best bid is always below the best ask when both exist. Prices in different lanes are never compared.
Same-outcome matching only#
The book enforces same-outcome matching: BuyYes orders match only against
SellYes orders, and BuyNo orders match only against SellNo orders. The
YES and NO lanes never cross. A Buy NO @ 4000 does not fill against a Sell YES
@ 6000, even though the two positions are economically related.
Every fill is therefore an escrow transfer inside one outcome: the buyer's locked stablecoin pays the seller, and the seller's escrowed shares go to the buyer. New YES/NO pairs are created only by pair minting, never by matching.
Why this matters#
- Prices mean what they say. A NO order at 4000 locks, fills, pays fees,
and refunds at 4000. Tick rounding, the maker price band, and
CancelUpTotick limits all work in the order's own outcome price space. - Shared capacity. Both lanes share the account's capacity, free lists, and eviction, so a market needs only one order-book account.
- Simple, deterministic matching. A taker walks exactly one maker lane, derived once from its stored side.
The trade-off is that nothing forces the best YES price and the best NO price to sum to 1.00. Pair minting (1 USDT → 1 YES + 1 NO) and complete-set merging link the two in value, so traders can arbitrage any gap.
Stored in a single account#
The entire book for a market lives in one deep-orderbook account (the
orderbook PDA, derived at ["seesaw", "orderbook", market_pubkey]). Every
market uses the one canonical capacity of 4,096 orders per side; there is no
tier table. The account stores both sides as fixed-capacity red/black trees
plus parallel order records.
DeepOrderbookAccount (192 + 336 * capacity bytes)
├── Header (128 bytes) discriminator, market, bump, capacity, next order id, counts
├── Bid side (32 bytes + capacity nodes + capacity orders)
└── Ask side (32 bytes + capacity nodes + capacity orders)
Each order is a 136-byte record holding its id, owner, remaining and original
quantity, timestamp, price, side, active flag, status, optional time-to-live,
a 16-byte optional client_order_id, the trading generation, and its owner-list,
client-ID tree and strategy links. The generated field map and every
tier's exact account size are in Protocol facts.
Matching walks the opposing tree by price-time priority — best price first, then earliest order id:
Place a bid @ 6500:
1. Scan asks from lowest price upward.
2. While the best ask ≤ 6500, fill at the ask price.
3. Stop when no ask is matchable or the order is fully filled.
4. Rest any remainder in the bid tree at its price-time key.
Asks match symmetrically against the bids.
Why a single account#
Solana requires every account a transaction touches to be declared upfront, and caps each instruction at a fixed compute budget. A single self-contained book fits those constraints cleanly:
- One account to read and write. Matching needs no cross-account calls, and a transaction only declares the orderbook, market, position, and vault.
- Predictable, bounded compute. Matching walks a bounded configured capacity per side through price-time red/black trees. Insert and remove operations do rebalance the in-account tree, but the selected tier caps the work and account size for every market.
- Fixed, reclaimable rent. The account is always the same size regardless of how many orders rest in it, and the rent is returned when the market closes.
- Zero-copy access. The book is read directly from account bytes with no deserialization step, which keeps reads cheap for both the program and off-chain consumers.
The deliberate cost is rent and compute scale: deeper books require larger orderbook accounts and more bounded matching work. Markets choose one symmetric capacity tier at creation, from 64 to 4096 resting orders per side. Once a side reaches its tier capacity, new resting orders on that side are rejected until orders fill, cancel, or expire. Post-only and immediate-or-cancel order types help keep the resting count intentional.
Alternatives we did not take#
- Two separate order-book accounts (one each for YES and NO) would double rent and account access for the same lane-local matching.
- One YES-only book with NO orders mirrored to
10000 − pmade every NO order move cash at the complement of its own price. It was replaced by outcome-space storage. - A signed single share (positive = YES, negative = NO) makes balances and solvency harder to reason about.
- An AMM trades worse for large orders on binary outcomes, exposes liquidity providers to loss, and is easier to manipulate than an order book.
- A tree- or slab-based book across many accounts would add capacity through additional account access, unpredictable rent, and significantly more complexity. Seesaw uses a single-account RBT instead, preserving deep books while keeping every transaction's account set explicit.
- An off-chain matcher would reintroduce a trusted intermediary and censorship/front-running risk, which contradicts Seesaw's permissionless design.
For the user-facing walkthrough of placing and matching orders, see How It Works → Order Book. For fill estimation and price impact, see How It Works → Slippage. For where collateral lives at each step, see How It Works → Flow of Funds.