Aave V3 Origin

repository·main·Indexed 43 days ago

https://github.com/aave-dao/aave-v3-origin

The complete Foundry-based codebase for the Aave V3 protocol, including version 3.7. It serves as the source of truth for protocol implementation, featuring isolated eMode, liquidation rounding, and the stataToken EIP-4626 compliant vault. The repository includes technical specifications, security audit reports from v3 Base through v3.7, and the AaveV3ConfigEngine for managing governance proposal payloads.

Tokens
52.5K
Snippets
78
Records
231
Agent score
54%

What's inside Aave V3

  1. Overview of Aave V3.7 Origin

    main
    Aave V3.7 Origin is the complete codebase for Aave V3.7, built using the Foundry framework. It serves as the source of truth for the Aave V3 protocol implementation, including features like isolated eMode and liquidation rounding introduced in version 3.7.
  2. What is stataToken?

    main

    stataToken is an EIP-4626 compliant generic token vault/wrapper designed specifically for use with Aave V3 aTokens. It allows users to wrap their aTokens into a standardized vault format while maintaining eligibility for liquidity mining rewards.

    Key Features

    • EIP-4626 Compatibility: Standardized interface for token vaults.
    • Liquidity Mining Support: Automatically accounts for rewards from the Aave ecosystem or community. Note that while the design supports infinite reward tokens, each new reward must be permissionlessly registered.
    • Governance Upgradable: Deployed instances can be upgraded by Aave governance via the Level 1 executor.
    • Permissionless Deployment: New stataToken instances for newly listed assets can be deployed by anyone using the StataTokenFactory.
  3. Overview of Aave v3.3 Key Changes

    main

    Aave v3.3 is an upgrade to the Aave V3 protocol designed to improve debt management, liquidations, and compatibility with the upcoming Umbrella system.

    Key functional improvements include:

    • Bad Debt Management: Implementation of bad debt logging and burn functionality to handle unresolvable debts, enabling compatibility with automated bad debt coverage via the Umbrella system.
    • Liquidation Optimisations: Refined liquidation algorithms aimed at reducing 'dust' debt positions and improving economic efficiency for liquidators.
    • Protocol Optimisations: Various improvements to data reading and protocol configurations.
  4. Understand the solvency proofs for the repay() function

    main

    The solvency property for the repay() function is verified using Certora specifications split into two primary files:

    1. main.spec: Contains the primary proof for the main solvency property.
    2. lemma.spec: Contains proofs for several assumptions required by main.spec to ensure the verification process is efficient and avoids timeouts.

    Key assumptions proven in lemma.spec include:

    • Non-zero supply: Proves that if the scaled-total-supply of variable-debt is 0, the call to repay() reverts.
    • Index Summarization: To prevent verification timeouts, the functions getNormalizedIncome() and getNormalizedDebt() are summarized as the constant values LIQUIDITY_INDEX and DEBT_INDEX, respectively. This relationship is justified in the repay__index_unchanged() rule within lemma.spec.
  5. Key changes in the Aave v3.4 Upgrade

    main

    The Aave v3.4 upgrade introduces several architectural improvements and feature additions to the v3 protocol:

    • GHO Logic Migration: Custom GHO logic and a/v tokens are migrated to a standard asset model to simplify the codebase.
    • Multicall Support: Added to the Pool contract.
    • Position Manager Role: Allows users to assign a role to other addresses to perform specific actions on their behalf, such as switching Liquid modes or enabling/disabling an asset as collateral.
    • Code Cleanup: Removed unused BridgeLogic and the concept of "unbacked" assets.
    • Immutability: Various variables have been made immutable to prevent accidental changes.
    • Error Handling: Refactored to use Error signatures instead of error codes.
    • aToken Unification: Unified storage and implementation for all aTokens (including aAAVE).
    • Compiler Upgrade: Updated to version 0.8.27 for better tooling compatibility.
  6. Key changes in Aave v3.4

    main

    Aave v3.4 is an upgrade to the v3 protocol that introduces several architectural improvements and feature additions:

    • GHO Migration: Custom GHO logic and aTokens are migrated to a standard asset model to simplify the codebase.
    • Multicall Support: Added to the Pool contract.
    • Position Manager Role: Users can assign a Position Manager to perform specific actions on their behalf, such as switching Liquidation modes and enabling/disabling assets as collateral.
    • Code Cleanup: Removed unused BridgeLogic and the concept of "unbacked" assets.
    • Immutability: Various variables have been made immutable to align with protocol design.
    • Error Handling: Refactored to use Error signatures instead of error codes.
    • aToken Unification: Unified storage and implementation for all aTokens (previously aAAVE had a unique implementation for governance).
    • Compiler Upgrade: Upgraded to Solidity 0.8.27.
    • Optimizations: Multiple minor improvements and optimizations.
  7. What is the AaveV3ConfigEngine?

    main

    The AaveV3ConfigEngine is a helper smart contract designed to abstract best practices for performing 'admin' interactions with the Aave v3 protocol. It acts as an orchestration layer that sits on top of core contracts without modifying them. It provides a simplified interface for developers to create governance proposal payloads for common tasks such as:

    • Listing new assets
    • Modifying supply and borrow caps
    • Changing collateral or borrow-related parameters
    • Updating asset price feeds
    • Managing eMode (Efficiency Mode) configurations
  8. Use Stateful Interest Rate Strategy in Aave v3.1

    main

    Aave v3.1 introduced a stateful interest rate strategy to reduce errors when connecting new strategy contracts. Instead of using immutable parameters on separate contracts for each asset, parameters are now stored in a mapping within a single default interest rate contract.

    Key Features:

    • Single Contract: A single DefaultReserveInterestRateStrategyV2 can be connected to all assets.
    • Rate Limits: A strict upper limit is enforced (currently 1000%) to prevent chaotic protocol reactions to extreme rate configurations.
    • Configuration: Rate parameters (base variable borrow rate, slope1, slope2) are managed via the PoolConfigurator using setReserveInterestRateData().
  9. Understand Deficit Management in Aave v3.3

    main

    In Aave v3.3, deficits are used to manage bad debt. Deficits are tracked via reserve.deficit and accumulate over time.

    Key behaviors:

    • Creation: A deficit is created during a liquidation if the user's total collateral across all reserves becomes zero in the base currency, while their total debt remains non-zero.
    • Reduction: Deficits can only be reduced by burning claims, which reduces the protocol's obligations in reserve.deficit.
    • Interest Rates: For interest rate calculations, the deficit is treated as an 'unbacked' parameter, meaning it reduces the utilization rate.
    • Constraints: Deficits can only be created or eliminated for active reserves. However, an edge case allows deficit creation/elimination on paused reserves if they are not the main liquidated asset.
  10. Understand AToken fee accounting and minting

    main

    Aave handles AToken fees (from liquidations or accrued debt interest) by first "accounting" for them in reserve.accruedToTreasury rather than minting them immediately to the treasury. The actual minting is performed later via the permissionless Pool.mintToTreasury function.

    Implications for developers:

    • Complexity: When calculating or fetching AToken.totalSupply, you must account for reserve.accruedToTreasury to get the real total supply.
    • Gas vs. Predictability: This approach reduces gas costs for the user triggering the state update, but it makes the value of non-minted shares less predictable and introduces potential rounding imprecisions due to multiple asset-to-share conversions.
  11. Batch transactions using Multicall in Aave v3.4

    main
    Aave v3.4 includes native multicall support, allowing users or contracts to batch multiple transactions into a single call. This is useful for improving UX (e.g., supplying, enabling eMode, and borrowing in one step) or enabling transaction subsidization by allowing a separate entity to execute transactions on a user's behalf.