Index / VolatilityFee
pattern · MIT · last updated 2026-08-27
VolatilityFee
LP fee rises with |currentTick − lastTick| since the previous swap.
First-party teaching hook inspired by Clanker-style tick-accumulator dynamic fees. Stores lastTick per pool; beforeSwap reads current tick from StateLibrary and adds tickFactor × |Δtick| to baseFee, capped at maxFee. afterSwap updates lastTick. Contrast surge-fee.yml (size vs liquidity) and volatility-oracle.yml (time ramp). Requires dynamic fee pool. Experimental. Forge tests in test/VolatilityFee.t.sol. Listing is not an audit.
Permission bits
These bits must match the deployed address. Confirm on-chain before you route.
afterInitializebeforeSwapafterSwap
Solidity
Excerpt from contracts/VolatilityFee.sol. Copy the full file to implement this. Not an audit.
// SPDX-License-Identifier: MIT
function feeFor(PoolKey calldata key) public view returns (uint24) {
(, int24 tick,,) = poolManager.getSlot0(key.toId());
uint256 move = _absTickDelta(tick, lastTick[key.toId()]);
uint256 total = uint256(baseFee) + move * uint256(tickFactor);
if (total > maxFee) return maxFee;
return uint24(total);
}Spec
| Kind | pattern |
|---|---|
| Status | experimental |
| License | MIT |
| Source | https://github.com/CryptoGnome/v4hooks |
| Categories | Dynamic fees |
| Properties | Dynamic feeVanilla swap |
| Chains | Base |
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.