Documentation Index
Fetch the complete documentation index at: https://docs.geode.ag/llms.txt
Use this file to discover all available pages before exploring further.
Overview
ClearingPriceLib is a pure Solidity library that computes the uniform clearing price, determines which intents fill, calculates internal match amounts, and computes the residual to route through the AMM.
This library is used for standard mode and post-graduation pools. Launch-mode pools use ConstantProductCurveLib instead.
Core Function
computeClearingPrice()
buys— Buy intents, sorted by implicit limit price descending (most generous first)sells— Sell intents, sorted by implicit limit price ascending (cheapest first)maxBatchSize— Maximum allowed intents per sideammSpotPriceQ128— Current AMM spot price in Q128 fixed-pointsettlementFeeBps— Fee charged on each filled intent’s input (in basis points)
SettlementResult with exact deposit-denominated quantities, plus boolean fill arrays.
Algorithm
Verify Sort Order
Buy intents must be sorted by descending limit price. Sell intents must be sorted by ascending limit price. Reverts with
BuysNotSorted() or SellsNotSorted() if violated.Sort verification uses cross-multiplication to avoid division:Determine Fills
For each intent, compute its implicit limit price and compare against the clearing price:Intents that don’t meet the clearing price are skipped — their tokens are never pulled.
Key Properties
Pure Function
No state reads or writes. The entire computation is deterministic from its inputs.
Deposit-Denominated
All output quantities are in exact deposit units. No predictions about AMM output — the hook captures actual swap deltas at execution time.
Input-Side Fees
Fees are carved from gross input before matching. Net input drives all routing decisions.
Settler Competition
A malicious settler can omit intents to manipulate the clearing price. The mitigation is competition — any settler can submit a more complete batch. First valid settlement wins.
Source
ClearingPriceLib.sol
View the full source code on GitHub (~143 lines).