P2Pool Contract Reference
LendingPool.sol
This contract is a peer 2 pool lending pool contract for instant, permissionless NFT-backed loans. It allows for the borrow/repay of loans and deposit/withdrawal of assets.
Functionality
The contract provides the following functionality:
initReserve(address collateral, address asset, uint256 maxTokenId, uint256 minTokenId, address interestRateStrategy, address fToken, address debtToken, address stakedToken, string memory assetPriceFeed)
Initializes a reserve.
collateral
: NFT collateral contract addressasset
: reserve asset tokenmaxTokenId
: max tokenId permitted for the given collateralminTokenId
: min tokenId permitted for the given collateralinterestRateStrategy
: interest rate strategy contract addressfToken
: derivative fToken addressdebtToken
: derivative debtToken addressstakedToken
: derivative stakedToken addressassetPriceFeed
: NFT oracle price feed used for asset price conversion
deposit(uint256 amount, uint256 reserveId, address onBehalfOf, uint16 referralCode)
Deposits assets into the lending pool.
amount
: amount of tokensreserveId
: id of the reserveonBehalfOf
: loan receiver's addressreferralCode
: referral code number
withdraw(uint256 amount, uint256 reserveId, address to)
Withdraws assets from the lending pool.
amount
: amount of tokensreserveId
: reserve idto
: receiver address
withdrawViaLending(address initiator, uint256 amount, uint256 reserveId, address to)
Withdraws assets from the lending pool to a P2Peer loan.
initiator
: address of lenderamount
: amount of ERC20 tokensreserveId
: reserve idto
: receiver address
borrow(uint256 amount, uint256 tokenId, uint256 reserveId, address onBehalfOf, uint16 referralCode)
Creates a borrow position.
amount
: amount of tokens to be borrowed.tokenId
: tokenId of the ERC721 token to be depositedreserveId
: id of the reserve to borrow againstonBehalfOf
: loan receiver's addressreferralCode
: referral code number
repay(address collateral, uint256 tokenId, uint256 amount)
Repays a borrow position.
collateral
: NFT collateral contract address.tokenId
: tokenId of NFTamount
: amount of tokens to be repaid.
repayViaLending(address initiator, address collateral, uint256 tokenId, uint256 amount)
Repays a borrow position using a P2Peer loan.
initiator
: address of listing order initiatorcollateral
: The NFT collateral contract address.tokenId
: tokenId of NFTamount
: amount of tokens to be repaid
liquidate(address collateral, uint256 tokenId, address paymentAsset, uint256 paymentAmount, address onBehalfOf)
Purchases the collateral of a defaulted borrow position at a discount.
collateral
: underlying collateral contract addresstokenId
: underlying collateral tokenIdpaymentAsset
: address of asset used for paymentonBehalfOf
: loan receiver's address
Dependencies
Interfaces:
- ILendingPool
- IFToken
- IDebtToken
- ICollateralManager
- IAddressProvider
- IERC20
- IERC721ReceiverUpgradeable
Contracts:
SharedStorage.sol
LendingPoolStorage.sol
Libraries:
- ReserveLogic
- SupplyLogic
- BorrowLogic
- LiquidateLogic
- InterestLogic
- ValidationLogic
- ConfigTypes
- DataTypes
- Errors
- WadRayMath
LendingPoolStorage.sol
This contract is responsible for separating the storage logic from the main Lending Pool contract in the protocol.
Functionality
The Lending Pool Storage contract defines and manages various storage variables and mappings used by the Lending Pool contract. It provides the following functionality:
- Storage for reserves
- Reserve ID management
- Initialization status for collaterals and assets
- Lists of initialized collaterals and assets
- Count and limit of reserves
- Fee management
- Auction duration
- Pause functionality
- Discount boosters
- Upgradable support
Please note that the contract follows specific guidelines for appending new variables to ensure compatibility and upgradability.