Links
Comment on page

Lending Pool

The LendingPool contract is the main contract of the protocol. It exposes all the user-oriented actions that can be invoked using either Solidity or web3 libraries. The source code can be found here.
Web3 code samples exclude the imports and transaction related parts to focus on methods interactions.
If you need development support, join the #developers channel on our Aave community Discord server.

Methods

deposit()

function deposit( address _reserve, uint256 _amount, uint16 _referralCode)
Deposits a certain _amount of an asset specified by the _reserve parameter.
The caller receives a certain amount of corresponding aTokens in exchange. aTokens are 1:1 redeemable for the underlying token. For more info, see the aTokens section.
For _referralCode input explanations, please refer to the referral program section of this documentation. During testing, you can use the referral code: 0.
When depositing an ERC-20 token, the LendingPoolCore contract (which is different from the LendingPool contract) will need to have the relevant allowance via approve() of _amount for the underlying ERC20 of the _reserve asset you are depositing.
Parameter Name
Type
Description
_reserve
address
address of the underlying asset​
_amount
uint256
amount deposited, expressed in decimal units
_referralCode
uint256
referral code for our referral program​

ETH deposits

Our protocol doesn't use any EIP-20 wrapper such as wETH for ETH deposits, therefore amount parameter of deposit() method must match the msg.value parameter of the transaction, and be included in your deposit() call.
E.g: lendingPool.deposit{ value: msg.value }(reserve, msg.value, referralCode)
Since ETH is used directly in the protocol (instead of an abstraction such as WETH), we use a mock address to indicate ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE

ERC20 deposits

The _reserve parameter corresponds to the ERC20 contract address of the underlying asset.
Solidity
Web3.js
// Import interface for ERC20 standard
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
​
// ... rest of your contract ...
​
// Retrieve LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
uint16 referral = 0;
​
// Approve LendingPool contract to move your DAI
IERC20(daiAddress).approve(provider.getLendingPoolCore(), amount);
​
// Deposit 1000 DAI
lendingPool.deposit(daiAddress, amount, referral);
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import DaiTokenABI from "./DAItoken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
​
// ... The rest of your code ...
​
// Input variables
const daiAmountinWei = web3.utils.toWei("1000", "ether").toString()
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAI
const referralCode = '0'
const userAddress = 'YOUR_WALLET_ADDRESS'
​
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
​
// Get the latest LendingPoolCore address
const lpCoreAddress = await lpAddressProviderContract.methods
.getLendingPoolCore()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Approve the LendingPoolCore address with the DAI contract
const daiContract = new web3.eth.Contract(DAITokenABI, daiAddress)
await daiContract.methods
.approve(
lpCoreAddress,
daiAmountinWei
)
.send()
.catch((e) => {
throw Error(`Error approving DAI allowance: ${e.message}`)
})
​
// Get the latest LendingPool contract address
const lpAddress = await lpAddressProviderContract.methods
.getLendingPool()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Make the deposit transaction via LendingPool contract
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
await lpContract.methods
.deposit(
daiAddress,
daiAmountinWei,
referralCode
)
.send()
.catch((e) => {
throw Error(`Error depositing to the LendingPool contract: ${e.message}`)
})
The deposit() flow within the protocol

setUserUseReserveAsCollateral()

function setUserUseReserveAsCollateral(address _reserve, bool _useAsCollateral)
Enable the user's specific deposit to be used as collateral. Users will only be able to disable deposits that are not currently being used as collateral.
Parameter Name
Type
Description
_reserve
address
address of the underlying asset​
_useAsCollateral
bool
if true, the asset is allowed as a collateral for borrow
Solidity
Web3.js
/// Retrieve LendingPoolAddress
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
bool useAsCollateral = true;
​
/// setUserUseReserveAsCollateral method call
lendingPool.setUserUseReserveAsCollateral(daiAddress, useAsCollateral);
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
​
// input variables
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet
const useAsCollateral = true
​
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
​
// Get the latest LendingPool contract address
const lpAddress = await lpAddressProviderContract.methods
.getLendingPool()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Set user reserve as collateral
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
await lpContract.methods
.setUserUseReserveAsCollateral(
daiAddress,
useAsCollateral
)
.send()
.catch((e) => {
throw Error(`Error setting user reserve as collateral in the LendingPool contract: ${e.message}`)
})

borrow()

