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.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.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 pass
0
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.Parameter Name | Type | Description |
---|---|---|
asset | address | address of the underlying asset |
amount | uint256 | amount deposited, expressed in wei units |
onBehalfOf | address | address whom will receive the vTokens.
Use msg.sender when the vTokens should be sent to the caller. |
referralCode | 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 vTokens.When withdrawing
to
another address,**msg.sender
**should havevToken
that will be burned by lendingPool .Parameter Name | Type | Description |
---|---|---|
asset | address | address of the underlying asset, not the vToken |
amount | uint256 | amount deposited, expressed in wei units.
Use type(uint).max to withdraw the entire balance. |
to | address | address that will receive the asset |
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 pass
0
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.Parameter Name | Type | Description |
---|---|---|
asset | address | address of the underlying asset |
tokenIds | uint256[] | The list of token ids to be deposited. |
amounts | uint256[] | The amounts of tokens to be deposited for each token id. All elements must be 1 for an ERC721 NFT collection. |
onBehalfOf | address | address whom will receive the nTokens.
Use msg.sender when the nTokens should be sent to the caller. |
referralCode | uint16 | referral code for our referral program. Use 0 for no referral. |
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 .Parameter Name | Type | Description |
---|---|---|
nft | address | address of the underlying NFT, not the nToken |
tokenIds | uint256[] | The list of token ids to be deposited. |
amounts | uint256[] | The amounts of tokens to be deposited for each token id. All elements must be 1 for an ERC721 NFT collection. |
tokenIds | uint256[] | The list of token ids to be deposited. |
amounts | uint256[] | The amounts of tokens to be deposited for each token id. All elements must be 1 for an ERC721 NFT collection. |
to | address | address that will receive the nft |
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()
.Parameter Name | Type | Description |
---|---|---|
asset | address | address of the underlying asset |
amount | uint256 | amount to be borrowed, expressed in wei units |
interestRateMode | uint256 | the type of borrow debt. Currently unused, must be > 0 |
referralCode | uint16 | referral code for our referral program. Use 0 for no referral code. |
onBehalfOf | address | address of user who will incur the debt. Use msg.sender when not calling on behalf of a different user. |
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 |
---|---|---|
asset | address | address of the underlying asset.md#supported-assets) |
amount | uint256 | amount to be borrowed, expressed in wei units. Use uint(-1) to repay the entire debt, ONLY when the repayment is not executed on behalf of a 3rd party.In case of repayments on behalf of another user, it's recommended to send an _amount slightly higher than the current borrowed amount. |
rateMode | uint256 | the type of borrow debt. Currently unused, must be > 0. |
onBehalfOf | address | address of user who will incur the debt. Use msg.sender when not calling on behalf of a different user. |
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).
Parameter Name | Type | Description |
---|---|---|
collateral | address | address of the collateral nft |
debt | address | address of the underlying borrowed asset to be repaid |
user | address | address of the borrower |
tokenIds | uint256[] | The list of token ids to be obtained after the liquidation |
amounts | uint256[] | The amounts of tokens to be obtained for each token id. All elements must be 1 for an ERC721 NFT collection. |
receiveNToken | bool | if true , the user receives the nTokens equivalent of the purchased collateral. If false , the user receives the underlying NFT directly. |
function getReserveData(address asset)
Returns the state and configuration of the reserve
Parameter Name | Type | Description |
---|---|---|
asset | address | address of the reserve |
Parameter Name | Type | Description |
---|---|---|
configuration | uint256 | bit 0-47: reserved bit 48-55: Decimals bit 56: reserve is active bit 57: reserve is frozen bit 58: borrowing is enabled bit 59-63: reserved bit 64-79: reserve factor ** All % are 1e4 i.e. percentage plus two decimals ** Decimals is 1e2 |
liquidityIndex | uint128 | liquidity index in ray |
variableBorrowIndex | uint128 | variable borrow index in ray |
currentLiquidityRate | uint128 | current supply / liquidity / deposit rate in ray |
currentVariableBorrowRate | uint128 | current variable borrow rate in ray |
currentStableBorrowRate | uint128 | reserved |
lastUpdateTimestamp | uint40 | timestamp of when reserve data was last updated |
vTokenAddress | address | address of associated vToken (tokenised deposit) |
stableDebtTokenAddress | address | reserved |
variableDebtTokenAddress | address | address of associated variable debt token |
interestRateStrategyAddress | address | address of interest rate strategy. |
id | uint8 | the position in the list of active reserves |
function getNFTVaultData(address asset)
Returns the state and configuration of the reserve
Parameter Name | Type | Description |
---|---|---|
asset | address | address of the NFT |
Parameter Name | Type | Description |
---|---|---|
configuration | uint256 | bit 0-15: LTV bit 16-31: Liq. threshold bit 32-47: Liq. bonus bit 48-55: Decimals bit 56: vault is active bit 57: vault is frozen ** All % are 1e4 i.e. percentage plus two decimals ** Decimals is 1e2 ** Caveat on Liquidation bonus
105% Liq Bonus = 100% principal + 5% bonus |
nTokenAddress | address | address of associated nToken (tokenised vault) |
nftEligibility | address | address of the contract that checks the eligibility of the deposited NFTs |
id | uint8 | the position in the list of active reserves |
expiration | uint40 | reserved |
function getUserAccountData(address user)
Returns the user account data across all the reserves
Parameter Name | Type | Description |
---|---|---|
user | address | address of the user |
Parameter Name | Type | Description |
---|---|---|
totalCollateralETH | uint256 | total collateral in ETH of the use (wei decimal unit) |
totalDebtETH | uint256 | total debt in ETH of the user (wei decimal unit) |
availableBorrowsETH | uint256 | borrowing power left of the user (wei decimal unit) |
currentLiquidationThreshold | uint256 | liquidation threshold of the user
(1e4 format => percentage plus two decimals) |
ltv | uint256 | Loan To Value of the user
(1e4 format => percentage plus two decimals) |
healthFactor | uint256 | current health factor of the user. |
function getConfiguration(address asset)
Returns the configuration of the reserve
Parameter Name | Type | Description |
---|---|---|
asset | address | address of the reserve |
Return Type | Description |
---|---|
uint256 | bit 0-47: reserved bit 48-55: Decimals bit 56: reserve is active bit 57: reserve is frozen bit 58: borrowing is enabled bit 59-63: reserved bit 64-79: reserve factor ** All % are 1e4 i.e. percentage plus two decimals ** Decimals is 1e2 |
function getNFTVaultConfiguration(address asset)
Returns the configuration of the reserve
Parameter Name | Type | Description |
---|---|---|
asset | address | address of the NFT |
Return Type | Description |
---|---|
uint256 | bit 0-15: LTV bit 16-31: Liq. threshold bit 32-47: Liq. bonus bit 48-55: Decimals bit 56: vault is active bit 57: vault is frozen ** All % are 1e4 i.e. percentage plus two decimals ** Decimals is 1e2 ** Caveat on Liquidation bonus
105% Liq Bonus = 100% principal + 5% bonus |
function getUserConfiguration(address user)
Returns the configuration of the user across all the reserves.
Parameter Name | Type | Description |
---|---|---|
user | address | address of the user |
Parameter Name | Return Type | Description |
---|---|---|
data | uint256 | For ERC20 asset. The bitmask is divided into pairs of bits, one pair for each asset. The first bit of the pair is reserved, the second bit indicates if it is being borrowed.
The corresponding assets are in the same position as getReservesList()
For example, if the hex value returned is 0x40010 , which represents a decimal value of 262160 , 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 01 00 00 .If we start from the right and move left in the above binary pairs, the third pair is 01 . The third reserve listed in getReserveList() is WETH. Therefore the 1 indicates that WETH is being borrowed by this user.If we continue to go to the end of the binary pairs (furthest left), we have 1 which can also be represented as 01 . This is the 10th pair, which in getReserveList() is DAI. Therefore the 1 indicates that it is being borrowed by this user. |
ndata | uint256 | For NFT asset. The bitmask is divided into bits, one bit for each NFT. The bit indicates if it is being used as collateral by the user.
The corresponding assets are in the same position as getNFTVaultsList()
For example, if the hex value returned is 0x40010 , which represents a decimal value of 262160 , 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 01 00 00 .If we start from the right and move left in the above binary pairs, the third pair is 01 . The third reserve listed in getNFTVaultsList() is WPUNKS. Therefore the 1 indicates that WPUNKS is used as collateral by this user.If we continue to go to the end of the binary pairs (furthest left), we have 1 which can also be represented as 01 . This is the 10th pair, which in getNFTVaultsList() is BAYC. Therefore the 1 indicates that it is being used as collateral. |
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 |
---|---|---|
asset | 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 |
---|---|---|
asset | address | address of the reserve |
function paused()
Returns
true
if the LendingPool is paused.function getReservesList()
Returns the list of initialized reserves.
function getNFTVaultsList()
Returns the list of initialized NFT vaults.
function getAddressesProvider()
Returns the addresses provider.
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 modified 5mo ago