Token FeedLoan

 

Overview ERC-721

Total Supply:
0 fLoan

Holders:
3 addresses
Balance
0 fLoan
0x0000000000000000000000000000000000000000
Loading
[ Download CSV Export  ] 
Loading
Loading

Click here to update the token ICO / general information
# Exchange Pair Price  24H Volume % Volume
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
FeedLoan

Compiler Version
v0.8.1+commit.df193b15

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 18 : FeedLoan.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./interfaces/IFeesController.sol";
import "./interfaces/IVaultController.sol";

contract FeedLoan is ERC721, Ownable, ReentrancyGuard {
    using Counters for Counters.Counter;
    using Address for address;
    using SafeERC20 for IERC20;
    using SafeMath for uint256;

    Counters.Counter private _tokenIds;

    /***********************
     ** Structs and Enums **
     ***********************/

    enum LoanStatus {
        Active,
        Repaid,
        Liquidated,
        Completed
    }

    struct Loan {
        LoanStatus status;
        address collateral; // Collateral asset
        uint256 collateralAmount; // Amount of collateral asset put down by borrower
        address asset;
        uint256 assetAmount;
        uint256 startTime;
        uint256 duration;
        uint256 intRateBP;
        bool intProRated;
        uint256 maxRepayment;
        uint256 earnedInterest;
        bool allowLiquidator;
    }

    struct VaultInfo {
        bool useVault;
        uint256 vid;
    }

    /***************
     ** Variables **
     ***************/

    /// @dev Fees cap
    uint256 public constant MAXIMUM_LENDER_FEE_BP = 1000;
    uint256 public constant MAXIMUM_BORROWER_FEE_BP = 1000;

    /// @dev An autoincrement number which represent an Unique ID for each individual loan
    uint256 public totalLoansCount;

    /// @dev A counter for total active loans
    uint256 public totalActiveLoans;

    /// @dev An address of DealManager
    address public dealManager;

    /// @dev An address of FeesController
    address public feesController;

    /// @dev An address of VaultController
    address public vaultController;

    /// @dev A lender's fees basis point
    uint256 public lenderFeeBP = 15;

    /// @dev Lender's fees collector address
    address public lenderFeeCollector;

    /// @dev A borrower's fees basis point
    uint256 public borrowerFeeBP = 15;

    /// @dev Borrower's fees collector address
    address public borrowerFeeCollector;

    /*************
     ** Mapping **
     *************/

    /// @dev Mapping loan's ID to loan
    mapping(uint256 => Loan) public loans;

    /// @dev Mapping loan's ID to lender address
    mapping(uint256 => address) public loanLender;

    /// @dev Mapping loan's ID to borrower address
    mapping(uint256 => address) public loanBorrower;

    /// @dev Mapping loan's ID to VaultInfo
    mapping(uint256 => VaultInfo) public loanVault;

    /// @dev Mapping lender address to loan's ID
    mapping(address => uint256[]) public lenderLoans;

    /// @dev Mapping borrower address to loan's ID
    mapping(address => uint256[]) public borrowerLoans;

    /*************
     ** Events **
     *************/

    event LoanStarted(
        uint256 indexed _id,
        address indexed _lender,
        address _asset,
        uint256 _assetAmount,
        address indexed _borrower,
        address _collateral,
        uint256 _collateralAmount,
        uint256 _duration,
        uint256 _intRateBP,
        bool _intProRated,
        bool _useVault,
        uint256 _vaultId
    );
    event LoanAllowLiquidatorChanged(uint256 indexed _loanId, bool _allowLiquidator);
    event LoanRepaid(
        uint256 indexed _loanId,
        uint256 _repaymentAmount,
        uint256 _earnedInterest,
        uint256 _lenderFee,
        uint256 _borrowerFee
    );
    event LoanLiquidated(uint256 indexed _loanId, uint256 _returnAmount, uint256 _lenderFee, uint256 _borrowerFee);
    event LoanLiquidatedOnBehalf(
        uint256 indexed _loanId,
        address indexed _liquidator,
        uint256 _returnAmount,
        uint256 _repaymentAmount,
        uint256 _earnedInterest,
        uint256 _lenderFee,
        uint256 _borrowerFee
    );
    event LoanRedeemed(uint256 _loanId);

    event LenderFeeBPChanged(uint256 _lenderFeeBP);
    event BorrowerFeeBPChanged(uint256 _borrowerFeeBP);
    event LenderFeeCollectorChanged(address _lenderFeeCollector);
    event BorrowerFeeCollectorChanged(address _borrowerFeeCollector);
    event VaultControllerChanged(address _vaultController);

    /***************
     ** Modifiers **
     ***************/

    /**
     * @notice Function modifier to check whether send is deal manager
     */
    modifier onlyDealManager() {
        require(msg.sender == dealManager, "Forbidden: only deal manager is allowed");
        _;
    }

    /************************
     ** Internal Functions **
     ************************/

    /**
     * @notice Override beforeTokenTransfer function
     * @param from: sender's address
     * @param to: receiver's address
     * @param tokenId: token'id to transfer
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, tokenId);
        if (to != address(0)) {
            loanLender[tokenId] = to;
        }
    }

    /**
     * @notice Calculate loan maximum repayment
     * @param _loanPrincipalAmount: Loan principal
     * @param _loanDuration: Loan duration in seconds
     * @param _loanIntRateBP: Loan interest rate in basis points
     * @return uint256: maximum repayment amount
     */
    function _calcMaximumRepayment(
        uint256 _loanPrincipalAmount,
        uint256 _loanDuration,
        uint256 _loanIntRateBP
    ) internal pure returns (uint256) {
        return _loanPrincipalAmount.mul(_loanIntRateBP).mul(_loanDuration).div(10000).div(31536000).add(_loanPrincipalAmount);
    }

    /**
     * @notice Calculate loan interest rate due
     * @param _loanPrincipalAmount: Loan principal
     * @param _loanIntRateBP: Loan interest rate in basis points
     * @param _loanDuration: Loan duration in seconds
     * @param _loanDurationElapsed: Loan elapsed duration in seconds
     * @param _loanIntProRated: Loan prorated setting
     * @return uint256: interest rate due
     */
    function _calcInterestDue(
        uint256 _loanPrincipalAmount,
        uint256 _loanIntRateBP,
        uint256 _loanDuration,
        uint256 _loanDurationElapsed,
        bool _loanIntProRated
    ) internal pure returns (uint256) {
        uint256 _interestDue = _loanPrincipalAmount.mul(_loanIntRateBP).mul(_loanDuration).div(10000).div(31536000);
        uint256 _interestAccured = _interestDue.mul(_loanDurationElapsed).div(_loanDuration);
        // If loan is prorated
        if (_loanIntProRated) return _interestAccured;

        // if loan is not prorated
        uint256 _maximumInterest = _calcMaximumRepayment(_loanPrincipalAmount, _loanDuration, _loanIntRateBP);
        if (_loanPrincipalAmount.add(_interestAccured) > _maximumInterest) {
            return _maximumInterest.sub(_loanPrincipalAmount);
        } else {
            return _interestAccured;
        }
    }

    /***************
     ** Functions **
     ***************/

    /**
     * @notice Constructor
     * @param tokenName: Name of Token
     * @param symbol: Symbol of Token
     * @param _dealManager: An address of DealManager
     * @param _feesController: An address of FeesController
     * @param _lenderFeeCollector: An address of lender's fee collector
     * @param _borrowerFeeCollector: An address of borrower's fee collector
     */
    constructor(
        string memory tokenName,
        string memory symbol,
        address _dealManager,
        address _feesController,
        address _lenderFeeCollector,
        address _borrowerFeeCollector
    ) ERC721(tokenName, symbol) {
        dealManager = _dealManager;
        feesController = _feesController;
        lenderFeeCollector = _lenderFeeCollector;
        borrowerFeeCollector = _borrowerFeeCollector;
    }

    /**
     * @dev Transfer and check for deflationary effects
     * @param _from: sender's address
     * @param _to: receiver's address
     * @param _token: token contract address
     * @param _amount: amount of token to transfer
     * @return uint256 number of token transfer
     */
    function _safeDeflationaryTransfer(
        address _from,
        address _to,
        address _token,
        uint256 _amount
    ) internal returns (uint256) {
        uint256 _before = IERC20(_token).balanceOf(address(_to));
        IERC20(_token).safeTransferFrom(address(_from), address(_to), _amount);
        return IERC20(_token).balanceOf(address(_to)).sub(_before);
    }

    /**
     * @notice Start Loan
     * @param _lender: An address of lender
     * @param _asset: An address of asset to lend
     * @param _assetAmount: Amount of asset to lend
     * @param _borrower: An address of borrower
     * @param _collateral: An address of collateral
     * @param _collateralAmount: Amount of colleteral to collateralize
     * @param _duration: A duration of loan in seconds
     * @param _intRateBP: Loan's interest rate in basis points
     * @param _intProRated: Loan's prorated setting
     * @param _useVault: Deposit loan's collateral to Vault
     * @param _vaultId: Vault ID to deposit
     * @return uint256 Loan ID
     */
    function startLoan(
        address _lender,
        address _asset,
        uint256 _assetAmount,
        address _borrower,
        address _collateral,
        uint256 _collateralAmount,
        uint256 _duration,
        uint256 _intRateBP,
        bool _intProRated,
        bool _useVault,
        uint256 _vaultId
    ) external onlyDealManager returns (uint256) {
        // Transfer collateral from DealManager to this contract
        _collateralAmount = _safeDeflationaryTransfer(msg.sender, address(this), _collateral, _collateralAmount);

        // Transfer lending asset to borrower
        _assetAmount = _safeDeflationaryTransfer(msg.sender, _borrower, _asset, _assetAmount);

        // Increment token's ID which use for loan ID
        _tokenIds.increment();
        uint256 _id = _tokenIds.current();

        // Interest rate basis points must be greater than zero
        require(_intRateBP > 0, "StartLoan: Interest rate is negative");

        // Duration msut be greater than zero
        require(_duration > 0, "StartLoan: Duration is zero");

        // If Loan use Vault to monetize on collateral
        if (_useVault) {
            // Store loan's vault info
            loanVault[_id] = VaultInfo({useVault: _useVault, vid: _vaultId});

            uint256 _beforeVaultBalance = IVaultController(vaultController).balance(_vaultId, _id);

            // Approve and deposit collateral to Vault through VaultController
            IERC20(_collateral).safeApprove(address(vaultController), 0);
            IERC20(_collateral).safeApprove(address(vaultController), _collateralAmount);
            IVaultController(vaultController).deposit(_vaultId, _id, _collateralAmount);

            _collateralAmount = IVaultController(vaultController).balance(_vaultId, _id).sub(_beforeVaultBalance);
        }

        // Save Loan to storage and increment total loans count
        loans[_id] = Loan({
            status: LoanStatus.Active,
            collateral: _collateral,
            collateralAmount: _collateralAmount,
            asset: _asset,
            assetAmount: _assetAmount,
            startTime: block.timestamp,
            duration: _duration,
            intRateBP: _intRateBP,
            intProRated: _intProRated,
            maxRepayment: _calcMaximumRepayment(_assetAmount, _duration, _intRateBP),
            earnedInterest: 0,
            allowLiquidator: false
        });

        loanLender[_id] = _lender;
        loanBorrower[_id] = _borrower;
        totalLoansCount += 1;
        totalActiveLoans += 1;
        lenderLoans[_lender].push(_id);
        borrowerLoans[_borrower].push(_id);

        // Mint NFT to lender
        _safeMint(_lender, _id);

        // Emit LoanStarted event
        emit LoanStarted(
            _id,
            _lender,
            _asset,
            _assetAmount,
            _borrower,
            _collateral,
            _collateralAmount,
            _duration,
            _intRateBP,
            _intProRated,
            _useVault,
            _vaultId
        );

        // Return Loan's ID
        return _id;
    }

    /**
     * @notice Set Loan's to allow or disallow liquidator
     * @param _loanId: Loan's ID
     * @param _allowLiquidator: Allow or disallow liquidator
     */
    function setAllowLiquidator(uint256 _loanId, bool _allowLiquidator) external onlyDealManager {
        Loan storage _loan = loans[_loanId];

        _loan.allowLiquidator = _allowLiquidator;

        emit LoanAllowLiquidatorChanged(_loanId, _allowLiquidator);
    }

    /**
     * @notice Borrower make payback loan with borrowed asset
     * @param _loanId: Loan's ID
     */
    function payback(uint256 _loanId) external nonReentrant {
        // Verify sender is borrower
        require(msg.sender == loanBorrower[_loanId], "Payback: Sender is not borrower");

        // Fetch loan details from storage
        Loan storage _loan = loans[_loanId];

        // Verify loan is only in Active status
        require(_loan.status == LoanStatus.Active, "Payback: Loan is not active");

        // Get loan interest due
        uint256 _interestDue = _loan.maxRepayment.sub(_loan.assetAmount);

        // If loan is prorated
        if (_loan.intProRated) {
            // Calculate interest due until current block
            _interestDue = _calcInterestDue(
                _loan.assetAmount,
                _loan.intRateBP,
                _loan.duration,
                block.timestamp.sub(_loan.startTime),
                _loan.intProRated
            );
        }

        // Get lender's fee
        uint256 _lenderFee = _interestDue.mul(lenderFeeBP).div(10000);

        // Get borrower's fee
        uint256 _borrowerFee = _interestDue.mul(borrowerFeeBP).div(10000);

        // If fees controller is set, adjust lender and borrower fees accordingly
        if (feesController != address(0)) {
            // Calculate and set lender & borrower fee by using discount basis point from FeesController
            _lenderFee = _lenderFee.sub(_lenderFee.mul(IFeesController(feesController).getDiscountBP(loanLender[_loanId])).div(10000));
            _borrowerFee = _borrowerFee.sub(
                _borrowerFee.mul(IFeesController(feesController).getDiscountBP(loanBorrower[_loanId])).div(10000)
            );
        }

        // Calculate total repayment amount
        uint256 _repaymentAmount = _loan.assetAmount.add(_interestDue).sub(_lenderFee.add(_borrowerFee));

        // Transfer principal including interest from borrower to contract
        uint256 _assetAmount = _safeDeflationaryTransfer(loanBorrower[_loanId], address(this), _loan.asset, _repaymentAmount);

        // Update loan asset amount in case token is deflationary
        _loan.assetAmount = _assetAmount.sub(_interestDue.sub(_lenderFee.add(_borrowerFee)));

        // Transfer lender's fee
        IERC20(_loan.asset).safeTransferFrom(loanBorrower[_loanId], address(lenderFeeCollector), _lenderFee);

        // Transfer borrower's fee
        IERC20(_loan.asset).safeTransferFrom(loanBorrower[_loanId], address(borrowerFeeCollector), _borrowerFee);

        // Set loan as repaid
        _loan.status = LoanStatus.Repaid;

        // Update loan asset amount
        _loan.earnedInterest = _interestDue.sub(_lenderFee.add(_borrowerFee));

        // Update total number of active loans
        totalActiveLoans -= 1;

        // If collateral is in vault
        if (loanVault[_loanId].useVault) {
            uint256 _withdrawnAmount = _withdrawFromVault(_loanId);
            // Transfer collateral to borrower
            IERC20(_loan.collateral).safeTransfer(loanBorrower[_loanId], _withdrawnAmount);
        } else {
            // Transfer collateral to borrower
            IERC20(_loan.collateral).safeTransfer(loanBorrower[_loanId], _loan.collateralAmount);
        }

        // Emit LoanRepaid event
        emit LoanRepaid(_loanId, _repaymentAmount, _loan.earnedInterest, _lenderFee, _borrowerFee);
    }

    // Lender liquidate overdue loan
    function liquidateOnBehalf(uint256 _loanId) external nonReentrant {
        // Fetch loan from storage
        Loan storage _loan = loans[_loanId];

        // Check whether lender allow liquidator to liquidate loan
        require(_loan.allowLiquidator, "FeedLoan(liquidateOnBehalf): Liquidator is not allowed");

        // Loan should not be repaid, liquidated or completed
        require(_loan.status == LoanStatus.Active, "FeedLoan(liquidateOnBehalf): Loan is not active");

        // Current block time is greater than loan starting time plus duration
        require(block.timestamp > _loan.startTime.add(_loan.duration), "FeedLoan(liquidateOnBehalf): Loan is not overdue");

        uint256 _interestDue = _loan.maxRepayment.sub(_loan.assetAmount);
        if (_loan.intProRated) {
            _interestDue = _calcInterestDue(
                _loan.assetAmount,
                _loan.intRateBP,
                _loan.duration,
                block.timestamp.sub(_loan.startTime),
                _loan.intProRated
            );
        }

        uint256 _lenderFee = _interestDue.mul(lenderFeeBP).div(10000);
        uint256 _borrowerFee = _interestDue.mul(borrowerFeeBP).div(10000);

        // If fees controller is set, adjust lender and borrower fees accordingly
        if (feesController != address(0)) {
            // Calculate and set lender & borrower fee by using discount basis point from FeesController
            _lenderFee = _lenderFee.sub(_lenderFee.mul(IFeesController(feesController).getDiscountBP(loanLender[_loanId])).div(10000));
            _borrowerFee = _borrowerFee.sub(
                _borrowerFee.mul(IFeesController(feesController).getDiscountBP(loanBorrower[_loanId])).div(10000)
            );
        }

        uint256 _repaymentAmount = _loan.assetAmount.add(_interestDue).sub(_lenderFee.add(_borrowerFee));

        // Transfer principal including interest from liquidator to contract
        uint256 _assetAmount = _safeDeflationaryTransfer(address(msg.sender), address(this), _loan.asset, _repaymentAmount);

        // Update loan asset amount in case token is deflationary
        _loan.assetAmount = _assetAmount.sub(_interestDue.sub(_lenderFee.add(_borrowerFee)));

        // Transfer lender's fee
        IERC20(_loan.asset).safeTransferFrom(address(msg.sender), address(lenderFeeCollector), _lenderFee);

        // Transfer borrower's fee
        IERC20(_loan.asset).safeTransferFrom(address(msg.sender), address(borrowerFeeCollector), _borrowerFee);

        // Set loan status
        _loan.status = LoanStatus.Repaid;

        // Update loan asset amount
        _loan.earnedInterest = _interestDue.sub(_lenderFee.add(_borrowerFee));

        // Update total number of active loans
        totalActiveLoans -= 1;

        uint256 _returnAmount = 0;
        // If collateral is in vault
        if (loanVault[_loanId].useVault) {
            _returnAmount = _withdrawFromVault(_loanId);
        } else {
            _returnAmount = _loan.collateralAmount;
        }

        // Tranfer collateral to liquidator
        IERC20(_loan.collateral).safeTransfer(address(msg.sender), _returnAmount);

        // Emit LoanLiquidatedOnBehalf event
        emit LoanLiquidatedOnBehalf(
            _loanId,
            address(msg.sender),
            _returnAmount,
            _repaymentAmount,
            _loan.earnedInterest,
            _lenderFee,
            _borrowerFee
        );
    }

    // Lender liquidate overdue loan
    function liquidate(uint256 _loanId) external nonReentrant {
        // Fetch loan from storage
        Loan storage _loan = loans[_loanId];

        // Loan should not be repaid, liquidated or completed
        require(_loan.status == LoanStatus.Active, "FeedLoan(liquidate): Loan is not active");

        // Current block time is greater than loan starting time plus duration
        require(block.timestamp > _loan.startTime.add(_loan.duration), "FeedLoan(liquidate): Loan is not overdue");

        // Get loan's lender
        address _lender = loanLender[_loanId];

        // Only lender is allowed to liquidate the loan
        require(_lender == msg.sender, "FeedLoan(liquidate): Sender is not lender");

        // Burn NFT
        _burn(_loanId);

        // Set loan status
        _loan.status = LoanStatus.Liquidated;

        // Update total number of active loans
        totalActiveLoans -= 1;

        uint256 _returnAmount = 0;
        // If collateral is in vault
        if (loanVault[_loanId].useVault) {
            // Collateral balance AFTER withdraw
            _returnAmount = _withdrawFromVault(_loanId);
        } else {
            _returnAmount = _loan.collateralAmount;
        }

        uint256 _lenderFee = _returnAmount.mul(lenderFeeBP).div(10000);
        uint256 _borrowerFee = _returnAmount.mul(borrowerFeeBP).div(10000);

        // If fees controller is set, adjust lender and borrower fees accordingly
        if (feesController != address(0)) {
            // Calculate and set lender & borrower fee by using discount basis point from FeesController
            _lenderFee = _lenderFee.sub(_lenderFee.mul(IFeesController(feesController).getDiscountBP(loanLender[_loanId])).div(10000));
            _borrowerFee = _borrowerFee.sub(
                _borrowerFee.mul(IFeesController(feesController).getDiscountBP(loanBorrower[_loanId])).div(10000)
            );
        }

        // Transfer lender's fee
        IERC20(_loan.collateral).safeTransfer(lenderFeeCollector, _lenderFee);

        // Transfer borrower's fee
        IERC20(_loan.collateral).safeTransfer(borrowerFeeCollector, _borrowerFee);

        // Calculate amount of collateral to return to lender after fees
        _returnAmount = _returnAmount.sub(_lenderFee).sub(_borrowerFee);

        // Tranfer collateral to lender
        IERC20(_loan.collateral).safeTransfer(_lender, _returnAmount);

        // Emit LoanLiquidated event
        emit LoanLiquidated(_loanId, _returnAmount, _lenderFee, _borrowerFee);
    }

    // Lender redeem repaid loan
    function redeem(uint256 _loanId) external nonReentrant {
        Loan storage _loan = loans[_loanId];
        require(_loan.status == LoanStatus.Repaid, "FeedLoan(redeem): Loan is not repaid");

        require(ownerOf(_loanId) == address(msg.sender), "FeedLoan(redeem): Sender is not owner");
        require(loanLender[_loanId] == address(msg.sender), "FeedLoan(redeem): Sender is not lender");

        // Burn NFT
        _burn(_loanId);

        // Set loan's status to completed
        _loan.status = LoanStatus.Completed;

        // Transfer asset to lender
        IERC20(_loan.asset).safeTransfer(loanLender[_loanId], _loan.assetAmount.add(_loan.earnedInterest));

        // Emit LoanRedeemed event
        emit LoanRedeemed(_loanId);
    }

    /**
     * @dev Withdraw collateral from vault
     * @param _loanId: Loan ID
     * @return uint256: amount of collateral withdrawn from vault
     */
    function _withdrawFromVault(uint256 _loanId) internal returns (uint256) {
        Loan storage _loan = loans[_loanId];
        uint256 _before = IERC20(_loan.collateral).balanceOf(address(this));
        IVaultController(vaultController).withdraw(loanVault[_loanId].vid, _loanId);
        uint256 _after = IERC20(_loan.collateral).balanceOf(address(this));

        // Update collateral amount
        _loan.collateralAmount = _after.sub(_before);

        return _loan.collateralAmount;
    }

    /********************
     ** View Functions **
     ********************/

    /**
     * @notice Get interest rate due to current block by loan's ID
     * @param _loanId: Loan ID
     * @return uint256: interest rate due
     */
    function interestDue(uint256 _loanId) public view returns (uint256) {
        Loan memory _loan = loans[_loanId];
        return
            _calcInterestDue(
                _loan.assetAmount,
                _loan.intRateBP,
                _loan.duration,
                block.timestamp.sub(_loan.startTime),
                _loan.intProRated
            );
    }

    /**
     * @notice Get balance of collateral in target vault
     * @param _loanId: Loan ID
     * @return uint256: Balance of collateral
     */
    function vaultBalance(uint256 _loanId) public view returns (uint256) {
        return IVaultController(vaultController).balance(loanVault[_loanId].vid, _loanId);
    }

    /**
     * @notice Get total number of loans for specific lender
     * @param _lender: Loan's lender address
     * @return uint256: Total number of loans
     */
    function lenderLoansCount(address _lender) public view returns (uint256) {
        return lenderLoans[_lender].length;
    }

    /**
     * @notice Get total number of loans for specific borrower
     * @param _borrower: Loan's lender address
     * @return uint256: Total number of loans
     */
    function borrowerLoansCount(address _borrower) public view returns (uint256) {
        return borrowerLoans[_borrower].length;
    }

    /**
     * @notice View list of loans
     * @param _cursor: cursor
     * @param _size: size
     */
    function viewLoans(uint256 _cursor, uint256 _size) public view returns (Loan[] memory, uint256) {
        uint256 _length = _size;
        uint256 _offersLength = totalLoansCount;
        if (_length > _offersLength - _cursor) {
            _length = _offersLength - _cursor;
        }

        Loan[] memory _values = new Loan[](_length);
        for (uint256 i = 0; i < _length; i++) {
            _values[i] = loans[_cursor + i + 1];
        }

        return (_values, _cursor + _length);
    }

    /**
     * @notice View list of loans by lender
     * @param _lender: lender address
     * @param _cursor: cursor
     * @param _size: size
     */
    function viewLoansPerLender(
        address _lender,
        uint256 _cursor,
        uint256 _size
    ) external view returns (Loan[] memory, uint256) {
        uint256 _length = _size;
        uint256 _bidsLength = lenderLoans[_lender].length;
        if (_length > _bidsLength - _cursor) {
            _length = _bidsLength - _cursor;
        }

        Loan[] memory _values = new Loan[](_length);
        for (uint256 i = 0; i < _length; i++) {
            uint256 _loanId = lenderLoans[_lender][_cursor + i];
            _values[i] = loans[_loanId];
        }

        return (_values, _cursor + _length);
    }

    /**
     * @notice View list of loans by borrower
     * @param _borrower: borrower address
     * @param _cursor: cursor
     * @param _size: size
     */
    function viewLoansPerBorrower(
        address _borrower,
        uint256 _cursor,
        uint256 _size
    ) external view returns (Loan[] memory, uint256) {
        uint256 _length = _size;
        uint256 _bidsLength = borrowerLoans[_borrower].length;
        if (_length > _bidsLength - _cursor) {
            _length = _bidsLength - _cursor;
        }

        Loan[] memory _values = new Loan[](_length);
        for (uint256 i = 0; i < _length; i++) {
            uint256 _loanId = borrowerLoans[_borrower][_cursor + i];
            _values[i] = loans[_loanId];
        }

        return (_values, _cursor + _length);
    }

    /*********************
     ** Admin Functions **
     *********************/

    /**
     * @notice Set Lender's fee basis point
     * @param _lenderFeeBP: lender's fee in basis point
     * @dev Callable by owner
     */
    function setLenderFeeBP(uint256 _lenderFeeBP) external onlyOwner nonReentrant {
        require(_lenderFeeBP <= MAXIMUM_LENDER_FEE_BP, "SetLenderFeeBP: must lesser than or equal to threshold");
        require(_lenderFeeBP >= 0, "SetLenderFeeBP: must greater than or equal to zero");

        lenderFeeBP = _lenderFeeBP;

        emit LenderFeeBPChanged(lenderFeeBP);
    }

    /**
     * @notice Set Borrower's fee basis point
     * @param _borrowerFeeBP: borrower's fee in basis point
     * @dev Callable by owner
     */
    function setBorrowerFeeBP(uint256 _borrowerFeeBP) external onlyOwner nonReentrant {
        require(_borrowerFeeBP <= MAXIMUM_BORROWER_FEE_BP, "SetBorrowerFeeBP: must lesser than or equal to threshold");
        require(_borrowerFeeBP >= 0, "SetBorrowerFeeBP: must greater than or equal to zero");

        borrowerFeeBP = _borrowerFeeBP;

        emit BorrowerFeeBPChanged(borrowerFeeBP);
    }

    /**
     * @notice Set Lender's fee collector
     * @param _lenderFeeCollector: lender's fee collector address
     * @dev Callable by owner
     */
    function setLenderFeeCollector(address _lenderFeeCollector) external onlyOwner nonReentrant {
        require(_lenderFeeCollector != address(0), "SetLenderFeeCollector: Cannot be zero address");

        lenderFeeCollector = _lenderFeeCollector;

        emit LenderFeeCollectorChanged(lenderFeeCollector);
    }

    /**
     * @notice Set Borrower's fee collector
     * @param _borrowerFeeCollector: borrower's fee collector address
     * @dev Callable by owner
     */
    function setBorrowerFeeCollector(address _borrowerFeeCollector) external onlyOwner nonReentrant {
        require(_borrowerFeeCollector != address(0), "SetBorrowerFeeCollector: Cannot be zero address");

        borrowerFeeCollector = _borrowerFeeCollector;

        emit BorrowerFeeCollectorChanged(borrowerFeeCollector);
    }

    /**
     * @notice Set VaultController address
     * @param _vaultController: address of new VaultController
     * @dev Callable by owner
     */
    function setVaultController(address _vaultController) external onlyOwner nonReentrant {
        require(_vaultController != address(0), "SetVaultController: Cannot be zero address");
        require(vaultController == address(0), "SetVaultController: Cannot replace vault controller");

        vaultController = _vaultController;

        emit VaultControllerChanged(_vaultController);
    }
}

