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
GeodeHook.sol is the entire Geode protocol in a single contract (~1,260 lines). It implements the Uniswap v4 IHooks interface and IUnlockCallback, intercepting swaps via beforeSwap and providing batch settlement through geodeSettleBatch().
Hook flags: BEFORE_SWAP | BEFORE_SWAP_RETURNS_DELTA
Immutables
Constants
State Variables
External Entry Points
geodeSettleBatch()
The main settlement function. Permissionless — anyone can call it and earn rewards.
- Validate pool is configured and batch interval has elapsed
- Validate all intent bindings (
poolId, deadlines) - Record batch-open anchor
sqrtPriceX96for residual protection - Compute clearing price and determine fills (phase-aware: curve vs AMM)
- Update batch state, emit
GeodeIntentFilledevents - Call
poolManager.unlock()→ enters flash accounting context - Inside
unlockCallback():- Pull tokens from each user via Permit2
- Route residual through AMM (or curve in launch mode)
- Distribute outputs pro-rata to filled intents
- Pay settler (fees + gas reimbursement)
beforeSwap()
Hook callback intercepting every swap on configured pools.
- If
sender == address(this)(hook routing residual): no fee, pass through - If pool is in Active/PendingGraduation launch phase: revert (
LaunchNotGraduated) - Otherwise: charge
directSwapFeeBpson the swap amount- 50% →
protocolTreasuryviapoolManager.take() - 50% → per-pool surplus (held as ERC20 on hook)
- 50% →
take(unspecified, hook, feeAmount)→ negative hook deltaBeforeSwapDelta(0, +feeAmount)→ positive hook delta charged to swapper
geodeInitializePool()
One-time pool configuration. Curve pools (with deployer set) require the factory as caller.
registerLaunch()
Called by the factory to register launch curve state. Sets up LaunchState with virtual reserves and graduation threshold.
finalizeGraduation()
Permissionless. Called after PendingGraduation phase. Initializes the v4 pool at terminal curve price and seeds permanent full-range liquidity.
Internal Settlement Functions
_computeSettlement()
Phase-aware routing:
- Active launch →
ConstantProductCurveLib.computeLaunchSettlement() - PendingGraduation → revert (no trading)
- Standard / Graduated →
ClearingPriceLib.computeClearingPrice()
_routeAndDistribute()
Standard mode: routes residual through poolManager.swap() with anchor price protection, then distributes outputs.
_routeAndDistributeLaunchMode()
Launch mode: dispenses/absorbs tokens via bonding curve. Updates launchTokenReserve, launchEthReserve, and cumulativeSupplyDistributed. Checks graduation conditions after every batch.
_paySettler()
Pays the settler:
- Settlement fees from unrouted input deposits via
poolManager.take() - Gas reimbursement from surplus via
_fundSettlerFromSurplus()(capped atmaxGasReimbursement)
SettlerPaid with exact per-currency breakdown.
_distributeBuyOutputs() / _distributeSellOutputs()
Pro-rata distribution using each intent’s amountIn as weight. Remainder dust goes to the last filled intent.
View Functions
Events
| Event | When |
|---|---|
GeodeBatchSettled | Batch settlement completes |
GeodeIntentFilled | Each filled intent |
SettlerPaid | Settler receives payment (per-currency breakdown) |
GeodeDirectSwap | Direct swap fee charged |
GeodeProtocolFeeCollected | Protocol treasury receives fee share |
GeodePoolConfigured | Pool configured for batching |
GeodeLaunched | Launch token registered |
GraduationTriggered | Phase → PendingGraduation |
GeodeGraduated | Phase → Graduated, AMM seeded |
UnsoldTokensRetired | Unsold tokens sent to dead address |
GeodeDeployerRoyaltyPaid | Deployer royalty paid from surplus |
Source
GeodeHook.sol
View the full source code on GitHub (~1,260 lines).