Index / Volatility oracle
pattern · UNLICENSED · last updated 2026-08-27
Volatility oracle
Require a dynamic fee on initialize, then ramp LP fee by elapsed time after deploy.
Uniswap’s VolatilityOracle example is a teaching dynamic-fee hook, not a live volatility feed. beforeInitialize requires key.fee.isDynamicFee(). afterInitialize calls setFee, which starts at 3000 and adds 100 bps per elapsed minute via poolManager.updateDynamicLPFee. UNLICENSED example-contracts file. Use it to learn the initialize-plus-poke pattern; do not treat the contract name as an oracle. Copy the full file from the permalink. Listing is not an audit.
Permission bits
These bits must match the deployed address. Confirm on-chain before you route.
beforeInitializeafterInitialize
Solidity
Excerpt from contracts/hooks/examples/VolatilityOracle.sol. Copy the full file to implement this. Not an audit.
// SPDX-License-Identifier: UNLICENSED
function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
return Hooks.Permissions({
beforeInitialize: true,
afterInitialize: true,
beforeAddLiquidity: false,
beforeRemoveLiquidity: false,
afterAddLiquidity: false,
afterRemoveLiquidity: false,
beforeSwap: false,
afterSwap: false,
beforeDonate: false,
afterDonate: false,
beforeSwapReturnDelta: false,
afterSwapReturnDelta: false,
afterAddLiquidityReturnDelta: false,
afterRemoveLiquidityReturnDelta: false
});
}
function beforeInitialize(address, PoolKey calldata key, uint160, bytes calldata)
external
pure
override
returns (bytes4)
{
if (!key.fee.isDynamicFee()) revert MustUseDynamicFee();
return VolatilityOracle.beforeInitialize.selector;
}
function setFee(PoolKey calldata key) public {
uint24 startingFee = 3000;
uint32 lapsed = _blockTimestamp() - deployTimestamp;
uint24 fee = startingFee + (uint24(lapsed) * 100) / 60; // 100 bps a minute
manager.updateDynamicLPFee(key, fee); // initial fee 0.30%
}Spec
| Kind | pattern |
|---|---|
| Status | experimental |
| License | UNLICENSED |
| Source | https://github.com/Uniswap/v4-periphery |
| Categories | Dynamic fees |
| Properties | Dynamic feeVanilla swap |
| Chains | Ethereum |
| Docs | https://docs.uniswap.org/contracts/v4/concepts/hooks |
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.