The relative-bin model

A market consists of twenty inventory accounts indexed relative to a common reference price. The oracle sets their prices. The assets in each account determine executable depth.

On this page

Price coordinates

Let P denote quote atoms per whole base token, S base atoms per whole base token, and i the zero-based contract index. In the hosted market, one WHYPE contains 1018 base atoms and one tUSDC contains 106 quote atoms. A reference of 100 tUSDC per WHYPE therefore enters the contract as 100000000.

pi = ⌊P · (181 + 2i) / 200⌋,   i ∈ {0, …, 19}

ObeliskMath.midpoint spaces the unrounded levels arithmetically by P/100. Bin 9 quotes 0.995P, bin 10 quotes 1.005P, and the reference falls between them. The API reports a signed step s = i − 10, so step zero denotes bin 10. Integer flooring can collapse adjacent levels onto the same quote atom when the reference is small.

Twenty oracle-relative bin midpointsTen quote-funded indices lie below the reference and ten base-funded indices above it. The center line falls between bins nine and ten. QUOTE DEPOSITS BASE DEPOSITS i = 0i = 19 0.905 PP1.095 P
The outlined cell is bin 10, the initial active bin. Each block denotes a price level. Block height carries no quantity information.

Inventory and the active bin

Each bin stores three integers (base, quote, shares). A trader buying base consumes the bin’s WHYPE and replenishes it with tUSDC. A trader selling base consumes tUSDC and replenishes it with WHYPE. A bin that began with a single asset can consequently hold both assets after its first fill.

The active index a records the last bin touched by a successful swap and initializes to 10. A buy visits a, a + 1, …, 19. A sell visits a, a − 1, …, 0. Both walks begin at the same index, so a partially consumed bin with both reserves may serve the next order in either direction. A bin without the requested output asset contributes zero to that walk.

The initial funding rule is independent of the active index. Deposits into indices 0–9 supply quote. Deposits into 10–19 supply base. The rule continues to apply after trades have moved the cursor across the center.

Repricing without reserve transfers

Suppose the reference advances from 100 to 105 tUSDC/WHYPE. The price of bin 10 advances from 100.500000 to 105.525000. Its inventory, share supply and index survive the update intact. Even with the same trade size and identical reserve balances, the next swap faces a different exchange rate.

At a fixed reference, a fill has a constant marginal conversion rate inside one bin, up to fees and atom rounding. Size-dependent price impact enters when a trade crosses into another index. Across observations there is a second source of execution variance because the whole price grid moves with the reference. Holding the reference fixed isolates the cost of crossing a bin boundary. Work through an exact-input order →