Hooks

Hooks have access to different data shared from the Vault. These allow a developer to build powerful execution logic when additionally utilizing the shared data.

onRegister

function onRegister(
    address factory,
    address pool,
    TokenConfig[] memory tokenConfig,
    LiquidityManagement calldata liquidityManagement
) external returns (bool);

Hook to be executed when pool is registered. If it returns false, the registration is reverted. Vault address can be accessed with msg.sender.

Parameters:

NameTypeDescription
factoryaddressAddress of the pool factory
pooladdressAddress of the pool
tokenConfigTokenConfig[] memoryAn array of descriptors for the tokens the pool will manage
liquidityManagementLiquidityManagement calldataLiquidity management flags with implemented methods

Returns:

NameTypeDescription
successboolTrue if the hook allowed the registration, false otherwise

getHookFlags

function getHookFlags() external returns (HookFlags memory hookFlags);

Returns flags informing which hooks are implemented in the contract.

Returns:

NameTypeDescription
hookFlagsHookFlags memoryFlags indicating which hooks the contract supports

onBeforeInitialize

function onBeforeInitialize(uint256[] memory exactAmountsIn, bytes memory userData) external returns (bool);

Optional hook to be executed before pool initialization.

Parameters:

NameTypeDescription
exactAmountsInuint256[] memoryExact amounts of input tokens
userDatabytes memoryOptional, arbitrary data with the encoded request

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with initialization

onAfterInitialize

function onAfterInitialize(
    uint256[] memory exactAmountsIn,
    uint256 bptAmountOut,
    bytes memory userData
) external returns (bool);

Optional hook to be executed after pool initialization.

Parameters:

NameTypeDescription
exactAmountsInuint256[] memoryExact amounts of input tokens
bptAmountOutuint256Amount of pool tokens minted during initialization
userDatabytes memoryOptional, arbitrary data with the encoded request

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with initialization

onBeforeAddLiquidity

function onBeforeAddLiquidity(
    address router,
    AddLiquidityKind kind,
    uint256[] memory maxAmountsInScaled18,
    uint256 minBptAmountOut,
    uint256[] memory balancesScaled18,
    bytes memory userData
) external returns (bool success);

Optional hook to be executed before adding liquidity.

Parameters:

NameTypeDescription
routeraddressThe address (usually a router contract) that initiated a swap operation on the Vault
kindAddLiquidityKindThe type of add liquidity operation (e.g., proportional, custom)
maxAmountsInScaled18uint256[] memoryMaximum amounts of input tokens
minBptAmountOutuint256Minimum amount of output pool tokens
balancesScaled18uint256[] memoryCurrent pool balances in token registration order
userDatabytes memoryOptional, arbitrary data with the encoded request

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with settlement

onAfterAddLiquidity

function onAfterAddLiquidity(
    address router,
    uint256[] memory amountsInScaled18,
    uint256 bptAmountOut,
    uint256[] memory balancesScaled18,
    bytes memory userData
) external returns (bool success);

Optional hook to be executed after adding liquidity.

Parameters:

NameTypeDescription
routeraddressThe address (usually a router contract) that initiated a swap operation on the Vault
amountsInScaled18uint256[] memoryScaled amounts of tokens added in token registration order
bptAmountOutuint256Amount of pool tokens minted
balancesScaled18uint256[] memoryCurrent pool balances in token registration order
userDatabytes memoryAdditional (optional) data provided by the user

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with settlement

onBeforeRemoveLiquidity

function onBeforeRemoveLiquidity(
    address router,
    RemoveLiquidityKind kind,
    uint256 maxBptAmountIn,
    uint256[] memory minAmountsOutScaled18,
    uint256[] memory balancesScaled18,
    bytes memory userData
) external returns (bool success);

Optional hook to be executed before removing liquidity.

Parameters:

NameTypeDescription
routeraddressThe address (usually a router contract) that initiated a swap operation on the Vault
kindRemoveLiquidityKindThe type of remove liquidity operation (e.g., proportional, custom)
maxBptAmountInuint256Maximum amount of input pool tokens
minAmountsOutScaled18uint256[] memoryMinimum output amounts in token registration order
balancesScaled18uint256[] memoryCurrent pool balances in token registration order
userDatabytes memoryOptional, arbitrary data with the encoded request

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with settlement

onAfterRemoveLiquidity

function onAfterRemoveLiquidity(
    address router,
    uint256 bptAmountIn,
    uint256[] memory amountsOutScaled18,
    uint256[] memory balancesScaled18,
    bytes memory userData
) external returns (bool success);

Optional hook to be executed after removing liquidity.

Parameters:

NameTypeDescription
routeraddressThe address (usually a router contract) that initiated a swap operation on the Vault
bptAmountInuint256Amount of pool tokens to burn
amountsOutScaled18uint256[] memoryAmount of tokens to receive in token registration order
balancesScaled18uint256[] memoryCurrent pool balances in token registration order
userDatabytes memoryAdditional (optional) data provided by the user

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with settlement

onBeforeSwap

function onBeforeSwap(PoolSwapParams calldata params, address pool) external returns (bool success);

Called before a swap to give the Pool an opportunity to perform actions.

Parameters:

NameTypeDescription
paramsPoolSwapParamsSwap parameters
pooladdressPool address, used to get pool information from the vault

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with settlement

onAfterSwap

function onAfterSwap(
    AfterSwapParams calldata params
) external returns (bool success, uint256 hookAdjustedAmountCalculatedRaw);

Called after a swap to give the Pool an opportunity to perform actions once the balances have been updated by the swap.

Parameters:

NameTypeDescription
paramsAfterSwapParamsSwap parameters

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with settlement
hookAdjustedAmountCalculatedRawuint256New amount calculated, modified by the hook

onComputeDynamicSwapFeePercentage

function onComputeDynamicSwapFeePercentage(
    PoolSwapParams calldata params,
    address pool,
    uint256 staticSwapFeePercentage
) external view returns (bool success, uint256 dynamicSwapFeePercentage);

Called after onBeforeSwap and before the main swap operation, if the pool has dynamic fees.

Parameters:

NameTypeDescription
paramsPoolSwapParamsSwap parameters
pooladdressAddress of the pool
staticSwapFeePercentageuint256Value of the static swap fee, for reference

Returns:

NameTypeDescription
successboolTrue if the pool wishes to proceed with settlement
dynamicSwapFeeuint256Value of the swap fee