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.
function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)
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 |
| address | address of the underlying asset​ |
| uint256 | amount deposited, expressed in wei units |
| address | address whom will receive the aTokens.
Use |
| uint16 | referral code for our referral program. Use 0 for no referral. |
function withdraw(address asset, uint256 amount, address to)
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 |
| address | address of the underlying asset, not the aToken |
| uint256 | amount deposited, expressed in wei units.
Use |
| address | address that will receive the |
function borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf)
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 |
| address | address of the underlying asset​ |
| uint256 | amount to be borrowed, expressed in wei units |
| uint256 | the type of borrow debt. Stable: 1, Variable: 2 |
| uint16 | referral code for our referral program. Use 0 for no referral code. |
| address | address of user who will incur the debt. Use |
function repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf)
Repays onBehalfOf
's debt amount
of asset
which has a rateMode
.
Parameter Name | Type | Description |
| address | address of the underlying asset​ |
| uint256 | amount to be borrowed, expressed in wei units. Use In case of repayments on behalf of another user, it's recommended to send an |
| uint256 | the type of borrow debt. Stable: 1, Variable: 2 |
| address | address of user who will incur the debt. Use |
function swapBorrowRateMode(address asset, uint256 rateMode)
Swaps the msg.sender
's borrow rate modes between stable and variable.
Parameter Name | Type | Description |
| address | address of the underlying asset​ |
| uint256 | the rate mode. Stable: 1, Variable: 2 |
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral)
Sets the asset
of msg.sender
to be used as collateral or not.
Parameter Name | Type | Description |
| address | address of the underlying asset​ |
| bool |
|
function liquidationCall(address collateral, address debt, address user, uint256 debtToCover, 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 liquidation discount applies to this amount.
Liquidators must approve()
the LendingPool
contract to use purchaseAmount
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 |
| address | address of the collateral reserve |
| address | address of the debt reserve |
| address | address of the borrower |
| uint256 | amount of |
| bool | if |
function flashLoan(address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] modes, address onBehalfOf, bytes calldata params, uint16 referralCode)
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.
Parameter Name | Type | Description |
| address | address of the contract receiving the funds. Must implement the |
|
| addresses of the reserves to flashloan |
|
| amounts of This needs to contain the same number of elements as |
|
| the types of debt to open if the flashloan is not returned. 0: Don't open any debt, just revert 1: stable mode debt 2: variable mode debt |
| address | if the associated Note: |
| bytes | bytes-encoded parameters to be used by the |
| uint16 | referral code for our referral program​ |
function getReserveData(address asset)
Returns the state and configuration of the reserve
Parameter Name | Type | Description |
| address | address of the reserve |
Parameter Name | Type | Description |
| uint256 | See the whitepaper for details on why a bitmask was used. To find out more about these values, see the Risk docs. bit 0-15: LTV bit 16-31: Liq. threshold bit 32-47: Liq. bonus bit 48-55: Decimals bit 56: reserve is active bit 57: reserve is frozen bit 58: borrowing is enabled bit 59: stable rate borrowing enabled bit 60-63: reserved bit 64-79: reserve factor |
| uint128 | liquidity index in ray |
| uint128 | variable borrow index in ray |
| uint128 | current supply / liquidity / deposit rate in ray |
| uint128 | current variable borrow rate in ray |
| uint128 | current stable borrow rate in ray |
| uint40 | timestamp of when reserve data was last updated |
| address | address of associated aToken (tokenised deposit) |
| address | address of associated stable debt token |
| address | address of associated variable debt token |
| address | address of interest rate strategy. See Risk docs for more info. |
| uint8 | the position in the list of active reserves |
function getUserAccountData(address user)
Returns the user account data across all the reserves
Parameter Name | Type | Description |
| address | address of the user |
Parameter Name | Type | Description |
| uint256 | total collateral in ETH of the user |
| uint256 | total debt in ETH of the user |
| uint256 | borrowing power left of the user |
| uint256 | liquidation threshold of the user |
| uint256 | Loan To Value of the user |
| uint256 | current health factor of the user. Also see |
function getConfiguration(address asset)
Returns the configuration of the reserve
Parameter Name | Type | Description |
| address | address of the reserve |
Return Type | Description |
uint256 | See the whitepaper for details on why a bitmask was used. bit 0-15: LTV bit 16-31: Liq. threshold bit 32-47: Liq. bonus bit 48-55: Decimals bit 56: reserve is active bit 57: reserve is frozen bit 58: borrowing is enabled bit 59: stable rate borrowing enabled bit 60-63: reserved bit 64-79: reserve factor |
function getUserConfiguration(address user)
Returns the configuration of the user across all the reserves.
Parameter Name | Type | Description |
| address | address of the user |
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 bit 0: Indicates whether Asset 0 is being used as collateral bit 1: Indicates whether Asset 0 is being borrowed bit 2: Indicates whether Asset 1 is being used as collateral bit 3: Indicates whether Asset 1 is being borrowed ... bit 255: Indicates whether Asset 128 is being used as collateral bit 256: Indicates whether Asset 128 is being borrowed |
function getReserveNormalizedIncome(address asset)
Returns the normalized income per unit of asset
.
A return value of indicates no income. As time passes, the income is accrued. A value of indicates that for each unit of asset, two units of income have been accrued.
Parameter Name | Type | Description |
| address | address of the reserve |
function getReserveNormalizedVariableDebt(address asset)
Returns the normalized variable debt per unit of asset
.
A return value of indicates no debt. As time passes, the debt is accrued. A value of indicates that for each unit of asset, two units of debt have been accrued.
Parameter Name | Type | Description |
| address | address of the reserve |
function paused()
Returns true
if the LendingPool is paused.
function getReservesList()
Returns the list of initialized reserves.
function getAddressesProvider()
Returns the addresses provider.
If you are making calls to the contract and receive numbered errors, you can find what the numbers represent by checking the Errors.sol
library contract.