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.
LendingPool
methods**deposit, 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.
Methods
deposit()
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 vTokens, and transferring them to the onBehalfOf
address.
The referral program is currently inactive and you can pass0
as thereferralCode.
In future for referral code to be active again, a governance proposal, with the list of unique referral codes for various integration must be passed via governance.
When depositing, the LendingPool
contract must have**allowance()
to spend funds on behalf ofmsg.sender
** for at-least**amount
** for the asset
being deposited. This can be done via the standard ERC20 approve()
method.
withdraw()
function withdraw(address asset, uint256 amount, address to)
Withdraws amount
of the underlying asset
, i.e. redeems the underlying token and burns the vTokens.
When withdrawing to
another address,**msg.sender
**should havevToken
that will be burned by lendingPool .
depositNFT()
function depositNFT(address nft, uint256[] tokenIds, uint256[] amounts, address onBehalfOf, uint16 referralCode)
Deposits NFTs with given tokenIds
and amounts
into the protocol, minting the corresponding nTokens, and transferring them to the onBehalfOf
address.
The referral program is currently inactive and you can pass0
as thereferralCode.
In future for referral code to be active again, a governance proposal, with the list of unique referral codes for various integration must be passed via governance.
When depositing NFTs, the LendingPool
contract must have**getApproved()
to transfering NFT on behalf ofmsg.sender
** for each token Id in tokenIds
for the nft
being deposited. This can be done via the standard ERC721 approve()
method.
withdrawNFT()
function withdrawNFT(address nft, uint256[] tokenIds, uint256[] amounts, address to)
Withdraws the underlying nft
corresponding to the tokenids
and amounts
, i.e. redeems the underlying tokens and burns the nTokens.
When withdrawing to
another address, msg.sender
should have nToken
that will be burned by lendingPool .
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: onBehalfOf
must have enough collateral via depositNFT()
or have delegated credit to msg.sender
via approveDelegation()
.
repay**()**
function repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf)
Repays onBehalfOf
's debt amount
of asset
which has a rateMode
.
nftLiquidationCall**()**
function nftLiquidationCall(address collateral, address debt, address user, uint256[] tokenIds, uint256[] amounts, bool receiveNToken)
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 nTokens, or the underlying NFT 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 collateral that is worth a maximum of 50% of the amount pending to be repaid in a position. The liquidation discount applies to this amount. The liquidator uses tokenIds
to select the NFTs he/she wishes to obtain. The NFT at the front of the tokenIds
list will be acquired first when liquidated.
Liquidators must approve()
the LendingPool
contract to use as much of the underlying ERC20 as the sum of the value of all tokensIds
used for the liquidation.
NOTES
In most scenarios, profitable liquidators will choose to liquidate as much as they can (50% of the
user
position).To check a user's health factor, use
getUserAccountData()
.
View Methods
getReserveData**()**
function getReserveData(address asset)
Returns the state and configuration of the reserve
Return values
getNFTVaultData**()**
function getNFTVaultData(address asset)
Returns the state and configuration of the reserve
Return values
getUserAccountData**()**
function getUserAccountData(address user)
Returns the user account data across all the reserves
Return values
getConfiguration**()**
function getConfiguration(address asset)
Returns the configuration of the reserve
Return values
getNFTVaultConfiguration**()**
function getNFTVaultConfiguration(address asset)
Returns the configuration of the reserve
Return values
getUserConfiguration**()**
function getUserConfiguration(address user)
Returns the configuration of the user across all the reserves.
Return values
getReserveNormalizedIncome**()**
function getReserveNormalizedIncome(address asset)
Returns the normalized income per unit of asset
.
getReserveNormalizedVariableDebt**()**
function getReserveNormalizedVariableDebt(address asset)
Returns the normalized variable debt per unit of asset
.
paused**()**
function paused()
Returns true
if the LendingPool is paused.
getReservesList**()**
function getReservesList()
Returns the list of initialized reserves.
getNFTVaultsList**()**
function getNFTVaultsList()
Returns the list of initialized NFT vaults.
getAddressesProvider**()**
function getAddressesProvider()
Returns the addresses provider.
Error Codes
In order to reduce gas usage and code size, vinci contracts return numbered errors. If you are making calls to the protocol and receive numbered errors, you can find what the numbers represent by checking the Errors.sol
Last updated