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:
preExecute
→ execution(s)
→ postExecute
Build – Frontend selects the addresses & calldata of the hook(s) in a chain.
Bundle – SuperBundler splits hooks per chain and wraps each into an ERC‑4337 UserOp, storing a Merkle tree.
Validate – Smart Account delegates to SuperValidator on‑chain to perform Merkle proof verification.
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 includeHookSubTypes
likeSWAP
,STAKE
,BRIDGE
INFLOW
- Hooks that process additions to positions and typically encode some sort ofdeposit
action. They include aHookSubType
corresponding to underlying vault being deposited into likeERC4626
,ERC7540
etc.OUTFLOW
- Hooks that process reductions to positions and typically encode some sort ofredeem
action. They include similarHookSubType
toINFLOW
hooks.
Last updated