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 |
| address | address of the underlying asset |
| uint256 | amount deposited, expressed in decimal units |
| 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.
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 |
| address | address of the underlying asset |
| bool | if true, the asset is allowed as a collateral for borrow |
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 |
| address | address of the underlying asset |
| uint256 | amount to borrow, expressed in decimal units |
| uint256 | type of interest rate mode to use, with |
| uint256 | referral code for our referral program |
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 |
| address | address of the underlying asset |
| uint256 | amount to repay, expressed in decimal units. To repay the whole borrowed amount, the function accepts In case of repayments on behalf of another user, it's recommended to send an |
| address payable | address to repay on behalf of. If the caller is repaying their own loan, then this value should be equal to |
swapBorrowRateMode()
function swapBorrowRateMode(address _reserve)
Swaps the msg.sender
's borrow rate modes between stable and variable.
Parameter Name | Type | Description |
| address | address of the underlying asset |
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 |
| address | address of the underlying asset |
| address | address of the |
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 touint(-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 |
| address | address of the liquidated collateral reserve |
| address | address of the underlying asset for the loan |
| address | address of the user borrowing |
| uint256 | amount of the discounted purchase |
| bool | if true, the user receives the aTokens equivalent of the purchased collateral. If false, the user receives the underlying asset directly |
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 |
| address, payable | address of the |
| address | address of the underlying asset |
| uint256 | amount to be received |
| bytes | bytes-encoded extra parameters to use inside the |
View Methods
getReserveConfigurationData()
function getReserveConfigurationData(address _reserve)
Returns specific reserve's configuration parameters.
| 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 |
borrowingEnabled | bool | if |
stableBorrowRateEnabled | bool | if |
isActive | bool | if |
getReserveData()
function getReserveData(address _reserve)
Returns global information on any asset reserve
pool
| Type | Description |
totalLiquidity | uint256 |
|
availableLiquidity | uint256 |
|
totalBorrowsStable | uint256 | total amount of outstanding borrows at Stable rate |
totalBorrowsVariable | uint256 | total amount of outstanding borrows at Variable rate |
liquidityRate | uint256 | |
variableBorrowRate | uint256 | |
stableBorrowRate | uint256 | |
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 |
lastUpdateTimestamp | uint40 | timestamp of the last update of |
getUserAccountData()
function getUserAccountData(address _user)
Returns information of a reserve exclusively related with a particular user
address
| Type | Description |
totalLiquidityETH | uint256 |
|
totalCollateralETH | uint256 |
|
totalBorrowsETH | uint256 |
|
totalFeesETH | uint256 |
|
availableBorrowsETH | uint256 |
|
currentLiquidationThreshold | uint256 |
|
ltv | uint256 |
|
healthFactor | uint256 |
|
getUserReserveData()
function getUserReserveData(address _reserve, address _user)
Returns information related to the user
data on a specific reserve
| Type | Description |
currentATokenBalance | uint256 |
|
currentBorrowBalance | uint256 |
|
principalBorrowBalance | uint256 |
|
borrowRateMode | uint256 |
|
borrowRate | uint256 |
|
liquidityRate | uint256 |
|
originationFee | uint256 |
|
variableBorrowIndex | uint256 |
|
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
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_amount | uint256 | amount deposited, in Wei. |
_referral | uint16 |
|
_timestamp | uint256 | timestamp of the transaction, in Unix time |
RedeemUnderlying
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_amount | uint256 | amount redeemed, in Wei. |
_timestamp | uint256 | timestamp of the transaction, in Unix time |
Borrow
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_amount | uint256 | amount borrowed, in Wei. |
_borrowRateMode | uint256 | interest rate mode |
_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 |
|
_timestamp | uint256 | timestamp of the transaction, in Unix time |
Repay
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_repayer | address | address of the |
_amountMinusFees | uint256 | amount repayed, without fees. |
_fees | uint256 | fees paid |
_borrowBalanceIncrease | uint256 | amount of debt increased since the last update by the user, in Wei. |
_timestamp | uint256 | timestamp of the transaction, in Unix time |
Swap
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_newRateMode | uint256 | interest rate mode |
_newRate | uint256 | |
_borrowBalanceIncrease | uint256 | amount of debt increased since the last update by the user, in Wei. |
_timestamp | uint256 | timestamp of the transaction, in Unix time |
ReserveUsedAsCollateralEnabled
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
ReserveUsedAsCollateralDisabled
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
RebalanceStableBorrowRate
| type | description |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_newStableRate | uint256 | |
_borrowBalanceIncrease | uint256 | amount of debt increased by the new borrow, |
_timestamp | uint256 | timestamp of the transaction, in Unix time |
FlashLoan
| type | description |
_target | address | address of the smart contract receiving the flashLoan, |
_reserve | address | address of the underlying asset |
_amount | uint256 | amount borrowed, in Wei. |
_totalFee | uint256 | FlashLoans fee paid by the borrower, currently set at 9 bps. In Wei. |
_protocolFee | uint256 | fee for the protocol, currently set at 30% of the |
_timestamp | uint256 | timestamp of the transaction, in Unix time |
OriginationFeeLiquidated
| type | description |
_collateral | address | address of the contract of collateral asset being liquidated |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_feeLiquidated | uint256 | amount of the fee liquidated denominated in borrowed currency, in Wei |
_liquidatedCollateralForFee | uint256 | amount of collateral liquidated to pay for the fee + liquidation bonus, in Wei |
_timestamp | uint256 | timestamp of the transaction, in Unix time |
LiquidationCall
| type | description |
_collateral | address | address of the contract of collateral asset being liquidated |
_reserve | address | address of the underlying asset |
_user | address | address of the |
_purchaseAmount | uint256 | amount of the liquidation, in Wei. |
_liquidatedCollateralAmount | uint256 | amount of collateral being liquidated |
_accruedBorrowInterest | uint256 | amount of debt increased since the last update by the user, in Wei. |
_liquidator | address | address of the liquidator |
_receiveAToken | Bool |
|
_timestamp | uint256 | timestamp of the transaction, in Unix time |
Last updated