LendPool
lendpool.sol
The LendPool
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**.**
LendPool methods deposit, withdraw, triggerUserCollateral, borrow, repay, auction, redeem, liquidate, and liquidateNFTX are only for ERC20 and ERC721. If you want to deposit, withdraw, triggerUserCollateral, borrow, repay, auction, or redeem using native ETH, use WETHGateway instead. If you want to borrow or repay using CryptoPunks as collateral, use PunkGateway.
View Methods
getReserveConfiguration
function getReserveConfiguration(address asset) external view override returns (DataTypes.ReserveConfigurationMap memory)
Returns the configuration of the reserve.
Call Params
Return Values
getNftConfigByTokenId
function getNftConfigByTokenId(address asset, uint256 nftTokenId) external view override returns (DataTypes.NftConfigurationMap memory)
Returns the configuration of the NFT collection as a default config.
Each NFT has its own configuration bytokenId
, not by collection.
Call Params
Return Values
getReserveNormalizedIncome
function getReserveNormalizedIncome(address asset) external view override returns (uint256)
Returns the normalized income of the reserve.
Call Params
Return Values
getReserveNormalizedVariableDebt
function getReserveNormalizedVariableDebt(address asset) external view override returns (uint256)
Returns the normalized variable debt per unit of asset.
Call Params
Return Params
getReserveData
function getReserveData(address asset) external view override returns (DataTypes.ReserveData memory)
Returns the state and configuration of the reserve.
Call Params
Return Values
getNftData
function getNftData(address asset) external view override returns (DataTypes.NftData memory)
Returns the state and configuration of the NFT.
Call Params
Return Values
getNftCollateralData
function getNftCollateralData(address nftAsset, uint256 nftTokenId, address reserveAsset) external view override returns (uint256 totalCollateralInETH, uint256 totalCollateralInReserve, uint256 availableBorrowsInETH, uint256 availableBorrowsInReserve, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus)
Returns the loan data of the NFT by TokenId.
Call Params
Return Values
getNftDebtData
function getNftDebtData(address nftAsset, uint256 nftTokenId) external view override returns (uint256 loanId, address reserveAsset, uint256 totalCollateral, uint256 totalDebt, uint256 availableBorrows, uint256 healthFactor)
Returns the debt data of the NFT.
Call Params
Return Values
getNftAuctionData
function getNftAuctionData(address nftAsset, uint256 nftTokenId) external view override returns (uint256 loanId, address bidderAddress, uint256 bidPrice, uint256 bidBorrowAmount, uint256 bidFine)
Returns the auction data of the NFT.
Call Params
Return Values
getReservesList
function getReservesList() external view override returns (address[] memory)
Returns the list of the initialized reserves.
Return Values
getNftsList
function getNftsList() external view override returns (address[] memory)
Returns the list of the initialized NFTs.
Return Values
Write Methods
deposit
function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external override nonReentrant whenNotPaused
Deposit the user-chosen amount of a certain asset
into the protocol, minting the same amount
of corresponding uTokens, and transferring them to the onBehalfOf
address.
Example: Bob deposits 100 WETH and will get 100 uWETH in return as proof of the deposited amount.
The referral program is coded but inactive. You can pass a 0 as referralCode.
When depositing, the LendPool
contract must haveallowance()
to spend funds on behalf ofmsg.sender
for at least theamount of
the asset
being deposited.
This can be done via the standard ERC20 approve()
method.
Call Params
withdraw
function withdraw(address asset, uint256 amount, address to) external override nonReentrant whenNotPaused returns (uint256)
Withdraws the amount of the underlying asset
based on the amount
of uTokens being held and burns the same amount of uTokens.
Example: Bob withdraws 10 ETH. Bob will get 10 ETH and will burn the same amount in uTokens.
When withdrawing to
another address, the msg.sender
should hold enough uTokens that the lendPool will burn.
Call Params
Return Params
approveValuation
function approveValuation(address nftAsset, uint256 nftTokenId) external payable override onlyHolder(nftAsset, nftTokenId) whenNotPaused
This will ensure that the user holds the nftAsset
or the uNFT version of it (ERC721). It will charge a small fee to the user to configure his NFT on the protocol.
This function needs to be done before borrowing. Otherwise, it will revert.
Call Params
borrow
function borrow(address asset, uint256 amount, address nftAsset, uint256 nftTokenId, address onBehalfOf, uint16 referralCode) external override nonReentrant whenNotPaused
The user will be able to borrow an amount
of asset
using his nftAsset
as collateral to a wallet onBehalfOf
and will also receive the same amount
in debt tokens as proof of debt.
Example: Alice borrows 10 ETH using her Lockey NFT with tokenid 1. Alice will lock her NFT and get a uNFT (wrapped version of the collateral), debt tokens representing her debt to the protocol and the 10 ETH.
The referral program is coded but inactive. You can pass a 0 as referralCode.
The borrowing can only be done if your NFT is configured on the protocol.
To do this, the triggerUserCollateral needs to be called first.
Also, there's a _timeFrame
variable configured that will validate the time between configuring the NFT and the borrow. If the time is exceeded, it will revert.\
The _timeFrame
can be checked with getTimeframe()
Call Params
repay
function repay(address nftAsset, uint256 nftTokenId, uint256 amount) external override nonReentrant whenNotPaused returns (uint256, bool)
Repays a borrowed amount
equal to or less than the amount owed from the specified collateral, nftAsset
. It will burn the same amount
of debt tokens
.
Example: Alice decides to pay 2 ETH from the borrowed amount. Alice will use her uNFT to identify the loan, will give 2 ETH and will burn the same amount in debt tokens.
Call Params
Return Values
auction
function auction(address nftAsset, uint256 nftTokenId, uint256 bidPrice, address onBehalfOf) external override nonReentrant whenNotPaused
When the health factor is below one, the users can trigger an auction if they want to buy the collateral asset, the NFT used in the loan. The bidPrice
needs to be higher than
When a user bids, the money gets locked on the contract till someone outbids or the liquidation happens.
Example: Alice's NFT price went down, and the health factor (HF) went below 1. Bob, that loves the Lockeys decide to bid. If there's a second bid, the first bidder will get a 2.5% bidFine for being the first. The bidFine will also be paid if Alice decides to redeem part of the debt and make the HF go above one.
redeem
function redeem(address nftAsset, uint256 nftTokenId, uint256 amount, uint256 bidFine) external override nonReentrant whenNotPaused returns (uint256)
Redeem should be used by the NFT Owner in case the NFT goes into auction and he wants to keep his NFT.
If the auction starts and the redeem duration are still available, the user can pay an amount to increase the Health Factor.
The amount needs to be higher than the (borrowAmount * redeemThreshold)/100
Example: Alice's NFT was bid by Bob, but since Alice can still redeem, she decides to pay 70% of her debt to get the Health Factor > 1.
Call Params
Return Values
Liquidate
function liquidate(address nftAsset, uint256 nftTokenId, uint256 amount) external override nonReentrant whenNotPaused returns (uint256)
After the auction period ends. The liquidator should trigger this so he can receive his collateral asset.
Example: Bob wins the auction. He can call this function to get his collateral (NFT) into his wallet.
Call Params
Return Values
Buyout
If the health factor of the NFT falls below one, an auction will be initiated. The minimum bid amount during the auction will be the same as the debt amount. Users will have the option to buyout the NFT during the auction by clicking on the buyout button. The buyout amount of the NFT will be calculated on the smart contract and will be the highest value between the NFT valuation and its debt. To enable this function, the "approve" function to spend WETH will need to take into consideration the buyout amount.
Call Params
Last updated