Index / SurgeFee
pattern · MIT · last updated 2026-08-27
SurgeFee
LP fee scales with swap size vs pool liquidity — no simulate-and-revert.
First-party teaching hook inspired by Spark Surge Fees. Contrast with slippage-fee.yml: that hook simulates the swap and reverts with the post-trade tick to price the fee; SurgeFee reads pool liquidity from StateLibrary and adds surgeFactor * (tradeSize / liquidity) to baseFee in beforeSwap, capped at maxFee. No try/catch simulation — cheaper gas, coarser signal (size vs liquidity, not tick walk). Inherits OpenZeppelin BaseOverrideFee. Requires dynamic fee pool. Experimental. Forge tests in test/SurgeFee.t.sol. Listing is not an audit.
Permission bits
These bits must match the deployed address. Confirm on-chain before you route.
afterInitializebeforeSwap
Solidity
Excerpt from contracts/SurgeFee.sol. Copy the full file to implement this. Not an audit.
// SPDX-License-Identifier: MIT
// v4hooks first-party — excerpt. Full file: source.url
function feeFor(PoolKey calldata key, SwapParams calldata params) public view returns (uint24) {
uint128 liquidity = poolManager.getLiquidity(key.toId());
if (liquidity == 0) return baseFee;
uint256 tradeSize = params.amountSpecified < 0
? uint256(-params.amountSpecified)
: uint256(params.amountSpecified);
uint256 surge = (tradeSize * uint256(surgeFactor)) / uint256(liquidity);
uint256 total = uint256(baseFee) + surge;
if (total > maxFee) return maxFee;
return uint24(total);
}
function _getFee(address, PoolKey calldata key, SwapParams calldata params, bytes calldata)
internal
view
override
returns (uint24)
{
return feeFor(key, params);
}Spec
| Kind | pattern |
|---|---|
| Status | experimental |
| License | MIT |
| Source | https://github.com/CryptoGnome/v4hooks |
| Categories | Dynamic feesLaunchpads |
| Properties | Dynamic feeVanilla swap |
| Chains | Ethereum |
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.