AAVE Source Code Analysis: The Interest Rate Model
The interest-rate model and risk control are the core of any lending protocol. In AAVE, interest updates can be divided into three parts:
- deposit interest
- variable borrow interest
- stable borrow interest
As for risk control, I discuss that separately in a later article.
The ReserveData Struct
ReserveData is the core data structure behind AAVE’s interest-rate mechanics. It is defined in contracts/protocol/libraries/types/DataTypes.sol:
| |
ReserveData is the most important structure in the lending relationship. Every asset that can be borrowed or supplied in the market has a corresponding ReserveData entry that records its key rate information.
The variables most directly related to interest are:
liquidityIndex: deposit interest indexvariableBorrowIndex: variable-rate borrowing indexcurrentLiquidityRate: supply-side liquidity rate, used to updateliquidityIndexcurrentStableBorrowRate: stable borrowing ratecurrentVariableBorrowRate: variable borrowing rate, used to updatevariableBorrowIndex
Two-Slope Interest Rates
At the core, interest rates are driven by supply and demand. Whenever available liquidity changes, AAVE adjusts rates automatically. In both AAVE and Compound, the variable used to express this supply-demand relationship is utilization. The definition is:
The rate curve looks like this:

The chart shows the behavior clearly:
- When utilization is below the optimal utilization level, rate = base rate + utilization * slope1
- When utilization exceeds the optimal level, rate = base rate + slope1 + (utilization - optimal utilization) * slope2
Once utilization moves past the optimal point, rates rise very quickly. That pushes borrowers to repay sooner, otherwise they risk being liquidated.
liquidityIndex
This is the deposit-side index that describes the token/aToken exchange relationship.
It is mainly used in:
Deposits
The user’s tokens are transferred into the protocol and aTokens are minted to the user.
The conversion is:
| |
Withdrawals
The user’s aTokens are transferred back and burned, and the corresponding amount of underlying tokens is returned.
| |
Because liquidityIndex keeps increasing over time, these two formulas are enough to derive deposit interest earned by the user.
variableBorrowIndex
Variable-rate borrowing
When a user borrows, the system mints debt tokens to track the principal plus time-based interest accrual.
| |
Variable-rate repayment
When the user repays, the amount owed is calculated as:
| |
Liquidation
Liquidation is one of the most important parts of risk control, and I cover it separately in the risk-control article.
Stable Borrowing
Stable borrowing is conceptually similar to variable borrowing, but with some important differences. Because stable borrowing usage is relatively low, I will skip a detailed analysis of it here.
Interest Rate Calculation Flow
The main logic lives in contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol, in the function calculateInterestRates.
The rough flow is:
- Total borrows = variable borrows + stable borrows
- Utilization = total borrows / (total deposits + total borrows)
- Calculate the variable and stable borrow rates. Both use a two-slope piecewise-linear formula. a. variable rate = base variable rate + utilization * variable slope1, plus slope2 if utilization is in the second segment b. stable rate = base stable rate + utilization * stable slope1
- Weighted average borrow rate =
(variable borrows * variable rate + stable borrows * average stable borrow rate) / total borrowsThe average stable borrow rate is an input parameter and is not calculated here. currentLiquidityRate = (weighted average borrow rate / total borrows) * utilization * (1 - reserve factor)
You can see that currentLiquidityRate is the most complex variable in the chain. Its purpose is to drive the calculation of the deposit-side rate, i.e. liquidityIndex.
For the code-level analysis of these formulas, see the separate article on AAVE interest-rate code.
AAVE series:
- Introduction to the AAVE lending protocol
- Overall AAVE code architecture
- AAVE interest-rate model
- AAVE interest-rate code walkthrough
- AAVE liquidation
- AAVE flash loans
- How AAVE decouples modules
- AAVE proxy pattern
- AAVE testing and deployment