Protocol
Clearing
Revealed orders become two histograms over 64 rate ticks. Clearing picks the rate that matches the most USDC, in one instruction.
Ticks#
Rates live on a grid of 64 ticks. Tick k is k × 0.25%, so the grid runs from 0.00% at tick 0 to 15.75% at tick 63. Every order names one tick.
Histograms#
A reveal adds the order's size to one bucket: offers[tick] for a lender, bids[tick] for a borrower. The auction never keeps a list of orders, only these two arrays of 64 numbers.
For any tick t:
- supply is the sum of offers at or below
t, the USDC lenders would lend at that rate, - demand is the sum of bids at or above
t, the USDC borrowers would take at that rate, - matched is the smaller of the two.
Choosing the rate#
Clearing evaluates all 64 ticks and picks the one with the largest matched volume. If several ticks match the same volume, the lowest of them wins. The instruction reads 64 buckets on each side and never loops over orders, so it costs the same for ten orders or ten thousand.
Clearing is permissionless and allowed once the reveal window has ended. The keeper sends it right away.
Who fills#
On each side, orders at better ticks fill first: lenders from the lowest rate up, borrowers from the highest rate down. Each side has a marginal tick where only part of the volume fits. Orders at better ticks fill completely, orders at the marginal tick fill pro rata, and orders at worse ticks don't fill. The two sides' marginal ticks can differ from each other and from the clearing tick; they only decide who fills. Everyone who fills gets the clearing rate.
The marginal tick#
Within the marginal tick, each order received a prefix p when it was revealed: the volume revealed at that tick before it. For an order of size s at a tick holding T, with Q selected there:
fill = floor((p + s) × Q / T) − floor(p × Q / T)The fills add up to exactly Q, so lenders and borrowers always allocate the same total. An order's fill can differ from its exact share by at most one millionth of a USDC, and reveal order decides which order gets that atom.
Limits#
Each side's revealed total is capped at half of u64::MAX in USDC atoms, about 9.2 trillion USDC. A reveal that would exceed it is rejected and leaves the histogram unchanged.