CLAP Oracle Formula
Concentrated-Liquidity with Asymmetric Pricing (CLAP) extends the CLCP pricing model with a two-phase swap mechanism. Trades that rebalance the pool toward equal value execute at the flat oracle price, while the remainder follows the concentrated-liquidity curve. This document traces the complete formula path from inputs to final quote output for off-chain integration.
How CLAP Differs from CLCP
Improving trades (rebalancing toward 50/50)
Execute on the curve (mid-price discount)
Execute at flat oracle price P (no discount)
Worsening trades
Execute on the curve
Execute on the curve (identical)
LP impact
Pool gives away value on rebalancing trades
Pool captures full fee on rebalancing trades
CLAP is strictly better for LPs when trades rebalance the pool, because the flat-price phase produces fewer output tokens than the curve would.
Inputs
reserveX
Pool
Current reserve of token X
Token decimals
reserveY
Pool
Current reserve of token Y
Token decimals
price (P)
Oracle data
Price of X in terms of Y
1e24 precision
alpha
Oracle data
Concentration factor defining range [P/alpha, Palpha]
BPS (10000 = 1.0)
feeHbps
Oracle data
Trading fee
Hundred basis points (1e6 = 100%)
amountInWithFee
Caller
Gross input amount (fee included)
Token decimals
swapXtoY
Caller
Swap direction
Boolean
All intermediate math uses 1e24 precision (the PRECISION constant). Alpha is expressed in basis points where 10000 = 1.0, so alpha = 10100 means a 1.01x concentration factor.
The Quote Formula
The getQuote function computes the swap output in two phases: a stable phase at the flat oracle price, followed by a curve phase on the concentrated-liquidity xy=k curve.
Step 2 — Stable Phase (Flat Oracle Price)
The improving portion of a trade — the part that moves reserves toward 50/50 value — executes at the flat oracle price P. This phase only fires when the trade reduces the pool's imbalance.
Imbalance check. Compare the value of each reserve side:
X → Y
scaledPrx < scaledRy (pool is Y-heavy)
targetX = (scaledRy - scaledPrx) / (2 * P)
Y → X
scaledPrx > scaledRy (pool is X-heavy)
targetY = (scaledPrx - scaledRy) / (2 * 1e24)
If the condition is not met, the trade is worsening from the start — skip directly to Step 3 with stableIn = 0 and stableOut = 0.
Stable execution. Consume at most enough input to reach balance:
Output at flat price:
X → Y
floor(stableIn * P / 1e24)
Y → X
floor(stableIn * 1e24 / P)
Update working reserves for the curve phase:
Reduce remaining input:
Step 3 — Curve Phase (Concentrated Liquidity)
The remaining input swaps on the concentrated xy=k curve defined by virtual reserves. This is the same CLCP formula used in the standard oracle.
Computing Liquidity L
Solve the concentrated-liquidity invariant for L using the updated reserves (reserveX', reserveY'):
Compute the square root of alpha * P:
Then:
Computing Virtual Reserves
X → Y
reserveX' + ceil(L * 1e24 / sqrtAlphaP)
reserveY' + floor(L * sqrtAlphaP * 10000 / (alpha * 1e24))
reserveY'
Y → X
reserveY' + ceil(L * ceilSqrtAlphaP * 10000 / (alpha * 1e24))
reserveX' + floor(L * 1e24 / ceilSqrtAlphaP)
reserveX'
Virtual reserves are rounded to favor the protocol: virtualIn rounds up, virtualOut rounds down.
Constant-Product Output
Apply the standard constant-product formula on the virtual reserves:
Reserve Cap
If cpAmountOut > reserveOut, the pool cannot deliver the full curve output. The input is capped and fees are recalculated:
Otherwise (normal case — entire input consumed):
Bid/Ask Spread
The getCurrentPrice function returns a bid/ask pair rather than a single price. It computes the curve-implied price from the current reserves and pairs it with the oracle price.
Curve-implied price:
Bid/Ask assignment:
The oracle price is always one of the two bounds; the other is the curve-derived price from the current reserve ratio.
Solidity Entry Points
The oracle key is derived from the token pair:
Order matters! tokenX must come first when computing the key.