Launch app

Docs / Protocol

Settlement

settle(batch, market) can be called by anyone once the batch's reveal window has closed, and succeeds once per batch and market.

Void or cross

The contract reads the midpoint now and averages the batch's price samples. The batch is voided if any of these is true:

  • the book is empty;
  • more than 26 blocks have passed since the reveal window closed;
  • fewer than 2 price samples were recorded;
  • the midpoint is further from the sample average than the market's price guard.

A void returns every order to its trader in full. No fee is charged.

Crossing

Otherwise, with mid the midpoint in USDG per share:

buys    = Σ usable(o)          over buy orders with mid ≤ limit
sells   = Σ o.amount × mid     over sell orders with mid ≥ limit
matched = min(buys, sells)     in USDG
  • Orders whose limit is not met take no part and are returned whole.
  • The lighter side fills in full.
  • The heavier side fills pro rata: each order gets matched / side total of its size.

A buyer pays usable × matched / buys USDG plus the fee on that, and receives shares worth it at mid. A seller gives amount × matched / sells shares and receives their value at mid, minus the fee. Everything not used is returned to the trader's free balance in the same call.

One price

Every fill in a batch uses the same mid. There is no price impact between crossed orders: a buyer of 10 shares and a buyer of 10,000 get the same price, and the fill never goes beyond either side's limit.

Gas

Settlement touches every order in the book twice. The book is capped at 96 orders per market per batch to keep one call well inside the block gas limit.