ETH Price: $3,234.10 (-0.63%)
Gas: 1 Gwei

Contract

0x3b6d52e325d66482C9cb86140b6949B3E0E19Cbc
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x60806040160230252022-11-22 4:00:35614 days ago1669089635IN
 Create: Vault
0 ETH0.0545937511.86132804

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Vault

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 35 : Vault.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.9;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "@openzeppelin/contracts/utils/Multicall.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "prb-math/contracts/PRBMathUD60x18.sol";
import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol";

import "./interfaces/IVault.sol";
import "./LPToken.sol";

/**
 * @title Storage for Vault, V1
 */
abstract contract VaultStorageV1 {
    /**************************************************************************/
    /* Structures */
    /**************************************************************************/

    /**
     * @notice Tranche state
     * @param realizedValue Realized value
     * @param pendingRedemptions Pending redemptions
     * @param redemptionQueue Current redemption queue (tail)
     * @param processedRedemptionQueue Processed redemption queue (head)
     * @param pendingReturns Mapping of time bucket to pending returns
     */
    struct Tranche {
        uint256 realizedValue;
        uint256 pendingRedemptions;
        uint256 redemptionQueue;
        uint256 processedRedemptionQueue;
        mapping(uint256 => uint256) pendingReturns;
    }

    /**
     * @notice Loan status
     */
    enum LoanStatus {
        Uninitialized,
        Active,
        Liquidated,
        Complete
    }

    /**
     * @notice Loan state
     * @param status Loan status
     * @param maturityTimeBucket Maturity time bucket
     * @param collateralToken Collateral token contract
     * @param collateralTokenId Collateral token ID
     * @param purchasePrice Purchase price in currency tokens
     * @param repayment Repayment in currency tokens
     * @param seniorTrancheReturn Senior tranche return in currency tokens
     */
    struct Loan {
        LoanStatus status;
        uint64 maturityTimeBucket;
        IERC721 collateralToken;
        uint256 collateralTokenId;
        uint256 purchasePrice;
        uint256 repayment;
        uint256 seniorTrancheReturn;
    }

    /**************************************************************************/
    /* Properties and Linked Contracts */
    /**************************************************************************/

    string internal _name;
    IERC20 internal _currencyToken;
    ILoanPriceOracle internal _loanPriceOracle;
    mapping(address => INoteAdapter) internal _noteAdapters;
    EnumerableSet.AddressSet internal _noteTokens;
    LPToken internal _seniorLPToken;
    LPToken internal _juniorLPToken;

    /**************************************************************************/
    /* Parameters */
    /**************************************************************************/

    /**
     * @dev Senior tranche rate in UD60x18 amount per second
     */
    uint256 internal _seniorTrancheRate;

    /**
     * @dev Admin fee rate in UD60x18 fraction of interest
     */
    uint256 internal _adminFeeRate;

    /**************************************************************************/
    /* State */
    /**************************************************************************/

    Tranche internal _seniorTranche;
    Tranche internal _juniorTranche;
    uint256 internal _totalCashBalance;
    /* _totalLoanBalance is computed at runtime */
    uint256 internal _totalAdminFeeBalance;
    uint256 internal _totalWithdrawalBalance;

    /**
     * @dev Mapping of note token contract to loan ID to loan
     */
    mapping(address => mapping(uint256 => Loan)) internal _loans;

    /**
     * @dev Mapping of maturity time bucket to note token contract to list of loan IDs
     */
    mapping(uint256 => mapping(address => uint256[])) internal _pendingLoans;
}

/**
 * @title Storage for Vault, aggregated
 */
abstract contract VaultStorage is VaultStorageV1 {

}

/**
 * @title Vault
 */
