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 hook’sbuild() function:
preExecute → execution(s) → postExecute
- Build - Frontend selects the addresses and 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 onHookType 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
HookSubTypeslikeSWAP,STAKE,BRIDGE. - INFLOW - Hooks that process additions to positions and typically encode some sort of
depositaction. They include aHookSubTypecorresponding to the underlying vault being deposited into likeERC4626,ERC7540, etc. - OUTFLOW - Hooks that process reductions to positions and typically encode some sort of
redeemaction. They include similarHookSubTypetoINFLOWhooks.