LendingPool

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 on Github here.

If you need development support, join the #developers channel on the Aave community Discord server.

Methods

deposit()

Deposits a certain amount of an asset into the protocol, minting the same amount of corresponding aTokens, and transferring them to the onBehalfOf address.

For referralCode input explanations, please refer to the referral program section of the documentation. During testing, you can use the referral code: 0.

When depositing, the LendingPool contract must have at least an allowance() of amount for the asset being deposited. This can be done via the standard ERC20 approve() method.

 Parameter Name Type Description asset address address of the underlying asset​ amount uint256 amount deposited, expressed in wei units onBehalfOf address address whom will receive the aTokens. Use msg.sender when the aTokens should be sent to the caller. referralCode uint16 referral code for our referral program. Use 0 for no referral.

withdraw()

Withdraws amount of the underlying asset, i.e. redeems the underlying token and burns the aTokens.

Ensure you set the relevant ERC20 allowance of the aToken, before calling this function, so the LendingPool contract can burn the associated aTokens.

 ​
 Parameter Name Type Description asset address address of the underlying asset, not the aToken amount uint256 amount deposited, expressed in wei units. Use type(uint).max to withdraw the entire balance. to address address that will receive the asset

borrow()

Borrows amount of asset with interestRateMode, sending the amount to msg.sender, with the debt being incurred by onBehalfOf.

Note: onBehalfOf must have enough collateral via deposit() or have delegated credit to msg.sender via approveDelegation(). See the Credit Delegation guide for more details.

 Parameter Name Type Description asset address address of the underlying asset​ amount uint256 amount to be borrowed, expressed in wei units interestRateMode uint256 the type of borrow debt.Stable: 1, Variable: 2 referralCode uint16 referral code for our referral program. Use 0 for no referral code. onBehalfOf address address of user who will incur the debt.Use msg.sender when not calling on behalf of a different user.

repay()

Repays onBehalfOf's debt amount of asset which has a rateMode.

 Parameter Name Type Description asset address address of the underlying asset​ amount uint256 amount to be borrowed, expressed in wei units.Use uint(-1) to repay the entire debt, 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. rateMode uint256 the type of borrow debt.Stable: 1, Variable: 2 onBehalfOf address address of user who will incur the debt.Use msg.sender when not calling on behalf of a different user.

swapBorrowRateMode()

Swaps the msg.sender's borrow rate modes between stable and variable.

 Parameter Name Type Description asset address address of the underlying asset​ rateMode uint256 the rate mode.Stable: 1, Variable: 2

setUserUseReserveAsCollateral()

Sets the asset of msg.sender to be used as collateral or not.

 Parameter Name Type Description asset address address of the underlying asset​ useAsCollateral bool true if the asset should be used as collateral

liquidationCall()

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 liquidation discount applies to this amount.

Liquidators must approve() the LendingPool contract to use debtToCover of the underlying ERC20 of theasset used for the liquidation.

NOTES

• In most scenarios, profitable liquidators will choose to liquidate as much as they can (50% of the user position).

• debtToCover parameter can be set to uint(-1) and the protocol will proceed with the highest possible liquidation allowed by the close factor.

• To check a user's health factor, use getUserAccountData().

 Parameter Name Type Description collateral address address of the collateral reserve debt address address of the debt reserve user address address of the borrower debtToCover uint256 amount of asset debt that the liquidator will repay receiveAToken bool if true, the user receives the aTokens equivalent of the purchased collateral. If false, the user receives the underlying asset directly.

flashLoan()

Sends the requested amounts of assets to the receiverAddress contract, passing the included params.

If the flash loaned amounts + fee is not returned by the end of the transaction, then the transaction will either:

• revert if the associated mode is 0,

• onBehalfOf incurs a stable debt if mode is 1, or

• onBehalfOf incurs a variable debt if mode is 2.

Your contract which receives the flash loaned amounts must conform to the IFlashLoanReceiver interface. For more, see the flash loan guides.

View Methods

getReserveData()

Returns the state and configuration of the reserve

getUserAccountData()

Returns the user account data across all the reserves

Return values

 Parameter Name Type Description totalCollateralETH uint256 total collateral in ETH of the user totalDebtETH uint256 total debt in ETH of the user availableBorrowsETH uint256 borrowing power left of the user currentLiquidationThreshold uint256 liquidation threshold of the user ltv uint256 Loan To Value of the user healthFactor uint256 current health factor of the user.Also see liquidationCall()​

getConfiguration()

Returns the configuration of the reserve

Return values

 Return Type Description uint256 See the whitepaper for details on why a bitmask was used.bit 0-15: LTVbit 16-31: Liq. thresholdbit 32-47: Liq. bonusbit 48-55: Decimalsbit 56: reserve is activebit 57: reserve is frozenbit 58: borrowing is enabledbit 59: stable rate borrowing enabledbit 60-63: reservedbit 64-79: reserve factor

getUserConfiguration()

Returns the configuration of the user across all the reserves.

Return values

 Return Type Description uint256 See the whitepaper for details on why a bitmask was used.The bitmask is divided into pairs of bits, one pair for each asset. ​The first bit of the pair indicates if it is being used as collateral by the user, the second bit indicates if it is being borrowed. The corresponding assets are in the same position as getReservesList() For example, if the hex value returned is 0x40020, which represents a decimal value of 262176, then in binary it is 1000000000000100000. If we format the binary value into pairs, starting from the right, we get 1 00 00 00 00 00 00 10 00 00.If we start from the right and move left in the above binary pairs, the third pair is 10. The third reserve listed in getReserveList() is WETH. Therefore the 1 indicates that WETH is used as collateral, and 0 indicates that WETH has not been borrowed by this user. If we continue to go to the end of the binary pairs (furthest left), we have 1 which can also be represented as 01. This is the 10th pair, which in getReserveList() is DAI. Therefore the 0 indicates that DAI is not used as collateral, and the 1 indicates that it is being borrowed by this user.In short, if a user is using WETH as collateral and has borrowed DAI, then the value returned would be 0x40020 (in hex) or 262176 (in decimal).

getReserveNormalizedIncome()

Returns the normalized income per unit of asset.

A return value of $1e27$ indicates no income. As time passes, the income is accrued. A value of $2 * 1e27$ indicates that for each unit of asset, two units of income have been accrued.

getReserveNormalizedVariableDebt()

Returns the normalized variable debt per unit of asset.

A return value of $1e27$ indicates no debt. As time passes, the debt is accrued. A value of $2 * 1e27$ indicates that for each unit of asset, two units of debt have been accrued.

paused()

function paused()

Returns true if the LendingPool is paused.

getReservesList()

function getReservesList()

Returns the list of initialized reserves.