contract Vault is
    Initializable,
    AccessControlUpgradeable,
    PausableUpgradeable,
    ReentrancyGuardUpgradeable,
    VaultStorage,
    ERC721Holder,
    ERC165,
    Multicall,
    KeeperCompatibleInterface,
    IVault
{
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    /**************************************************************************/
    /* Constants */
    /**************************************************************************/

    /**
     * @notice Implementation version
     */
    string public constant IMPLEMENTATION_VERSION = "1.4";

    /**
     * @notice Time bucket duration in seconds
     */
    uint256 public constant TIME_BUCKET_DURATION = 7 days;

    /**
     * @notice Number of share price proration buckets
     */
    uint256 public constant SHARE_PRICE_PRORATION_BUCKETS = 14;

    /**
     * @notice Total share price proration window in seconds
     */
    uint256 public constant TOTAL_SHARE_PRICE_PRORATION_DURATION = TIME_BUCKET_DURATION * SHARE_PRICE_PRORATION_BUCKETS;

    /**
     * @notice One in UD60x18
     */
    uint256 private constant ONE_UD60X18 = 1e18;

    /**************************************************************************/
    /* Access Control Roles */
    /**************************************************************************/

    /**
     * @notice Collateral liquidator role
     */
    bytes32 public constant COLLATERAL_LIQUIDATOR_ROLE = keccak256("COLLATERAL_LIQUIDATOR");

    /**
     * @notice Emergency administrator role
     */
    bytes32 public constant EMERGENCY_ADMIN_ROLE = keccak256("EMERGENCY_ADMIN");

    /**************************************************************************/
    /* Errors */
    /**************************************************************************/

    /**
     * @notice Invalid address (e.g. zero address)
     */
    error InvalidAddress();

    /**
     * @notice Parameter out of bounds
     */
    error ParameterOutOfBounds();

    /**
     * @notice Unsupported token decimals
     */
    error UnsupportedTokenDecimals();

    /**
     * @notice Unsupported note token
     */
    error UnsupportedNoteToken();

    /**
     * @notice Unsupported note parameters
     */
    error UnsupportedNoteParameters();

    /**
     * @notice Insolvent tranche
     */
    error InsolventTranche(TrancheId trancheId);

    /**
     * @notice Purchase price too low
     */
    error PurchasePriceTooLow();

    /**
     * @notice Purchase price too high
     */
    error PurchasePriceTooHigh();

    /**
     * @notice Insufficient cash available
     */
    error InsufficientCashAvailable();

    /**
     * @notice Interest rate too low
     */
    error InterestRateTooLow();

    /**
     * @notice Invalid loan status
     */
    error InvalidLoanStatus();

    /**
     * @notice Loan not repaid
     */
    error LoanNotRepaid();

    /**
     * @notice Loan not expired
     */
    error LoanNotExpired();

    /**
     * @notice Call failed
     */
    error CallFailed();

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

    /**
     * @notice Emitted when senior tranche rate is updated
     * @param rate New senior tranche rate in UD60x18 amount per second
     */
    event SeniorTrancheRateUpdated(uint256 rate);

    /**
     * @notice Emitted when admin fee rate is updated
     * @param rate New admin fee rate in UD60x18 fraction of interest
     */
    event AdminFeeRateUpdated(uint256 rate);

    /**
     * @notice Emitted when loan price oracle contract is updated
     * @param loanPriceOracle New loan price oracle contract
     */
    event LoanPriceOracleUpdated(address loanPriceOracle);

    /**
     * @notice Emitted when note adapter is updated
     * @param noteToken Note token contract
     * @param noteAdapter Note adapter contract
     */
    event NoteAdapterUpdated(address indexed noteToken, address noteAdapter);

    /**
     * @notice Emitted when admin fees are withdrawn
     * @param account Recipient account
     * @param amount Amount of currency tokens withdrawn
     */
    event AdminFeesWithdrawn(address indexed account, uint256 amount);

    /**************************************************************************/
    /* Constructor */
    /**************************************************************************/

    /**
     * @notice Vault constructor (for implementation)
     * @custom:oz-upgrades-unsafe-allow constructor
     */
    constructor() initializer {}

    /**
     * @notice Vault constructor (for proxy)
     * @param name_ Vault name
     * @param currencyToken_ Currency token contract
     * @param loanPriceOracle_ Loan price oracle contract
     * @param seniorLPToken_ Senior LP token contract
     * @param juniorLPToken_ Junior LP token contract
     */
    function initialize(
        string memory name_,
        IERC20 currencyToken_,
        ILoanPriceOracle loanPriceOracle_,
        LPToken seniorLPToken_,
        LPToken juniorLPToken_
    ) external initializer {
        if (address(currencyToken_) == address(0)) revert InvalidAddress();
        if (address(loanPriceOracle_) == address(0)) revert InvalidAddress();
        if (address(seniorLPToken_) == address(0)) revert InvalidAddress();
        if (address(juniorLPToken_) == address(0)) revert InvalidAddress();

        if (IERC20Metadata(address(currencyToken_)).decimals() != 18) revert UnsupportedTokenDecimals();

        __AccessControl_init();
        __Pausable_init();
        __ReentrancyGuard_init();

        _name = name_;
        _currencyToken = currencyToken_;
        _loanPriceOracle = loanPriceOracle_;
        _seniorLPToken = seniorLPToken_;
        _juniorLPToken = juniorLPToken_;

        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(EMERGENCY_ADMIN_ROLE, msg.sender);
    }

    /**************************************************************************/
    /* Interface Getters (defined in IVault) */
    /**************************************************************************/

    /**
     * @inheritdoc IVault
     */
    function name() external view returns (string memory) {
        return _name;
    }

    /**
     * @inheritdoc IVault
     */
    function currencyToken() external view returns (IERC20) {
        return _currencyToken;
    }

    /**
     * @inheritdoc IVault
     */
    function lpToken(TrancheId trancheId) external view returns (IERC20) {
        return IERC20(address(_lpToken(trancheId)));
    }

    /**
     * @inheritdoc IVault
     */
    function loanPriceOracle() external view returns (ILoanPriceOracle) {
        return _loanPriceOracle;
    }

    /**
     * @inheritdoc IVault
     */
    function noteAdapters(address noteToken) external view returns (INoteAdapter) {
        return _noteAdapters[noteToken];
    }

    /**
     * @inheritdoc IVault
     */
    function supportedNoteTokens() external view returns (address[] memory) {
        return _noteTokens.values();
    }

    /**
     * @inheritdoc IVault
     */
    function sharePrice(TrancheId trancheId) external view returns (uint256) {
        return _computeSharePrice(trancheId);
    }

    /**
     * @inheritdoc IVault
     */
    function redemptionSharePrice(TrancheId trancheId) external view returns (uint256) {
        return _computeRedemptionSharePrice(trancheId);
    }

    /**
     * @inheritdoc IVault
     */
    function utilization() external view returns (uint256) {
        return _computeUtilization(0);
    }

    /**
     * @inheritdoc IVault
     */
    function utilization(uint256 additionalLoanBalance) external view returns (uint256) {
        return _computeUtilization(additionalLoanBalance);
    }

    /**************************************************************************/
    /* Additional Getters */
    /**************************************************************************/

    /**
     * @notice Get tranche state
     * @param trancheId Tranche
     * @return realizedValue Realized value
     * @return estimatedValue Estimated value
     * @return pendingRedemptions Pending redemptions
     * @return redemptionQueue Current redemption queue
     * @return processedRedemptionQueue Processed redemption queue
     * @return depositSharePrice Deposit share price in UD60x18
     * @return redemptionSharePrice_ Redemption share price in UD60x18
     */
    function trancheState(TrancheId trancheId)
        external
        view
        returns (
            uint256 realizedValue,
            uint256 estimatedValue,
            uint256 pendingRedemptions,
            uint256 redemptionQueue,
            uint256 processedRedemptionQueue,
            uint256 depositSharePrice,
            uint256 redemptionSharePrice_
        )
    {
        Tranche storage tranche = _trancheState(trancheId);
        return (
            tranche.realizedValue,
            _computeEstimatedValue(trancheId),
            tranche.pendingRedemptions,
            tranche.redemptionQueue,
            tranche.processedRedemptionQueue,
            _computeSharePrice(trancheId),
            _computeRedemptionSharePrice(trancheId)
        );
    }

    /**
     * @notice Get vault balance state
     * @return totalCashBalance Total cash balance
     * @return totalLoanBalance Total loan balance
     * @return totalAdminFeeBalance Total admin fee balance
     * @return totalWithdrawalBalance Total withdrawal balance
     */
    function balanceState()
        external
        view
        returns (
            uint256 totalCashBalance,
            uint256 totalLoanBalance,
            uint256 totalAdminFeeBalance,
            uint256 totalWithdrawalBalance
        )
    {
        return (_totalCashBalance, _totalLoanBalance(), _totalAdminFeeBalance, _totalWithdrawalBalance);
    }

    /**
     * @notice Get Loan state
     * @param noteToken Note token contract
     * @param loanId Loan ID
     * @return Loan state
     */
    function loanState(address noteToken, uint256 loanId) external view returns (Loan memory) {
        return _loans[noteToken][loanId];
    }

    /**
     * @notice Get Pending Loans
     * @param timeBucket Time bucket
     * @param noteToken Note token contract
     * @return Loan IDs
     */
    function pendingLoans(uint64 timeBucket, address noteToken) external view returns (uint256[] memory) {
        return _pendingLoans[uint256(timeBucket)][noteToken];
    }

    /**
     * @notice Get senior tranche rate
     * @return Senior tranche rate in UD60x18 amount per second
     */
    function seniorTrancheRate() external view returns (uint256) {
        return _seniorTrancheRate;
    }

    /**
     * @notice Get admin fee rate
     * @return Admin fee rate in UD60x18 fraction of interest
     */
    function adminFeeRate() external view returns (uint256) {
        return _adminFeeRate;
    }

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

    /**
     * @dev Get LP token contract
     */
    function _lpToken(TrancheId trancheId) internal view returns (LPToken) {
        return (trancheId == TrancheId.Senior) ? _seniorLPToken : _juniorLPToken;
    }

    /**
     * @dev Get tranche state
     */
    function _trancheState(TrancheId trancheId) internal view returns (Tranche storage) {
        return (trancheId == TrancheId.Senior) ? _seniorTranche : _juniorTranche;
    }

    /**
     * @dev Get the total loan balance, computed indirectly from tranche
     * realized values and cash balances
     * @return Total loan balance in UD60x18
     */
    function _totalLoanBalance() internal view returns (uint256) {
        return _seniorTranche.realizedValue + _juniorTranche.realizedValue - _totalCashBalance;
    }

    /**
     * @dev Get and validate the note adapter for a note token
     */
    function _getNoteAdapter(address noteToken) internal view returns (INoteAdapter) {
        INoteAdapter noteAdapter = _noteAdapters[noteToken];

        /* Validate note token is supported */
        if (noteAdapter == INoteAdapter(address(0x0))) revert UnsupportedNoteToken();

        return noteAdapter;
    }

    /**
     * @dev Convert Unix timestamp to time bucket
     */
    function _timestampToTimeBucket(uint256 timestamp) internal pure returns (uint256) {
        return timestamp / TIME_BUCKET_DURATION;
    }

    /**
     * @dev Convert time bucket to Unix timestamp
     */
    function _timeBucketToTimestamp(uint256 timeBucket) internal pure returns (uint256) {
        return timeBucket * TIME_BUCKET_DURATION;
    }

    /**
     * @dev Compute solvent value of the tranche
     * @param trancheId tranche
     * @return Solvent value in currency tokens
     */
    function _computeSolventValue(TrancheId trancheId) internal view returns (uint256) {
        Tranche storage tranche = _trancheState(trancheId);
        return
            tranche.realizedValue > tranche.pendingRedemptions ? tranche.realizedValue - tranche.pendingRedemptions : 0;
    }

    /**
     * @dev Compute estimated value of the tranche, including prorated pending
     * returns
     * @param trancheId tranche
     * @return Estimated value in currency tokens
     */
    function _computeEstimatedValue(TrancheId trancheId) internal view returns (uint256) {
        Tranche storage tranche = _trancheState(trancheId);

        /* Get the current time bucket */
        uint256 currentTimeBucket = _timestampToTimeBucket(block.timestamp);

        /* Compute elapsed time into current time bucket and convert to UD60x18 */
        uint256 elapsedTimeIntoBucket = PRBMathUD60x18.fromUint(
            block.timestamp - _timeBucketToTimestamp(currentTimeBucket)
        );

        /* Sum the prorated returns from pending returns in each time bucket */
        uint256 proratedReturns;
        for (uint256 i; i < SHARE_PRICE_PRORATION_BUCKETS; ++i) {
            /* Prorated Returns[i] = ((Elapsed Time + W * (N - 1 - i)) / (W * N)) * Pending Returns[i]  */
            proratedReturns += PRBMathUD60x18.div(
                PRBMathUD60x18.mul(
                    elapsedTimeIntoBucket +
                        PRBMathUD60x18.fromUint(TIME_BUCKET_DURATION * (SHARE_PRICE_PRORATION_BUCKETS - 1 - i)),
                    tranche.pendingReturns[currentTimeBucket + i]
                ),
                PRBMathUD60x18.fromUint(TOTAL_SHARE_PRICE_PRORATION_DURATION)
            );
        }

        /* Return the realized value plus prorated returns */
        return _computeSolventValue(trancheId) + proratedReturns;
    }

    /**
     * @dev Check if a tranche is solvent
     * @param trancheId tranche
     * @return Tranche is solvent
     */
    function _isSolvent(TrancheId trancheId) internal view returns (bool) {
        Tranche storage tranche = _trancheState(trancheId);
        return tranche.realizedValue > tranche.pendingRedemptions || _lpToken(trancheId).totalSupply() == 0;
    }

    /**
     * @dev Compute share price of tranche including prorated pending returns
     * @param trancheId tranche
     * @return Share price in UD60x18
     */
    function _computeSharePrice(TrancheId trancheId) internal view returns (uint256) {
        uint256 totalSupply = _lpToken(trancheId).totalSupply();
        if (totalSupply == 0) {
            return ONE_UD60X18;
        }
        return PRBMathUD60x18.div(_computeEstimatedValue(trancheId), totalSupply);
    }

    /**
     * @dev Compute redemption share price of tranche
     * @param trancheId tranche
     * @return Redemption share price in UD60x18
     */
    function _computeRedemptionSharePrice(TrancheId trancheId) internal view returns (uint256) {
        uint256 totalSupply = _lpToken(trancheId).totalSupply();
        if (totalSupply == 0) {
            return ONE_UD60X18;
        }
        return PRBMathUD60x18.div(_computeSolventValue(trancheId), totalSupply);
    }

    /**
     * @dev Compute utilization
     * @param additionalLoanBalance Additional loan balance in currency tokens
     * @return Utilization in UD60x18, between 0 and 1
     */
    function _computeUtilization(uint256 additionalLoanBalance) internal view returns (uint256) {
        uint256 totalLoanBalance = _totalLoanBalance();
        uint256 totalBalance = _totalCashBalance + totalLoanBalance;
        return (totalBalance == 0) ? 0 : PRBMathUD60x18.div(totalLoanBalance + additionalLoanBalance, totalBalance);
    }

    /**
     * @dev Process redemptions for tranche
     * @param tranche Tranche
     * @param proceeds Proceeds in currency tokens
     */
    function _processRedemptions(Tranche storage tranche, uint256 proceeds) internal returns (uint256) {
        /* Compute maximum redemption possible */
        uint256 redemptionAmount = Math.min(tranche.realizedValue, Math.min(tranche.pendingRedemptions, proceeds));

        /* Update tranche redemption state */
        tranche.pendingRedemptions -= redemptionAmount;
        tranche.processedRedemptionQueue += redemptionAmount;
        tranche.realizedValue -= redemptionAmount;

        /* Add redemption to withdrawal balance */
        _totalWithdrawalBalance += redemptionAmount;

        /* Return amount of proceeds leftover */
        return proceeds - redemptionAmount;
    }

    /**
     * @dev Process new proceeds by applying them to redemptions and undeployed
     * cash
     * @param proceeds Proceeds in currency tokens
     */
    function _processProceeds(uint256 proceeds) internal {
        /* Process senior redemptions */
        proceeds = _processRedemptions(_seniorTranche, proceeds);
        /* Process junior redemptions */
        proceeds = _processRedemptions(_juniorTranche, proceeds);
        /* Update undeployed cash balance */
        _totalCashBalance += proceeds;
    }

    /**
     * @dev Update tranche state with currency deposit and mint LP tokens to
     * depositer
     * @param trancheId tranche
     * @param amount Amount of currency tokens
     */
    function _deposit(TrancheId trancheId, uint256 amount) internal {
        /* Check tranche is solvent */
        if (!_isSolvent(trancheId)) revert InsolventTranche(trancheId);

        /* Compute current share price */
        uint256 currentSharePrice = _computeSharePrice(trancheId);

        /* Compute number of shares to mint from current tranche share price */
        uint256 shares = PRBMathUD60x18.div(amount, currentSharePrice);

        /* Increase realized value of tranche */
        _trancheState(trancheId).realizedValue += amount;

        /* Process new proceeds */
        _processProceeds(amount);

        /* Mint LP tokens to user */
        _lpToken(trancheId).mint(msg.sender, shares);

        emit Deposited(msg.sender, trancheId, amount, shares);
    }

    /**
     * @dev Calculate purchase price of a loan
     * @param loanInfo Loan info
     */
    function _priceLoan(INoteAdapter.LoanInfo memory loanInfo, INoteAdapter.AssetInfo[] memory collateralAssets)
        internal
        view
        returns (uint256)
    {
        uint256 purchasePrice = 0;

        /* Calculate principal and repayment per asset */
        uint256 collateralCount = PRBMathUD60x18.fromUint(collateralAssets.length);
        uint256 principalPerAsset = PRBMathUD60x18.div(loanInfo.principal, collateralCount);
        uint256 repaymentPerAsset = PRBMathUD60x18.div(loanInfo.repayment, collateralCount);

        /* For each collateral asset */
        for (uint256 i; i < collateralAssets.length; ++i) {
            purchasePrice += _loanPriceOracle.priceLoan(
                collateralAssets[i].token,
                collateralAssets[i].tokenId,
                principalPerAsset,
                repaymentPerAsset,
                loanInfo.duration,
                loanInfo.maturity,
                _computeUtilization(purchasePrice)
            );
        }

        return purchasePrice;
    }

    /**
     * @dev Calculate purchase price of note and update tranche state with note
     * purchase
     * @param noteToken Note token contract
     * @param noteTokenId Note token ID
     * @param minPurchasePrice Minimum purchase price in currency tokens
     */
    function _sellNote(
        address noteToken,
        uint256 noteTokenId,
        uint256 minPurchasePrice
    ) internal returns (uint256) {
        /* Lookup note adapter */
        INoteAdapter noteAdapter = _getNoteAdapter(noteToken);

        /* Check if loan parameters are supported */
        if (!noteAdapter.isSupported(noteTokenId, address(_currencyToken))) revert UnsupportedNoteParameters();

        /* Get loan info */
        INoteAdapter.LoanInfo memory loanInfo = noteAdapter.getLoanInfo(noteTokenId);

        /* Compute loan purchase price */
        uint256 purchasePrice = _priceLoan(loanInfo, noteAdapter.getLoanAssets(noteTokenId));

        /* Validate purchase price */
        if (purchasePrice < minPurchasePrice) revert PurchasePriceTooLow();

        /* Validate repayment */
        if (purchasePrice >= loanInfo.repayment) revert PurchasePriceTooHigh();

        /* Validate cash available */
        if (purchasePrice > _totalCashBalance) revert InsufficientCashAvailable();

        /* Calculate senior tranche contribution based on realized value proportion */
        /* Senior Tranche Contribution = (D_s * Purchase Price) / (D_s + D_j) */
        uint256 seniorTrancheContribution = PRBMathUD60x18.div(
            PRBMathUD60x18.mul(_seniorTranche.realizedValue, purchasePrice),
            _seniorTranche.realizedValue + _juniorTranche.realizedValue
        );

        /* Calculate senior tranche return */
        /* Senior Tranche Return = Senior Tranche Contribution * r * t */
        uint256 seniorTrancheReturn = PRBMathUD60x18.mul(
            seniorTrancheContribution,
            PRBMathUD60x18.mul(_seniorTrancheRate, PRBMathUD60x18.fromUint(loanInfo.maturity - block.timestamp))
        );

        /* Validate senior tranche return */
        if (loanInfo.repayment - purchasePrice < seniorTrancheReturn) revert InterestRateTooLow();

        /* Calculate junior tranche return */
        /* Junior Tranche Return = Repayment - Purchase Price - Senior Tranche Return */
        uint256 juniorTrancheReturn = loanInfo.repayment - purchasePrice - seniorTrancheReturn;

        /* Compute loan maturity time bucket */
        uint256 maturityTimeBucket = _timestampToTimeBucket(loanInfo.maturity);

        /* Schedule pending tranche returns */
        _seniorTranche.pendingReturns[maturityTimeBucket] += seniorTrancheReturn;
        _juniorTranche.pendingReturns[maturityTimeBucket] += juniorTrancheReturn;

        /* Update total cash balance */
        _totalCashBalance -= purchasePrice;

        /* Store loan state */
        Loan storage loan = _loans[noteToken][loanInfo.loanId];
        loan.status = LoanStatus.Active;
        loan.maturityTimeBucket = uint64(maturityTimeBucket);
        loan.collateralToken = IERC721(loanInfo.collateralToken);
        loan.collateralTokenId = loanInfo.collateralTokenId;
        loan.purchasePrice = purchasePrice;
        loan.repayment = loanInfo.repayment;
        loan.seniorTrancheReturn = seniorTrancheReturn;

        /* Add loan to pending loan ids */
        _pendingLoans[maturityTimeBucket][noteToken].push(loanInfo.loanId);

        emit NotePurchased(
            msg.sender,
            noteToken,
            noteTokenId,
            loanInfo.loanId,
            purchasePrice,
            [seniorTrancheContribution, purchasePrice - seniorTrancheContribution]
        );

        return purchasePrice;
    }

    /**************************************************************************/
    /* User API */
    /**************************************************************************/

    /**
     * @inheritdoc IVault
     */
    function deposit(TrancheId trancheId, uint256 amount) external whenNotPaused nonReentrant {
        /* Validate amount */
        if (amount == 0) revert ParameterOutOfBounds();

        /* Deposit into tranche */
        _deposit(trancheId, amount);

        /* Transfer cash from user to vault */
        _currencyToken.safeTransferFrom(msg.sender, address(this), amount);
    }

    /**
     * @inheritdoc IVault
     */
    function priceNote(address noteToken, uint256 noteTokenId) external view returns (uint256) {
        /* Lookup note adapter */
        INoteAdapter noteAdapter = _getNoteAdapter(noteToken);

        /* Check if loan parameters are supported */
        if (!noteAdapter.isSupported(noteTokenId, address(_currencyToken))) revert UnsupportedNoteParameters();

        /* Get loan info */
        INoteAdapter.LoanInfo memory loanInfo = noteAdapter.getLoanInfo(noteTokenId);

        /* Compute loan purchase price */
        return _priceLoan(loanInfo, noteAdapter.getLoanAssets(noteTokenId));
    }

    /**
     * @inheritdoc IVault
     */
    function sellNote(
        address noteToken,
        uint256 noteTokenId,
        uint256 minPurchasePrice
    ) external whenNotPaused nonReentrant returns (uint256) {
        /* Purchase the note */
        uint256 purchasePrice = _sellNote(noteToken, noteTokenId, minPurchasePrice);

        /* Transfer promissory note from user to vault */
        IERC721(noteToken).safeTransferFrom(msg.sender, address(this), noteTokenId);

        /* Transfer cash from vault to user */
        _currencyToken.safeTransfer(msg.sender, purchasePrice);

        return purchasePrice;
    }

    /**
     * @inheritdoc IVault
     */
    function sellNoteAndDeposit(
        address noteToken,
        uint256 noteTokenId,
        uint256 minPurchasePrice,
        uint256[2] calldata allocation
    ) external whenNotPaused nonReentrant returns (uint256) {
        /* Check allocations sum to one */
        if (allocation[0] + allocation[1] != ONE_UD60X18) revert ParameterOutOfBounds();

        /* Purchase the note */
        uint256 purchasePrice = _sellNote(noteToken, noteTokenId, minPurchasePrice);

        /* Calculate split of sale proceeds */
        uint256 seniorTrancheAmount = PRBMathUD60x18.mul(allocation[0], purchasePrice);
        uint256 juniorTrancheAmount = purchasePrice - seniorTrancheAmount;

        /* Deposit sale proceeds in tranches */
        if (seniorTrancheAmount != 0) _deposit(TrancheId.Senior, seniorTrancheAmount);
        if (juniorTrancheAmount != 0) _deposit(TrancheId.Junior, juniorTrancheAmount);

        /* Transfer promissory note from user to vault */
        IERC721(noteToken).safeTransferFrom(msg.sender, address(this), noteTokenId);

        return purchasePrice;
    }

    /**
     * @inheritdoc IVault
     */
    function redeem(TrancheId trancheId, uint256 shares) external whenNotPaused nonReentrant {
        /* Validate shares */
        if (shares == 0) revert ParameterOutOfBounds();

        Tranche storage tranche = _trancheState(trancheId);

        /* Check tranche is solvent */
        if (!_isSolvent(trancheId)) revert InsolventTranche(trancheId);

        /* Compute current redemption share price */
        uint256 currentRedemptionSharePrice = _computeRedemptionSharePrice(trancheId);

        /* Compute redemption amount */
        uint256 redemptionAmount = PRBMathUD60x18.mul(shares, currentRedemptionSharePrice);

        /* Schedule redemption with user's token state and burn LP tokens */
        _lpToken(trancheId).redeem(msg.sender, shares, redemptionAmount, tranche.redemptionQueue);

        /* Schedule redemption in tranche */
        tranche.pendingRedemptions += redemptionAmount;
        tranche.redemptionQueue += redemptionAmount;

        /* Process redemptions from undeployed cash */
        uint256 immediateRedemptionAmount = Math.min(redemptionAmount, _totalCashBalance);
        _totalCashBalance -= immediateRedemptionAmount;
        _processProceeds(immediateRedemptionAmount);

        emit Redeemed(msg.sender, trancheId, shares, redemptionAmount);
    }

    /**
     * @inheritdoc IVault
     */
    function withdraw(TrancheId trancheId, uint256 maxAmount) external whenNotPaused nonReentrant {
        Tranche storage tranche = _trancheState(trancheId);

        /* Calculate amount available to withdraw */
        uint256 amount = Math.min(
            _lpToken(trancheId).redemptionAvailable(msg.sender, tranche.processedRedemptionQueue),
            maxAmount
        );

        if (amount != 0) {
            /* Update user's token state with redemption */
            _lpToken(trancheId).withdraw(msg.sender, amount, tranche.processedRedemptionQueue);

            /* Decrease total withdrawal balance */
            _totalWithdrawalBalance -= amount;

            /* Transfer cash from vault to user */
            _currencyToken.safeTransfer(msg.sender, amount);
        }

        emit Withdrawn(msg.sender, trancheId, amount);
    }

    /**************************************************************************/
    /* Collateral API */
    /**************************************************************************/

    /**
     * @inheritdoc IVault
     */
    function withdrawCollateral(address noteToken, uint256 loanId)
        external
        nonReentrant
        onlyRole(COLLATERAL_LIQUIDATOR_ROLE)
    {
        /* Lookup note adapter */
        INoteAdapter noteAdapter = _getNoteAdapter(noteToken);

        /* Lookup loan state */
        Loan storage loan = _loans[noteToken][loanId];

        /* Validate loan is liquidated */
        if (loan.status != LoanStatus.Liquidated) revert InvalidLoanStatus();

        /* Get unwrap target and calldata */
        (address target, bytes memory data) = noteAdapter.getUnwrapCalldata(loanId);

        /* Call unwrap if required */
        if (target != address(0x0)) {
            (bool success, ) = target.call(data);
            if (!success) revert CallFailed();
        }

        /* Transfer collateral to liquidator */
        loan.collateralToken.safeTransferFrom(address(this), msg.sender, loan.collateralTokenId);

        emit CollateralWithdrawn(noteToken, loanId, address(loan.collateralToken), loan.collateralTokenId, msg.sender);
    }

    /**************************************************************************/
    /* Callbacks */
    /**************************************************************************/

    /**
     * @inheritdoc ILoanReceiver
     */
    function onLoanRepaid(address noteToken, uint256 loanId) public nonReentrant {
        /* Lookup note adapter */
        INoteAdapter noteAdapter = _getNoteAdapter(noteToken);

        /* Lookup loan state */
        Loan storage loan = _loans[noteToken][loanId];

        /* Validate loan is active */
        if (loan.status != LoanStatus.Active) revert InvalidLoanStatus();

        /* Validate loan was repaid */
        if (!noteAdapter.isRepaid(loanId)) revert LoanNotRepaid();

        /* Calculate tranche returns */
        uint256 seniorTrancheReturn = loan.seniorTrancheReturn;
        uint256 juniorTrancheReturn = loan.repayment - loan.purchasePrice - seniorTrancheReturn;

        /* Unschedule pending returns */
        _seniorTranche.pendingReturns[loan.maturityTimeBucket] -= seniorTrancheReturn;
        _juniorTranche.pendingReturns[loan.maturityTimeBucket] -= juniorTrancheReturn;

        /* Calculate and apply admin fee */
        seniorTrancheReturn -= PRBMathUD60x18.mul(_adminFeeRate, seniorTrancheReturn);
        juniorTrancheReturn -= PRBMathUD60x18.mul(_adminFeeRate, juniorTrancheReturn);
        uint256 adminFee = loan.repayment - loan.purchasePrice - seniorTrancheReturn - juniorTrancheReturn;

        /* Increase admin fee balance */
        _totalAdminFeeBalance += adminFee;

        /* Increase tranche realized values */
        _seniorTranche.realizedValue += seniorTrancheReturn;
        _juniorTranche.realizedValue += juniorTrancheReturn;

        /* Process new proceeds */
        _processProceeds(loan.repayment - adminFee);

        /* Mark loan complete */
        loan.status = LoanStatus.Complete;

        emit LoanRepaid(noteToken, loanId, adminFee, [seniorTrancheReturn, juniorTrancheReturn]);
    }

    /**
     * @inheritdoc ILoanReceiver
     */
    function onLoanExpired(address noteToken, uint256 loanId) public nonReentrant {
        /* Lookup note adapter */
        INoteAdapter noteAdapter = _getNoteAdapter(noteToken);

        /* Lookup loan state */
        Loan storage loan = _loans[noteToken][loanId];

        /* Validate loan is active */
        if (loan.status != LoanStatus.Active) revert InvalidLoanStatus();

        /* Validate loan is not repaid and expired */
        if (noteAdapter.isRepaid(loanId) || !noteAdapter.isExpired(loanId)) revert LoanNotExpired();

        /* Calculate tranche returns */
        uint256 seniorTrancheReturn = loan.seniorTrancheReturn;
        uint256 juniorTrancheReturn = loan.repayment - loan.purchasePrice - seniorTrancheReturn;

        /* Unschedule pending returns */
        _seniorTranche.pendingReturns[loan.maturityTimeBucket] -= seniorTrancheReturn;
        _juniorTranche.pendingReturns[loan.maturityTimeBucket] -= juniorTrancheReturn;

        /* Compute tranche losses */
        uint256 juniorTrancheLoss = Math.min(loan.purchasePrice, _juniorTranche.realizedValue);
        uint256 seniorTrancheLoss = loan.purchasePrice - juniorTrancheLoss;

        /* Decrease tranche realized values */
        _seniorTranche.realizedValue -= seniorTrancheLoss;
        _juniorTranche.realizedValue -= juniorTrancheLoss;

        /* Update senior tranche return for collateral liquidation */
        loan.seniorTrancheReturn += seniorTrancheLoss;

        /* Mark loan liquidated in loan state */
        loan.status = LoanStatus.Liquidated;

        /* Get liquidate target and calldata */
        (address target, bytes memory data) = noteAdapter.getLiquidateCalldata(loanId);
        if (target == address(0x0)) revert InvalidAddress();

        /* Call liquidate on lending platform */
        (bool success, ) = target.call(data);
        if (!success) revert CallFailed();

        emit LoanLiquidated(noteToken, loanId, [seniorTrancheLoss, juniorTrancheLoss]);
    }

    /**
     * @inheritdoc IVault
     */
    function onCollateralLiquidated(
        address noteToken,
        uint256 loanId,
        uint256 proceeds
    ) external nonReentrant onlyRole(COLLATERAL_LIQUIDATOR_ROLE) {
        /* Lookup loan state */
        Loan storage loan = _loans[noteToken][loanId];

        /* Validate loan is liquidated */
        if (loan.status != LoanStatus.Liquidated) revert InvalidLoanStatus();

        /* Compute tranche repayments */
        uint256 seniorTrancheRepayment = Math.min(proceeds, loan.seniorTrancheReturn);
        uint256 juniorTrancheRepayment = proceeds - seniorTrancheRepayment;

        /* Increase tranche realized values */
        _seniorTranche.realizedValue += seniorTrancheRepayment;
        _juniorTranche.realizedValue += juniorTrancheRepayment;

        /* Process proceeds */
        _processProceeds(proceeds);

        /* Mark loan complete */
        loan.status = LoanStatus.Complete;

        /* Transfer cash from liquidator to vault */
        _currencyToken.safeTransferFrom(msg.sender, address(this), proceeds);

        emit CollateralLiquidated(noteToken, loanId, [seniorTrancheRepayment, juniorTrancheRepayment]);
    }

    /**************************************************************************/
    /* Keeper Integration */
    /**************************************************************************/

    /**
     * @inheritdoc KeeperCompatibleInterface
     */
    function checkUpkeep(bytes calldata) external view returns (bool, bytes memory) {
        /* Compute current time bucket */
        uint256 currentTimeBucket = _timestampToTimeBucket(block.timestamp);

        /* For each note token */
        uint256 numNoteTokens = _noteTokens.length();
        for (uint256 i; i < numNoteTokens; ++i) {
            /* Get note token */
            address noteToken = _noteTokens.at(i);

            /* Lookup note adapter */
            INoteAdapter noteAdapter = _getNoteAdapter(noteToken);

            /* Check previous, current, and future time buckets */
            for (
                uint256 timeBucket = currentTimeBucket - 1;
                timeBucket < currentTimeBucket + SHARE_PRICE_PRORATION_BUCKETS;
                timeBucket++
            ) {
                /* For each loan ID */
                uint256 numLoans = _pendingLoans[timeBucket][noteToken].length;
                for (uint256 j; j < numLoans; ++j) {
                    /* Get loan ID */
                    uint256 loanId = _pendingLoans[timeBucket][noteToken][j];

                    /* Lookup loan state */
                    Loan memory loan = _loans[noteToken][loanId];

                    /* Make sure loan is active */
                    if (loan.status != LoanStatus.Active) {
                        continue;
                    } else if (noteAdapter.isRepaid(loanId)) {
                        /* Call onLoanRepaid() */
                        return (true, abi.encode(uint8(0), noteToken, loanId));
                    } else if (noteAdapter.isExpired(loanId)) {
                        /* Call onLoanExpired() */
                        return (true, abi.encode(uint8(1), noteToken, loanId));
                    }
                }
            }
        }

        return (false, "");
    }

    /**
     * @inheritdoc KeeperCompatibleInterface
     */
    function performUpkeep(bytes calldata performData) external {
        (uint8 code, address noteToken, uint256 loanId) = abi.decode(performData, (uint8, address, uint256));

        /* Call appropriate callback based on code */
        if (code == 0) {
            onLoanRepaid(noteToken, loanId);
        } else if (code == 1) {
            onLoanExpired(noteToken, loanId);
        } else {
            revert ParameterOutOfBounds();
        }
    }

    /**************************************************************************/
    /* Setters */
    /**************************************************************************/

    /**
     * @notice Set the senior tranche rate
     *
     * Emits a {SeniorTrancheRateUpdated} event.
     *
     * @param rate Rate in UD60x18 amount per second
     */
    function setSeniorTrancheRate(uint256 rate) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (rate == 0 || rate >= ONE_UD60X18) revert ParameterOutOfBounds();
        _seniorTrancheRate = rate;
        emit SeniorTrancheRateUpdated(rate);
    }

    /**
     * @notice Set the admin fee rate
     *
     * Emits a {AdminFeeRateUpdated} event.
     *
     * @param rate Rate in UD60x18 fraction of interest
     */
    function setAdminFeeRate(uint256 rate) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (rate == 0 || rate >= ONE_UD60X18) revert ParameterOutOfBounds();
        _adminFeeRate = rate;
        emit AdminFeeRateUpdated(rate);
    }

    /**
     * @notice Set the loan price oracle contract
     *
     * Emits a {LoanPriceOracleUpdated} event.
     *
     * @param loanPriceOracle_ Loan price oracle contract
     */
    function setLoanPriceOracle(address loanPriceOracle_) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (loanPriceOracle_ == address(0)) revert InvalidAddress();
        _loanPriceOracle = ILoanPriceOracle(loanPriceOracle_);
        emit LoanPriceOracleUpdated(loanPriceOracle_);
    }

    /**
     * @notice Set note adapter contract
     *
     * Emits a {NoteAdapterUpdated} event.
     *
     * @param noteToken Note token contract
     * @param noteAdapter Note adapter contract
     */
    function setNoteAdapter(address noteToken, address noteAdapter) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (noteToken == address(0)) revert InvalidAddress();
        _noteAdapters[noteToken] = INoteAdapter(noteAdapter);
        if (noteAdapter != address(0)) {
            _noteTokens.add(noteToken);
        } else {
            _noteTokens.remove(noteToken);
        }
        emit NoteAdapterUpdated(noteToken, noteAdapter);
    }

    /**
     * @notice Pause contract
     */
    function pause() external onlyRole(EMERGENCY_ADMIN_ROLE) {
        _pause();
    }

    /**
     * @notice Unpause contract
     */
    function unpause() external onlyRole(EMERGENCY_ADMIN_ROLE) {
        _unpause();
    }

    /**************************************************************************/
    /* Admin Fees API */
    /**************************************************************************/

    /**
     * @notice Withdraw admin fees
     *
     * Emits a {AdminFeesWithdrawn} event.
     *
     * @param recipient Recipient account
     * @param amount Amount to withdraw
     */
    function withdrawAdminFees(address recipient, uint256 amount) external nonReentrant onlyRole(DEFAULT_ADMIN_ROLE) {
        if (recipient == address(0)) revert InvalidAddress();
        if (amount > _totalAdminFeeBalance) revert ParameterOutOfBounds();

        /* Update admin fees balance */
        _totalAdminFeeBalance -= amount;

        /* Transfer cash from vault to recipient */
        _currencyToken.safeTransfer(recipient, amount);

        emit AdminFeesWithdrawn(recipient, amount);
    }

    /******************************************************/
    /* ERC165 interface */
    /******************************************************/

    /**
     * @inheritdoc IERC165
     */
    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(AccessControlUpgradeable, ERC165)
        returns (bool)
    {
        return
            interfaceId == type(IAccessControlUpgradeable).interfaceId ||
            interfaceId == type(IERC721Receiver).interfaceId ||
            interfaceId == type(ILoanReceiver).interfaceId ||
            interfaceId == type(KeeperCompatibleInterface).interfaceId ||
            super.supportsInterface(interfaceId);
    }
}

File 2 of 35 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 3 of 35 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role, _msgSender());
        _;
    }

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

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(uint160(account), 20),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 4 of 35 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

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

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

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

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

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

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 5 of 35 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @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 ReentrancyGuardUpgradeable is Initializable {
    // 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;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 6 of 35 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)

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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

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

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

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

    /**
     * @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 7 of 35 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

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 8 of 35 : ERC721Holder.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)

pragma solidity ^0.8.0;

import "../IERC721Receiver.sol";

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

File 9 of 35 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 10 of 35 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastvalue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastvalue;
                // Update the index for the moved value
                set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        assembly {
            result := store
        }

        return result;
    }
}

File 11 of 35 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

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 12 of 35 : Multicall.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Multicall.sol)

pragma solidity ^0.8.0;

import "./Address.sol";

/**
 * @dev Provides a function to batch together multiple calls in a single external call.
 *
 * _Available since v4.1._
 */
abstract contract Multicall {
    /**
     * @dev Receives and executes a batch of function calls on this contract.
     */
    function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            results[i] = Address.functionDelegateCall(address(this), data[i]);
        }
        return results;
    }
}

File 13 of 35 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

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

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

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

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

File 14 of 35 : PRBMathUD60x18.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

import "./PRBMath.sol";

