How to Calculate Historical Interest Rates on Aave
A guide for crypto researchers, borrowers and depositors. Learn how to accurately track DeFi APRs and APYs.
Why Calculate Your Historical Interest Rate?
Whether you're lending or borrowing on platforms like Aave, Compound, or Euler, knowing your historical interest rate helps you clearly understand your gains or interest owed over time.
Two Ways to Calculate DeFi Interest Rates
1. Use Historical APRs
You can take an average of the historical APRs listed on Aavescan. This is quick and straightforward but does not account for intraday fluctuations and compounding effects.
2. Use the Interest Index
The most accurate method for calculating historical interest is to track the growth of the market index (available on Aavescan exports), such as Aave's liquidityIndex for deposits or variableBorrowIndex for borrows. This method precisely captures compounded interest and all associated fees.
What is the Interest Index?
The interest index (such as Aave’s liquidityIndex or variableBorrowIndex) is a number that continuously increases to reflect accumulated interest. By comparing the index values of two different dates you can precisely calculate the interest that has accrued, i.e. the interest earned or owed, fully accounting for compounding and additional sources of income such as flash loan fees.
Calculating Interest Using the Index
To find your accurate historical interest:
- Locate the initial value of the interest index when you entered the market. This is either the liquidityIndex or the variableBorrowIndex depending on whether you want to calculate deposit interest or borrow interest. These values can be found on the Aavescan data exports.
- Find the value of the same index when you exited the market. The difference between the initial index and the final index represents the amount of interest that accrued during the period.
- Divide the current index by the initial index, subtract 1, and then multiply by your original deposit or borrowed amount.
The resulting number reflects the total interest earned or owed, fully accounting for compounding and additional fees or rewards. This is the most accurate way to calculate historical interest for research or tax accounting purposes.
Calculating Interest Rates Using the Index
Take the delta between two snapshots to calculate the actual interest accrued during that period. This is the most precise method for calculating historical interest rates.
// 1. Get liquidityIndex values
snapshotNow = currentSnapshot.liquidityIndex
snapshot24hAgo = snapshot24hAgo.liquidityIndex
// 2. Compute daily growth
growth = snapshotNow / snapshot24hAgo
// 3. Convert to APR
depositApr = (growth - 1) * 365
// 4. Annualise to APY
depositApy = Math.pow(growth, 365) - 1
Rate reflects the actual interest accrued during the past 24 hours.
Aave Interest Technical Details
The amount of interest earned by lenders and paid by borrowers depends on lending rates, compounding frequency and extra rewards such as flash loan fees.
Aave V2 and V3 use APRs that accrue every second. Borrow interest compounds every second. However, deposit interest only compounds when the market is updated, typically when users interact with it. Depositors also receive additional yield from flash loan fees.
Rates example
The chart below illustrates how APY calculations can differ depending on how blockchain data is intepreted. This is pronounced in Compound V2 lending market data where rates are quoted on a per-block basis.
Special thanks to @samlafer for insights in this Twitter thread and to Robert L. in Compound’s Discord.
Join the discussion on Aavescan Discord.