function borrow(address _reserve, uint256 _amount, uint256 _interestRateMode, uint16 _referralCode)
Transfers a specific amount of the asset identified by the _reserve parameter to the msg.sender, provided that the caller has preemptively deposited enough collateral to cover the borrow.
Every borrow can be opened with a stable or variable rate mode. Borrows have infinite duration and there is no repayment schedule. In case of price fluctuations, a borrow position is liquidated if the price of the collateral drops below a certain threshold. Please refer to the White Paper to understand how the stable rate economy works.
For _referralCode input explanations, please refer to the referral program section of this documentation. During testing, you can use the referral code: 0.
In our documentation and elsewhere, we refer to stable rates instead of the deprecated fixed rates. However in the audited smart contract code, the term fixed rate remains in use.
Parameter Name
Type
Description
_reserve
address
address of the underlying asset​
_amount
uint256
amount to borrow, expressed in decimal units
_interestRateMode
uint256
type of interest rate mode to use, with uint 2 representing variable rate and uint 1 representing stable rate
_referralCode
uint256
referral code for our referral program​
Solidity
Web3.js
/// Retrieve LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
​
/// 1 is stable rate, 2 is variable rate
uint256 variableRate = 2;
uint256 referral = 0;
​
/// Borrow method call
lendingPool.borrow(daiAddress, amount, variableRate, referral);
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
​
// input variables
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet
const daiAmountinWei = web3.utils.toWei("1000", "gwei")
const interestRateMode = 2 // variable rate
const referralCode = '0'
​
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
​
// Get the latest LendingPool contract address
const lpAddress = await lpAddressProviderContract.methods
.getLendingPool()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Make the borrow transaction via LendingPool contract
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
await lpContract.methods
.borrow(
daiAddress,
daiAmountinWei,
interestRateMode,
referralCode
)
.send()
.catch((e) => {
throw Error(`Error with borrow() call to the LendingPool contract: ${e.message}`)
})
The borrow() flow within the protocol

repay()

function repay( address _reserve, uint256 _amount, address payable _onBehalfOf)
Repay a borrowed asset, either fully or partially. The _onBehalfOf parameter can be used to repay the debt of a different user.
When a third-party is repaying another user debt on their behalf, the third-party address needs to approve() the LendingPoolCore contract (which is different from the LendingPool contract) with _amount of the underlying ERC20 of the _reserve contract.
Parameter Name
Type
Description
_reserve
address
address of the underlying asset​
_amount
uint256
amount to repay, expressed in decimal units. To repay the whole borrowed amount, the function accepts uint(-1) as a value for _amount, ONLY when the repayment is not executed on behalf of a 3rd party.
In case of repayments on behalf of another user, it's recommended to send an _amount slightly higher than the current borrowed amount.
_onBehalfOf
address payable
address to repay on behalf of. If the caller is repaying their own loan, then this value should be equal to msg.sender
Solidity
Web3.js
// Import interface for ERC20 standard (only needed if repaying onBehalfOf)
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
​
/// Retrieve LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
​
/// If repaying own loan
lendingPool.repay(daiAddress, amount, msg.sender);
​
/// If repaying on behalf of someone else
address userAddress = /*users_address*/;
IERC20(daiAddress).approve(provider.getLendingPoolCore(), amount); // Approve LendingPool contract
lendingPool.repay(daiAddres, amount, userAddress);
​
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import DaiTokenABI from "./DAItoken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
​
// Input variables
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const daiAmountinWei = web3.utils.toWei("1000", "ether")
​
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
​
// Get the latest LendingPool contract address
const lpAddress = await lpAddressProviderContract.methods
.getLendingPool()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
​
/*
If repaying own loan...
*/
const myAddress = 'YOUR_ADDRESS'
​
// Make the repay transaction via LendingPool contract
await lpContract.methods
.repay(
daiAddress,
daiAmountinWei,
myAddress
)
.send()
.catch((e) => {
throw Error(`Error in repay() call to the LendingPool contract: ${e.message}`)
})
​
/*
If repaying loan on behalf of someone else...
*/
const userAddress = 'USER_ADDRESS'
​
// Approve the LendingPoolCore address with the DAI contract
const daiContract = new web3.eth.Contract(DaiTokenABI, daiAddress)
await daiContract.methods
.approve(
lpCoreAddress,
daiAmountinWei
)
.send()
.catch((e) => {
throw Error(`Error approving DAI allowance: ${e.message}`)
})
​
// Make the repay transaction via LendingPool contract
await lpContract.methods
.repay(
daiAddress,
daiAmountinWei,
userAddress
)
.send()
.catch((e) => {
throw Error(`Error in repay() call to the LendingPool contract: ${e.message}`)
})
The repay() flow within the protocol

swapBorrowRateMode()

