Hooks

Introduction

Hooks are lightweight, permissionless contracts which perform a specific action—bridge, swap, lend, etc. They are designed to be composable and can be chained together to create complex transaction flows which can achieve any multichain strategy. Hook chains can be fulfilled by any ERC-7579 smart account with the SuperValidator and SuperExecutor modules installed.

If you're interesting in building hooks, jump straight to Write Hooks.

Key Concepts

Hooks implement transient storage during the execution of a transaction to temporarily hold state changes. This allows for efficient inter-hook communication that avoids the high gas costs associated with permanent storage writes. If any hook in a chain fails, the entire transaction is reverted, ensuring atomicity.

Hook Lifecycle

The execution of hooks is a three‑step sequence bundled in the hooks build() function: preExecuteexecution(s)postExecute

  1. Build – Frontend selects the addresses & calldata of the hook(s) in a chain.

  2. Bundle – SuperBundler splits hooks per chain and wraps each into an ERC‑4337 UserOp, storing a Merkle tree.

  3. Validate – Smart Account delegates to SuperValidator on‑chain to perform Merkle proof verification.

  4. Execute – SuperExecutor iterates through hooks, performs each action and updates SuperLedger.

Hook Classifications

Hooks are classified based on HookType and HookSubType. HookType must be defined as NONACCOUNTING, INFLOW, or OUTFLOW depending on the hook's expected interaction with the accounting system. HookSubTypes designate which action category the hook implements.

  • NONACCOUNTING - Utility hooks that do not update the accounting system. These hooks include HookSubTypes like SWAP, STAKE, BRIDGE

  • INFLOW - Hooks that process additions to positions and typically encode some sort of deposit action. They include a HookSubType corresponding to underlying vault being deposited into like ERC4626, ERC7540 etc.

  • OUTFLOW - Hooks that process reductions to positions and typically encode some sort of redeem action. They include similar HookSubType to INFLOW hooks.

Last updated