PxLend

Git Source

Inherits: ILendData, Ownable, ERC721Holder, ERC1155Receiver, ERC1155Holder

Authors: pxswap (https://github.com/pxswap-xyz/pxswap/blob/main/src/Pxswap.sol), Ali Konuk - @alikonuk1

This contract is for lending and borrowing non-fungible tokens (NFTs)

Please reach out to ali@pxswap.xyz if you find any issues

State Variables

beneficiary

address payable private beneficiary;

SECONDS_IN_DAY

uint256 private constant SECONDS_IN_DAY = 86400;

lendingID

uint256 private lendingID = 1;

borrowingID

uint256 private borrowingID = 1;

borrowFee

uint256 public borrowFee = 100;

tokenMap

mapping(uint8 => address) private tokenMap;

lendings

mapping(bytes32 => Lending) private lendings;

borrowings

mapping(bytes32 => Borrowing) private borrowings;

Functions

constructor

constructor(address payable beneficiary_);

lend

function lend(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory lendAmount,
    uint8[] memory maxBorrowDuration,
    bytes4[] memory dailyBorrowPrice,
    uint8[] memory paymentToken,
    bool[] memory willAutoRenew
) external;

stopLend

function stopLend(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory _lendingID
) external;

borrow

function borrow(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory _lendingID,
    uint8[] memory borrowDuration,
    uint256[] memory borrowAmount
) external payable;

stopBorrow

function stopBorrow(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory _lendingID,
    uint256[] memory _borrowingID
) external;

claimBorrow

function claimBorrow(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory _lendingID,
    uint256[] memory _borrowingID
) external;

handleLend

function handleLend(ILendData.CallData memory cd) internal;

handleStopLend

function handleStopLend(ILendData.CallData memory cd) internal;

handleBorrow

function handleBorrow(ILendData.CallData memory cd) internal;

handleStopBorrow

function handleStopBorrow(ILendData.CallData memory cd) private;

handleClaimBorrow

function handleClaimBorrow(CallData memory cd) private;

manageWillAutoRenew

function manageWillAutoRenew(
    ILendData.Lending storage lending,
    ILendData.Borrowing storage borrowing,
    address nftAddress,
    ILendData.NFTStandard nftStandard,
    uint256 tokenID,
    uint256 lendingID
) internal;

bundleCall

function bundleCall(function(ILendData.CallData memory) handler, ILendData.CallData memory cd) internal;

takeFee

function takeFee(uint256 borrowAmt, ERC20 token) internal returns (uint256 fee);

distributePayments

function distributePayments(
    ILendData.Lending memory lending,
    ILendData.Borrowing memory borrowing,
    uint256 secondsSinceBorrowStart
) private;

distributeClaimPayment

function distributeClaimPayment(ILendData.Lending memory lending, ILendData.Borrowing memory borrowing) internal;

safeTransfer

function safeTransfer(
    CallData memory cd,
    address from,
    address to,
    uint256[] memory tokenID,
    uint256[] memory lendAmount
) internal;

getLending9CFF8D4

function getLending9CFF8D4(address nftAddress, uint256 tokenID, uint256 _lendingID)
    external
    view
    returns (uint8, address, uint8, bytes4, uint16, uint16, uint8);

getBorrowing144DC65D

function getBorrowing144DC65D(address nftAddress, uint256 tokenID, uint256 _borrowingID)
    external
    view
    returns (address, uint16, uint8, uint32);

createLendCallData

function createLendCallData(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory lendAmount,
    uint8[] memory maxBorrowDuration,
    bytes4[] memory dailyBorrowPrice,
    uint8[] memory paymentToken,
    bool[] memory willAutoRenew
) internal pure returns (CallData memory cd);

createBorrowCallData

function createBorrowCallData(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory _lendingID,
    uint8[] memory borrowDuration,
    uint256[] memory borrowAmount
) internal pure returns (CallData memory cd);

createActionCallData

function createActionCallData(
    ILendData.NFTStandard[] memory nftStandard,
    address[] memory nftAddress,
    uint256[] memory tokenID,
    uint256[] memory _lendingID,
    uint256[] memory _borrowingID
) internal pure returns (CallData memory cd);

unpackPrice

function unpackPrice(bytes4 price, uint256 scale) internal pure returns (uint256);

sliceArr

function sliceArr(uint256[] memory arr, uint256 fromIx, uint256 toIx, uint256 arrOffset)
    internal
    pure
    returns (uint256[] memory r);

isNotZero

function isNotZero(address addr) internal pure;

isZero

function isZero(address addr) internal pure;

isReturnable

function isReturnable(Borrowing memory borrowing, address msgSender, uint256 blockTimestamp) internal pure;

isPastReturnDate

function isPastReturnDate(Borrowing memory borrowing, uint256 nowTime) internal pure returns (bool);

getPaymentToken

function getPaymentToken(uint8 paymentToken) internal view returns (address);

setPaymentToken

function setPaymentToken(uint8 paymentToken, address t) external payable onlyOwner;

setBorrowFee

function setBorrowFee(uint256 borrowFee_) external payable onlyOwner;

setBeneficiary

function setBeneficiary(address payable beneficiary_) external payable onlyOwner;