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. LendingPool
methodsdeposit, borrow, withdraw and repay
are only for ERC20, if you want to deposit, borrow, withdraw or repay using native ETH (or native MATIC incase of Polygon), use WETHGateway
instead.function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)
amount
of an asset
into the protocol, minting the same amount
of corresponding aTokens, and transferring them to the onBehalfOf
address.0
as thereferralCode.
LendingPool
contract must haveallowance()
to spend funds on behalf ofmsg.sender
for at-leastamount
for the asset
being deposited. This can be done via the standard ERC20 approve()
method.amount
onBehalfOf
msg.sender
when the aTokens should be sent to the caller.function withdraw(address asset, uint256 amount, address to)
amount
of the underlying asset
, i.e. redeems the underlying token and burns the aTokens.to
another address,msg.sender
should haveaToken
that will be burned by lendingPool .amount
type(uint).max
to withdraw the entire balance.to
asset
function borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf)
amount
of asset
with interestRateMode
, sending the amount
to msg.sender
, with the debt being incurred by onBehalfOf
. onBehalfOf
must have enough collateral via deposit()
or have delegated credit to msg.sender
via approveDelegation()
. See the Credit Delegation guide for more details.amount
interestRateMode
onBehalfOf
msg.sender
when not calling on behalf of a different user.function repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf)
onBehalfOf
's debt amount
of asset
which has a rateMode
.amount
uint(-1)
to repay the entire debt, ONLY when the repayment is not executed on behalf of a 3rd party. _amount
slightly higher than the current borrowed amount.rateMode
onBehalfOf
msg.sender
when not calling on behalf of a different user.function swapBorrowRateMode(address asset, uint256 rateMode)
msg.sender
's borrow rate modes between stable and variable.rateMode
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral)
asset
of msg.sender
to be used as collateral or not.useAsCollateral
true
if the asset
should be used as collateralfunction liquidationCall(address collateral, address debt, address user, uint256 debtToCover, bool receiveAToken)
approve()
the LendingPool
contract to use debtToCover
of the underlying ERC20 of theasset
used for the liquidation.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.collateral
debt
user
debtToCover
asset
debt that the liquidator will repayreceiveAToken
true
, the user receives the aTokens equivalent of the purchased collateral. If false
, the user receives the underlying asset directly.function flashLoan(address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] modes, address onBehalfOf, bytes calldata params, uint16 referralCode)
amounts
of assets
to the receiverAddress
contract, passing the included params
. amounts
+ fee is not returned by the end of the transaction, then the transaction will either:mode
is 0,onBehalfOf
incurs a stable debt if mode
is 1, oronBehalfOf
incurs a variable debt if mode
is 2.IFlashLoanReceiver
interface. For more, see the flash loan guides.receiverAddress
IFlashLoanReceiver
interface.assets
address[]
amounts
uint256[]
assets
to flashloan.assets
.modes
uint256[]
onBehalfOf
mode
is not0
then the incurred debt will be applied to the onBehalfOf
address.onBehalfOf
must already have approved sufficient borrow allowance of the associated asset to msg.sender
params
receiverAddress
contractfunction getReserveData(address asset)
asset
configuration
105% Liq Bonus = 100% principal + 5% bonus
liquidityIndex
variableBorrowIndex
currentLiquidityRate
currentVariableBorrowRate
currentStableBorrowRate
lastUpdateTimestamp
aTokenAddress
stableDebtTokenAddress
variableDebtTokenAddress
id
function getUserAccountData(address user)
user
totalCollateralETH
totalDebtETH
availableBorrowsETH
currentLiquidationThreshold
ltv
function getConfiguration(address asset)
asset
function getUserConfiguration(address user)
user
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
.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. 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.0x40020
(in hex) or 262176
(in decimal).function getReserveNormalizedIncome(address asset)
asset
. asset
function getReserveNormalizedVariableDebt(address asset)
asset
.asset
function paused()
true
if the LendingPool is paused.function getReservesList()
Errors.sol
​