Hooks Reference
Hooks let a pool run extra logic around Vault operations, most relevantly computing a dynamic swap fee. A hook that changes the swap fee changes the quote, so an aggregator must model it. Every hook attached by an approved factory ships with its maths in the maths/ package alongside the pool maths; the Vault class applies it when you pass the pool's hookType and a hookState.
For more details about Bush Hooks see Hooks Core Concepts and the Hooks API. To find which hook (if any) a pool has, call getHooksConfig(pool) on the Vault; hooksContract is address(0) for pools without one.
Supported Hook Types
Stable Surge Hook
- Uses the onComputeDynamicSwapFeePercentage hook to raise the fee on swaps that push a Stable pool further from balance, and charge the static fee otherwise.
- Pools with the StableSurge hook are deployed from a dedicated factory,
StableSurgePoolFactory, which attaches the hook on registration. The pool itself is a standard Stable pool. - Factory address: Deployment Addresses - see
StableSurgePoolFactory. - Contracts:
StableSurgeHook.sol,SurgeHookCommon.sol - Maths: TypeScript, Python, Rust
- Maths requires the configurable
maxSurgeFeePercentageandsurgeThresholdPercentagevalues for the pool, which can be fetched and tracked on the hook contract using the following functions and events:
function getMaxSurgeFeePercentage(address pool) external view returns (uint256);
function getSurgeThresholdPercentage(address pool) external view returns (uint256);
event MaxSurgeFeePercentageChanged(address indexed pool, uint256 newMaxSurgeFeePercentage);
event ThresholdSurgePercentageChanged(address indexed pool, uint256 newSurgeThresholdPercentage);
- In the maths package, pass the hook alongside the pool state:
const poolState: StableState = { poolType: 'STABLE', hookType: 'StableSurge', /* ...base + amp */ };
const hookState = {
hookType: 'StableSurge',
amp, // same raw amp as the pool state
surgeThresholdPercentage, // getSurgeThresholdPercentage(pool)
maxSurgeFeePercentage, // getMaxSurgeFeePercentage(pool)
};
const amountOut = new Vault().swap(swapInput, poolState, hookState);
Adding a hook
A new hook is contributed together with the factory that attaches it, and its maths is part of that contribution; see Contributing a Pool Factory.