Configuring Pre-hooks

Pre-hooks are very powerful feature of the Fusion Vaults. They allow an execution of an additional functions before invoking a primary action.

Because the pre-hooks are very powerful functionality their management should always be done by user with a long timelock. IPOR web app will be alerting liquidity providers about the use of unverified pre-hooks.

What is a pre-hook

Fusion vault allows for an execution of a code when invoking restricted methods on the core vault. Pre-hooks are not available to methods on managers.

Pre-hooks are smart contracts with an access to the memory of the contract and authority to execute functions. They can be used for various applications such as:

  • updating balance cache on markets

  • raising exceptions (effectively pausing functions)

  • triggering auto-withdrawals from complex strategies

  • etc.

Due to that power and flexibility it is important that the user allowed to modify the prehooks has timelock configured

To add pre-hook to the vault use setPreHookImplementaions

PlasmaVaultGovernance(PLASMA_VAULT)
    .setPreHookImplementations(selectors, preHooks, substrates);

where selectors are the signatures of restricted methods on the vault, pre-hooks are addresses of implementations and substrates are the params required by the pre-hooks.

Example implementation can be found in below test case: https://github.com/IPOR-Labs/ipor-fusion/blob/main/test/pre_hooks/UpdateBalancesIgnoreDustPreHookTest.t.solarrow-up-right . It demonstrates the use of the pre-hook that rebalances the cache of the vault before deposit and withdrawal while ignoring balances with dust.

List of the deployed prehooks: https://github.com/IPOR-Labs/ipor-abi?tab=readme-ov-file#prehooks-listarrow-up-right

Bundled Pre-hooks

IPOR Fusion web-app comes with some bunled prehooks that bring some valuable functionalities to the vaults. This list may not be exhaustive as there are new components being developed but below you can find some pre-hooks available at the time of writing this documentation and use cases for them.

Function Pausing Pre-hook

Under the prehooks section of the administrative panel /edit you can find Pause Functions . You can use this interface to pause individual functions of the fusion vaults. Underneeth a special pre-hook is used that simply raises an exception. By attaching it before a restricted method you essentially render it unable to execute.

Auto Rebalance Pre-hook

Another prehook provided via the app.ipor.io interface is the auto rebalance prehook. Because rebalancing of the vault before deposit and withdrawals would cost additional gas, vaults for gas optimisation rely on cached balances that are refreshed each time the vault interacts with connected markets. You can force rebalancing before every deposit/withdraw action by using this pre-hook.

Exchange rate validator

Another example of what pre-hooks can be used for is validating of the changes in the exchange rate since the last rebalance. When this is enabled then pre-hook will keep track of the exchange rates and will block selected functions is the jump of the share exchange rate exeeds the defined threshold. This is useful in case you want to restrict access in the situaltions where vault is misconfigured or price oracles are experiencing issues.

Last updated