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
1
// Import interface for ERC20 standard
2
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
3
4
// ... rest of your contract ...
5
6
// Retrieve LendingPool address
7
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
8
LendingPool lendingPool = LendingPool(provider.getLendingPool());
9
10
// Input variables
11
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
12
uint256 amount = 1000 * 1e18;
13
uint16 referral = 0;
14
15
// Approve LendingPool contract to move your DAI
16
IERC20(daiAddress).approve(provider.getLendingPoolCore(), amount);
17
18
// Deposit 1000 DAI
19
lendingPool.deposit(daiAddress, amount, referral);
Copied!
1
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
2
import DaiTokenABI from "./DAItoken.json"
3
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
4
import LendingPoolABI from "./LendingPool.json"
5
6
// ... The rest of your code ...
7
8
// Input variables
9
const daiAmountinWei = web3.utils.toWei("1000", "ether").toString()
10
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet DAI
11
const referralCode = '0'
12
const userAddress = 'YOUR_WALLET_ADDRESS'
13
14
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
15
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
16
17
// Get the latest LendingPoolCore address
18
const lpCoreAddress = await lpAddressProviderContract.methods
19
.getLendingPoolCore()
20
.call()
21
.catch((e) => {
22
throw Error(`Error getting lendingPool address: ${e.message}`)
23
})
24
25
// Approve the LendingPoolCore address with the DAI contract
26
const daiContract = new web3.eth.Contract(DAITokenABI, daiAddress)
27
await daiContract.methods
28
.approve(
29
lpCoreAddress,
30
daiAmountinWei
31
)
32
.send()
33
.catch((e) => {
34
throw Error(`Error approving DAI allowance: ${e.message}`)
35
})
36
37
// Get the latest LendingPool contract address
38
const lpAddress = await lpAddressProviderContract.methods
39
.getLendingPool()
40
.call()
41
.catch((e) => {
42
throw Error(`Error getting lendingPool address: ${e.message}`)
43
})
44
45
// Make the deposit transaction via LendingPool contract
46
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
47
await lpContract.methods
48
.deposit(
49
daiAddress,
50
daiAmountinWei,
51
referralCode
52
)
53
.send()
54
.catch((e) => {
55
throw Error(`Error depositing to the LendingPool contract: ${e.message}`)
56
})
Copied!
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
1
/// Retrieve LendingPoolAddress
2
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
3
LendingPool lendingPool = LendingPool(provider.getLendingPool());
4
5
/// Input variables
6
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
7
bool useAsCollateral = true;
8
9
/// setUserUseReserveAsCollateral method call
10
lendingPool.setUserUseReserveAsCollateral(daiAddress, useAsCollateral);
Copied!
1
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
2
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
3
import LendingPoolABI from "./LendingPool.json"
4
5
// input variables
6
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet
7
const useAsCollateral = true
8
9
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
10
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
11
12
// Get the latest LendingPool contract address
13
const lpAddress = await lpAddressProviderContract.methods
14
.getLendingPool()
15
.call()
16
.catch((e) => {
17
throw Error(`Error getting lendingPool address: ${e.message}`)
18
})
19
20
// Set user reserve as collateral
21
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
22
await lpContract.methods
23
.setUserUseReserveAsCollateral(
24
daiAddress,
25
useAsCollateral
26
)
27
.send()
28
.catch((e) => {
29
throw Error(`Error setting user reserve as collateral in the LendingPool contract: ${e.message}`)
30
})
Copied!

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
1
/// Retrieve LendingPool address
2
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
3
LendingPool lendingPool = LendingPool(provider.getLendingPool());
4
5
/// Input variables
6
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
7
uint256 amount = 1000 * 1e18;
8
9
/// 1 is stable rate, 2 is variable rate
10
uint256 variableRate = 2;
11
uint256 referral = 0;
12
13
/// Borrow method call
14
lendingPool.borrow(daiAddress, amount, variableRate, referral);
Copied!
1
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
2
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
3
import LendingPoolABI from "./LendingPool.json"
4
5
// input variables
6
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // mainnet
7
const daiAmountinWei = web3.utils.toWei("1000", "gwei")
8
const interestRateMode = 2 // variable rate
9
const referralCode = '0'
10
11
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
12
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
13
14
// Get the latest LendingPool contract address
15
const lpAddress = await lpAddressProviderContract.methods
16
.getLendingPool()
17
.call()
18
.catch((e) => {
19
throw Error(`Error getting lendingPool address: ${e.message}`)
20
})
21
22
// Make the borrow transaction via LendingPool contract
23
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
24
await lpContract.methods
25
.borrow(
26
daiAddress,
27
daiAmountinWei,
28
interestRateMode,
29
referralCode
30
)
31
.send()
32
.catch((e) => {
33
throw Error(`Error with borrow() call to the LendingPool contract: ${e.message}`)
34
})
Copied!
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
1
// Import interface for ERC20 standard (only needed if repaying onBehalfOf)
2
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
3
4
/// Retrieve LendingPool address
5
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
6
LendingPool lendingPool = LendingPool(provider.getLendingPool());
7
8
/// Input variables
9
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
10
uint256 amount = 1000 * 1e18;
11
12
/// If repaying own loan
13
lendingPool.repay(daiAddress, amount, msg.sender);
14
15
/// If repaying on behalf of someone else
16
address userAddress = /*users_address*/;
17
IERC20(daiAddress).approve(provider.getLendingPoolCore(), amount); // Approve LendingPool contract
18
lendingPool.repay(daiAddres, amount, userAddress);
19
Copied!
1
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
2
import DaiTokenABI from "./DAItoken.json"
3
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
4
import LendingPoolABI from "./LendingPool.json"
5
6
// Input variables
7
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
8
const daiAmountinWei = web3.utils.toWei("1000", "ether")
9
10
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
11
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
12
13
// Get the latest LendingPool contract address
14
const lpAddress = await lpAddressProviderContract.methods
15
.getLendingPool()
16
.call()
17
.catch((e) => {
18
throw Error(`Error getting lendingPool address: ${e.message}`)
19
})
20
21
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
22
23
/*
24
If repaying own loan...
25
*/
26
const myAddress = 'YOUR_ADDRESS'
27
28
// Make the repay transaction via LendingPool contract
29
await lpContract.methods
30
.repay(
31
daiAddress,
32
daiAmountinWei,
33
myAddress
34
)
35
.send()
36
.catch((e) => {
37
throw Error(`Error in repay() call to the LendingPool contract: ${e.message}`)
38
})
39
40
/*
41
If repaying loan on behalf of someone else...
42
*/
43
const userAddress = 'USER_ADDRESS'
44
45
// Approve the LendingPoolCore address with the DAI contract
46
const daiContract = new web3.eth.Contract(DaiTokenABI, daiAddress)
47
await daiContract.methods
48
.approve(
49
lpCoreAddress,
50
daiAmountinWei
51
)
52
.send()
53
.catch((e) => {
54
throw Error(`Error approving DAI allowance: ${e.message}`)
55
})
56
57
// Make the repay transaction via LendingPool contract
58
await lpContract.methods
59
.repay(
60
daiAddress,
61
daiAmountinWei,
62
userAddress
63
)
64
.send()
65
.catch((e) => {
66
throw Error(`Error in repay() call to the LendingPool contract: ${e.message}`)
67
})
Copied!
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
1
/// Retrieve the LendingPool address
2
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
3
LendingPool lendingPool = LendingPool(provider.getLendingPool());
4
5
/// Input variables
6
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
7
8
/// swapBorrowRateMode method call
9
lendingPool.swapBorrowRateMode(daiAddress);
Copied!
1
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
2
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
3
import LendingPoolABI from "./LendingPool.json"
4
5
// input variables
6
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
7
8
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
9
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
10
11
// Get the latest LendingPool contract address
12
const lpAddress = await lpAddressProviderContract.methods
13
.getLendingPool()
14
.call()
15
.catch((e) => {
16
throw Error(`Error getting lendingPool address: ${e.message}`)
17
})
18
19
// Make the swap rate transaction via LendingPool contract
20
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
21
await lpContract.methods
22
.swapBorrowRateMode(
23
daiAddress
24
)
25
.send()
26
.catch((e) => {
27
throw Error(`Error with swap rate call to the LendingPool contract: ${e.message}`)
28
})
Copied!

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
1
/// Retrieve the LendingPool address
2
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
3
LendingPool lendingPool = LendingPool(provider.getLendingPool());
4
5
/// Input variables
6
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
7
address rebalancedUser = /*address_to_rebalance*/;
8
9
/// rebalanceStableBorrowRate method call
10
lendingPool.rebalanceStableBorrowRate(daiAddress, rebalancedUser);
Copied!
1
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
2
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
3
import LendingPoolABI from "./LendingPool.json"
4
5
// input variables
6
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
7
const myAddress = 'YOUR_ADDRESS'
8
9
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
10
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
11
12
// Get the latest LendingPool contract address
13
const lpAddress = await lpAddressProviderContract.methods
14
.getLendingPool()
15
.call()
16
.catch((e) => {
17
throw Error(`Error getting lendingPool address: ${e.message}`)
18
})
19
20
// Make the rebalance transaction via LendingPool contract
21
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
22
await lpContract.methods
23
.rebalanceFixedBorrowRate(
24
daiAddress,
25
myAddress
26
)
27
.send()
28
.catch((e) => {
29
throw Error(`Error with rebalance call to the LendingPool contract: ${e.message}`)
30
})
Copied!
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
1
/// Import interface for ERC20 standard
2
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
3
4
/// Retrieve the LendingPool address
5
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
6
LendingPool lendingPool = LendingPool(provider.getLendingPool());
7
8
/// Input variables
9
address collateralAddress = /*collateral_address*/;
10
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
11
address userAddress = /*user_address_being_liquidated*/;
12
uint256 purchaseAmount = 100 * 1e18;
13
bool receiveATokens = true;
14
15
/// Approve LendingPool contract to move your DAI
16
IERC20(daiAddress).approve(provider.getLendingPoolCore(), purchaseAmount);
17
18
/// LiquidationCall method call
19
lendingPool.liquidationCall(
20
collateralAddress,
21
daiAddress,
22
userAddress,
23
purchaseAmount,
24
receiveATokens
25
);
Copied!
1
// Import the ABIs, see: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
2
import DaiTokenABI from "./DAItoken.json"
3
import LendingPoolAddressesProviderABI from "./LendingPoolAddressesProvider.json"
4
import LendingPoolABI from "./LendingPool.json"
5
6
// Input variables
7
const collateralAddress = "COLLATERAL_ADDRESS"
8
const daiAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
9
const userLiquidated = "USER_BEING_LIQUIDATED"
10
const purchaseAmount = web3.utils.toWei("100", "ether")
11
const receiveATokens = true
12
13
const lpAddressProviderAddress = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8' // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
14
const lpAddressProviderContract = new web3.eth.Contract(LendingPoolAddressesProviderABI, lpAddressProviderAddress)
15
16
// Get the latest LendingPoolCore address
17
const lpCoreAddress = await lpAddressProviderContract.methods
18
.getLendingPoolCore()
19
.call()
20
.catch((e) => {
21
throw Error(`Error getting lendingPool address: ${e.message}`)
22
})
23
24
// Approve the LendingPoolCore address with the DAI contract
25
const daiContract = new web3.eth.Contract(DaiTokenABI, daiAddress)
26
await daiContract.methods
27
.approve(
28
lpCoreAddress,
29
purchaseAmount
30
)
31
.send()
32
.catch((e) => {
33
throw Error(`Error approving DAI allowance: ${e.message}`)
34
})
35
36
// Get the latest LendingPool contract address
37
const lpAddress = await lpAddressProviderContract.methods
38
.getLendingPool()
39
.call()
40
.catch((e) => {
41
throw Error(`Error getting lendingPool address: ${e.message}`)
42
})
43
44
// Liquidate the position via LendingPool contract
45
const lpContract = new web3.eth.Contract(LendingPoolABI, lpAddress)
46
await lpContract.methods
47
.liquidationCall(
48
collateralAddress,
49
daiAddress,
50
userLiquidated,
51
purchaseAmount,
52
receiveATokens
53
)
54
.send()
55
.catch((e) => {
56
throw Error(`Error with liquidate call to the LendingPool contract: ${e.message}`)
57
})
Copied!
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
1
/**
2
* Flash Loan of 1000 DAI.
3
* See the full tutorial here: https://docs.aave.com/developers/tutorials/performing-a-flash-loan
4
*/
5
6
/// Retrieve the LendingPool address
7
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances
8
LendingPool lendingPool = LendingPool(provider.getLendingPool());
9
10
/// Input variables
11
12
/* the receiver is a contract that implements the IFLashLoanReceiver interface */
13
address receiver = /*contract_address*/;
14
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
15
uint256 amount = 1000 * 1e18;
16
17
// If no params are needed, use an empty params:
18
bytes memory params = "";
19
// Else encode the params like below (bytes encoded param of type `address` and `uint`)
20
// bytes memory params = abi.encode(address(this), 1234);
21
22
/// flashLoan method call
23
lendingPool.flashLoan(receiver, daiAddress, amount, params);
Copied!
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
Description
totalLiquidityETH
uint256
user aggregated deposits across all the reserves. In Wei
totalCollateralETH
uint256
user aggregated collateral across all the reserves. In Wei
totalBorrowsETH
uint256
user aggregated outstanding borrows across all the reserves. In Wei
totalFeesETH
uint256
user aggregated current outstanding fees in ETH. In Wei
availableBorrowsETH
uint256
user available amount to borrow in ETH
currentLiquidationThreshold
uint256
user current average liquidation threshold across all the collaterals deposited
ltv
uint256
user average Loan-to-Value between all the collaterals
healthFactor
uint256
user current Health Factor

