ETH Price: $3,435.48 (+1.62%)
Gas: 2 Gwei

Contract

0xD0C6e59B50C32530C627107F50Acc71958C4341F
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Token Holdings

Transaction Hash
Method
Block
From
To
Value
Pay Back Loan202073782024-06-30 22:05:352 hrs ago1719785135IN
0xD0C6e59B...958C4341F
0 ETH0.000590692.65325839
Accept Collectio...202068082024-06-30 20:11:354 hrs ago1719778295IN
0xD0C6e59B...958C4341F
0 ETH0.002212194.6161123
Accept Collectio...202053742024-06-30 15:23:479 hrs ago1719761027IN
0xD0C6e59B...958C4341F
0 ETH0.002301765.02520329
Accept Collectio...202050722024-06-30 14:22:5910 hrs ago1719757379IN
0xD0C6e59B...958C4341F
0 ETH0.00226924.63993727
Accept Collectio...202050682024-06-30 14:22:1110 hrs ago1719757331IN
0xD0C6e59B...958C4341F
0 ETH0.002236154.7251134
Pay Back Loan202049052024-06-30 13:49:2311 hrs ago1719755363IN
0xD0C6e59B...958C4341F
0 ETH0.000857983.85385193
Renegotiate Loan202047602024-06-30 13:20:1111 hrs ago1719753611IN
0xD0C6e59B...958C4341F
0 ETH0.000886593.40227199
Liquidate Overdu...202036192024-06-30 9:30:5915 hrs ago1719739859IN
0xD0C6e59B...958C4341F
0 ETH0.000427062.52383008
Accept Collectio...202026792024-06-30 6:21:5918 hrs ago1719728519IN
0xD0C6e59B...958C4341F
0 ETH0.001039152.1335695
Accept Collectio...202026732024-06-30 6:20:4718 hrs ago1719728447IN
0xD0C6e59B...958C4341F
0 ETH0.000929091.95700301
Accept Collectio...202026722024-06-30 6:20:3518 hrs ago1719728435IN
0xD0C6e59B...958C4341F
0 ETH0.001017692.01703219
Accept Collectio...202026712024-06-30 6:20:2318 hrs ago1719728423IN
0xD0C6e59B...958C4341F
0 ETH0.001016711.97633926
Pay Back Loan202026382024-06-30 6:13:4718 hrs ago1719728027IN
0xD0C6e59B...958C4341F
0 ETH0.000410481.71696892
Accept Collectio...202026022024-06-30 6:06:3518 hrs ago1719727595IN
0xD0C6e59B...958C4341F
0 ETH0.000137662.02790433
Accept Collectio...202026022024-06-30 6:06:3518 hrs ago1719727595IN
0xD0C6e59B...958C4341F
0 ETH0.000137662.02790433
Accept Collectio...202026002024-06-30 6:06:1118 hrs ago1719727571IN
0xD0C6e59B...958C4341F
0 ETH0.001120052.21684715
Accept Collectio...202025992024-06-30 6:05:5918 hrs ago1719727559IN
0xD0C6e59B...958C4341F
0 ETH0.001135012.20629176
Accept Collectio...202017232024-06-30 3:09:4721 hrs ago1719716987IN
0xD0C6e59B...958C4341F
0 ETH0.001138042.10015627
Liquidate Overdu...202009182024-06-30 0:27:1124 hrs ago1719707231IN
0xD0C6e59B...958C4341F
0 ETH0.000256741.45441832
Liquidate Overdu...202009162024-06-30 0:26:4724 hrs ago1719707207IN
0xD0C6e59B...958C4341F
0 ETH0.000285441.48512963
Liquidate Overdu...202009152024-06-30 0:26:3524 hrs ago1719707195IN
0xD0C6e59B...958C4341F
0 ETH0.000235951.56297831
Renegotiate Loan202002092024-06-29 22:05:1126 hrs ago1719698711IN
0xD0C6e59B...958C4341F
0 ETH0.001043874.00585169
Accept Collectio...202001372024-06-29 21:50:4727 hrs ago1719697847IN
0xD0C6e59B...958C4341F
0 ETH0.000733171.55345792
Pay Back Loan201992072024-06-29 18:43:3530 hrs ago1719686615IN
0xD0C6e59B...958C4341F
0 ETH0.000726772.90198031
Pay Back Loan201991992024-06-29 18:41:5930 hrs ago1719686519IN
0xD0C6e59B...958C4341F
0 ETH0.000684552.60542926
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
DirectLoanFixedCollectionOffer

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 100 runs

Other Settings:
default evmVersion
File 1 of 37 : DirectLoanFixedCollectionOffer.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "./DirectLoanFixedOffer.sol";
import "../../../utils/NFTfiCollectionOfferSigningUtils.sol";

/**
 * @title  DirectLoanFixedCollectionOffer
 * @author NFTfi
 * @notice Main contract for NFTfi Direct Loans Fixed Collection Type.
 * This contract manages the ability to create reoccurring NFT-backed
 * peer-to-peer loans of type Fixed (agreed to be a fixed-repayment loan) where the borrower pays the
 * maximumRepaymentAmount regardless of whether they repay early or not.
 * In collection offer type loans the collateral can be any one item (id) of a given NFT collection (contract).
 *
 * To commence an NFT-backed loan:
 *
 * The borrower accepts a lender's offer by calling `acceptOffer`.
 *   1. the borrower calls nftContract.approveAll(NFTfi), approving the NFTfi contract to move their NFT's on their
 * be1alf.
 *   2. the lender calls erc20Contract.approve(NFTfi), allowing NFTfi to move the lender's ERC20 tokens on their
 * behalf.
 *   3. the lender signs a reusable off-chain message, proposing its collection offer terms.
 *   4. the borrower calls `acceptOffer` to accept these terms and enter into the loan. The NFT is stored in
 * the contract, the borrower receives the loan principal in the specified ERC20 currency, the lender receives an
 * NFTfi promissory note (in ERC721 form) that represents the rights to either the principal-plus-interest, or the
 * underlying NFT collateral if the borrower does not pay back in time, and the borrower receives obligation receipt
 * (in ERC721 form) that gives them the right to pay back the loan and get the collateral back.
 *  5. another borrower can also repeat step 4 until the original lender cancels or their
 * wallet runs out of funds with allowance to the contract
 *
 * The lender can freely transfer and trade this ERC721 promissory note as they wish, with the knowledge that
 * transferring the ERC721 promissory note tranfsers the rights to principal-plus-interest and/or collateral, and that
 * they will no longer have a claim on the loan. The ERC721 promissory note itself represents that claim.
 *
 * The borrower can freely transfer and trade this ERC721 obligaiton receipt as they wish, with the knowledge that
 * transferring the ERC721 obligaiton receipt tranfsers the rights right to pay back the loan and get the collateral
 * back.
 *
 *
 * A loan may end in one of two ways:
 * - First, a borrower may call NFTfi.payBackLoan() and pay back the loan plus interest at any time, in which case they
 * receive their NFT back in the same transaction.
 * - Second, if the loan's duration has passed and the loan has not been paid back yet, a lender can call
 * NFTfi.liquidateOverdueLoan(), in which case they receive the underlying NFT collateral and forfeit the rights to the
 * principal-plus-interest, which the borrower now keeps.
 */
contract DirectLoanFixedCollectionOffer is DirectLoanFixedOffer {
    /* ************* */
    /* CUSTOM ERRORS */
    /* ************* */

    error CollateralIdNotInRange();
    error MinIdGreaterThanMaxId();
    error OriginalAcceptOfferDisabled();

    /* *********** */
    /* CONSTRUCTOR */
    /* *********** */

    /**
     * @dev Sets `hub` and permitted erc20-s
     *
     * @param _admin - Initial admin of this contract.
     * @param  _nftfiHub - NFTfiHub address
     * @param  _permittedErc20s - list of permitted ERC20 token contract addresses
     */
    constructor(
        address _admin,
        address _nftfiHub,
        address[] memory _permittedErc20s
    ) DirectLoanFixedOffer(_admin, _nftfiHub, _permittedErc20s) {
        // solhint-disable-previous-line no-empty-blocks
    }

    /* ******************* */
    /* READ-ONLY FUNCTIONS */
    /* ******************* */

    /**
     * @notice This function returns a bytes32 value identifying the loan type for the coordinator
     */
    // all caps, because used to be a constant storage and the interface should be the same
    // solhint-disable-next-line func-name-mixedcase
    function LOAN_TYPE() public pure override returns (bytes32) {
        return bytes32("DIRECT_LOAN_FIXED_COLLECTION");
    }

    /**
     * @notice overriding to make it impossible to create a regular offer on this contract (only collection offers)
     */
    function acceptOffer(
        Offer memory,
        Signature memory,
        BorrowerSettings memory
    ) external override whenNotPaused nonReentrant returns (uint32) {
        revert OriginalAcceptOfferDisabled();
    }

    /**
     * @notice This function is called by the borrower when accepting a lender's collection offer to begin a loan.
     *
     * @param _offer - The offer made by the lender.
     * @param _signature - The components of the lender's signature.
     * stolen or otherwise unwanted items
     * @param _borrowerSettings - Some extra parameters that the borrower needs to set when accepting an offer.
     */
    function acceptCollectionOffer(
        Offer memory _offer,
        Signature memory _signature,
        BorrowerSettings memory _borrowerSettings
    ) external whenNotPaused nonReentrant {
        address nftWrapper = _getWrapper(_offer.nftCollateralContract);
        _loanSanityChecks(_offer, nftWrapper);
        _loanSanityChecksOffer(_offer);
        _acceptOffer(
            _setupLoanTerms(_offer, nftWrapper),
            _setupLoanExtras(_borrowerSettings.revenueSharePartner, _borrowerSettings.referralFeeInBasisPoints),
            _offer,
            _signature
        );
    }

    /**
     * @notice This function is called by the borrower when accepting a lender's
     * collection offer with a given id range to begin a loan
     *
     * @param _offer - The offer made by the lender.
     * @param _idRange - min and max (inclusive) Id ranges for collection offers on collections,
     * like ArtBlocks, where multiple collections are defined on one contract differentiated by id-ranges
     * @param _signature - The components of the lender's signature.
     * stolen or otherwise unwanted items
     * @param _borrowerSettings - Some extra parameters that the borrower needs to set when accepting an offer.
     */
    function acceptCollectionOfferWithIdRange(
        Offer memory _offer,
        CollectionIdRange memory _idRange,
        Signature memory _signature,
        BorrowerSettings memory _borrowerSettings
    ) external whenNotPaused nonReentrant {
        address nftWrapper = _getWrapper(_offer.nftCollateralContract);
        _loanSanityChecks(_offer, nftWrapper);
        _loanSanityChecksOffer(_offer);
        _idRangeSanityCheck(_idRange);
        _acceptOfferWithIdRange(
            _setupLoanTerms(_offer, nftWrapper),
            _setupLoanExtras(_borrowerSettings.revenueSharePartner, _borrowerSettings.referralFeeInBasisPoints),
            _offer,
            _idRange,
            _signature
        );
    }

    /* ****************** */
    /* INTERNAL FUNCTIONS */
    /* ****************** */

    /**
     * @notice This function is called by the borrower when accepting a lender's offer
     * to begin a loan with the public function acceptCollectionOffer.
     *
     * @param _loanTerms - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoan.
     * @param _loanExtras - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoanExtras.
     * @param _offer - The offer made by the lender.
     * @param _signature - The components of the lender's signature.
     * stolen or otherwise unwanted items
     */
    function _acceptOffer(
        LoanTerms memory _loanTerms,
        LoanExtras memory _loanExtras,
        Offer memory _offer,
        Signature memory _signature
    ) internal override returns (uint32) {
        // still checking the nonce for possible cancellations
        if (_nonceHasBeenUsedForUser[_signature.signer][_signature.nonce]) {
            revert InvalidNonce();
        }
        // Note that we are not invalidating the nonce as part of acceptOffer (as is the case for loan types in general)
        // since the nonce that the lender signed with remains valid for all loans for the collection offer

        Offer memory offerToCheck = _offer;

        offerToCheck.nftCollateralId = 0;

        if (!NFTfiSigningUtils.isValidLenderSignature(offerToCheck, _signature)) {
            revert InvalidLenderSignature();
        }

        uint32 loanId = _createLoan(
            LOAN_TYPE(),
            _loanTerms,
            _loanExtras,
            msg.sender,
            _signature.signer,
            _offer.referrer
        );

        // Emit an event with all relevant details from this transaction.
        emit LoanStarted(loanId, msg.sender, _signature.signer, _loanTerms, _loanExtras);

        return loanId;
    }

    /**
     * @notice This function is called by the borrower when accepting a lender's
     * collection offer with a given id range to begin a loan
     *
     * @param _loanTerms - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoan.
     * @param _loanExtras - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoanExtras.
     * @param _idRange - min and max (inclusive) Id ranges for collection offers on collections,
     * like ArtBlocks, where multiple collections are defined on one contract differentiated by id-ranges
     * @param _offer - The offer made by the lender.
     * @param _signature - The components of the lender's signature.
     * stolen or otherwise unwanted items
     */
    function _acceptOfferWithIdRange(
        LoanTerms memory _loanTerms,
        LoanExtras memory _loanExtras,
        Offer memory _offer,
        CollectionIdRange memory _idRange,
        Signature memory _signature
    ) internal {
        // still checking the nonce for possible cancellations
        if (_nonceHasBeenUsedForUser[_signature.signer][_signature.nonce]) {
            revert InvalidNonce();
        }
        // Note that we are not invalidating the nonce as part of acceptOffer (as is the case for loan types in general)
        // since the nonce that the lender signed with remains valid for all loans for the collection offer

        //check for id range
        if (_loanTerms.nftCollateralId < _idRange.minId || _loanTerms.nftCollateralId > _idRange.maxId) {
            revert CollateralIdNotInRange();
        }
        Offer memory offerToCheck = _offer;

        offerToCheck.nftCollateralId = 0;

        if (!NFTfiCollectionOfferSigningUtils.isValidLenderSignatureWithIdRange(offerToCheck, _idRange, _signature)) {
            revert InvalidLenderSignature();
        }

        uint32 loanId = _createLoan(
            LOAN_TYPE(),
            _loanTerms,
            _loanExtras,
            msg.sender,
            _signature.signer,
            _offer.referrer
        );

        // Emit an event with all relevant details from this transaction.
        emit LoanStarted(loanId, msg.sender, _signature.signer, _loanTerms, _loanExtras);
    }

    function _idRangeSanityCheck(CollectionIdRange memory _idRange) internal pure {
        if (_idRange.minId > _idRange.maxId) {
            revert MinIdGreaterThanMaxId();
        }
    }
}

File 2 of 37 : IERC1271.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 *
 * _Available since v4.1._
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

File 3 of 37 : Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

File 4 of 37 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

File 5 of 37 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

File 6 of 37 : IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev _Available since v3.1._
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @dev Handles the receipt of a single ERC1155 token type. This function is
     * called at the end of a `safeTransferFrom` after the balance has been updated.
     *
     * NOTE: To accept the transfer, this must return
     * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     * (i.e. 0xf23a6e61, or its own function selector).
     *
     * @param operator The address which initiated the transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param id The ID of the token being transferred
     * @param value The amount of tokens being transferred
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @dev Handles the receipt of a multiple ERC1155 token types. This function
     * is called at the end of a `safeBatchTransferFrom` after the balances have
     * been updated.
     *
     * NOTE: To accept the transfer(s), this must return
     * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
     * (i.e. 0xbc197c81, or its own function selector).
     *
     * @param operator The address which initiated the batch transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param ids An array containing ids of each token being transferred (order and length must match values array)
     * @param values An array containing amounts of each token being transferred (order and length must match ids array)
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}

File 7 of 37 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 8 of 37 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

File 9 of 37 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 10 of 37 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 11 of 37 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 12 of 37 : ERC721Holder.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/utils/ERC721Holder.sol)

pragma solidity ^0.8.0;

import "../IERC721Receiver.sol";

/**
 * @dev Implementation of the {IERC721Receiver} interface.
 *
 * Accepts all token transfers.
 * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
 */
