Pool
Pool
The pool.sol
contract is the main user facing contract of the protocol. It exposes the liquidity management methods that can be invoked using either Solidity or Web3 libraries.
Write Methods
supply
function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)
The referralCode
is emitted in Supply event and can be for third party referral integrations. To activate referral feature and obtain a unique referral code, integrators need to submit proposal to Aave Governance.
When supplying, the Pool
contract must have**allowance()
to spend funds on behalf ofmsg.sender
** for at-least**amount
** for the asset
being supplied. This can be done via the standard ERC20 approve()
method on the underlying token contract
Referral supply is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Aave governance proposal
supplyWithPermit
function supplyWithPermit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode, uint256 deadline, uint8 permitV, permitR, bytes32 permitS)
Supply with transfer approval of supplied asset via permit function. This method removes the need for separate approval tx before supplying asset to the pool.
Permit signature must be signed by msg.sender
with spender as Pool address.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Aave governance proposal
Call Params
withdraw
function withdraw(address asset, uint256 amount, address to)
Withdraws amount
of the underlying asset
, i.e. redeems the underlying token and burns the aTokens.
If user has any existing debt backed by the underlying token, then the max amount available to withdraw is the amount that will not leave user health factor < 1 after withdrawal.
When withdrawingto
another address, msg.sender
should have aToken
that will be burned by Pool .
Call Params
borrow
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: If onBehalfOf
is not same as msg.sender
, then onBehalfOf
must have supplied enough collateral via supply()
and have delegated credit to msg.sender
via approveDelegation()
.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Aave governance proposal
Call Params
repay
function repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf)
Repays onBehalfOf
's debt amount
of asset
which has a rateMode
.
When repaying, the Pool
contract must have**allowance()
to spend funds on behalf ofmsg.sender
** for at-least**amount
** for the asset
you are repaying with. This can be done via the standard ERC20 approve()
method on the underlying token contract.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Aave governance proposal
Call Params
repayWithPermit
function repayWithPermit(address asset, uint256 amount, uint256 interestRateMode, address onBehalfOf, uint256 deadline, uint8 permitV, permitR, bytes32 permitS)
Repay with transfer approval of borrowed asset via permit function. This method removes the need for separate approval tx before repaying asset to the pool.
Permit signature must be signed by msg.sender
with spender value as Pool
address.
Call Params
repayWithATokens
function repayWithATokens(address asset,uint256 amount,uint256 interestRateMode)
Allows user to repay with aTokens of the underlying debt asset without any approvals eg. Pay DAI debt using aDAI tokens.
Call Params
swapBorrowRateMode
function swapBorrowRateMode(address asset, uint256 rateMode)
Swaps msg.sender
's borrow rate mode between stable and variable.
Call Params
rebalanceStableBorrowRate
function rebalanceStableBorrowRate(address asset, address user)
Rebalances stable borrow rate of the user
for given asset
. In certain conditions, the protocol allows for stable rates to be rebalanced to avoid a large percentage of liquidity being borrowed at a stable rate below market variable rate. In V3, The condition for rebalance is if the current supply rate <= supply rate if all borrows are variable * 0.9, contract reference.
Call Params
setUserUseReserveAsCollateral
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral)
Sets the asset
of msg.sender
to be used as collateral or not.
An asset in Isolation Mode can be enabled to use as collateral only if no other asset is already enabled to use as collateral.
User won’t be able to disable an asset as collateral if they have an outstanding debt position which could be left with HF < HEALTH_FACTOR_LIQUIDATION_THRESHOLD
on disabling the given asset as collateral.
Call Params
liquidationCall
function liquidationCall(address collateral, address debt, address user, uint256 debtToCover, bool receiveAToken)
Liquidate positions with a health factor below 1.
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 instead of the underlying asset. 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 `Pool` contract to use `debtToCover` of the underlying ERC20 of the`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).debtToCover
parameter can be set touint(-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()
.
Call Params
flashLoan
function flashLoan( address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] interestRateModes, address onBehalfOf, bytes calldata params, uint16 referralCode)
Allows users to access liquidity of the pool for given list of assets for one transaction as long as the amount taken plus fee is returned or debt position is opened by the end of transaction.
If no debt position is opened, receiver must approve the Pool contract for at least the amount borrowed + fee, else transaction will revert.
Flash loan fee is waived for the approved flashBorrowers
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Aave governance proposal
Call Params
flashLoanSimple
function flashLoanSimple( address receiverAddress, address asset, uint256 amount, bytes calldata params, uint16 referralCode)
Allows users to access liquidity of one reserve or one transaction as long as the amount taken plus fee is returned.
Receiver must approve the Pool contract for at least the amount borrowed + fee, else transaction will revert.
Does not waive few for approved flashBorrowers nor allow opening a debt position instead of repaying.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Aave governance proposal
Call Params
mintToTreasury
function mintToTreasury(address[] calldata assets)
Mints reserve income accrued to treasury (as per the reserve factor) for the given list of assets.
Call Params
setUserEMode
function setUserEMode(uint8 categoryId)
Updates the user efficiency mode category. The category id must be a valid id already defined by Pool or Risk Admins
Will revert if user is borrowing non-compatible asset or change will drop HF < HEALTH_FACTOR_LIQUIDATION_THRESHOLD
Call Params
mintUnbacked
mintUnbacked (asset, amount, onBehalfOf, referralCode)
Allows contracts, with BRIDGE
role permission, to mint unbacked aTokens to the onBehalfOf
address. This method is part of the V3 Portal feature.
Only available to the addresses withBRIDGE
role. Bridge addresses can be whitelisted by the governance.
backUnbacked
backUnbacked (asset, amount, fee)
Allows contracts, with BRIDGE
role permission, to back the currently unbacked aTokens with amount
of underlying asset and pay fee
. This method is part of the V3 Portal feature.
Only available to the addresses withBRIDGE
role. Bridge addresses can be whitelisted by the governance.
rescueTokens
function rescueTokens(address token, address to, uint256 amount)
Rescue and transfer tokens locked in this contract.
Only available toPOOL_ADMIN
role. Pool admin is selected by the governance.
View Methods
getReserveData
function getReserveData(address asset)
Returns the state and configuration of the reserve.
Call Params
Return Values
getUserAccountData
function getUserAccountData(address user)
Returns the user account data across all the reserves
Call params
Return Values
getConfiguration
function getConfiguration(address asset)
Returns the configuration of the reserve.
Call Params
Return Values
getUserConfiguration
function getUserConfiguration(address user)
Returns the configuration of the user across all the reserves.
Call Params
Return Values
getReserveNormalizedIncome
function getReserveNormalizedIncome(address asset)
Returns the ongoing normalized income for the reserve.
A value of 1e27 means there is no income. As time passes, the yield is accrued. A value of 2*1e27 means for each unit of asset one unit of income has been accrued.
Return Value
getReserveNormalizedDebt
function getReserveNormalizedVariableDebt(address asset)
Returns the ongoing normalized variable debt for the reserve.
A value of 1e27 means there is no debt. As time passes, the debt is accrued. A value of 2*1e27 means that for each unit of debt, one unit worth of interest has been accumulated.
Return Value
getReservesList
function getReservesList()
Returns the list of initialized reserves.
getEModeCategoryData
function getEModeCategoryData(uint8 id)
Returns category data for the given eModeCategory id.
Return Values
getUserEMode
function getUserEMode(address user)
Returns eModeCategory Id of the user’s eMode. 0 ⇒ no eMode.
FLASHLOAN_PREMIUM_TOTAL
function FLASHLOAN_PREMIUM_TOTAL() public view returns (uint128)
Returns the percent of total flashloan premium paid by the borrower. A part of this premium is added to reserve's liquidity index i.e. paid to the liquidity provider and the other part is paid to the protocol i.e. accrued to the treasury.
FLASHLOAN_PREMIUM_TO_PROTOCOL
function FLASHLOAN_PREMIUM_TO_PROTOCOL() public view returns (uint128)
Returns the percent of flashloan premium that is accrued to the treasury.