/// @title PRBMathUD60x18
/// @author Paul Razvan Berg
/// @notice Smart contract library for advanced fixed-point math that works with uint256 numbers considered to have 18
/// trailing decimals. We call this number representation unsigned 60.18-decimal fixed-point, since there can be up to 60
/// digits in the integer part and up to 18 decimals in the fractional part. The numbers are bound by the minimum and the
/// maximum values permitted by the Solidity type uint256.
library PRBMathUD60x18 {
    /// @dev Half the SCALE number.
    uint256 internal constant HALF_SCALE = 5e17;

    /// @dev log2(e) as an unsigned 60.18-decimal fixed-point number.
    uint256 internal constant LOG2_E = 1_442695040888963407;

    /// @dev The maximum value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_584007913129639935;

    /// @dev The maximum whole value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_WHOLE_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_000000000000000000;

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @notice Calculates the arithmetic average of x and y, rounding down.
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number.
    function avg(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // The operations can never overflow.
        unchecked {
            // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need
            // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice.
            result = (x >> 1) + (y >> 1) + (x & y & 1);
        }
    }

    /// @notice Yields the least unsigned 60.18 decimal fixed-point number greater than or equal to x.
    ///
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    ///
    /// Requirements:
    /// - x must be less than or equal to MAX_WHOLE_UD60x18.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number to ceil.
    /// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function ceil(uint256 x) internal pure returns (uint256 result) {
        if (x > MAX_WHOLE_UD60x18) {
            revert PRBMathUD60x18__CeilOverflow(x);
        }
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "SCALE - remainder" but faster.
            let delta := sub(SCALE, remainder)

            // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster.
            result := add(x, mul(delta, gt(remainder, 0)))
        }
    }

    /// @notice Divides two unsigned 60.18-decimal fixed-point numbers, returning a new unsigned 60.18-decimal fixed-point number.
    ///
    /// @dev Uses mulDiv to enable overflow-safe multiplication and division.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    ///
    /// @param x The numerator as an unsigned 60.18-decimal fixed-point number.
    /// @param y The denominator as an unsigned 60.18-decimal fixed-point number.
    /// @param result The quotient as an unsigned 60.18-decimal fixed-point number.
    function div(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDiv(x, SCALE, y);
    }

    /// @notice Returns Euler's number as an unsigned 60.18-decimal fixed-point number.
    /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant).
    function e() internal pure returns (uint256 result) {
        result = 2_718281828459045235;
    }

    /// @notice Calculates the natural exponent of x.
    ///
    /// @dev Based on the insight that e^x = 2^(x * log2(e)).
    ///
    /// Requirements:
    /// - All from "log2".
    /// - x must be less than 133.084258667509499441.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp(uint256 x) internal pure returns (uint256 result) {
        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133_084258667509499441) {
            revert PRBMathUD60x18__ExpInputTooBig(x);
        }

        // Do the fixed-point multiplication inline to save gas.
        unchecked {
            uint256 doubleScaleProduct = x * LOG2_E;
            result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE);
        }
    }

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    ///
    /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
    ///
    /// Requirements:
    /// - x must be 192 or less.
    /// - The result must fit within MAX_UD60x18.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
        if (x >= 192e18) {
            revert PRBMathUD60x18__Exp2InputTooBig(x);
        }

        unchecked {
            // Convert x to the 192.64-bit fixed-point format.
            uint256 x192x64 = (x << 64) / SCALE;

            // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation.
            result = PRBMath.exp2(x192x64);
        }
    }

    /// @notice Yields the greatest unsigned 60.18 decimal fixed-point number less than or equal to x.
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    /// @param x The unsigned 60.18-decimal fixed-point number to floor.
    /// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function floor(uint256 x) internal pure returns (uint256 result) {
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster.
            result := sub(x, mul(remainder, gt(remainder, 0)))
        }
    }

    /// @notice Yields the excess beyond the floor of x.
    /// @dev Based on the odd function definition https://en.wikipedia.org/wiki/Fractional_part.
    /// @param x The unsigned 60.18-decimal fixed-point number to get the fractional part of.
    /// @param result The fractional part of x as an unsigned 60.18-decimal fixed-point number.
    function frac(uint256 x) internal pure returns (uint256 result) {
        assembly {
            result := mod(x, SCALE)
        }
    }

    /// @notice Converts a number from basic integer form to unsigned 60.18-decimal fixed-point representation.
    ///
    /// @dev Requirements:
    /// - x must be less than or equal to MAX_UD60x18 divided by SCALE.
    ///
    /// @param x The basic integer to convert.
    /// @param result The same number in unsigned 60.18-decimal fixed-point representation.
    function fromUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__FromUintOverflow(x);
            }
            result = x * SCALE;
        }
    }

    /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down.
    ///
    /// @dev Requirements:
    /// - x * y must fit within MAX_UD60x18, lest it overflows.
    ///
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function gm(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        unchecked {
            // Checking for overflow this way is faster than letting Solidity do it.
            uint256 xy = x * y;
            if (xy / x != y) {
                revert PRBMathUD60x18__GmOverflow(x, y);
            }

            // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE
            // during multiplication. See the comments within the "sqrt" function.
            result = PRBMath.sqrt(xy);
        }
    }

    /// @notice Calculates 1 / x, rounding toward zero.
    ///
    /// @dev Requirements:
    /// - x cannot be zero.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the inverse.
    /// @return result The inverse as an unsigned 60.18-decimal fixed-point number.
    function inv(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // 1e36 is SCALE * SCALE.
            result = 1e36 / x;
        }
    }

    /// @notice Calculates the natural logarithm of x.
    ///
    /// @dev Based on the insight that ln(x) = log2(x) / log2(e).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    /// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm.
    /// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number.
    function ln(uint256 x) internal pure returns (uint256 result) {
        // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x)
        // can return is 196205294292027477728.
        unchecked {
            result = (log2(x) * SCALE) / LOG2_E;
        }
    }

    /// @notice Calculates the common logarithm of x.
    ///
    /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common
    /// logarithm based on the insight that log10(x) = log2(x) / log2(10).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the common logarithm.
    /// @return result The common logarithm as an unsigned 60.18-decimal fixed-point number.
    function log10(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }

        // Note that the "mul" in this block is the assembly multiplication operation, not the "mul" function defined
        // in this contract.
        // prettier-ignore
        assembly {
            switch x
            case 1 { result := mul(SCALE, sub(0, 18)) }
            case 10 { result := mul(SCALE, sub(1, 18)) }
            case 100 { result := mul(SCALE, sub(2, 18)) }
            case 1000 { result := mul(SCALE, sub(3, 18)) }
            case 10000 { result := mul(SCALE, sub(4, 18)) }
            case 100000 { result := mul(SCALE, sub(5, 18)) }
            case 1000000 { result := mul(SCALE, sub(6, 18)) }
            case 10000000 { result := mul(SCALE, sub(7, 18)) }
            case 100000000 { result := mul(SCALE, sub(8, 18)) }
            case 1000000000 { result := mul(SCALE, sub(9, 18)) }
            case 10000000000 { result := mul(SCALE, sub(10, 18)) }
            case 100000000000 { result := mul(SCALE, sub(11, 18)) }
            case 1000000000000 { result := mul(SCALE, sub(12, 18)) }
            case 10000000000000 { result := mul(SCALE, sub(13, 18)) }
            case 100000000000000 { result := mul(SCALE, sub(14, 18)) }
            case 1000000000000000 { result := mul(SCALE, sub(15, 18)) }
            case 10000000000000000 { result := mul(SCALE, sub(16, 18)) }
            case 100000000000000000 { result := mul(SCALE, sub(17, 18)) }
            case 1000000000000000000 { result := 0 }
            case 10000000000000000000 { result := SCALE }
            case 100000000000000000000 { result := mul(SCALE, 2) }
            case 1000000000000000000000 { result := mul(SCALE, 3) }
            case 10000000000000000000000 { result := mul(SCALE, 4) }
            case 100000000000000000000000 { result := mul(SCALE, 5) }
            case 1000000000000000000000000 { result := mul(SCALE, 6) }
            case 10000000000000000000000000 { result := mul(SCALE, 7) }
            case 100000000000000000000000000 { result := mul(SCALE, 8) }
            case 1000000000000000000000000000 { result := mul(SCALE, 9) }
            case 10000000000000000000000000000 { result := mul(SCALE, 10) }
            case 100000000000000000000000000000 { result := mul(SCALE, 11) }
            case 1000000000000000000000000000000 { result := mul(SCALE, 12) }
            case 10000000000000000000000000000000 { result := mul(SCALE, 13) }
            case 100000000000000000000000000000000 { result := mul(SCALE, 14) }
            case 1000000000000000000000000000000000 { result := mul(SCALE, 15) }
            case 10000000000000000000000000000000000 { result := mul(SCALE, 16) }
            case 100000000000000000000000000000000000 { result := mul(SCALE, 17) }
            case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) }
            case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) }
            case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) }
            case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) }
            case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) }
            case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) }
            case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) }
            case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) }
            case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) }
            case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) }
            case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) }
            case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) }
            case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) }
            case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) }
            case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) }
            case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) }
            case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) }
            case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) }
            case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) }
            case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) }
            case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) }
            case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) }
            case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) }
            case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) }
            case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) }
            case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) }
            case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) }
            case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) }
            case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) }
            case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) }
            case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) }
            case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) }
            case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 59) }
            default {
                result := MAX_UD60x18
            }
        }

        if (result == MAX_UD60x18) {
            // Do the fixed-point division inline to save gas. The denominator is log2(10).
            unchecked {
                result = (log2(x) * SCALE) / 3_321928094887362347;
            }
        }
    }

    /// @notice Calculates the binary logarithm of x.
    ///
    /// @dev Based on the iterative approximation algorithm.
    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
    ///
    /// Requirements:
    /// - x must be greater than or equal to SCALE, otherwise the result would be negative.
    ///
    /// Caveats:
    /// - The results are nor perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the binary logarithm.
    /// @return result The binary logarithm as an unsigned 60.18-decimal fixed-point number.
    function log2(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }
        unchecked {
            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).
            uint256 n = PRBMath.mostSignificantBit(x / SCALE);

            // The integer part of the logarithm as an unsigned 60.18-decimal fixed-point number. The operation can't overflow
            // because n is maximum 255 and SCALE is 1e18.
            result = n * SCALE;

            // This is y = x * 2^(-n).
            uint256 y = x >> n;

            // If y = 1, the fractional part is zero.
            if (y == SCALE) {
                return result;
            }

            // Calculate the fractional part via the iterative approximation.
            // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster.
            for (uint256 delta = HALF_SCALE; delta > 0; delta >>= 1) {
                y = (y * y) / SCALE;

                // Is y^2 > 2 and so in the range [2,4)?
                if (y >= 2 * SCALE) {
                    // Add the 2^(-m) factor to the logarithm.
                    result += delta;

                    // Corresponds to z/2 on Wikipedia.
                    y >>= 1;
                }
            }
        }
    }

    /// @notice Multiplies two unsigned 60.18-decimal fixed-point numbers together, returning a new unsigned 60.18-decimal
    /// fixed-point number.
    /// @dev See the documentation for the "PRBMath.mulDivFixedPoint" function.
    /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
    /// @return result The product as an unsigned 60.18-decimal fixed-point number.
    function mul(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDivFixedPoint(x, y);
    }

    /// @notice Returns PI as an unsigned 60.18-decimal fixed-point number.
    function pi() internal pure returns (uint256 result) {
        result = 3_141592653589793238;
    }

    /// @notice Raises x to the power of y.
    ///
    /// @dev Based on the insight that x^y = 2^(log2(x) * y).
    ///
    /// Requirements:
    /// - All from "exp2", "log2" and "mul".
    ///
    /// Caveats:
    /// - All from "exp2", "log2" and "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number.
    /// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number.
    /// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number.
    function pow(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            result = y == 0 ? SCALE : uint256(0);
        } else {
            result = exp2(mul(log2(x), y));
        }
    }

    /// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
    /// famous algorithm "exponentiation by squaring".
    ///
    /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
    ///
    /// Requirements:
    /// - The result must fit within MAX_UD60x18.
    ///
    /// Caveats:
    /// - All from "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x The base as an unsigned 60.18-decimal fixed-point number.
    /// @param y The exponent as an uint256.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function powu(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // Calculate the first iteration of the loop in advance.
        result = y & 1 > 0 ? x : SCALE;

        // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster.
        for (y >>= 1; y > 0; y >>= 1) {
            x = PRBMath.mulDivFixedPoint(x, x);

            // Equivalent to "y % 2 == 1" but faster.
            if (y & 1 > 0) {
                result = PRBMath.mulDivFixedPoint(result, x);
            }
        }
    }

    /// @notice Returns 1 as an unsigned 60.18-decimal fixed-point number.
    function scale() internal pure returns (uint256 result) {
        result = SCALE;
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Requirements:
    /// - x must be less than MAX_UD60x18 / SCALE.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root.
    /// @return result The result as an unsigned 60.18-decimal fixed-point .
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__SqrtOverflow(x);
            }
            // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned
            // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root).
            result = PRBMath.sqrt(x * SCALE);
        }
    }

    /// @notice Converts a unsigned 60.18-decimal fixed-point number to basic integer form, rounding down in the process.
    /// @param x The unsigned 60.18-decimal fixed-point number to convert.
    /// @return result The same number in basic integer form.
    function toUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            result = x / SCALE;
        }
    }
}

File 15 of 35 : KeeperCompatibleInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface KeeperCompatibleInterface {
  /**
   * @notice method that is simulated by the keepers to see if any work actually
   * needs to be performed. This method does does not actually need to be
   * executable, and since it is only ever simulated it can consume lots of gas.
   * @dev To ensure that it is never called, you may want to add the
   * cannotExecute modifier from KeeperBase to your implementation of this
   * method.
   * @param checkData specified in the upkeep registration so it is always the
   * same for a registered upkeep. This can easily be broken down into specific
   * arguments using `abi.decode`, so multiple upkeeps can be registered on the
   * same contract and easily differentiated by the contract.
   * @return upkeepNeeded boolean to indicate whether the keeper should call
   * performUpkeep or not.
   * @return performData bytes that the keeper should call performUpkeep with, if
   * upkeep is needed. If you would like to encode data to decode later, try
   * `abi.encode`.
   */
  function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData);

  /**
   * @notice method that is actually executed by the keepers, via the registry.
   * The data returned by the checkUpkeep simulation will be passed into
   * this method to actually be executed.
   * @dev The input to this method should not be trusted, and the caller of the
   * method should not even be restricted to any single registry. Anyone should
   * be able call it, and the input should be validated, there is no guarantee
   * that the data passed in is the performData returned from checkUpkeep. This
   * could happen due to malicious keepers, racing keepers, or simply a state
   * change while the performUpkeep transaction is waiting for confirmation.
   * Always validate the data passed in.
   * @param performData is the data which was passed back from the checkData
   * simulation. If it is encoded, it can easily be decoded into other types by
   * calling `abi.decode`. This data should not be trusted, and should be
   * validated against the contract's current state.
   */
  function performUpkeep(bytes calldata performData) external;
}

File 16 of 35 : IVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "./ILoanPriceOracle.sol";
import "./INoteAdapter.sol";
import "./ILoanReceiver.sol";

/**
 * @title Interface to a Vault
 */
interface IVault is ILoanReceiver {
    /**************************************************************************/
    /* Enums */
    /**************************************************************************/

    /**
     * @notice Tranche identifier
     */
    enum TrancheId {
        Senior,
        Junior
    }

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

    /**
     * @notice Emitted when currency is deposited
     * @param account Depositing account
     * @param trancheId Tranche
     * @param amount Amount of currency tokens
     * @param shares Amount of LP tokens minted
     */
    event Deposited(address indexed account, TrancheId indexed trancheId, uint256 amount, uint256 shares);

    /**
     * @notice Emitted when a note is purchased
     * @param account Selling account
     * @param noteToken Note token contract
     * @param noteTokenId Note token ID
     * @param loanId Loan ID
     * @param purchasePrice Purchase price in currency tokens
     * @param trancheContributions Tranche contributions in currency tokens
     */
    event NotePurchased(
        address indexed account,
        address indexed noteToken,
        uint256 noteTokenId,
        uint256 indexed loanId,
        uint256 purchasePrice,
        uint256[2] trancheContributions
    );

    /**
     * @notice Emitted when LP tokens are redeemed
     * @param account Redeeming account
     * @param trancheId Tranche
     * @param shares Amount of LP tokens burned
     * @param amount Amount of currency tokens
     */
    event Redeemed(address indexed account, TrancheId indexed trancheId, uint256 shares, uint256 amount);

    /**
     * @notice Emitted when redeemed currency tokens are withdrawn
     * @param account Withdrawing account
     * @param trancheId Tranche
     * @param amount Amount of currency tokens withdrawn
     */
    event Withdrawn(address indexed account, TrancheId indexed trancheId, uint256 amount);

    /**
     * @notice Emitted when liquidated loan collateral is withdrawn
     * @param noteToken Note token contract
     * @param loanId Loan ID
     * @param collateralToken Collateral token contract
     * @param collateralTokenId Collateral token ID
     * @param collateralLiquidator Collateral liquidator contract
     */
    event CollateralWithdrawn(
        address indexed noteToken,
        uint256 indexed loanId,
        address collateralToken,
        uint256 collateralTokenId,
        address collateralLiquidator
    );

    /**
     * @notice Emitted when loan is repaid
     * @param noteToken Note token contract
     * @param loanId Loan ID
     * @param adminFee Admin fee in currency tokens
     * @param trancheReturns Tranches returns in currency tokens
     */
    event LoanRepaid(address indexed noteToken, uint256 indexed loanId, uint256 adminFee, uint256[2] trancheReturns);

    /**
     * @notice Emitted when loan is liquidated
     * @param noteToken Note token contract
     * @param loanId Loan ID
     * @param trancheLosses Tranche losses in currency tokens
     */
    event LoanLiquidated(address indexed noteToken, uint256 indexed loanId, uint256[2] trancheLosses);

    /**
     * @notice Emitted when collateral is liquidated
     * @param noteToken Note token contract
     * @param loanId Loan ID
     * @param trancheReturns Tranches returns in currency tokens
     */
    event CollateralLiquidated(address indexed noteToken, uint256 indexed loanId, uint256[2] trancheReturns);

    /**************************************************************************/
    /* Getters */
    /**************************************************************************/

    /**
     * @notice Get vault name
     * @return Vault name
     */
    function name() external view returns (string memory);

    /**
     * @notice Get currency token
     * @return Currency token contract
     */
    function currencyToken() external view returns (IERC20);

    /**
     * @notice Get LP token
     * @param trancheId Tranche
     * @return LP token contract
     */
    function lpToken(TrancheId trancheId) external view returns (IERC20);

    /**
     * @notice Get loan price oracle
     * @return Loan price oracle contract
     */
    function loanPriceOracle() external view returns (ILoanPriceOracle);

    /**
     * @notice Get note adapter contract
     * @param noteToken Note token contract
     * @return Note adapter contract
     */
    function noteAdapters(address noteToken) external view returns (INoteAdapter);

    /**
     * @notice Get list of supported note tokens
     * @return List of note token addresses
     */
    function supportedNoteTokens() external view returns (address[] memory);

    /**
     * @notice Get share price
     * @param trancheId Tranche
     * @return Share price in UD60x18
     */
    function sharePrice(TrancheId trancheId) external view returns (uint256);

    /**
     * @notice Get redemption share price
     * @param trancheId Tranche
     * @return Redemption share price in UD60x18
     */
    function redemptionSharePrice(TrancheId trancheId) external view returns (uint256);

    /**
     * @notice Get utilization
     * @return Utilization in UD60x18, between 0 to 1
     */
    function utilization() external view returns (uint256);

    /**
     * @notice Get utilization with added loan balanace
     * @param additionalLoanBalance Additional loan balance in currency tokens
     * @return Utilization in UD60x18, between 0 to 1
     */
    function utilization(uint256 additionalLoanBalance) external view returns (uint256);

    /**************************************************************************/
    /* User API */
    /**************************************************************************/

    /**
     * @notice Deposit currency into a tranche in exchange for LP tokens
     *
     * Emits a {Deposited} event.
     *
     * @param trancheId Tranche
     * @param amount Amount of currency tokens
     */
    function deposit(TrancheId trancheId, uint256 amount) external;

    /**
     * @notice Price a note
     *
     * @param noteToken Note token contract
     * @param noteTokenId Note token ID
     * @return Purchase price in currency tokens
     */
    function priceNote(address noteToken, uint256 noteTokenId) external view returns (uint256);

    /**
     * @notice Sell a note to the vault
     *
     * Emits a {NotePurchased} event.
     *
     * @param noteToken Note token contract
     * @param noteTokenId Note token ID
     * @param minPurchasePrice Minimum purchase price in currency tokens
     * @return Executed purchase price in currency tokens
     */
    function sellNote(
        address noteToken,
        uint256 noteTokenId,
        uint256 minPurchasePrice
    ) external returns (uint256);

    /**
     * @notice Sell a note to the vault and deposit its proceeds into one or
     * more tranches
     *
     * Emits {NotePurchased} and {Deposited} events.
     *
     * Note: the minimum purchase price is the sum of `amounts`.
     *
     * @param noteToken Note token contract
     * @param noteTokenId Note token ID
     * @param minPurchasePrice Minimum purchase price in currency tokens
     * @param allocation Allocation for each tranche as a percentage in UD60x18
     * @return Executed purchase price in currency tokens
     */
    function sellNoteAndDeposit(
        address noteToken,
        uint256 noteTokenId,
        uint256 minPurchasePrice,
        uint256[2] calldata allocation
    ) external returns (uint256);

    /**
     * @notice Redeem LP tokens in exchange for currency tokens. Currency
     * tokens can be withdrawn with the `withdraw()` method, once the
     * redemption is processed.
     *
     * Emits a {Redeemed} event.
     *
     * @param trancheId Tranche
     * @param shares Amount of LP tokens
     */
    function redeem(TrancheId trancheId, uint256 shares) external;

    /**
     * @notice Withdraw redeemed currency tokens
     *
     * Emits a {Withdrawn} event.
     *
     * @param trancheId Tranche
     * @param maxAmount Maximum amount of currency tokens to withdraw
     */
    function withdraw(TrancheId trancheId, uint256 maxAmount) external;

    /**************************************************************************/
    /* Collateral API */
    /**************************************************************************/

    /**
     * @notice Withdraw the collateral of a liquidated loan
     *
     * Emits a {CollateralWithdrawn} event.
     *
     * @param noteToken Note token contract
     * @param loanId Loan ID
     */
    function withdrawCollateral(address noteToken, uint256 loanId) external;

    /**************************************************************************/
    /* Callbacks */
    /**************************************************************************/

    /* See ILoanReceiver */

    /**
     * @notice Callback on collateral liquidated
     *
     * Emits a {CollateralLiquidated} event.
     *
     * @param noteToken Note token contract
     * @param loanId Loan ID
     * @param proceeds Proceeds from collateral liquidation in currency tokens
     */
    function onCollateralLiquidated(
        address noteToken,
        uint256 loanId,
        uint256 proceeds
    ) external;
}

File 17 of 35 : LPToken.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.9;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

/**
 * @title Storage for LPToken, V1
 */