contract ERC721Holder is IERC721Receiver {
    /**
     * @dev See {IERC721Receiver-onERC721Received}.
     *
     * Always returns `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
        return this.onERC721Received.selector;
    }
}

File 13 of 37 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 14 of 37 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 15 of 37 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV // Deprecated in v4.8
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32")
            mstore(0x1c, hash)
            message := keccak256(0x00, 0x3c)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, "\x19\x01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x00", validator, data));
    }
}

File 16 of 37 : SignatureChecker.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/SignatureChecker.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";
import "../../interfaces/IERC1271.sol";

/**
 * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
 * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like
 * Argent and Gnosis Safe.
 *
 * _Available since v4.1._
 */
library SignatureChecker {
    /**
     * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
     * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
        (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
        return
            (error == ECDSA.RecoverError.NoError && recovered == signer) ||
            isValidERC1271SignatureNow(signer, hash, signature);
    }

    /**
     * @dev Checks if a signature is valid for a given signer and data hash. The signature is validated
     * against the signer smart contract using ERC1271.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidERC1271SignatureNow(
        address signer,
        bytes32 hash,
        bytes memory signature
    ) internal view returns (bool) {
        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
        );
        return (success &&
            result.length >= 32 &&
            abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
    }
}

File 17 of 37 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 18 of 37 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 19 of 37 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 20 of 37 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 21 of 37 : IDirectLoanCoordinator.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

/**
 * @title IDirectLoanCoordinator
 * @author NFTfi
 * @dev DirectLoanCoordinator interface.
 */
interface IDirectLoanCoordinator {
    enum StatusType {
        NOT_EXISTS,
        NEW,
        REPAID,
        LIQUIDATED
    }

    /**
     * @notice This struct contains data related to a loan
     *
     * @param smartNftId - The id of both the promissory note and obligation receipt.
     * @param status - The status in which the loan currently is.
     * @param loanContract - Address of the LoanType contract that created the loan.
     */
    struct Loan {
        address loanContract;
        uint64 smartNftId;
        StatusType status;
    }

    function registerLoan(address _lender, bytes32 _loanType) external returns (uint32);

    function resetSmartNfts(uint32 _loanId, address _borrower) external;

    function mintObligationReceipt(uint32 _loanId, address _borrower) external;

    function resolveLoan(uint32 _loanId, bool liquidated) external;

    function promissoryNoteToken() external view returns (address);

    function obligationReceiptToken() external view returns (address);

    function getLoanData(uint32 _loanId) external view returns (Loan memory);

    function isValidLoanId(uint32 _loanId, address _loanContract) external view returns (bool);
}

File 22 of 37 : INftfiHub.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

/**
 * @title INftfiHub
 * @author NFTfi
 * @dev NftfiHub interface
 */
interface INftfiHub {
    function setContract(string calldata _contractKey, address _contractAddress) external;

    function getContract(bytes32 _contractKey) external view returns (address);
}

File 23 of 37 : INftWrapper.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

/**
 * @title INftTypeRegistry
 * @author NFTfi
 * @dev Interface for NFT Wrappers.
 */
interface INftWrapper {
    function transferNFT(
        address from,
        address to,
        address nftContract,
        uint256 tokenId
    ) external returns (bool);

    function isOwner(
        address owner,
        address nftContract,
        uint256 tokenId
    ) external view returns (bool);
}

File 24 of 37 : IPermittedERC20s.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

interface IPermittedERC20s {
    function getERC20Permit(address _erc20) external view returns (bool);
}

File 25 of 37 : IPermittedNFTs.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

interface IPermittedNFTs {
    function setNFTPermit(address _nftContract, string memory _nftType) external;

    function getNFTPermit(address _nftContract) external view returns (bytes32);

    function getNFTWrapper(address _nftContract) external view returns (address);
}

File 26 of 37 : IPermittedPartners.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

interface IPermittedPartners {
    function getPartnerPermit(address _partner) external view returns (uint16);
}

File 27 of 37 : BaseLoan.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "../utils/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

/**
 * @title  BaseLoan
 * @author NFTfi
 * @dev Implements base functionalities common to all Loan types.
 * Mostly related to governance and security.
 */
abstract contract BaseLoan is Ownable, Pausable, ReentrancyGuard {
    /* *********** */
    /* CONSTRUCTOR */
    /* *********** */

    /**
     * @notice Sets the admin of the contract.
     *
     * @param _admin - Initial admin of this contract.
     */
    constructor(address _admin) Ownable(_admin) {
        // solhint-disable-previous-line no-empty-blocks
    }

    /* ********* */
    /* FUNCTIONS */
    /* ********* */

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - Only the owner can call this method.
     * - The contract must not be paused.
     */
    function pause() external onlyOwner {
        _pause();
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - Only the owner can call this method.
     * - The contract must be paused.
     */
    function unpause() external onlyOwner {
        _unpause();
    }
}

File 28 of 37 : DirectLoanBaseMinimal.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "./IDirectLoanBase.sol";
import "./LoanData.sol";
import "./LoanChecksAndCalculations.sol";
import "../../BaseLoan.sol";
import "../../../utils/NftReceiver.sol";
import "../../../utils/NFTfiSigningUtils.sol";
import "../../../interfaces/INftfiHub.sol";
import "../../../utils/ContractKeys.sol";
import "../../../interfaces/IDirectLoanCoordinator.sol";
import "../../../interfaces/INftWrapper.sol";
import "../../../interfaces/IPermittedPartners.sol";
import "../../../interfaces/IPermittedERC20s.sol";
import "../../../interfaces/IPermittedNFTs.sol";

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/**
 * @title  DirectLoanBase
 * @author NFTfi
 * @notice Main contract for NFTfi Direct Loans Type. This contract manages the ability to create NFT-backed
 * peer-to-peer loans.
 *
 * There are two ways to commence an NFT-backed loan:
 *
 * a. The borrower accepts a lender's offer by calling `acceptOffer`.
 *   1. the borrower calls nftContract.approveAll(NFTfi), approving the NFTfi contract to move their NFT's on their
 * be1alf.
 *   2. the lender calls erc20Contract.approve(NFTfi), allowing NFTfi to move the lender's ERC20 tokens on their
 * behalf.
 *   3. the lender signs an off-chain message, proposing its offer terms.
 *   4. the borrower calls `acceptOffer` to accept these terms and enter into the loan. The NFT is stored in
 * the contract, the borrower receives the loan principal in the specified ERC20 currency, the lender receives an
 * NFTfi promissory note (in ERC721 form) that represents the rights to either the principal-plus-interest, or the
 * underlying NFT collateral if the borrower does not pay back in time, and the borrower receives obligation receipt
 * (in ERC721 form) that gives them the right to pay back the loan and get the collateral back.
 *
 * The lender can freely transfer and trade this ERC721 promissory note as they wish, with the knowledge that
 * transferring the ERC721 promissory note tranfsers the rights to principal-plus-interest and/or collateral, and that
 * they will no longer have a claim on the loan. The ERC721 promissory note itself represents that claim.
 *
 * The borrower can freely transfer and trade this ERC721 obligaiton receipt as they wish, with the knowledge that
 * transferring the ERC721 obligaiton receipt tranfsers the rights right to pay back the loan and get the collateral
 * back.
 *
 * A loan may end in one of two ways:
 * - First, a borrower may call NFTfi.payBackLoan() and pay back the loan plus interest at any time, in which case they
 * receive their NFT back in the same transaction.
 * - Second, if the loan's duration has passed and the loan has not been paid back yet, a lender can call
 * NFTfi.liquidateOverdueLoan(), in which case they receive the underlying NFT collateral and forfeit the rights to the
 * principal-plus-interest, which the borrower now keeps.
 *
 *
 * If the loan was created as a ProRated type loan (pro-rata interest loan), then the user only pays the principal plus
 * pro-rata interest if repaid early.
 * However, if the loan was was created as a Fixed type loan (agreed to be a fixed-repayment loan), then the borrower
 * pays the maximumRepaymentAmount regardless of whether they repay early or not.
 *
 */
abstract contract DirectLoanBaseMinimal is IDirectLoanBase, IPermittedERC20s, BaseLoan, NftReceiver, LoanData {
    using SafeERC20 for IERC20;

    /* ******* */
    /* STORAGE */
    /* ******* */

    uint16 public constant HUNDRED_PERCENT = 10000;

    bytes32 public immutable override LOAN_COORDINATOR;

    /**
     * @notice The maximum duration of any loan started for this loan type, measured in seconds. This is both a
     * sanity-check for borrowers and an upper limit on how long admins will have to support v1 of this contract if they
     * eventually deprecate it, as well as a check to ensure that the loan duration never exceeds the space alotted for
     * it in the loan struct.
     */
    uint256 public override maximumLoanDuration = 53 weeks;

    /**
     * @notice The percentage of interest earned by lenders on this platform that is taken by the contract admin's as a
     * fee, measured in basis points (hundreths of a percent). The max allowed value is 10000.
     */
    uint16 public override adminFeeInBasisPoints = 500;

    /**
     * @notice A mapping from a loan's identifier to the loan's details, represted by the loan struct.
     */
    mapping(uint32 => LoanTerms) public override loanIdToLoan;
    mapping(uint32 => LoanExtras) public loanIdToLoanExtras;

    /**
     * @notice A mapping tracking whether a loan has either been repaid or liquidated. This prevents an attacker trying
     * to repay or liquidate the same loan twice.
     */
    mapping(uint32 => bool) public override loanRepaidOrLiquidated;

    /**
     * @dev keeps track of tokens being held as loan collateral, so we dont allow these
     * to be transferred with the aridrop draining functions
     * nft contract address => nft id => amount (in case of 1155)
     */
    mapping(address => mapping(uint256 => uint256)) private _escrowTokens;

    /**
     * @dev keeps track of payed back erc20 tokens being held in escrow of finished loans, so we dont allow these
     * to be transferred with the aridrop draining functions
     * token contract => amount
     */
    mapping(address => uint256) private _escrowErc20Tokens;

    /**
     * @dev keeps track of payed back erc20 tokens being held in escrow of finished loans for each lender
     * lender => token contract => amount
     */
    mapping(address => mapping(address => uint256)) private _payBackEscrow;

    /**
     * @notice A mapping that takes both a user's address and a loan nonce that was first used when signing an off-chain
     * order and checks whether that nonce has previously either been used for a loan, or has been pre-emptively
     * cancelled. The nonce referred to here is not the same as an Ethereum account's nonce. We are referring instead to
     * nonces that are used by both the lender and the borrower when they are first signing off-chain NFTfi orders.
     *
     * These nonces can be any uint256 value that the user has not previously used to sign an off-chain order. Each
     * nonce can be used at most once per user within NFTfi, regardless of whether they are the lender or the borrower
     * in that situation. This serves two purposes. First, it prevents replay attacks where an attacker would submit a
     * user's off-chain order more than once. Second, it allows a user to cancel an off-chain order by calling
     * NFTfi.cancelLoanCommitmentBeforeLoanHasBegun(), which marks the nonce as used and prevents any future loan from
     * using the user's off-chain order that contains that nonce.
     */
    mapping(address => mapping(uint256 => bool)) internal _nonceHasBeenUsedForUser;

    /**
     * @notice A mapping from an ERC20 currency address to whether that currency
     * is permitted to be used by this contract.
     */
    mapping(address => bool) private erc20Permits;

    INftfiHub public immutable hub;

    /* ****** */
    /* EVENTS */
    /* ****** */

    /**
     * @notice This event is fired whenever the admins change the percent of interest rates earned that they charge as a
     * fee. Note that newAdminFee can never exceed 10,000, since the fee is measured in basis points.
     *
     * @param  newAdminFee - The new admin fee measured in basis points. This is a percent of the interest paid upon a
     * loan's completion that go to the contract admins.
     */
    event AdminFeeUpdated(uint16 newAdminFee);

    /**
     * @notice This event is fired whenever the admins change the maximum duration of any loan started for this loan
     * type.
     *
     * @param  newMaximumLoanDuration - The new maximum duration.
     */
    event MaximumLoanDurationUpdated(uint256 newMaximumLoanDuration);

    /**
     * @notice This event is fired whenever a borrower begins a loan by calling NFTfi.beginLoan(), which can only occur
     * after both the lender and borrower have approved their ERC721 and ERC20 contracts to use NFTfi, and when they
     * both have signed off-chain messages that agree on the terms of the loan.
     *
     * @param  loanId - A unique identifier for this particular loan, sourced from the Loan Coordinator.
     * @param  borrower - The address of the borrower.
     * @param  lender - The address of the lender. The lender can change their address by transferring the NFTfi ERC721
     * token that they received when the loan began.
     */
    event LoanStarted(
        uint32 indexed loanId,
        address indexed borrower,
        address indexed lender,
        LoanTerms loanTerms,
        LoanExtras loanExtras
    );

    /**
     * @notice This event is fired whenever a borrower successfully repays their loan, paying
     * principal-plus-interest-minus-fee to the lender in loanERC20Denomination, paying fee to owner in
     * loanERC20Denomination, and receiving their NFT collateral back.
     *
     * @param  loanId - A unique identifier for this particular loan, sourced from the Loan Coordinator.
     * @param  borrower - The address of the borrower.
     * @param  lender - The address of the lender. The lender can change their address by transferring the NFTfi ERC721
     * token that they received when the loan began.
     * @param  loanPrincipalAmount - The original sum of money transferred from lender to borrower at the beginning of
     * the loan, measured in loanERC20Denomination's smallest units.
     * @param  nftCollateralId - The ID within the NFTCollateralContract for the NFT being used as collateral for this
     * loan. The NFT is stored within this contract during the duration of the loan.
     * @param  amountPaidToLender The amount of ERC20 that the borrower paid to the lender, measured in the smalled
     * units of loanERC20Denomination.
     * @param  adminFee The amount of interest paid to the contract admins, measured in the smalled units of
     * loanERC20Denomination and determined by adminFeeInBasisPoints. This amount never exceeds the amount of interest
     * earned.
     * @param  revenueShare The amount taken from admin fee amount shared with the partner.
     * @param  revenueSharePartner  - The address of the partner that will receive the revenue share.
     * @param  nftCollateralContract - The ERC721 contract of the NFT collateral
     * @param  loanERC20Denomination - The ERC20 contract of the currency being used as principal/interest for this
     * loan.
     */
    event LoanRepaid(
        uint32 indexed loanId,
        address indexed borrower,
        address indexed lender,
        uint256 loanPrincipalAmount,
        uint256 nftCollateralId,
        uint256 amountPaidToLender,
        uint256 adminFee,
        uint256 revenueShare,
        address revenueSharePartner,
        address nftCollateralContract,
        address loanERC20Denomination
    );

    /**
     * @notice This event is fired whenever a loan is repaid into escrow
     *
     * @param  loanId - A unique identifier for this particular loan, sourced from the Loan Coordinator.
     */
    event EscrowRepay(uint32 indexed loanId);

    /**
     * @notice This event is fired whenever a lender liquidates an outstanding loan that is owned to them that has
     * exceeded its duration. The lender receives the underlying NFT collateral, and the borrower no longer needs to
     * repay the loan principal-plus-interest.
     *
     * @param  loanId - A unique identifier for this particular loan, sourced from the Loan Coordinator.
     * @param  borrower - The address of the borrower.
     * @param  lender - The address of the lender. The lender can change their address by transferring the NFTfi ERC721
     * token that they received when the loan began.
     * @param  loanPrincipalAmount - The original sum of money transferred from lender to borrower at the beginning of
     * the loan, measured in loanERC20Denomination's smallest units.
     * @param  nftCollateralId - The ID within the NFTCollateralContract for the NFT being used as collateral for this
     * loan. The NFT is stored within this contract during the duration of the loan.
     * @param  loanMaturityDate - The unix time (measured in seconds) that the loan became due and was eligible for
     * liquidation.
     * @param  loanLiquidationDate - The unix time (measured in seconds) that liquidation occurred.
     * @param  nftCollateralContract - The ERC721 contract of the NFT collateral
     */
    event LoanLiquidated(
        uint32 indexed loanId,
        address indexed borrower,
        address indexed lender,
        uint256 loanPrincipalAmount,
        uint256 nftCollateralId,
        uint256 loanMaturityDate,
        uint256 loanLiquidationDate,
        address nftCollateralContract
    );

    /**
     * @notice This event is fired when some of the terms of a loan are being renegotiated.
     *
     * @param loanId - The unique identifier for the loan to be renegotiated
     * @param newLoanDuration - The new amount of time (measured in seconds) that can elapse before the lender can
     * liquidate the loan and seize the underlying collateral NFT.
     * @param newMaximumRepaymentAmount - The new maximum amount of money that the borrower would be required to
     * retrieve their collateral, measured in the smallest units of the ERC20 currency used for the loan. The
     * borrower will always have to pay this amount to retrieve their collateral, regardless of whether they repay
     * early.
     * @param renegotiationFee Agreed upon fee in loan denomination that borrower pays for the lender for the
     * renegotiation, has to be paid with an ERC20 transfer loanERC20Denomination token, uses transfer from,
     * frontend will have to propmt an erc20 approve for this from the borrower to the lender
     * @param renegotiationAdminFee renegotiationFee admin portion based on determined by adminFeeInBasisPoints
     */
    event LoanRenegotiated(
        uint32 indexed loanId,
        address indexed borrower,
        address indexed lender,
        uint32 newLoanDuration,
        uint256 newMaximumRepaymentAmount,
        uint256 renegotiationFee,
        uint256 renegotiationAdminFee
    );

    /**
     * @notice This event is fired whenever the admin sets a ERC20 permit.
     *
     * @param erc20Contract - Address of the ERC20 contract.
     * @param isPermitted - Signals ERC20 permit.
     */
    event ERC20Permit(address indexed erc20Contract, bool isPermitted);

    /* ************* */
    /* CUSTOM ERRORS */
    /* ************* */

    error LoanDurationOverflow();
    error BasisPointsTooHigh();
    error NoTokensOwned();
    error TokensInEscrow();
    error FunctionInformationArityMismatch();
    error TokenIsCollateral();
    error NFTNotOwned();
    error SenderNotBorrower();
    error NoNFTsOwned();
    error NoTokensInEscrow();
    error LoanAlreadyRepaidOrLiquidated();
    error LoanNotOverdueYet();
    error OnlyLenderCanLiquidate();
    error InvalidNonce();
    error RenegotiationSignatureInvalid();
    error ERC20ZeroAddress();
    error CurrencyDenominationNotPermitted();
    error NFTCollateralContractNotPermitted();
    error LoanDurationExceedsMaximum();
    error LoanDurationCannotBeZero();
    error AdminFeeChanged();

    /* *********** */
    /* CONSTRUCTOR */
    /* *********** */

    /**
     * @dev Sets `hub`
     *
     * @param _admin - Initial admin of this contract.
     * @param  _nftfiHub - NFTfiHub address
     * @param  _loanCoordinatorKey -
     * @param  _permittedErc20s -
     */
    constructor(
        address _admin,
        address _nftfiHub,
        bytes32 _loanCoordinatorKey,
        address[] memory _permittedErc20s
    ) BaseLoan(_admin) {
        hub = INftfiHub(_nftfiHub);
        LOAN_COORDINATOR = _loanCoordinatorKey;
        for (uint256 i; i < _permittedErc20s.length; ++i) {
            _setERC20Permit(_permittedErc20s[i], true);
        }
    }

    /* *************** */
    /* ADMIN FUNCTIONS */
    /* *************** */

    /**
     * @notice This function can be called by admins to change the maximumLoanDuration. Note that they can never change
     * maximumLoanDuration to be greater than UINT32_MAX, since that's the maximum space alotted for the duration in the
     * loan struct.
     *
     * @param _newMaximumLoanDuration - The new maximum loan duration, measured in seconds.
     */
    function updateMaximumLoanDuration(uint256 _newMaximumLoanDuration) external onlyOwner {
        if (_newMaximumLoanDuration > uint256(type(uint32).max)) {
            revert LoanDurationOverflow();
        }
        maximumLoanDuration = _newMaximumLoanDuration;
        emit MaximumLoanDurationUpdated(_newMaximumLoanDuration);
    }

    /**
     * @notice This function can be called by admins to change the percent of interest rates earned that they charge as
     * a fee. Note that newAdminFee can never exceed 10,000, since the fee is measured in basis points.
     *
     * @param _newAdminFeeInBasisPoints - The new admin fee measured in basis points. This is a percent of the interest
     * paid upon a loan's completion that go to the contract admins.
     */
    function updateAdminFee(uint16 _newAdminFeeInBasisPoints) external onlyOwner {
        if (_newAdminFeeInBasisPoints > HUNDRED_PERCENT) {
            revert BasisPointsTooHigh();
        }
        adminFeeInBasisPoints = _newAdminFeeInBasisPoints;
        emit AdminFeeUpdated(_newAdminFeeInBasisPoints);
    }

    /**
     * @notice used by the owner account to be able to drain ERC20 tokens received as airdrops
     * for the locked  collateral NFT-s
     * @param _tokenAddress - address of the token contract for the token to be sent out
     * @param _receiver - receiver of the token
     */
    function drainERC20Airdrop(
        address _tokenAddress,
        uint256 amount,
        address _receiver
    ) external onlyOwner {
        IERC20 tokenContract = IERC20(_tokenAddress);
        uint256 balance = tokenContract.balanceOf(address(this));
        if (balance == 0) {
            revert NoTokensOwned();
        }
        if (balance - _escrowErc20Tokens[_tokenAddress] < amount) {
            revert TokensInEscrow();
        }
        tokenContract.safeTransfer(_receiver, amount);
    }

    /**
     * @notice This function can be called by admins to change the permitted status of an ERC20 currency. This includes
     * both adding an ERC20 currency to the permitted list and removing it.
     *
     * @param _erc20 - The address of the ERC20 currency whose permit list status changed.
     * @param _permit - The new status of whether the currency is permitted or not.
     */
    function setERC20Permit(address _erc20, bool _permit) external onlyOwner {
        _setERC20Permit(_erc20, _permit);
    }

    /**
     * @notice This function can be called by admins to change the permitted status of a batch of ERC20 currency. This
     * includes both adding an ERC20 currency to the permitted list and removing it.
     *
     * @param _erc20s - The addresses of the ERC20 currencies whose permit list status changed.
     * @param _permits - The new statuses of whether the currency is permitted or not.
     */
    function setERC20Permits(address[] memory _erc20s, bool[] memory _permits) external onlyOwner {
        if (_erc20s.length != _permits.length) {
            revert FunctionInformationArityMismatch();
        }
        for (uint256 i = 0; i < _erc20s.length; ++i) {
            _setERC20Permit(_erc20s[i], _permits[i]);
        }
    }

    /**
     * @notice used by the owner account to be able to drain ERC721 tokens received as airdrops
     * for the locked  collateral NFT-s
     * @param _tokenAddress - address of the token contract for the token to be sent out
     * @param _tokenId - id token to be sent out
     * @param _receiver - receiver of the token
     */
    function drainERC721Airdrop(
        address _tokenAddress,
        uint256 _tokenId,
        address _receiver
    ) external onlyOwner {
        IERC721 tokenContract = IERC721(_tokenAddress);
        if (_escrowTokens[_tokenAddress][_tokenId] > 0) {
            revert TokenIsCollateral();
        }
        if (tokenContract.ownerOf(_tokenId) != address(this)) {
            revert NFTNotOwned();
        }
        tokenContract.safeTransferFrom(address(this), _receiver, _tokenId);
    }

    /**
     * @notice used by the owner account to be able to drain ERC1155 tokens received as airdrops
     * for the locked  collateral NFT-s
     * @param _tokenAddress - address of the token contract for the token to be sent out
     * @param _tokenId - id token to be sent out
     * @param _receiver - receiver of the token
     */
    function drainERC1155Airdrop(
        address _tokenAddress,
        uint256 _tokenId,
        address _receiver
    ) external onlyOwner {
        IERC1155 tokenContract = IERC1155(_tokenAddress);
        uint256 amount = tokenContract.balanceOf(address(this), _tokenId);
        if (_escrowTokens[_tokenAddress][_tokenId] > 0) {
            revert TokenIsCollateral();
        }
        if (amount == 0) {
            revert NoNFTsOwned();
        }
        tokenContract.safeTransferFrom(address(this), _receiver, _tokenId, amount, "");
    }

    function mintObligationReceipt(uint32 _loanId) external nonReentrant {
        address borrower = loanIdToLoan[_loanId].borrower;
        if (msg.sender != borrower) {
            revert SenderNotBorrower();
        }
        IDirectLoanCoordinator loanCoordinator = IDirectLoanCoordinator(hub.getContract(LOAN_COORDINATOR));
        loanCoordinator.mintObligationReceipt(_loanId, borrower);

        delete loanIdToLoan[_loanId].borrower;
    }

    /**
     * @dev makes possible to change loan duration and max repayment amount, loan duration even can be extended if
     * loan was expired but not liquidated.
     *
     * @param _loanId - The unique identifier for the loan to be renegotiated
     * @param _newLoanDuration - The new amount of time (measured in seconds) that can elapse before the lender can
     * liquidate the loan and seize the underlying collateral NFT.
     * @param _newMaximumRepaymentAmount - The new maximum amount of money that the borrower would be required to
     * retrieve their collateral, measured in the smallest units of the ERC20 currency used for the loan. The
     * borrower will always have to pay this amount to retrieve their collateral, regardless of whether they repay
     * early.
     * @param _renegotiationFee Agreed upon fee in ether that borrower pays for the lender for the renegitiation
     * @param _lenderNonce - The nonce referred to here is not the same as an Ethereum account's nonce. We are
     * referring instead to nonces that are used by both the lender and the borrower when they are first signing
     * off-chain NFTfi orders. These nonces can be any uint256 value that the user has not previously used to sign an
     * off-chain order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the
     * lender or the borrower in that situation. This serves two purposes:
     * - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     * - Second, it allows a user to cancel an off-chain order by calling NFTfi.cancelLoanCommitmentBeforeLoanHasBegun()
     * , which marks the nonce as used and prevents any future loan from using the user's off-chain order that contains
     * that nonce.
     * @param _expiry - The date when the renegotiation offer expires
     * @param _lenderSignature - The ECDSA signature of the lender, obtained off-chain ahead of time, signing the
     * following combination of parameters:
     * - _loanId
     * - _newLoanDuration
     * - _newMaximumRepaymentAmount
     * - _lender
     * - _expiry
     *  - address of this contract
     * - chainId
     */
    function renegotiateLoan(
        uint32 _loanId,
        uint32 _newLoanDuration,
        uint256 _newMaximumRepaymentAmount,
        uint256 _renegotiationFee,
        uint256 _lenderNonce,
        uint256 _expiry,
        bytes memory _lenderSignature
    ) external whenNotPaused nonReentrant {
        _renegotiateLoan(
            _loanId,
            _newLoanDuration,
            _newMaximumRepaymentAmount,
            _renegotiationFee,
            _lenderNonce,
            _expiry,
            _lenderSignature
        );
    }

    /**
     * @notice This function is called by a anyone to repay a loan. It can be called at any time after the loan has
     * begun and before loan expiry.. The caller will pay a pro-rata portion of their interest if the loan is paid off
     * early and the loan is pro-rated type, but the complete repayment amount if it is fixed type.
     * The the borrower (current owner of the obligation note) will get the collaterl NFT back.
     *
     * This function is purposefully not pausable in order to prevent an attack where the contract admin's pause the
     * contract and hold hostage the NFT's that are still within it.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     */
    function payBackLoan(uint32 _loanId) external nonReentrant {
        LoanChecksAndCalculations.payBackChecks(_loanId, hub);
        (
            address borrower,
            address lender,
            LoanTerms memory loan,
            IDirectLoanCoordinator loanCoordinator
        ) = _getPartiesAndData(_loanId);

        _payBackLoan(_loanId, borrower, lender, loan);

        bool repaid = true;
        _resolveLoan(_loanId, borrower, loan, loanCoordinator, repaid);
    }

    /**
     * @notice This function is called by a anyone to repay a loan. It can be called at any time after the loan has
     * begun and before loan expiry.. The caller will pay a pro-rata portion of their interest if the loan is paid off
     * early and the loan is pro-rated type, but the complete repayment amount if it is fixed type.
     * The the borrower (current owner of the obligation note) will get the collaterl NFT back.
     *
     * This function is purposefully not pausable in order to prevent an attack where the contract admin's pause the
     * contract and hold hostage the NFT's that are still within it.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     */
    function payBackLoanSafe(uint32 _loanId) external nonReentrant {
        LoanChecksAndCalculations.payBackChecks(_loanId, hub);
        (
            address borrower,
            address lender,
            LoanTerms memory loan,
            IDirectLoanCoordinator loanCoordinator
        ) = _getPartiesAndData(_loanId);

        _payBackLoanSafe(_loanId, borrower, lender, loan);

        bool repaid = true;
        _resolveLoan(_loanId, borrower, loan, loanCoordinator, repaid);
    }

    /**
     * @notice Used for lenders to get their payback from escrow,
     * in case the direct loan payback didn't work, because it caused a revert.
     *
     * @param _token  ERC20 token conract address
     */
    function getEscrowedPayBack(address _token) external nonReentrant {
        uint256 amount = _payBackEscrow[msg.sender][_token];
        if (amount == 0) {
            revert NoTokensInEscrow();
        }
        IERC20(_token).safeTransfer(msg.sender, amount);
        delete _payBackEscrow[msg.sender][_token];
        _escrowErc20Tokens[_token] -= amount;
    }

    /**
     * @notice This function is called by a lender once a loan has finished its duration and the borrower still has not
     * repaid. The lender can call this function to seize the underlying NFT collateral, although the lender gives up
     * all rights to the principal-plus-collateral by doing so.
     *
     * This function is purposefully not pausable in order to prevent an attack where the contract admin's pause
     * the contract and hold hostage the NFT's that are still within it.
     *
     * We intentionally allow anybody to call this function, although only the lender will end up receiving the seized
     * collateral. We are exploring the possbility of incentivizing users to call this function by using some of the
     * admin funds.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     */
    function liquidateOverdueLoan(uint32 _loanId) external nonReentrant {
        LoanChecksAndCalculations.checkLoanIdValidity(_loanId, hub);
        // Sanity check that payBackLoan() and liquidateOverdueLoan() have never been called on this loanId.
        // Depending on how the rest of the code turns out, this check may be unnecessary.
        if (loanRepaidOrLiquidated[_loanId]) {
            revert LoanAlreadyRepaidOrLiquidated();
        }

        (
            address borrower,
            address lender,
            LoanTerms memory loan,
            IDirectLoanCoordinator loanCoordinator
        ) = _getPartiesAndData(_loanId);

        // Ensure that the loan is indeed overdue, since we can only liquidate overdue loans.
        uint256 loanMaturityDate = uint256(loan.loanStartTime) + uint256(loan.loanDuration);
        if (block.timestamp <= loanMaturityDate) {
            revert LoanNotOverdueYet();
        }
        if (msg.sender != lender) {
            revert OnlyLenderCanLiquidate();
        }

        bool repaid = false;

        _resolveLoan(_loanId, lender, loan, loanCoordinator, repaid);

        // Emit an event with all relevant details from this transaction.
        emit LoanLiquidated(
            _loanId,
            borrower,
            lender,
            loan.loanPrincipalAmount,
            loan.nftCollateralId,
            loanMaturityDate,
            block.timestamp,
            loan.nftCollateralContract
        );
    }

    /**
     * @notice This function can be called by either a lender or a borrower to cancel all off-chain orders that they
     * have signed that contain this nonce. If the off-chain orders were created correctly, there should only be one
     * off-chain order that contains this nonce at all.
     *
     * The nonce referred to here is not the same as an Ethereum account's nonce. We are referring
     * instead to nonces that are used by both the lender and the borrower when they are first signing off-chain NFTfi
     * orders. These nonces can be any uint256 value that the user has not previously used to sign an off-chain order.
     * Each nonce can be used at most once per user within NFTfi, regardless of whether they are the lender or the
     * borrower in that situation. This serves two purposes. First, it prevents replay attacks where an attacker would
     * submit a user's off-chain order more than once. Second, it allows a user to cancel an off-chain order by calling
     * NFTfi.cancelLoanCommitmentBeforeLoanHasBegun(), which marks the nonce as used and prevents any future loan from
     * using the user's off-chain order that contains that nonce.
     *
     * @param  _nonce - User nonce
     */
    function cancelLoanCommitmentBeforeLoanHasBegun(uint256 _nonce) external {
        if (_nonceHasBeenUsedForUser[msg.sender][_nonce]) {
            revert InvalidNonce();
        }
        _nonceHasBeenUsedForUser[msg.sender][_nonce] = true;
    }

    /* ******************* */
    /* READ-ONLY FUNCTIONS */
    /* ******************* */

    /**
     * @notice This function can be used to view the current quantity of the ERC20 currency used in the specified loan
     * required by the borrower to repay their loan, measured in the smallest unit of the ERC20 currency.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     *
     * @return The amount of the specified ERC20 currency required to pay back this loan, measured in the smallest unit
     * of the specified ERC20 currency.
     */
    function getPayoffAmount(uint32 _loanId) external view virtual returns (uint256);

    /**
     * @notice This function can be used to view whether a particular nonce for a particular user has already been used,
     * either from a successful loan or a cancelled off-chain order.
     *
     * @param _user - The address of the user. This function works for both lenders and borrowers alike.
     * @param  _nonce - The nonce referred to here is not the same as an Ethereum account's nonce. We are referring
     * instead to nonces that are used by both the lender and the borrower when they are first signing off-chain
     * NFTfi orders. These nonces can be any uint256 value that the user has not previously used to sign an off-chain
     * order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the lender or
     * the borrower in that situation. This serves two purposes:
     * - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     * - Second, it allows a user to cancel an off-chain order by calling NFTfi.cancelLoanCommitmentBeforeLoanHasBegun()
     * , which marks the nonce as used and prevents any future loan from using the user's off-chain order that contains
     * that nonce.
     *
     * @return A bool representing whether or not this nonce has been used for this user.
     */
    function getWhetherNonceHasBeenUsedForUser(address _user, uint256 _nonce) external view override returns (bool) {
        return _nonceHasBeenUsedForUser[_user][_nonce];
    }

    /**
     * @notice This function can be called by anyone to get the permit associated with the erc20 contract.
     *
     * @param _erc20 - The address of the erc20 contract.
     *
     * @return Returns whether the erc20 is permitted
     */
    function getERC20Permit(address _erc20) public view override returns (bool) {
        return erc20Permits[_erc20];
    }

    /* ****************** */
    /* INTERNAL FUNCTIONS */
    /* ****************** */

    /**
     * @dev makes possible to change loan duration and max repayment amount, loan duration even can be extended if
     * loan was expired but not liquidated. IMPORTANT: Frontend will have to propt the caller to do an ERC20 approve for
     * the fee amount from themselves (borrower/obligation reciept holder) to the lender (promissory note holder)
     *
     * @param _loanId - The unique identifier for the loan to be renegotiated
     * @param _newLoanDuration - The new amount of time (measured in seconds) that can elapse before the lender can
     * liquidate the loan and seize the underlying collateral NFT.
     * @param _newMaximumRepaymentAmount - The new maximum amount of money that the borrower would be required to
     * retrieve their collateral, measured in the smallest units of the ERC20 currency used for the loan. The
     * borrower will always have to pay this amount to retrieve their collateral, regardless of whether they repay
     * early.
     * @param _renegotiationFee Agreed upon fee in loan denomination that borrower pays for the lender and
     * the admin for the renegotiation, has to be paid with an ERC20 transfer loanERC20Denomination token,
     * uses transfer from, frontend will have to propmt an erc20 approve for this from the borrower to the lender,
     * admin fee is calculated by the loan's loanAdminFeeInBasisPoints value
     * @param _lenderNonce - The nonce referred to here is not the same as an Ethereum account's nonce. We are
     * referring instead to nonces that are used by both the lender and the borrower when they are first signing
     * off-chain NFTfi orders. These nonces can be any uint256 value that the user has not previously used to sign an
     * off-chain order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the
     * lender or the borrower in that situation. This serves two purposes:
     * - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     * - Second, it allows a user to cancel an off-chain order by calling NFTfi.cancelLoanCommitmentBeforeLoanHasBegun()
     , which marks the nonce as used and prevents any future loan from using the user's off-chain order that contains
     * that nonce.
     * @param _expiry - The date when the renegotiation offer expires
     * @param _lenderSignature - The ECDSA signature of the lender, obtained off-chain ahead of time, signing the
     * following combination of parameters:
     * - _loanId
     * - _newLoanDuration
     * - _newMaximumRepaymentAmount
     * - _lender
     * - _expiry
     * - address of this contract
     * - chainId
     */
    function _renegotiateLoan(
        uint32 _loanId,
        uint32 _newLoanDuration,
        uint256 _newMaximumRepaymentAmount,
        uint256 _renegotiationFee,
        uint256 _lenderNonce,
        uint256 _expiry,
        bytes memory _lenderSignature
    ) internal {
        LoanTerms storage loan = loanIdToLoan[_loanId];

        (address borrower, address lender) = LoanChecksAndCalculations.renegotiationChecks(
            loan,
            _loanId,
            _newLoanDuration,
            _newMaximumRepaymentAmount,
            _lenderNonce,
            hub
        );

        _nonceHasBeenUsedForUser[lender][_lenderNonce] = true;

        if (
            !NFTfiSigningUtils.isValidLenderRenegotiationSignature(
                _loanId,
                _newLoanDuration,
                _newMaximumRepaymentAmount,
                _renegotiationFee,
                Signature({signer: lender, nonce: _lenderNonce, expiry: _expiry, signature: _lenderSignature})
            )
        ) {
            revert RenegotiationSignatureInvalid();
        }

        uint256 renegotiationAdminFee;
        /**
         * @notice Transfers fee to the lender immediately
         * @dev implements Checks-Effects-Interactions pattern by modifying state only after
         * the transfer happened successfully, we also add the nonReentrant modifier to
         * the pbulic versions
         */
        if (_renegotiationFee > 0) {
            renegotiationAdminFee = LoanChecksAndCalculations.computeAdminFee(
                _renegotiationFee,
                loan.loanAdminFeeInBasisPoints
            );
            // Transfer principal-plus-interest-minus-fees from the caller (always has to be borrower) to lender
            IERC20(loan.loanERC20Denomination).safeTransferFrom(
                borrower,
                lender,
                _renegotiationFee - renegotiationAdminFee
            );
            // Transfer fees from the caller (always has to be borrower) to admins
            IERC20(loan.loanERC20Denomination).safeTransferFrom(borrower, owner(), renegotiationAdminFee);
        }

        loan.loanDuration = _newLoanDuration;
        loan.maximumRepaymentAmount = _newMaximumRepaymentAmount;

        // we have to reinstate borrower record here, because obligation receipt gets deleted in reMint
        if (loan.borrower == address(0)) {
            loan.borrower = borrower;
        }
        IDirectLoanCoordinator(hub.getContract(LOAN_COORDINATOR)).resetSmartNfts(_loanId, lender);

        emit LoanRenegotiated(
            _loanId,
            borrower,
            lender,
            _newLoanDuration,
            _newMaximumRepaymentAmount,
            _renegotiationFee,
            renegotiationAdminFee
        );
    }

    /**
     * @dev Transfer collateral NFT from borrower to this contract and principal from lender to the borrower and
     * registers the new loan through the loan coordinator.
     *
     * @param _loanType - The type of loan it is being created
     * @param _loanTerms - Struct containing the loan's settings
     * @param _loanExtras - Struct containing some loan's extra settings, needed to avoid stack too deep
     * @param _lender - The address of the lender.
     * @param _referrer - The address of the referrer who found the lender matching the listing, Zero address to signal
     * that there is no referrer.
     */
    function _createLoan(
        bytes32 _loanType,
        LoanTerms memory _loanTerms,
        LoanExtras memory _loanExtras,
        address _borrower,
        address _lender,
        address _referrer
    ) internal returns (uint32) {
        // Transfer collateral from borrower to this contract to be held until
        // loan completion.
        _transferNFT(_loanTerms, _borrower, address(this));

        return _createLoanNoNftTransfer(_loanType, _loanTerms, _loanExtras, _borrower, _lender, _referrer);
    }

    /**
     * @dev Transfer principal from lender to the borrower and
     * registers the new loan through the loan coordinator.
     *
     * @param _loanType - The type of loan it is being created
     * @param _loanTerms - Struct containing the loan's settings
     * @param _loanExtras - Struct containing some loan's extra settings, needed to avoid stack too deep
     * @param _lender - The address of the lender.
     * @param _referrer - The address of the referrer who found the lender matching the listing, Zero address to signal
     * that there is no referrer.
     */
    function _createLoanNoNftTransfer(
        bytes32 _loanType,
        LoanTerms memory _loanTerms,
        LoanExtras memory _loanExtras,
        address _borrower,
        address _lender,
        address _referrer
    ) internal returns (uint32 loanId) {
        _escrowTokens[_loanTerms.nftCollateralContract][_loanTerms.nftCollateralId] += 1;

        uint256 referralfee = LoanChecksAndCalculations.computeReferralFee(
            _loanTerms.loanPrincipalAmount,
            _loanExtras.referralFeeInBasisPoints,
            _referrer
        );
        uint256 principalAmount = _loanTerms.loanPrincipalAmount - referralfee;
        if (referralfee > 0) {
            // Transfer the referral fee from lender to referrer.
            IERC20(_loanTerms.loanERC20Denomination).safeTransferFrom(_lender, _referrer, referralfee);
        }
        // Transfer principal from lender to borrower.
        IERC20(_loanTerms.loanERC20Denomination).safeTransferFrom(_lender, _borrower, principalAmount);

        // Issue an ERC721 promissory note to the lender that gives them the
        // right to either the principal-plus-interest or the collateral,
        // and an obligation note to the borrower that gives them the
        // right to pay back the loan and get the collateral back.
        IDirectLoanCoordinator loanCoordinator = IDirectLoanCoordinator(hub.getContract(LOAN_COORDINATOR));
        loanId = loanCoordinator.registerLoan(_lender, _loanType);

        // Add the loan to storage before moving collateral/principal to follow
        // the Checks-Effects-Interactions pattern.
        loanIdToLoan[loanId] = _loanTerms;
        loanIdToLoanExtras[loanId] = _loanExtras;

        return loanId;
    }

    /**
     * @dev Transfers several types of NFTs using a wrapper that knows how to handle each case.
     *
     * @param _loanTerms - Struct containing all the loan's parameters
     * @param _sender - Current owner of the NFT
     * @param _recipient - Recipient of the transfer
     */
    function _transferNFT(
        LoanTerms memory _loanTerms,
        address _sender,
        address _recipient
    ) internal {
        Address.functionDelegateCall(
            _loanTerms.nftCollateralWrapper,
            abi.encodeWithSelector(
                INftWrapper(_loanTerms.nftCollateralWrapper).transferNFT.selector,
                _sender,
                _recipient,
                _loanTerms.nftCollateralContract,
                _loanTerms.nftCollateralId
            ),
            "NFT not successfully transferred"
        );
    }

    /**
     * @notice This function is called by a anyone to repay a loan. It can be called at any time after the loan has
     * begun and before loan expiry.. The caller will pay a pro-rata portion of their interest if the loan is paid off
     * early and the loan is pro-rated type, but the complete repayment amount if it is fixed type.
     * The the borrower (current owner of the obligation note) will get the collaterl NFT back.
     *
     * This function is purposefully not pausable in order to prevent an attack where the contract admin's pause the
     * contract and hold hostage the NFT's that are still within it.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     */
    function _payBackLoan(
        uint32 _loanId,
        address _borrower,
        address _lender,
        LoanTerms memory _loan
    ) internal {
        // Fetch loan details from storage, but store them in memory for the sake of saving gas.
        LoanExtras memory loanExtras = loanIdToLoanExtras[_loanId];

        (uint256 adminFee, uint256 payoffAmount) = _payoffAndFee(_loan);

        // Transfer principal-plus-interest-minus-fees from the caller to lender
        IERC20(_loan.loanERC20Denomination).safeTransferFrom(msg.sender, _lender, payoffAmount);

        uint256 revenueShare = LoanChecksAndCalculations.computeRevenueShare(
            adminFee,
            loanExtras.revenueShareInBasisPoints
        );
        // PermittedPartners contract doesn't allow to set a revenueShareInBasisPoints for address zero so revenuShare
        // > 0 implies that revenueSharePartner ~= address(0), BUT revenueShare can be zero for a partener when the
        // adminFee is low
        if (revenueShare > 0 && loanExtras.revenueSharePartner != address(0)) {
            adminFee -= revenueShare;
            // Transfer revenue share from the caller to permitted partner
            IERC20(_loan.loanERC20Denomination).safeTransferFrom(
                msg.sender,
                loanExtras.revenueSharePartner,
                revenueShare
            );
        }

        // Transfer fees from the caller to admins
        IERC20(_loan.loanERC20Denomination).safeTransferFrom(msg.sender, owner(), adminFee);

        // Emit an event with all relevant details from this transaction.
        emit LoanRepaid(
            _loanId,
            _borrower,
            _lender,
            _loan.loanPrincipalAmount,
            _loan.nftCollateralId,
            payoffAmount,
            adminFee,
            revenueShare,
            loanExtras.revenueSharePartner, // this could be a non address zero even if revenueShare is 0
            _loan.nftCollateralContract,
            _loan.loanERC20Denomination
        );
    }

    /**
     * @notice This function is called by a anyone to repay a loan. It can be called at any time after the loan has
     * begun and before loan expiry.. The caller will pay a pro-rata portion of their interest if the loan is paid off
     * early and the loan is pro-rated type, but the complete repayment amount if it is fixed type.
     * The the borrower (current owner of the obligation note) will get the collaterl NFT back.
     *
     * This function is purposefully not pausable in order to prevent an attack where the contract admin's pause the
     * contract and hold hostage the NFT's that are still within it.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     */
    function _payBackLoanSafe(
        uint32 _loanId,
        address _borrower,
        address _lender,
        LoanTerms memory _loan
    ) internal {
        // Fetch loan details from storage, but store them in memory for the sake of saving gas.
        LoanExtras memory loanExtras = loanIdToLoanExtras[_loanId];

        (uint256 adminFee, uint256 payoffAmount) = _payoffAndFee(_loan);

        // use try to detect the case of erc20 transfer failing for some reason (e.g. USDC blacklisted address)
        try IERC20(_loan.loanERC20Denomination).transferFrom(msg.sender, _lender, payoffAmount) {
            // solhint-disable-previous-line no-empty-blocks
        } catch {
            // if ERC20 transfer fails, we store the amount in escrow in this contract
            IERC20(_loan.loanERC20Denomination).safeTransferFrom(msg.sender, address(this), payoffAmount);
            _payBackEscrow[_lender][_loan.loanERC20Denomination] += payoffAmount;
            _escrowErc20Tokens[_loan.loanERC20Denomination] += payoffAmount;
            emit EscrowRepay(_loanId);
        }

        uint256 revenueShare = LoanChecksAndCalculations.computeRevenueShare(
            adminFee,
            loanExtras.revenueShareInBasisPoints
        );

        // PermittedPartners contract doesn't allow to set a revenueShareInBasisPoints for address zero so revenuShare
        // > 0 implies that revenueSharePartner ~= address(0), BUT revenueShare can be zero for a partener when the
        // adminFee is low
        if (revenueShare > 0 && loanExtras.revenueSharePartner != address(0)) {
            adminFee -= revenueShare;
            // Transfer revenue share from the caller to permitted partner
            // try is here so if for whatever reason (USCD blacklist specifically) this
            // transfer would fail the borrowerr still can pay back and get their nft back
            // revenue share can be later drained by us and distributed manually
            try
                IERC20(_loan.loanERC20Denomination).transferFrom(
                    msg.sender,
                    loanExtras.revenueSharePartner,
                    revenueShare
                )
            {
                // solhint-disable-previous-line no-empty-blocks
            } catch {
                IERC20(_loan.loanERC20Denomination).safeTransferFrom(msg.sender, address(this), revenueShare);
            }
        }

        // Transfer fees from the caller to admins
        // try is here so if for whatever reason (USCD blacklist specifically) this
        // transfer would fail the borrowerr still can pay back and get their nft back
        // admin fee can be later drained by us
        try IERC20(_loan.loanERC20Denomination).transferFrom(msg.sender, owner(), adminFee) {
            // solhint-disable-previous-line no-empty-blocks
        } catch {
            IERC20(_loan.loanERC20Denomination).safeTransferFrom(msg.sender, address(this), adminFee);
        }

        // Emit an event with all relevant details from this transaction.
        emit LoanRepaid(
            _loanId,
            _borrower,
            _lender,
            _loan.loanPrincipalAmount,
            _loan.nftCollateralId,
            payoffAmount,
            adminFee,
            revenueShare,
            loanExtras.revenueSharePartner, // this could be a non address zero even if revenueShare is 0
            _loan.nftCollateralContract,
            _loan.loanERC20Denomination
        );
    }

    /**
     * @notice A convenience function with shared functionality between `payBackLoan` and `liquidateOverdueLoan`.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     * @param _nftReceiver - The receiver of the collateral nft. The borrower when `payBackLoan` or the lender when
     * `liquidateOverdueLoan`.
     * @param _loanTerms - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoan.
     * @param _loanCoordinator - The loan coordinator used when creating the loan.
     */
    function _resolveLoan(
        uint32 _loanId,
        address _nftReceiver,
        LoanTerms memory _loanTerms,
        IDirectLoanCoordinator _loanCoordinator,
        bool _repaid
    ) internal {
        _resolveLoanNoNftTransfer(_loanId, _loanTerms, _loanCoordinator, _repaid);
        // Transfer collateral from this contract to the lender, since the lender is seizing collateral for an overdue
        // loan
        _transferNFT(_loanTerms, address(this), _nftReceiver);
    }

    /**
     * @notice Resolving the loan without trasferring the nft to provide a base for the bundle
     * break up of the bundled loans
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     * @param _loanTerms - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoan.
     * @param _loanCoordinator - The loan coordinator used when creating the loan.
     */
    function _resolveLoanNoNftTransfer(
        uint32 _loanId,
        LoanTerms memory _loanTerms,
        IDirectLoanCoordinator _loanCoordinator,
        bool _repaid
    ) internal {
        // Mark loan as liquidated before doing any external transfers to follow the Checks-Effects-Interactions design
        // pattern
        loanRepaidOrLiquidated[_loanId] = true;

        _escrowTokens[_loanTerms.nftCollateralContract][_loanTerms.nftCollateralId] -= 1;

        // Destroy the lender's promissory note for this loan and borrower obligation receipt
        _loanCoordinator.resolveLoan(_loanId, _repaid);
    }

    /**
     * @notice This function can be called by admins to change the permitted status of an ERC20 currency. This includes
     * both adding an ERC20 currency to the permitted list and removing it.
     *
     * @param _erc20 - The address of the ERC20 currency whose permit list status changed.
     * @param _permit - The new status of whether the currency is permitted or not.
     */
    function _setERC20Permit(address _erc20, bool _permit) internal {
        if (_erc20 == address(0)) {
            revert ERC20ZeroAddress();
        }
        erc20Permits[_erc20] = _permit;

        emit ERC20Permit(_erc20, _permit);
    }

    /**
     * @dev Performs some validation checks over loan parameters
     *
     */
    function _loanSanityChecks(LoanData.Offer memory _offer, address _nftWrapper) internal view {
        if (!getERC20Permit(_offer.loanERC20Denomination)) {
            revert CurrencyDenominationNotPermitted();
        }
        if (_nftWrapper == address(0)) {
            revert NFTCollateralContractNotPermitted();
        }
        if (uint256(_offer.loanDuration) > maximumLoanDuration) {
            revert LoanDurationExceedsMaximum();
        }
        if (uint256(_offer.loanDuration) == 0) {
            revert LoanDurationCannotBeZero();
        }
        if (_offer.loanAdminFeeInBasisPoints != adminFeeInBasisPoints) {
            revert AdminFeeChanged();
        }
    }

    /**
     * @dev reads some variable values of a loan for payback functions, created to reduce code repetition
     */
    function _getPartiesAndData(uint32 _loanId)
        internal
        view
        returns (
            address borrower,
            address lender,
            LoanTerms memory loan,
            IDirectLoanCoordinator loanCoordinator
        )
    {
        loanCoordinator = IDirectLoanCoordinator(hub.getContract(LOAN_COORDINATOR));
        IDirectLoanCoordinator.Loan memory loanCoordinatorData = loanCoordinator.getLoanData(_loanId);
        uint256 smartNftId = loanCoordinatorData.smartNftId;
        // Fetch loan details from storage, but store them in memory for the sake of saving gas.
        loan = loanIdToLoan[_loanId];
        if (loan.borrower != address(0)) {
            borrower = loan.borrower;
        } else {
            // Fetch current owner of loan obligation note.
            borrower = IERC721(loanCoordinator.obligationReceiptToken()).ownerOf(smartNftId);
        }
        lender = IERC721(loanCoordinator.promissoryNoteToken()).ownerOf(smartNftId);
    }

    /**
     * @dev Creates a `LoanExtras` struct using data sent as the borrower's extra settings.
     * This is needed in order to avoid stack too deep issues.
     */
    function _setupLoanExtras(address _revenueSharePartner, uint16 _referralFeeInBasisPoints)
        internal
        view
        returns (LoanExtras memory)
    {
        // Save loan details to a struct in memory first, to save on gas if any
        // of the below checks fail, and to avoid the "Stack Too Deep" error by
        // clumping the parameters together into one struct held in memory.
        return
            LoanExtras({
                revenueSharePartner: _revenueSharePartner,
                revenueShareInBasisPoints: LoanChecksAndCalculations.getRevenueSharePercent(_revenueSharePartner, hub),
                referralFeeInBasisPoints: _referralFeeInBasisPoints
            });
    }

    /**
     * @dev Calculates the payoff amount and admin fee
     */
    function _payoffAndFee(LoanTerms memory _loanTerms) internal view virtual returns (uint256, uint256);

    /**
     * @dev Checks that the collateral is a supported contracts and returns what wrapper to use for the loan's NFT
     * collateral contract.
     *
     * @param _nftCollateralContract - The address of the the NFT collateral contract.
     *
     * @return Address of the NftWrapper to use for the loan's NFT collateral.
     */
    function _getWrapper(address _nftCollateralContract) internal view returns (address) {
        return IPermittedNFTs(hub.getContract(ContractKeys.PERMITTED_NFTS)).getNFTWrapper(_nftCollateralContract);
    }
}

File 29 of 37 : DirectLoanFixedOffer.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "./DirectLoanBaseMinimal.sol";
import "../../../utils/ContractKeys.sol";

/**
 * @title  DirectLoanFixedOffer
 * @author NFTfi
 * @notice Main contract for NFTfi Direct Loans Fixed Type. This contract manages the ability to create NFT-backed
 * peer-to-peer loans of type Fixed (agreed to be a fixed-repayment loan) where the borrower pays the
 * maximumRepaymentAmount regardless of whether they repay early or not.
 *
 * There are two ways to commence an NFT-backed loan:
 *
 * a. The borrower accepts a lender's offer by calling `acceptOffer`.
 *   1. the borrower calls nftContract.approveAll(NFTfi), approving the NFTfi contract to move their NFT's on their
 * be1alf.
 *   2. the lender calls erc20Contract.approve(NFTfi), allowing NFTfi to move the lender's ERC20 tokens on their
 * behalf.
 *   3. the lender signs an off-chain message, proposing its offer terms.
 *   4. the borrower calls `acceptOffer` to accept these terms and enter into the loan. The NFT is stored in
 * the contract, the borrower receives the loan principal in the specified ERC20 currency, the lender receives an
 * NFTfi promissory note (in ERC721 form) that represents the rights to either the principal-plus-interest, or the
 * underlying NFT collateral if the borrower does not pay back in time, and the borrower receives obligation receipt
 * (in ERC721 form) that gives them the right to pay back the loan and get the collateral back.
 *
 * The lender can freely transfer and trade this ERC721 promissory note as they wish, with the knowledge that
 * transferring the ERC721 promissory note tranfsers the rights to principal-plus-interest and/or collateral, and that
 * they will no longer have a claim on the loan. The ERC721 promissory note itself represents that claim.
 *
 * The borrower can freely transfer and trade this ERC721 obligaiton receipt as they wish, with the knowledge that
 * transferring the ERC721 obligaiton receipt tranfsers the rights right to pay back the loan and get the collateral
 * back.
 *
 *
 * A loan may end in one of two ways:
 * - First, a borrower may call NFTfi.payBackLoan() and pay back the loan plus interest at any time, in which case they
 * receive their NFT back in the same transaction.
 * - Second, if the loan's duration has passed and the loan has not been paid back yet, a lender can call
 * NFTfi.liquidateOverdueLoan(), in which case they receive the underlying NFT collateral and forfeit the rights to the
 * principal-plus-interest, which the borrower now keeps.
 */
contract DirectLoanFixedOffer is DirectLoanBaseMinimal {
    /* ************* */
    /* CUSTOM ERRORS */
    /* ************* */

    error InvalidLenderSignature();
    error NegativeInterestRate();

    /* *********** */
    /* CONSTRUCTOR */
    /* *********** */

    /**
     * @dev Sets `hub` and permitted erc20-s
     *
     * @param _admin - Initial admin of this contract.
     * @param  _nftfiHub - NFTfiHub address
     * @param  _permittedErc20s - list of permitted ERC20 token contract addresses
     */
    constructor(
        address _admin,
        address _nftfiHub,
        address[] memory _permittedErc20s
    )
        DirectLoanBaseMinimal(
            _admin,
            _nftfiHub,
            ContractKeys.getIdFromStringKey("DIRECT_LOAN_COORDINATOR"),
            _permittedErc20s
        )
    {
        // solhint-disable-previous-line no-empty-blocks
    }

    /* ********* */
    /* FUNCTIONS */
    /* ********* */

    /**
     * @notice This function is called by the borrower when accepting a lender's offer to begin a loan.
     *
     * @param _offer - The offer made by the lender.
     * @param _signature - The components of the lender's signature.
     * @param _borrowerSettings - Some extra parameters that the borrower needs to set when accepting an offer.
     */
    function acceptOffer(
        Offer memory _offer,
        Signature memory _signature,
        BorrowerSettings memory _borrowerSettings
    ) external virtual whenNotPaused nonReentrant returns (uint32) {
        address nftWrapper = _getWrapper(_offer.nftCollateralContract);
        _loanSanityChecks(_offer, nftWrapper);
        _loanSanityChecksOffer(_offer);
        return
            _acceptOffer(
                _setupLoanTerms(_offer, nftWrapper),
                _setupLoanExtras(_borrowerSettings.revenueSharePartner, _borrowerSettings.referralFeeInBasisPoints),
                _offer,
                _signature
            );
    }

    /* ******************* */
    /* READ-ONLY FUNCTIONS */
    /* ******************* */

    /**
     * @notice This function returns a bytes32 value identifying the loan type for the coordinator
     */
    // all caps, because used to be a constant storage and the interface should be the same
    // solhint-disable-next-line func-name-mixedcase
    function LOAN_TYPE() public pure virtual returns (bytes32) {
        return bytes32("DIRECT_LOAN_FIXED_OFFER");
    }

    /**
     * @notice This function can be used to view the current quantity of the ERC20 currency used in the specified loan
     * required by the borrower to repay their loan, measured in the smallest unit of the ERC20 currency.
     *
     * @param _loanId  A unique identifier for this particular loan, sourced from the Loan Coordinator.
     *
     * @return The amount of the specified ERC20 currency required to pay back this loan, measured in the smallest unit
     * of the specified ERC20 currency.
     */
    function getPayoffAmount(uint32 _loanId) external view override returns (uint256) {
        LoanTerms storage loan = loanIdToLoan[_loanId];
        return loan.maximumRepaymentAmount;
    }

    /* ****************** */
    /* INTERNAL FUNCTIONS */
    /* ****************** */

    /**
     * @notice This function is called by the borrower when accepting a lender's offer to begin a loan.
     *
     * @param _loanTerms - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoan.
     * @param _loanExtras - The main Loan Terms struct. This data is saved upon loan creation on loanIdToLoanExtras.
     * @param _offer - The offer made by the lender.
     * @param _signature - The components of the lender's signature.
     */
    function _acceptOffer(
        LoanTerms memory _loanTerms,
        LoanExtras memory _loanExtras,
        Offer memory _offer,
        Signature memory _signature
    ) internal virtual returns (uint32) {
        // Check loan nonces. These are different from Ethereum account nonces.
        // Here, these are uint256 numbers that should uniquely identify
        // each signature for each user (i.e. each user should only create one
        // off-chain signature for each nonce, with a nonce being any arbitrary
        // uint256 value that they have not used yet for an off-chain NFTfi
        // signature).
        if (_nonceHasBeenUsedForUser[_signature.signer][_signature.nonce]) {
            revert InvalidNonce();
        }

        _nonceHasBeenUsedForUser[_signature.signer][_signature.nonce] = true;

        if (!NFTfiSigningUtils.isValidLenderSignature(_offer, _signature)) {
            revert InvalidLenderSignature();
        }

        uint32 loanId = _createLoan(
            LOAN_TYPE(),
            _loanTerms,
            _loanExtras,
            msg.sender,
            _signature.signer,
            _offer.referrer
        );

        // Emit an event with all relevant details from this transaction.
        emit LoanStarted(loanId, msg.sender, _signature.signer, _loanTerms, _loanExtras);
        return loanId;
    }

    /**
     * @dev Creates a `LoanTerms` struct using data sent as the lender's `_offer` on `acceptOffer`.
     * This is needed in order to avoid stack too deep issues.
     * Since this is a Fixed loan type loanInterestRateForDurationInBasisPoints is ignored.
     */
    function _setupLoanTerms(Offer memory _offer, address _nftWrapper) internal view returns (LoanTerms memory) {
        return
            LoanTerms({
                loanERC20Denomination: _offer.loanERC20Denomination,
                loanPrincipalAmount: _offer.loanPrincipalAmount,
                maximumRepaymentAmount: _offer.maximumRepaymentAmount,
                nftCollateralContract: _offer.nftCollateralContract,
                nftCollateralWrapper: _nftWrapper,
                nftCollateralId: _offer.nftCollateralId,
                loanStartTime: uint64(block.timestamp),
                loanDuration: _offer.loanDuration,
                loanInterestRateForDurationInBasisPoints: uint16(0),
                loanAdminFeeInBasisPoints: _offer.loanAdminFeeInBasisPoints,
                borrower: msg.sender
            });
    }

    /**
     * @dev Calculates the payoff amount and admin fee
     *
     * @param _loanTerms - Struct containing all the loan's parameters
     */
    function _payoffAndFee(LoanTerms memory _loanTerms)
        internal
        pure
        override
        returns (uint256 adminFee, uint256 payoffAmount)
    {
        // Calculate amounts to send to lender and admins
        uint256 interestDue = _loanTerms.maximumRepaymentAmount - _loanTerms.loanPrincipalAmount;
        adminFee = LoanChecksAndCalculations.computeAdminFee(
            interestDue,
            uint256(_loanTerms.loanAdminFeeInBasisPoints)
        );
        payoffAmount = _loanTerms.maximumRepaymentAmount - adminFee;
    }

    /**
     * @dev Function that performs some validation checks over loan parameters when accepting an offer
     *
     */
    function _loanSanityChecksOffer(LoanData.Offer memory _offer) internal pure {
        if (_offer.maximumRepaymentAmount < _offer.loanPrincipalAmount) {
            revert NegativeInterestRate();
        }
    }
}

File 30 of 37 : IDirectLoanBase.sol
// SPDX-License-Identifier: BUSL-1.1

import "./LoanData.sol";

pragma solidity 0.8.19;

interface IDirectLoanBase {
    function maximumLoanDuration() external view returns (uint256);

    function adminFeeInBasisPoints() external view returns (uint16);

    // solhint-disable-next-line func-name-mixedcase
    function LOAN_COORDINATOR() external view returns (bytes32);

    function loanIdToLoan(uint32)
        external
        view
        returns (
            uint256,
            uint256,
            uint256,
            address,
            uint32,
            uint16,
            uint16,
            address,
            uint64,
            address,
            address
        );

    function loanRepaidOrLiquidated(uint32) external view returns (bool);

    function getWhetherNonceHasBeenUsedForUser(address _user, uint256 _nonce) external view returns (bool);
}

File 31 of 37 : LoanChecksAndCalculations.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "./IDirectLoanBase.sol";
import "./LoanData.sol";
import "../../../interfaces/IDirectLoanCoordinator.sol";
import "../../../utils/ContractKeys.sol";
import "../../../interfaces/INftfiHub.sol";
import "../../../interfaces/IPermittedPartners.sol";
import "../../../interfaces/IPermittedERC20s.sol";

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/**
 * @title  LoanChecksAndCalculations
 * @author NFTfi
 * @notice Helper library for LoanBase
 */
library LoanChecksAndCalculations {
    uint16 private constant HUNDRED_PERCENT = 10000;

    /**
     * @dev Function that performs some validation checks before trying to repay a loan
     *
     * @param _loanId - The id of the loan being repaid
     */
    function payBackChecks(uint32 _loanId, INftfiHub _hub) external view {
        checkLoanIdValidity(_loanId, _hub);
        // Sanity check that payBackLoan() and liquidateOverdueLoan() have never been called on this loanId.
        // Depending on how the rest of the code turns out, this check may be unnecessary.
        require(!IDirectLoanBase(address(this)).loanRepaidOrLiquidated(_loanId), "Loan already repaid/liquidated");

        // Fetch loan details from storage, but store them in memory for the sake of saving gas.
        (, , , , uint32 loanDuration, , , , uint64 loanStartTime, , ) = IDirectLoanBase(address(this)).loanIdToLoan(
            _loanId
        );

        // When a loan exceeds the loan term, it is expired. At this stage the Lender can call Liquidate Loan to resolve
        // the loan.
        require(block.timestamp <= (uint256(loanStartTime) + uint256(loanDuration)), "Loan is expired");
    }

    function checkLoanIdValidity(uint32 _loanId, INftfiHub _hub) public view {
        require(
            IDirectLoanCoordinator(_hub.getContract(IDirectLoanBase(address(this)).LOAN_COORDINATOR())).isValidLoanId(
                _loanId,
                address(this)
            ),
            "invalid loanId"
        );
    }

    /**
     * @dev Function that the partner is permitted and returns its shared percent.
     *
     * @param _revenueSharePartner - Partner's address
     *
     * @return The revenue share percent for the partner.
     */
    function getRevenueSharePercent(address _revenueSharePartner, INftfiHub _hub) external view returns (uint16) {
        // return soon if no partner is set to avoid a public call
        if (_revenueSharePartner == address(0)) {
            return 0;
        }

        uint16 revenueSharePercent = IPermittedPartners(_hub.getContract(ContractKeys.PERMITTED_PARTNERS))
        .getPartnerPermit(_revenueSharePartner);

        return revenueSharePercent;
    }

    /**
     * @dev Performs some validation checks before trying to renegotiate a loan.
     * Needed to avoid stack too deep.
     *
     * @param _loan - The main Loan Terms struct.
     * @param _loanId - The unique identifier for the loan to be renegotiated
     * @param _newLoanDuration - The new amount of time (measured in seconds) that can elapse before the lender can
     * liquidate the loan and seize the underlying collateral NFT.
     * @param _newMaximumRepaymentAmount - The new maximum amount of money that the borrower would be required to
     * retrieve their collateral, measured in the smallest units of the ERC20 currency used for the loan. The
     * borrower will always have to pay this amount to retrieve their collateral, regardless of whether they repay
     * early.
     * @param _lenderNonce - The nonce referred to here is not the same as an Ethereum account's nonce. We are
     * referring instead to nonces that are used by both the lender and the borrower when they are first signing
     * off-chain NFTfi orders. These nonces can be any uint256 value that the user has not previously used to sign an
     * off-chain order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the
     * lender or the borrower in that situation. This serves two purposes:
     * - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     * - Second, it allows a user to cancel an off-chain order by calling NFTfi.cancelLoanCommitmentBeforeLoanHasBegun()
     , which marks the nonce as used and prevents any future loan from using the user's off-chain order that contains
     * that nonce.
     * @return Borrower and Lender addresses
     */
    function renegotiationChecks(
        LoanData.LoanTerms memory _loan,
        uint32 _loanId,
        uint32 _newLoanDuration,
        uint256 _newMaximumRepaymentAmount,
        uint256 _lenderNonce,
        INftfiHub _hub
    ) external view returns (address, address) {
        checkLoanIdValidity(_loanId, _hub);
        IDirectLoanCoordinator loanCoordinator = IDirectLoanCoordinator(
            _hub.getContract(IDirectLoanBase(address(this)).LOAN_COORDINATOR())
        );
        uint256 smartNftId = loanCoordinator.getLoanData(_loanId).smartNftId;

        address borrower;

        if (_loan.borrower != address(0)) {
            borrower = _loan.borrower;
        } else {
            borrower = IERC721(loanCoordinator.obligationReceiptToken()).ownerOf(smartNftId);
        }

        require(msg.sender == borrower, "Only borrower can initiate");
        require(block.timestamp <= (uint256(_loan.loanStartTime) + _newLoanDuration), "New duration already expired");
        require(
            uint256(_newLoanDuration) <= IDirectLoanBase(address(this)).maximumLoanDuration(),
            "New duration exceeds maximum loan duration"
        );
        require(!IDirectLoanBase(address(this)).loanRepaidOrLiquidated(_loanId), "Loan already repaid/liquidated");
        require(
            _newMaximumRepaymentAmount >= _loan.loanPrincipalAmount,
            "Negative interest rate loans are not allowed."
        );

        // Fetch current owner of loan promissory note.
        address lender = IERC721(loanCoordinator.promissoryNoteToken()).ownerOf(smartNftId);

        require(
            !IDirectLoanBase(address(this)).getWhetherNonceHasBeenUsedForUser(lender, _lenderNonce),
            "Lender nonce invalid"
        );

        return (borrower, lender);
    }

    /**
     * @notice A convenience function computing the revenue share taken from the admin fee to transferr to the permitted
     * partner.
     *
     * @param _adminFee - The quantity of ERC20 currency (measured in smalled units of that ERC20 currency) that is due
     * as an admin fee.
     * @param _revenueShareInBasisPoints - The percent (measured in basis points) of the admin fee amount that will be
     * taken as a revenue share for a the partner, at the moment the loan is begun.
     *
     * @return The quantity of ERC20 currency (measured in smalled units of that ERC20 currency) that should be sent to
     * the `revenueSharePartner`.
     */
    function computeRevenueShare(uint256 _adminFee, uint256 _revenueShareInBasisPoints)
        external
        pure
        returns (uint256)
    {
        return (_adminFee * _revenueShareInBasisPoints) / HUNDRED_PERCENT;
    }

    /**
     * @notice A convenience function computing the adminFee taken from a specified quantity of interest.
     *
     * @param _interestDue - The amount of interest due, measured in the smallest quantity of the ERC20 currency being
     * used to pay the interest.
     * @param _adminFeeInBasisPoints - The percent (measured in basis points) of the interest earned that will be taken
     * as a fee by the contract admins when the loan is repaid. The fee is stored in the loan struct to prevent an
     * attack where the contract admins could adjust the fee right before a loan is repaid, and take all of the interest
     * earned.
     *
     * @return The quantity of ERC20 currency (measured in smalled units of that ERC20 currency) that is due as an admin
     * fee.
     */
    function computeAdminFee(uint256 _interestDue, uint256 _adminFeeInBasisPoints) external pure returns (uint256) {
        return (_interestDue * _adminFeeInBasisPoints) / HUNDRED_PERCENT;
    }

    /**
     * @notice A convenience function computing the referral fee taken from the loan principal amount to transferr to
     * the referrer.
     *
     * @param _loanPrincipalAmount - The original sum of money transferred from lender to borrower at the beginning of
     * the loan, measured in loanERC20Denomination's smallest units.
     * @param _referralFeeInBasisPoints - The percent (measured in basis points) of the loan principal amount that will
     * be taken as a fee to pay to the referrer, 0 if the lender is not paying referral fee.
     * @param _referrer - The address of the referrer who found the lender matching the listing, Zero address to signal
     * that there is no referrer.
     *
     * @return The quantity of ERC20 currency (measured in smalled units of that ERC20 currency) that should be sent to
     * the referrer.
     */
    function computeReferralFee(
        uint256 _loanPrincipalAmount,
        uint256 _referralFeeInBasisPoints,
        address _referrer
    ) external pure returns (uint256) {
        if (_referralFeeInBasisPoints == 0 || _referrer == address(0)) {
            return 0;
        }
        return (_loanPrincipalAmount * _referralFeeInBasisPoints) / HUNDRED_PERCENT;
    }
}

File 32 of 37 : LoanData.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

/**
 * @title  LoanData
 * @author NFTfi
 * @notice An interface containg the main Loan struct shared by Direct Loans types.
 */
interface LoanData {
    /* ********** */
    /* DATA TYPES */
    /* ********** */

    /**
     * @notice The main Loan Terms struct. This data is saved upon loan creation.
     *
     * @param loanERC20Denomination - The address of the ERC20 contract of the currency being used as principal/interest
     * for this loan.
     * @param loanPrincipalAmount - The original sum of money transferred from lender to borrower at the beginning of
     * the loan, measured in loanERC20Denomination's smallest units.
     * @param maximumRepaymentAmount - The maximum amount of money that the borrower would be required to retrieve their
     * collateral, measured in the smallest units of the ERC20 currency used for the loan. The borrower will always have
     * to pay this amount to retrieve their collateral, regardless of whether they repay early.
     * @param nftCollateralContract - The address of the the NFT collateral contract.
     * @param nftCollateralWrapper - The NFTfi wrapper of the NFT collateral contract.
     * @param nftCollateralId - The ID within the NFTCollateralContract for the NFT being used as collateral for this
     * loan. The NFT is stored within this contract during the duration of the loan.
     * @param loanStartTime - The block.timestamp when the loan first began (measured in seconds).
     * @param loanDuration - The amount of time (measured in seconds) that can elapse before the lender can liquidate
     * the loan and seize the underlying collateral NFT.
     * @param loanInterestRateForDurationInBasisPoints - This is the interest rate (measured in basis points, e.g.
     * hundreths of a percent) for the loan, that must be repaid pro-rata by the borrower at the conclusion of the loan
     * or risk seizure of their nft collateral. Note if the type of the loan is fixed then this value  is not used and
     * is irrelevant so it should be set to 0.
     * @param loanAdminFeeInBasisPoints - The percent (measured in basis points) of the interest earned that will be
     * taken as a fee by the contract admins when the loan is repaid. The fee is stored in the loan struct to prevent an
     * attack where the contract admins could adjust the fee right before a loan is repaid, and take all of the interest
     * earned.
     * @param borrower
     */
    struct LoanTerms {
        uint256 loanPrincipalAmount;
        uint256 maximumRepaymentAmount;
        uint256 nftCollateralId;
        address loanERC20Denomination;
        uint32 loanDuration;
        uint16 loanInterestRateForDurationInBasisPoints;
        uint16 loanAdminFeeInBasisPoints;
        address nftCollateralWrapper;
        uint64 loanStartTime;
        address nftCollateralContract;
        address borrower;
    }

    /**
     * @notice Some extra Loan's settings struct. This data is saved upon loan creation.
     * We need this to avoid stack too deep errors.
     *
     * @param revenueSharePartner - The address of the partner that will receive the revenue share.
     * @param revenueShareInBasisPoints - The percent (measured in basis points) of the admin fee amount that will be
     * taken as a revenue share for a t
     * @param referralFeeInBasisPoints - The percent (measured in basis points) of the loan principal amount that will
     * be taken as a fee to pay to the referrer, 0 if the lender is not paying referral fee.he partner, at the moment
     * the loan is begun.
     */
    struct LoanExtras {
        address revenueSharePartner;
        uint16 revenueShareInBasisPoints;
        uint16 referralFeeInBasisPoints;
    }

    /**
     * @notice The offer made by the lender. Used as parameter on both acceptOffer (initiated by the borrower)
     *
     * @param loanERC20Denomination - The address of the ERC20 contract of the currency being used as principal/interest
     * for this loan.
     * @param loanPrincipalAmount - The original sum of money transferred from lender to borrower at the beginning of
     * the loan, measured in loanERC20Denomination's smallest units.
     * @param maximumRepaymentAmount - The maximum amount of money that the borrower would be required to retrieve their
     *  collateral, measured in the smallest units of the ERC20 currency used for the loan. The borrower will always
     * have to pay this amount to retrieve their collateral, regardless of whether they repay early.
     * @param nftCollateralContract - The address of the ERC721 contract of the NFT collateral.
     * @param nftCollateralId - The ID within the NFTCollateralContract for the NFT being used as collateral for this
     * loan. The NFT is stored within this contract during the duration of the loan.
     * @param referrer - The address of the referrer who found the lender matching the listing, Zero address to signal
     * this there is no referrer.
     * @param loanDuration - The amount of time (measured in seconds) that can elapse before the lender can liquidate
     * the loan and seize the underlying collateral NFT.
     * @param loanAdminFeeInBasisPoints - The percent (measured in basis points) of the interest earned that will be
     * taken as a fee by the contract admins when the loan is repaid. The fee is stored in the loan struct to prevent an
     * attack where the contract admins could adjust the fee right before a loan is repaid, and take all of the interest
     * earned.
     */
    struct Offer {
        uint256 loanPrincipalAmount;
        uint256 maximumRepaymentAmount;
        uint256 nftCollateralId;
        address nftCollateralContract;
        uint32 loanDuration;
        uint16 loanAdminFeeInBasisPoints;
        address loanERC20Denomination;
        address referrer;
    }

    /**
     * @notice Signature related params. Used as parameter on both acceptOffer (containing borrower signature)
     *
     * @param signer - The address of the signer. The borrower for `acceptOffer`
     * @param nonce - The nonce referred here is not the same as an Ethereum account's nonce.
     * We are referring instead to a nonce that is used by the lender or the borrower when they are first signing
     * off-chain NFTfi orders. These nonce can be any uint256 value that the user has not previously used to sign an
     * off-chain order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the
     * lender or the borrower in that situation. This serves two purposes:
     * - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     * - Second, it allows a user to cancel an off-chain order by calling NFTfi.cancelLoanCommitmentBeforeLoanHasBegun()
     * , which marks the nonce as used and prevents any future loan from using the user's off-chain order that contains
     * that nonce.
     * @param expiry - Date when the signature expires
     * @param signature - The ECDSA signature of the borrower or the lender, obtained off-chain ahead of time, signing
     * the following combination of parameters:
     * - Lender:
     *   - Offer.loanERC20Denomination
     *   - Offer.loanPrincipalAmount
     *   - Offer.maximumRepaymentAmount
     *   - Offer.nftCollateralContract
     *   - Offer.nftCollateralId
     *   - Offer.referrer
     *   - Offer.loanDuration
     *   - Offer.loanAdminFeeInBasisPoints
     *   - Signature.signer,
     *   - Signature.nonce,
     *   - Signature.expiry,
     *   - address of the loan type contract
     *   - chainId
     */
    struct Signature {
        uint256 nonce;
        uint256 expiry;
        address signer;
        bytes signature;
    }

    /**
     * inclusive min and max Id ranges for collection offers on collections,
     * like ArtBlocks, where multiple collections are defined on one contract differentiated by id-ranges
     */
    struct CollectionIdRange {
        uint256 minId;
        uint256 maxId;
    }

    /**
     * @notice Some extra parameters that the borrower needs to set when accepting an offer.
     *
     * @param revenueSharePartner - The address of the partner that will receive the revenue share.
     * @param referralFeeInBasisPoints - The percent (measured in basis points) of the loan principal amount that will
     * be taken as a fee to pay to the referrer, 0 if the lender is not paying referral fee.
     */
    struct BorrowerSettings {
        address revenueSharePartner;
        uint16 referralFeeInBasisPoints;
    }
}

File 33 of 37 : ContractKeys.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

/**
 * @title ContractKeys
 * @author NFTfi
 * @dev Common library for contract keys
 */
library ContractKeys {
    bytes32 public constant PERMITTED_ERC20S = bytes32("PERMITTED_ERC20S");
    bytes32 public constant PERMITTED_NFTS = bytes32("PERMITTED_NFTS");
    bytes32 public constant PERMITTED_PARTNERS = bytes32("PERMITTED_PARTNERS");
    bytes32 public constant NFT_TYPE_REGISTRY = bytes32("NFT_TYPE_REGISTRY");
    bytes32 public constant LOAN_REGISTRY = bytes32("LOAN_REGISTRY");
    bytes32 public constant PERMITTED_SNFT_RECEIVER = bytes32("PERMITTED_SNFT_RECEIVER");

    /**
     * @notice Returns the bytes32 representation of a string
     * @param _key the string key
     * @return id bytes32 representation
     */
    function getIdFromStringKey(string memory _key) external pure returns (bytes32 id) {
        require(bytes(_key).length <= 32, "invalid key");

        // solhint-disable-next-line no-inline-assembly
        assembly {
            id := mload(add(_key, 32))
        }
    }
}

File 34 of 37 : NFTfiCollectionOfferSigningUtils.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "../loans/direct/loanTypes/LoanData.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

/**
 * @title  NFTfiCollectionOfferSigningUtils
 * @author NFTfi
 * @notice Helper contract for NFTfi. This contract manages verifying signatures from off-chain NFTfi orders.
 * Based on the version of this same contract used on NFTfi V1
 */
library NFTfiCollectionOfferSigningUtils {
    /* ********* */
    /* FUNCTIONS */
    /* ********* */

    /**
     * @dev This function gets the current chain ID.
     */
    function getChainID() internal view returns (uint256) {
        uint256 id;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            id := chainid()
        }
        return id;
    }

    /**
     * @notice This function is when the borrower accepts a lender's offer, to validate the lender's signature that the
     * lender provided off-chain to verify that it did indeed made such offer.
     *
     * @param _offer - The offer struct containing:
     * - loanERC20Denomination: The address of the ERC20 contract of the currency being used as principal/interest
     * for this loan.
     * - loanPrincipalAmount: The original sum of money transferred from lender to borrower at the beginning of
     * the loan, measured in loanERC20Denomination's smallest units.
     * - maximumRepaymentAmount: The maximum amount of money that the borrower would be required to retrieve their
     * collateral, measured in the smallest units of the ERC20 currency used for the loan. The borrower will always have
     * to pay this amount to retrieve their collateral, regardless of whether they repay early.
     * - nftCollateralContract: The address of the ERC721 contract of the NFT collateral.
     * - nftCollateralId: The ID within the NFTCollateralContract for the NFT being used as collateral for this
     * loan. The NFT is stored within this contract during the duration of the loan.
     * - referrer: The address of the referrer who found the lender matching the listing, Zero address to signal
     * this there is no referrer.
     * - loanDuration: The amount of time (measured in seconds) that can elapse before the lender can liquidate the
     * loan and seize the underlying collateral NFT.
     * - loanInterestRateForDurationInBasisPoints: This is the interest rate (measured in basis points, e.g.
     * hundreths of a percent) for the loan, that must be repaid pro-rata by the borrower at the conclusion of the loan
     * or risk seizure of their nft collateral. Note if the type of the loan is fixed then this value  is not used and
     * is irrelevant so it should be set to 0.
     * - loanAdminFeeInBasisPoints: The percent (measured in basis points) of the interest earned that will be
     * taken as a fee by the contract admins when the loan is repaid. The fee is stored in the loan struct to prevent an
     * attack where the contract admins could adjust the fee right before a loan is repaid, and take all of the interest
     * earned.
     * @param _idRange - min and max (inclusive) Id ranges for collection offers on collections,
     * like ArtBlocks, where multiple collections are defined on one contract differentiated by id-ranges
     * @param _signature - The signature structure containing:
     * - signer: The address of the signer. The borrower for `acceptOffer`
     * - nonce: The nonce referred here is not the same as an Ethereum account's nonce.
     * We are referring instead to a nonce that is used by the lender or the borrower when they are first signing
     * off-chain NFTfi orders. These nonce can be any uint256 value that the user has not previously used to sign an
     * off-chain order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the
     * lender or the borrower in that situation. This serves two purposes:
     *   - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     *   - Second, it allows a user to cancel an off-chain order by calling
     * NFTfi.cancelLoanCommitmentBeforeLoanHasBegun(), which marks the nonce as used and prevents any future loan from
     * using the user's off-chain order that contains that nonce.
     * - expiry: Date when the signature expires
     * - signature: The ECDSA signature of the lender, obtained off-chain ahead of time, signing the following
     * combination of parameters:
     *   - offer.loanERC20Denomination
     *   - offer.loanPrincipalAmount
     *   - offer.maximumRepaymentAmount
     *   - offer.nftCollateralContract
     *   - offer.nftCollateralId
     *   - offer.referrer
     *   - offer.loanDuration
     *   - offer.loanAdminFeeInBasisPoints,
     *   - idRange.minId,
     *   - idRange.maxId,
     *   - signature.signer,
     *   - signature.nonce,
     *   - signature.expiry,
     *   - address of this contract
     *   - chainId
     */
    function isValidLenderSignatureWithIdRange(
        LoanData.Offer memory _offer,
        LoanData.CollectionIdRange memory _idRange,
        LoanData.Signature memory _signature
    ) internal view returns (bool) {
        return isValidLenderSignatureWithIdRange(_offer, _idRange, _signature, address(this));
    }

    /**
     * @dev This function overload the previous function to allow the caller to specify the address of the contract
     *
     */
    function isValidLenderSignatureWithIdRange(
        LoanData.Offer memory _offer,
        LoanData.CollectionIdRange memory _idRange,
        LoanData.Signature memory _signature,
        address _loanContract
    ) internal view returns (bool) {
        require(block.timestamp <= _signature.expiry, "Lender Signature has expired");
        require(_loanContract != address(0), "Loan is zero address");
        if (_signature.signer == address(0)) {
            return false;
        } else {
            bytes32 message = keccak256(
                abi.encodePacked(
                    getEncodedOffer(_offer),
                    abi.encodePacked(_idRange.minId, _idRange.maxId),
                    getEncodedSignature(_signature),
                    _loanContract,
                    getChainID()
                )
            );

            return
                SignatureChecker.isValidSignatureNow(
                    _signature.signer,
                    ECDSA.toEthSignedMessageHash(message),
                    _signature.signature
                );
        }
    }

    /**
     * @dev We need this to avoid stack too deep errors.
     */
    function getEncodedOffer(LoanData.Offer memory _offer) internal pure returns (bytes memory) {
        return
            abi.encodePacked(
                _offer.loanERC20Denomination,
                _offer.loanPrincipalAmount,
                _offer.maximumRepaymentAmount,
                _offer.nftCollateralContract,
                _offer.nftCollateralId,
                _offer.referrer,
                _offer.loanDuration,
                _offer.loanAdminFeeInBasisPoints
            );
    }

    /**
     * @dev We need this to avoid stack too deep errors.
     */
    function getEncodedSignature(LoanData.Signature memory _signature) internal pure returns (bytes memory) {
        return abi.encodePacked(_signature.signer, _signature.nonce, _signature.expiry);
    }
}

File 35 of 37 : NFTfiSigningUtils.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "../loans/direct/loanTypes/LoanData.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

/**
 * @title  NFTfiSigningUtils
 * @author NFTfi
 * @notice Helper contract for NFTfi. This contract manages verifying signatures from off-chain NFTfi orders.
 * Based on the version of this same contract used on NFTfi V1
 */
library NFTfiSigningUtils {
    /* ********* */
    /* FUNCTIONS */
    /* ********* */

    /**
     * @dev This function gets the current chain ID.
     */
    function getChainID() internal view returns (uint256) {
        uint256 id;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            id := chainid()
        }
        return id;
    }

    /**
     * @notice This function is when the borrower accepts a lender's offer, to validate the lender's signature that the
     * lender provided off-chain to verify that it did indeed made such offer.
     *
     * @param _offer - The offer struct containing:
     * - loanERC20Denomination: The address of the ERC20 contract of the currency being used as principal/interest
     * for this loan.
     * - loanPrincipalAmount: The original sum of money transferred from lender to borrower at the beginning of
     * the loan, measured in loanERC20Denomination's smallest units.
     * - maximumRepaymentAmount: The maximum amount of money that the borrower would be required to retrieve their
     * collateral, measured in the smallest units of the ERC20 currency used for the loan. The borrower will always have
     * to pay this amount to retrieve their collateral, regardless of whether they repay early.
     * - nftCollateralContract: The address of the ERC721 contract of the NFT collateral.
     * - nftCollateralId: The ID within the NFTCollateralContract for the NFT being used as collateral for this
     * loan. The NFT is stored within this contract during the duration of the loan.
     * - referrer: The address of the referrer who found the lender matching the listing, Zero address to signal
     * this there is no referrer.
     * - loanDuration: The amount of time (measured in seconds) that can elapse before the lender can liquidate the
     * loan and seize the underlying collateral NFT.
     * - loanInterestRateForDurationInBasisPoints: This is the interest rate (measured in basis points, e.g.
     * hundreths of a percent) for the loan, that must be repaid pro-rata by the borrower at the conclusion of the loan
     * or risk seizure of their nft collateral. Note if the type of the loan is fixed then this value  is not used and
     * is irrelevant so it should be set to 0.
     * - loanAdminFeeInBasisPoints: The percent (measured in basis points) of the interest earned that will be
     * taken as a fee by the contract admins when the loan is repaid. The fee is stored in the loan struct to prevent an
     * attack where the contract admins could adjust the fee right before a loan is repaid, and take all of the interest
     * earned.
     * @param _signature - The signature structure containing:
     * - signer: The address of the signer. The borrower for `acceptOffer`
     * - nonce: The nonce referred here is not the same as an Ethereum account's nonce.
     * We are referring instead to a nonce that is used by the lender or the borrower when they are first signing
     * off-chain NFTfi orders. These nonce can be any uint256 value that the user has not previously used to sign an
     * off-chain order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the
     * lender or the borrower in that situation. This serves two purposes:
     *   - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     *   - Second, it allows a user to cancel an off-chain order by calling
     * NFTfi.cancelLoanCommitmentBeforeLoanHasBegun(), which marks the nonce as used and prevents any future loan from
     * using the user's off-chain order that contains that nonce.
     * - expiry: Date when the signature expires
     * - signature: The ECDSA signature of the lender, obtained off-chain ahead of time, signing the following
     * combination of parameters:
     *   - offer.loanERC20Denomination
     *   - offer.loanPrincipalAmount
     *   - offer.maximumRepaymentAmount
     *   - offer.nftCollateralContract
     *   - offer.nftCollateralId
     *   - offer.referrer
     *   - offer.loanDuration
     *   - offer.loanAdminFeeInBasisPoints
     *   - signature.signer,
     *   - signature.nonce,
     *   - signature.expiry,
     *   - address of this contract
     *   - chainId
     */
    function isValidLenderSignature(LoanData.Offer memory _offer, LoanData.Signature memory _signature)
        external
        view
        returns (bool)
    {
        return isValidLenderSignature(_offer, _signature, address(this));
    }

    /**
     * @dev This function overload the previous function to allow the caller to specify the address of the contract
     *
     */
    function isValidLenderSignature(
        LoanData.Offer memory _offer,
        LoanData.Signature memory _signature,
        address _loanContract
    ) public view returns (bool) {
        require(block.timestamp <= _signature.expiry, "Lender Signature has expired");
        require(_loanContract != address(0), "Loan is zero address");
        if (_signature.signer == address(0)) {
            return false;
        } else {
            bytes32 message = keccak256(
                abi.encodePacked(getEncodedOffer(_offer), getEncodedSignature(_signature), _loanContract, getChainID())
            );

            return
                SignatureChecker.isValidSignatureNow(
                    _signature.signer,
                    ECDSA.toEthSignedMessageHash(message),
                    _signature.signature
                );
        }
    }

    /**
     * @notice This function is called in renegotiateLoan() to validate the lender's signature that the lender provided
     * off-chain to verify that they did indeed want to agree to this loan renegotiation according to these terms.
     *
     * @param _loanId - The unique identifier for the loan to be renegotiated
     * @param _newLoanDuration - The new amount of time (measured in seconds) that can elapse before the lender can
     * liquidate the loan and seize the underlying collateral NFT.
     * @param _newMaximumRepaymentAmount - The new maximum amount of money that the borrower would be required to
     * retrieve their collateral, measured in the smallest units of the ERC20 currency used for the loan. The
     * borrower will always have to pay this amount to retrieve their collateral, regardless of whether they repay
     * early.
     * @param _renegotiationFee Agreed upon fee in ether that borrower pays for the lender for the renegitiation
     * @param _signature - The signature structure containing:
     * - signer: The address of the signer. The borrower for `acceptOffer`
     * - nonce: The nonce referred here is not the same as an Ethereum account's nonce.
     * We are referring instead to a nonce that is used by the lender or the borrower when they are first signing
     * off-chain NFTfi orders. These nonce can be any uint256 value that the user has not previously used to sign an
     * off-chain order. Each nonce can be used at most once per user within NFTfi, regardless of whether they are the
     * lender or the borrower in that situation. This serves two purposes:
     * - First, it prevents replay attacks where an attacker would submit a user's off-chain order more than once.
     * - Second, it allows a user to cancel an off-chain order by calling NFTfi.cancelLoanCommitmentBeforeLoanHasBegun()
     * , which marks the nonce as used and prevents any future loan from using the user's off-chain order that contains
     * that nonce.
     * - expiry - The date when the renegotiation offer expires
     * - lenderSignature - The ECDSA signature of the lender, obtained off-chain ahead of time, signing the
     * following combination of parameters:
     * - _loanId
     * - _newLoanDuration
     * - _newMaximumRepaymentAmount
     * - _lender
     * - _lenderNonce
     * - _expiry
     * - address of this contract
     * - chainId
     */
    function isValidLenderRenegotiationSignature(
        uint256 _loanId,
        uint32 _newLoanDuration,
        uint256 _newMaximumRepaymentAmount,
        uint256 _renegotiationFee,
        LoanData.Signature memory _signature
    ) external view returns (bool) {
        return
            isValidLenderRenegotiationSignature(
                _loanId,
                _newLoanDuration,
                _newMaximumRepaymentAmount,
                _renegotiationFee,
                _signature,
                address(this)
            );
    }

    /**
     * @dev This function overload the previous function to allow the caller to specify the address of the contract
     *
     */
    function isValidLenderRenegotiationSignature(
        uint256 _loanId,
        uint32 _newLoanDuration,
        uint256 _newMaximumRepaymentAmount,
        uint256 _renegotiationFee,
        LoanData.Signature memory _signature,
        address _loanContract
    ) public view returns (bool) {
        require(block.timestamp <= _signature.expiry, "Renegotiation Signature expired");
        require(_loanContract != address(0), "Loan is zero address");
        if (_signature.signer == address(0)) {
            return false;
        } else {
            bytes32 message = keccak256(
                abi.encodePacked(
                    _loanId,
                    _newLoanDuration,
                    _newMaximumRepaymentAmount,
                    _renegotiationFee,
                    getEncodedSignature(_signature),
                    _loanContract,
                    getChainID()
                )
            );

            return
                SignatureChecker.isValidSignatureNow(
                    _signature.signer,
                    ECDSA.toEthSignedMessageHash(message),
                    _signature.signature
                );
        }
    }

    /**
     * @dev We need this to avoid stack too deep errors.
     */
    function getEncodedOffer(LoanData.Offer memory _offer) internal pure returns (bytes memory) {
        return
            abi.encodePacked(
                _offer.loanERC20Denomination,
                _offer.loanPrincipalAmount,
                _offer.maximumRepaymentAmount,
                _offer.nftCollateralContract,
                _offer.nftCollateralId,
                _offer.referrer,
                _offer.loanDuration,
                _offer.loanAdminFeeInBasisPoints
            );
    }

    /**
     * @dev We need this to avoid stack too deep errors.
     */
    function getEncodedSignature(LoanData.Signature memory _signature) internal pure returns (bytes memory) {
        return abi.encodePacked(_signature.signer, _signature.nonce, _signature.expiry);
    }
}

File 36 of 37 : NftReceiver.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";

/**
 * @title NftReceiver
 * @author NFTfi
 * @dev Base contract with capabilities for receiving ERC1155 and ERC721 tokens
 */
abstract contract NftReceiver is IERC1155Receiver, ERC721Holder {
    /**
     *  @dev Handles the receipt of a single ERC1155 token type. This function is called at the end of a
     * `safeTransferFrom` after the balance has been updated.
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if allowed
     */
    function onERC1155Received(
        address,
        address,
        uint256,
        uint256,
        bytes calldata
    ) external virtual override returns (bytes4) {
        return this.onERC1155Received.selector;
    }

    /**
     *  @dev Handles the receipt of a multiple ERC1155 token types. This function is called at the end of a
     * `safeBatchTransferFrom` after the balances have been updated.
     *  @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if allowed
     */
    function onERC1155BatchReceived(
        address,
        address,
        uint256[] calldata,
        uint256[] calldata,
        bytes calldata
    ) external virtual override returns (bytes4) {
        revert("ERC1155 batch not supported");
    }

    /**
     * @dev Checks whether this contract implements the interface defined by `interfaceId`.
     * @param _interfaceId Id of the interface
     * @return true if this contract implements the interface
     */
    function supportsInterface(bytes4 _interfaceId) public view virtual override returns (bool) {
        return
            _interfaceId == type(IERC1155Receiver).interfaceId ||
            _interfaceId == type(IERC721Receiver).interfaceId ||
            _interfaceId == type(IERC165).interfaceId;
    }
}

File 37 of 37 : Ownable.sol
// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.19;

import "@openzeppelin/contracts/utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 *
 * Modified version from openzeppelin/contracts/access/Ownable.sol that allows to
 * initialize the owner using a parameter in the constructor
 */
abstract contract Ownable is Context {
    address private _owner;

    address private _ownerCandidate;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor(address _initialOwner) {
        _setOwner(_initialOwner);
    }

    /**
     * @dev Requests transferring ownership of the contract to a new account (`_newOwnerCandidate`).
     * Can only be called by the current owner.
     */
    function requestTransferOwnership(address _newOwnerCandidate) public virtual onlyOwner {
        require(_newOwnerCandidate != address(0), "Ownable: new owner is the zero address");
        _ownerCandidate = _newOwnerCandidate;
    }

    function acceptTransferOwnership() public virtual {
        require(_ownerCandidate == _msgSender(), "Ownable: not owner candidate");
        _setOwner(_ownerCandidate);
        delete _ownerCandidate;
    }

    function cancelTransferOwnership() public virtual onlyOwner {
        delete _ownerCandidate;
    }

    function rejectTransferOwnership() public virtual {
        require(_ownerCandidate == _msgSender(), "Ownable: not owner candidate");
        delete _ownerCandidate;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Sets the owner.
     */
    function _setOwner(address _newOwner) internal {
        address oldOwner = _owner;
        _owner = _newOwner;
        emit OwnershipTransferred(oldOwner, _newOwner);
    }
}

Settings
{
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 100
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {
    "contracts/utils/NFTfiSigningUtils.sol": {
      "NFTfiSigningUtils": "0x199e38f5ed54bc56c4dc7fdd0c5c64eae923673f"
    },
    "contracts/loans/direct/loanTypes/LoanChecksAndCalculations.sol": {
      "LoanChecksAndCalculations": "0xc955962611226cd2ae467a097aec900e4b722294"
    },
    "contracts/utils/ContractKeys.sol": {
      "ContractKeys": "0x733aC632056AA272130Af63809fF3301C80bD1e7"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_admin","type":"address"},{"internalType":"address","name":"_nftfiHub","type":"address"},{"internalType":"address[]","name":"_permittedErc20s","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AdminFeeChanged","type":"error"},{"inputs":[],"name":"BasisPointsTooHigh","type":"error"},{"inputs":[],"name":"CollateralIdNotInRange","type":"error"},{"inputs":[],"name":"CurrencyDenominationNotPermitted","type":"error"},{"inputs":[],"name":"ERC20ZeroAddress","type":"error"},{"inputs":[],"name":"FunctionInformationArityMismatch","type":"error"},{"inputs":[],"name":"InvalidLenderSignature","type":"error"},{"inputs":[],"name":"InvalidNonce","type":"error"},{"inputs":[],"name":"LoanAlreadyRepaidOrLiquidated","type":"error"},{"inputs":[],"name":"LoanDurationCannotBeZero","type":"error"},{"inputs":[],"name":"LoanDurationExceedsMaximum","type":"error"},{"inputs":[],"name":"LoanDurationOverflow","type":"error"},{"inputs":[],"name":"LoanNotOverdueYet","type":"error"},{"inputs":[],"name":"MinIdGreaterThanMaxId","type":"error"},{"inputs":[],"name":"NFTCollateralContractNotPermitted","type":"error"},{"inputs":[],"name":"NFTNotOwned","type":"error"},{"inputs":[],"name":"NegativeInterestRate","type":"error"},{"inputs":[],"name":"NoNFTsOwned","type":"error"},{"inputs":[],"name":"NoTokensInEscrow","type":"error"},{"inputs":[],"name":"NoTokensOwned","type":"error"},{"inputs":[],"name":"OnlyLenderCanLiquidate","type":"error"},{"inputs":[],"name":"OriginalAcceptOfferDisabled","type":"error"},{"inputs":[],"name":"RenegotiationSignatureInvalid","type":"error"},{"inputs":[],"name":"SenderNotBorrower","type":"error"},{"inputs":[],"name":"TokenIsCollateral","type":"error"},{"inputs":[],"name":"TokensInEscrow","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newAdminFee","type":"uint16"}],"name":"AdminFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"erc20Contract","type":"address"},{"indexed":false,"internalType":"bool","name":"isPermitted","type":"bool"}],"name":"ERC20Permit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"loanId","type":"uint32"}],"name":"EscrowRepay","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"loanId","type":"uint32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint256","name":"loanPrincipalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nftCollateralId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"loanMaturityDate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"loanLiquidationDate","type":"uint256"},{"indexed":false,"internalType":"address","name":"nftCollateralContract","type":"address"}],"name":"LoanLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"loanId","type":"uint32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint32","name":"newLoanDuration","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"newMaximumRepaymentAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"renegotiationFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"renegotiationAdminFee","type":"uint256"}],"name":"LoanRenegotiated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"loanId","type":"uint32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"indexed":false,"internalType":"uint256","name":"loanPrincipalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nftCollateralId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountPaidToLender","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"adminFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"revenueShare","type":"uint256"},{"indexed":false,"internalType":"address","name":"revenueSharePartner","type":"address"},{"indexed":false,"internalType":"address","name":"nftCollateralContract","type":"address"},{"indexed":false,"internalType":"address","name":"loanERC20Denomination","type":"address"}],"name":"LoanRepaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"loanId","type":"uint32"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":true,"internalType":"address","name":"lender","type":"address"},{"components":[{"internalType":"uint256","name":"loanPrincipalAmount","type":"uint256"},{"internalType":"uint256","name":"maximumRepaymentAmount","type":"uint256"},{"internalType":"uint256","name":"nftCollateralId","type":"uint256"},{"internalType":"address","name":"loanERC20Denomination","type":"address"},{"internalType":"uint32","name":"loanDuration","type":"uint32"},{"internalType":"uint16","name":"loanInterestRateForDurationInBasisPoints","type":"uint16"},{"internalType":"uint16","name":"loanAdminFeeInBasisPoints","type":"uint16"},{"internalType":"address","name":"nftCollateralWrapper","type":"address"},{"internalType":"uint64","name":"loanStartTime","type":"uint64"},{"internalType":"address","name":"nftCollateralContract","type":"address"},{"internalType":"address","name":"borrower","type":"address"}],"indexed":false,"internalType":"struct LoanData.LoanTerms","name":"loanTerms","type":"tuple"},{"components":[{"internalType":"address","name":"revenueSharePartner","type":"address"},{"internalType":"uint16","name":"revenueShareInBasisPoints","type":"uint16"},{"internalType":"uint16","name":"referralFeeInBasisPoints","type":"uint16"}],"indexed":false,"internalType":"struct LoanData.LoanExtras","name":"loanExtras","type":"tuple"}],"name":"LoanStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newMaximumLoanDuration","type":"uint256"}],"name":"MaximumLoanDurationUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"HUNDRED_PERCENT","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOAN_COORDINATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOAN_TYPE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"loanPrincipalAmount","type":"uint256"},{"internalType":"uint256","name":"maximumRepaymentAmount","type":"uint256"},{"internalType":"uint256","name":"nftCollateralId","type":"uint256"},{"internalType":"address","name":"nftCollateralContract","type":"address"},{"internalType":"uint32","name":"loanDuration","type":"uint32"},{"internalType":"uint16","name":"loanAdminFeeInBasisPoints","type":"uint16"},{"internalType":"address","name":"loanERC20Denomination","type":"address"},{"internalType":"address","name":"referrer","type":"address"}],"internalType":"struct LoanData.Offer","name":"_offer","type":"tuple"},{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct LoanData.Signature","name":"_signature","type":"tuple"},{"components":[{"internalType":"address","name":"revenueSharePartner","type":"address"},{"internalType":"uint16","name":"referralFeeInBasisPoints","type":"uint16"}],"internalType":"struct LoanData.BorrowerSettings","name":"_borrowerSettings","type":"tuple"}],"name":"acceptCollectionOffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"loanPrincipalAmount","type":"uint256"},{"internalType":"uint256","name":"maximumRepaymentAmount","type":"uint256"},{"internalType":"uint256","name":"nftCollateralId","type":"uint256"},{"internalType":"address","name":"nftCollateralContract","type":"address"},{"internalType":"uint32","name":"loanDuration","type":"uint32"},{"internalType":"uint16","name":"loanAdminFeeInBasisPoints","type":"uint16"},{"internalType":"address","name":"loanERC20Denomination","type":"address"},{"internalType":"address","name":"referrer","type":"address"}],"internalType":"struct LoanData.Offer","name":"_offer","type":"tuple"},{"components":[{"internalType":"uint256","name":"minId","type":"uint256"},{"internalType":"uint256","name":"maxId","type":"uint256"}],"internalType":"struct LoanData.CollectionIdRange","name":"_idRange","type":"tuple"},{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct LoanData.Signature","name":"_signature","type":"tuple"},{"components":[{"internalType":"address","name":"revenueSharePartner","type":"address"},{"internalType":"uint16","name":"referralFeeInBasisPoints","type":"uint16"}],"internalType":"struct LoanData.BorrowerSettings","name":"_borrowerSettings","type":"tuple"}],"name":"acceptCollectionOfferWithIdRange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"loanPrincipalAmount","type":"uint256"},{"internalType":"uint256","name":"maximumRepaymentAmount","type":"uint256"},{"internalType":"uint256","name":"nftCollateralId","type":"uint256"},{"internalType":"address","name":"nftCollateralContract","type":"address"},{"internalType":"uint32","name":"loanDuration","type":"uint32"},{"internalType":"uint16","name":"loanAdminFeeInBasisPoints","type":"uint16"},{"internalType":"address","name":"loanERC20Denomination","type":"address"},{"internalType":"address","name":"referrer","type":"address"}],"internalType":"struct LoanData.Offer","name":"","type":"tuple"},{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct LoanData.Signature","name":"","type":"tuple"},{"components":[{"internalType":"address","name":"revenueSharePartner","type":"address"},{"internalType":"uint16","name":"referralFeeInBasisPoints","type":"uint16"}],"internalType":"struct LoanData.BorrowerSettings","name":"","type":"tuple"}],"name":"acceptOffer","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"acceptTransferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"adminFeeInBasisPoints","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nonce","type":"uint256"}],"name":"cancelLoanCommitmentBeforeLoanHasBegun","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelTransferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"drainERC1155Airdrop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"drainERC20Airdrop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"drainERC721Airdrop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_erc20","type":"address"}],"name":"getERC20Permit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"getEscrowedPayBack","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_loanId","type":"uint32"}],"name":"getPayoffAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_nonce","type":"uint256"}],"name":"getWhetherNonceHasBeenUsedForUser","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hub","outputs":[{"internalType":"contract INftfiHub","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_loanId","type":"uint32"}],"name":"liquidateOverdueLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"loanIdToLoan","outputs":[{"internalType":"uint256","name":"loanPrincipalAmount","type":"uint256"},{"internalType":"uint256","name":"maximumRepaymentAmount","type":"uint256"},{"internalType":"uint256","name":"nftCollateralId","type":"uint256"},{"internalType":"address","name":"loanERC20Denomination","type":"address"},{"internalType":"uint32","name":"loanDuration","type":"uint32"},{"internalType":"uint16","name":"loanInterestRateForDurationInBasisPoints","type":"uint16"},{"internalType":"uint16","name":"loanAdminFeeInBasisPoints","type":"uint16"},{"internalType":"address","name":"nftCollateralWrapper","type":"address"},{"internalType":"uint64","name":"loanStartTime","type":"uint64"},{"internalType":"address","name":"nftCollateralContract","type":"address"},{"internalType":"address","name":"borrower","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"loanIdToLoanExtras","outputs":[{"internalType":"address","name":"revenueSharePartner","type":"address"},{"internalType":"uint16","name":"revenueShareInBasisPoints","type":"uint16"},{"internalType":"uint16","name":"referralFeeInBasisPoints","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"loanRepaidOrLiquidated","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maximumLoanDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_loanId","type":"uint32"}],"name":"mintObligationReceipt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_loanId","type":"uint32"}],"name":"payBackLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_loanId","type":"uint32"}],"name":"payBackLoanSafe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rejectTransferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_loanId","type":"uint32"},{"internalType":"uint32","name":"_newLoanDuration","type":"uint32"},{"internalType":"uint256","name":"_newMaximumRepaymentAmount","type":"uint256"},{"internalType":"uint256","name":"_renegotiationFee","type":"uint256"},{"internalType":"uint256","name":"_lenderNonce","type":"uint256"},{"internalType":"uint256","name":"_expiry","type":"uint256"},{"internalType":"bytes","name":"_lenderSignature","type":"bytes"}],"name":"renegotiateLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwnerCandidate","type":"address"}],"name":"requestTransferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_erc20","type":"address"},{"internalType":"bool","name":"_permit","type":"bool"}],"name":"setERC20Permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_erc20s","type":"address[]"},{"internalType":"bool[]","name":"_permits","type":"bool[]"}],"name":"setERC20Permits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_newAdminFeeInBasisPoints","type":"uint16"}],"name":"updateAdminFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newMaximumLoanDuration","type":"uint256"}],"name":"updateMaximumLoanDuration","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60c06040526301e91c806003556004805461ffff19166101f41790553480156200002857600080fd5b50604051620051ce380380620051ce8339810160408190526200004b9162000298565b828282828273733ac632056aa272130af63809ff3301c80bd1e763f99a8ffb6040518163ffffffff1660e01b8152600401620000b89060208082526017908201527f4449524543545f4c4f414e5f434f4f5244494e41544f52000000000000000000604082015260600190565b602060405180830381865af4158015620000d6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000fc919062000392565b8383806200010a816200018e565b50506001805460ff60a01b191681556002556001600160a01b03831660a052608082905260005b81518110156200017d576200016a828281518110620001545762000154620003ac565b60200260200101516001620001de60201b60201c565b6200017581620003c2565b905062000131565b5050505050505050505050620003ea565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b0382166200020657604051636e8ab17b60e11b815260040160405180910390fd5b6001600160a01b0382166000818152600c6020908152604091829020805460ff191685151590811790915591519182527ff100355be652ecc881568750e6a98c0713e4316f75d5314ebc9039e0acb52f24910160405180910390a25050565b80516001600160a01b03811681146200027d57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600080600060608486031215620002ae57600080fd5b620002b98462000265565b92506020620002ca81860162000265565b60408601519093506001600160401b0380821115620002e857600080fd5b818701915087601f830112620002fd57600080fd5b81518181111562000312576200031262000282565b8060051b604051601f19603f830116810181811085821117156200033a576200033a62000282565b60405291825284820192508381018501918a8311156200035957600080fd5b938501935b828510156200038257620003728562000265565b845293850193928501926200035e565b8096505050505050509250925092565b600060208284031215620003a557600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b600060018201620003e357634e487b7160e01b600052601160045260246000fd5b5060010190565b60805160a051614d5c62000472600039600081816104e1015281816109030152818161123f015281816114b6015281816117070152818161184a01528181611b5e01528181611d7601528181612500015281816127bc015261349d01526000818161059f0152818161148d01528181611d4d0152818161279601526134740152614d5c6000f3fe608060405234801561001057600080fd5b50600436106102535760003560e01c806377cfa99111610146578063a4441a6f116100c3578063bc197c8111610087578063bc197c81146106c9578063bce42e42146106dc578063c192f4e5146106ef578063ddfddad614610702578063eda928ab14610715578063f23a6e611461072857600080fd5b8063a4441a6f14610659578063ab3b128014610667578063ac4e35ea14610690578063b18e7772146106a3578063b31ec1d4146106b657600080fd5b8063872873be1161010a578063872873be146105f75780638da5cb5b1461062357806392fede001461062b5780639658e405146106335780639d6fa6181461064657600080fd5b806377cfa9911461059a5780637836baf1146105c157806379b64040146105d45780637b371107146105e75780638456cb59146105ef57600080fd5b8063328404b0116101d457806356efe98c1161019857806356efe98c1461053e5780635c975abb146105665780635f992fdd1461056e578063616693d8146105765780636ed93dd01461057e57600080fd5b8063328404b0146104a3578063365a86fc146104dc5780633f4ba83a1461051057806347948d92146105185780635163a1c31461052b57600080fd5b80631c6caf411161021b5780631c6caf41146103505780631f908a1c14610365578063227cda18146103785780632b2180221461047d5780632c1d4ec21461049057600080fd5b806301ffc9a7146102585780630717f3aa146102805780630ff81c3f146102a3578063150b7a021461030d578063192b355d14610339575b600080fd5b61026b610266366004613d55565b610748565b60405190151581526020015b60405180910390f35b61026b61028e366004613da1565b60076020526000908152604090205460ff1681565b6102e36102b1366004613da1565b6006602052600090815260409020546001600160a01b0381169061ffff600160a01b8204811691600160b01b90041683565b604080516001600160a01b03909416845261ffff9283166020850152911690820152606001610277565b61032061031b366004613ec8565b61079a565b6040516001600160e01b03199091168152602001610277565b61034260035481565b604051908152602001610277565b61036361035e366004613f4e565b6107ab565b005b6103636103733660046140f2565b610855565b610409610386366004613da1565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006909501549395929491936001600160a01b0380831694600160a01b80850463ffffffff1695600160c01b860461ffff90811696600160d01b9004169484841694929093046001600160401b03169290821691168b565b604080519b8c5260208c019a909a52988a01979097526001600160a01b0395861660608a015263ffffffff909416608089015261ffff92831660a0890152911660c0870152821660e08601526001600160401b03166101008501529081166101208401521661014082015261016001610277565b61036361048b366004613da1565b6108ca565b61036361049e366004614188565b61099f565b61026b6104b13660046141ca565b6001600160a01b03919091166000908152600b60209081526040808320938352929052205460ff1690565b6105037f000000000000000000000000000000000000000000000000000000000000000081565b60405161027791906141f6565b610363610ac2565b61036361052636600461420a565b610afb565b610363610539366004614188565b610b84565b61055161054c366004614223565b610cf1565b60405163ffffffff9091168152602001610277565b61026b610d23565b610363610d33565b610342610d6f565b61058761271081565b60405161ffff9091168152602001610277565b6103427f000000000000000000000000000000000000000000000000000000000000000081565b6103636105cf366004614293565b610d93565b6103636105e2366004614363565b610dd0565b610363610e7d565b610363610ebc565b61026b610605366004614424565b6001600160a01b03166000908152600c602052604090205460ff1690565b610503610ef3565b610363610f02565b61036361064136600461420a565b610f31565b610363610654366004614424565b610f93565b6004546105879061ffff1681565b610342610675366004613da1565b63ffffffff1660009081526005602052604090206001015490565b61036361069e366004614188565b611049565b6103636106b1366004614441565b6111d4565b6103636106c4366004613da1565b611206565b6103206106d736600461454e565b6113e9565b6103636106ea366004613da1565b611434565b6103636106fd366004614223565b6115bc565b610363610710366004614424565b611622565b610363610723366004613da1565b6116ce565b61032061073636600461460c565b63f23a6e6160e01b9695505050505050565b60006001600160e01b03198216630271189760e51b148061077957506001600160e01b03198216630a85bd0160e11b145b8061079457506001600160e01b031982166301ffc9a760e01b145b92915050565b630a85bd0160e11b5b949350505050565b336107b4610ef3565b6001600160a01b0316146107e35760405162461bcd60e51b81526004016107da90614687565b60405180910390fd5b61271061ffff8216111561080a576040516314004bcf60e21b815260040160405180910390fd5b6004805461ffff191661ffff83169081179091556040519081527f03017365bbe16943b524030df07e7689168ab63e854d27417498e6f9dc584dab906020015b60405180910390a150565b61085d611782565b6108656117ca565b60006108748560600151611821565b90506108808582611929565b61088985611a13565b61089284611a39565b6108b961089f8683611a5f565b6108b184600001518560200151611b13565b878787611c02565b506108c46001600255565b50505050565b6108d26117ca565b60405163364d0abb60e11b815273c955962611226cd2ae467a097aec900e4b72229490636c9a15769061092b9084907f0000000000000000000000000000000000000000000000000000000000000000906004016146bc565b60006040518083038186803b15801561094357600080fd5b505af4158015610957573d6000803e3d6000fd5b5050505060008060008061096a85611d33565b935093509350935061097e858585856120ed565b600161098d86868585856122d8565b505050505061099c6001600255565b50565b336109a8610ef3565b6001600160a01b0316146109ce5760405162461bcd60e51b81526004016107da90614687565b6040516370a0823160e01b815283906000906001600160a01b038316906370a08231906109ff9030906004016141f6565b602060405180830381865afa158015610a1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4091906146db565b905080600003610a63576040516334b5d06d60e21b815260040160405180910390fd5b6001600160a01b0385166000908152600960205260409020548490610a88908361470a565b1015610aa75760405163368e910d60e21b815260040160405180910390fd5b610abb6001600160a01b03831684866122ef565b5050505050565b33610acb610ef3565b6001600160a01b031614610af15760405162461bcd60e51b81526004016107da90614687565b610af9612345565b565b33610b04610ef3565b6001600160a01b031614610b2a5760405162461bcd60e51b81526004016107da90614687565b63ffffffff811115610b4f57604051630737847960e51b815260040160405180910390fd5b60038190556040518181527f64f65a4a1a932867ad599da36210fc47c698b3abb2413cfdfd36bf59697a69cb9060200161084a565b33610b8d610ef3565b6001600160a01b031614610bb35760405162461bcd60e51b81526004016107da90614687565b6001600160a01b0383166000908152600860209081526040808320858452909152902054839015610bf757604051636a32439f60e01b815260040160405180910390fd5b6040516331a9108f60e11b81526004810184905230906001600160a01b03831690636352211e90602401602060405180830381865afa158015610c3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c62919061471d565b6001600160a01b031614610c895760405163ca5ae8a360e01b815260040160405180910390fd5b604051632142170760e11b81526001600160a01b038216906342842e0e90610cb99030908690889060040161473a565b600060405180830381600087803b158015610cd357600080fd5b505af1158015610ce7573d6000803e3d6000fd5b5050505050505050565b6000610cfb611782565b610d036117ca565b60405163160b89f160e31b815260040160405180910390fd5b9392505050565b600154600160a01b900460ff1690565b6001546001600160a01b03163314610d5d5760405162461bcd60e51b81526004016107da9061475e565b600180546001600160a01b0319169055565b7f4449524543545f4c4f414e5f46495845445f434f4c4c454354494f4e0000000090565b33610d9c610ef3565b6001600160a01b031614610dc25760405162461bcd60e51b81526004016107da90614687565b610dcc8282612394565b5050565b33610dd9610ef3565b6001600160a01b031614610dff5760405162461bcd60e51b81526004016107da90614687565b8051825114610e2057604051621dbe8b60e81b815260040160405180910390fd5b60005b8251811015610e7857610e68838281518110610e4157610e41614795565b6020026020010151838381518110610e5b57610e5b614795565b6020026020010151612394565b610e71816147ab565b9050610e23565b505050565b6001546001600160a01b03163314610ea75760405162461bcd60e51b81526004016107da9061475e565b600154610d5d906001600160a01b031661241a565b33610ec5610ef3565b6001600160a01b031614610eeb5760405162461bcd60e51b81526004016107da90614687565b610af961246a565b6000546001600160a01b031690565b33610f0b610ef3565b6001600160a01b031614610d5d5760405162461bcd60e51b81526004016107da90614687565b336000908152600b6020908152604080832084845290915290205460ff1615610f6d57604051633ab3447f60e11b815260040160405180910390fd5b336000908152600b6020908152604080832093835292905220805460ff19166001179055565b33610f9c610ef3565b6001600160a01b031614610fc25760405162461bcd60e51b81526004016107da90614687565b6001600160a01b0381166110275760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016107da565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b33611052610ef3565b6001600160a01b0316146110785760405162461bcd60e51b81526004016107da90614687565b604051627eeac760e11b815283906000906001600160a01b0383169062fdd58e906110a990309088906004016147c4565b602060405180830381865afa1580156110c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ea91906146db565b6001600160a01b03861660009081526008602090815260408083208884529091529020549091501561112f57604051636a32439f60e01b815260040160405180910390fd5b806000036111505760405163f266c3ab60e01b815260040160405180910390fd5b604051637921219560e11b81523060048201526001600160a01b038481166024830152604482018690526064820183905260a06084830152600060a483015283169063f242432a9060c401600060405180830381600087803b1580156111b557600080fd5b505af11580156111c9573d6000803e3d6000fd5b505050505050505050565b6111dc611782565b6111e46117ca565b6111f3878787878787876124ad565b6111fd6001600255565b50505050505050565b61120e6117ca565b604051635bfd0fb160e11b815273c955962611226cd2ae467a097aec900e4b7222949063b7fa1f62906112679084907f0000000000000000000000000000000000000000000000000000000000000000906004016146bc565b60006040518083038186803b15801561127f57600080fd5b505af4158015611293573d6000803e3d6000fd5b5050505063ffffffff811660009081526007602052604090205460ff16156112ce57604051633db5ad0160e11b815260040160405180910390fd5b6000806000806112dd85611d33565b93509350935093506000826080015163ffffffff168361010001516001600160401b031661130b91906147dd565b905080421161132d5760405163477e47f960e11b815260040160405180910390fd5b336001600160a01b0385161461135657604051633c35984560e11b815260040160405180910390fd5b600061136587868686856122d8565b8351604080860151610120870151825193845260208401919091529082018490524260608301526001600160a01b039081166080830152808716919088169063ffffffff8a16907f4fac0ff43299a330bce57d0579985305af580acf256a6d7977083ede81be13269060a00160405180910390a450505050505061099c6001600255565b60405162461bcd60e51b815260206004820152601b60248201527f45524331313535206261746368206e6f7420737570706f72746564000000000060448201526000906064016107da565b61143c6117ca565b63ffffffff81166000908152600560205260409020600601546001600160a01b031633811461147e576040516348c5194760e11b815260040160405180910390fd5b604051631c2d8fb360e31b81527f000000000000000000000000000000000000000000000000000000000000000060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e16c7d9890602401602060405180830381865afa158015611505573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611529919061471d565b604051631b982cf160e01b81529091506001600160a01b03821690631b982cf19061155a90869086906004016146bc565b600060405180830381600087803b15801561157457600080fd5b505af1158015611588573d6000803e3d6000fd5b5050505063ffffffff8316600090815260056020526040902060060180546001600160a01b03191690555050600160025550565b6115c4611782565b6115cc6117ca565b60006115db8460600151611821565b90506115e78482611929565b6115f084611a13565b6116166115fd8583611a5f565b61160f84600001518560200151611b13565b86866128fd565b5050610e786001600255565b61162a6117ca565b336000908152600a602090815260408083206001600160a01b03851684529091528120549081900361166f5760405163073ad17560e51b815260040160405180910390fd5b6116836001600160a01b03831633836122ef565b336000908152600a602090815260408083206001600160a01b038616845282528083208390556009909152812080548392906116c090849061470a565b909155505060016002555050565b6116d66117ca565b60405163364d0abb60e11b815273c955962611226cd2ae467a097aec900e4b72229490636c9a15769061172f9084907f0000000000000000000000000000000000000000000000000000000000000000906004016146bc565b60006040518083038186803b15801561174757600080fd5b505af415801561175b573d6000803e3d6000fd5b5050505060008060008061176e85611d33565b935093509350935061097e85858585612a6b565b61178a610d23565b15610af95760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016107da565b600280540361181b5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016107da565b60028055565b604051631c2d8fb360e31b81526d5045524d49545445445f4e46545360901b60048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e16c7d9890602401602060405180830381865afa158015611899573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118bd919061471d565b6001600160a01b031663b8c8aff8836040518263ffffffff1660e01b81526004016118e891906141f6565b602060405180830381865afa158015611905573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610794919061471d565b60c08201516001600160a01b03166000908152600c602052604090205460ff1661196657604051633bf6dbbd60e11b815260040160405180910390fd5b6001600160a01b03811661198d57604051634499a26b60e01b815260040160405180910390fd5b600354826080015163ffffffff1611156119ba57604051631c71337360e11b815260040160405180910390fd5b816080015163ffffffff166000036119e55760405163f883f39d60e01b815260040160405180910390fd5b60045460a083015161ffff908116911614610dcc57604051635b5e710360e01b815260040160405180910390fd5b80516020820151101561099c57604051635169219960e01b815260040160405180910390fd5b60208101518151111561099c5760405163813d0b5b60e01b815260040160405180910390fd5b611a67613cf9565b6040518061016001604052808460000151815260200184602001518152602001846040015181526020018460c001516001600160a01b03168152602001846080015163ffffffff168152602001600061ffff1681526020018460a0015161ffff168152602001836001600160a01b03168152602001426001600160401b0316815260200184606001516001600160a01b03168152602001336001600160a01b0316815250905092915050565b6040805160608101825260008082526020820181905291810191909152604080516060810182526001600160a01b0380861680835292516347e332df60e11b815260048101939093527f000000000000000000000000000000000000000000000000000000000000000016602483015290602082019073c955962611226cd2ae467a097aec900e4b72229490638fc665be90604401602060405180830381865af4158015611bc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611be991906147f0565b61ffff1681526020018361ffff16815250905092915050565b6040808201516001600160a01b03166000908152600b6020908152828220845183529052205460ff1615611c4957604051633ab3447f60e11b815260040160405180910390fd5b815160408601511080611c63575081602001518560400151115b15611c815760405163227d1a9160e11b815260040160405180910390fd5b6000604084015282611c94818484612e52565b611cb157604051636d2a03cf60e01b815260040160405180910390fd5b6000611cd0611cbe610d6f565b88883387604001518a60e00151612e60565b905082604001516001600160a01b0316336001600160a01b03168263ffffffff167f42cc7f53ef7b494c5dd6f0095175f7d07b5d3d7b2a03f34389fea445ba4a3a8b8a8a604051611d2292919061480d565b60405180910390a450505050505050565b600080611d3e613cf9565b604051631c2d8fb360e31b81527f000000000000000000000000000000000000000000000000000000000000000060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e16c7d9890602401602060405180830381865afa158015611dc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de9919061471d565b60405163e6c5a54160e01b815263ffffffff871660048201529091506000906001600160a01b0383169063e6c5a54190602401606060405180830381865afa158015611e39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e5d9190614909565b60208181015163ffffffff898116600090815260058085526040918290208251610160810184528154815260018201549681019690965260028101549286019290925260038201546001600160a01b038082166060880152600160a01b8083049095166080880152600160c01b820461ffff90811660a0890152600160d01b90920490911660c0870152600483015480821660e08801526001600160401b039490048416610100870152908201548116610120860152600690910154166101408401819052929650929350919091169015611f3f578361014001519550612012565b826001600160a01b0316638208e76c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fa1919061471d565b6001600160a01b0316636352211e826040518263ffffffff1660e01b8152600401611fce91815260200190565b602060405180830381865afa158015611feb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061200f919061471d565b95505b826001600160a01b0316634fbe68a06040518163ffffffff1660e01b8152600401602060405180830381865afa158015612050573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612074919061471d565b6001600160a01b0316636352211e826040518263ffffffff1660e01b81526004016120a191815260200190565b602060405180830381865afa1580156120be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120e2919061471d565b945050509193509193565b63ffffffff84166000908152600660209081526040808320815160608101835290546001600160a01b038116825261ffff600160a01b8204811694830194909452600160b01b900490921690820152908061214784612e86565b60608601519193509150612166906001600160a01b0316338784612f40565b6020830151604051637f5e0ed360e01b81526004810184905261ffff909116602482015260009073c955962611226cd2ae467a097aec900e4b72229490637f5e0ed390604401602060405180830381865af41580156121c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121ed91906146db565b9050600081118015612208575083516001600160a01b031615155b1561223757612217818461470a565b84516060870151919450612237916001600160a01b031690339084612f40565b61225933612243610ef3565b60608801516001600160a01b0316919086612f40565b856001600160a01b0316876001600160a01b03168963ffffffff167f3687d64f40b11dd1c102a76882ac1735891c546a96ae27935eb5c7865b9d86fa886000015189604001518789888c600001518e61012001518f606001516040516122c698979695949392919061498a565b60405180910390a45050505050505050565b6122e485848484612f61565b610abb833086612ffa565b610e788363a9059cbb60e01b848460405160240161230e9291906147c4565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261309d565b61234d613172565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405161238a91906141f6565b60405180910390a1565b6001600160a01b0382166123bb57604051636e8ab17b60e11b815260040160405180910390fd5b6001600160a01b0382166000818152600c6020908152604091829020805460ff191685151590811790915591519182527ff100355be652ecc881568750e6a98c0713e4316f75d5314ebc9039e0acb52f24910160405180910390a25050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b612472611782565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861237d3390565b63ffffffff8716600090815260056020526040808220905163b5ec526360e01b8152909190819073c955962611226cd2ae467a097aec900e4b7222949063b5ec5263906125289086908e908e908e908d907f0000000000000000000000000000000000000000000000000000000000000000906004016149cf565b6040805180830381865af4158015612544573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125689190614ada565b6001600160a01b0381166000818152600b602090815260408083208c8452825291829020805460ff1916600117905581516080810183528b81529081018a905280820192909252606082018890525163d06ff74160e01b815292945090925073199e38f5ed54bc56c4dc7fdd0c5c64eae923673f9163d06ff741916125f7918e918e918e918e91600401614b94565b602060405180830381865af4158015612614573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126389190614bc9565b6126555760405163e83dc84b60e01b815260040160405180910390fd5b60008715612730576003840154604051632ad659af60e01b8152600481018a9052600160d01b90910461ffff16602482015273c955962611226cd2ae467a097aec900e4b72229490632ad659af90604401602060405180830381865af41580156126c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126e791906146db565b905061270e83836126f8848c61470a565b60038801546001600160a01b0316929190612f40565b6127308361271a610ef3565b60038701546001600160a01b0316919084612f40565b60038401805463ffffffff60a01b1916600160a01b63ffffffff8d16021790556001840189905560068401546001600160a01b0316612787576006840180546001600160a01b0319166001600160a01b0385161790555b604051631c2d8fb360e31b81527f000000000000000000000000000000000000000000000000000000000000000060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e16c7d9890602401602060405180830381865afa15801561280b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061282f919061471d565b6001600160a01b031663072db1478c846040518363ffffffff1660e01b815260040161285c9291906146bc565b600060405180830381600087803b15801561287657600080fd5b505af115801561288a573d6000803e3d6000fd5b50506040805163ffffffff8e81168252602082018e90529181018c9052606081018590526001600160a01b03808716945087169250908e16907f37357bed780fda5aed28c32fe9cd762cb2f2f8a70c0d9b342aba59c945943ca09060800160405180910390a45050505050505050505050565b6040808201516001600160a01b03166000908152600b60209081528282208451835290529081205460ff161561294657604051633ab3447f60e11b815260040160405180910390fd5b60006040808501919091525163eb2ac63f60e01b8152839073199e38f5ed54bc56c4dc7fdd0c5c64eae923673f9063eb2ac63f9061298a9084908790600401614be6565b602060405180830381865af41580156129a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129cb9190614bc9565b6129e857604051636d2a03cf60e01b815260040160405180910390fd5b6000612a076129f5610d6f565b88883388604001518a60e00151612e60565b905083604001516001600160a01b0316336001600160a01b03168263ffffffff167f42cc7f53ef7b494c5dd6f0095175f7d07b5d3d7b2a03f34389fea445ba4a3a8b8a8a604051612a5992919061480d565b60405180910390a49695505050505050565b63ffffffff84166000908152600660209081526040808320815160608101835290546001600160a01b038116825261ffff600160a01b8204811694830194909452600160b01b9004909216908201529080612ac584612e86565b9150915083606001516001600160a01b03166323b872dd3387846040518463ffffffff1660e01b8152600401612afd9392919061473a565b6020604051808303816000875af1925050508015612b38575060408051601f3d908101601f19168201909252612b3591810190614bc9565b60015b612bfe576060840151612b56906001600160a01b0316333084612f40565b6001600160a01b038086166000908152600a60209081526040808320606089015190941683529290529081208054839290612b929084906147dd565b909155505060608401516001600160a01b031660009081526009602052604081208054839290612bc39084906147dd565b909155505060405163ffffffff8816907fe6dfda7486ec1e06f754c28be83c676af29b18143765a2843361313cdab2712590600090a2612c00565b505b6020830151604051637f5e0ed360e01b81526004810184905261ffff909116602482015260009073c955962611226cd2ae467a097aec900e4b72229490637f5e0ed390604401602060405180830381865af4158015612c63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c8791906146db565b9050600081118015612ca2575083516001600160a01b031615155b15612d4b57612cb1818461470a565b606086015185516040516323b872dd60e01b81529295506001600160a01b03909116916323b872dd91612ceb91339190869060040161473a565b6020604051808303816000875af1925050508015612d26575060408051601f3d908101601f19168201909252612d2391810190614bc9565b60015b612d49576060850151612d44906001600160a01b0316333084612f40565b612d4b565b505b84606001516001600160a01b03166323b872dd33612d67610ef3565b866040518463ffffffff1660e01b8152600401612d869392919061473a565b6020604051808303816000875af1925050508015612dc1575060408051601f3d908101601f19168201909252612dbe91810190614bc9565b60015b612de4576060850151612ddf906001600160a01b0316333086612f40565b612259565b50856001600160a01b0316876001600160a01b03168963ffffffff167f3687d64f40b11dd1c102a76882ac1735891c546a96ae27935eb5c7865b9d86fa886000015189604001518789888c600001518e61012001518f606001516040516122c698979695949392919061498a565b60006107a3848484306131bd565b6000612e6d868530612ffa565b612e7b87878787878761333b565b979650505050505050565b600080600083600001518460200151612e9f919061470a565b60c0850151604051632ad659af60e01b81526004810183905261ffff909116602482015290915073c955962611226cd2ae467a097aec900e4b72229490632ad659af90604401602060405180830381865af4158015612f02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f2691906146db565b9250828460200151612f38919061470a565b915050915091565b6108c4846323b872dd60e01b85858560405160240161230e9392919061473a565b63ffffffff84166000908152600760209081526040808320805460ff191660019081179091556101208701516001600160a01b03168452600883528184208783015185529092528220805491929091612fbb90849061470a565b909155505060405163a4d0845d60e01b815263ffffffff8516600482015281151560248201526001600160a01b0383169063a4d0845d90604401610cb9565b60e083015161012084015160408086015181516001600160a01b038781166024830152868116604483015290931660648401526084808401919091528151808403909101815260a49092018152602080830180516001600160e01b031663b030667160e01b17905281518083019092528082527f4e4654206e6f74207375636365737366756c6c79207472616e73666572726564908201526108c49291906137bb565b60006130f2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166138339092919063ffffffff16565b90508051600014806131135750808060200190518101906131139190614bc9565b610e785760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016107da565b61317a610d23565b610af95760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016107da565b600082602001514211156132135760405162461bcd60e51b815260206004820152601c60248201527f4c656e646572205369676e61747572652068617320657870697265640000000060448201526064016107da565b6001600160a01b0382166132605760405162461bcd60e51b81526020600482015260146024820152734c6f616e206973207a65726f206164647265737360601b60448201526064016107da565b60408301516001600160a01b031661327a575060006107a3565b600061328586613842565b85516020808801516040516132a4939201918252602082015260400190565b6040516020818303038152906040526132bc86613901565b85466040516020016132d2959493929190614c75565b6040516020818303038152906040528051906020012090506133338460400151613329837f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c91909152603c902090565b8660600151613944565b9150506107a3565b6101208501516001600160a01b03166000908152600860209081526040808320818901518452909152812080546001919083906133799084906147dd565b909155505085516040868101519051637b2392f160e01b8152600481019290925261ffff1660248201526001600160a01b038316604482015260009073c955962611226cd2ae467a097aec900e4b72229490637b2392f190606401602060405180830381865af41580156133f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341591906146db565b90506000818860000151613429919061470a565b9050811561344b57606088015161344b906001600160a01b0316868685612f40565b6060880151613465906001600160a01b0316868884612f40565b604051631c2d8fb360e31b81527f000000000000000000000000000000000000000000000000000000000000000060048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e16c7d9890602401602060405180830381865afa1580156134ec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613510919061471d565b60405163d1f7659560e01b81529091506001600160a01b0382169063d1f76595906135419089908e906004016147c4565b6020604051808303816000875af1158015613560573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135849190614cd4565b935088600560008663ffffffff1663ffffffff16815260200190815260200160002060008201518160000155602082015181600101556040820151816002015560608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060808201518160030160146101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160030160186101000a81548161ffff021916908361ffff16021790555060c082015181600301601a6101000a81548161ffff021916908361ffff16021790555060e08201518160040160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506101008201518160040160146101000a8154816001600160401b0302191690836001600160401b031602179055506101208201518160050160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506101408201518160060160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555090505087600660008663ffffffff1663ffffffff16815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060208201518160000160146101000a81548161ffff021916908361ffff16021790555060408201518160000160166101000a81548161ffff021916908361ffff1602179055509050505050509695505050505050565b6060600080856001600160a01b0316856040516137d89190614cf1565b600060405180830381855af49150503d8060008114613813576040519150601f19603f3d011682016040523d82523d6000602084013e613818565b606091505b50915091506138298683838761399b565b9695505050505050565b60606107a38484600085613a14565b60608160c0015182600001518360200151846060015185604001518660e0015187608001518860a001516040516020016138eb989796959493929190606098891b6001600160601b031990811682526014820198909852603481019690965293871b86166054860152606885019290925290941b909216608882015260e09290921b6001600160e01b031916609c83015260f01b6001600160f01b03191660a082015260a20190565b6040516020818303038152906040529050919050565b60608160400151826000015183602001516040516020016138eb9392919060609390931b6001600160601b03191683526014830191909152603482015260540190565b60008060006139538585613ae4565b9092509050600081600481111561396c5761396c614d0d565b14801561398a5750856001600160a01b0316826001600160a01b0316145b806138295750613829868686613b29565b60608315613a0a578251600003613a03576001600160a01b0385163b613a035760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016107da565b50816107a3565b6107a38383613c15565b606082471015613a755760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016107da565b600080866001600160a01b03168587604051613a919190614cf1565b60006040518083038185875af1925050503d8060008114613ace576040519150601f19603f3d011682016040523d82523d6000602084013e613ad3565b606091505b5091509150612e7b8783838761399b565b6000808251604103613b1a5760208301516040840151606085015160001a613b0e87828585613c3f565b94509450505050613b22565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b8686604051602401613b53929190614d23565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613b919190614cf1565b600060405180830381855afa9150503d8060008114613bcc576040519150601f19603f3d011682016040523d82523d6000602084013e613bd1565b606091505b5091509150818015613be557506020815110155b801561382957508051630b135d3f60e11b90613c0a90830160209081019084016146db565b149695505050505050565b815115613c255781518083602001fd5b8060405162461bcd60e51b81526004016107da9190614d3c565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b03831115613c6c5750600090506003613cf0565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015613cc0573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116613ce957600060019250925050613cf0565b9150600090505b94509492505050565b6040805161016081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905261014081019190915290565b600060208284031215613d6757600080fd5b81356001600160e01b031981168114610d1c57600080fd5b63ffffffff8116811461099c57600080fd5b8035613d9c81613d7f565b919050565b600060208284031215613db357600080fd5b8135610d1c81613d7f565b6001600160a01b03169052565b6001600160a01b038116811461099c57600080fd5b8035613d9c81613dcb565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715613e2357613e23613deb565b60405290565b604051601f8201601f191681016001600160401b0381118282101715613e5157613e51613deb565b604052919050565b600082601f830112613e6a57600080fd5b81356001600160401b03811115613e8357613e83613deb565b613e96601f8201601f1916602001613e29565b818152846020838601011115613eab57600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060808587031215613ede57600080fd5b8435613ee981613dcb565b93506020850135613ef981613dcb565b92506040850135915060608501356001600160401b03811115613f1b57600080fd5b613f2787828801613e59565b91505092959194509250565b61ffff8116811461099c57600080fd5b8035613d9c81613f33565b600060208284031215613f6057600080fd5b8135610d1c81613f33565b6000610100808385031215613f7f57600080fd5b604051908101906001600160401b0382118183101715613fa157613fa1613deb565b8160405280925083358152602084013560208201526040840135604082015260608401359150613fd082613dcb565b816060820152613fe260808501613d91565b6080820152613ff360a08501613f43565b60a082015261400460c08501613de0565b60c082015261401560e08501613de0565b60e0820152505092915050565b60006080828403121561403457600080fd5b604051608081016001600160401b03828210818311171561405757614057613deb565b8160405282935084358352602085013560208401526040850135915061407c82613dcb565b816040840152606085013591508082111561409657600080fd5b506140a385828601613e59565b6060830152505092915050565b6000604082840312156140c257600080fd5b6140ca613e01565b905081356140d781613dcb565b815260208201356140e781613f33565b602082015292915050565b6000806000808486036101a081121561410a57600080fd5b6141148787613f6b565b9450604060ff198201121561412857600080fd5b50614131613e01565b6101008601358152610120860135602082015292506101408501356001600160401b0381111561416057600080fd5b61416c87828801614022565b92505061417d8661016087016140b0565b905092959194509250565b60008060006060848603121561419d57600080fd5b83356141a881613dcb565b92506020840135915060408401356141bf81613dcb565b809150509250925092565b600080604083850312156141dd57600080fd5b82356141e881613dcb565b946020939093013593505050565b6001600160a01b0391909116815260200190565b60006020828403121561421c57600080fd5b5035919050565b6000806000610160848603121561423957600080fd5b6142438585613f6b565b92506101008401356001600160401b0381111561425f57600080fd5b61426b86828701614022565b92505061427c8561012086016140b0565b90509250925092565b801515811461099c57600080fd5b600080604083850312156142a657600080fd5b82356142b181613dcb565b915060208301356142c181614285565b809150509250929050565b60006001600160401b038211156142e5576142e5613deb565b5060051b60200190565b600082601f83011261430057600080fd5b81356020614315614310836142cc565b613e29565b82815260059290921b8401810191818101908684111561433457600080fd5b8286015b8481101561435857803561434b81614285565b8352918301918301614338565b509695505050505050565b6000806040838503121561437657600080fd5b82356001600160401b038082111561438d57600080fd5b818501915085601f8301126143a157600080fd5b813560206143b1614310836142cc565b82815260059290921b840181019181810190898411156143d057600080fd5b948201945b838610156143f75785356143e881613dcb565b825294820194908201906143d5565b9650508601359250508082111561440d57600080fd5b5061441a858286016142ef565b9150509250929050565b60006020828403121561443657600080fd5b8135610d1c81613dcb565b600080600080600080600060e0888a03121561445c57600080fd5b873561446781613d7f565b9650602088013561447781613d7f565b955060408801359450606088013593506080880135925060a0880135915060c08801356001600160401b038111156144ae57600080fd5b6144ba8a828b01613e59565b91505092959891949750929550565b60008083601f8401126144db57600080fd5b5081356001600160401b038111156144f257600080fd5b6020830191508360208260051b8501011115613b2257600080fd5b60008083601f84011261451f57600080fd5b5081356001600160401b0381111561453657600080fd5b602083019150836020828501011115613b2257600080fd5b60008060008060008060008060a0898b03121561456a57600080fd5b883561457581613dcb565b9750602089013561458581613dcb565b965060408901356001600160401b03808211156145a157600080fd5b6145ad8c838d016144c9565b909850965060608b01359150808211156145c657600080fd5b6145d28c838d016144c9565b909650945060808b01359150808211156145eb57600080fd5b506145f88b828c0161450d565b999c989b5096995094979396929594505050565b60008060008060008060a0878903121561462557600080fd5b863561463081613dcb565b9550602087013561464081613dcb565b9450604087013593506060870135925060808701356001600160401b0381111561466957600080fd5b61467589828a0161450d565b979a9699509497509295939492505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b63ffffffff9290921682526001600160a01b0316602082015260400190565b6000602082840312156146ed57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610794576107946146f4565b60006020828403121561472f57600080fd5b8151610d1c81613dcb565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6020808252601c908201527f4f776e61626c653a206e6f74206f776e65722063616e64696461746500000000604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6000600182016147bd576147bd6146f4565b5060010190565b6001600160a01b03929092168252602082015260400190565b80820180821115610794576107946146f4565b60006020828403121561480257600080fd5b8151610d1c81613f33565b60006101c08201905083518252602084015160208301526040840151604083015260608401516148406060840182613dbe565b506080840151614858608084018263ffffffff169052565b5060a084015161486e60a084018261ffff169052565b5060c084015161488460c084018261ffff169052565b5060e084015161489760e0840182613dbe565b50610100848101516001600160401b031690830152610120808501516148bf82850182613dbe565b5050610140808501516148d482850182613dbe565b505082516001600160a01b0316610160830152602083015161ffff9081166101808401526040840151166101a0830152610d1c565b60006060828403121561491b57600080fd5b604051606081016001600160401b03828210818311171561493e5761493e613deb565b816040528451915061494f82613dcb565b908252602084015190808216821461496657600080fd5b50602082015260408301516004811061497e57600080fd5b60408201529392505050565b97885260208801969096526040870194909452606086019290925260808501526001600160a01b0390811660a085015290811660c08401521660e08201526101000190565b86548152600187015460208201526002870154604082015260038701546102008201906001600160a01b03614a0960608501828416613dbe565b60a082901c63ffffffff16608085015261ffff60c083901c811660a0860152614a3d60c08601828560d01c1661ffff169052565b5060048a01549150614a5460e08501828416613dbe565b5060a081901c6001600160401b03166101008401525060058801546001600160a01b0316614a86610120840182613dbe565b5060068801546001600160a01b0316614aa3610140840182613dbe565b5063ffffffff871661016083015263ffffffff8616610180830152846101a0830152836101c0830152612e7b6101e0830184613dbe565b60008060408385031215614aed57600080fd5b8251614af881613dcb565b60208401519092506142c181613dcb565b60005b83811015614b24578181015183820152602001614b0c565b50506000910152565b60008151808452614b45816020860160208601614b09565b601f01601f19169290920160200192915050565b805182526020810151602083015260018060a01b03604082015116604083015260006060820151608060608501526107a36080850182614b2d565b600063ffffffff808816835280871660208401525084604083015283606083015260a06080830152612e7b60a0830184614b59565b600060208284031215614bdb57600080fd5b8151610d1c81614285565b600061012084518352602085015160208401526040850151604084015260018060a01b03606086015116606084015263ffffffff608086015116608084015261ffff60a08601511660a084015260c0850151614c4560c0850182613dbe565b5060e0850151614c5860e0850182613dbe565b5080610100840152614c6c81840185614b59565b95945050505050565b60008651614c87818460208b01614b09565b865190830190614c9b818360208b01614b09565b8651910190614cae818360208a01614b09565b60609590951b6001600160601b0319169401938452505060148201526034019392505050565b600060208284031215614ce657600080fd5b8151610d1c81613d7f565b60008251614d03818460208701614b09565b9190910192915050565b634e487b7160e01b600052602160045260246000fd5b8281526040602082015260006107a36040830184614b2d565b602081526000610d1c6020830184614b2d56fea164736f6c6343000813000a000000000000000000000000169ee6762811ab9bc59a609331bc721d9f0cd56c0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102535760003560e01c806377cfa99111610146578063a4441a6f116100c3578063bc197c8111610087578063bc197c81146106c9578063bce42e42146106dc578063c192f4e5146106ef578063ddfddad614610702578063eda928ab14610715578063f23a6e611461072857600080fd5b8063a4441a6f14610659578063ab3b128014610667578063ac4e35ea14610690578063b18e7772146106a3578063b31ec1d4146106b657600080fd5b8063872873be1161010a578063872873be146105f75780638da5cb5b1461062357806392fede001461062b5780639658e405146106335780639d6fa6181461064657600080fd5b806377cfa9911461059a5780637836baf1146105c157806379b64040146105d45780637b371107146105e75780638456cb59146105ef57600080fd5b8063328404b0116101d457806356efe98c1161019857806356efe98c1461053e5780635c975abb146105665780635f992fdd1461056e578063616693d8146105765780636ed93dd01461057e57600080fd5b8063328404b0146104a3578063365a86fc146104dc5780633f4ba83a1461051057806347948d92146105185780635163a1c31461052b57600080fd5b80631c6caf411161021b5780631c6caf41146103505780631f908a1c14610365578063227cda18146103785780632b2180221461047d5780632c1d4ec21461049057600080fd5b806301ffc9a7146102585780630717f3aa146102805780630ff81c3f146102a3578063150b7a021461030d578063192b355d14610339575b600080fd5b61026b610266366004613d55565b610748565b60405190151581526020015b60405180910390f35b61026b61028e366004613da1565b60076020526000908152604090205460ff1681565b6102e36102b1366004613da1565b6006602052600090815260409020546001600160a01b0381169061ffff600160a01b8204811691600160b01b90041683565b604080516001600160a01b03909416845261ffff9283166020850152911690820152606001610277565b61032061031b366004613ec8565b61079a565b6040516001600160e01b03199091168152602001610277565b61034260035481565b604051908152602001610277565b61036361035e366004613f4e565b6107ab565b005b6103636103733660046140f2565b610855565b610409610386366004613da1565b600560208190526000918252604090912080546001820154600283015460038401546004850154958501546006909501549395929491936001600160a01b0380831694600160a01b80850463ffffffff1695600160c01b860461ffff90811696600160d01b9004169484841694929093046001600160401b03169290821691168b565b604080519b8c5260208c019a909a52988a01979097526001600160a01b0395861660608a015263ffffffff909416608089015261ffff92831660a0890152911660c0870152821660e08601526001600160401b03166101008501529081166101208401521661014082015261016001610277565b61036361048b366004613da1565b6108ca565b61036361049e366004614188565b61099f565b61026b6104b13660046141ca565b6001600160a01b03919091166000908152600b60209081526040808320938352929052205460ff1690565b6105037f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda81565b60405161027791906141f6565b610363610ac2565b61036361052636600461420a565b610afb565b610363610539366004614188565b610b84565b61055161054c366004614223565b610cf1565b60405163ffffffff9091168152602001610277565b61026b610d23565b610363610d33565b610342610d6f565b61058761271081565b60405161ffff9091168152602001610277565b6103427f4449524543545f4c4f414e5f434f4f5244494e41544f5200000000000000000081565b6103636105cf366004614293565b610d93565b6103636105e2366004614363565b610dd0565b610363610e7d565b610363610ebc565b61026b610605366004614424565b6001600160a01b03166000908152600c602052604090205460ff1690565b610503610ef3565b610363610f02565b61036361064136600461420a565b610f31565b610363610654366004614424565b610f93565b6004546105879061ffff1681565b610342610675366004613da1565b63ffffffff1660009081526005602052604090206001015490565b61036361069e366004614188565b611049565b6103636106b1366004614441565b6111d4565b6103636106c4366004613da1565b611206565b6103206106d736600461454e565b6113e9565b6103636106ea366004613da1565b611434565b6103636106fd366004614223565b6115bc565b610363610710366004614424565b611622565b610363610723366004613da1565b6116ce565b61032061073636600461460c565b63f23a6e6160e01b9695505050505050565b60006001600160e01b03198216630271189760e51b148061077957506001600160e01b03198216630a85bd0160e11b145b8061079457506001600160e01b031982166301ffc9a760e01b145b92915050565b630a85bd0160e11b5b949350505050565b336107b4610ef3565b6001600160a01b0316146107e35760405162461bcd60e51b81526004016107da90614687565b60405180910390fd5b61271061ffff8216111561080a576040516314004bcf60e21b815260040160405180910390fd5b6004805461ffff191661ffff83169081179091556040519081527f03017365bbe16943b524030df07e7689168ab63e854d27417498e6f9dc584dab906020015b60405180910390a150565b61085d611782565b6108656117ca565b60006108748560600151611821565b90506108808582611929565b61088985611a13565b61089284611a39565b6108b961089f8683611a5f565b6108b184600001518560200151611b13565b878787611c02565b506108c46001600255565b50505050565b6108d26117ca565b60405163364d0abb60e11b815273c955962611226cd2ae467a097aec900e4b72229490636c9a15769061092b9084907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda906004016146bc565b60006040518083038186803b15801561094357600080fd5b505af4158015610957573d6000803e3d6000fd5b5050505060008060008061096a85611d33565b935093509350935061097e858585856120ed565b600161098d86868585856122d8565b505050505061099c6001600255565b50565b336109a8610ef3565b6001600160a01b0316146109ce5760405162461bcd60e51b81526004016107da90614687565b6040516370a0823160e01b815283906000906001600160a01b038316906370a08231906109ff9030906004016141f6565b602060405180830381865afa158015610a1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4091906146db565b905080600003610a63576040516334b5d06d60e21b815260040160405180910390fd5b6001600160a01b0385166000908152600960205260409020548490610a88908361470a565b1015610aa75760405163368e910d60e21b815260040160405180910390fd5b610abb6001600160a01b03831684866122ef565b5050505050565b33610acb610ef3565b6001600160a01b031614610af15760405162461bcd60e51b81526004016107da90614687565b610af9612345565b565b33610b04610ef3565b6001600160a01b031614610b2a5760405162461bcd60e51b81526004016107da90614687565b63ffffffff811115610b4f57604051630737847960e51b815260040160405180910390fd5b60038190556040518181527f64f65a4a1a932867ad599da36210fc47c698b3abb2413cfdfd36bf59697a69cb9060200161084a565b33610b8d610ef3565b6001600160a01b031614610bb35760405162461bcd60e51b81526004016107da90614687565b6001600160a01b0383166000908152600860209081526040808320858452909152902054839015610bf757604051636a32439f60e01b815260040160405180910390fd5b6040516331a9108f60e11b81526004810184905230906001600160a01b03831690636352211e90602401602060405180830381865afa158015610c3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c62919061471d565b6001600160a01b031614610c895760405163ca5ae8a360e01b815260040160405180910390fd5b604051632142170760e11b81526001600160a01b038216906342842e0e90610cb99030908690889060040161473a565b600060405180830381600087803b158015610cd357600080fd5b505af1158015610ce7573d6000803e3d6000fd5b5050505050505050565b6000610cfb611782565b610d036117ca565b60405163160b89f160e31b815260040160405180910390fd5b9392505050565b600154600160a01b900460ff1690565b6001546001600160a01b03163314610d5d5760405162461bcd60e51b81526004016107da9061475e565b600180546001600160a01b0319169055565b7f4449524543545f4c4f414e5f46495845445f434f4c4c454354494f4e0000000090565b33610d9c610ef3565b6001600160a01b031614610dc25760405162461bcd60e51b81526004016107da90614687565b610dcc8282612394565b5050565b33610dd9610ef3565b6001600160a01b031614610dff5760405162461bcd60e51b81526004016107da90614687565b8051825114610e2057604051621dbe8b60e81b815260040160405180910390fd5b60005b8251811015610e7857610e68838281518110610e4157610e41614795565b6020026020010151838381518110610e5b57610e5b614795565b6020026020010151612394565b610e71816147ab565b9050610e23565b505050565b6001546001600160a01b03163314610ea75760405162461bcd60e51b81526004016107da9061475e565b600154610d5d906001600160a01b031661241a565b33610ec5610ef3565b6001600160a01b031614610eeb5760405162461bcd60e51b81526004016107da90614687565b610af961246a565b6000546001600160a01b031690565b33610f0b610ef3565b6001600160a01b031614610d5d5760405162461bcd60e51b81526004016107da90614687565b336000908152600b6020908152604080832084845290915290205460ff1615610f6d57604051633ab3447f60e11b815260040160405180910390fd5b336000908152600b6020908152604080832093835292905220805460ff19166001179055565b33610f9c610ef3565b6001600160a01b031614610fc25760405162461bcd60e51b81526004016107da90614687565b6001600160a01b0381166110275760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016107da565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b33611052610ef3565b6001600160a01b0316146110785760405162461bcd60e51b81526004016107da90614687565b604051627eeac760e11b815283906000906001600160a01b0383169062fdd58e906110a990309088906004016147c4565b602060405180830381865afa1580156110c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ea91906146db565b6001600160a01b03861660009081526008602090815260408083208884529091529020549091501561112f57604051636a32439f60e01b815260040160405180910390fd5b806000036111505760405163f266c3ab60e01b815260040160405180910390fd5b604051637921219560e11b81523060048201526001600160a01b038481166024830152604482018690526064820183905260a06084830152600060a483015283169063f242432a9060c401600060405180830381600087803b1580156111b557600080fd5b505af11580156111c9573d6000803e3d6000fd5b505050505050505050565b6111dc611782565b6111e46117ca565b6111f3878787878787876124ad565b6111fd6001600255565b50505050505050565b61120e6117ca565b604051635bfd0fb160e11b815273c955962611226cd2ae467a097aec900e4b7222949063b7fa1f62906112679084907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda906004016146bc565b60006040518083038186803b15801561127f57600080fd5b505af4158015611293573d6000803e3d6000fd5b5050505063ffffffff811660009081526007602052604090205460ff16156112ce57604051633db5ad0160e11b815260040160405180910390fd5b6000806000806112dd85611d33565b93509350935093506000826080015163ffffffff168361010001516001600160401b031661130b91906147dd565b905080421161132d5760405163477e47f960e11b815260040160405180910390fd5b336001600160a01b0385161461135657604051633c35984560e11b815260040160405180910390fd5b600061136587868686856122d8565b8351604080860151610120870151825193845260208401919091529082018490524260608301526001600160a01b039081166080830152808716919088169063ffffffff8a16907f4fac0ff43299a330bce57d0579985305af580acf256a6d7977083ede81be13269060a00160405180910390a450505050505061099c6001600255565b60405162461bcd60e51b815260206004820152601b60248201527f45524331313535206261746368206e6f7420737570706f72746564000000000060448201526000906064016107da565b61143c6117ca565b63ffffffff81166000908152600560205260409020600601546001600160a01b031633811461147e576040516348c5194760e11b815260040160405180910390fd5b604051631c2d8fb360e31b81527f4449524543545f4c4f414e5f434f4f5244494e41544f5200000000000000000060048201526000907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda6001600160a01b03169063e16c7d9890602401602060405180830381865afa158015611505573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611529919061471d565b604051631b982cf160e01b81529091506001600160a01b03821690631b982cf19061155a90869086906004016146bc565b600060405180830381600087803b15801561157457600080fd5b505af1158015611588573d6000803e3d6000fd5b5050505063ffffffff8316600090815260056020526040902060060180546001600160a01b03191690555050600160025550565b6115c4611782565b6115cc6117ca565b60006115db8460600151611821565b90506115e78482611929565b6115f084611a13565b6116166115fd8583611a5f565b61160f84600001518560200151611b13565b86866128fd565b5050610e786001600255565b61162a6117ca565b336000908152600a602090815260408083206001600160a01b03851684529091528120549081900361166f5760405163073ad17560e51b815260040160405180910390fd5b6116836001600160a01b03831633836122ef565b336000908152600a602090815260408083206001600160a01b038616845282528083208390556009909152812080548392906116c090849061470a565b909155505060016002555050565b6116d66117ca565b60405163364d0abb60e11b815273c955962611226cd2ae467a097aec900e4b72229490636c9a15769061172f9084907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda906004016146bc565b60006040518083038186803b15801561174757600080fd5b505af415801561175b573d6000803e3d6000fd5b5050505060008060008061176e85611d33565b935093509350935061097e85858585612a6b565b61178a610d23565b15610af95760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016107da565b600280540361181b5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016107da565b60028055565b604051631c2d8fb360e31b81526d5045524d49545445445f4e46545360901b60048201526000907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda6001600160a01b03169063e16c7d9890602401602060405180830381865afa158015611899573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118bd919061471d565b6001600160a01b031663b8c8aff8836040518263ffffffff1660e01b81526004016118e891906141f6565b602060405180830381865afa158015611905573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610794919061471d565b60c08201516001600160a01b03166000908152600c602052604090205460ff1661196657604051633bf6dbbd60e11b815260040160405180910390fd5b6001600160a01b03811661198d57604051634499a26b60e01b815260040160405180910390fd5b600354826080015163ffffffff1611156119ba57604051631c71337360e11b815260040160405180910390fd5b816080015163ffffffff166000036119e55760405163f883f39d60e01b815260040160405180910390fd5b60045460a083015161ffff908116911614610dcc57604051635b5e710360e01b815260040160405180910390fd5b80516020820151101561099c57604051635169219960e01b815260040160405180910390fd5b60208101518151111561099c5760405163813d0b5b60e01b815260040160405180910390fd5b611a67613cf9565b6040518061016001604052808460000151815260200184602001518152602001846040015181526020018460c001516001600160a01b03168152602001846080015163ffffffff168152602001600061ffff1681526020018460a0015161ffff168152602001836001600160a01b03168152602001426001600160401b0316815260200184606001516001600160a01b03168152602001336001600160a01b0316815250905092915050565b6040805160608101825260008082526020820181905291810191909152604080516060810182526001600160a01b0380861680835292516347e332df60e11b815260048101939093527f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda16602483015290602082019073c955962611226cd2ae467a097aec900e4b72229490638fc665be90604401602060405180830381865af4158015611bc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611be991906147f0565b61ffff1681526020018361ffff16815250905092915050565b6040808201516001600160a01b03166000908152600b6020908152828220845183529052205460ff1615611c4957604051633ab3447f60e11b815260040160405180910390fd5b815160408601511080611c63575081602001518560400151115b15611c815760405163227d1a9160e11b815260040160405180910390fd5b6000604084015282611c94818484612e52565b611cb157604051636d2a03cf60e01b815260040160405180910390fd5b6000611cd0611cbe610d6f565b88883387604001518a60e00151612e60565b905082604001516001600160a01b0316336001600160a01b03168263ffffffff167f42cc7f53ef7b494c5dd6f0095175f7d07b5d3d7b2a03f34389fea445ba4a3a8b8a8a604051611d2292919061480d565b60405180910390a450505050505050565b600080611d3e613cf9565b604051631c2d8fb360e31b81527f4449524543545f4c4f414e5f434f4f5244494e41544f5200000000000000000060048201526000907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda6001600160a01b03169063e16c7d9890602401602060405180830381865afa158015611dc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de9919061471d565b60405163e6c5a54160e01b815263ffffffff871660048201529091506000906001600160a01b0383169063e6c5a54190602401606060405180830381865afa158015611e39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e5d9190614909565b60208181015163ffffffff898116600090815260058085526040918290208251610160810184528154815260018201549681019690965260028101549286019290925260038201546001600160a01b038082166060880152600160a01b8083049095166080880152600160c01b820461ffff90811660a0890152600160d01b90920490911660c0870152600483015480821660e08801526001600160401b039490048416610100870152908201548116610120860152600690910154166101408401819052929650929350919091169015611f3f578361014001519550612012565b826001600160a01b0316638208e76c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fa1919061471d565b6001600160a01b0316636352211e826040518263ffffffff1660e01b8152600401611fce91815260200190565b602060405180830381865afa158015611feb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061200f919061471d565b95505b826001600160a01b0316634fbe68a06040518163ffffffff1660e01b8152600401602060405180830381865afa158015612050573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612074919061471d565b6001600160a01b0316636352211e826040518263ffffffff1660e01b81526004016120a191815260200190565b602060405180830381865afa1580156120be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120e2919061471d565b945050509193509193565b63ffffffff84166000908152600660209081526040808320815160608101835290546001600160a01b038116825261ffff600160a01b8204811694830194909452600160b01b900490921690820152908061214784612e86565b60608601519193509150612166906001600160a01b0316338784612f40565b6020830151604051637f5e0ed360e01b81526004810184905261ffff909116602482015260009073c955962611226cd2ae467a097aec900e4b72229490637f5e0ed390604401602060405180830381865af41580156121c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121ed91906146db565b9050600081118015612208575083516001600160a01b031615155b1561223757612217818461470a565b84516060870151919450612237916001600160a01b031690339084612f40565b61225933612243610ef3565b60608801516001600160a01b0316919086612f40565b856001600160a01b0316876001600160a01b03168963ffffffff167f3687d64f40b11dd1c102a76882ac1735891c546a96ae27935eb5c7865b9d86fa886000015189604001518789888c600001518e61012001518f606001516040516122c698979695949392919061498a565b60405180910390a45050505050505050565b6122e485848484612f61565b610abb833086612ffa565b610e788363a9059cbb60e01b848460405160240161230e9291906147c4565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261309d565b61234d613172565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405161238a91906141f6565b60405180910390a1565b6001600160a01b0382166123bb57604051636e8ab17b60e11b815260040160405180910390fd5b6001600160a01b0382166000818152600c6020908152604091829020805460ff191685151590811790915591519182527ff100355be652ecc881568750e6a98c0713e4316f75d5314ebc9039e0acb52f24910160405180910390a25050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b612472611782565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861237d3390565b63ffffffff8716600090815260056020526040808220905163b5ec526360e01b8152909190819073c955962611226cd2ae467a097aec900e4b7222949063b5ec5263906125289086908e908e908e908d907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda906004016149cf565b6040805180830381865af4158015612544573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125689190614ada565b6001600160a01b0381166000818152600b602090815260408083208c8452825291829020805460ff1916600117905581516080810183528b81529081018a905280820192909252606082018890525163d06ff74160e01b815292945090925073199e38f5ed54bc56c4dc7fdd0c5c64eae923673f9163d06ff741916125f7918e918e918e918e91600401614b94565b602060405180830381865af4158015612614573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126389190614bc9565b6126555760405163e83dc84b60e01b815260040160405180910390fd5b60008715612730576003840154604051632ad659af60e01b8152600481018a9052600160d01b90910461ffff16602482015273c955962611226cd2ae467a097aec900e4b72229490632ad659af90604401602060405180830381865af41580156126c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126e791906146db565b905061270e83836126f8848c61470a565b60038801546001600160a01b0316929190612f40565b6127308361271a610ef3565b60038701546001600160a01b0316919084612f40565b60038401805463ffffffff60a01b1916600160a01b63ffffffff8d16021790556001840189905560068401546001600160a01b0316612787576006840180546001600160a01b0319166001600160a01b0385161790555b604051631c2d8fb360e31b81527f4449524543545f4c4f414e5f434f4f5244494e41544f5200000000000000000060048201527f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda6001600160a01b03169063e16c7d9890602401602060405180830381865afa15801561280b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061282f919061471d565b6001600160a01b031663072db1478c846040518363ffffffff1660e01b815260040161285c9291906146bc565b600060405180830381600087803b15801561287657600080fd5b505af115801561288a573d6000803e3d6000fd5b50506040805163ffffffff8e81168252602082018e90529181018c9052606081018590526001600160a01b03808716945087169250908e16907f37357bed780fda5aed28c32fe9cd762cb2f2f8a70c0d9b342aba59c945943ca09060800160405180910390a45050505050505050505050565b6040808201516001600160a01b03166000908152600b60209081528282208451835290529081205460ff161561294657604051633ab3447f60e11b815260040160405180910390fd5b60006040808501919091525163eb2ac63f60e01b8152839073199e38f5ed54bc56c4dc7fdd0c5c64eae923673f9063eb2ac63f9061298a9084908790600401614be6565b602060405180830381865af41580156129a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129cb9190614bc9565b6129e857604051636d2a03cf60e01b815260040160405180910390fd5b6000612a076129f5610d6f565b88883388604001518a60e00151612e60565b905083604001516001600160a01b0316336001600160a01b03168263ffffffff167f42cc7f53ef7b494c5dd6f0095175f7d07b5d3d7b2a03f34389fea445ba4a3a8b8a8a604051612a5992919061480d565b60405180910390a49695505050505050565b63ffffffff84166000908152600660209081526040808320815160608101835290546001600160a01b038116825261ffff600160a01b8204811694830194909452600160b01b9004909216908201529080612ac584612e86565b9150915083606001516001600160a01b03166323b872dd3387846040518463ffffffff1660e01b8152600401612afd9392919061473a565b6020604051808303816000875af1925050508015612b38575060408051601f3d908101601f19168201909252612b3591810190614bc9565b60015b612bfe576060840151612b56906001600160a01b0316333084612f40565b6001600160a01b038086166000908152600a60209081526040808320606089015190941683529290529081208054839290612b929084906147dd565b909155505060608401516001600160a01b031660009081526009602052604081208054839290612bc39084906147dd565b909155505060405163ffffffff8816907fe6dfda7486ec1e06f754c28be83c676af29b18143765a2843361313cdab2712590600090a2612c00565b505b6020830151604051637f5e0ed360e01b81526004810184905261ffff909116602482015260009073c955962611226cd2ae467a097aec900e4b72229490637f5e0ed390604401602060405180830381865af4158015612c63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c8791906146db565b9050600081118015612ca2575083516001600160a01b031615155b15612d4b57612cb1818461470a565b606086015185516040516323b872dd60e01b81529295506001600160a01b03909116916323b872dd91612ceb91339190869060040161473a565b6020604051808303816000875af1925050508015612d26575060408051601f3d908101601f19168201909252612d2391810190614bc9565b60015b612d49576060850151612d44906001600160a01b0316333084612f40565b612d4b565b505b84606001516001600160a01b03166323b872dd33612d67610ef3565b866040518463ffffffff1660e01b8152600401612d869392919061473a565b6020604051808303816000875af1925050508015612dc1575060408051601f3d908101601f19168201909252612dbe91810190614bc9565b60015b612de4576060850151612ddf906001600160a01b0316333086612f40565b612259565b50856001600160a01b0316876001600160a01b03168963ffffffff167f3687d64f40b11dd1c102a76882ac1735891c546a96ae27935eb5c7865b9d86fa886000015189604001518789888c600001518e61012001518f606001516040516122c698979695949392919061498a565b60006107a3848484306131bd565b6000612e6d868530612ffa565b612e7b87878787878761333b565b979650505050505050565b600080600083600001518460200151612e9f919061470a565b60c0850151604051632ad659af60e01b81526004810183905261ffff909116602482015290915073c955962611226cd2ae467a097aec900e4b72229490632ad659af90604401602060405180830381865af4158015612f02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f2691906146db565b9250828460200151612f38919061470a565b915050915091565b6108c4846323b872dd60e01b85858560405160240161230e9392919061473a565b63ffffffff84166000908152600760209081526040808320805460ff191660019081179091556101208701516001600160a01b03168452600883528184208783015185529092528220805491929091612fbb90849061470a565b909155505060405163a4d0845d60e01b815263ffffffff8516600482015281151560248201526001600160a01b0383169063a4d0845d90604401610cb9565b60e083015161012084015160408086015181516001600160a01b038781166024830152868116604483015290931660648401526084808401919091528151808403909101815260a49092018152602080830180516001600160e01b031663b030667160e01b17905281518083019092528082527f4e4654206e6f74207375636365737366756c6c79207472616e73666572726564908201526108c49291906137bb565b60006130f2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166138339092919063ffffffff16565b90508051600014806131135750808060200190518101906131139190614bc9565b610e785760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016107da565b61317a610d23565b610af95760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016107da565b600082602001514211156132135760405162461bcd60e51b815260206004820152601c60248201527f4c656e646572205369676e61747572652068617320657870697265640000000060448201526064016107da565b6001600160a01b0382166132605760405162461bcd60e51b81526020600482015260146024820152734c6f616e206973207a65726f206164647265737360601b60448201526064016107da565b60408301516001600160a01b031661327a575060006107a3565b600061328586613842565b85516020808801516040516132a4939201918252602082015260400190565b6040516020818303038152906040526132bc86613901565b85466040516020016132d2959493929190614c75565b6040516020818303038152906040528051906020012090506133338460400151613329837f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c91909152603c902090565b8660600151613944565b9150506107a3565b6101208501516001600160a01b03166000908152600860209081526040808320818901518452909152812080546001919083906133799084906147dd565b909155505085516040868101519051637b2392f160e01b8152600481019290925261ffff1660248201526001600160a01b038316604482015260009073c955962611226cd2ae467a097aec900e4b72229490637b2392f190606401602060405180830381865af41580156133f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341591906146db565b90506000818860000151613429919061470a565b9050811561344b57606088015161344b906001600160a01b0316868685612f40565b6060880151613465906001600160a01b0316868884612f40565b604051631c2d8fb360e31b81527f4449524543545f4c4f414e5f434f4f5244494e41544f5200000000000000000060048201526000907f0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda6001600160a01b03169063e16c7d9890602401602060405180830381865afa1580156134ec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613510919061471d565b60405163d1f7659560e01b81529091506001600160a01b0382169063d1f76595906135419089908e906004016147c4565b6020604051808303816000875af1158015613560573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135849190614cd4565b935088600560008663ffffffff1663ffffffff16815260200190815260200160002060008201518160000155602082015181600101556040820151816002015560608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060808201518160030160146101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160030160186101000a81548161ffff021916908361ffff16021790555060c082015181600301601a6101000a81548161ffff021916908361ffff16021790555060e08201518160040160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506101008201518160040160146101000a8154816001600160401b0302191690836001600160401b031602179055506101208201518160050160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506101408201518160060160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555090505087600660008663ffffffff1663ffffffff16815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060208201518160000160146101000a81548161ffff021916908361ffff16021790555060408201518160000160166101000a81548161ffff021916908361ffff1602179055509050505050509695505050505050565b6060600080856001600160a01b0316856040516137d89190614cf1565b600060405180830381855af49150503d8060008114613813576040519150601f19603f3d011682016040523d82523d6000602084013e613818565b606091505b50915091506138298683838761399b565b9695505050505050565b60606107a38484600085613a14565b60608160c0015182600001518360200151846060015185604001518660e0015187608001518860a001516040516020016138eb989796959493929190606098891b6001600160601b031990811682526014820198909852603481019690965293871b86166054860152606885019290925290941b909216608882015260e09290921b6001600160e01b031916609c83015260f01b6001600160f01b03191660a082015260a20190565b6040516020818303038152906040529050919050565b60608160400151826000015183602001516040516020016138eb9392919060609390931b6001600160601b03191683526014830191909152603482015260540190565b60008060006139538585613ae4565b9092509050600081600481111561396c5761396c614d0d565b14801561398a5750856001600160a01b0316826001600160a01b0316145b806138295750613829868686613b29565b60608315613a0a578251600003613a03576001600160a01b0385163b613a035760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016107da565b50816107a3565b6107a38383613c15565b606082471015613a755760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016107da565b600080866001600160a01b03168587604051613a919190614cf1565b60006040518083038185875af1925050503d8060008114613ace576040519150601f19603f3d011682016040523d82523d6000602084013e613ad3565b606091505b5091509150612e7b8783838761399b565b6000808251604103613b1a5760208301516040840151606085015160001a613b0e87828585613c3f565b94509450505050613b22565b506000905060025b9250929050565b6000806000856001600160a01b0316631626ba7e60e01b8686604051602401613b53929190614d23565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613b919190614cf1565b600060405180830381855afa9150503d8060008114613bcc576040519150601f19603f3d011682016040523d82523d6000602084013e613bd1565b606091505b5091509150818015613be557506020815110155b801561382957508051630b135d3f60e11b90613c0a90830160209081019084016146db565b149695505050505050565b815115613c255781518083602001fd5b8060405162461bcd60e51b81526004016107da9190614d3c565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b03831115613c6c5750600090506003613cf0565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015613cc0573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116613ce957600060019250925050613cf0565b9150600090505b94509492505050565b6040805161016081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905261014081019190915290565b600060208284031215613d6757600080fd5b81356001600160e01b031981168114610d1c57600080fd5b63ffffffff8116811461099c57600080fd5b8035613d9c81613d7f565b919050565b600060208284031215613db357600080fd5b8135610d1c81613d7f565b6001600160a01b03169052565b6001600160a01b038116811461099c57600080fd5b8035613d9c81613dcb565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715613e2357613e23613deb565b60405290565b604051601f8201601f191681016001600160401b0381118282101715613e5157613e51613deb565b604052919050565b600082601f830112613e6a57600080fd5b81356001600160401b03811115613e8357613e83613deb565b613e96601f8201601f1916602001613e29565b818152846020838601011115613eab57600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060808587031215613ede57600080fd5b8435613ee981613dcb565b93506020850135613ef981613dcb565b92506040850135915060608501356001600160401b03811115613f1b57600080fd5b613f2787828801613e59565b91505092959194509250565b61ffff8116811461099c57600080fd5b8035613d9c81613f33565b600060208284031215613f6057600080fd5b8135610d1c81613f33565b6000610100808385031215613f7f57600080fd5b604051908101906001600160401b0382118183101715613fa157613fa1613deb565b8160405280925083358152602084013560208201526040840135604082015260608401359150613fd082613dcb565b816060820152613fe260808501613d91565b6080820152613ff360a08501613f43565b60a082015261400460c08501613de0565b60c082015261401560e08501613de0565b60e0820152505092915050565b60006080828403121561403457600080fd5b604051608081016001600160401b03828210818311171561405757614057613deb565b8160405282935084358352602085013560208401526040850135915061407c82613dcb565b816040840152606085013591508082111561409657600080fd5b506140a385828601613e59565b6060830152505092915050565b6000604082840312156140c257600080fd5b6140ca613e01565b905081356140d781613dcb565b815260208201356140e781613f33565b602082015292915050565b6000806000808486036101a081121561410a57600080fd5b6141148787613f6b565b9450604060ff198201121561412857600080fd5b50614131613e01565b6101008601358152610120860135602082015292506101408501356001600160401b0381111561416057600080fd5b61416c87828801614022565b92505061417d8661016087016140b0565b905092959194509250565b60008060006060848603121561419d57600080fd5b83356141a881613dcb565b92506020840135915060408401356141bf81613dcb565b809150509250925092565b600080604083850312156141dd57600080fd5b82356141e881613dcb565b946020939093013593505050565b6001600160a01b0391909116815260200190565b60006020828403121561421c57600080fd5b5035919050565b6000806000610160848603121561423957600080fd5b6142438585613f6b565b92506101008401356001600160401b0381111561425f57600080fd5b61426b86828701614022565b92505061427c8561012086016140b0565b90509250925092565b801515811461099c57600080fd5b600080604083850312156142a657600080fd5b82356142b181613dcb565b915060208301356142c181614285565b809150509250929050565b60006001600160401b038211156142e5576142e5613deb565b5060051b60200190565b600082601f83011261430057600080fd5b81356020614315614310836142cc565b613e29565b82815260059290921b8401810191818101908684111561433457600080fd5b8286015b8481101561435857803561434b81614285565b8352918301918301614338565b509695505050505050565b6000806040838503121561437657600080fd5b82356001600160401b038082111561438d57600080fd5b818501915085601f8301126143a157600080fd5b813560206143b1614310836142cc565b82815260059290921b840181019181810190898411156143d057600080fd5b948201945b838610156143f75785356143e881613dcb565b825294820194908201906143d5565b9650508601359250508082111561440d57600080fd5b5061441a858286016142ef565b9150509250929050565b60006020828403121561443657600080fd5b8135610d1c81613dcb565b600080600080600080600060e0888a03121561445c57600080fd5b873561446781613d7f565b9650602088013561447781613d7f565b955060408801359450606088013593506080880135925060a0880135915060c08801356001600160401b038111156144ae57600080fd5b6144ba8a828b01613e59565b91505092959891949750929550565b60008083601f8401126144db57600080fd5b5081356001600160401b038111156144f257600080fd5b6020830191508360208260051b8501011115613b2257600080fd5b60008083601f84011261451f57600080fd5b5081356001600160401b0381111561453657600080fd5b602083019150836020828501011115613b2257600080fd5b60008060008060008060008060a0898b03121561456a57600080fd5b883561457581613dcb565b9750602089013561458581613dcb565b965060408901356001600160401b03808211156145a157600080fd5b6145ad8c838d016144c9565b909850965060608b01359150808211156145c657600080fd5b6145d28c838d016144c9565b909650945060808b01359150808211156145eb57600080fd5b506145f88b828c0161450d565b999c989b5096995094979396929594505050565b60008060008060008060a0878903121561462557600080fd5b863561463081613dcb565b9550602087013561464081613dcb565b9450604087013593506060870135925060808701356001600160401b0381111561466957600080fd5b61467589828a0161450d565b979a9699509497509295939492505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b63ffffffff9290921682526001600160a01b0316602082015260400190565b6000602082840312156146ed57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610794576107946146f4565b60006020828403121561472f57600080fd5b8151610d1c81613dcb565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6020808252601c908201527f4f776e61626c653a206e6f74206f776e65722063616e64696461746500000000604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6000600182016147bd576147bd6146f4565b5060010190565b6001600160a01b03929092168252602082015260400190565b80820180821115610794576107946146f4565b60006020828403121561480257600080fd5b8151610d1c81613f33565b60006101c08201905083518252602084015160208301526040840151604083015260608401516148406060840182613dbe565b506080840151614858608084018263ffffffff169052565b5060a084015161486e60a084018261ffff169052565b5060c084015161488460c084018261ffff169052565b5060e084015161489760e0840182613dbe565b50610100848101516001600160401b031690830152610120808501516148bf82850182613dbe565b5050610140808501516148d482850182613dbe565b505082516001600160a01b0316610160830152602083015161ffff9081166101808401526040840151166101a0830152610d1c565b60006060828403121561491b57600080fd5b604051606081016001600160401b03828210818311171561493e5761493e613deb565b816040528451915061494f82613dcb565b908252602084015190808216821461496657600080fd5b50602082015260408301516004811061497e57600080fd5b60408201529392505050565b97885260208801969096526040870194909452606086019290925260808501526001600160a01b0390811660a085015290811660c08401521660e08201526101000190565b86548152600187015460208201526002870154604082015260038701546102008201906001600160a01b03614a0960608501828416613dbe565b60a082901c63ffffffff16608085015261ffff60c083901c811660a0860152614a3d60c08601828560d01c1661ffff169052565b5060048a01549150614a5460e08501828416613dbe565b5060a081901c6001600160401b03166101008401525060058801546001600160a01b0316614a86610120840182613dbe565b5060068801546001600160a01b0316614aa3610140840182613dbe565b5063ffffffff871661016083015263ffffffff8616610180830152846101a0830152836101c0830152612e7b6101e0830184613dbe565b60008060408385031215614aed57600080fd5b8251614af881613dcb565b60208401519092506142c181613dcb565b60005b83811015614b24578181015183820152602001614b0c565b50506000910152565b60008151808452614b45816020860160208601614b09565b601f01601f19169290920160200192915050565b805182526020810151602083015260018060a01b03604082015116604083015260006060820151608060608501526107a36080850182614b2d565b600063ffffffff808816835280871660208401525084604083015283606083015260a06080830152612e7b60a0830184614b59565b600060208284031215614bdb57600080fd5b8151610d1c81614285565b600061012084518352602085015160208401526040850151604084015260018060a01b03606086015116606084015263ffffffff608086015116608084015261ffff60a08601511660a084015260c0850151614c4560c0850182613dbe565b5060e0850151614c5860e0850182613dbe565b5080610100840152614c6c81840185614b59565b95945050505050565b60008651614c87818460208b01614b09565b865190830190614c9b818360208b01614b09565b8651910190614cae818360208a01614b09565b60609590951b6001600160601b0319169401938452505060148201526034019392505050565b600060208284031215614ce657600080fd5b8151610d1c81613d7f565b60008251614d03818460208701614b09565b9190910192915050565b634e487b7160e01b600052602160045260246000fd5b8281526040602082015260006107a36040830184614b2d565b602081526000610d1c6020830184614b2d56fea164736f6c6343000813000a

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000169ee6762811ab9bc59a609331bc721d9f0cd56c0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f

-----Decoded View---------------
Arg [0] : _admin (address): 0x169ee6762811ab9BC59A609331bc721d9f0CD56c
Arg [1] : _nftfiHub (address): 0x4deAcdDEF0E6ada9a35e360126181C75fA7F8EdA
Arg [2] : _permittedErc20s (address[]): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,0x6B175474E89094C44Da98b954EedeAC495271d0F

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 000000000000000000000000169ee6762811ab9bc59a609331bc721d9f0cd56c
Arg [1] : 0000000000000000000000004deacddef0e6ada9a35e360126181c75fa7f8eda
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000060
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [4] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [5] : 0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.