Skip to main content

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

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 launch-mode settlement: computing the clearing price from the curve, determining fills, and calculating how many tokens to dispense or absorb.

Curve Formula

(Vt - S) × (Ve + E) = K = Vt × Ve
VariableMeaning
VtVirtual token reserve (immutable, ≥ totalSupply)
VeVirtual ETH reserve (immutable)
SCumulative tokens distributed
ECumulative real ETH raised
KInvariant constant

Core Functions

computeLaunchSettlement()

Main entry point for launch-mode batch settlement. Replaces ClearingPriceLib.computeClearingPrice() during the Active phase.
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:
  1. Computes the current curve price as the clearing price
  2. Determines which intents fill at that price
  3. Deducts settlement fees from inputs
  4. Computes internal match amounts
  5. Calculates curveDispensed (net buy residual → tokens from hook) and curveAbsorbed (net sell residual → tokens back to hook)
  6. 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

ActionSEPrice
Buy↑ increases↑ increases↑ rises
Sell↓ decreases↓ decreases↓ falls
Nothingunchangedunchangedunchanged
The curve is fully reversible — tokens can be bought and sold at any time during the Active phase.
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).