Queueing
submit_order (isolated) or submit_cross drops a trader’s order into one
of a market’s 8 queue shards, 32 orders each, 256 in flight per market.
Before it queues, the margin it reserves is checked against the worst price
the next batch could realistically give it:
What one uncross call does
Clearing a market’s queue is one instruction, uncross. It can run at most
once per slot per market, enforced on-chain, and in practice a reference
crank only calls it when there’s something to do: orders are actually
queued, a liquidation heap looks crossed, or funding is due a sample. Each
call, in order:
- Fetches a fresh oracle price. A price no newer than the last one already used is rejected outright.
- Collects every maker’s mid that is still fresh. A stale mid just drops that maker out of this batch, see The Shared Book.
- Merges every included maker’s resting orders into one ladder and finds the real best bid, best ask, and a mark price: the midpoint of the two, valid only when the book is two-sided, uncrossed, inside the oracle band, and at least 10 lots deep on both sides. Otherwise there’s no mark this pass, and funding doesn’t accrue.
- Samples funding from that mark against the oracle, carrying the remainder forward so a quiet market still accrues the right amount over time.
- Steps the liquidation brake price toward the oracle by at most 1% per second, never further.
- Scans cross accounts, if this market allows cross margin: refreshes this market’s row in the shared cross price table, then checks the next 64 cross accounts in line and force-closes part of any that’s gone under maintenance, filled by this same batch.
- Liquidates, up to 8 positions per side per call: while this market’s long or short liquidation heap has a top position crossed by the braked price, it’s closed, partially if that alone restores health, in full only once equity is gone.
- Clears the batch auction, the actual matching step, described below.
- Rolls this market’s solvency numbers into the pool, and advances the batch counter.
The batch auction
For each side, asks against buy demand and bids against sell demand, the same idea runs:Getting paid
ADONE queued order still has to be settled, and that’s its own
permissionless step, claim. It releases any unused locked margin back to
the trader on an open, or on a close, pays profit out of the pool first,
then the market’s insurance fund if the pool alone falls short, and if even
that’s not enough, leaves the remainder as an IOU the trader can claim later
once the pool’s balance recovers. Every settled fill pays a 1 basis point
keeper fee to whoever called the uncross or claim that touched it, free
if a trader settles their own order.
A liquidated or partially liquidated position settles through
settle_liquidation instead: 4% of what was liquidated goes to whoever ran
the crank, 1% to the market’s insurance fund, and the rest back to the
trader’s free balance, with the market maker side absorbing the loss up to
the position’s margin. A self-liquidation sends the keeper’s cut to
insurance instead of to the trader’s own transaction.
Running the crank is not a privileged role. Anyone can run it, and anyone
who does earns these fees for doing so.