abstract contract LPTokenStorageV1 {
    /**
     * @notice Redemption state for account
     * @param pending Pending redemption amount
     * @param withdrawn Withdrawn redemption amount
     * @param redemptionQueueTarget Target in vault's redemption queue
     */
    struct Redemption {
        uint256 pending;
        uint256 withdrawn;
        uint256 redemptionQueueTarget;
    }

    /**
     * @dev Mapping of account to redemption state
     */
    mapping(address => Redemption) internal _redemptions;
}

/**
 * @title Storage for LPToken, aggregated
 */
abstract contract LPTokenStorage is LPTokenStorageV1 {

}

/**
 * @title Liquidity Provider (LP) Token for Vault Tranches
 */
contract LPToken is Initializable, OwnableUpgradeable, ERC20Upgradeable, LPTokenStorage {
    /**************************************************************************/
    /* Constants */
    /**************************************************************************/

    /**
     * @notice Implementation version
     */
    string public constant IMPLEMENTATION_VERSION = "1.1";

    /**************************************************************************/
    /* Errors */
    /**************************************************************************/

    /**
     * @notice Insufficient balance
     */
    error InsufficientBalance();

    /**
     * @notice Redemption in progress
     */
    error RedemptionInProgress();

    /**
     * @notice Invalid amount
     */
    error InvalidAmount();

    /**************************************************************************/
    /* Constructor */
    /**************************************************************************/

    /**
     * @notice LPToken constructor (for implementation)
     * @custom:oz-upgrades-unsafe-allow constructor
     */
    constructor() initializer {}

    /**
     * @notice LPToken constructor (for proxy)
     * @param name Token name
     * @param symbol Token symbol
     */
    function initialize(string memory name, string memory symbol) external initializer {
        __Ownable_init();
        __ERC20_init(name, symbol);
    }

    /**************************************************************************/
    /* Getters */
    /**************************************************************************/

    /**
     * @notice Get redemption state for account
     * @param account Account
     * @return Redemption state
     */
    function redemptions(address account) external view returns (Redemption memory) {
        return _redemptions[account];
    }

    /**
     * @notice Get amount of redemption available for withdraw for account
     * @param account Account
     * @param processedRedemptionQueue Current value of vault's processed
     * redemption queue
     * @return Amount available for withdraw
     */
    function redemptionAvailable(address account, uint256 processedRedemptionQueue) public view returns (uint256) {
        Redemption storage redemption = _redemptions[account];

        if (redemption.pending == 0) {
            /* No redemption pending */
            return 0;
        } else if (processedRedemptionQueue >= redemption.redemptionQueueTarget + redemption.pending) {
            /* Full redemption available for withdraw */
            return redemption.pending - redemption.withdrawn;
        } else if (processedRedemptionQueue > redemption.redemptionQueueTarget) {
            /* Partial redemption available for withdraw */
            return processedRedemptionQueue - redemption.redemptionQueueTarget - redemption.withdrawn;
        } else {
            /* No redemption available for withdraw */
            return 0;
        }
    }

    /**************************************************************************/
    /* Privileged API */
    /**************************************************************************/

    /**
     * @notice Mint tokens to account
     * @param to Recipient account
     * @param amount Amount of LP tokens
     */
    function mint(address to, uint256 amount) external virtual onlyOwner {
        _mint(to, amount);
    }

    /**
     * @notice Burn tokens from account for redemption
     * @param account Redeeming account
     * @param amount Amount of LP tokens
     * @param currencyAmount Amount of currency tokens
     * @param redemptionQueueTarget Target in vault's redemption queue
     */
    function redeem(
        address account,
        uint256 amount,
        uint256 currencyAmount,
        uint256 redemptionQueueTarget
    ) external onlyOwner {
        Redemption storage redemption = _redemptions[account];

        if (balanceOf(account) < amount) revert InsufficientBalance();
        if (redemption.pending != 0) revert RedemptionInProgress();

        redemption.pending = currencyAmount;
        redemption.withdrawn = 0;
        redemption.redemptionQueueTarget = redemptionQueueTarget;

        _burn(account, amount);
    }

    /**
     * @notice Update account's redemption state for withdraw
     * @param account Redeeming account
     * @param currencyAmount Amount of currency tokens
     * @param processedRedemptionQueue Current value of vault's processed
     * redemption queue
     */
    function withdraw(
        address account,
        uint256 currencyAmount,
        uint256 processedRedemptionQueue
    ) external onlyOwner {
        Redemption storage redemption = _redemptions[account];

        if (redemptionAvailable(account, processedRedemptionQueue) < currencyAmount) revert InvalidAmount();

        if (redemption.withdrawn + currencyAmount == redemption.pending) {
            delete _redemptions[account];
        } else {
            redemption.withdrawn += currencyAmount;
        }
    }
}

File 18 of 35 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://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 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 19 of 35 : IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 20 of 35 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 21 of 35 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    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 22 of 35 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.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 ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

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

pragma solidity ^0.8.0;

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

File 24 of 35 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://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 25 of 35 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

File 27 of 35 : PRBMath.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivFixedPointOverflow(uint256 prod1);

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator);

/// @notice Emitted when one of the inputs is type(int256).min.
error PRBMath__MulDivSignedInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows int256.
error PRBMath__MulDivSignedOverflow(uint256 rAbs);

/// @notice Emitted when the input is MIN_SD59x18.
error PRBMathSD59x18__AbsInputTooSmall();