function swapBorrowRateMode(address _reserve)
Swaps the msg.sender's borrow rate modes between stable and variable.
Parameter Name
Type
Description
_reserve
address
address of the underlying asset​
Solidity
Web3.js
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
​
/// swapBorrowRateMode method call
lendingPool.swapBorrowRateMode(daiAddress);
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
​
// input variables
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
​
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
​
// Get the latest LendingPool contract address
const lpAddress = await lpAddressProviderContract.methods
.getLendingPool()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Make the swap rate transaction via LendingPool contract
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
await lpContract.methods
.swapBorrowRateMode(
daiAddress
)
.send()
.catch((e) => {
throw Error(`Error with swap rate call to the LendingPool contract: ${e.message}`)
})

rebalanceStableBorrowRate()

function rebalanceStableBorrowRate(address _reserve, address _user)
Rebalances the stable rate of _user. If the user is not borrowing at a stable rate or the conditions for the rebalance are not satisfied, the transaction gets reverted.
Please refer to the White Paper for details on how and when a user position can be rebalanced.
Parameter Name
Type
Description
_reserve
address
address of the underlying asset​
_user
address
address of the user to rebalance
Solidity
Web3.js
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
address rebalancedUser = /*address_to_rebalance*/;
​
/// rebalanceStableBorrowRate method call
lendingPool.rebalanceStableBorrowRate(daiAddress, rebalancedUser);
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
​
// input variables
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const myAddress = 'YOUR_ADDRESS'
​
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
​
// Get the latest LendingPool contract address
const lpAddress = await lpAddressProviderContract.methods
.getLendingPool()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Make the rebalance transaction via LendingPool contract
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
await lpContract.methods
.rebalanceFixedBorrowRate(
daiAddress,
myAddress
)
.send()
.catch((e) => {
throw Error(`Error with rebalance call to the LendingPool contract: ${e.message}`)
})
The rebalance flow for stable rates in the protocol

liquidationCall()

