Skip to main content

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 address
  • asset: reserve asset token
  • maxTokenId: max tokenId permitted for the given collateral
  • minTokenId: min tokenId permitted for the given collateral
  • interestRateStrategy: interest rate strategy contract address
  • fToken: derivative fToken address
  • debtToken: derivative debtToken address
  • stakedToken: derivative stakedToken address
  • assetPriceFeed: 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 tokens
  • reserveId: id of the reserve
  • onBehalfOf: loan receiver's address
  • referralCode: referral code number

withdraw(uint256 amount, uint256 reserveId, address to)

Withdraws assets from the lending pool.

  • amount: amount of tokens
  • reserveId: reserve id
  • to: receiver address

withdrawViaLending(address initiator, uint256 amount, uint256 reserveId, address to)

Withdraws assets from the lending pool to a P2Peer loan.

  • initiator: address of lender
  • amount: amount of ERC20 tokens
  • reserveId: reserve id
  • to: 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 deposited
  • reserveId: id of the reserve to borrow against
  • onBehalfOf: loan receiver's address
  • referralCode: referral code number

repay(address collateral, uint256 tokenId, uint256 amount)

Repays a borrow position.

  • collateral: NFT collateral contract address.
  • tokenId: tokenId of NFT
  • amount: 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 initiator
  • collateral: The NFT collateral contract address.
  • tokenId: tokenId of NFT
  • amount: 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 address
  • tokenId: underlying collateral tokenId
  • paymentAsset: address of asset used for payment
  • onBehalfOf: 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.