Overview
ConstantProductCurveLib implements the Geocurve bonding curve math. It uses a virtual constant-product formula — the same x × y = k as Uniswap, but with virtual reserves that anchor the starting price.
This library handles all curve-mode settlement: computing the clearing price from the curve, determining fills, and calculating how many tokens to dispense or absorb.
(Vt - S) × (Ve + E) = K = Vt × Ve
Variable Meaning Vt Virtual token reserve (immutable, ≥ totalSupply) Ve Virtual ETH reserve (immutable) S Cumulative tokens distributed E Cumulative real ETH raised K Invariant constant
Core Functions
computeLaunchSettlement()
Main entry point for curve-mode batch settlement. Replaces ClearingPriceLib.computeClearingPrice() for curve pools.
function computeLaunchSettlement (
GeodeIntent [] memory buys ,
GeodeIntent [] memory sells ,
uint256 maxBatchSize ,
LaunchState memory ls ,
uint256 settlementFeeBps ,
uint256 deployerRoyaltyBps
) internal pure returns (
SettlementResult memory result ,
bool [] memory buyFills ,
bool [] memory sellFills
)
Behavior :
Computes the current curve price as the clearing price
Determines which intents fill at that price
Deducts settlement fees from inputs
Computes internal match amounts
Calculates curveDispensed (net buy residual → tokens from hook) and curveAbsorbed (net sell residual → tokens back to hook)
Computes deployer royalty
curvePrice()
Returns the current marginal price on the curve:
function curvePrice (
uint256 Vt , uint256 Ve ,
uint256 cumulativeDistributed , uint256 ethReserve
) internal pure returns ( uint256 priceX18 )
price = (Ve + E) / (Vt - S)
ethCostToBuy()
How much ETH to buy deltaTokens from the current state:
function ethCostToBuy (
uint256 Vt , uint256 Ve ,
uint256 cumulativeDistributed , uint256 ethReserve ,
uint256 deltaTokens
) internal pure returns ( uint256 ethIn )
ethIn = K / (Vt - S - Δs) - (Ve + E)
tokensForEth()
How many tokens for spending ethIn ETH:
function tokensForEth (
uint256 Vt , uint256 Ve ,
uint256 cumulativeDistributed , uint256 ethReserve ,
uint256 ethIn
) internal pure returns ( uint256 deltaTokens )
Δs = (Vt - S) - K / (Ve + E + ethIn)
ethReturnOnSell()
How much ETH returned for selling deltaTokens:
function ethReturnOnSell (
uint256 Vt , uint256 Ve ,
uint256 cumulativeDistributed , uint256 ethReserve ,
uint256 deltaTokens
) internal pure returns ( uint256 ethOut )
ethOut = (Ve + E) - K / (Vt - S + Δs)
Price Behavior
Action S E Price Buy ↑ increases ↑ increases ↑ rises Sell ↓ decreases ↓ decreases ↓ falls Nothing unchanged unchanged unchanged
The curve is fully reversible — tokens can be bought and sold at any time. The curve is permanent; there is no graduation or migration.
Asymptotic pricing : When Vt = totalSupply, the price approaches infinity as 100% of tokens are distributed. When Vt > totalSupply, the curve has a finite maximum price at full distribution.
Source
ConstantProductCurveLib.sol View the full source code on GitHub (~269 lines).