File 2 of 18 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../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.
 */
abstract contract Ownable is Context {
    address private _owner;

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

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

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

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

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(address(0));
    }

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

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 3 of 18 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

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 make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

File 4 of 18 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.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;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    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));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    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");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @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");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 5 of 18 : ERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: owner query for nonexistent token");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overriden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @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.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        require(_exists(tokenId), "ERC721: operator query for nonexistent token");
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

        emit Transfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits a {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}
}

File 6 of 18 : Counters.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

File 7 of 18 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

File 8 of 18 : IFeesController.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

interface IFeesController {
    function getDiscountBP(address _user) external view returns (uint256);
}

File 9 of 18 : IVaultController.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

interface IVaultController {
    function deposit(
        uint256 _vid,
        uint256 _loanId,
        uint256 _amount
    ) external;

    function withdraw(uint256 _vid, uint256 _loanId) external;

    function vaultInfo(uint256 _vid) external view returns (address, address);

    function vaultLength() external view returns (uint256);

    function balance(uint256 _vid, uint256 _loanId) external view returns (uint256);
}

File 10 of 18 : Context.sol
// SPDX-License-Identifier: MIT

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 11 of 18 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @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);
}

File 12 of 18 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 13 of 18 : IERC721.sol
// SPDX-License-Identifier: MIT

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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * 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 Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @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 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);

    /**
     * @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;
}

File 14 of 18 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT

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 `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 15 of 18 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

File 16 of 18 : Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @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] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}

File 17 of 18 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 18 of 18 : IERC165.sol
// SPDX-License-Identifier: MIT

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);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "istanbul",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"string","name":"tokenName","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"address","name":"_dealManager","type":"address"},{"internalType":"address","name":"_feesController","type":"address"},{"internalType":"address","name":"_lenderFeeCollector","type":"address"},{"internalType":"address","name":"_borrowerFeeCollector","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_borrowerFeeBP","type":"uint256"}],"name":"BorrowerFeeBPChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_borrowerFeeCollector","type":"address"}],"name":"BorrowerFeeCollectorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_lenderFeeBP","type":"uint256"}],"name":"LenderFeeBPChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_lenderFeeCollector","type":"address"}],"name":"LenderFeeCollectorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_loanId","type":"uint256"},{"indexed":false,"internalType":"bool","name":"_allowLiquidator","type":"bool"}],"name":"LoanAllowLiquidatorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_loanId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_returnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_lenderFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_borrowerFee","type":"uint256"}],"name":"LoanLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_loanId","type":"uint256"},{"indexed":true,"internalType":"address","name":"_liquidator","type":"address"},{"indexed":false,"internalType":"uint256","name":"_returnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_repaymentAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_earnedInterest","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_lenderFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_borrowerFee","type":"uint256"}],"name":"LoanLiquidatedOnBehalf","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_loanId","type":"uint256"}],"name":"LoanRedeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_loanId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_repaymentAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_earnedInterest","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_lenderFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_borrowerFee","type":"uint256"}],"name":"LoanRepaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_id","type":"uint256"},{"indexed":true,"internalType":"address","name":"_lender","type":"address"},{"indexed":false,"internalType":"address","name":"_asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_assetAmount","type":"uint256"},{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"address","name":"_collateral","type":"address"},{"indexed":false,"internalType":"uint256","name":"_collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_duration","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_intRateBP","type":"uint256"},{"indexed":false,"internalType":"bool","name":"_intProRated","type":"bool"},{"indexed":false,"internalType":"bool","name":"_useVault","type":"bool"},{"indexed":false,"internalType":"uint256","name":"_vaultId","type":"uint256"}],"name":"LoanStarted","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":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_vaultController","type":"address"}],"name":"VaultControllerChanged","type":"event"},{"inputs":[],"name":"MAXIMUM_BORROWER_FEE_BP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAXIMUM_LENDER_FEE_BP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowerFeeBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowerFeeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"borrowerLoans","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_borrower","type":"address"}],"name":"borrowerLoansCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dealManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feesController","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_loanId","type":"uint256"}],"name":"interestDue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lenderFeeBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lenderFeeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"lenderLoans","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_lender","type":"address"}],"name":"lenderLoansCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_loanId","type":"uint256"}],"name":"liquidate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_loanId","type":"uint256"}],"name":"liquidateOnBehalf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"loanBorrower","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"loanLender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"loanVault","outputs":[{"internalType":"bool","name":"useVault","type":"bool"},{"internalType":"uint256","name":"vid","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"loans","outputs":[{"internalType":"enum FeedLoan.LoanStatus","name":"status","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"duration","type":"uint256"},{"internalType":"uint256","name":"intRateBP","type":"uint256"},{"internalType":"bool","name":"intProRated","type":"bool"},{"internalType":"uint256","name":"maxRepayment","type":"uint256"},{"internalType":"uint256","name":"earnedInterest","type":"uint256"},{"internalType":"bool","name":"allowLiquidator","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_loanId","type":"uint256"}],"name":"payback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_loanId","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_loanId","type":"uint256"},{"internalType":"bool","name":"_allowLiquidator","type":"bool"}],"name":"setAllowLiquidator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_borrowerFeeBP","type":"uint256"}],"name":"setBorrowerFeeBP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_borrowerFeeCollector","type":"address"}],"name":"setBorrowerFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lenderFeeBP","type":"uint256"}],"name":"setLenderFeeBP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lenderFeeCollector","type":"address"}],"name":"setLenderFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vaultController","type":"address"}],"name":"setVaultController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lender","type":"address"},{"internalType":"address","name":"_asset","type":"address"},{"internalType":"uint256","name":"_assetAmount","type":"uint256"},{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"address","name":"_collateral","type":"address"},{"internalType":"uint256","name":"_collateralAmount","type":"uint256"},{"internalType":"uint256","name":"_duration","type":"uint256"},{"internalType":"uint256","name":"_intRateBP","type":"uint256"},{"internalType":"bool","name":"_intProRated","type":"bool"},{"internalType":"bool","name":"_useVault","type":"bool"},{"internalType":"uint256","name":"_vaultId","type":"uint256"}],"name":"startLoan","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalActiveLoans","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLoansCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_loanId","type":"uint256"}],"name":"vaultBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultController","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cursor","type":"uint256"},{"internalType":"uint256","name":"_size","type":"uint256"}],"name":"viewLoans","outputs":[{"components":[{"internalType":"enum FeedLoan.LoanStatus","name":"status","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"duration","type":"uint256"},{"internalType":"uint256","name":"intRateBP","type":"uint256"},{"internalType":"bool","name":"intProRated","type":"bool"},{"internalType":"uint256","name":"maxRepayment","type":"uint256"},{"internalType":"uint256","name":"earnedInterest","type":"uint256"},{"internalType":"bool","name":"allowLiquidator","type":"bool"}],"internalType":"struct FeedLoan.Loan[]","name":"","type":"tuple[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_borrower","type":"address"},{"internalType":"uint256","name":"_cursor","type":"uint256"},{"internalType":"uint256","name":"_size","type":"uint256"}],"name":"viewLoansPerBorrower","outputs":[{"components":[{"internalType":"enum FeedLoan.LoanStatus","name":"status","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"duration","type":"uint256"},{"internalType":"uint256","name":"intRateBP","type":"uint256"},{"internalType":"bool","name":"intProRated","type":"bool"},{"internalType":"uint256","name":"maxRepayment","type":"uint256"},{"internalType":"uint256","name":"earnedInterest","type":"uint256"},{"internalType":"bool","name":"allowLiquidator","type":"bool"}],"internalType":"struct FeedLoan.Loan[]","name":"","type":"tuple[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_lender","type":"address"},{"internalType":"uint256","name":"_cursor","type":"uint256"},{"internalType":"uint256","name":"_size","type":"uint256"}],"name":"viewLoansPerLender","outputs":[{"components":[{"internalType":"enum FeedLoan.LoanStatus","name":"status","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"duration","type":"uint256"},{"internalType":"uint256","name":"intRateBP","type":"uint256"},{"internalType":"bool","name":"intProRated","type":"bool"},{"internalType":"uint256","name":"maxRepayment","type":"uint256"},{"internalType":"uint256","name":"earnedInterest","type":"uint256"},{"internalType":"bool","name":"allowLiquidator","type":"bool"}],"internalType":"struct FeedLoan.Loan[]","name":"","type":"tuple[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

6080604052600f600e55600f6010553480156200001b57600080fd5b506040516200527c3803806200527c8339810160408190526200003e91620002b2565b855186908690620000579060009060208501906200013c565b5080516200006d9060019060208401906200013c565b5050506200008a62000084620000e660201b60201c565b620000ea565b6001600755600b80546001600160a01b039586166001600160a01b031991821617909155600c805494861694821694909417909355600f8054928516928416929092179091556011805491909316911617905550620003b59050565b3390565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8280546200014a9062000362565b90600052602060002090601f0160209004810192826200016e5760008555620001b9565b82601f106200018957805160ff1916838001178555620001b9565b82800160010185558215620001b9579182015b82811115620001b95782518255916020019190600101906200019c565b50620001c7929150620001cb565b5090565b5b80821115620001c75760008155600101620001cc565b80516001600160a01b0381168114620001fa57600080fd5b919050565b600082601f83011262000210578081fd5b81516001600160401b03808211156200022d576200022d6200039f565b604051601f8301601f19908116603f011681019082821181831017156200025857620002586200039f565b8160405283815260209250868385880101111562000274578485fd5b8491505b8382101562000297578582018301518183018401529082019062000278565b83821115620002a857848385830101525b9695505050505050565b60008060008060008060c08789031215620002cb578182fd5b86516001600160401b0380821115620002e2578384fd5b620002f08a838b01620001ff565b9750602089015191508082111562000306578384fd5b506200031589828a01620001ff565b9550506200032660408801620001e2565b93506200033660608801620001e2565b92506200034660808801620001e2565b91506200035660a08801620001e2565b90509295509295509295565b6002810460018216806200037757607f821691505b602082108114156200039957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b614eb780620003c56000396000f3fe608060405234801561001057600080fd5b50600436106102f15760003560e01c806378573c811161019d578063c87b56dd116100e9578063e3ed1902116100a2578063f1ffac311161007c578063f1ffac3114610639578063f2fde38b1461064c578063f3c03c971461065f578063f7d3ab9714610672576102f1565b8063e3ed19021461060b578063e8f627641461061e578063e985e9c514610626576102f1565b8063c87b56dd1461058c578063d0a87f7a1461059f578063d2a66d97146105b2578063db006a75146105c5578063dc63af41146105d8578063e1ec3c68146105e0576102f1565b806399747f1511610156578063ab965aed11610130578063ab965aed1461055e578063b112cb68146103c7578063b33bae8414610566578063b88d4fde14610579576102f1565b806399747f1514610525578063a22cb46514610538578063a846c2fd1461054b576102f1565b806378573c81146104d457806380e05b35146104dc5780638da5cb5b146104ef57806390d0e7fc146104f757806395281b3b1461050a57806395d89b411461051d576102f1565b8063415f12401161025c578063695f8b551161021557806370a08231116101ef57806370a082311461048557806370daa49d14610498578063715018a6146104b957806377b49db5146104c1576102f1565b8063695f8b551461044c5780636d3d8ff31461045f578063706cf8fd14610472576102f1565b8063415f1240146103e257806342842e0e146103f55780634db6e3f7146104085780635d7a2b23146104105780635f36b048146104315780636352211e14610439576102f1565b80630fbd5647116102ae5780630fbd5647146103845780631e0d45c61461039957806323b872dd146103a157806331a2a1f6146103b45780633a5a8cf9146103c75780633cdb72f1146103cf576102f1565b806301df538d146102f657806301ffc9a71461031457806306fdde0314610334578063081812fc14610349578063095ea7b31461035c57806309ec958714610371575b600080fd5b6102fe610685565b60405161030b9190613ec6565b60405180910390f35b610327610322366004613d6d565b610694565b60405161030b91906140a5565b61033c6106dc565b60405161030b9190614133565b6102fe610357366004613da5565b61076e565b61036f61036a366004613cf6565b6107ba565b005b61036f61037f366004613dd5565b610852565b61038c6108da565b60405161030b9190614cb8565b61038c6108e0565b61036f6103af366004613b02565b6108e6565b61038c6103c2366004613da5565b61091e565b61038c6109b0565b61038c6103dd366004613cf6565b6109b6565b61036f6103f0366004613da5565b6109e7565b61036f610403366004613b02565b610d9c565b6102fe610db7565b61042361041e366004613d1f565b610dc6565b60405161030b929190613fb6565b6102fe611010565b6102fe610447366004613da5565b61101f565b61038c61045a366004613ab6565b611054565b61038c61046d366004613da5565b61106f565b61036f610480366004613da5565b6111ac565b61038c610493366004613ab6565b61127a565b6104ab6104a6366004613da5565b6112be565b60405161030b9291906140b0565b61036f6112dd565b6104236104cf366004613d1f565b611328565b6102fe611557565b6104236104ea366004613df9565b611566565b6102fe611765565b61036f610505366004613da5565b611774565b6102fe610518366004613da5565b611832565b61033c61184d565b61036f610533366004613ab6565b61185c565b61036f610546366004613cc0565b61195d565b61036f610559366004613da5565b611a2b565b61038c611e24565b61038c610574366004613b3d565b611e2a565b61036f610587366004613beb565b6123ad565b61033c61059a366004613da5565b6123ec565b61038c6105ad366004613ab6565b61246f565b6102fe6105c0366004613da5565b61248a565b61036f6105d3366004613da5565b6124a5565b61038c612621565b6105f36105ee366004613da5565b612627565b60405161030b9c9b9a999897969594939291906140c0565b61038c610619366004613cf6565b61268e565b6102fe6126aa565b610327610634366004613ad0565b6126b9565b61036f610647366004613da5565b6126e7565b61036f61065a366004613ab6565b612a6f565b61036f61066d366004613ab6565b612ae0565b61036f610680366004613ab6565b612bbe565b600b546001600160a01b031681565b60006001600160e01b031982166380ac58cd60e01b14806106c557506001600160e01b03198216635b5e139f60e01b145b806106d457506106d482612c9c565b90505b919050565b6060600080546106eb90614db1565b80601f016020809104026020016040519081016040528092919081815260200182805461071790614db1565b80156107645780601f1061073957610100808354040283529160200191610764565b820191906000526020600020905b81548152906001019060200180831161074757829003601f168201915b5050505050905090565b600061077982612cb5565b61079e5760405162461bcd60e51b815260040161079590614822565b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006107c58261101f565b9050806001600160a01b0316836001600160a01b031614156107f95760405162461bcd60e51b81526004016107959061493b565b806001600160a01b031661080b612cd2565b6001600160a01b03161480610827575061082781610634612cd2565b6108435760405162461bcd60e51b815260040161079590614667565b61084d8383612cd6565b505050565b600b546001600160a01b0316331461087c5760405162461bcd60e51b8152600401610795906147db565b60008281526012602052604090819020600a8101805460ff1916841515179055905183907f6ee87c7ed7a3b6a5606925ef4d44cfa2b0ceb0a8720298ba6b50db5c4df1ddbd906108cd9085906140a5565b60405180910390a2505050565b60105481565b600e5481565b6108f76108f1612cd2565b82612d44565b6109135760405162461bcd60e51b815260040161079590614a00565b61084d838383612dc9565b600d546000828152601560205260408082206001015490516394813dd160e01b815291926001600160a01b0316916394813dd191610960918690600401614cc1565b60206040518083038186803b15801561097857600080fd5b505afa15801561098c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d49190613dbd565b6103e881565b601660205281600052604060002081815481106109d257600080fd5b90600052602060002001600091509150505481565b60026007541415610a0a5760405162461bcd60e51b815260040161079590614c2b565b6002600755600081815260126020526040812090815460ff166003811115610a4257634e487b7160e01b600052602160045260246000fd5b14610a5f5760405162461bcd60e51b81526004016107959061423a565b60058101546004820154610a7291612ef6565b4211610a905760405162461bcd60e51b8152600401610795906145e8565b6000828152601360205260409020546001600160a01b0316338114610ac75760405162461bcd60e51b81526004016107959061437a565b610ad083612f02565b815460ff19166002178255600a805460019190600090610af1908490614d6e565b909155505060008381526015602052604081205460ff1615610b1d57610b1684612fa9565b9050610b24565b5060018201545b6000610b47612710610b41600e548561315a90919063ffffffff16565b90613166565b90506000610b66612710610b416010548661315a90919063ffffffff16565b600c549091506001600160a01b031615610cdf57600c546000878152601360205260409081902054905163b6104a1f60e01b8152610c2a92610c239261271092610b41926001600160a01b039081169263b6104a1f92610bcc9290911690600401613ec6565b60206040518083038186803b158015610be457600080fd5b505afa158015610bf8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1c9190613dbd565b869061315a565b8390613172565b600c546000888152601460205260409081902054905163b6104a1f60e01b8152929450610cdc92610cd59261271092610b41926001600160a01b039283169263b6104a1f92610c7e92911690600401613ec6565b60206040518083038186803b158015610c9657600080fd5b505afa158015610caa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cce9190613dbd565b859061315a565b8290613172565b90505b600f548554610d00916001600160a01b03610100909204821691168461317e565b6011548554610d21916001600160a01b03610100909204821691168361317e565b610d3581610d2f8585613172565b90613172565b8554909350610d539061010090046001600160a01b0316858561317e565b857ff2d932763377b0d691487ba847e159565f9926361b9c719edd77508949f8d91c848484604051610d8793929190614ccf565b60405180910390a25050600160075550505050565b61084d838383604051806020016040528060008152506123ad565b6011546001600160a01b031681565b6001600160a01b038316600090815260166020526040812054606091908390610def8682614d6e565b821115610e0357610e008682614d6e565b91505b60008267ffffffffffffffff811115610e2c57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610e6557816020015b610e52613a27565b815260200190600190039081610e4a5790505b50905060005b83811015610ff5576001600160a01b0389166000908152601660205260408120610e95838b614d23565b81548110610eb357634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910154808352601290915260409182902082516101808101909352805491935090829060ff166003811115610f0357634e487b7160e01b600052602160045260246000fd5b6003811115610f2257634e487b7160e01b600052602160045260246000fd5b815281546001600160a01b03610100918290048116602084015260018401546040840152600284015416606083015260038301546080830152600483015460a0830152600583015460c0830152600683015460e0830152600783015460ff90811615159183019190915260088301546101208301526009830154610140830152600a909201549091161515610160909101528351849084908110610fd657634e487b7160e01b600052603260045260246000fd5b6020026020010181905250508080610fed90614dec565b915050610e6b565b50806110018489614d23565b94509450505050935093915050565b600d546001600160a01b031681565b6000818152600260205260408120546001600160a01b0316806106d45760405162461bcd60e51b81526004016107959061470e565b6001600160a01b031660009081526016602052604090205490565b60008181526012602052604080822081516101808101909252805483929190829060ff1660038111156110b257634e487b7160e01b600052602160045260246000fd5b60038111156110d157634e487b7160e01b600052602160045260246000fd5b815281546001600160a01b0361010091829004811660208401526001840154604084015260028401541660608301526003830154608080840191909152600484015460a080850191909152600585015460c080860191909152600686015460e080870191909152600787015460ff90811615159587019590955260088701546101208701526009870154610140870152600a909601549093161515610160909401939093528401519284015190840151918401519394506111a59390919061119a904290613172565b8561010001516131d4565b9392505050565b6111b4612cd2565b6001600160a01b03166111c5611765565b6001600160a01b0316146111eb5760405162461bcd60e51b81526004016107959061486e565b6002600754141561120e5760405162461bcd60e51b815260040161079590614c2b565b60026007556103e88111156112355760405162461bcd60e51b815260040161079590614ad8565b60108190556040517f2c6f1e3587bb807a9f1a6771b8c729234c246de304ea17aa864daf08a6f5efb19061126a908390614cb8565b60405180910390a1506001600755565b60006001600160a01b0382166112a25760405162461bcd60e51b8152600401610795906146c4565b506001600160a01b031660009081526003602052604090205490565b6015602052600090815260409020805460019091015460ff9091169082565b6112e5612cd2565b6001600160a01b03166112f6611765565b6001600160a01b03161461131c5760405162461bcd60e51b81526004016107959061486e565b6113266000613261565b565b6001600160a01b0383166000908152601760205260408120546060919083906113518682614d6e565b821115611365576113628682614d6e565b91505b60008267ffffffffffffffff81111561138e57634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156113c757816020015b6113b4613a27565b8152602001906001900390816113ac5790505b50905060005b83811015610ff5576001600160a01b03891660009081526017602052604081206113f7838b614d23565b8154811061141557634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910154808352601290915260409182902082516101808101909352805491935090829060ff16600381111561146557634e487b7160e01b600052602160045260246000fd5b600381111561148457634e487b7160e01b600052602160045260246000fd5b815281546001600160a01b03610100918290048116602084015260018401546040840152600284015416606083015260038301546080830152600483015460a0830152600583015460c0830152600683015460e0830152600783015460ff90811615159183019190915260088301546101208301526009830154610140830152600a90920154909116151561016090910152835184908490811061153857634e487b7160e01b600052603260045260246000fd5b602002602001018190525050808061154f90614dec565b9150506113cd565b600f546001600160a01b031681565b600954606090600090839061157b8682614d6e565b82111561158f5761158c8682614d6e565b91505b60008267ffffffffffffffff8111156115b857634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156115f157816020015b6115de613a27565b8152602001906001900390816115d65790505b50905060005b8381101561174b576012600061160d838b614d23565b611618906001614d23565b815260208101919091526040908101600020815161018081019092528054829060ff16600381111561165a57634e487b7160e01b600052602160045260246000fd5b600381111561167957634e487b7160e01b600052602160045260246000fd5b815281546001600160a01b03610100918290048116602084015260018401546040840152600284015416606083015260038301546080830152600483015460a0830152600583015460c0830152600683015460e0830152600783015460ff90811615159183019190915260088301546101208301526009830154610140830152600a90920154909116151561016090910152825183908390811061172d57634e487b7160e01b600052603260045260246000fd5b6020026020010181905250808061174390614dec565b9150506115f7565b50806117578489614d23565b945094505050509250929050565b6006546001600160a01b031690565b61177c612cd2565b6001600160a01b031661178d611765565b6001600160a01b0316146117b35760405162461bcd60e51b81526004016107959061486e565b600260075414156117d65760405162461bcd60e51b815260040161079590614c2b565b60026007556103e88111156117fd5760405162461bcd60e51b815260040161079590614bd5565b600e8190556040517f7eb5d370d4e9f5567d7a6f44beea1af911e0632b530ad5679225613ffa6dfe2b9061126a908390614cb8565b6013602052600090815260409020546001600160a01b031681565b6060600180546106eb90614db1565b611864612cd2565b6001600160a01b0316611875611765565b6001600160a01b03161461189b5760405162461bcd60e51b81526004016107959061486e565b600260075414156118be5760405162461bcd60e51b815260040161079590614c2b565b60026007556001600160a01b0381166118e95760405162461bcd60e51b81526004016107959061459e565b600d546001600160a01b0316156119125760405162461bcd60e51b815260040161079590614195565b600d80546001600160a01b0319166001600160a01b0383161790556040517f9bb8d65116f0284df2ba1fbfbc918ba434a023911f7a62069ca5e3b3063696879061126a908390613ec6565b611965612cd2565b6001600160a01b0316826001600160a01b031614156119965760405162461bcd60e51b81526004016107959061444b565b80600560006119a3612cd2565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff1916921515929092179091556119e7612cd2565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051611a1f91906140a5565b60405180910390a35050565b60026007541415611a4e5760405162461bcd60e51b815260040161079590614c2b565b60026007556000818152601460205260409020546001600160a01b03163314611a895760405162461bcd60e51b815260040161079590614343565b600081815260126020526040812090815460ff166003811115611abc57634e487b7160e01b600052602160045260246000fd5b14611ad95760405162461bcd60e51b815260040161079590614630565b6000611af68260030154836008015461317290919063ffffffff16565b600783015490915060ff1615611b3f57611b3c826003015483600601548460050154611b2f86600401544261317290919063ffffffff16565b600787015460ff166131d4565b90505b6000611b5c612710610b41600e548561315a90919063ffffffff16565b90506000611b7b612710610b416010548661315a90919063ffffffff16565b600c549091506001600160a01b031615611c3857600c546000868152601360205260409081902054905163b6104a1f60e01b8152611be192610c239261271092610b41926001600160a01b039081169263b6104a1f92610bcc9290911690600401613ec6565b600c546000878152601460205260409081902054905163b6104a1f60e01b8152929450611c3592610cd59261271092610b41926001600160a01b039283169263b6104a1f92610c7e92911690600401613ec6565b90505b6000611c56611c478484612ef6565b6003870154610d2f9087612ef6565b60008781526014602052604081205460028801549293509091611c88916001600160a01b0390811691309116856132b3565b9050611ca1610cd5611c9a8686612ef6565b8790613172565b6003870155600087815260146020526040902054600f546002880154611cd8926001600160a01b0391821692908216911687613383565b6000878152601460205260409020546011546002880154611d0a926001600160a01b0391821692908216911686613383565b855460ff19166001178655611d29611d228585612ef6565b8690613172565b86600901819055506001600a6000828254611d449190614d6e565b909155505060008781526015602052604090205460ff1615611da1576000611d6b88612fa9565b6000898152601460205260409020548854919250611d9b9161010090046001600160a01b0390811691168361317e565b50611dd4565b60008781526014602052604090205460018701548754611dd4926001600160a01b0361010090920482169291169061317e565b867f91f28e20f26321cf8a71cadbefe77cfe670ee70b71a621e3ce3fb1b57e19dfaa8388600901548787604051611e0e9493929190614ce5565b60405180910390a2505060016007555050505050565b60095481565b600b546000906001600160a01b03163314611e575760405162461bcd60e51b8152600401610795906147db565b611e6333308a8a6132b3565b9650611e71338a8d8d6132b3565b9950611e7d60086133a4565b6000611e8960086133ad565b905060008611611eab5760405162461bcd60e51b8152600401610795906143c3565b60008711611ecb5760405162461bcd60e51b81526004016107959061497c565b83156120b55760408051808201825285151581526020808201868152600085815260159092528382209251835460ff191690151517835551600190920191909155600d5491516394813dd160e01b815290916001600160a01b0316906394813dd190611f3d9087908690600401614cc1565b60206040518083038186803b158015611f5557600080fd5b505afa158015611f69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f8d9190613dbd565b600d54909150611fab906001600160a01b038c8116911660006133b1565b600d54611fc5906001600160a01b038c811691168b6133b1565b600d54604051625777c560e11b81526001600160a01b039091169062aeef8a90611ff790879086908e90600401614ccf565b600060405180830381600087803b15801561201157600080fd5b505af1158015612025573d6000803e3d6000fd5b5050600d546040516394813dd160e01b81526120b193508492506001600160a01b03909116906394813dd1906120619089908890600401614cc1565b60206040518083038186803b15801561207957600080fd5b505afa15801561208d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d2f9190613dbd565b9850505b60408051610180810190915280600081526020018a6001600160a01b031681526020018981526020018d6001600160a01b031681526020018c815260200142815260200188815260200187815260200186151581526020016121188d8a8a613474565b8152600060208083018290526040928301829052848252601290522081518154829060ff1916600183600381111561216057634e487b7160e01b600052602160045260246000fd5b021790555060208201518160000160016101000a8154816001600160a01b0302191690836001600160a01b031602179055506040820151816001015560608201518160020160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816003015560a0820151816004015560c0820151816005015560e082015181600601556101008201518160070160006101000a81548160ff0219169083151502179055506101208201518160080155610140820151816009015561016082015181600a0160006101000a81548160ff0219169083151502179055509050508c6013600083815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b03160217905550896014600083815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055506001600960008282546122cf9190614d23565b925050819055506001600a60008282546122e99190614d23565b90915550506001600160a01b03808e16600090815260166020908152604080832080546001818101835591855283852001869055938e1683526017825282208054938401815582529020018190556123418d8261349a565b896001600160a01b03168d6001600160a01b0316827f84e32f5898ec9727f1b1e49fde6c9698f87f378486e41939b45597f94aa2f8458f8f8e8e8e8e8e8e8e60405161239599989796959493929190613f64565b60405180910390a49c9b505050505050505050505050565b6123be6123b8612cd2565b83612d44565b6123da5760405162461bcd60e51b815260040161079590614a00565b6123e6848484846134b8565b50505050565b60606123f782612cb5565b6124135760405162461bcd60e51b8152600401610795906148ec565b600061241d6134eb565b9050600081511161243d57604051806020016040528060008152506111a5565b80612447846134fd565b604051602001612458929190613e97565b604051602081830303815290604052915050919050565b6001600160a01b031660009081526017602052604090205490565b6014602052600090815260409020546001600160a01b031681565b600260075414156124c85760405162461bcd60e51b815260040161079590614c2b565b600260075560008181526012602052604090206001815460ff16600381111561250157634e487b7160e01b600052602160045260246000fd5b1461251e5760405162461bcd60e51b815260040161079590614482565b336125288361101f565b6001600160a01b03161461254e5760405162461bcd60e51b8152600401610795906142fe565b6000828152601360205260409020546001600160a01b031633146125845760405162461bcd60e51b8152600401610795906144c6565b61258d82612f02565b805460ff1916600390811782556000838152601360205260409020546009830154918301546125e1926001600160a01b03909216916125cc9190612ef6565b60028401546001600160a01b0316919061317e565b7f722b6f6c8a40111cd707c9533dddac2eedf2d74edcf42495df3d388d081e30c3826040516126109190614cb8565b60405180910390a150506001600755565b600a5481565b601260205260009081526040902080546001820154600283015460038401546004850154600586015460068701546007880154600889015460098a0154600a909a015460ff808b169b610100909b046001600160a01b039081169b9916989381169391168c565b601760205281600052604060002081815481106109d257600080fd5b600c546001600160a01b031681565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6002600754141561270a5760405162461bcd60e51b815260040161079590614c2b565b60026007556000818152601260205260409020600a81015460ff166127415760405162461bcd60e51b815260040161079590614b35565b6000815460ff16600381111561276757634e487b7160e01b600052602160045260246000fd5b146127845760405162461bcd60e51b815260040161079590614146565b6005810154600482015461279791612ef6565b42116127b55760405162461bcd60e51b815260040161079590614a51565b60006127d28260030154836008015461317290919063ffffffff16565b600783015490915060ff161561280e5761280b826003015483600601548460050154611b2f86600401544261317290919063ffffffff16565b90505b600061282b612710610b41600e548561315a90919063ffffffff16565b9050600061284a612710610b416010548661315a90919063ffffffff16565b600c549091506001600160a01b03161561290757600c546000868152601360205260409081902054905163b6104a1f60e01b81526128b092610c239261271092610b41926001600160a01b039081169263b6104a1f92610bcc9290911690600401613ec6565b600c546000878152601460205260409081902054905163b6104a1f60e01b815292945061290492610cd59261271092610b41926001600160a01b039283169263b6104a1f92610c7e92911690600401613ec6565b90505b6000612916611c478484612ef6565b600286015490915060009061293890339030906001600160a01b0316856132b3565b905061294a610cd5611c9a8686612ef6565b6003870155600f546002870154612970916001600160a01b039182169133911687613383565b6011546002870154612991916001600160a01b039182169133911686613383565b855460ff191660011786556129a9611d228585612ef6565b86600901819055506001600a60008282546129c49190614d6e565b909155505060008781526015602052604081205460ff16156129f0576129e988612fa9565b90506129f7565b5060018601545b8654612a129061010090046001600160a01b0316338361317e565b336001600160a01b0316887fdd0091bb00b04f6c6a49ff0ef41a6b5d96194161d064a15fce893c762562ef1383868b600901548a8a604051612a58959493929190614d00565b60405180910390a350506001600755505050505050565b612a77612cd2565b6001600160a01b0316612a88611765565b6001600160a01b031614612aae5760405162461bcd60e51b81526004016107959061486e565b6001600160a01b038116612ad45760405162461bcd60e51b815260040161079590614281565b612add81613261565b50565b612ae8612cd2565b6001600160a01b0316612af9611765565b6001600160a01b031614612b1f5760405162461bcd60e51b81526004016107959061486e565b60026007541415612b425760405162461bcd60e51b815260040161079590614c2b565b60026007556001600160a01b038116612b6d5760405162461bcd60e51b8152600401610795906149b3565b600f80546001600160a01b0319166001600160a01b0383811691909117918290556040517f5ce9b6ed22675a361a041103762e745b21c4da88b0dcb34cf7e15f067f10c8af9261126a921690613ec6565b612bc6612cd2565b6001600160a01b0316612bd7611765565b6001600160a01b031614612bfd5760405162461bcd60e51b81526004016107959061486e565b60026007541415612c205760405162461bcd60e51b815260040161079590614c2b565b60026007556001600160a01b038116612c4b5760405162461bcd60e51b815260040161079590614757565b601180546001600160a01b0319166001600160a01b0383811691909117918290556040517f9682c38ce5f990d8067beb9f4730680a8dbbde4e29c522c11308a9341c88c5bc9261126a921690613ec6565b6001600160e01b031981166301ffc9a760e01b14919050565b6000908152600260205260409020546001600160a01b0316151590565b3390565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190612d0b8261101f565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000612d4f82612cb5565b612d6b5760405162461bcd60e51b815260040161079590614552565b6000612d768361101f565b9050806001600160a01b0316846001600160a01b03161480612db15750836001600160a01b0316612da68461076e565b6001600160a01b0316145b80612dc15750612dc181856126b9565b949350505050565b826001600160a01b0316612ddc8261101f565b6001600160a01b031614612e025760405162461bcd60e51b8152600401610795906148a3565b6001600160a01b038216612e285760405162461bcd60e51b815260040161079590614407565b612e33838383613618565b612e3e600082612cd6565b6001600160a01b0383166000908152600360205260408120805460019290612e67908490614d6e565b90915550506001600160a01b0382166000908152600360205260408120805460019290612e95908490614d23565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60006111a58284614d23565b6000612f0d8261101f565b9050612f1b81600084613618565b612f26600083612cd6565b6001600160a01b0381166000908152600360205260408120805460019290612f4f908490614d6e565b909155505060008281526002602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600081815260126020526040808220805491516370a0823160e01b8152909183916101009091046001600160a01b0316906370a0823190612fee903090600401613ec6565b60206040518083038186803b15801561300657600080fd5b505afa15801561301a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061303e9190613dbd565b600d5460008681526015602052604090819020600101549051630441a3e760e41b81529293506001600160a01b039091169163441a3e7091613084918890600401614cc1565b600060405180830381600087803b15801561309e57600080fd5b505af11580156130b2573d6000803e3d6000fd5b505083546040516370a0823160e01b8152600093506101009091046001600160a01b031691506370a08231906130ec903090600401613ec6565b60206040518083038186803b15801561310457600080fd5b505afa158015613118573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061313c9190613dbd565b90506131488183613172565b60019093018390555090915050919050565b60006111a58284614d4f565b60006111a58284614d3b565b60006111a58284614d6e565b61084d8363a9059cbb60e01b848460405160240161319d929190613f4b565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613660565b6000806131f76301e13380610b4161271081896131f18d8d61315a565b9061315a565b9050600061320986610b41848861315a565b9050831561321a5791506132589050565b600061322789888a613474565b9050806132348a84612ef6565b111561324e57613244818a613172565b9350505050613258565b5091506132589050565b95945050505050565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600080836001600160a01b03166370a08231866040518263ffffffff1660e01b81526004016132e29190613ec6565b60206040518083038186803b1580156132fa57600080fd5b505afa15801561330e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133329190613dbd565b90506133496001600160a01b038516878786613383565b61337981856001600160a01b03166370a08231886040518263ffffffff1660e01b81526004016120619190613ec6565b9695505050505050565b6123e6846323b872dd60e01b85858560405160240161319d93929190613ef4565b80546001019055565b5490565b8015806134395750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e906133e79030908690600401613eda565b60206040518083038186803b1580156133ff57600080fd5b505afa158015613413573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134379190613dbd565b155b6134555760405162461bcd60e51b815260040161079590614c62565b61084d8363095ea7b360e01b848460405160240161319d929190613f4b565b6000612dc1846134946301e13380610b4161271081896131f1878b61315a565b90612ef6565b6134b48282604051806020016040528060008152506136ef565b5050565b6134c3848484612dc9565b6134cf84848484613722565b6123e65760405162461bcd60e51b8152600401610795906141e8565b60408051602081019091526000815290565b60608161352257506040805180820190915260018152600360fc1b60208201526106d7565b8160005b811561354c578061353681614dec565b91506135459050600a83614d3b565b9150613526565b60008167ffffffffffffffff81111561357557634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561359f576020820181803683370190505b5090505b8415612dc1576135b4600183614d6e565b91506135c1600a86614e07565b6135cc906030614d23565b60f81b8183815181106135ef57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350613611600a86614d3b565b94506135a3565b61362383838361084d565b6001600160a01b0382161561084d57600081815260136020526040902080546001600160a01b0384166001600160a01b0319909116179055505050565b60006136b5826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661383a9092919063ffffffff16565b80519091501561084d57808060200190518101906136d39190613d51565b61084d5760405162461bcd60e51b815260040161079590614b8b565b6136f98383613849565b6137066000848484613722565b61084d5760405162461bcd60e51b8152600401610795906141e8565b6000613736846001600160a01b0316613928565b1561383257836001600160a01b031663150b7a02613752612cd2565b8786866040518563ffffffff1660e01b81526004016137749493929190613f18565b602060405180830381600087803b15801561378e57600080fd5b505af19250505080156137be575060408051601f3d908101601f191682019092526137bb91810190613d89565b60015b613818573d8080156137ec576040519150601f19603f3d011682016040523d82523d6000602084013e6137f1565b606091505b5080516138105760405162461bcd60e51b8152600401610795906141e8565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050612dc1565b506001612dc1565b6060612dc1848460008561392e565b6001600160a01b03821661386f5760405162461bcd60e51b8152600401610795906147a6565b61387881612cb5565b156138955760405162461bcd60e51b8152600401610795906142c7565b6138a160008383613618565b6001600160a01b03821660009081526003602052604081208054600192906138ca908490614d23565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b3b151590565b6060824710156139505760405162461bcd60e51b81526004016107959061450c565b61395985613928565b6139755760405162461bcd60e51b815260040161079590614aa1565b600080866001600160a01b031685876040516139919190613e7b565b60006040518083038185875af1925050503d80600081146139ce576040519150601f19603f3d011682016040523d82523d6000602084013e6139d3565b606091505b50915091506139e38282866139ee565b979650505050505050565b606083156139fd5750816111a5565b825115613a0d5782518084602001fd5b8160405162461bcd60e51b81526004016107959190614133565b604080516101808101909152806000815260200160006001600160a01b031681526020016000815260200160006001600160a01b031681526020016000815260200160008152602001600081526020016000815260200160001515815260200160008152602001600081526020016000151581525090565b80356001600160a01b03811681146106d757600080fd5b600060208284031215613ac7578081fd5b6111a582613a9f565b60008060408385031215613ae2578081fd5b613aeb83613a9f565b9150613af960208401613a9f565b90509250929050565b600080600060608486031215613b16578081fd5b613b1f84613a9f565b9250613b2d60208501613a9f565b9150604084013590509250925092565b60008060008060008060008060008060006101608c8e031215613b5e578687fd5b613b678c613a9f565b9a50613b7560208d01613a9f565b995060408c01359850613b8a60608d01613a9f565b9750613b9860808d01613a9f565b965060a08c0135955060c08c0135945060e08c013593506101008c0135613bbe81614e5d565b92506101208c0135613bcf81614e5d565b809250506101408c013590509295989b509295989b9093969950565b60008060008060808587031215613c00578384fd5b613c0985613a9f565b9350613c1760208601613a9f565b925060408501359150606085013567ffffffffffffffff80821115613c3a578283fd5b818701915087601f830112613c4d578283fd5b813581811115613c5f57613c5f614e47565b604051601f8201601f19908116603f01168101908382118183101715613c8757613c87614e47565b816040528281528a6020848701011115613c9f578586fd5b82602086016020830137918201602001949094529598949750929550505050565b60008060408385031215613cd2578182fd5b613cdb83613a9f565b91506020830135613ceb81614e5d565b809150509250929050565b60008060408385031215613d08578182fd5b613d1183613a9f565b946020939093013593505050565b600080600060608486031215613d33578283fd5b613d3c84613a9f565b95602085013595506040909401359392505050565b600060208284031215613d62578081fd5b81516111a581614e5d565b600060208284031215613d7e578081fd5b81356111a581614e6b565b600060208284031215613d9a578081fd5b81516111a581614e6b565b600060208284031215613db6578081fd5b5035919050565b600060208284031215613dce578081fd5b5051919050565b60008060408385031215613de7578182fd5b823591506020830135613ceb81614e5d565b60008060408385031215613e0b578182fd5b50508035926020909101359150565b6001600160a01b03169052565b15159052565b60008151808452613e45816020860160208601614d85565b601f01601f19169290920160200192915050565b60048110613e7757634e487b7160e01b600052602160045260246000fd5b9052565b60008251613e8d818460208701614d85565b9190910192915050565b60008351613ea9818460208801614d85565b835190830190613ebd818360208801614d85565b01949350505050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061337990830184613e2d565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03998a16815260208101989098529590971660408701526060860193909352608085019190915260a0840152151560c083015291151560e08201526101008101919091526101200190565b6040808252835182820181905260009190606090818501906020808901865b83811015614091578151613fea868251613e59565b83810151613ffa85880182613e1a565b5087810151888701528681015161401388880182613e1a565b506080818101519087015260a0808201519087015260c0808201519087015260e080820151908701526101008082015161404f82890182613e27565b505061012081810151908701526101408082015190870152610160908101519061407b81880183613e27565b5050610180949094019390820190600101613fd5565b505095909501959095525092949350505050565b901515815260200190565b9115158252602082015260400190565b61018081016140cf828f613e59565b6001600160a01b039c8d166020830152604082019b909b5298909a166060890152608088019690965260a087019490945260c086019290925260e0850152151561010084015261012083015261014082015291151561016090920191909152919050565b6000602082526111a56020830184613e2d565b6020808252602f908201527f466565644c6f616e286c69717569646174654f6e426568616c66293a204c6f6160408201526e6e206973206e6f742061637469766560881b606082015260800190565b60208082526033908201527f5365745661756c74436f6e74726f6c6c65723a2043616e6e6f74207265706c6160408201527231b2903b30bab63a1031b7b73a3937b63632b960691b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526027908201527f466565644c6f616e286c6971756964617465293a204c6f616e206973206e6f746040820152662061637469766560c81b606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b60208082526025908201527f466565644c6f616e2872656465656d293a2053656e646572206973206e6f742060408201526437bbb732b960d91b606082015260800190565b6020808252601f908201527f5061796261636b3a2053656e646572206973206e6f7420626f72726f77657200604082015260600190565b60208082526029908201527f466565644c6f616e286c6971756964617465293a2053656e646572206973206e60408201526837ba103632b73232b960b91b606082015260800190565b60208082526024908201527f53746172744c6f616e3a20496e7465726573742072617465206973206e6567616040820152637469766560e01b606082015260800190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646040820152637265737360e01b606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b60208082526024908201527f466565644c6f616e2872656465656d293a204c6f616e206973206e6f742072656040820152631c185a5960e21b606082015260800190565b60208082526026908201527f466565644c6f616e2872656465656d293a2053656e646572206973206e6f74206040820152653632b73232b960d11b606082015260800190565b60208082526026908201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6040820152651c8818d85b1b60d21b606082015260800190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252602a908201527f5365745661756c74436f6e74726f6c6c65723a2043616e6e6f74206265207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526028908201527f466565644c6f616e286c6971756964617465293a204c6f616e206973206e6f74604082015267206f76657264756560c01b606082015260800190565b6020808252601b908201527f5061796261636b3a204c6f616e206973206e6f74206163746976650000000000604082015260600190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526029908201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460408201526832b73a103a37b5b2b760b91b606082015260800190565b6020808252602f908201527f536574426f72726f776572466565436f6c6c6563746f723a2043616e6e6f742060408201526e6265207a65726f206164647265737360881b606082015260800190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b60208082526027908201527f466f7262696464656e3a206f6e6c79206465616c206d616e6167657220697320604082015266185b1b1bddd95960ca1b606082015260800190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201526839903737ba1037bbb760b91b606082015260800190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656040820152603960f91b606082015260800190565b6020808252601b908201527f53746172744c6f616e3a204475726174696f6e206973207a65726f0000000000604082015260600190565b6020808252602d908201527f5365744c656e646572466565436f6c6c6563746f723a2043616e6e6f7420626560408201526c207a65726f206164647265737360981b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60208082526030908201527f466565644c6f616e286c69717569646174654f6e426568616c66293a204c6f6160408201526f6e206973206e6f74206f76657264756560801b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b60208082526038908201527f536574426f72726f77657246656542503a206d757374206c657373657220746860408201527f616e206f7220657175616c20746f207468726573686f6c640000000000000000606082015260800190565b60208082526036908201527f466565644c6f616e286c69717569646174654f6e426568616c66293a204c69716040820152751d5a59185d1bdc881a5cc81b9bdd08185b1b1bddd95960521b606082015260800190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b60208082526036908201527f5365744c656e64657246656542503a206d757374206c6573736572207468616e604082015275081bdc88195c5d585b081d1bc81d1a1c995cda1bdb1960521b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526036908201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60408201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606082015260800190565b90815260200190565b918252602082015260400190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b948552602085019390935260408401919091526060830152608082015260a00190565b60008219821115614d3657614d36614e1b565b500190565b600082614d4a57614d4a614e31565b500490565b6000816000190483118215151615614d6957614d69614e1b565b500290565b600082821015614d8057614d80614e1b565b500390565b60005b83811015614da0578181015183820152602001614d88565b838111156123e65750506000910152565b600281046001821680614dc557607f821691505b60208210811415614de657634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415614e0057614e00614e1b565b5060010190565b600082614e1657614e16614e31565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b8015158114612add57600080fd5b6001600160e01b031981168114612add57600080fdfea26469706673582212204f53bbaaaa071d9205e43b49fd980223c0d5b2f501c384cb59fbb87ce640c01664736f6c6343000801003300000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000f9caf713d2468a68ff46ee31a7f4c400d51006e60000000000000000000000003de794678748438861420e78629eafce5893ff47000000000000000000000000d3168abaa522fce2a4fa7d7e60859c78f1592a87000000000000000000000000d3168abaa522fce2a4fa7d7e60859c78f1592a870000000000000000000000000000000000000000000000000000000000000008466565644c6f616e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005664c6f616e000000000000000000000000000000000000000000000000000000

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

00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000f9caf713d2468a68ff46ee31a7f4c400d51006e60000000000000000000000003de794678748438861420e78629eafce5893ff47000000000000000000000000d3168abaa522fce2a4fa7d7e60859c78f1592a87000000000000000000000000d3168abaa522fce2a4fa7d7e60859c78f1592a870000000000000000000000000000000000000000000000000000000000000008466565644c6f616e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005664c6f616e000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : tokenName (string): FeedLoan
Arg [1] : symbol (string): fLoan
Arg [2] : _dealManager (address): 0xf9caf713d2468a68ff46ee31a7f4c400d51006e6
Arg [3] : _feesController (address): 0x3de794678748438861420e78629eafce5893ff47
Arg [4] : _lenderFeeCollector (address): 0xd3168abaa522fce2a4fa7d7e60859c78f1592a87
Arg [5] : _borrowerFeeCollector (address): 0xd3168abaa522fce2a4fa7d7e60859c78f1592a87

-----Encoded View---------------
10 Constructor Arguments found :
Arg [0] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [2] : 000000000000000000000000f9caf713d2468a68ff46ee31a7f4c400d51006e6
Arg [3] : 0000000000000000000000003de794678748438861420e78629eafce5893ff47
Arg [4] : 000000000000000000000000d3168abaa522fce2a4fa7d7e60859c78f1592a87
Arg [5] : 000000000000000000000000d3168abaa522fce2a4fa7d7e60859c78f1592a87
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000008
Arg [7] : 466565644c6f616e000000000000000000000000000000000000000000000000
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [9] : 664c6f616e000000000000000000000000000000000000000000000000000000


Loading