function liquidationCall(address _collateral, address _reserve, address _user, uint256 _purchaseAmount, bool _receiveaToken)
Liquidate positions with a health factor below 1. Also see our Liquidations guide.
When the health factor of a position is below 1, liquidators repay part or all of the outstanding borrowed amount on behalf of the borrower, while receiving a discounted amount of collateral in return (also known as a liquidation 'bonus"). Liquidators can decide if they want to receive an equivalent amount of collateral aTokens, or the underlying asset directly. When the liquidation is completed successfully, the health factor of the position is increased, bringing the health factor above 1.
Liquidators can only close a certain amount of collateral defined by a close factor. Currently the close factor is 0.5. In other words, liquidators can only liquidate a maximum of 50% of the amount pending to be repaid in a position. The discount for liquidating is in terms of this amount.
Liquidators must approve() the LendingPoolCore contract (which is different from the LendingPool contract) to use _purchaseAmount of the underlying ERC20 of the _reserve asset used for the liquidation.
NOTES
  • In most scenarios, profitable liquidators will choose to liquidate as much as they can (50% of the _user position).
  • _purchaseAmount parameter can be set to uint(-1) and the protocol will proceed with the highest possible liquidation allowed by the close factor.
  • For ETH liquidations, msg.value of the transaction should be equal to the _purchaseAmount parameter.
  • To check a user's health factor, use getUserAccountData().
Parameter Name
Type
Description
_collateral
address
address of the liquidated collateral reserve
_reserve
address
address of the underlying asset for the loan
_user
address
address of the user borrowing
_purchaseAmount
uint256
amount of the discounted purchase
_receiveaToken
bool
if true, the user receives the aTokens equivalent of the purchased collateral. If false, the user receives the underlying asset directly
Solidity
Web3.js
/// Import interface for ERC20 standard
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
​
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
/// Input variables
address collateralAddress = /*collateral_address*/;
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
address userAddress = /*user_address_being_liquidated*/;
uint256 purchaseAmount = 100 * 1e18;
bool receiveATokens = true;
​
/// Approve LendingPool contract to move your DAI
IERC20(daiAddress).approve(provider.getLendingPoolCore(), purchaseAmount);
​
/// LiquidationCall method call
lendingPool.liquidationCall(
collateralAddress,
daiAddress,
userAddress,
purchaseAmount,
receiveATokens
);
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
import DaiTokenABI from "./DAItoken.json"
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
import LendingPoolABI from "./LendingPool.json"
​
// Input variables
const collateralAddress = "COLLATERAL_ADDRESS"
const daiAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
const userLiquidated = "USER_BEING_LIQUIDATED"
const purchaseAmount = web3.utils.toWei("100", "ether")
const receiveATokens = true
​
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
​
// Get the latest LendingPoolCore address
const lpCoreAddress = await lpAddressProviderContract.methods
.getLendingPoolCore()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Approve the LendingPoolCore address with the DAI contract
const daiContract = new web3.eth.Contract(DaiTokenABI, daiAddress)
await daiContract.methods
.approve(
lpCoreAddress,
purchaseAmount
)
.send()
.catch((e) => {
throw Error(`Error approving DAI allowance: ${e.message}`)
})
​
// Get the latest LendingPool contract address
const lpAddress = await lpAddressProviderContract.methods
.getLendingPool()
.call()
.catch((e) => {
throw Error(`Error getting lendingPool address: ${e.message}`)
})
​
// Liquidate the position via LendingPool contract
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
await lpContract.methods
.liquidationCall(
collateralAddress,
daiAddress,
userLiquidated,
purchaseAmount,
receiveATokens
)
.send()
.catch((e) => {
throw Error(`Error with liquidate call to the LendingPool contract: ${e.message}`)
})
The liquidation flow in the protocol

flashLoan()

function flashLoan(address payable _receiver, address _reserve, uint _amount, bytes memory _params) external
Allows the calling contract to borrow (without collateral) from the _reserve pool, a certain _amount of liquidity, that must be returned before the end of the transaction.
Since the Flash Loan occurs within 1 transaction, it is only possible to call this function successfully on the smart contract level (i.e. Solidity or Vyper).
Need help implementing a Flash Loan? See the Flash Loan tutorial and/or join the #development channel on our discord.
Flash Loans incur a fee of 0.09% of the loan amount.
Parameter Name
Type
Description
_receiver
address, payable
address of the receiver of the borrowed assets
_reserve
address
address of the underlying asset​
_amount
uint256
amount to be received
_params
bytes
bytes-encoded extra parameters to use inside the executeOperation() function
Solidity
/**
* Flash Loan of 1000 DAI.
* See the full tutorial here: https://docs.aave.com/developers/tutorials/performing-a-flash-loan
*/
​
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
LendingPool lendingPool = LendingPool(provider.getLendingPool());
​
/// Input variables
​
/* the receiver is a contract that implements the IFLashLoanReceiver interface */
address receiver = /*contract_address*/;
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
​
// If no params are needed, use an empty params:
bytes memory params = "";
// Else encode the params like below (bytes encoded param of type `address` and `uint`)
// bytes memory params = abi.encode(address(this), 1234);
​
/// flashLoan method call
lendingPool.flashLoan(receiver, daiAddress, amount, params);
The Flash Loan flow in the protocol

View Methods

getReserveConfigurationData()

function getReserveConfigurationData(address _reserve)
Returns specific reserve's configuration parameters.
return name
Type
Description
ltv
uint256
Loan-to-value. Value in percentage
liquidationThreshold
uint256
liquidation threshold. Value in percentage
liquidationDiscount
uint256
liquidation bonus. Value in percentage
interestRateStrategyAddress
address
address of the contract defining the interest rate strategy
usageAsCollateralEnabled
bool
if true, reserve asset can be used as collateral for borrowing
borrowingEnabled
bool
if true, reserve asset can be borrowed
stableBorrowRateEnabled
bool
if true, reserve asset can be borrowed with stable rate mode
isActive
bool
if true, users can interact with reserve asset

getReserveData()

function getReserveData(address _reserve)
Returns global information on any asset reserve pool
return name
Type
Description
totalLiquidity
uint256
reserve total liquidity
availableLiquidity
uint256
reserve available liquidity for borrowing
totalBorrowsStable
uint256
total amount of outstanding borrows at Stable rate
totalBorrowsVariable
uint256
total amount of outstanding borrows at Variable rate
liquidityRate
uint256
current deposit APY of the reservefor depositors, in Ray units.
variableBorrowRate
uint256
current variable rate APY of the reserve pool, in Ray units.
stableBorrowRate
uint256
current stable rate APY of the reserve pool, in Ray units.
averageStableBorrowRate
uint256
current average stable borrow rate
utilizationRate
uint256
expressed as total borrows/total liquidity.
liquidityIndex
uint256
cumulative liquidity index
variableBorrowIndex
uint256
cumulative variable borrow index
aTokenAddress
address
aTokens contract address for the specific _reserve
lastUpdateTimestamp
uint40
timestamp of the last update of reserve data

getUserAccountData()

function getUserAccountData(address _user)
Returns information of a reserve exclusively related with a particular user address
return name
Type