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/open in new window 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

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.