getUserReserveData()

function getUserReserveData(address _reserve, address _user)
Returns information related to the user data on a specific reserve
return name
Type
Description
currentATokenBalance
uint256
user current reserve aToken balance
currentBorrowBalance
uint256
user current reserve outstanding borrow balance
principalBorrowBalance
uint256
user balance of borrowed asset
borrowRateMode
uint256
user borrow rate mode either Stable or Variable
borrowRate
uint256
user current borrow rate APY
liquidityRate
uint256
user current earn rate on _reserve
originationFee
uint256
user outstanding loan origination fee
variableBorrowIndex
uint256
user variable cumulative index
lastUpdateTimestamp
uint256
Timestamp of the last data update
usageAsCollateralEnabled
bool
Whether the user's current reserve is enabled as a collateral

getReserves()

function getReserves()
Returns an array of all the active reserves addresses.

Emitted Events

The LendingPool contract produces events that can be monitored on the Ethereum blockchain. For more information on emitted events and filters, refer to the official solidity documentation.
If you are analysing data about Aave Protocol, see the GraphQL or Blockchain data section.
In Aave protocol, reserve is defined by the smart-contract of the asset used for the method interaction.
    A list of all smart-contract addresses is available in here.
    To avoid the usage of an ETH wrapper throughout the protocol (such as WETH), a mock address is used for the ETH reserve: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE

Deposit

return name
type
description
_reserve
address
address of the underlying asset
_user
address
address of the user
_amount
uint256
amount deposited, in Wei.
_referral
uint16
ReferralCode for referral programs
_timestamp
uint256
timestamp of the transaction, in Unix time

RedeemUnderlying

return name
type
description
_reserve
address
address of the underlying asset
_user
address
address of the user
_amount
uint256
amount redeemed, in Wei.
_timestamp
uint256
timestamp of the transaction, in Unix time

Borrow

return name
type
description
_reserve
address
address of the underlying asset
_user
address
address of the user
_amount
uint256
amount borrowed, in Wei.
_borrowRateMode
uint256
interest rate mode 0 for None, 1 for stable and 2 for variable
_borrowRate
uint256
APY of the loan at the time of the borrow() call. in Wei.
_originationFee
uint256
amount of the originationFee of the loan, in Ray units.
_borrowBalanceIncrease
uint256
amount of debt increased since the last update by the user, in Wei.
_referral
uint16
ReferralCode for referral programs
_timestamp
uint256
timestamp of the transaction, in Unix time

Repay

return name
type
description
_reserve
address
address of the underlying asset
_user
address
address of the user