Hooks

Overview

Hooks are external contracts that execute custom logic at key protocol lifecycle events. They enable extensibility without modifying the core protocol.

When an operation occurs, the LendingManager checks if a hook exists for the term. If present, it calls the hook before and after executing core logic. Before hooks can validate and block operations; after hooks can perform side effects.

Hook Points

Term Lifecycle

Initialization — Configure term-specific settings when the term is created.

Position Modification — Validate deposits and withdrawals. Use cases include whitelisting depositors, enforcing deposit limits, and auto-depositing to external protocols.

Settlement — Handle interest distribution events.

Loan Lifecycle

Allocation — Validate loan funding requests. Use cases include checking caller authorization, verifying borrower whitelists, and calling module verification.

Repayment — Handle loan completion events including settlement notifications and external protocol updates.

Built-in Hooks

P2P Hook

The simplest hook: only the term owner can allocate funds. This enables manual loan approval for private lending circles.

AaveV3 Hook

Automatically deposits idle funds to Aave for additional yield. When deposits arrive, idle capital moves to Aave. When loans are allocated, capital withdraws from Aave to fund the loan. When loans repay, capital redeposits to Aave.

The hook uses share-based accounting for gas efficiency and proportional yield distribution.

Timelock Module Hook

Enforces additional validation including whitelist management for callers and borrowers, module integration for collateral verification, and timelock for parameter changes.

Hook Capabilities

Can Do
Cannot Do

Revert to block operations

Modify term/loan state directly

Call external contracts

Transfer term assets

Store custom state

Bypass core protocol logic

Emit custom events

Change fee parameters

Custom Hooks

Custom hooks can extend protocol functionality through access control (whitelists, role-based access), rate limiting (operation frequency limits), external integration (DeFi protocol connections), and module coordination (collateral verification).

Each hook call receives additional data that can encode custom parameters like referral codes, configuration options, or validation context. Hooks interpret this data according to their logic.

Security

Hooks should only accept calls from the LendingManager to prevent unauthorized access. Hooks inherit reentrancy protection from the LendingManager but should take care with external calls. Hooks cannot directly modify term or loan state—all state changes go through the LendingManager.

Hook Type
Purpose
Use Case

P2P

Manual approval

Private lending

AaveV3

Yield optimization

Idle fund deployment

Timelock

Governance controls

DAO treasury lending

Custom

Any logic

KYC gates, referrals

Last updated