/// @notice Emitted when ceiling a number overflows SD59x18.
error PRBMathSD59x18__CeilOverflow(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__DivInputTooSmall();

/// @notice Emitted when one of the intermediary unsigned results overflows SD59x18.
error PRBMathSD59x18__DivOverflow(uint256 rAbs);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathSD59x18__ExpInputTooBig(int256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathSD59x18__Exp2InputTooBig(int256 x);

/// @notice Emitted when flooring a number underflows SD59x18.
error PRBMathSD59x18__FloorUnderflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMathSD59x18__FromIntOverflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMathSD59x18__FromIntUnderflow(int256 x);

/// @notice Emitted when the product of the inputs is negative.
error PRBMathSD59x18__GmNegativeProduct(int256 x, int256 y);

/// @notice Emitted when multiplying the inputs overflows SD59x18.
error PRBMathSD59x18__GmOverflow(int256 x, int256 y);

/// @notice Emitted when the input is less than or equal to zero.
error PRBMathSD59x18__LogInputTooSmall(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__MulInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__MulOverflow(uint256 rAbs);

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__PowuOverflow(uint256 rAbs);

/// @notice Emitted when the input is negative.
error PRBMathSD59x18__SqrtNegativeInput(int256 x);

/// @notice Emitted when the calculating the square root overflows SD59x18.
error PRBMathSD59x18__SqrtOverflow(int256 x);

/// @notice Emitted when addition overflows UD60x18.
error PRBMathUD60x18__AddOverflow(uint256 x, uint256 y);

/// @notice Emitted when ceiling a number overflows UD60x18.
error PRBMathUD60x18__CeilOverflow(uint256 x);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathUD60x18__ExpInputTooBig(uint256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathUD60x18__Exp2InputTooBig(uint256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format format overflows UD60x18.
error PRBMathUD60x18__FromUintOverflow(uint256 x);

/// @notice Emitted when multiplying the inputs overflows UD60x18.
error PRBMathUD60x18__GmOverflow(uint256 x, uint256 y);

/// @notice Emitted when the input is less than 1.
error PRBMathUD60x18__LogInputTooSmall(uint256 x);

/// @notice Emitted when the calculating the square root overflows UD60x18.
error PRBMathUD60x18__SqrtOverflow(uint256 x);

/// @notice Emitted when subtraction underflows UD60x18.
error PRBMathUD60x18__SubUnderflow(uint256 x, uint256 y);

/// @dev Common mathematical functions used in both PRBMathSD59x18 and PRBMathUD60x18. Note that this shared library
/// does not always assume the signed 59.18-decimal fixed-point or the unsigned 60.18-decimal fixed-point
/// representation. When it does not, it is explicitly mentioned in the NatSpec documentation.
library PRBMath {
    /// STRUCTS ///

    struct SD59x18 {
        int256 value;
    }

    struct UD60x18 {
        uint256 value;
    }

    /// STORAGE ///

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @dev Largest power of two divisor of SCALE.
    uint256 internal constant SCALE_LPOTD = 262144;

    /// @dev SCALE inverted mod 2^256.
    uint256 internal constant SCALE_INVERSE =
        78156646155174841979727994598816262306175212592076161876661_508869554232690281;

    /// FUNCTIONS ///

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    /// @dev Has to use 192.64-bit fixed-point numbers.
    /// See https://ethereum.stackexchange.com/a/96594/24693.
    /// @param x The exponent as an unsigned 192.64-bit fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // Start from 0.5 in the 192.64-bit fixed-point format.
            result = 0x800000000000000000000000000000000000000000000000;

            // Multiply the result by root(2, 2^-i) when the bit at position i is 1. None of the intermediary results overflows
            // because the initial result is 2^191 and all magic factors are less than 2^65.
            if (x & 0x8000000000000000 > 0) {
                result = (result * 0x16A09E667F3BCC909) >> 64;
            }
            if (x & 0x4000000000000000 > 0) {
                result = (result * 0x1306FE0A31B7152DF) >> 64;
            }
            if (x & 0x2000000000000000 > 0) {
                result = (result * 0x1172B83C7D517ADCE) >> 64;
            }
            if (x & 0x1000000000000000 > 0) {
                result = (result * 0x10B5586CF9890F62A) >> 64;
            }
            if (x & 0x800000000000000 > 0) {
                result = (result * 0x1059B0D31585743AE) >> 64;
            }
            if (x & 0x400000000000000 > 0) {
                result = (result * 0x102C9A3E778060EE7) >> 64;
            }
            if (x & 0x200000000000000 > 0) {
                result = (result * 0x10163DA9FB33356D8) >> 64;
            }
            if (x & 0x100000000000000 > 0) {
                result = (result * 0x100B1AFA5ABCBED61) >> 64;
            }
            if (x & 0x80000000000000 > 0) {
                result = (result * 0x10058C86DA1C09EA2) >> 64;
            }
            if (x & 0x40000000000000 > 0) {
                result = (result * 0x1002C605E2E8CEC50) >> 64;
            }
            if (x & 0x20000000000000 > 0) {
                result = (result * 0x100162F3904051FA1) >> 64;
            }
            if (x & 0x10000000000000 > 0) {
                result = (result * 0x1000B175EFFDC76BA) >> 64;
            }
            if (x & 0x8000000000000 > 0) {
                result = (result * 0x100058BA01FB9F96D) >> 64;
            }
            if (x & 0x4000000000000 > 0) {
                result = (result * 0x10002C5CC37DA9492) >> 64;
            }
            if (x & 0x2000000000000 > 0) {
                result = (result * 0x1000162E525EE0547) >> 64;
            }
            if (x & 0x1000000000000 > 0) {
                result = (result * 0x10000B17255775C04) >> 64;
            }
            if (x & 0x800000000000 > 0) {
                result = (result * 0x1000058B91B5BC9AE) >> 64;
            }
            if (x & 0x400000000000 > 0) {
                result = (result * 0x100002C5C89D5EC6D) >> 64;
            }
            if (x & 0x200000000000 > 0) {
                result = (result * 0x10000162E43F4F831) >> 64;
            }
            if (x & 0x100000000000 > 0) {
                result = (result * 0x100000B1721BCFC9A) >> 64;
            }
            if (x & 0x80000000000 > 0) {
                result = (result * 0x10000058B90CF1E6E) >> 64;
            }
            if (x & 0x40000000000 > 0) {
                result = (result * 0x1000002C5C863B73F) >> 64;
            }
            if (x & 0x20000000000 > 0) {
                result = (result * 0x100000162E430E5A2) >> 64;
            }
            if (x & 0x10000000000 > 0) {
                result = (result * 0x1000000B172183551) >> 64;
            }
            if (x & 0x8000000000 > 0) {
                result = (result * 0x100000058B90C0B49) >> 64;
            }
            if (x & 0x4000000000 > 0) {
                result = (result * 0x10000002C5C8601CC) >> 64;
            }
            if (x & 0x2000000000 > 0) {
                result = (result * 0x1000000162E42FFF0) >> 64;
            }
            if (x & 0x1000000000 > 0) {
                result = (result * 0x10000000B17217FBB) >> 64;
            }
            if (x & 0x800000000 > 0) {
                result = (result * 0x1000000058B90BFCE) >> 64;
            }
            if (x & 0x400000000 > 0) {
                result = (result * 0x100000002C5C85FE3) >> 64;
            }
            if (x & 0x200000000 > 0) {
                result = (result * 0x10000000162E42FF1) >> 64;
            }
            if (x & 0x100000000 > 0) {
                result = (result * 0x100000000B17217F8) >> 64;
            }
            if (x & 0x80000000 > 0) {
                result = (result * 0x10000000058B90BFC) >> 64;
            }
            if (x & 0x40000000 > 0) {
                result = (result * 0x1000000002C5C85FE) >> 64;
            }
            if (x & 0x20000000 > 0) {
                result = (result * 0x100000000162E42FF) >> 64;
            }
            if (x & 0x10000000 > 0) {
                result = (result * 0x1000000000B17217F) >> 64;
            }
            if (x & 0x8000000 > 0) {
                result = (result * 0x100000000058B90C0) >> 64;
            }
            if (x & 0x4000000 > 0) {
                result = (result * 0x10000000002C5C860) >> 64;
            }
            if (x & 0x2000000 > 0) {
                result = (result * 0x1000000000162E430) >> 64;
            }
            if (x & 0x1000000 > 0) {
                result = (result * 0x10000000000B17218) >> 64;
            }
            if (x & 0x800000 > 0) {
                result = (result * 0x1000000000058B90C) >> 64;
            }
            if (x & 0x400000 > 0) {
                result = (result * 0x100000000002C5C86) >> 64;
            }
            if (x & 0x200000 > 0) {
                result = (result * 0x10000000000162E43) >> 64;
            }
            if (x & 0x100000 > 0) {
                result = (result * 0x100000000000B1721) >> 64;
            }
            if (x & 0x80000 > 0) {
                result = (result * 0x10000000000058B91) >> 64;
            }
            if (x & 0x40000 > 0) {
                result = (result * 0x1000000000002C5C8) >> 64;
            }
            if (x & 0x20000 > 0) {
                result = (result * 0x100000000000162E4) >> 64;
            }
            if (x & 0x10000 > 0) {
                result = (result * 0x1000000000000B172) >> 64;
            }
            if (x & 0x8000 > 0) {
                result = (result * 0x100000000000058B9) >> 64;
            }
            if (x & 0x4000 > 0) {
                result = (result * 0x10000000000002C5D) >> 64;
            }
            if (x & 0x2000 > 0) {
                result = (result * 0x1000000000000162E) >> 64;
            }
            if (x & 0x1000 > 0) {
                result = (result * 0x10000000000000B17) >> 64;
            }
            if (x & 0x800 > 0) {
                result = (result * 0x1000000000000058C) >> 64;
            }
            if (x & 0x400 > 0) {
                result = (result * 0x100000000000002C6) >> 64;
            }
            if (x & 0x200 > 0) {
                result = (result * 0x10000000000000163) >> 64;
            }
            if (x & 0x100 > 0) {
                result = (result * 0x100000000000000B1) >> 64;
            }
            if (x & 0x80 > 0) {
                result = (result * 0x10000000000000059) >> 64;
            }
            if (x & 0x40 > 0) {
                result = (result * 0x1000000000000002C) >> 64;
            }
            if (x & 0x20 > 0) {
                result = (result * 0x10000000000000016) >> 64;
            }
            if (x & 0x10 > 0) {
                result = (result * 0x1000000000000000B) >> 64;
            }
            if (x & 0x8 > 0) {
                result = (result * 0x10000000000000006) >> 64;
            }
            if (x & 0x4 > 0) {
                result = (result * 0x10000000000000003) >> 64;
            }
            if (x & 0x2 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }
            if (x & 0x1 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }

            // We're doing two things at the same time:
            //
            //   1. Multiply the result by 2^n + 1, where "2^n" is the integer part and the one is added to account for
            //      the fact that we initially set the result to 0.5. This is accomplished by subtracting from 191
            //      rather than 192.
            //   2. Convert the result to the unsigned 60.18-decimal fixed-point format.
            //
            // This works because 2^(191-ip) = 2^ip / 2^191, where "ip" is the integer part "2^n".
            result *= SCALE;
            result >>= (191 - (x >> 64));
        }
    }

    /// @notice Finds the zero-based index of the first one in the binary representation of x.
    /// @dev See the note on msb in the "Find First Set" Wikipedia article https://en.wikipedia.org/wiki/Find_first_set
    /// @param x The uint256 number for which to find the index of the most significant bit.
    /// @return msb The index of the most significant bit as an uint256.
    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {
        if (x >= 2**128) {
            x >>= 128;
            msb += 128;
        }
        if (x >= 2**64) {
            x >>= 64;
            msb += 64;
        }
        if (x >= 2**32) {
            x >>= 32;
            msb += 32;
        }
        if (x >= 2**16) {
            x >>= 16;
            msb += 16;
        }
        if (x >= 2**8) {
            x >>= 8;
            msb += 8;
        }
        if (x >= 2**4) {
            x >>= 4;
            msb += 4;
        }
        if (x >= 2**2) {
            x >>= 2;
            msb += 2;
        }
        if (x >= 2**1) {
            // No need to shift x any more.
            msb += 1;
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The multiplicand as an uint256.
    /// @param y The multiplier as an uint256.
    /// @param denominator The divisor as an uint256.
    /// @return result The result as an uint256.
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
        // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
        // variables such that product = prod1 * 2^256 + prod0.
        uint256 prod0; // Least significant 256 bits of the product
        uint256 prod1; // Most significant 256 bits of the product
        assembly {
            let mm := mulmod(x, y, not(0))
            prod0 := mul(x, y)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        // Handle non-overflow cases, 256 by 256 division.
        if (prod1 == 0) {
            unchecked {
                result = prod0 / denominator;
            }
            return result;
        }

        // Make sure the result is less than 2^256. Also prevents denominator == 0.
        if (prod1 >= denominator) {
            revert PRBMath__MulDivOverflow(prod1, denominator);
        }

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

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

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

        // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
        // See https://cs.stackexchange.com/q/138556/92363.
        unchecked {
            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 lpotdod = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by lpotdod.
                denominator := div(denominator, lpotdod)

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

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

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

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

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

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

    /// @notice Calculates floor(x*y÷1e18) with full precision.
    ///
    /// @dev Variant of "mulDiv" with constant folding, i.e. in which the denominator is always 1e18. Before returning the
    /// final result, we add 1 if (x * y) % SCALE >= HALF_SCALE. Without this, 6.6e-19 would be truncated to 0 instead of
    /// being rounded to 1e-18.  See "Listing 6" and text above it at https://accu.org/index.php/journals/1717.
    ///
    /// Requirements:
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works.
    /// - It is assumed that the result can never be type(uint256).max when x and y solve the following two equations:
    ///     1. x * y = type(uint256).max * SCALE
    ///     2. (x * y) % SCALE >= SCALE / 2
    ///
    /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function mulDivFixedPoint(uint256 x, uint256 y) internal pure returns (uint256 result) {
        uint256 prod0;
        uint256 prod1;
        assembly {
            let mm := mulmod(x, y, not(0))
            prod0 := mul(x, y)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        if (prod1 >= SCALE) {
            revert PRBMath__MulDivFixedPointOverflow(prod1);
        }

        uint256 remainder;
        uint256 roundUpUnit;
        assembly {
            remainder := mulmod(x, y, SCALE)
            roundUpUnit := gt(remainder, 499999999999999999)
        }

        if (prod1 == 0) {
            unchecked {
                result = (prod0 / SCALE) + roundUpUnit;
                return result;
            }
        }

        assembly {
            result := add(
                mul(
                    or(
                        div(sub(prod0, remainder), SCALE_LPOTD),
                        mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, SCALE_LPOTD), SCALE_LPOTD), 1))
                    ),
                    SCALE_INVERSE
                ),
                roundUpUnit
            )
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev An extension of "mulDiv" for signed numbers. Works by computing the signs and the absolute values separately.
    ///
    /// Requirements:
    /// - None of the inputs can be type(int256).min.
    /// - The result must fit within int256.
    ///
    /// @param x The multiplicand as an int256.
    /// @param y The multiplier as an int256.
    /// @param denominator The divisor as an int256.
    /// @return result The result as an int256.
    function mulDivSigned(
        int256 x,
        int256 y,
        int256 denominator
    ) internal pure returns (int256 result) {
        if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
            revert PRBMath__MulDivSignedInputTooSmall();
        }

        // Get hold of the absolute values of x, y and the denominator.
        uint256 ax;
        uint256 ay;
        uint256 ad;
        unchecked {
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);
            ad = denominator < 0 ? uint256(-denominator) : uint256(denominator);
        }

        // Compute the absolute value of (x*y)÷denominator. The result must fit within int256.
        uint256 rAbs = mulDiv(ax, ay, ad);
        if (rAbs > uint256(type(int256).max)) {
            revert PRBMath__MulDivSignedOverflow(rAbs);
        }

        // Get the signs of x, y and the denominator.
        uint256 sx;
        uint256 sy;
        uint256 sd;
        assembly {
            sx := sgt(x, sub(0, 1))
            sy := sgt(y, sub(0, 1))
            sd := sgt(denominator, sub(0, 1))
        }

        // XOR over sx, sy and sd. This is checking whether there are one or three negative signs in the inputs.
        // If yes, the result should be negative.
        result = sx ^ sy ^ sd == 0 ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The uint256 number for which to calculate the square root.
    /// @return result The result as an uint256.
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        // Set the initial guess to the least power of two that is greater than or equal to sqrt(x).
        uint256 xAux = uint256(x);
        result = 1;
        if (xAux >= 0x100000000000000000000000000000000) {
            xAux >>= 128;
            result <<= 64;
        }
        if (xAux >= 0x10000000000000000) {
            xAux >>= 64;
            result <<= 32;
        }
        if (xAux >= 0x100000000) {
            xAux >>= 32;
            result <<= 16;
        }
        if (xAux >= 0x10000) {
            xAux >>= 16;
            result <<= 8;
        }
        if (xAux >= 0x100) {
            xAux >>= 8;
            result <<= 4;
        }
        if (xAux >= 0x10) {
            xAux >>= 4;
            result <<= 2;
        }
        if (xAux >= 0x8) {
            result <<= 1;
        }

        // The operations can never overflow because the result is max 2^127 when it enters this block.
        unchecked {
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1; // Seven iterations should be enough
            uint256 roundedDownResult = x / result;
            return result >= roundedDownResult ? roundedDownResult : result;
        }
    }
}

File 28 of 35 : ILoanPriceOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title Interface to a LoanPriceOracle
 */
interface ILoanPriceOracle {
    /**************************************************************************/
    /* Error codes */
    /**************************************************************************/

    /**
     * @notice Unsupported collateral token contract
     */
    error UnsupportedCollateral();
    /**
     * @notice Insufficient time remaining for loan
     */
    error InsufficientTimeRemaining();
    /**
     * @notice Loan parameter out of bounds
     * @param index Index of out of bound parameter
     */
    error ParameterOutOfBounds(uint256 index);

    /**************************************************************************/
    /* Getters */
    /**************************************************************************/

    /**
     * @notice Get currency token used for pricing
     * @return Currency token contract
     */
    function currencyToken() external view returns (IERC20);

    /**************************************************************************/
    /* Primary API */
    /**************************************************************************/

    /**
     * @notice Price a loan collateralized by the specified token contract and
     * token id
     * @param collateralToken Collateral token contract
     * @param collateralTokenId Collateral token ID
     * @param principal Principal value of loan, in UD60x18
     * @param repayment Repayment value of loan, in UD60x18
     * @param duration Duration of loan, in seconds
     * @param maturity Maturity of loan, in seconds since Unix epoch
     * @param utilization Vault fund utilization, in UD60x18
     * @return Price of loan, in UD60x18
     */
    function priceLoan(
        address collateralToken,
        uint256 collateralTokenId,
        uint256 principal,
        uint256 repayment,
        uint256 duration,
        uint256 maturity,
        uint256 utilization
    ) external view returns (uint256);

    /**
     * @notice Price a loan's repayment, collateralized by the specified token
     * contract and token id
     * @param collateralToken Collateral token contract
     * @param collateralTokenId Collateral token ID
     * @param principal Principal value of loan, in UD60x18
     * @param duration Duration of loan, in seconds
     * @param utilization Vault fund utilization, in UD60x18
     * @return Repayment price of loan, in UD60x18
     */
    function priceLoanRepayment(
        address collateralToken,
        uint256 collateralTokenId,
        uint256 principal,
        uint256 duration,
        uint256 utilization
    ) external view returns (uint256);
}

File 29 of 35 : INoteAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

/**
 * @title Interface to a note adapter, a generic interface to a lending
 * platform
 */
interface INoteAdapter {
    /**************************************************************************/
    /* Structures */
    /**************************************************************************/

    /**
     * @notice Asset information
     * @param token Token contract
     * @param tokenId Token ID
     */
    struct AssetInfo {
        address token;
        uint256 tokenId;
    }

    /**
     * @notice Loan information
     * @param loanId Loan ID
     * @param borrower Borrower
     * @param principal Principal value
     * @param repayment Repayment value
     * @param maturity Maturity in seconds since Unix epoch
     * @param duration Duration in seconds
     * @param currencyToken Currency token used by loan
     * @param collateralToken Collateral token contract
     * @param collateralTokenId Collateral token ID
     */
    struct LoanInfo {
        uint256 loanId;
        address borrower;
        uint256 principal;
        uint256 repayment;
        uint64 maturity;
        uint64 duration;
        address currencyToken;
        address collateralToken;
        uint256 collateralTokenId;
    }

    /**************************************************************************/
    /* Primary API */
    /**************************************************************************/

    /**
     * @notice Get note adapter name
     * @return Note adapter name
     */
    function name() external view returns (string memory);

    /**
     * @notice Get note token of lending platform
     * @return Note token contract
     */
    function noteToken() external view returns (IERC721);

    /**
     * @notice Check if loan is supported by Vault
     * @param noteTokenId Note token ID
     * @param currencyToken Currency token used by Vault
     * @return True if supported, otherwise false
     */
    function isSupported(uint256 noteTokenId, address currencyToken) external view returns (bool);

    /**
     * @notice Get loan information
     * @param noteTokenId Note token ID
     * @return Loan information
     */
    function getLoanInfo(uint256 noteTokenId) external view returns (LoanInfo memory);

    /**
     * @notice Get loan collateral assets
     * @param noteTokenId Note token ID
     * @return Loan collateral assets
     */
    function getLoanAssets(uint256 noteTokenId) external view returns (AssetInfo[] memory);

    /**
     * @notice Get target and calldata to liquidate loan
     * @param loanId Loan ID
     * @return Target address
     * @return Encoded calldata with selector
     */
    function getLiquidateCalldata(uint256 loanId) external view returns (address, bytes memory);

    /**
     * @notice Get target and calldata to unwrap collateral
     * @param loanId Loan ID
     * @return Target address
     * @return Encoded calldata with selector
     */
    function getUnwrapCalldata(uint256 loanId) external view returns (address, bytes memory);

    /**
     * @notice Check if loan is repaid
     * @param loanId Loan ID
     * @return True if repaid, otherwise false
     */
    function isRepaid(uint256 loanId) external view returns (bool);

    /**
     * @notice Check if loan is liquidated
     * @param loanId Loan ID
     * @return True if liquidated, otherwise false
     */
    function isLiquidated(uint256 loanId) external view returns (bool);

    /**
     * @notice Check if loan is expired
     * @param loanId Loan ID
     * @return True if expired, otherwise false
     */
    function isExpired(uint256 loanId) external view returns (bool);
}

File 30 of 35 : ILoanReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/**
 * @title Interface containing callbacks for smart contract loan holders
 * @notice Lending platforms should detect if a lender implements this
 * interface and call it on loan repayment.
 */
interface ILoanReceiver {
    /**
     * @notice Callback on loan repaid
     * @param noteToken Note token contract
     * @param loanId Loan ID
     */
    function onLoanRepaid(address noteToken, uint256 loanId) external;

    /**
     * @notice Callback on loan expired
     * @param noteToken Note token contract
     * @param loanId Loan ID
     */
    function onLoanExpired(address noteToken, uint256 loanId) external;
}

File 31 of 35 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, 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 32 of 35 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_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 {
        _transferOwnership(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");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 33 of 35 : ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
        __ERC20_init_unchained(name_, symbol_);
    }

    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, _allowances[owner][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = _allowances[owner][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Spend `amount` form the allowance of `owner` toward `spender`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens 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 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[45] private __gap;
}

File 34 of 35 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

    /**
     * @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 35 of 35 : IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

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

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CallFailed","type":"error"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"}],"name":"InsolventTranche","type":"error"},{"inputs":[],"name":"InsufficientCashAvailable","type":"error"},{"inputs":[],"name":"InterestRateTooLow","type":"error"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"InvalidLoanStatus","type":"error"},{"inputs":[],"name":"LoanNotExpired","type":"error"},{"inputs":[],"name":"LoanNotRepaid","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"PRBMathUD60x18__FromUintOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"}],"name":"PRBMath__MulDivFixedPointOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"PRBMath__MulDivOverflow","type":"error"},{"inputs":[],"name":"ParameterOutOfBounds","type":"error"},{"inputs":[],"name":"PurchasePriceTooHigh","type":"error"},{"inputs":[],"name":"PurchasePriceTooLow","type":"error"},{"inputs":[],"name":"UnsupportedNoteParameters","type":"error"},{"inputs":[],"name":"UnsupportedNoteToken","type":"error"},{"inputs":[],"name":"UnsupportedTokenDecimals","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rate","type":"uint256"}],"name":"AdminFeeRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AdminFeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"noteToken","type":"address"},{"indexed":true,"internalType":"uint256","name":"loanId","type":"uint256"},{"indexed":false,"internalType":"uint256[2]","name":"trancheReturns","type":"uint256[2]"}],"name":"CollateralLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"noteToken","type":"address"},{"indexed":true,"internalType":"uint256","name":"loanId","type":"uint256"},{"indexed":false,"internalType":"address","name":"collateralToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralTokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"collateralLiquidator","type":"address"}],"name":"CollateralWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"noteToken","type":"address"},{"indexed":true,"internalType":"uint256","name":"loanId","type":"uint256"},{"indexed":false,"internalType":"uint256[2]","name":"trancheLosses","type":"uint256[2]"}],"name":"LoanLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"loanPriceOracle","type":"address"}],"name":"LoanPriceOracleUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"noteToken","type":"address"},{"indexed":true,"internalType":"uint256","name":"loanId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"adminFee","type":"uint256"},{"indexed":false,"internalType":"uint256[2]","name":"trancheReturns","type":"uint256[2]"}],"name":"LoanRepaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"noteToken","type":"address"},{"indexed":false,"internalType":"address","name":"noteAdapter","type":"address"}],"name":"NoteAdapterUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"noteToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"noteTokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"loanId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"purchasePrice","type":"uint256"},{"indexed":false,"internalType":"uint256[2]","name":"trancheContributions","type":"uint256[2]"}],"name":"NotePurchased","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Redeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rate","type":"uint256"}],"name":"SeniorTrancheRateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[],"name":"COLLATERAL_LIQUIDATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EMERGENCY_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"IMPLEMENTATION_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SHARE_PRICE_PRORATION_BUCKETS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TIME_BUCKET_DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_SHARE_PRICE_PRORATION_DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"adminFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceState","outputs":[{"internalType":"uint256","name":"totalCashBalance","type":"uint256"},{"internalType":"uint256","name":"totalLoanBalance","type":"uint256"},{"internalType":"uint256","name":"totalAdminFeeBalance","type":"uint256"},{"internalType":"uint256","name":"totalWithdrawalBalance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"checkUpkeep","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currencyToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"contract IERC20","name":"currencyToken_","type":"address"},{"internalType":"contract ILoanPriceOracle","name":"loanPriceOracle_","type":"address"},{"internalType":"contract LPToken","name":"seniorLPToken_","type":"address"},{"internalType":"contract LPToken","name":"juniorLPToken_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"loanPriceOracle","outputs":[{"internalType":"contract ILoanPriceOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"loanId","type":"uint256"}],"name":"loanState","outputs":[{"components":[{"internalType":"enum VaultStorageV1.LoanStatus","name":"status","type":"uint8"},{"internalType":"uint64","name":"maturityTimeBucket","type":"uint64"},{"internalType":"contract IERC721","name":"collateralToken","type":"address"},{"internalType":"uint256","name":"collateralTokenId","type":"uint256"},{"internalType":"uint256","name":"purchasePrice","type":"uint256"},{"internalType":"uint256","name":"repayment","type":"uint256"},{"internalType":"uint256","name":"seniorTrancheReturn","type":"uint256"}],"internalType":"struct VaultStorageV1.Loan","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"}],"name":"lpToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"}],"name":"noteAdapters","outputs":[{"internalType":"contract INoteAdapter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"loanId","type":"uint256"},{"internalType":"uint256","name":"proceeds","type":"uint256"}],"name":"onCollateralLiquidated","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"loanId","type":"uint256"}],"name":"onLoanExpired","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"loanId","type":"uint256"}],"name":"onLoanRepaid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"timeBucket","type":"uint64"},{"internalType":"address","name":"noteToken","type":"address"}],"name":"pendingLoans","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"performData","type":"bytes"}],"name":"performUpkeep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"noteTokenId","type":"uint256"}],"name":"priceNote","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"},{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"redeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"}],"name":"redemptionSharePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"noteTokenId","type":"uint256"},{"internalType":"uint256","name":"minPurchasePrice","type":"uint256"}],"name":"sellNote","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"noteTokenId","type":"uint256"},{"internalType":"uint256","name":"minPurchasePrice","type":"uint256"},{"internalType":"uint256[2]","name":"allocation","type":"uint256[2]"}],"name":"sellNoteAndDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"seniorTrancheRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"rate","type":"uint256"}],"name":"setAdminFeeRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"loanPriceOracle_","type":"address"}],"name":"setLoanPriceOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"address","name":"noteAdapter","type":"address"}],"name":"setNoteAdapter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rate","type":"uint256"}],"name":"setSeniorTrancheRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"}],"name":"sharePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"supportedNoteTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"}],"name":"trancheState","outputs":[{"internalType":"uint256","name":"realizedValue","type":"uint256"},{"internalType":"uint256","name":"estimatedValue","type":"uint256"},{"internalType":"uint256","name":"pendingRedemptions","type":"uint256"},{"internalType":"uint256","name":"redemptionQueue","type":"uint256"},{"internalType":"uint256","name":"processedRedemptionQueue","type":"uint256"},{"internalType":"uint256","name":"depositSharePrice","type":"uint256"},{"internalType":"uint256","name":"redemptionSharePrice_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"additionalLoanBalance","type":"uint256"}],"name":"utilization","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"utilization","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum IVault.TrancheId","name":"trancheId","type":"uint8"},{"internalType":"uint256","name":"maxAmount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawAdminFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"noteToken","type":"address"},{"internalType":"uint256","name":"loanId","type":"uint256"}],"name":"withdrawCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b50600054610100900460ff166200002f5760005460ff161562000039565b62000039620000de565b620000a15760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b600054610100900460ff16158015620000c4576000805461ffff19166101011790555b8015620000d7576000805461ff00191690555b506200010b565b6000620000f630620000fc60201b62002ae01760201c565b15905090565b6001600160a01b03163b151590565b6151d3806200011b6000396000f3fe608060405234801561001057600080fd5b506004361061030c5760003560e01c80636d7e6f801161019d578063a3578efd116100e9578063c42e473e116100a2578063d828b5541161007c578063d828b5541461074e578063e80aac1014610763578063ea21cd921461078a578063f4d4c9d71461079257600080fd5b8063c42e473e146106fc578063c44cdea214610728578063d547741f1461073b57600080fd5b8063a3578efd14610670578063ac9650d814610683578063b36a5af3146106a3578063b6069ee5146106b6578063bb482f96146106c9578063c1a79a7e146106dc57600080fd5b80637e1c0b56116101565780638cece527116101305780638cece527146106395780638d3c13691461064257806391d1485414610655578063a217fddf1461066857600080fd5b80637e1c0b561461061857806383b715a5146106295780638456cb591461063157600080fd5b80636d7e6f80146105725780636e04ff0d146105855780636e76fc8f146105a65780637292b317146105bb578063754b377c146105ce5780637ada7400146105f057600080fd5b8063308ab8291161025c5780634813b7d91161021557806361a9da23116101ef57806361a9da231461052857806361f6d4491461053b5780636a0f23d01461054e5780636b2fa3741461056157600080fd5b80634813b7d9146104ea5780634aee96121461050a5780635c975abb1461051d57600080fd5b8063308ab8291461048c578063350c35e91461049657806336568abe146104a95780633f489914146104bc5780633f4ba83a146104cf5780634585e33b146104d757600080fd5b80631dd0101e116102c9578063248a9ca3116102a3578063248a9ca3146103fb57806326ba9c411461041e5780632986de10146104665780632f2ff15d1461047957600080fd5b80631dd0101e146103b55780631f2363ac146103c8578063242b8d7b146103f357600080fd5b806301cc8fdc1461031157806301ffc9a71461032957806306fdde031461034c5780630b885ac3146103615780630f93945014610376578063150b7a0214610389575b600080fd5b610103545b6040519081526020015b60405180910390f35b61033c610337366004614479565b6107a5565b6040519015158152602001610320565b61035461082d565b60405161032091906144fb565b61037461036f366004614619565b6108bf565b005b6103746103843660046146b6565b610b4d565b61039c6103973660046146eb565b610ce1565b6040516001600160e01b03199091168152602001610320565b6103746103c336600461476a565b610cf2565b6103db6103d63660046147b7565b610dba565b6040516001600160a01b039091168152602001610320565b610316610dc5565b6103166104093660046147d2565b60009081526065602052604090206001015490565b61043161042c3660046147b7565b610dd6565b604080519788526020880196909652948601939093526060850191909152608084015260a083015260c082015260e001610320565b6103166104743660046147b7565b610e32565b6103746104873660046147eb565b610e3d565b61031662093a8081565b6103746104a4366004614810565b610e68565b6103746104b73660046147eb565b611102565b6103746104ca36600461483c565b611180565b610374611373565b6103746104e5366004614858565b611397565b6104fd6104f83660046148de565b6113fe565b60405161032091906148fc565b610316610518366004614940565b61147d565b60975460ff1661033c565b6103166105363660046147b7565b6115c7565b6103166105493660046146b6565b6115d2565b61037461055c366004614810565b6116bc565b60fc546001600160a01b03166103db565b6103166105803660046147d2565b611b11565b610598610593366004614858565b611b1c565b60405161032092919061498f565b61031660008051602061517e83398151915281565b6103746105c93660046149aa565b611e93565b610354604051806040016040528060038152602001620c4b8d60ea1b81525081565b6105f8611f1c565b604080519485526020850193909352918301526060820152608001610320565b60fd546001600160a01b03166103db565b610316600e81565b610374611f44565b61010454610316565b610374610650366004614810565b611f65565b61033c6106633660046147eb565b612241565b610316600081565b61037461067e3660046147d2565b61226c565b6106966106913660046149c7565b6122e1565b6040516103209190614a29565b6103746106b13660046147d2565b6123d5565b6103746106c4366004614810565b61244a565b6103746106d736600461483c565b612545565b6106ef6106ea366004614810565b612740565b6040516103209190614aa1565b6103db61070a3660046149aa565b6001600160a01b03908116600090815260fe60205260409020541690565b610316610736366004614810565b612848565b6103746107493660046147eb565b612a09565b610756612a2f565b6040516103209190614b0f565b6103167fa335b259335fa3a9eb51356010ae22f26e6d67512a1f9cd4cb939b2a2350a82b81565b610316612a40565b6103746107a036600461483c565b612a4c565b60006001600160e01b03198216637965db0b60e01b14806107d657506001600160e01b03198216630a85bd0160e11b145b806107f157506001600160e01b0319821663e73330b960e01b145b8061080c57506001600160e01b031982166315c08e1b60e11b145b8061082757506301ffc9a760e01b6001600160e01b03198316145b92915050565b606060fb805461083c90614b50565b80601f016020809104026020016040519081016040528092919081815260200182805461086890614b50565b80156108b55780601f1061088a576101008083540402835291602001916108b5565b820191906000526020600020905b81548152906001019060200180831161089857829003601f168201915b5050505050905090565b600054610100900460ff166108da5760005460ff16156108de565b303b155b6109465760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b600054610100900460ff16158015610968576000805461ffff19166101011790555b6001600160a01b03851661098f5760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b0384166109b65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b0383166109dd5760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b038216610a045760405163e6c4247b60e01b815260040160405180910390fd5b846001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610a3d57600080fd5b505afa158015610a51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a759190614b9a565b60ff16601214610a985760405163455de91560e01b815260040160405180910390fd5b610aa0612aef565b610aa8612b18565b610ab0612b47565b8551610ac39060fb9060208901906143e0565b5060fc80546001600160a01b038088166001600160a01b03199283161790925560fd80548784169083161790556101018054868416908316179055610102805492851692909116919091179055610b1b600033612b76565b610b3360008051602061517e83398151915233612b76565b8015610b45576000805461ff00191690555b505050505050565b600260c9541415610b705760405162461bcd60e51b815260040161093d90614bb7565b600260c9557fa335b259335fa3a9eb51356010ae22f26e6d67512a1f9cd4cb939b2a2350a82b610ba08133612bfc565b6001600160a01b03841660009081526101126020908152604080832086845290915290206002815460ff166003811115610bdc57610bdc614a8b565b14610bfa576040516308e0f14560e41b815260040160405180910390fd5b6000610c0a848360040154612c60565b90506000610c188286614c04565b9050816101056000016000828254610c309190614c1b565b909155505061010a8054829190600090610c4b908490614c1b565b90915550610c5a905085612c78565b825460ff1916600317835560fc54610c7d906001600160a01b0316333088612caf565b85876001600160a01b03167f45a0fb303e8424bbe6ea9139885f98615440567e1c38631e302c624f49e8860a604051806040016040528086815260200185815250604051610ccb9190614c56565b60405180910390a35050600160c9555050505050565b630a85bd0160e11b5b949350505050565b6000610cfe8133612bfc565b6001600160a01b038316610d255760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03838116600090815260fe6020526040902080546001600160a01b031916918416918217905515610d6857610d6260ff84612d0d565b50610d75565b610d7360ff84612d22565b505b6040516001600160a01b0383811682528416907fea35018717cda71458fe9bff9e04fe17da9abf282246ce43841616965a7a44d99060200160405180910390a2505050565b600061082782612d37565b610dd3600e62093a80614c64565b81565b600080600080600080600080610deb89612d75565b8054909150610df98a612da0565b826001015483600201548460030154610e118e612e93565b610e1a8f612f38565b959f949e50929c50909a509850965090945092505050565b600061082782612f38565b600082815260656020526040902060010154610e598133612bfc565b610e638383612b76565b505050565b600260c9541415610e8b5760405162461bcd60e51b815260040161093d90614bb7565b600260c9557fa335b259335fa3a9eb51356010ae22f26e6d67512a1f9cd4cb939b2a2350a82b610ebb8133612bfc565b6000610ec684612fd7565b6001600160a01b03851660009081526101126020908152604080832087845290915290209091506002815460ff166003811115610f0557610f05614a8b565b14610f23576040516308e0f14560e41b815260040160405180910390fd5b60405163596f2b5760e11b81526004810185905260009081906001600160a01b0385169063b2de56ae9060240160006040518083038186803b158015610f6857600080fd5b505afa158015610f7c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610fa49190810190614c8e565b90925090506001600160a01b03821615611038576000826001600160a01b031682604051610fd29190614d1a565b6000604051808303816000865af19150503d806000811461100f576040519150601f19603f3d011682016040523d82523d6000602084013e611014565b606091505b505090508061103657604051633204506f60e01b815260040160405180910390fd5b505b82546001840154604051632142170760e11b8152600160481b9092046001600160a01b0316916342842e0e916110749130913391600401614d36565b600060405180830381600087803b15801561108e57600080fd5b505af11580156110a2573d6000803e3d6000fd5b50508454600186015460408051600160481b9093046001600160a01b039081168452602084019290925233908301528993508a1691507f03b25c25e514112cb36b34989f2a8e31cebe9e34b6204acb2f3a9d047394779190606001610ccb565b6001600160a01b03811633146111725760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161093d565b61117c8282613012565b5050565b60975460ff16156111a35760405162461bcd60e51b815260040161093d90614d5a565b600260c95414156111c65760405162461bcd60e51b815260040161093d90614bb7565b600260c95560006111d683612d75565b905060006112726111e685612d37565b600384015460405163624ddda560e11b815233600482015260248101919091526001600160a01b03919091169063c49bbb4a9060440160206040518083038186803b15801561123457600080fd5b505afa158015611248573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061126c9190614d84565b84612c60565b905080156113215761128384612d37565b6003830154604051635ae2fb3960e11b81523360048201526024810184905260448101919091526001600160a01b03919091169063b5c5f67290606401600060405180830381600087803b1580156112da57600080fd5b505af11580156112ee573d6000803e3d6000fd5b505050508061011160008282546113059190614c04565b909155505060fc54611321906001600160a01b03163383613079565b83600181111561133357611333614a8b565b60405182815233907f83637d0d125e3dae88720b1ad229ce05c339c065b6282caf315dcb35a999d6d49060200160405180910390a35050600160c9555050565b60008051602061517e83398151915261138c8133612bfc565b6113946130a9565b50565b600080806113a784860186614d9d565b9250925092508260ff16600014156113c8576113c38282611f65565b6113f7565b8260ff16600114156113de576113c382826116bc565b604051631168860160e01b815260040160405180910390fd5b5050505050565b6001600160401b0382166000908152610113602090815260408083206001600160a01b038516845282529182902080548351818402810184019094528084526060939283018282801561147057602002820191906000526020600020905b81548152602001906001019080831161145c575b5050505050905092915050565b600061148b60975460ff1690565b156114a85760405162461bcd60e51b815260040161093d90614d5a565b600260c95414156114cb5760405162461bcd60e51b815260040161093d90614bb7565b600260c955670de0b6b3a76400006114e860208401358435614c1b565b1461150657604051631168860160e01b815260040160405180910390fd5b600061151386868661313c565b905060006115228435836135cd565b905060006115308284614c04565b90508115611543576115436000836135d9565b8015611554576115546001826135d9565b604051632142170760e11b81526001600160a01b038916906342842e0e9061158490339030908c90600401614d36565b600060405180830381600087803b15801561159e57600080fd5b505af11580156115b2573d6000803e3d6000fd5b5050600160c955509298975050505050505050565b600061082782612e93565b60006115e060975460ff1690565b156115fd5760405162461bcd60e51b815260040161093d90614d5a565b600260c95414156116205760405162461bcd60e51b815260040161093d90614bb7565b600260c955600061163285858561313c565b604051632142170760e11b81529091506001600160a01b038616906342842e0e9061166590339030908990600401614d36565b600060405180830381600087803b15801561167f57600080fd5b505af1158015611693573d6000803e3d6000fd5b505060fc546116af92506001600160a01b031690503383613079565b600160c955949350505050565b600260c95414156116df5760405162461bcd60e51b815260040161093d90614bb7565b600260c95560006116ef83612fd7565b6001600160a01b03841660009081526101126020908152604080832086845290915290209091506001815460ff16600381111561172e5761172e614a8b565b1461174c576040516308e0f14560e41b815260040160405180910390fd5b604051638e1eb41160e01b8152600481018490526001600160a01b03831690638e1eb4119060240160206040518083038186803b15801561178c57600080fd5b505afa1580156117a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117c49190614df4565b80611844575060405163d9548e5360e01b8152600481018490526001600160a01b0383169063d9548e539060240160206040518083038186803b15801561180a57600080fd5b505afa15801561181e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118429190614df4565b155b156118625760405163261094a960e21b815260040160405180910390fd5b60048101546002820154600383015460009183916118809190614c04565b61188a9190614c04565b835461010090046001600160401b0316600090815261010960205260408120805492935084929091906118be908490614c04565b9091555050825461010090046001600160401b0316600090815261010e6020526040812080548392906118f2908490614c04565b9091555050600283015461010a5460009161190c91612c60565b905060008185600201546119209190614c04565b90508061010560000160008282546119389190614c04565b909155505061010a8054839190600090611953908490614c04565b925050819055508085600401600082825461196e9190614c1b565b9091555050845460ff19166002178555604051637ebc460160e01b81526004810188905260009081906001600160a01b03891690637ebc46019060240160006040518083038186803b1580156119c357600080fd5b505afa1580156119d7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526119ff9190810190614c8e565b90925090506001600160a01b038216611a2b5760405163e6c4247b60e01b815260040160405180910390fd5b6000826001600160a01b031682604051611a459190614d1a565b6000604051808303816000865af19150503d8060008114611a82576040519150601f19603f3d011682016040523d82523d6000602084013e611a87565b606091505b5050905080611aa957604051633204506f60e01b815260040160405180910390fd5b898b6001600160a01b03167f18f2acac4f8af7206d6aa5341adbdb36d2847dd58b47d458fa586e99b4457735604051806040016040528088815260200189815250604051611af79190614c56565b60405180910390a35050600160c955505050505050505050565b600061082782613703565b600060606000611b2b42613745565b90506000611b3960ff613754565b905060005b81811015611e72576000611b5360ff8361375e565b90506000611b6082612fd7565b90506000611b6f600187614c04565b90505b611b7d600e87614c1b565b811015611e5e576000818152610113602090815260408083206001600160a01b0387168452909152812054905b81811015611e49576000838152610113602090815260408083206001600160a01b03891684529091528120805483908110611be757611be7614dde565b60009182526020808320909101546001600160a01b038916835261011282526040808420828552909252818320825160e08101909352805491945090829060ff166003811115611c3957611c39614a8b565b6003811115611c4a57611c4a614a8b565b8152815461010081046001600160401b03166020830152600160481b90046001600160a01b03166040820152600180830154606083015260028301546080830152600383015460a083015260049092015460c09091015290915081516003811115611cb757611cb7614a8b565b14611cc3575050611e39565b604051638e1eb41160e01b8152600481018390526001600160a01b03871690638e1eb4119060240160206040518083038186803b158015611d0357600080fd5b505afa158015611d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3b9190614df4565b15611d8c5760408051600060208201526001600160a01b03891691810191909152606081018390526001906080015b6040516020818303038152906040529b509b5050505050505050505050611e8c565b60405163d9548e5360e01b8152600481018390526001600160a01b0387169063d9548e539060240160206040518083038186803b158015611dcc57600080fd5b505afa158015611de0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e049190614df4565b15611e3657604080516001602082018190526001600160a01b038a169282019290925260608101849052608001611d6a565b50505b611e4281614e16565b9050611baa565b50508080611e5690614e16565b915050611b72565b50505080611e6b90614e16565b9050611b3e565b506000604051806020016040528060008152509350935050505b9250929050565b6000611e9f8133612bfc565b6001600160a01b038216611ec65760405163e6c4247b60e01b815260040160405180910390fd5b60fd80546001600160a01b0319166001600160a01b0384169081179091556040519081527fdeaab187cd6294a6e31ae5f53fefdfb21f250f3ae3c99fe3d7bdefe6732c3321906020015b60405180910390a15050565b60008060008061010f54611f2e61376a565b6101105461011154935093509350935090919293565b60008051602061517e833981519152611f5d8133612bfc565b61139461378d565b600260c9541415611f885760405162461bcd60e51b815260040161093d90614bb7565b600260c9556000611f9883612fd7565b6001600160a01b03841660009081526101126020908152604080832086845290915290209091506001815460ff166003811115611fd757611fd7614a8b565b14611ff5576040516308e0f14560e41b815260040160405180910390fd5b604051638e1eb41160e01b8152600481018490526001600160a01b03831690638e1eb4119060240160206040518083038186803b15801561203557600080fd5b505afa158015612049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061206d9190614df4565b61208957604051625bdcbf60e11b815260040160405180910390fd5b60048101546002820154600383015460009183916120a79190614c04565b6120b19190614c04565b835461010090046001600160401b0316600090815261010960205260408120805492935084929091906120e5908490614c04565b9091555050825461010090046001600160401b0316600090815261010e602052604081208054839290612119908490614c04565b90915550506101045461212c90836135cd565b6121369083614c04565b915061214561010454826135cd565b61214f9082614c04565b905060008183856002015486600301546121699190614c04565b6121739190614c04565b61217d9190614c04565b90508061011060008282546121929190614c1b565b909155505061010580548491906000906121ad908490614c1b565b909155505061010a80548391906000906121c8908490614c1b565b909155505060038401546121e6906121e1908390614c04565b612c78565b835460ff1916600317845560408051808201825284815260208101849052905187916001600160a01b038a16917f019ccf97cecb44d15855a7ba0d961075243a642dee90ff0bfb013edc855a522a91610ccb91869190614e31565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60006122788133612bfc565b81158061228d5750670de0b6b3a76400008210155b156122ab57604051631168860160e01b815260040160405180910390fd5b6101038290556040518281527f5c8abcc1f1bd53755e680b13c3e68ec5c3fdffe11bf764c462d795dc20684d3990602001611f10565b6060816001600160401b038111156122fb576122fb61450e565b60405190808252806020026020018201604052801561232e57816020015b60608152602001906001900390816123195790505b50905060005b828110156123ce5761239e3085858481811061235257612352614dde565b90506020028101906123649190614e45565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506137e592505050565b8282815181106123b0576123b0614dde565b602002602001018190525080806123c690614e16565b915050612334565b5092915050565b60006123e18133612bfc565b8115806123f65750670de0b6b3a76400008210155b1561241457604051631168860160e01b815260040160405180910390fd5b6101048290556040518281527f576be7f9615bb4c6e139635cf4380b1ce9f6aa425dabe6b9057c24a86cc3c97990602001611f10565b600260c954141561246d5760405162461bcd60e51b815260040161093d90614bb7565b600260c955600061247e8133612bfc565b6001600160a01b0383166124a55760405163e6c4247b60e01b815260040160405180910390fd5b610110548211156124c957604051631168860160e01b815260040160405180910390fd5b8161011060008282546124dc9190614c04565b909155505060fc546124f8906001600160a01b03168484613079565b826001600160a01b03167fcdcaff67ac16639664e5f9343c9223a1dc9c972ec367b69ae9fc1325c7be54748360405161253391815260200190565b60405180910390a25050600160c95550565b60975460ff16156125685760405162461bcd60e51b815260040161093d90614d5a565b600260c954141561258b5760405162461bcd60e51b815260040161093d90614bb7565b600260c955806125ae57604051631168860160e01b815260040160405180910390fd5b60006125b983612d75565b90506125c48361380a565b6125e3578260405163a87b5fc560e01b815260040161093d9190614e8b565b60006125ee84612f38565b905060006125fc84836135cd565b905061260785612d37565b600284015460405163ea2092f360e01b8152336004820152602481018790526044810184905260648101919091526001600160a01b03919091169063ea2092f390608401600060405180830381600087803b15801561266557600080fd5b505af1158015612679573d6000803e3d6000fd5b50505050808360010160008282546126919190614c1b565b92505081905550808360020160008282546126ac9190614c1b565b9250508190555060006126c28261010f54612c60565b90508061010f60008282546126d79190614c04565b909155506126e6905081612c78565b8560018111156126f8576126f8614a8b565b604080518781526020810185905233917ff8b564b1b7f5bb9fea632ddf0036474f68d8cec99f4b2e96a29be779871e059a910160405180910390a35050600160c95550505050565b6127936040805160e08101909152806000815260200160006001600160401b0316815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600081525090565b6001600160a01b03831660009081526101126020908152604080832085845290915290819020815160e081019092528054829060ff1660038111156127da576127da614a8b565b60038111156127eb576127eb614a8b565b8152815461010081046001600160401b03166020830152600160481b90046001600160a01b031660408201526001820154606082015260028201546080820152600382015460a082015260049091015460c0909101529392505050565b60008061285484612fd7565b60fc546040516344147cf960e11b8152600481018690526001600160a01b039182166024820152919250821690638828f9f29060440160206040518083038186803b1580156128a257600080fd5b505afa1580156128b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128da9190614df4565b6128f75760405163aec6813d60e01b815260040160405180910390fd5b6040516301c5004b60e21b8152600481018490526000906001600160a01b03831690630714012c906024016101206040518083038186803b15801561293b57600080fd5b505afa15801561294f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129739190614eb0565b9050612a0081836001600160a01b031663323c70e4876040518263ffffffff1660e01b81526004016129a791815260200190565b60006040518083038186803b1580156129bf57600080fd5b505afa1580156129d3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526129fb9190810190614f4c565b6138aa565b95945050505050565b600082815260656020526040902060010154612a258133612bfc565b610e638383613012565b6060612a3b60ff613a29565b905090565b6000612a3b6000613703565b60975460ff1615612a6f5760405162461bcd60e51b815260040161093d90614d5a565b600260c9541415612a925760405162461bcd60e51b815260040161093d90614bb7565b600260c95580612ab557604051631168860160e01b815260040160405180910390fd5b612abf82826135d9565b60fc54612ad7906001600160a01b0316333084612caf565b5050600160c955565b6001600160a01b03163b151590565b600054610100900460ff16612b165760405162461bcd60e51b815260040161093d90615016565b565b600054610100900460ff16612b3f5760405162461bcd60e51b815260040161093d90615016565b612b16613a36565b600054610100900460ff16612b6e5760405162461bcd60e51b815260040161093d90615016565b612b16613a69565b612b808282612241565b61117c5760008281526065602090815260408083206001600160a01b03851684529091529020805460ff19166001179055612bb83390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b612c068282612241565b61117c57612c1e816001600160a01b03166014613a97565b612c29836020613a97565b604051602001612c3a929190615061565b60408051601f198184030181529082905262461bcd60e51b825261093d916004016144fb565b6000818310612c6f5781612c71565b825b9392505050565b612c8461010582613c32565b9050612c9261010a82613c32565b90508061010f6000828254612ca79190614c1b565b909155505050565b612d07846323b872dd60e01b858585604051602401612cd093929190614d36565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613cc4565b50505050565b6000612c71836001600160a01b038416613d96565b6000612c71836001600160a01b038416613de5565b600080826001811115612d4c57612d4c614a8b565b14612d6357610102546001600160a01b0316610827565b5050610101546001600160a01b031690565b600080826001811115612d8a57612d8a614a8b565b14612d975761010a610827565b61010592915050565b600080612dac83612d75565b90506000612db942613745565b90506000612dd8612dc983613ed8565b612dd39042614c04565b613ee7565b90506000805b600e811015612e7457612e58612e42612e1483612dfd6001600e614c04565b612e079190614c04565b612dd39062093a80614c64565b612e1e9086614c1b565b600488016000612e2e868a614c1b565b8152602001908152602001600020546135cd565b612e53612dd3600e62093a80614c64565b613f34565b612e629083614c1b565b9150612e6d81614e16565b9050612dde565b5080612e7f87613f49565b612e899190614c1b565b9695505050505050565b600080612e9f83612d37565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612ed757600080fd5b505afa158015612eeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f0f9190614d84565b905080612f265750670de0b6b3a764000092915050565b612c71612f3284612da0565b82613f34565b600080612f4483612d37565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612f7c57600080fd5b505afa158015612f90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb49190614d84565b905080612fcb5750670de0b6b3a764000092915050565b612c71612f3284613f49565b6001600160a01b03808216600090815260fe6020526040812054909116806108275760405163f55484e360e01b815260040160405180910390fd5b61301c8282612241565b1561117c5760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6040516001600160a01b038316602482015260448101829052610e6390849063a9059cbb60e01b90606401612cd0565b60975460ff166130f25760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161093d565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60008061314885612fd7565b60fc546040516344147cf960e11b8152600481018790526001600160a01b039182166024820152919250821690638828f9f29060440160206040518083038186803b15801561319657600080fd5b505afa1580156131aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ce9190614df4565b6131eb5760405163aec6813d60e01b815260040160405180910390fd5b6040516301c5004b60e21b8152600481018590526000906001600160a01b03831690630714012c906024016101206040518083038186803b15801561322f57600080fd5b505afa158015613243573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132679190614eb0565b9050600061329d82846001600160a01b031663323c70e4896040518263ffffffff1660e01b81526004016129a791815260200190565b9050848110156132c05760405163a7e5f4f560e01b815260040160405180910390fd5b816060015181106132e45760405163591445fd60e01b815260040160405180910390fd5b61010f54811115613308576040516304604ced60e31b815260040160405180910390fd5b600061332f61331d61010560000154846135cd565b61010a5461010554612e539190614c1b565b9050600061335f8261335a6101035461335a4289608001516001600160401b0316612dd39190614c04565b6135cd565b9050808385606001516133729190614c04565b101561339157604051630d2693ab60e41b815260040160405180910390fd5b6000818486606001516133a49190614c04565b6133ae9190614c04565b905060006133c886608001516001600160401b0316613745565b600081815261010960205260408120805492935085929091906133ec908490614c1b565b9091555050600081815261010e602052604081208054849290613410908490614c1b565b925050819055508461010f600082825461342a9190614c04565b90915550506001600160a01b038b166000908152610112602090815260408083208951845290915290208054600190829060ff191682800217905550818160000160016101000a8154816001600160401b0302191690836001600160401b031602179055508660e001518160000160096101000a8154816001600160a01b0302191690836001600160a01b03160217905550866101000151816001018190555085816002018190555086606001518160030181905550838160040181905550610113600083815260200190815260200160002060008d6001600160a01b03166001600160a01b031681526020019081526020016000208760000151908060018154018082558091505060019003906000526020600020016000909190919091505586600001518c6001600160a01b0316336001600160a01b03167f68b109887fa59f92d688277b490d91fcd24133d99bcffaa50c75e81bdf5a4a078e8a60405180604001604052808c81526020018c8e6135a49190614c04565b90526040516135b5939291906150d6565b60405180910390a450939a9950505050505050505050565b6000612c718383613f7e565b6135e28261380a565b613601578160405163a87b5fc560e01b815260040161093d9190614e8b565b600061360c83612e93565b9050600061361a8383613f34565b90508261362685612d75565b8054600090613636908490614c1b565b90915550613645905083612c78565b61364e84612d37565b6040516340c10f1960e01b8152336004820152602481018390526001600160a01b0391909116906340c10f1990604401600060405180830381600087803b15801561369857600080fd5b505af11580156136ac573d6000803e3d6000fd5b505050508360018111156136c2576136c2614a8b565b604080518581526020810184905233917f2ec61e8cb9905b0de268566bd6b90da9952dd7672a5bf79ac53ef7f2064a09a6910160405180910390a350505050565b60008061370e61376a565b905060008161010f546137219190614c1b565b9050801561373b57613736612f328584614c1b565b610cea565b6000949350505050565b600061082762093a8083615107565b6000610827825490565b6000612c718383614040565b61010f5461010a54610105546000929161378391614c1b565b612a3b9190614c04565b60975460ff16156137b05760405162461bcd60e51b815260040161093d90614d5a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861311f3390565b6060612c7183836040518060600160405280602781526020016151576027913961406a565b60008061381683612d75565b9050806001015481600001541180612c71575061383283612d37565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561386a57600080fd5b505afa15801561387e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138a29190614d84565b159392505050565b6000806000905060006138bd8451613ee7565b905060006138cf866040015183613f34565b905060006138e1876060015184613f34565b905060005b8651811015613a1d5760fd5487516001600160a01b039091169063d3e4d5fd9089908490811061391857613918614dde565b60200260200101516000015189848151811061393657613936614dde565b60200260200101516020015186868d60a001518e608001516139578d613703565b6040516001600160e01b031960e08a901b1681526001600160a01b0390971660048801526024870195909552604486019390935260648501919091526001600160401b0390811660848501521660a483015260c482015260e40160206040518083038186803b1580156139c957600080fd5b505afa1580156139dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a019190614d84565b613a0b9086614c1b565b9450613a1681614e16565b90506138e6565b50929695505050505050565b60606000612c718361413d565b600054610100900460ff16613a5d5760405162461bcd60e51b815260040161093d90615016565b6097805460ff19169055565b600054610100900460ff16613a905760405162461bcd60e51b815260040161093d90615016565b600160c955565b60606000613aa6836002614c64565b613ab1906002614c1b565b6001600160401b03811115613ac857613ac861450e565b6040519080825280601f01601f191660200182016040528015613af2576020820181803683370190505b509050600360fc1b81600081518110613b0d57613b0d614dde565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110613b3c57613b3c614dde565b60200101906001600160f81b031916908160001a9053506000613b60846002614c64565b613b6b906001614c1b565b90505b6001811115613be3576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613b9f57613b9f614dde565b1a60f81b828281518110613bb557613bb5614dde565b60200101906001600160f81b031916908160001a90535060049490941c93613bdc81615129565b9050613b6e565b508315612c715760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161093d565b600080613c508460000154613c4b866001015486612c60565b612c60565b905080846001016000828254613c669190614c04565b9250508190555080846003016000828254613c819190614c1b565b9091555050835481908590600090613c9a908490614c04565b92505081905550806101116000828254613cb49190614c1b565b90915550610cea90508184614c04565b6000613d19826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166141999092919063ffffffff16565b805190915015610e635780806020019051810190613d379190614df4565b610e635760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161093d565b6000818152600183016020526040812054613ddd57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610827565b506000610827565b60008181526001830160205260408120548015613ece576000613e09600183614c04565b8554909150600090613e1d90600190614c04565b9050818114613e82576000866000018281548110613e3d57613e3d614dde565b9060005260206000200154905080876000018481548110613e6057613e60614dde565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613e9357613e93615140565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610827565b6000915050610827565b600061082762093a8083614c64565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f21821115613f2657604051633492ffd960e01b81526004810183905260240161093d565b50670de0b6b3a76400000290565b6000612c7183670de0b6b3a7640000846141a8565b600080613f5583612d75565b90508060010154816000015411613f6d576000612c71565b60018101548154612c719190614c04565b60008080600019848609848602925082811083820303915050670de0b6b3a76400008110613fc25760405163698d9a0160e11b81526004810182905260240161093d565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff811182613ffc5780670de0b6b3a7640000850401945050505050610827565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b600082600001828154811061405757614057614dde565b9060005260206000200154905092915050565b60606001600160a01b0384163b6140d25760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b606482015260840161093d565b600080856001600160a01b0316856040516140ed9190614d1a565b600060405180830381855af49150503d8060008114614128576040519150601f19603f3d011682016040523d82523d6000602084013e61412d565b606091505b5091509150612e89828286614276565b60608160000180548060200260200160405190810160405280929190818152602001828054801561418d57602002820191906000526020600020905b815481526020019060010190808311614179575b50505050509050919050565b6060610cea84846000856142af565b6000808060001985870985870292508281108382030391505080600014156141e3578382816141d9576141d96150f1565b0492505050612c71565b83811061420d57604051631dcf306360e21b8152600481018290526024810185905260440161093d565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b60608315614285575081612c71565b8251156142955782518084602001fd5b8160405162461bcd60e51b815260040161093d91906144fb565b6060824710156143105760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161093d565b6001600160a01b0385163b6143675760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161093d565b600080866001600160a01b031685876040516143839190614d1a565b60006040518083038185875af1925050503d80600081146143c0576040519150601f19603f3d011682016040523d82523d6000602084013e6143c5565b606091505b50915091506143d5828286614276565b979650505050505050565b8280546143ec90614b50565b90600052602060002090601f01602090048101928261440e5760008555614454565b82601f1061442757805160ff1916838001178555614454565b82800160010185558215614454579182015b82811115614454578251825591602001919060010190614439565b50614460929150614464565b5090565b5b808211156144605760008155600101614465565b60006020828403121561448b57600080fd5b81356001600160e01b031981168114612c7157600080fd5b60005b838110156144be5781810151838201526020016144a6565b83811115612d075750506000910152565b600081518084526144e78160208601602086016144a3565b601f01601f19169290920160200192915050565b602081526000612c7160208301846144cf565b634e487b7160e01b600052604160045260246000fd5b60405161012081016001600160401b03811182821017156145475761454761450e565b60405290565b604080519081016001600160401b03811182821017156145475761454761450e565b604051601f8201601f191681016001600160401b03811182821017156145975761459761450e565b604052919050565b60006001600160401b038211156145b8576145b861450e565b50601f01601f191660200190565b60006145d96145d48461459f565b61456f565b90508281528383830111156145ed57600080fd5b828260208301376000602084830101529392505050565b6001600160a01b038116811461139457600080fd5b600080600080600060a0868803121561463157600080fd5b85356001600160401b0381111561464757600080fd5b8601601f8101881361465857600080fd5b614667888235602084016145c6565b955050602086013561467881614604565b9350604086013561468881614604565b9250606086013561469881614604565b915060808601356146a881614604565b809150509295509295909350565b6000806000606084860312156146cb57600080fd5b83356146d681614604565b95602085013595506040909401359392505050565b6000806000806080858703121561470157600080fd5b843561470c81614604565b9350602085013561471c81614604565b92506040850135915060608501356001600160401b0381111561473e57600080fd5b8501601f8101871361474f57600080fd5b61475e878235602084016145c6565b91505092959194509250565b6000806040838503121561477d57600080fd5b823561478881614604565b9150602083013561479881614604565b809150509250929050565b8035600281106147b257600080fd5b919050565b6000602082840312156147c957600080fd5b612c71826147a3565b6000602082840312156147e457600080fd5b5035919050565b600080604083850312156147fe57600080fd5b82359150602083013561479881614604565b6000806040838503121561482357600080fd5b823561482e81614604565b946020939093013593505050565b6000806040838503121561484f57600080fd5b61482e836147a3565b6000806020838503121561486b57600080fd5b82356001600160401b038082111561488257600080fd5b818501915085601f83011261489657600080fd5b8135818111156148a557600080fd5b8660208285010111156148b757600080fd5b60209290920196919550909350505050565b6001600160401b038116811461139457600080fd5b600080604083850312156148f157600080fd5b8235614788816148c9565b6020808252825182820181905260009190848201906040850190845b8181101561493457835183529284019291840191600101614918565b50909695505050505050565b60008060008060a0858703121561495657600080fd5b843561496181614604565b9350602085013592506040850135915060a0850186101561498157600080fd5b509194909350909160600190565b8215158152604060208201526000610cea60408301846144cf565b6000602082840312156149bc57600080fd5b8135612c7181614604565b600080602083850312156149da57600080fd5b82356001600160401b03808211156149f157600080fd5b818501915085601f830112614a0557600080fd5b813581811115614a1457600080fd5b8660208260051b85010111156148b757600080fd5b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015614a7e57603f19888603018452614a6c8583516144cf565b94509285019290850190600101614a50565b5092979650505050505050565b634e487b7160e01b600052602160045260246000fd5b815160e082019060048110614ab857614ab8614a8b565b808352506001600160401b03602084015116602083015260018060a01b036040840151166040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015292915050565b6020808252825182820181905260009190848201906040850190845b818110156149345783516001600160a01b031683529284019291840191600101614b2b565b600181811c90821680614b6457607f821691505b60208210811415614b8557634e487b7160e01b600052602260045260246000fd5b50919050565b60ff8116811461139457600080fd5b600060208284031215614bac57600080fd5b8151612c7181614b8b565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600082821015614c1657614c16614bee565b500390565b60008219821115614c2e57614c2e614bee565b500190565b8060005b6002811015612d07578151845260209384019390910190600101614c37565b604081016108278284614c33565b6000816000190483118215151615614c7e57614c7e614bee565b500290565b80516147b281614604565b60008060408385031215614ca157600080fd5b8251614cac81614604565b60208401519092506001600160401b03811115614cc857600080fd5b8301601f81018513614cd957600080fd5b8051614ce76145d48261459f565b818152866020838501011115614cfc57600080fd5b614d0d8260208301602086016144a3565b8093505050509250929050565b60008251614d2c8184602087016144a3565b9190910192915050565b6001600160a01b039384168152919092166020820152604081019190915260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b600060208284031215614d9657600080fd5b5051919050565b600080600060608486031215614db257600080fd5b8335614dbd81614b8b565b92506020840135614dcd81614604565b929592945050506040919091013590565b634e487b7160e01b600052603260045260246000fd5b600060208284031215614e0657600080fd5b81518015158114612c7157600080fd5b6000600019821415614e2a57614e2a614bee565b5060010190565b82815260608101612c716020830184614c33565b6000808335601e19843603018112614e5c57600080fd5b8301803591506001600160401b03821115614e7657600080fd5b602001915036819003821315611e8c57600080fd5b6020810160028310614e9f57614e9f614a8b565b91905290565b80516147b2816148c9565b60006101208284031215614ec357600080fd5b614ecb614524565b82518152614edb60208401614c83565b60208201526040830151604082015260608301516060820152614f0060808401614ea5565b6080820152614f1160a08401614ea5565b60a0820152614f2260c08401614c83565b60c0820152614f3360e08401614c83565b60e0820152610100928301519281019290925250919050565b60006020808385031215614f5f57600080fd5b82516001600160401b0380821115614f7657600080fd5b818501915085601f830112614f8a57600080fd5b815181811115614f9c57614f9c61450e565b614faa848260051b0161456f565b818152848101925060069190911b830184019087821115614fca57600080fd5b928401925b818410156143d55760408489031215614fe85760008081fd5b614ff061454d565b8451614ffb81614604565b81528486015186820152835260409093019291840191614fcf565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516150998160178501602088016144a3565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516150ca8160288401602088016144a3565b01602801949350505050565b8381526020810183905260808101610cea6040830184614c33565b634e487b7160e01b600052601260045260246000fd5b60008261512457634e487b7160e01b600052601260045260246000fd5b500490565b60008161513857615138614bee565b506000190190565b634e487b7160e01b600052603160045260246000fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65645c91514091af31f62f596a314af7d5be40146b2f2355969392f055e12e0982fba26469706673582212202986f331d164cbf71548f6a5d92fce5174c028183d9ea580d2ab9855d91f468464736f6c63430008090033

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061030c5760003560e01c80636d7e6f801161019d578063a3578efd116100e9578063c42e473e116100a2578063d828b5541161007c578063d828b5541461074e578063e80aac1014610763578063ea21cd921461078a578063f4d4c9d71461079257600080fd5b8063c42e473e146106fc578063c44cdea214610728578063d547741f1461073b57600080fd5b8063a3578efd14610670578063ac9650d814610683578063b36a5af3146106a3578063b6069ee5146106b6578063bb482f96146106c9578063c1a79a7e146106dc57600080fd5b80637e1c0b56116101565780638cece527116101305780638cece527146106395780638d3c13691461064257806391d1485414610655578063a217fddf1461066857600080fd5b80637e1c0b561461061857806383b715a5146106295780638456cb591461063157600080fd5b80636d7e6f80146105725780636e04ff0d146105855780636e76fc8f146105a65780637292b317146105bb578063754b377c146105ce5780637ada7400146105f057600080fd5b8063308ab8291161025c5780634813b7d91161021557806361a9da23116101ef57806361a9da231461052857806361f6d4491461053b5780636a0f23d01461054e5780636b2fa3741461056157600080fd5b80634813b7d9146104ea5780634aee96121461050a5780635c975abb1461051d57600080fd5b8063308ab8291461048c578063350c35e91461049657806336568abe146104a95780633f489914146104bc5780633f4ba83a146104cf5780634585e33b146104d757600080fd5b80631dd0101e116102c9578063248a9ca3116102a3578063248a9ca3146103fb57806326ba9c411461041e5780632986de10146104665780632f2ff15d1461047957600080fd5b80631dd0101e146103b55780631f2363ac146103c8578063242b8d7b146103f357600080fd5b806301cc8fdc1461031157806301ffc9a71461032957806306fdde031461034c5780630b885ac3146103615780630f93945014610376578063150b7a0214610389575b600080fd5b610103545b6040519081526020015b60405180910390f35b61033c610337366004614479565b6107a5565b6040519015158152602001610320565b61035461082d565b60405161032091906144fb565b61037461036f366004614619565b6108bf565b005b6103746103843660046146b6565b610b4d565b61039c6103973660046146eb565b610ce1565b6040516001600160e01b03199091168152602001610320565b6103746103c336600461476a565b610cf2565b6103db6103d63660046147b7565b610dba565b6040516001600160a01b039091168152602001610320565b610316610dc5565b6103166104093660046147d2565b60009081526065602052604090206001015490565b61043161042c3660046147b7565b610dd6565b604080519788526020880196909652948601939093526060850191909152608084015260a083015260c082015260e001610320565b6103166104743660046147b7565b610e32565b6103746104873660046147eb565b610e3d565b61031662093a8081565b6103746104a4366004614810565b610e68565b6103746104b73660046147eb565b611102565b6103746104ca36600461483c565b611180565b610374611373565b6103746104e5366004614858565b611397565b6104fd6104f83660046148de565b6113fe565b60405161032091906148fc565b610316610518366004614940565b61147d565b60975460ff1661033c565b6103166105363660046147b7565b6115c7565b6103166105493660046146b6565b6115d2565b61037461055c366004614810565b6116bc565b60fc546001600160a01b03166103db565b6103166105803660046147d2565b611b11565b610598610593366004614858565b611b1c565b60405161032092919061498f565b61031660008051602061517e83398151915281565b6103746105c93660046149aa565b611e93565b610354604051806040016040528060038152602001620c4b8d60ea1b81525081565b6105f8611f1c565b604080519485526020850193909352918301526060820152608001610320565b60fd546001600160a01b03166103db565b610316600e81565b610374611f44565b61010454610316565b610374610650366004614810565b611f65565b61033c6106633660046147eb565b612241565b610316600081565b61037461067e3660046147d2565b61226c565b6106966106913660046149c7565b6122e1565b6040516103209190614a29565b6103746106b13660046147d2565b6123d5565b6103746106c4366004614810565b61244a565b6103746106d736600461483c565b612545565b6106ef6106ea366004614810565b612740565b6040516103209190614aa1565b6103db61070a3660046149aa565b6001600160a01b03908116600090815260fe60205260409020541690565b610316610736366004614810565b612848565b6103746107493660046147eb565b612a09565b610756612a2f565b6040516103209190614b0f565b6103167fa335b259335fa3a9eb51356010ae22f26e6d67512a1f9cd4cb939b2a2350a82b81565b610316612a40565b6103746107a036600461483c565b612a4c565b60006001600160e01b03198216637965db0b60e01b14806107d657506001600160e01b03198216630a85bd0160e11b145b806107f157506001600160e01b0319821663e73330b960e01b145b8061080c57506001600160e01b031982166315c08e1b60e11b145b8061082757506301ffc9a760e01b6001600160e01b03198316145b92915050565b606060fb805461083c90614b50565b80601f016020809104026020016040519081016040528092919081815260200182805461086890614b50565b80156108b55780601f1061088a576101008083540402835291602001916108b5565b820191906000526020600020905b81548152906001019060200180831161089857829003601f168201915b5050505050905090565b600054610100900460ff166108da5760005460ff16156108de565b303b155b6109465760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b600054610100900460ff16158015610968576000805461ffff19166101011790555b6001600160a01b03851661098f5760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b0384166109b65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b0383166109dd5760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b038216610a045760405163e6c4247b60e01b815260040160405180910390fd5b846001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610a3d57600080fd5b505afa158015610a51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a759190614b9a565b60ff16601214610a985760405163455de91560e01b815260040160405180910390fd5b610aa0612aef565b610aa8612b18565b610ab0612b47565b8551610ac39060fb9060208901906143e0565b5060fc80546001600160a01b038088166001600160a01b03199283161790925560fd80548784169083161790556101018054868416908316179055610102805492851692909116919091179055610b1b600033612b76565b610b3360008051602061517e83398151915233612b76565b8015610b45576000805461ff00191690555b505050505050565b600260c9541415610b705760405162461bcd60e51b815260040161093d90614bb7565b600260c9557fa335b259335fa3a9eb51356010ae22f26e6d67512a1f9cd4cb939b2a2350a82b610ba08133612bfc565b6001600160a01b03841660009081526101126020908152604080832086845290915290206002815460ff166003811115610bdc57610bdc614a8b565b14610bfa576040516308e0f14560e41b815260040160405180910390fd5b6000610c0a848360040154612c60565b90506000610c188286614c04565b9050816101056000016000828254610c309190614c1b565b909155505061010a8054829190600090610c4b908490614c1b565b90915550610c5a905085612c78565b825460ff1916600317835560fc54610c7d906001600160a01b0316333088612caf565b85876001600160a01b03167f45a0fb303e8424bbe6ea9139885f98615440567e1c38631e302c624f49e8860a604051806040016040528086815260200185815250604051610ccb9190614c56565b60405180910390a35050600160c9555050505050565b630a85bd0160e11b5b949350505050565b6000610cfe8133612bfc565b6001600160a01b038316610d255760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03838116600090815260fe6020526040902080546001600160a01b031916918416918217905515610d6857610d6260ff84612d0d565b50610d75565b610d7360ff84612d22565b505b6040516001600160a01b0383811682528416907fea35018717cda71458fe9bff9e04fe17da9abf282246ce43841616965a7a44d99060200160405180910390a2505050565b600061082782612d37565b610dd3600e62093a80614c64565b81565b600080600080600080600080610deb89612d75565b8054909150610df98a612da0565b826001015483600201548460030154610e118e612e93565b610e1a8f612f38565b959f949e50929c50909a509850965090945092505050565b600061082782612f38565b600082815260656020526040902060010154610e598133612bfc565b610e638383612b76565b505050565b600260c9541415610e8b5760405162461bcd60e51b815260040161093d90614bb7565b600260c9557fa335b259335fa3a9eb51356010ae22f26e6d67512a1f9cd4cb939b2a2350a82b610ebb8133612bfc565b6000610ec684612fd7565b6001600160a01b03851660009081526101126020908152604080832087845290915290209091506002815460ff166003811115610f0557610f05614a8b565b14610f23576040516308e0f14560e41b815260040160405180910390fd5b60405163596f2b5760e11b81526004810185905260009081906001600160a01b0385169063b2de56ae9060240160006040518083038186803b158015610f6857600080fd5b505afa158015610f7c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610fa49190810190614c8e565b90925090506001600160a01b03821615611038576000826001600160a01b031682604051610fd29190614d1a565b6000604051808303816000865af19150503d806000811461100f576040519150601f19603f3d011682016040523d82523d6000602084013e611014565b606091505b505090508061103657604051633204506f60e01b815260040160405180910390fd5b505b82546001840154604051632142170760e11b8152600160481b9092046001600160a01b0316916342842e0e916110749130913391600401614d36565b600060405180830381600087803b15801561108e57600080fd5b505af11580156110a2573d6000803e3d6000fd5b50508454600186015460408051600160481b9093046001600160a01b039081168452602084019290925233908301528993508a1691507f03b25c25e514112cb36b34989f2a8e31cebe9e34b6204acb2f3a9d047394779190606001610ccb565b6001600160a01b03811633146111725760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161093d565b61117c8282613012565b5050565b60975460ff16156111a35760405162461bcd60e51b815260040161093d90614d5a565b600260c95414156111c65760405162461bcd60e51b815260040161093d90614bb7565b600260c95560006111d683612d75565b905060006112726111e685612d37565b600384015460405163624ddda560e11b815233600482015260248101919091526001600160a01b03919091169063c49bbb4a9060440160206040518083038186803b15801561123457600080fd5b505afa158015611248573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061126c9190614d84565b84612c60565b905080156113215761128384612d37565b6003830154604051635ae2fb3960e11b81523360048201526024810184905260448101919091526001600160a01b03919091169063b5c5f67290606401600060405180830381600087803b1580156112da57600080fd5b505af11580156112ee573d6000803e3d6000fd5b505050508061011160008282546113059190614c04565b909155505060fc54611321906001600160a01b03163383613079565b83600181111561133357611333614a8b565b60405182815233907f83637d0d125e3dae88720b1ad229ce05c339c065b6282caf315dcb35a999d6d49060200160405180910390a35050600160c9555050565b60008051602061517e83398151915261138c8133612bfc565b6113946130a9565b50565b600080806113a784860186614d9d565b9250925092508260ff16600014156113c8576113c38282611f65565b6113f7565b8260ff16600114156113de576113c382826116bc565b604051631168860160e01b815260040160405180910390fd5b5050505050565b6001600160401b0382166000908152610113602090815260408083206001600160a01b038516845282529182902080548351818402810184019094528084526060939283018282801561147057602002820191906000526020600020905b81548152602001906001019080831161145c575b5050505050905092915050565b600061148b60975460ff1690565b156114a85760405162461bcd60e51b815260040161093d90614d5a565b600260c95414156114cb5760405162461bcd60e51b815260040161093d90614bb7565b600260c955670de0b6b3a76400006114e860208401358435614c1b565b1461150657604051631168860160e01b815260040160405180910390fd5b600061151386868661313c565b905060006115228435836135cd565b905060006115308284614c04565b90508115611543576115436000836135d9565b8015611554576115546001826135d9565b604051632142170760e11b81526001600160a01b038916906342842e0e9061158490339030908c90600401614d36565b600060405180830381600087803b15801561159e57600080fd5b505af11580156115b2573d6000803e3d6000fd5b5050600160c955509298975050505050505050565b600061082782612e93565b60006115e060975460ff1690565b156115fd5760405162461bcd60e51b815260040161093d90614d5a565b600260c95414156116205760405162461bcd60e51b815260040161093d90614bb7565b600260c955600061163285858561313c565b604051632142170760e11b81529091506001600160a01b038616906342842e0e9061166590339030908990600401614d36565b600060405180830381600087803b15801561167f57600080fd5b505af1158015611693573d6000803e3d6000fd5b505060fc546116af92506001600160a01b031690503383613079565b600160c955949350505050565b600260c95414156116df5760405162461bcd60e51b815260040161093d90614bb7565b600260c95560006116ef83612fd7565b6001600160a01b03841660009081526101126020908152604080832086845290915290209091506001815460ff16600381111561172e5761172e614a8b565b1461174c576040516308e0f14560e41b815260040160405180910390fd5b604051638e1eb41160e01b8152600481018490526001600160a01b03831690638e1eb4119060240160206040518083038186803b15801561178c57600080fd5b505afa1580156117a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117c49190614df4565b80611844575060405163d9548e5360e01b8152600481018490526001600160a01b0383169063d9548e539060240160206040518083038186803b15801561180a57600080fd5b505afa15801561181e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118429190614df4565b155b156118625760405163261094a960e21b815260040160405180910390fd5b60048101546002820154600383015460009183916118809190614c04565b61188a9190614c04565b835461010090046001600160401b0316600090815261010960205260408120805492935084929091906118be908490614c04565b9091555050825461010090046001600160401b0316600090815261010e6020526040812080548392906118f2908490614c04565b9091555050600283015461010a5460009161190c91612c60565b905060008185600201546119209190614c04565b90508061010560000160008282546119389190614c04565b909155505061010a8054839190600090611953908490614c04565b925050819055508085600401600082825461196e9190614c1b565b9091555050845460ff19166002178555604051637ebc460160e01b81526004810188905260009081906001600160a01b03891690637ebc46019060240160006040518083038186803b1580156119c357600080fd5b505afa1580156119d7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526119ff9190810190614c8e565b90925090506001600160a01b038216611a2b5760405163e6c4247b60e01b815260040160405180910390fd5b6000826001600160a01b031682604051611a459190614d1a565b6000604051808303816000865af19150503d8060008114611a82576040519150601f19603f3d011682016040523d82523d6000602084013e611a87565b606091505b5050905080611aa957604051633204506f60e01b815260040160405180910390fd5b898b6001600160a01b03167f18f2acac4f8af7206d6aa5341adbdb36d2847dd58b47d458fa586e99b4457735604051806040016040528088815260200189815250604051611af79190614c56565b60405180910390a35050600160c955505050505050505050565b600061082782613703565b600060606000611b2b42613745565b90506000611b3960ff613754565b905060005b81811015611e72576000611b5360ff8361375e565b90506000611b6082612fd7565b90506000611b6f600187614c04565b90505b611b7d600e87614c1b565b811015611e5e576000818152610113602090815260408083206001600160a01b0387168452909152812054905b81811015611e49576000838152610113602090815260408083206001600160a01b03891684529091528120805483908110611be757611be7614dde565b60009182526020808320909101546001600160a01b038916835261011282526040808420828552909252818320825160e08101909352805491945090829060ff166003811115611c3957611c39614a8b565b6003811115611c4a57611c4a614a8b565b8152815461010081046001600160401b03166020830152600160481b90046001600160a01b03166040820152600180830154606083015260028301546080830152600383015460a083015260049092015460c09091015290915081516003811115611cb757611cb7614a8b565b14611cc3575050611e39565b604051638e1eb41160e01b8152600481018390526001600160a01b03871690638e1eb4119060240160206040518083038186803b158015611d0357600080fd5b505afa158015611d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3b9190614df4565b15611d8c5760408051600060208201526001600160a01b03891691810191909152606081018390526001906080015b6040516020818303038152906040529b509b5050505050505050505050611e8c565b60405163d9548e5360e01b8152600481018390526001600160a01b0387169063d9548e539060240160206040518083038186803b158015611dcc57600080fd5b505afa158015611de0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e049190614df4565b15611e3657604080516001602082018190526001600160a01b038a169282019290925260608101849052608001611d6a565b50505b611e4281614e16565b9050611baa565b50508080611e5690614e16565b915050611b72565b50505080611e6b90614e16565b9050611b3e565b506000604051806020016040528060008152509350935050505b9250929050565b6000611e9f8133612bfc565b6001600160a01b038216611ec65760405163e6c4247b60e01b815260040160405180910390fd5b60fd80546001600160a01b0319166001600160a01b0384169081179091556040519081527fdeaab187cd6294a6e31ae5f53fefdfb21f250f3ae3c99fe3d7bdefe6732c3321906020015b60405180910390a15050565b60008060008061010f54611f2e61376a565b6101105461011154935093509350935090919293565b60008051602061517e833981519152611f5d8133612bfc565b61139461378d565b600260c9541415611f885760405162461bcd60e51b815260040161093d90614bb7565b600260c9556000611f9883612fd7565b6001600160a01b03841660009081526101126020908152604080832086845290915290209091506001815460ff166003811115611fd757611fd7614a8b565b14611ff5576040516308e0f14560e41b815260040160405180910390fd5b604051638e1eb41160e01b8152600481018490526001600160a01b03831690638e1eb4119060240160206040518083038186803b15801561203557600080fd5b505afa158015612049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061206d9190614df4565b61208957604051625bdcbf60e11b815260040160405180910390fd5b60048101546002820154600383015460009183916120a79190614c04565b6120b19190614c04565b835461010090046001600160401b0316600090815261010960205260408120805492935084929091906120e5908490614c04565b9091555050825461010090046001600160401b0316600090815261010e602052604081208054839290612119908490614c04565b90915550506101045461212c90836135cd565b6121369083614c04565b915061214561010454826135cd565b61214f9082614c04565b905060008183856002015486600301546121699190614c04565b6121739190614c04565b61217d9190614c04565b90508061011060008282546121929190614c1b565b909155505061010580548491906000906121ad908490614c1b565b909155505061010a80548391906000906121c8908490614c1b565b909155505060038401546121e6906121e1908390614c04565b612c78565b835460ff1916600317845560408051808201825284815260208101849052905187916001600160a01b038a16917f019ccf97cecb44d15855a7ba0d961075243a642dee90ff0bfb013edc855a522a91610ccb91869190614e31565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60006122788133612bfc565b81158061228d5750670de0b6b3a76400008210155b156122ab57604051631168860160e01b815260040160405180910390fd5b6101038290556040518281527f5c8abcc1f1bd53755e680b13c3e68ec5c3fdffe11bf764c462d795dc20684d3990602001611f10565b6060816001600160401b038111156122fb576122fb61450e565b60405190808252806020026020018201604052801561232e57816020015b60608152602001906001900390816123195790505b50905060005b828110156123ce5761239e3085858481811061235257612352614dde565b90506020028101906123649190614e45565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506137e592505050565b8282815181106123b0576123b0614dde565b602002602001018190525080806123c690614e16565b915050612334565b5092915050565b60006123e18133612bfc565b8115806123f65750670de0b6b3a76400008210155b1561241457604051631168860160e01b815260040160405180910390fd5b6101048290556040518281527f576be7f9615bb4c6e139635cf4380b1ce9f6aa425dabe6b9057c24a86cc3c97990602001611f10565b600260c954141561246d5760405162461bcd60e51b815260040161093d90614bb7565b600260c955600061247e8133612bfc565b6001600160a01b0383166124a55760405163e6c4247b60e01b815260040160405180910390fd5b610110548211156124c957604051631168860160e01b815260040160405180910390fd5b8161011060008282546124dc9190614c04565b909155505060fc546124f8906001600160a01b03168484613079565b826001600160a01b03167fcdcaff67ac16639664e5f9343c9223a1dc9c972ec367b69ae9fc1325c7be54748360405161253391815260200190565b60405180910390a25050600160c95550565b60975460ff16156125685760405162461bcd60e51b815260040161093d90614d5a565b600260c954141561258b5760405162461bcd60e51b815260040161093d90614bb7565b600260c955806125ae57604051631168860160e01b815260040160405180910390fd5b60006125b983612d75565b90506125c48361380a565b6125e3578260405163a87b5fc560e01b815260040161093d9190614e8b565b60006125ee84612f38565b905060006125fc84836135cd565b905061260785612d37565b600284015460405163ea2092f360e01b8152336004820152602481018790526044810184905260648101919091526001600160a01b03919091169063ea2092f390608401600060405180830381600087803b15801561266557600080fd5b505af1158015612679573d6000803e3d6000fd5b50505050808360010160008282546126919190614c1b565b92505081905550808360020160008282546126ac9190614c1b565b9250508190555060006126c28261010f54612c60565b90508061010f60008282546126d79190614c04565b909155506126e6905081612c78565b8560018111156126f8576126f8614a8b565b604080518781526020810185905233917ff8b564b1b7f5bb9fea632ddf0036474f68d8cec99f4b2e96a29be779871e059a910160405180910390a35050600160c95550505050565b6127936040805160e08101909152806000815260200160006001600160401b0316815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600081525090565b6001600160a01b03831660009081526101126020908152604080832085845290915290819020815160e081019092528054829060ff1660038111156127da576127da614a8b565b60038111156127eb576127eb614a8b565b8152815461010081046001600160401b03166020830152600160481b90046001600160a01b031660408201526001820154606082015260028201546080820152600382015460a082015260049091015460c0909101529392505050565b60008061285484612fd7565b60fc546040516344147cf960e11b8152600481018690526001600160a01b039182166024820152919250821690638828f9f29060440160206040518083038186803b1580156128a257600080fd5b505afa1580156128b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128da9190614df4565b6128f75760405163aec6813d60e01b815260040160405180910390fd5b6040516301c5004b60e21b8152600481018490526000906001600160a01b03831690630714012c906024016101206040518083038186803b15801561293b57600080fd5b505afa15801561294f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129739190614eb0565b9050612a0081836001600160a01b031663323c70e4876040518263ffffffff1660e01b81526004016129a791815260200190565b60006040518083038186803b1580156129bf57600080fd5b505afa1580156129d3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526129fb9190810190614f4c565b6138aa565b95945050505050565b600082815260656020526040902060010154612a258133612bfc565b610e638383613012565b6060612a3b60ff613a29565b905090565b6000612a3b6000613703565b60975460ff1615612a6f5760405162461bcd60e51b815260040161093d90614d5a565b600260c9541415612a925760405162461bcd60e51b815260040161093d90614bb7565b600260c95580612ab557604051631168860160e01b815260040160405180910390fd5b612abf82826135d9565b60fc54612ad7906001600160a01b0316333084612caf565b5050600160c955565b6001600160a01b03163b151590565b600054610100900460ff16612b165760405162461bcd60e51b815260040161093d90615016565b565b600054610100900460ff16612b3f5760405162461bcd60e51b815260040161093d90615016565b612b16613a36565b600054610100900460ff16612b6e5760405162461bcd60e51b815260040161093d90615016565b612b16613a69565b612b808282612241565b61117c5760008281526065602090815260408083206001600160a01b03851684529091529020805460ff19166001179055612bb83390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b612c068282612241565b61117c57612c1e816001600160a01b03166014613a97565b612c29836020613a97565b604051602001612c3a929190615061565b60408051601f198184030181529082905262461bcd60e51b825261093d916004016144fb565b6000818310612c6f5781612c71565b825b9392505050565b612c8461010582613c32565b9050612c9261010a82613c32565b90508061010f6000828254612ca79190614c1b565b909155505050565b612d07846323b872dd60e01b858585604051602401612cd093929190614d36565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613cc4565b50505050565b6000612c71836001600160a01b038416613d96565b6000612c71836001600160a01b038416613de5565b600080826001811115612d4c57612d4c614a8b565b14612d6357610102546001600160a01b0316610827565b5050610101546001600160a01b031690565b600080826001811115612d8a57612d8a614a8b565b14612d975761010a610827565b61010592915050565b600080612dac83612d75565b90506000612db942613745565b90506000612dd8612dc983613ed8565b612dd39042614c04565b613ee7565b90506000805b600e811015612e7457612e58612e42612e1483612dfd6001600e614c04565b612e079190614c04565b612dd39062093a80614c64565b612e1e9086614c1b565b600488016000612e2e868a614c1b565b8152602001908152602001600020546135cd565b612e53612dd3600e62093a80614c64565b613f34565b612e629083614c1b565b9150612e6d81614e16565b9050612dde565b5080612e7f87613f49565b612e899190614c1b565b9695505050505050565b600080612e9f83612d37565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612ed757600080fd5b505afa158015612eeb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f0f9190614d84565b905080612f265750670de0b6b3a764000092915050565b612c71612f3284612da0565b82613f34565b600080612f4483612d37565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015612f7c57600080fd5b505afa158015612f90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb49190614d84565b905080612fcb5750670de0b6b3a764000092915050565b612c71612f3284613f49565b6001600160a01b03808216600090815260fe6020526040812054909116806108275760405163f55484e360e01b815260040160405180910390fd5b61301c8282612241565b1561117c5760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6040516001600160a01b038316602482015260448101829052610e6390849063a9059cbb60e01b90606401612cd0565b60975460ff166130f25760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161093d565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60008061314885612fd7565b60fc546040516344147cf960e11b8152600481018790526001600160a01b039182166024820152919250821690638828f9f29060440160206040518083038186803b15801561319657600080fd5b505afa1580156131aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ce9190614df4565b6131eb5760405163aec6813d60e01b815260040160405180910390fd5b6040516301c5004b60e21b8152600481018590526000906001600160a01b03831690630714012c906024016101206040518083038186803b15801561322f57600080fd5b505afa158015613243573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132679190614eb0565b9050600061329d82846001600160a01b031663323c70e4896040518263ffffffff1660e01b81526004016129a791815260200190565b9050848110156132c05760405163a7e5f4f560e01b815260040160405180910390fd5b816060015181106132e45760405163591445fd60e01b815260040160405180910390fd5b61010f54811115613308576040516304604ced60e31b815260040160405180910390fd5b600061332f61331d61010560000154846135cd565b61010a5461010554612e539190614c1b565b9050600061335f8261335a6101035461335a4289608001516001600160401b0316612dd39190614c04565b6135cd565b9050808385606001516133729190614c04565b101561339157604051630d2693ab60e41b815260040160405180910390fd5b6000818486606001516133a49190614c04565b6133ae9190614c04565b905060006133c886608001516001600160401b0316613745565b600081815261010960205260408120805492935085929091906133ec908490614c1b565b9091555050600081815261010e602052604081208054849290613410908490614c1b565b925050819055508461010f600082825461342a9190614c04565b90915550506001600160a01b038b166000908152610112602090815260408083208951845290915290208054600190829060ff191682800217905550818160000160016101000a8154816001600160401b0302191690836001600160401b031602179055508660e001518160000160096101000a8154816001600160a01b0302191690836001600160a01b03160217905550866101000151816001018190555085816002018190555086606001518160030181905550838160040181905550610113600083815260200190815260200160002060008d6001600160a01b03166001600160a01b031681526020019081526020016000208760000151908060018154018082558091505060019003906000526020600020016000909190919091505586600001518c6001600160a01b0316336001600160a01b03167f68b109887fa59f92d688277b490d91fcd24133d99bcffaa50c75e81bdf5a4a078e8a60405180604001604052808c81526020018c8e6135a49190614c04565b90526040516135b5939291906150d6565b60405180910390a450939a9950505050505050505050565b6000612c718383613f7e565b6135e28261380a565b613601578160405163a87b5fc560e01b815260040161093d9190614e8b565b600061360c83612e93565b9050600061361a8383613f34565b90508261362685612d75565b8054600090613636908490614c1b565b90915550613645905083612c78565b61364e84612d37565b6040516340c10f1960e01b8152336004820152602481018390526001600160a01b0391909116906340c10f1990604401600060405180830381600087803b15801561369857600080fd5b505af11580156136ac573d6000803e3d6000fd5b505050508360018111156136c2576136c2614a8b565b604080518581526020810184905233917f2ec61e8cb9905b0de268566bd6b90da9952dd7672a5bf79ac53ef7f2064a09a6910160405180910390a350505050565b60008061370e61376a565b905060008161010f546137219190614c1b565b9050801561373b57613736612f328584614c1b565b610cea565b6000949350505050565b600061082762093a8083615107565b6000610827825490565b6000612c718383614040565b61010f5461010a54610105546000929161378391614c1b565b612a3b9190614c04565b60975460ff16156137b05760405162461bcd60e51b815260040161093d90614d5a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861311f3390565b6060612c7183836040518060600160405280602781526020016151576027913961406a565b60008061381683612d75565b9050806001015481600001541180612c71575061383283612d37565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561386a57600080fd5b505afa15801561387e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138a29190614d84565b159392505050565b6000806000905060006138bd8451613ee7565b905060006138cf866040015183613f34565b905060006138e1876060015184613f34565b905060005b8651811015613a1d5760fd5487516001600160a01b039091169063d3e4d5fd9089908490811061391857613918614dde565b60200260200101516000015189848151811061393657613936614dde565b60200260200101516020015186868d60a001518e608001516139578d613703565b6040516001600160e01b031960e08a901b1681526001600160a01b0390971660048801526024870195909552604486019390935260648501919091526001600160401b0390811660848501521660a483015260c482015260e40160206040518083038186803b1580156139c957600080fd5b505afa1580156139dd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a019190614d84565b613a0b9086614c1b565b9450613a1681614e16565b90506138e6565b50929695505050505050565b60606000612c718361413d565b600054610100900460ff16613a5d5760405162461bcd60e51b815260040161093d90615016565b6097805460ff19169055565b600054610100900460ff16613a905760405162461bcd60e51b815260040161093d90615016565b600160c955565b60606000613aa6836002614c64565b613ab1906002614c1b565b6001600160401b03811115613ac857613ac861450e565b6040519080825280601f01601f191660200182016040528015613af2576020820181803683370190505b509050600360fc1b81600081518110613b0d57613b0d614dde565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110613b3c57613b3c614dde565b60200101906001600160f81b031916908160001a9053506000613b60846002614c64565b613b6b906001614c1b565b90505b6001811115613be3576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613b9f57613b9f614dde565b1a60f81b828281518110613bb557613bb5614dde565b60200101906001600160f81b031916908160001a90535060049490941c93613bdc81615129565b9050613b6e565b508315612c715760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161093d565b600080613c508460000154613c4b866001015486612c60565b612c60565b905080846001016000828254613c669190614c04565b9250508190555080846003016000828254613c819190614c1b565b9091555050835481908590600090613c9a908490614c04565b92505081905550806101116000828254613cb49190614c1b565b90915550610cea90508184614c04565b6000613d19826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166141999092919063ffffffff16565b805190915015610e635780806020019051810190613d379190614df4565b610e635760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161093d565b6000818152600183016020526040812054613ddd57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610827565b506000610827565b60008181526001830160205260408120548015613ece576000613e09600183614c04565b8554909150600090613e1d90600190614c04565b9050818114613e82576000866000018281548110613e3d57613e3d614dde565b9060005260206000200154905080876000018481548110613e6057613e60614dde565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613e9357613e93615140565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610827565b6000915050610827565b600061082762093a8083614c64565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f21821115613f2657604051633492ffd960e01b81526004810183905260240161093d565b50670de0b6b3a76400000290565b6000612c7183670de0b6b3a7640000846141a8565b600080613f5583612d75565b90508060010154816000015411613f6d576000612c71565b60018101548154612c719190614c04565b60008080600019848609848602925082811083820303915050670de0b6b3a76400008110613fc25760405163698d9a0160e11b81526004810182905260240161093d565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff811182613ffc5780670de0b6b3a7640000850401945050505050610827565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b600082600001828154811061405757614057614dde565b9060005260206000200154905092915050565b60606001600160a01b0384163b6140d25760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b606482015260840161093d565b600080856001600160a01b0316856040516140ed9190614d1a565b600060405180830381855af49150503d8060008114614128576040519150601f19603f3d011682016040523d82523d6000602084013e61412d565b606091505b5091509150612e89828286614276565b60608160000180548060200260200160405190810160405280929190818152602001828054801561418d57602002820191906000526020600020905b815481526020019060010190808311614179575b50505050509050919050565b6060610cea84846000856142af565b6000808060001985870985870292508281108382030391505080600014156141e3578382816141d9576141d96150f1565b0492505050612c71565b83811061420d57604051631dcf306360e21b8152600481018290526024810185905260440161093d565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b60608315614285575081612c71565b8251156142955782518084602001fd5b8160405162461bcd60e51b815260040161093d91906144fb565b6060824710156143105760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161093d565b6001600160a01b0385163b6143675760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161093d565b600080866001600160a01b031685876040516143839190614d1a565b60006040518083038185875af1925050503d80600081146143c0576040519150601f19603f3d011682016040523d82523d6000602084013e6143c5565b606091505b50915091506143d5828286614276565b979650505050505050565b8280546143ec90614b50565b90600052602060002090601f01602090048101928261440e5760008555614454565b82601f1061442757805160ff1916838001178555614454565b82800160010185558215614454579182015b82811115614454578251825591602001919060010190614439565b50614460929150614464565b5090565b5b808211156144605760008155600101614465565b60006020828403121561448b57600080fd5b81356001600160e01b031981168114612c7157600080fd5b60005b838110156144be5781810151838201526020016144a6565b83811115612d075750506000910152565b600081518084526144e78160208601602086016144a3565b601f01601f19169290920160200192915050565b602081526000612c7160208301846144cf565b634e487b7160e01b600052604160045260246000fd5b60405161012081016001600160401b03811182821017156145475761454761450e565b60405290565b604080519081016001600160401b03811182821017156145475761454761450e565b604051601f8201601f191681016001600160401b03811182821017156145975761459761450e565b604052919050565b60006001600160401b038211156145b8576145b861450e565b50601f01601f191660200190565b60006145d96145d48461459f565b61456f565b90508281528383830111156145ed57600080fd5b828260208301376000602084830101529392505050565b6001600160a01b038116811461139457600080fd5b600080600080600060a0868803121561463157600080fd5b85356001600160401b0381111561464757600080fd5b8601601f8101881361465857600080fd5b614667888235602084016145c6565b955050602086013561467881614604565b9350604086013561468881614604565b9250606086013561469881614604565b915060808601356146a881614604565b809150509295509295909350565b6000806000606084860312156146cb57600080fd5b83356146d681614604565b95602085013595506040909401359392505050565b6000806000806080858703121561470157600080fd5b843561470c81614604565b9350602085013561471c81614604565b92506040850135915060608501356001600160401b0381111561473e57600080fd5b8501601f8101871361474f57600080fd5b61475e878235602084016145c6565b91505092959194509250565b6000806040838503121561477d57600080fd5b823561478881614604565b9150602083013561479881614604565b809150509250929050565b8035600281106147b257600080fd5b919050565b6000602082840312156147c957600080fd5b612c71826147a3565b6000602082840312156147e457600080fd5b5035919050565b600080604083850312156147fe57600080fd5b82359150602083013561479881614604565b6000806040838503121561482357600080fd5b823561482e81614604565b946020939093013593505050565b6000806040838503121561484f57600080fd5b61482e836147a3565b6000806020838503121561486b57600080fd5b82356001600160401b038082111561488257600080fd5b818501915085601f83011261489657600080fd5b8135818111156148a557600080fd5b8660208285010111156148b757600080fd5b60209290920196919550909350505050565b6001600160401b038116811461139457600080fd5b600080604083850312156148f157600080fd5b8235614788816148c9565b6020808252825182820181905260009190848201906040850190845b8181101561493457835183529284019291840191600101614918565b50909695505050505050565b60008060008060a0858703121561495657600080fd5b843561496181614604565b9350602085013592506040850135915060a0850186101561498157600080fd5b509194909350909160600190565b8215158152604060208201526000610cea60408301846144cf565b6000602082840312156149bc57600080fd5b8135612c7181614604565b600080602083850312156149da57600080fd5b82356001600160401b03808211156149f157600080fd5b818501915085601f830112614a0557600080fd5b813581811115614a1457600080fd5b8660208260051b85010111156148b757600080fd5b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015614a7e57603f19888603018452614a6c8583516144cf565b94509285019290850190600101614a50565b5092979650505050505050565b634e487b7160e01b600052602160045260246000fd5b815160e082019060048110614ab857614ab8614a8b565b808352506001600160401b03602084015116602083015260018060a01b036040840151166040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015292915050565b6020808252825182820181905260009190848201906040850190845b818110156149345783516001600160a01b031683529284019291840191600101614b2b565b600181811c90821680614b6457607f821691505b60208210811415614b8557634e487b7160e01b600052602260045260246000fd5b50919050565b60ff8116811461139457600080fd5b600060208284031215614bac57600080fd5b8151612c7181614b8b565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600082821015614c1657614c16614bee565b500390565b60008219821115614c2e57614c2e614bee565b500190565b8060005b6002811015612d07578151845260209384019390910190600101614c37565b604081016108278284614c33565b6000816000190483118215151615614c7e57614c7e614bee565b500290565b80516147b281614604565b60008060408385031215614ca157600080fd5b8251614cac81614604565b60208401519092506001600160401b03811115614cc857600080fd5b8301601f81018513614cd957600080fd5b8051614ce76145d48261459f565b818152866020838501011115614cfc57600080fd5b614d0d8260208301602086016144a3565b8093505050509250929050565b60008251614d2c8184602087016144a3565b9190910192915050565b6001600160a01b039384168152919092166020820152604081019190915260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b600060208284031215614d9657600080fd5b5051919050565b600080600060608486031215614db257600080fd5b8335614dbd81614b8b565b92506020840135614dcd81614604565b929592945050506040919091013590565b634e487b7160e01b600052603260045260246000fd5b600060208284031215614e0657600080fd5b81518015158114612c7157600080fd5b6000600019821415614e2a57614e2a614bee565b5060010190565b82815260608101612c716020830184614c33565b6000808335601e19843603018112614e5c57600080fd5b8301803591506001600160401b03821115614e7657600080fd5b602001915036819003821315611e8c57600080fd5b6020810160028310614e9f57614e9f614a8b565b91905290565b80516147b2816148c9565b60006101208284031215614ec357600080fd5b614ecb614524565b82518152614edb60208401614c83565b60208201526040830151604082015260608301516060820152614f0060808401614ea5565b6080820152614f1160a08401614ea5565b60a0820152614f2260c08401614c83565b60c0820152614f3360e08401614c83565b60e0820152610100928301519281019290925250919050565b60006020808385031215614f5f57600080fd5b82516001600160401b0380821115614f7657600080fd5b818501915085601f830112614f8a57600080fd5b815181811115614f9c57614f9c61450e565b614faa848260051b0161456f565b818152848101925060069190911b830184019087821115614fca57600080fd5b928401925b818410156143d55760408489031215614fe85760008081fd5b614ff061454d565b8451614ffb81614604565b81528486015186820152835260409093019291840191614fcf565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516150998160178501602088016144a3565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516150ca8160288401602088016144a3565b01602801949350505050565b8381526020810183905260808101610cea6040830184614c33565b634e487b7160e01b600052601260045260246000fd5b60008261512457634e487b7160e01b600052601260045260246000fd5b500490565b60008161513857615138614bee565b506000190190565b634e487b7160e01b600052603160045260246000fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65645c91514091af31f62f596a314af7d5be40146b2f2355969392f055e12e0982fba26469706673582212202986f331d164cbf71548f6a5d92fce5174c028183d9ea580d2ab9855d91f468464736f6c63430008090033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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