Hooks & Custom Logic
Euler Earn supports a flexible hooks system, allowing vault managers to extend or restrict vault functionality without modifying core contracts. Hooks can be used to pause specific operations, enforce custom requirements (like KYC or minimum deposit sizes), add fees, or implement other business logic.
How Hooks Work
Hooks are external contracts that the vault calls before certain operations, such as deposits, withdrawals, or strategy changes. If a hook reverts, the operation is blocked. This enables powerful customizations while preserving the security and immutability of the core protocol.
Registering and Using Hooks
- Vault managers can register a hook contract for specific operations (e.g., before deposit, before withdrawal).
- When a user triggers an operation, the vault calls the registered hook. If the hook returns normally, the operation proceeds; if it reverts, the operation is blocked.
- Hooks can be updated or removed by role holders, unless the vault is finalized (immutable).
Example: Pausing Deposits with a Hook
A simple pausing hook might look like this:
contract PauseHook {
bool public paused;
address public admin;
function setPaused(bool _paused) external {
require(msg.sender == admin);
paused = _paused;
}
function deposit(uint256, address) external view {
require(!paused, "Deposits are paused");
}
function isHookTarget() external pure returns (bytes4) {
return this.deposit.selector;
}
}
Register this contract as the deposit hook, and the vault will block deposits when paused
is true.
Best Practices & Security Considerations
- Keep hooks simple and gas-efficient to avoid blocking core operations.
- Avoid reentrancy and external calls in hooks.
- Test hooks thoroughly, especially for edge cases and failure modes.
Example Use Cases
- Pausing deposits or withdrawals during emergencies
- Enforcing allowlists or KYC checks
- Adding custom fees or minimum deposit amounts
Similarity to EVK Hooks
The hooks system in Euler Earn is modeled after the one in the Euler Vault Kit (EVK), providing a consistent developer experience across the protocol.