Ethereum & L2s
A decaying surge fee for Uniswap v4
The pure fee curve that makes arbitrageurs pay LPs for stale prices.
Overview
Parallax's hook charges the base fee unless a swap moves the pool toward a fresher reference price from another chain. Then the fee rises with the gap and decays by half every half-life, interpolated linearly between halvings, capped at a maximum.
The code
contracts/src/hook/libraries/LibShield.solView on GitHub ↗
function computeFee(Config memory c, int24 refTick, int24 poolCanonicalTick, bool moveUp, uint256 elapsedMs)
internal pure returns (Quote memory q)
{
q.fee = c.baseFee;
q.gapTicks = refTick - poolCanonicalTick;
q.toward = (q.gapTicks > 0 && moveUp) || (q.gapTicks < 0 && !moveUp);
q.decay = decayFactor(elapsedMs, c.halfLifeMs);
if (c.paused || !q.toward) return q;
uint256 absGap = uint256(q.gapTicks > 0 ? int256(q.gapTicks) : -int256(q.gapTicks));
if (absGap <= c.deadbandTicks) return q;
uint256 surge = (absGap * PIPS_PER_TICK * c.captureBps / 10_000) * q.decay / ONE;
uint256 fee = uint256(c.baseFee) + surge;
q.fee = fee > c.maxFee ? c.maxFee : uint24(fee);
}
// decayFactor: halvings, then linear between two halvings
// uint256 halvings = elapsedMs / halfLifeMs;
// if (halvings >= 60) return 0;
// return whole - (whole * rem) / (2 * halfLifeMs);
How it works
- Direction-aware: only the arbitrage leg pays the surge
- A deadband ignores small gaps; a pause switch falls back to the base fee
- Fixed-point decay with an early exit after 60 halvings
- Pure and side-effect free, so the site previews the same numbers the hook charges