Aave V3 Protocol DocumentationΒΆ
Comprehensive control flow diagrams and amount transformations for debugging Aave V3 Market operations.
For Automated AgentsΒΆ
Debugging WorkflowΒΆ
Identify the operation being investigated (supply, borrow, liquidation, etc.)
Load the flow file for that operation to see the execution path
Follow the transformations - refer to the transformations/index.md for detailed math
Check validation - each flow shows all validation checks and error conditions
Verify state changes - see exactly what storage is modified
Common Debugging PatternsΒΆ
**Investigating balance discrepancy:**
1. Check [Collateral Transformations](./transformations/index.md#collateral-token-transformations)
2. Verify rounding mode (v1-3 vs v4+)
3. Check index at specific block height
4. Look for treasury accruals
**Investigating liquidation:**
1. Check [Liquidation Flow](./flows/liquidation.md)
2. Verify health factor calculation in [E-Mode](./transformations/index.md#e-mode-calculations)
3. Check collateral conversion math
4. Verify close factor logic
**Investigating failed transaction:**
1. Find the operation flow
2. Check "Error Conditions" section
3. Match error to validation check
4. See validation logic in Solidity
Solidity Source MappingΒΆ
Each flow file includes:
File paths to actual contract source
Function names with line-level references
Complete code snippets showing actual implementation
Transformation markers linking to detailed math
Example:
// File: contracts/protocol/libraries/logic/SupplyLogic.sol
// Function: executeSupply()
uint256 scaledAmount = amount.rayDiv(index); // [TRANSFORMATION]
// Refer to transformations/index.md for:
// - Exact formula
// - Solidity implementation
// - Version differences
// - Edge cases
Document StructureΒΆ
docs/aave/
βββ README.md # This file - navigation hub
βββ AGENTS.md # Instructions for automated agents
βββ flows/ # Individual operation flows
β βββ supply.md # Supply execution flow
β βββ supply_with_permit.md # Supply with permit
β βββ withdraw.md # Withdraw execution flow
β βββ borrow.md # Borrow execution flow
β βββ repay.md # Repay execution flow
β βββ repay_with_atokens.md # Repay with aTokens
β βββ repay_with_permit.md # Repay with permit
β βββ liquidation.md # Liquidation execution flow
β βββ collateral_management.md # Collateral enable/disable
β βββ emode_management.md # E-Mode category management
β βββ flash_loan.md # Flash loan (with callback)
β βββ flash_loan_simple.md # Simple flash loan
β βββ gho_borrowing.md # GHO borrowing
β βββ gho_discount.md # GHO discount mechanism
β βββ rewards_claiming.md # Rewards claiming
β βββ position_manager.md # Position manager operations
β βββ eliminate_deficit.md # Umbrella deficit elimination
β βββ stk_aave_staking.md # stkAAVE staking
β βββ stk_aave_unstaking.md # stkAAVE unstaking
β βββ stk_aave_slashing.md # stkAAVE slashing
βββ transformations/ # Amount transformation reference
βββ index.md # All math operations
Key ConceptsΒΆ
Scaled Balances vs. Unscaled AmountsΒΆ
Collateral (aTokens):
Storage: Scaled balance (
_scaledBalance[user])Precision: RAY (27 decimals)
Conversion:
unscaled = scaled.rayMul(liquidityIndex)Interest: Automatic via index growth
Variable Debt:
Storage: Scaled balance (
_scaledBalance[user])Precision: RAY (27 decimals)
Conversion:
unscaled = scaled.rayMul(borrowIndex)Interest: Automatic via index growth
Stable Debt:
Storage: Principal + timestamp
Precision: WAD (18 decimals)
Conversion: Calculate interest on-demand
Interest: Compounded at borrow/repay time
Index UpdatesΒΆ
// Liquidity Index (for collateral)
liquidityIndex[t] = liquidityIndex[t-1].rayMul(1 + rate * timeDelta / YEAR)
// Borrow Index (for variable debt)
borrowIndex[t] = borrowIndex[t-1].rayMul(compoundInterest(rate, timeDelta))
See Interest Accrual for full details.
Rounding ModesΒΆ
Operation |
v1-3 |
v4+ |
Reason |
|---|---|---|---|
aToken Mint |
|
|
Prevent rounding up debt |
aToken Burn |
|
|
Ensure full repayment |
vToken Mint |
|
|
Round up debt issued |
vToken Burn |
|
|
Round down debt reduction |
See Version Differences.
Aave V3 Contract Addresses (Mainnet)ΒΆ
Pool Proxy: 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
PoolAddressesProvider: 0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e
Oracle: 0x54586bE62E3c3580375aE3723C145253060Ca0C2
ValidationΒΆ
All Mermaid diagrams in this documentation are validated using Maid:
# Validate all diagrams
npx maid .
# Auto-fix issues
npx maid --fix .
ContributingΒΆ
When adding new flows or transformations:
Include complete Solidity code snippets
Add links between flows and transformations
Document all error conditions
Show version differences where applicable
Run
npx maid --fixbefore committing