👻
Aave Book
  • Introduction
  • TradFi vs DeFi: Lending
  • Market forces x Interest Rate Models
  • On Indexes
    • Why use indexes?
  • Scaling and ATokens
  • Deposit & Borrow Interest
  • Stable borrowing
    • 🚧Under construction
  • Liquidation
    • 🚧TODO: Full example
    • 🚧Under construction: oracles
  • Primer
    • Bitmap & Masks
      • 🚧padding and bytes
    • WadRayLibrary
      • Math Operations
      • 🚧WIP: Scaling different decimal representations
      • 🚧WIP: 2's complement
      • 🚧casting: to uint128
    • PercentageMath
    • Embedded vs Linked Libraries
  • Functions
    • General Execution flow
    • Architecture & Design choices
      • 🚧Upgradability and Proxies
    • Common Functions
      • getReserveFactor, getDecimals
      • .cache
      • .updateState
      • .updateInterestRates
      • SupplyCap, BorrowCap
      • getFlags
        • 🚧more on flags
      • calculateUserAccountData
    • supply
      • validateSupply
      • transfer & mint
      • isFirstSupply
        • isUsingAsCollateralOne, isUsingAsCollateralAny
      • On check-effects-interactions pattern
    • withdraw
      • get user balance & withdraw amount
      • validateWithdraw
      • collateral check
      • burn ATokens
      • Ensure existing loans are collateralized
    • borrow
      • getIsolationModeState
      • .validateBorrow
      • Mint debt token
      • setBorrowing
      • update IsolationMode debt
      • transfer underlying to user
    • repay
      • get current debt
      • validateRepay, paybackAmount
      • burn debt tokens
      • Cleanup + Collect repay
    • liquidate
      • _calculateDebt
      • validateLiquidationCall
      • getConfigurationData
      • calculateAvailableCollateralToLiquidate
      • 🚧_burnDebtTokens
      • liquidate/burn collateral
      • liquidation Fee
      • Wrap-up
    • 🚧swapBorrowRateMode
    • 🚧setUserUseReserveAsCollateral
  • Contracts
    • AToken
      • Simple example: mint & balanceOf
    • StableDebtToken
      • Implementation explained
    • VariableDebtToken
    • DefaultReserveInterestRateStrategy
    • L2
      • 🚧PriceOracleSentinel
  • Audit findings
    • 🚧Under construction
  • Appendix
    • Simple, Compound, APR, APY
  • Aave Features
    • Risk Management
      • Supply & Borrow Caps
      • Isolation Mode
      • Siloed Borrowing
    • Other features
      • Repay with ATokens
      • eMode: High efficiency Mode
      • 🚧Aave Vault
      • 🚧Portal
Powered by GitBook
On this page
  • TLDR
  • Code
  • .updateInterestRates
  • Execution Flow
  • .calculateInterestRates
  • Visual Walkthrough
  • Complete picture

Was this helpful?

Edit on GitHub
  1. Functions
  2. Common Functions

.updateInterestRates

Previous.updateStateNextSupplyCap, BorrowCap

Last updated 1 year ago

Was this helpful?

TLDR

The updateInterestRates function serves to update the following interest rates

  • liquidity interest rate

  • variable borrow interest rate

  • stable borrow interest rate

Typically, this function is executed after state-changes have been done (borrow, repay, supply, etc), to reflect updated rates, accounting for said action taken.

Code

.updateInterestRates

updateInterestRates will modify system-wide rates according to whether

  • liquidity added: supply or repay

  • liquidity removed: borrow or redeem

  • In most instances, either liquidityAdded or liquidityRemoved will be a zero value, while the other is a non-zero value.

  • The core logic is wrapped within .calculateInterestRates, which returns the updated rates.

Execution Flow

.calculateInterestRates

Visual Walkthrough

  • get necessary ratios which will be used in the later section to examine if utilization has exceeded certain thresholds

  • If borrow utilization exceeds optimal utilization, {...}, else {...}

  • OPTIMAL_USAGE_RATIO and MAX_EXCESS_USAGE_RATIO are immutable; values are set within constructor.

  • For in-depth explanation on why the increments are done as above, see:

  • there is an additional check for stable rates

  • getOverallBorrowRate simply calculates the weighted average borrow rate based off variable and stable components

  • currentLiquidityRate is calculated as a component of overallBorrowRate, accounting for the portion that goes to the treasury.

Complete picture

Drawing
variable rate model
stable rate model