👻
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
  • Design choices
  • Pool contract

Was this helpful?

Edit on GitHub
  1. Functions

Architecture & Design choices

PreviousGeneral Execution flowNextUpgradability and Proxies

Last updated 1 year ago

Was this helpful?

While this screenshot is of v2, (lendingPool was renamed Pool in v3), it is useful to illustrate the architecture of Aave on the whole.

The Pool contract contains all the user-facing functions, and serves as the single access point into Aave. Regardless of which asset the user might want to interact with, or what they wish to do, it will always be through the Pool contract.

Design choices

Advantages

  1. Single Access Point

  • Makes integration easy as integrators simply need to point to the Pool contract.

  • Single consistent entry-point makes for better UX and security.

  1. Upgrading/Implementing new features

Easy to add new functionalities and have them on all the assets at once. Simply upgrade the Pool contract, and they are available on all the assets.

V3 added functionalities:

  • Permit for supply, repay

  • EIP712 signatures for credit delegation

However, on compound you must upgrade all the different cToken contracts, to introduce a new feature/function across the board.

Disadvantages

If a custom behaviour is needed for a particular asset, implementing can be tricky. For example, a specific action that occurs on supply, withdraw, etc.

  • This has not become an issue to date.

  • However, if it becomes an issue, a specific function can be added to the pool contract just for that asset.

Pool contract

There is no execution code on the Pool contract.

In v2, the lendingPool contract was rather big, almost exceeding the limit of 24 kb. Solution was to split the code into their logical groups; code was modularized via libraries.

  • E.g. SupplyLogic.sol library holds all the relevant logic pertaining to the supply action

  • supply function on Pool.sol calls executeSupply defined on SupplyLogic.sol library

  • Pool retains the necessary storage/state data, while "importing" execution logic from various libraries.

Libraries were deployed independently as linked libraries - containing external functions. This helped to downsize contract code.

While these libraries are independently deployed and their external functions can be accessed by anyone, they have to be called by the Pool contract to enact a change with Aave protocol.

One simple way to reduce contract size is using a . Don't declare the library functions as internal as those will be directly during compilation.

But if you use public functions, then those will be in fact in a separate library contract. Consider to make the use of libraries more convenient.

library
added to the contract
using for