AAVE Source Code Analysis: Overall Code Architecture

Summary
AAVE is the third major stage in DeFi lending after MakerDAO and Compound, and its codebase reflects that maturity.

AAVE Architecture Overview

AAVE is a lending protocol, so its core revolves around four major actions: deposit, borrow, repay, and liquidation. In my view, one major reason AAVE looks complex is the existence of stable-rate borrowing, which significantly increases the complexity of the interest-rate model. Without that feature, the overall design would be much easier to understand.

The high-level AAVE architecture looks like this:

Directory Structure and Files

The contracts live mainly under the contracts directory, which is organized like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
├─adapters  // External contract adapters
│  └─interfaces
├─dependencies  // Base libraries, mostly adapted from OpenZeppelin
│  └─openzeppelin
│      ├─contracts
│      └─upgradeability
├─deployments // Deployment-related code
├─flashloan  // Flash loan modules
│  ├─base
│  └─interfaces
├─interfaces  // Interface definitions
├─misc
│  └─interfaces
├─mocks    // Test-related contracts
│  ├─attacks
│  ├─dependencies
│  │  └─weth
│  ├─flashloan
│  ├─oracle
│  │  └─CLAggregators
│  ├─swap
│  ├─tokens
│  └─upgradeability
└─protocol   // Core implementation
    ├─configuration
    ├─lendingpool
    ├─libraries
    │  ├─aave-upgradeability
    │  ├─configuration
    │  ├─helpers
    │  ├─logic
    │  ├─math
    │  └─types
    └─tokenization
        └─base

If you combine the main codebase with the deployment scripts and mocks, AAVE has roughly 30 contracts:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  LendingPoolAddressesProvider = 'LendingPoolAddressesProvider',
  LendingPoolAddressesProviderRegistry = 'LendingPoolAddressesProviderRegistry',
  LendingPoolParametersProvider = 'LendingPoolParametersProvider',
  LendingPoolConfigurator = 'LendingPoolConfigurator',
  ValidationLogic = 'ValidationLogic',
  ReserveLogic = 'ReserveLogic',
  GenericLogic = 'GenericLogic',
  LendingPool = 'LendingPool',
  PriceOracle = 'PriceOracle',
  Proxy = 'Proxy',
  LendingRateOracle = 'LendingRateOracle',
  AaveOracle = 'AaveOracle',
  DefaultReserveInterestRateStrategy = 'DefaultReserveInterestRateStrategy',
  LendingPoolCollateralManager = 'LendingPoolCollateralManager',
  InitializableAdminUpgradeabilityProxy = 'InitializableAdminUpgradeabilityProxy',
  WalletBalanceProvider = 'WalletBalanceProvider',
  AToken = 'AToken',
  DelegationAwareAToken = 'DelegationAwareAToken',
  AaveProtocolDataProvider = 'AaveProtocolDataProvider',
  StableDebtToken = 'StableDebtToken',
  VariableDebtToken = 'VariableDebtToken',
  FeeProvider = 'FeeProvider',
  TokenDistributor = 'TokenDistributor',
  StableAndVariableTokensHelper = 'StableAndVariableTokensHelper',
  ATokensAndRatesHelper = 'ATokensAndRatesHelper',
  UiPoolDataProvider = 'UiPoolDataProvider',
  WETHGateway = 'WETHGateway',
  UniswapLiquiditySwapAdapter = 'UniswapLiquiditySwapAdapter',
  UniswapRepayAdapter = 'UniswapRepayAdapter',
  FlashLiquidationAdapter = 'FlashLiquidationAdapter',

  Mock contracts below
  MockAToken = 'MockAToken',
  MockAggregator = 'MockAggregator',
  WETHMocked = 'WETHMocked',
  SelfdestructTransferMock = 'SelfdestructTransferMock',
  MockStableDebtToken = 'MockStableDebtToken',
  MockVariableDebtToken = 'MockVariableDebtToken',
  MockFlashLoanReceiver = 'MockFlashLoanReceiver',
  MockUniswapV2Router02 = 'MockUniswapV2Router02',
  MintableERC20 = 'MintableERC20',
  MintableDelegationERC20 = 'MintableDelegationERC20',

Lending Core

The core lending system includes:

  1. Interest-rate logic

    AAVE moves most interest and validation logic into libraries under contracts/protocol/libraries/logic/, mainly:

    • GenericLogic.sol Calculates user account-level data.

    • ReserveLogic.sol The core of the core. It handles the main interest-related calculations.

    • ValidationLogic.sol This library performs safety checks for deposits, borrows, repayments, liquidations, transfers, stable/variable rate switching, and so on.

  2. LendingPool

    LendingPool is the main entry point for lending actions such as deposit, borrow, repay, and liquidation.

  3. LendingPoolCollateralManager

    Responsible mainly for liquidation handling.

  4. DefaultReserveInterestRateStrategy

    Defines how interest rates change through calculateInterestRates.

Tokenization

In AAVE, both user deposits and user debt are recorded as tokens. In Compound, only deposits are tokenized; debt is not. Personally, I do not think debt strictly needs tokenization, but AAVE chose that design.

  1. AToken

    Deposit receipt token, similar to Compound’s cToken. When a user deposits an asset, AAVE mints the corresponding aToken.

  2. DelegationAwareAToken

    An AToken variant that supports delegation-related behavior.

  3. StableDebtToken

    Token used to record stable-rate borrowing.

  4. VariableDebtToken

    Token used to record variable-rate borrowing.

Markets, Providers, and Configuration Management

  • LendingPoolAddressesProvider
  • LendingPoolAddressesProviderRegistry
  • LendingPoolParametersProvider
  • LendingPoolConfigurator

Oracle

The oracle layer provides the pricing inputs needed for borrowing power, liquidation, and other protocol decisions.

Helper Contracts

  • AaveProtocolDataProvider Aggregates and precomputes data for frontend consumption.

  • UiPoolDataProvider Also aggregates and prepares data for frontends.

  • StableAndVariableTokensHelper Helper management contract for setting borrow-rate-related parameters across multiple assets.

  • WalletBalanceProvider Queries balance information. It is not strictly necessary because similar functionality can be built with multicall, but this contract offers a more targeted and often faster interface.

  • ATokensAndRatesHelper Helper contract for configuration updates.

Adapters

The adapter layer mainly consists of Uniswap-related adapters:

  • UniswapLiquiditySwapAdapter
  • UniswapRepayAdapter
  • FlashLiquidationAdapter

Proxy

  • LendingPool proxy
  • plus several additional upgradeable proxies throughout the system

At first glance, this many contracts can feel overwhelming. The practical way to study AAVE is to start from the core, especially the interest-rate model and risk-control-related contracts. That narrows the focus to roughly 7 or 8 contracts and makes the codebase much easier to digest.