V4HOOKSCUT SHEET DIRECTORY

Index / Median oracle

pattern · MIT · last updated 2026-08-27

Median oracle

Ring buffer of post-swap ticks with onchain medianTick view.

First-party rewrite inspired by saucepoint median-oracles (MIT). afterSwap pushes floored tick into a 16-sample ring per pool. medianTick sorts the active window on read — teaching cut of a manipulation-resistant oracle vs TWAP geomean examples. Experimental. Listing is not an audit.

Permission bits

These bits must match the deployed address. Confirm on-chain before you route.

Initialize
ba
Liquidity
baba
Swap
ba
Donate
ba
Return delta
baaa

afterSwap

Solidity

Excerpt from contracts/MedianOracle.sol. Copy the full file to implement this. Not an audit.

function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
    return Hooks.Permissions({
        beforeInitialize: false,
        afterInitialize: false,
        beforeAddLiquidity: false,
        afterAddLiquidity: false,
        beforeRemoveLiquidity: false,
        afterRemoveLiquidity: false,
        beforeSwap: false,
        afterSwap: true,
        beforeDonate: false,
        afterDonate: false,
        beforeSwapReturnDelta: false,
        afterSwapReturnDelta: false,
        afterAddLiquidityReturnDelta: false,
        afterRemoveLiquidityReturnDelta: false
    });
}

Spec

Kindpattern
Statusexperimental
LicenseMIT
Sourcehttps://github.com/CryptoGnome/v4hooks
CategoriesOracles
PropertiesVanilla swap
ChainsEthereum
Docshttps://github.com/saucepoint/median-oracles

FAQ

Can I paste this into production? The snippet is an excerpt. Use the full file at the source URL, match flags to the address, and treat this page as a map, not a guarantee.

How do I build this safely? Start with secure v4 hooks and the OpenZeppelin hooks guide.