protocols/aave-v3-integration

Aave V3 Integration Guide

ethereumguide🏛️ Officialconfidence highhealth -2%
v1.0.0·Updated 3/20/2026

Core Contracts (Ethereum Mainnet)

  • Pool: 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
  • PoolAddressesProvider: 0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e
  • AaveOracle: 0x54586bE62E3c3580375aE3723C145253060Ca0C2

Installation

npm install @aave/contract-helpers @aave/math-utils

Supply (Deposit)

import { Pool } from '@aave/contract-helpers'

const pool = new Pool(provider, {
  POOL: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2',
  WETH_GATEWAY: '0xD322A49006FC828F9B5B37Ab215F99B4E5caB19C',
})

// Approve + Supply
const txs = await pool.supply({ user, reserve: USDC_ADDRESS, amount: '1000', onBehalfOf: user })
for (const tx of txs) await signer.sendTransaction(await tx.tx())

Borrow

// interestRateMode: 1 = stable, 2 = variable (variable recommended)
const txs = await pool.borrow({
  user, reserve: WETH_ADDRESS, amount: '0.1',
  interestRateMode: InterestRate.Variable,
  onBehalfOf: user,
})

Flash Loan

// Contract must inherit IFlashLoanSimpleReceiver
import "@aave/core-v3/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";

contract MyFlashLoan is FlashLoanSimpleReceiverBase {
  constructor(IPoolAddressesProvider provider) FlashLoanSimpleReceiverBase(provider) {}

  function executeOperation(
    address asset, uint256 amount, uint256 premium,
    address initiator, bytes calldata params
  ) external override returns (bool) {
    // ===== Write arbitrage/liquidation logic here =====
    
    // Repay = amount + premium
    IERC20(asset).approve(address(POOL), amount + premium);
    return true;
  }

  function requestFlashLoan(address token, uint256 amount) external {
    POOL.flashLoanSimple(address(this), token, amount, "", 0);
  }
}

Health Factor & Liquidation

// Get user account data
const { totalCollateralBase, totalDebtBase, availableBorrowsBase, currentLiquidationThreshold, ltv, healthFactor } 
  = await pool.getUserAccountData(userAddress)

// healthFactor < 1e18 = liquidatable
// healthFactor = totalCollateral * liquidationThreshold / totalDebt

E-Mode (Efficiency Mode)

  • E-Mode allows correlated assets (e.g., ETH ecosystem) to achieve higher LTV (up to 97%)
  • Enable with pool.setUserEMode(categoryId)
  • Only assets within the categoryId can be used as collateral

Common Pitfalls

  • Flash loan premium = 0.05%, must repay amount + premium
  • Variable rates fluctuate with market conditions, unsuitable for long-term unmonitored positions
  • Health factor dropping below 1.0 triggers immediate liquidation, set up alerts
  • aTokens (e.g., aUSDC) are interest-bearing tokens, balance grows continuously