The gap fee
How the hook prices one swap, step by step, with the exact numbers in the contract.
The rule
In beforeSwap the hook reads the pool's sqrtPriceX96 and the channel's reference sqrtRefX96, and computes r = (sqrtP / sqrtRef)² and the gap g = |r − 1|.
- Toward the reference and
g ≥ 0.10%:F = min(3%, max(0.05%, 0.8 · g)). - Any other swap:
F = 0.05%. - Reference older than 120 s, gap above 10%, or a channel that reverts or runs out of gas:
F = 0.30%both ways.
Direction
Price is quote per HYPE. Selling HYPE (zeroForOne) lowers it. A swap is toward the reference when it sells HYPE while the pool is above the reference, or buys HYPE while the pool is below it.
LP part and hook part
The hook returns the LP part as the pool's fee for that swap: 0.05% + 0.8 · (F − 0.05%). In afterSwap it takes the remaining 0.2 · (F − 0.05%) of the unspecified amount to the fee router and emits GapFee(poolId, g, F, toward, lpAmount, hookAmount).
The example from launch planning: HYPE +0.62% on HyperCore, the first arb buys about 102 HYPE and pays 0.49%. LPs get 0.402%, or 0.41 HYPE. A plain 0.30% pool would have kept 0.31 HYPE.
Why nobody overpays
A toward swap starts from a price better than the reference by the whole gap and pays at most 0.8 of it, so its all-in price stays on its side of the reference. The fuzz test testFuzz_allInNeverBeyondReference checks this on every run. An arb can close about 20% of a gap per swap profitably, so a jump closes over a few swaps (about ten for 90%) at 100 ms blocks.
The cap
The fee stops at 3%, reached at a 3.75% gap. A HYPE move larger than that inside one reference interval leaks above the cap to the arbitrageur.