ETH Price: $2,880.15 (-2.68%)

Contract

0x3A0F4944920C28B3a266F6DCF029dE5bECfB7946

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
LoanVault

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 500 runs

Other Settings:
default evmVersion
File 1 of 30 : LoanVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// (C) Florence Finance, 2022 - https://florence.finance/

pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

import "./FlorinToken.sol";
import "./FlorinTreasury.sol";
import "./Util.sol";
import "./Errors.sol";

/// @title LoanVault
/// @dev
contract LoanVault is ERC4626Upgradeable, ERC20PermitUpgradeable, OwnableUpgradeable, PausableUpgradeable {
    using MathUpgradeable for uint256;

    // LOAN EVENTS
    event RepayLoan(uint256 loanAmount);
    event WriteDownLoan(uint256 estimatedDefaultAmount);
    event WriteUpLoan(uint256 recoveredAmount);
    event FinalizeDefault(uint256 definiteDefaultAmount);

    // REWARDS EVENTS
    event DepositRewards(address from, uint256 rewards);
    event SetApr(uint256 apr);
    event SetFundingFee(uint256 fundingFee);

    // FUNDING EVENTS
    event ExecuteFundingAttempt(address indexed funder, IERC20Upgradeable fundingToken, uint256 fundingTokenAmount, uint256 florinTokens, uint256 shares);
    event AddFundingRequest(uint256 fundingRequestId, uint256 florinTokens);
    event CancelFundingRequest(uint256 fundingRequestId);

    event SetFundingTokenChainLinkFeed(
        IERC20Upgradeable fundingToken,
        AggregatorV3Interface fundingTokenChainLinkFeed,
        bool invertFundingTokenChainLinkFeedAnswer_,
        uint256 chainLinkFeedHeartBeat_
    );
    event SetFundingToken(IERC20Upgradeable token, bool accepted);
    event SetPrimaryFunder(address primaryFunder, bool accepted);
    event SetDelegate(address delegate);
    event CreateFundingAttempt(address indexed funder, IERC20Upgradeable fundingToken, uint256 fundingTokenAmount, uint256 florinTokens, uint256 shares);
    event ApproveFundingAttempt(uint256 fundingAttemptId);
    event RejectFundingAttempt(uint256 fundingAttemptId, string reason);
    event FundingAttemptFailed(uint256 fundId, string reason);
    event SetFundApprover(address funderApprover);

    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////CORE////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////

    /// @dev FlorinTreasury contract. Used by functions which require EUR transfers
    FlorinTreasury public florinTreasury;

    /// @dev Sum of capital actively deployed in loans (does not include defaults) [18 decimals]
    uint256 public loansOutstanding;

    /// @dev Amount of vault debt. This is used to handle edge cases which should not occur outside of extreme situations. Will be 0 usually. [18 decimals]
    uint256 public debt;

    /// @dev Sum of recent loan write downs that are not definite defaults yet. This is used to cap the writeUpLoan function to the upside in order to prevent abuse. [18 decimals]
    uint256 public loanWriteDown;

    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////REWARDS/////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////

    /// @dev Timestamp of when outstandingRewardsSnapshot was updated the last time [unix-timestamp]
    uint256 public outstandingRewardsSnapshotTimestamp;

    /// @dev Rewards that need to be deposited into the vault in order match the APR at the moment of outstandingRewardsSnapshotTimestamp [18 decimals]
    uint256 public outstandingRewardsSnapshot;

    /// @dev APR of the vault [16 decimals (e.g. 5%=0.05*10^18]
    uint256 public apr;

    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////FUNDING/////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////

    /// @dev Constant for FundingRequest id to signal that there is no currently active FundingRequest
    uint256 private constant NO_FUNDING_REQUEST = type(uint256).max;

    /// @dev A FundingRequest enables the delegate to raise money from primaryFunders
    struct FundingRequest {
        /// @dev Identifier for the FundingRequest
        uint256 id;
        /// @dev Delegate which created the FundingRequest
        address delegate;
        /// @dev Required funding [18 decimals (FLR)]
        uint256 amountRequested;
        /// @dev Amount filled / provided funding [18 decimals (FLR)]
        uint256 amountFilled;
        /// @dev State (see FundingRequestState enum)
        FundingRequestState state;
    }

    /// @dev States for the lifecycle of a FundingRequest
    enum FundingRequestState {
        OPEN,
        FILLED,
        PARTIALLY_FILLED,
        CANCELLED
    }

    /// @dev A Delegate creates a new pending funding attempt to be approved or rejected by the fund approver
    /// enables the delegate to raise money from primaryFunders
    struct FundingAttempt {
        uint256 id;
        address funder;
        IERC20Upgradeable fundingToken;
        uint256 fundingTokenAmount;
        uint256 flrFundingAmount;
        uint256 shares;
        uint256 fillableFundingTokenAmount;
        uint256 maxSlippage;
        FundingAttemptState state;
    }

    /// @dev The different states of a funding attempt
    enum FundingAttemptState {
        PENDING,
        EXECUTED,
        REJECTED,
        FAILED
    }

    /// @dev Enforces a function can only be executed by the vaults delegate
    modifier onlyDelegate() {
        if (delegate != _msgSender()) {
            revert Errors.CallerMustBeDelegate();
        }
        _;
    }

    /// @dev Enforces a function can only be executed by the vaults delegate
    modifier onlyFundApprover() {
        if (fundApprover != _msgSender()) {
            revert Errors.CallerMustBeFundApprover();
        }
        _;
    }

    /// @dev Delegate of the vault. Can create/cancel FundingRequests and call loan control functions
    address public delegate;

    /// @dev PrimaryFunders are allowed to fill open and partially filled FundingRequests. address => primaryFunder status [true/false]
    mapping(address => bool) private primaryFunders;

    /// @dev Contains all funding requests
    FundingRequest[] public fundingRequests;

    /// @dev Id of the last processed funding request
    uint256 public lastProcessedFundingRequestId;

    /// @dev Token => whether the token can be used to fill FundingRequests
    mapping(IERC20Upgradeable => bool) private fundingTokens;

    /// @dev All funding tokens
    IERC20Upgradeable[] private _fundingTokens;

    /// @dev FundingToken => ChainLink feed which provides a conversion rate for the fundingToken to the vaults loans base currency (e.g. USDC => EURSUD)
    mapping(IERC20Upgradeable => AggregatorV3Interface) private fundingTokenChainLinkFeeds;

    /// @dev FundingToken => whether the data provided by the ChainLink feed should be inverted (not all ChainLink feeds are Token->BaseCurrency, some could be BaseCurrency->Token)
    mapping(IERC20Upgradeable => bool) private invertFundingTokenChainLinkFeedAnswer;

    /// @dev ChainLink => uint256 After how many seconds the ChainLink Feed is updated // e.g. EUR/USD: 60 * 60 * 24 = 86400 seconds per day
    mapping(IERC20Upgradeable => uint256) private chainLinkFeedHeartBeat;

    /// Array including all open funding requests
    FundingAttempt[] public fundingAttempts;

    /// @dev The address of the approver who approves pending funding attempts
    address public fundApprover;

    /// @dev Used to correct the exchange rate of the Loan Vault when funding [16 decimals] (e.g. 1%=0.01*10^18)
    uint256 public fundingFee;

    //<INSERT NEW STATE VARIABLES ABOVE THIS LINE>

    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////CORE////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {} // solhint-disable-line

    /// @dev Initializes the LoanVault
    /// @param name ERC20 name
    /// @param symbol ERC20 symbol
    /// @param florinTreasury_ see FlorinTreasury contract
    function initialize(string calldata name, string calldata symbol, FlorinTreasury florinTreasury_) external initializer {
        florinTreasury = florinTreasury_;

        // solhint-disable-next-line not-rely-on-time
        outstandingRewardsSnapshotTimestamp = block.timestamp;
        __ERC20_init_unchained(name, symbol);
        __ERC20Permit_init(name);
        __Context_init_unchained();
        __Ownable_init_unchained();
        __Pausable_init_unchained();
        __ERC4626_init_unchained(IERC20MetadataUpgradeable(address(florinTreasury.florinToken())));

        inflationAttackProtectionInitalization();

        _pause();
    }

    /// @dev Minting some dead shares on initialization to avoid inflation attacks against the first depositor
    //       see https://github.com/OpenZeppelin/openzeppelin-contracts/issues/3706#issuecomment-1297230505
    function inflationAttackProtectionInitalization() internal {
        //The below two lines are equivalent of depositting 1 FLR to the vault in our case
        _mint(address(this), 10 ** 18); //Mint 1 share
        outstandingRewardsSnapshot += 10 ** 18; //Add 1 FLR as a reward this effectively increases totalAssets() by 1 FLR

        loansOutstanding += 10 ** 18; //Increase loansOutstanding to make sure this deposit has no impact on loan logic
    }

    /// @dev Overwritten to return always 18 decimals for Loan Vault asset.
    function decimals() public view virtual override(ERC4626Upgradeable, ERC20Upgradeable) returns (uint8) {
        return 18;
    }

    /// @dev Pauses the LoanVault. Check functions with whenPaused/whenNotPaused modifier
    function pause() external onlyOwner {
        _pause();
    }

    /// @dev Unpauses the LoanVault. Check functions with whenPaused/whenNotPaused modifier
    function unpause() external onlyOwner {
        _unpause();
    }

    /// @dev The contract owner sets the loansOutstanding. This is used for the initial deployment on Arbitrum.
    /// @param value The value that loansOutstanding is set to
    function setLoansOutstanding(uint256 value) external onlyOwner {
        loansOutstanding = value;
    }

    /// @dev Unique identifier of the LoanVault
    /// @return the id which is the symbol of the vaults asset token
    function id() external view returns (string memory) {
        return symbol();
    }

    /// @dev See {IERC4626-maxDeposit}. Overridden to cap investment to loansOutstanding
    /// @dev Determines how many FLR can currently be deposited into the LoanVault.
    ///      To avoid oversubscription of investment and consequent dilution of rewards this is capped to loansOutstanding.
    /// @return amount of FLR that can be deposited in the LoanVault currently.
    function maxDeposit(address) public view override returns (uint256) {
        if (loansOutstanding <= totalAssets() || debt > 0 || super.paused()) return 0;
        return loansOutstanding - totalAssets();
    }

    /// @dev Increase the vaults assets by minting Florin. If the vault is in debt the debt will be reduced first.
    /// @param amount of FLR to mint into the vault
    function _increaseAssets(uint256 amount) internal {
        if (debt < amount) {
            florinTreasury.mint(address(this), amount - debt);
            debt = 0;
        } else {
            debt -= amount;
        }
    }

    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////LOAN////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////

    /// @dev Repayment of a matured loan.
    /// @param loanAmount to be repaid in FlorinTreasury.eurToken [18 decimals, see FlorinTreasury.depositEUR]
    function repayLoan(uint256 loanAmount) external onlyDelegate whenNotPaused {
        if (loanAmount > loansOutstanding) {
            revert Errors.LoanAmountMustBeLessOrEqualLoansOutstanding();
        }

        _snapshotOutstandingRewards();
        loansOutstanding -= loanAmount;

        depositEURToTreasury(loanAmount);
        emit RepayLoan(loanAmount);
    }

    /// @dev Write down of loansOutstanding in case of a suspected loan default
    /// @param estimatedDefaultAmount the estimated default amount. Can be corrected via writeUpLoan in terms of recovery
    function writeDownLoan(uint256 estimatedDefaultAmount) external onlyDelegate whenNotPaused {
        if (estimatedDefaultAmount > loansOutstanding) {
            revert Errors.EstimatedDefaultAmountMustBeLessOrEqualLoansOutstanding();
        }
        _snapshotOutstandingRewards();
        uint256 flrBurnAmount = MathUpgradeable.min(estimatedDefaultAmount, IERC20Upgradeable(asset()).balanceOf(address(this)));

        florinTreasury.florinToken().burn(flrBurnAmount);
        loansOutstanding -= estimatedDefaultAmount;
        debt += estimatedDefaultAmount - flrBurnAmount;
        loanWriteDown += estimatedDefaultAmount;
        emit WriteDownLoan(estimatedDefaultAmount);
    }

    /// @dev Write up of loansOutstanding in case of a previously written down loan recovering
    /// @param recoveredAmount the amount the loan has recovered for
    function writeUpLoan(uint256 recoveredAmount) external onlyDelegate whenNotPaused {
        if (recoveredAmount > loanWriteDown) {
            revert Errors.RecoveredAmountMustBeLessOrEqualLoanWriteDown();
        }

        _snapshotOutstandingRewards();

        loansOutstanding += recoveredAmount;
        loanWriteDown -= recoveredAmount;
        _increaseAssets(recoveredAmount);
        emit WriteUpLoan(recoveredAmount);
    }

    /// @dev Lock-in a previously written down loan once it is clear it will not recover any more.
    /// @param definiteDefaultAmount the amount of the loan that has defaulted
    function finalizeDefault(uint256 definiteDefaultAmount) external onlyDelegate whenNotPaused {
        if (definiteDefaultAmount > loanWriteDown) {
            revert Errors.DefiniteDefaultAmountMustBeLessOrEqualLoanWriteDown();
        }

        loanWriteDown -= definiteDefaultAmount;
        emit FinalizeDefault(definiteDefaultAmount);
    }

    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////REWARDS/////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////

    /// @dev Persists the currently outstanding rewards as calculated by calculateOutstandingRewards to protect it
    /// from being distorted by changes to the underlying variables. This should be called before every deposit/withdraw or other
    //  operation that potentially affects the result of calculateOutstandingRewards
    function _snapshotOutstandingRewards() internal {
        outstandingRewardsSnapshot = calculateOutstandingRewards();
        // solhint-disable-next-line not-rely-on-time
        outstandingRewardsSnapshotTimestamp = block.timestamp;
    }

    /// @dev Calculates the amount of rewards that are owed to the vault at the current moment.
    /// This calculation is based on apr as well as the amount of depositors at the current moment.
    /// @return amount of outstanding rewards [18 decimals]
    function calculateOutstandingRewards() public view returns (uint256) {
        uint256 vaultFlrBalance = IERC20Upgradeable(asset()).balanceOf(address(this));
        // solhint-disable-next-line not-rely-on-time
        uint256 timeSinceLastOutstandingRewardsSnapshot = block.timestamp - outstandingRewardsSnapshotTimestamp;

        if (loansOutstanding == 0 || vaultFlrBalance == 0 || apr == 0 || timeSinceLastOutstandingRewardsSnapshot == 0) {
            return outstandingRewardsSnapshot;
        }

        uint256 absoluteFundingRequestSupplied = MathUpgradeable.min(vaultFlrBalance, loansOutstanding);
        uint256 rewardsPerSecondWeighted = absoluteFundingRequestSupplied.mulDiv(apr, (10 ** 18) * 365 * 24 * 60 * 60, MathUpgradeable.Rounding.Down);
        return outstandingRewardsSnapshot + rewardsPerSecondWeighted * timeSinceLastOutstandingRewardsSnapshot;
    }

    /** @dev See {IERC4626-totalAssets}. */
    function totalAssets() public view virtual override returns (uint256) {
        return IERC20Upgradeable(asset()).balanceOf(address(this)) + calculateOutstandingRewards();
    }

    /// @dev Deposit outstanding rewards to the vault. This function expects the rewards in FlorinTreasury.eurToken
    /// and mints an equal amount of FLR into the vault. The amount of rewards is capped to the amount of outstandingRewardsSnapshot
    /// @param rewards to be deposited in FlorinTreasury.eurToken [18 decimals, see FlorinTreasury.depositEUR]
    function depositRewards(uint256 rewards) external whenNotPaused {
        _snapshotOutstandingRewards();

        rewards = MathUpgradeable.min(outstandingRewardsSnapshot, rewards);
        outstandingRewardsSnapshot -= rewards;

        if (rewards == 0) {
            revert Errors.EffectiveRewardAmountMustBeGreaterThanZero();
        }

        _increaseAssets(rewards);
        depositEURToTreasury(rewards);

        emit DepositRewards(_msgSender(), rewards);
    }

    function depositEURToTreasury(uint256 amountEur) internal {
        IERC20Upgradeable eurToken = florinTreasury.eurToken();

        uint256 transferAmount = Util.convertDecimals(amountEur, 18, Util.getERC20Decimals(eurToken));
        if (transferAmount == 0) {
            revert Errors.TransferAmountMustBeGreaterThanZero();
        }
        SafeERC20Upgradeable.safeTransferFrom(eurToken, _msgSender(), address(florinTreasury), transferAmount);
    }

    /// @dev Set the APR for the vault. This does NOT affect rewards retroactively.
    /// @param _apr the APR
    function setApr(uint256 _apr) external onlyOwner {
        if (_apr != 0) {
            if (_apr < 1e14 || _apr > 1e18) {
                // 0.01% - 100%
                revert Errors.AprOutOfBounds();
            }
        }

        _snapshotOutstandingRewards();
        apr = _apr;
        emit SetApr(apr);
    }

    /// @dev Set the funding fee for the vault. Do not change this fee in between a funding request and funding approval.
    /// @param _fundingFee the funding fee
    function setFundingFee(uint256 _fundingFee) external onlyOwner {
        if (_fundingFee != 0) {
            if (_fundingFee < 1e14 || _fundingFee > 1e17) {
                // 0.01% - 10%
                revert Errors.FundingFeeOutOfBounds();
            }
        }
        fundingFee = _fundingFee;
        emit SetFundingFee(_fundingFee);
    }

    /**
     * @dev Deposit/mint common workflow. Overriden to inject _snapshotOutstandingRewards call and whenNotPaused
     */
    function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual override whenNotPaused {
        _snapshotOutstandingRewards();
        return super._deposit(caller, receiver, assets, shares);
    }

    /**
     * @dev Withdraw/redeem common workflow. Overriden to inject _snapshotOutstandingRewards call and whenNotPaused
     */
    function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares) internal virtual override whenNotPaused {
        _snapshotOutstandingRewards();
        return super._withdraw(caller, receiver, owner, assets, shares);
    }

    /////////////////////////////////////////////////////////////////////////
    /////////////////////////////FUNDING/////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////

    /// @dev Create a pending open funding request that will be approved or rejected by the fund approver
    /// The funds will be sent to the delegate in the process. In return the funder receive FLR based on the current exchange rate of their currency
    /// @param fundingToken The funding Token address (e.g. ERC20 USDT)
    /// @param fundingTokenAmount The amount of funding Token to use for creating the open funding request
    /// @param maxSlippage The maximum accepted slippage allowed by the primary funder between creating and approving the pendingOpenFundingRequest (e.g. 1% slippage = 0.01 * 10^18)
    function createFundingAttempt(IERC20Upgradeable fundingToken, uint256 fundingTokenAmount, uint256 maxSlippage) external whenNotPaused {
        (, uint256 flrFundingAmount, , uint256 shares, uint256 fillableFundingTokenAmount) = _previewFund(_msgSender(), fundingToken, fundingTokenAmount);

        if (fundingToken.allowance(_msgSender(), address(this)) < fillableFundingTokenAmount) {
            revert Errors.InsufficientAllowance();
        }

        uint256 openPendingFundingRequestId = fundingAttempts.length;
        fundingAttempts.push(
            FundingAttempt(
                openPendingFundingRequestId,
                _msgSender(),
                fundingToken,
                fundingTokenAmount,
                flrFundingAmount,
                shares,
                fillableFundingTokenAmount,
                maxSlippage,
                FundingAttemptState.PENDING
            )
        );
        emit CreateFundingAttempt(_msgSender(), fundingToken, fillableFundingTokenAmount, flrFundingAmount, shares);
    }

    /// @dev execute an open pending funding request. The funds will be sent to the delegate in the process. In return the funder receives FLR
    /// based on the current exchange rate of their currency
    /// @param fundingToken The funding Token address (e.g. ERC20 USDT)
    /// @param fundingTokenAmount The amount of funding Token to use for executing the open funding request
    /// @param funder The funder's address
    function executeFundingAttempt(IERC20Upgradeable fundingToken, uint256 fundingTokenAmount, address funder) internal {
        (uint256 nextOpenFundingRequestId, uint256 flrFundingAmount, uint256 uncorrectedFlrFundingAmount, uint256 shares, uint256 fillableFundingTokenAmount) = _previewFund(
            funder,
            fundingToken,
            fundingTokenAmount
        );

        FundingRequest storage currentFundingRequest = fundingRequests[nextOpenFundingRequestId];

        lastProcessedFundingRequestId = currentFundingRequest.id;

        currentFundingRequest.state = FundingRequestState.PARTIALLY_FILLED;

        currentFundingRequest.amountFilled += uncorrectedFlrFundingAmount;

        if (currentFundingRequest.amountRequested == currentFundingRequest.amountFilled) {
            currentFundingRequest.state = FundingRequestState.FILLED;
        }

        _snapshotOutstandingRewards();

        loansOutstanding += uncorrectedFlrFundingAmount;

        _mint(funder, shares);

        florinTreasury.mint(address(this), flrFundingAmount);

        SafeERC20Upgradeable.safeTransferFrom(fundingToken, funder, currentFundingRequest.delegate, fillableFundingTokenAmount);

        emit ExecuteFundingAttempt(funder, fundingToken, fillableFundingTokenAmount, flrFundingAmount, shares);
    }

    /// @dev Preview the amount of shares that a user will receive according to the amount of funding Token sent to the Loan Vault and converted into assets (FLRs)
    /// In case that fundingToken is USDT, the current exchange rate is taken into account
    /// @param wallet The funder's wallet address
    /// @param fundingToken The funding Token address (e.g. ERC20 USDT)
    /// @param fundingTokenAmount The amount of the funding Token that will be used to fund
    /// @return Amount of shares
    function previewFund(address wallet, IERC20Upgradeable fundingToken, uint256 fundingTokenAmount) external view returns (uint256) {
        (, , , uint256 shares, ) = _previewFund(wallet, fundingToken, fundingTokenAmount);
        return shares;
    }

    /// @dev Preview the amount of shares that a user will receive according to the amount of funding Token sent to the Loan Vault and converted into assets (FLRs)
    /// In case that fundingToken is USDT, the current exchange rate is taken into account
    /// @param funder The funder's wallet address
    /// @param fundingToken The funding Token address (e.g. ERC20 USDT)
    /// @param fundingTokenAmount The amount of the funding Token that will be used to fund
    /// @return current funding request id, corrected FLR funding amount, shares, corrected funding token amount
    function _previewFund(address funder, IERC20Upgradeable fundingToken, uint256 fundingTokenAmount) internal view returns (uint256, uint256, uint256, uint256, uint256) {
        if (!isPrimaryFunder(funder)) revert Errors.CallerMustBePrimaryFunder();
        if (fundingTokenAmount == 0) revert Errors.FundingAmountMustBeGreaterThanZero();
        if (!isFundingToken(fundingToken)) revert Errors.UnrecognizedFundingToken();
        if (getNextFundingRequestId() == NO_FUNDING_REQUEST) revert Errors.NoOpenFundingRequest();

        FundingRequest storage currentFundingRequest = fundingRequests[getNextFundingRequestId()];

        (uint256 exchangeRate, uint256 exchangeRateDecimals) = getFundingTokenExchangeRate(fundingToken);

        // uint256 currentFundingNeedInFLR = currentFundingRequest.amountRequested - currentFundingRequest.amountFilled;

        uint256 currentFundingNeedInFundingToken = (Util.convertDecimalsERC20(
            (currentFundingRequest.amountRequested - currentFundingRequest.amountFilled),
            florinTreasury.florinToken(),
            fundingToken
        ) * exchangeRate) / (uint256(10) ** exchangeRateDecimals);

        uint256 flrFundingAmount;

        if (fundingTokenAmount > currentFundingNeedInFundingToken) {
            fundingTokenAmount = currentFundingNeedInFundingToken;
            flrFundingAmount = (currentFundingRequest.amountRequested - currentFundingRequest.amountFilled); // currentFundingNeedInFLR;
        } else {
            flrFundingAmount = ((Util.convertDecimalsERC20(fundingTokenAmount, fundingToken, florinTreasury.florinToken()) * (uint256(10) ** exchangeRateDecimals)) / exchangeRate);
        }
        uint256 correctedFlrFundingAmount = (flrFundingAmount * (10 ** 18 - fundingFee)) / 10 ** 18;
        // uint256 correctedFlrFundingAmount = flrFundingAmount; // (flrFundingAmount * 10 ** 18 ) / 10 ** 18;

        return (currentFundingRequest.id, correctedFlrFundingAmount, flrFundingAmount, previewDeposit(correctedFlrFundingAmount), fundingTokenAmount);
    }

    /// @dev A Delegate creates a new OPEN funding request
    /// enables the delegate to raise money from primaryFunders
    /// emits event AddFundingRequest if successful
    /// @param amountRequested the requested amount in FLR
    function addFundingRequest(uint256 amountRequested) external onlyDelegate whenNotPaused {
        if (amountRequested == 0) {
            revert Errors.AmountRequestedMustBeGreaterThanZero();
        }

        uint256 fundingRequestId = fundingRequests.length;
        fundingRequests.push(FundingRequest(fundingRequestId, _msgSender(), amountRequested, 0, FundingRequestState.OPEN));
        emit AddFundingRequest(fundingRequestId, amountRequested);
    }

    /// @dev A Delegate cancels an OPEN funding request by its funding request id
    /// emits event CancelFundingRequest if successful
    /// @param fundingRequestId The funding request id
    function cancelFundingRequest(uint256 fundingRequestId) public whenNotPaused {
        if (fundingRequestId >= fundingRequests.length) {
            revert Errors.FundingRequestDoesNotExist();
        }

        FundingRequest storage fundingRequest = fundingRequests[fundingRequestId];

        if (_msgSender() != owner()) {
            if (fundingRequest.delegate != _msgSender()) {
                revert Errors.CallerMustBeOwnerOrDelegate();
            }

            if (fundingRequest.state != FundingRequestState.OPEN) {
                revert Errors.DelegateCanOnlyCancelOpenFundingRequests();
            }
        }

        fundingRequest.state = FundingRequestState.CANCELLED;
        emit CancelFundingRequest(fundingRequestId);
    }

    /// @dev Get the next open or partially filled funding request id in the array of fundingRequests
    /// @return Funding request id of next open or partially filled funding request or NO_FUNDING_REQUEST
    function getNextFundingRequestId() public view returns (uint256) {
        for (uint256 i = lastProcessedFundingRequestId; i < fundingRequests.length; i++) {
            FundingRequest memory fundingRequest = fundingRequests[i];
            if (fundingRequest.state == FundingRequestState.OPEN || fundingRequest.state == FundingRequestState.PARTIALLY_FILLED) return fundingRequest.id;
        }
        return NO_FUNDING_REQUEST;
    }

    /// @dev Get the last funding request id from the array of fundingRequests
    /// @return Last funding request id of the array or NO_FUNDING_REQUEST when array contains no funding requests
    function getLastFundingRequestId() public view returns (uint256) {
        if (fundingRequests.length == 0) return NO_FUNDING_REQUEST;
        return fundingRequests[fundingRequests.length - 1].id;
    }

    /// @dev Get data of a funding request using its id
    /// @param fundingRequestId id of funding request
    /// @return funding request data
    function getFundingRequest(uint256 fundingRequestId) public view returns (FundingRequest memory) {
        if (fundingRequestId >= fundingRequests.length) {
            revert Errors.FundingRequestDoesNotExist();
        }
        return fundingRequests[fundingRequestId];
    }

    /// @dev Get data of all funding requests in the array
    /// @return array containing all funding requests data
    function getFundingRequests() public view returns (FundingRequest[] memory) {
        return fundingRequests;
    }

    /// @dev  Get the exchange rate of a funding token via ChainLinkFeed
    /// @param fundingToken The funding Token address (e.g. ERC20 USDC)
    /// @return exchange rate and exchange rate decimals
    function getFundingTokenExchangeRate(IERC20Upgradeable fundingToken) public view returns (uint256, uint8) {
        if (!isFundingToken(fundingToken)) revert Errors.UnrecognizedFundingToken();

        if (address(fundingTokenChainLinkFeeds[fundingToken]) == address(0)) {
            revert Errors.NoChainLinkFeedAvailable();
        }

        (, int256 exchangeRate, , uint256 updatedAt, ) = fundingTokenChainLinkFeeds[fundingToken].latestRoundData();

        if (exchangeRate <= 0) {
            revert Errors.ZeroOrNegativeExchangeRate();
        }
        // solhint-disable-next-line not-rely-on-time
        if (updatedAt < block.timestamp - chainLinkFeedHeartBeat[fundingToken]) {
            revert Errors.ChainLinkFeedHeartBeatOutOfBoundary();
            // _pause();
        }

        uint8 exchangeRateDecimals = fundingTokenChainLinkFeeds[fundingToken].decimals();

        if (invertFundingTokenChainLinkFeedAnswer[fundingToken]) {
            exchangeRate = int256(10 ** (exchangeRateDecimals * 2)) / exchangeRate;
        }

        return (uint256(exchangeRate), exchangeRateDecimals);
    }

    /// @dev Adds/modifies a fundingToken <-> ChainLinkFeed mapping
    /// @param fundingToken funding token address
    /// @param fundingTokenChainLinkFeed the ChainLinkFeed address
    /// @param invertFundingTokenChainLinkFeedAnswer_ whether the answer should be inverted
    function setFundingTokenChainLinkFeed(
        IERC20Upgradeable fundingToken,
        AggregatorV3Interface fundingTokenChainLinkFeed,
        bool invertFundingTokenChainLinkFeedAnswer_,
        uint256 chainLinkFeedHeartBeat_
    ) external onlyOwner {
        fundingTokenChainLinkFeeds[fundingToken] = fundingTokenChainLinkFeed;
        invertFundingTokenChainLinkFeedAnswer[fundingToken] = invertFundingTokenChainLinkFeedAnswer_;
        chainLinkFeedHeartBeat[fundingToken] = chainLinkFeedHeartBeat_;
        emit SetFundingTokenChainLinkFeed(fundingToken, fundingTokenChainLinkFeed, invertFundingTokenChainLinkFeedAnswer_, chainLinkFeedHeartBeat_);
    }

    /// @dev Get ChainLinkFeed for a funding token
    /// @param fundingToken the funding token address
    /// @return the ChainLinkFeed address and whether the answer should be inverted
    function getFundingTokenChainLinkFeed(IERC20Upgradeable fundingToken) external view returns (AggregatorV3Interface, bool, uint256) {
        return (fundingTokenChainLinkFeeds[fundingToken], invertFundingTokenChainLinkFeedAnswer[fundingToken], chainLinkFeedHeartBeat[fundingToken]);
    }

    /// @dev Modifies the whitelist status of a funding token
    /// @param fundingToken the funding token
    /// @param accepted whether the funding token is accepted
    function setFundingToken(IERC20Upgradeable fundingToken, bool accepted) external onlyOwner {
        if (fundingTokens[fundingToken] != accepted) {
            fundingTokens[fundingToken] = accepted;
            emit SetFundingToken(fundingToken, accepted);
            if (accepted) {
                _fundingTokens.push(fundingToken);
            } else {
                Util.removeValueFromArray(fundingToken, _fundingTokens);
            }
        }
    }

    /// @dev Get all funding tokens
    /// @return array of all funding tokens
    function getFundingTokens() external view returns (IERC20Upgradeable[] memory) {
        return _fundingTokens;
    }

    /// @dev Check whether a funding token is accepted
    /// @param fundingToken the funding token address
    /// @return whether the token is an accepted funding token
    function isFundingToken(IERC20Upgradeable fundingToken) public view returns (bool) {
        return fundingTokens[fundingToken];
    }

    /// @dev Modifies the whitelist status of a primary funder
    /// @param primaryFunder the primary funder
    /// @param accepted whether the primary funder is accepted
    function setPrimaryFunder(address primaryFunder, bool accepted) external onlyOwner {
        if (primaryFunders[primaryFunder] != accepted) {
            primaryFunders[primaryFunder] = accepted;
            emit SetPrimaryFunder(primaryFunder, accepted);
        }
    }

    /// @dev Check whether a primary funder is accepted
    /// @param primaryFunder the primary funder address
    /// @return whether the primary funder is accepted
    function isPrimaryFunder(address primaryFunder) public view returns (bool) {
        return primaryFunders[primaryFunder];
    }

    /// Changes the delegate of the vault
    /// @param delegate_ the new delegate
    function setDelegate(address delegate_) external onlyOwner {
        if (delegate != delegate_) {
            delegate = delegate_;
            emit SetDelegate(delegate);
        }
    }

    /// Attemps to get a funding attempt by its id
    /// @param fundingAttemptId id of funding attempt
    /// @return funding attempt
    function getFundingAttempt(uint256 fundingAttemptId) public view returns (FundingAttempt memory) {
        if (fundingAttemptId >= fundingAttempts.length) {
            revert Errors.FundingAttemptDoesNotExist();
        }

        return fundingAttempts[fundingAttemptId];
    }

    /// @dev Get all funding attempts
    function getFundingAttempts() public view returns (FundingAttempt[] memory) {
        return fundingAttempts;
    }

    /// @dev Alows the fund approver to approve a funding attempt
    /// @param fundingAttemptId id of funding attempt
    function approveFundingAttempt(uint256 fundingAttemptId) public onlyFundApprover {
        FundingAttempt storage fundingAttempt = fundingAttempts[fundingAttemptId];

        if (fundingAttempt.state != FundingAttemptState.PENDING) {
            revert Errors.FundingAttemptNotPending();
        }

        (, uint256 assets, , , ) = _previewFund(fundingAttempt.funder, fundingAttempt.fundingToken, fundingAttempt.fundingTokenAmount);

        if (assets < fundingAttempt.flrFundingAmount) {
            uint256 slippage = 10 ** 18 - (assets * 10 ** 18) / fundingAttempt.flrFundingAmount;

            if (slippage >= fundingAttempt.maxSlippage) {
                fundingAttempt.state = FundingAttemptState.FAILED;
                emit FundingAttemptFailed(fundingAttemptId, "slippage too high");
                return;
            }
        }

        executeFundingAttempt(fundingAttempt.fundingToken, fundingAttempt.fundingTokenAmount, fundingAttempt.funder);
        fundingAttempt.state = FundingAttemptState.EXECUTED;
        emit ApproveFundingAttempt(fundingAttemptId);
    }

    /// @dev Alows the fund approver to reject a funding attempt
    /// @param fundingAttemptId id of funding attempt
    /// @param reason reason for rejection
    function rejectFundingAttempt(uint256 fundingAttemptId, string calldata reason) external onlyFundApprover {
        FundingAttempt storage fundingAttempt = fundingAttempts[fundingAttemptId];
        if (fundingAttempt.state != FundingAttemptState.PENDING) {
            revert Errors.FundingAttemptNotPending();
        }

        fundingAttempt.state = FundingAttemptState.REJECTED;
        emit RejectFundingAttempt(fundingAttemptId, reason);
    }

    /// Changes the fund approver of the vault
    /// @param fundApprover_ the new delegate
    function setFundApprover(address fundApprover_) external onlyOwner {
        fundApprover = fundApprover_;
        emit SetFundApprover(fundApprover);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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);
        _;
    }

    /**
     * @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 `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @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(account),
                        " 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.
     *
     * May emit a {RoleGranted} event.
     */
    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.
     *
     * May emit a {RoleRevoked} event.
     */
    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`.
     *
     * May emit a {RoleRevoked} event.
     */
    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.
     *
     * May emit a {RoleGranted} event.
     *
     * [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.
     *
     * May emit a {RoleGranted} event.
     */
    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.
     *
     * May emit a {RoleRevoked} event.
     */
    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;
}

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (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 Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        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;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (interfaces/IERC4626.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20Upgradeable.sol";
import "../token/ERC20/extensions/IERC20MetadataUpgradeable.sol";

/**
 * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 *
 * _Available since v4.7._
 */
interface IERC4626Upgradeable is IERC20Upgradeable, IERC20MetadataUpgradeable {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) external returns (uint256 assets);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * 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 prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

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

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initialized`
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initializing`
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (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 Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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.openzeppelin.com/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, allowance(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 = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * 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;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _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;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _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;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _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 Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * 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;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/extensions/draft-ERC20Permit.sol)

pragma solidity ^0.8.0;

import "./draft-IERC20PermitUpgradeable.sol";
import "../ERC20Upgradeable.sol";
import "../../../utils/cryptography/ECDSAUpgradeable.sol";
import "../../../utils/cryptography/EIP712Upgradeable.sol";
import "../../../utils/CountersUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * _Available since v3.4._
 *
 * @custom:storage-size 51
 */
abstract contract ERC20PermitUpgradeable is Initializable, ERC20Upgradeable, IERC20PermitUpgradeable, EIP712Upgradeable {
    using CountersUpgradeable for CountersUpgradeable.Counter;

    mapping(address => CountersUpgradeable.Counter) private _nonces;

    // solhint-disable-next-line var-name-mixedcase
    bytes32 private constant _PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
    /**
     * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.
     * However, to ensure consistency with the upgradeable transpiler, we will continue
     * to reserve a slot.
     * @custom:oz-renamed-from _PERMIT_TYPEHASH
     */
    // solhint-disable-next-line var-name-mixedcase
    bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    function __ERC20Permit_init(string memory name) internal onlyInitializing {
        __EIP712_init_unchained(name, "1");
    }

    function __ERC20Permit_init_unchained(string memory) internal onlyInitializing {}

    /**
     * @dev See {IERC20Permit-permit}.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual override {
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSAUpgradeable.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _approve(owner, spender, value);
    }

    /**
     * @dev See {IERC20Permit-nonces}.
     */
    function nonces(address owner) public view virtual override returns (uint256) {
        return _nonces[owner].current();
    }

    /**
     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view override returns (bytes32) {
        return _domainSeparatorV4();
    }

    /**
     * @dev "Consume a nonce": return the current value and increment.
     *
     * _Available since v4.1._
     */
    function _useNonce(address owner) internal virtual returns (uint256 current) {
        CountersUpgradeable.Counter storage nonce = _nonces[owner];
        current = nonce.current();
        nonce.increment();
    }

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20BurnableUpgradeable is Initializable, ContextUpgradeable, ERC20Upgradeable {
    function __ERC20Burnable_init() internal onlyInitializing {
    }

    function __ERC20Burnable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        _spendAllowance(account, _msgSender(), amount);
        _burn(account, amount);
    }

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/extensions/ERC4626.sol)

pragma solidity ^0.8.0;

import "../ERC20Upgradeable.sol";
import "../utils/SafeERC20Upgradeable.sol";
import "../../../interfaces/IERC4626Upgradeable.sol";
import "../../../utils/math/MathUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
 *
 * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
 * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
 * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
 * contract and not the "assets" token which is an independent contract.
 *
 * CAUTION: Deposits and withdrawals may incur unexpected slippage. Users should verify that the amount received of
 * shares or assets is as expected. EOAs should operate through a wrapper that performs these checks such as
 * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router].
 *
 * _Available since v4.7._
 */
abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626Upgradeable {
    using MathUpgradeable for uint256;

    IERC20Upgradeable private _asset;
    uint8 private _decimals;

    /**
     * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
     */
    function __ERC4626_init(IERC20Upgradeable asset_) internal onlyInitializing {
        __ERC4626_init_unchained(asset_);
    }

    function __ERC4626_init_unchained(IERC20Upgradeable asset_) internal onlyInitializing {
        (bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
        _decimals = success ? assetDecimals : super.decimals();
        _asset = asset_;
    }

    /**
     * @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
     */
    function _tryGetAssetDecimals(IERC20Upgradeable asset_) private returns (bool, uint8) {
        (bool success, bytes memory encodedDecimals) = address(asset_).call(
            abi.encodeWithSelector(IERC20MetadataUpgradeable.decimals.selector)
        );
        if (success && encodedDecimals.length >= 32) {
            uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
            if (returnedDecimals <= type(uint8).max) {
                return (true, uint8(returnedDecimals));
            }
        }
        return (false, 0);
    }

    /**
     * @dev Decimals are read from the underlying asset in the constructor and cached. If this fails (e.g., the asset
     * has not been created yet), the cached value is set to a default obtained by `super.decimals()` (which depends on
     * inheritance but is most likely 18). Override this function in order to set a guaranteed hardcoded value.
     * See {IERC20Metadata-decimals}.
     */
    function decimals() public view virtual override(IERC20MetadataUpgradeable, ERC20Upgradeable) returns (uint8) {
        return _decimals;
    }

    /** @dev See {IERC4626-asset}. */
    function asset() public view virtual override returns (address) {
        return address(_asset);
    }

    /** @dev See {IERC4626-totalAssets}. */
    function totalAssets() public view virtual override returns (uint256) {
        return _asset.balanceOf(address(this));
    }

    /** @dev See {IERC4626-convertToShares}. */
    function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) {
        return _convertToShares(assets, MathUpgradeable.Rounding.Down);
    }

    /** @dev See {IERC4626-convertToAssets}. */
    function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) {
        return _convertToAssets(shares, MathUpgradeable.Rounding.Down);
    }

    /** @dev See {IERC4626-maxDeposit}. */
    function maxDeposit(address) public view virtual override returns (uint256) {
        return _isVaultCollateralized() ? type(uint256).max : 0;
    }

    /** @dev See {IERC4626-maxMint}. */
    function maxMint(address) public view virtual override returns (uint256) {
        return type(uint256).max;
    }

    /** @dev See {IERC4626-maxWithdraw}. */
    function maxWithdraw(address owner) public view virtual override returns (uint256) {
        return _convertToAssets(balanceOf(owner), MathUpgradeable.Rounding.Down);
    }

    /** @dev See {IERC4626-maxRedeem}. */
    function maxRedeem(address owner) public view virtual override returns (uint256) {
        return balanceOf(owner);
    }

    /** @dev See {IERC4626-previewDeposit}. */
    function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
        return _convertToShares(assets, MathUpgradeable.Rounding.Down);
    }

    /** @dev See {IERC4626-previewMint}. */
    function previewMint(uint256 shares) public view virtual override returns (uint256) {
        return _convertToAssets(shares, MathUpgradeable.Rounding.Up);
    }

    /** @dev See {IERC4626-previewWithdraw}. */
    function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
        return _convertToShares(assets, MathUpgradeable.Rounding.Up);
    }

    /** @dev See {IERC4626-previewRedeem}. */
    function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
        return _convertToAssets(shares, MathUpgradeable.Rounding.Down);
    }

    /** @dev See {IERC4626-deposit}. */
    function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
        require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");

        uint256 shares = previewDeposit(assets);
        _deposit(_msgSender(), receiver, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-mint}. */
    function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
        require(shares <= maxMint(receiver), "ERC4626: mint more than max");

        uint256 assets = previewMint(shares);
        _deposit(_msgSender(), receiver, assets, shares);

        return assets;
    }

    /** @dev See {IERC4626-withdraw}. */
    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) public virtual override returns (uint256) {
        require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");

        uint256 shares = previewWithdraw(assets);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-redeem}. */
    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) public virtual override returns (uint256) {
        require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");

        uint256 assets = previewRedeem(shares);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return assets;
    }

    /**
     * @dev Internal conversion function (from assets to shares) with support for rounding direction.
     *
     * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset
     * would represent an infinite amount of shares.
     */
    function _convertToShares(uint256 assets, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256 shares) {
        uint256 supply = totalSupply();
        return
            (assets == 0 || supply == 0)
                ? _initialConvertToShares(assets, rounding)
                : assets.mulDiv(supply, totalAssets(), rounding);
    }

    /**
     * @dev Internal conversion function (from assets to shares) to apply when the vault is empty.
     *
     * NOTE: Make sure to keep this function consistent with {_initialConvertToAssets} when overriding it.
     */
    function _initialConvertToShares(
        uint256 assets,
        MathUpgradeable.Rounding /*rounding*/
    ) internal view virtual returns (uint256 shares) {
        return assets;
    }

    /**
     * @dev Internal conversion function (from shares to assets) with support for rounding direction.
     */
    function _convertToAssets(uint256 shares, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256 assets) {
        uint256 supply = totalSupply();
        return
            (supply == 0) ? _initialConvertToAssets(shares, rounding) : shares.mulDiv(totalAssets(), supply, rounding);
    }

    /**
     * @dev Internal conversion function (from shares to assets) to apply when the vault is empty.
     *
     * NOTE: Make sure to keep this function consistent with {_initialConvertToShares} when overriding it.
     */
    function _initialConvertToAssets(
        uint256 shares,
        MathUpgradeable.Rounding /*rounding*/
    ) internal view virtual returns (uint256 assets) {
        return shares;
    }

    /**
     * @dev Deposit/mint common workflow.
     */
    function _deposit(
        address caller,
        address receiver,
        uint256 assets,
        uint256 shares
    ) internal virtual {
        // If _asset is ERC777, `transferFrom` can trigger a reenterancy BEFORE the transfer happens through the
        // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
        // assets are transferred and before the shares are minted, which is a valid state.
        // slither-disable-next-line reentrancy-no-eth
        SafeERC20Upgradeable.safeTransferFrom(_asset, caller, address(this), assets);
        _mint(receiver, shares);

        emit Deposit(caller, receiver, assets, shares);
    }

    /**
     * @dev Withdraw/redeem common workflow.
     */
    function _withdraw(
        address caller,
        address receiver,
        address owner,
        uint256 assets,
        uint256 shares
    ) internal virtual {
        if (caller != owner) {
            _spendAllowance(owner, caller, shares);
        }

        // If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
        // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
        // shares are burned and after the assets are transferred, which is a valid state.
        _burn(owner, shares);
        SafeERC20Upgradeable.safeTransfer(_asset, receiver, assets);

        emit Withdraw(caller, receiver, owner, assets, shares);
    }

    function _isVaultCollateralized() private view returns (bool) {
        return totalAssets() > 0 || totalSupply() == 0;
    }

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/draft-IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

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

    function safeTransferFrom(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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(
        IERC20Upgradeable 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));
        }
    }

    function safePermit(
        IERC20PermitUpgradeable token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20Upgradeable 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");
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../StringsUpgradeable.sol";

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

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

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

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

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

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

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

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

        return (signer, RecoverError.NoError);
    }

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

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

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

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 *
 * @custom:storage-size 52
 */
abstract contract EIP712Upgradeable is Initializable {
    /* solhint-disable var-name-mixedcase */
    bytes32 private _HASHED_NAME;
    bytes32 private _HASHED_VERSION;
    bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    function __EIP712_init(string memory name, string memory version) internal onlyInitializing {
        __EIP712_init_unchained(name, version);
    }

    function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash());
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSAUpgradeable.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev The hash of the name parameter for the EIP712 domain.
     *
     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
     * are a concern.
     */
    function _EIP712NameHash() internal virtual view returns (bytes32) {
        return _HASHED_NAME;
    }

    /**
     * @dev The hash of the version parameter for the EIP712 domain.
     *
     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
     * are a concern.
     */
    function _EIP712VersionHash() internal virtual view returns (bytes32) {
        return _HASHED_VERSION;
    }

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/MathUpgradeable.sol";

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

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

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

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

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

File 26 of 30 : Errors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// (C) Florence Finance, 2022 - https://florence.finance/
pragma solidity ^0.8.17;

library Errors {
    //FlorinStaking
    error StakeAmountMustBeGreaterThanZero();
    error EligibleSharesMustBeGreaterThanZero();
    error UnclaimedRewardsMustBeGreaterThanZero();

    //LoanVault
    error CallerMustBeDelegate();
    error CallerMustBeFundApprover();
    error LoanAmountMustBeLessOrEqualLoansOutstanding();
    error EstimatedDefaultAmountMustBeLessOrEqualLoansOutstanding();
    error RecoveredAmountMustBeLessOrEqualLoanWriteDown();
    error DefiniteDefaultAmountMustBeLessOrEqualLoanWriteDown();
    error InsufficientAllowance();
    error CallerMustBePrimaryFunder();
    error FundingAmountMustBeGreaterThanZero();
    error UnrecognizedFundingToken();
    error NoOpenFundingRequest();
    error AmountRequestedMustBeGreaterThanZero();
    error FundingRequestDoesNotExist();
    error CallerMustBeOwnerOrDelegate();
    error DelegateCanOnlyCancelOpenFundingRequests();
    error NoChainLinkFeedAvailable();
    error ZeroOrNegativeExchangeRate();
    error ChainLinkFeedHeartBeatOutOfBoundary();
    error FundingAttemptDoesNotExist();
    error FundingAttemptNotPending();
    error AprOutOfBounds();
    error FundingFeeOutOfBounds();

    //LoanVaultRegistry
    error LoanVaultNotFound();
    error TooManyLoanVaultsRegistered();

    //FlorinToken
    error MintAmountMustBeGreaterThanZero();
    error BurnAmountMustBeGreaterThanZero();
    error AmountMustBeGreaterThanZero();
    error TransferAmountMustBeGreaterThanZero();
    error EffectiveRewardAmountMustBeGreaterThanZero();
}

// SPDX-License-Identifier: GPL-2.0-or-later
// (C) Florence Finance, 2022 - https://florence.finance/

pragma solidity ^0.8.17;

import "./interfaces/ICustomToken.sol"; // includes interfaces L1MintableToken & L1ReverseToken
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; // includes ContextUpgradeable

import "./Errors.sol";

/**
 * @title Interface needed to call function registerTokenToL2 of the L1CustomGateway
 */
interface IL1CustomGateway {
    function registerTokenToL2(
        address _l2Address,
        uint256 _maxGas,
        uint256 _gasPriceBid,
        uint256 _maxSubmissionCost,
        address _creditBackAddress
    ) external payable returns (uint256);
}

/**
 * @title Interface needed to call function setGateway of the L2GatewayRouter
 */
interface IL1GatewayRouter {
    function setGateway(address _gateway, uint256 _maxGas, uint256 _gasPriceBid, uint256 _maxSubmissionCost, address _creditBackAddress) external payable returns (uint256);
}

contract FlorinToken is ICustomToken, ERC20PermitUpgradeable, ERC20BurnableUpgradeable, OwnableUpgradeable {
    address private customGatewayAddress;
    address private routerAddress;
    bool private shouldRegisterGateway;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {} // solhint-disable-line

    function initialize(address _customGatewayAddress, address _routerAddress) external initializer {
        _initializeArbitrumBridging(_customGatewayAddress, _routerAddress);
        __ERC20_init_unchained("Florin", "FLR");
        __ERC20Permit_init("Florin");
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function initializeArbitrumBridging(address _customGatewayAddress, address _routerAddress) external onlyOwner {
        _initializeArbitrumBridging(_customGatewayAddress, _routerAddress);
    }

    function _initializeArbitrumBridging(address _customGatewayAddress, address _routerAddress) internal {
        customGatewayAddress = _customGatewayAddress;
        routerAddress = _routerAddress;
    }

    /// @dev Mints FLR. Protected, only be callable by owner which should be FlorinTreasury
    /// @param receiver receiver of the minted FLR
    /// @param amount amount to mint (18 decimals)
    function mint(address receiver, uint256 amount) external onlyOwner {
        if (amount == 0) {
            revert Errors.MintAmountMustBeGreaterThanZero();
        }
        _mint(receiver, amount);
    }

    /// @dev we only set shouldRegisterGateway to true when in `registerTokenOnL2`
    function isArbitrumEnabled() external view override returns (uint8) {
        require(shouldRegisterGateway, "NOT_EXPECTED_CALL");
        return uint8(0xb1);
    }

    /// @dev See {ICustomToken-registerTokenOnL2}
    function registerTokenOnL2(
        address l2CustomTokenAddress,
        uint256 maxSubmissionCostForCustomGateway,
        uint256 maxSubmissionCostForRouter,
        uint256 maxGasForCustomGateway,
        uint256 maxGasForRouter,
        uint256 gasPriceBid,
        uint256 valueForGateway,
        uint256 valueForRouter,
        address creditBackAddress
    ) public payable override onlyOwner {
        // we temporarily set `shouldRegisterGateway` to true for the callback in registerTokenToL2 to succeed
        bool prev = shouldRegisterGateway;
        shouldRegisterGateway = true;

        IL1CustomGateway(customGatewayAddress).registerTokenToL2{value: valueForGateway}(
            l2CustomTokenAddress,
            maxGasForCustomGateway,
            gasPriceBid,
            maxSubmissionCostForCustomGateway,
            creditBackAddress
        );

        IL1GatewayRouter(routerAddress).setGateway{value: valueForRouter}(customGatewayAddress, maxGasForRouter, gasPriceBid, maxSubmissionCostForRouter, creditBackAddress);

        shouldRegisterGateway = prev;
    }

    /// @dev See {ERC20-transferFrom}
    function transferFrom(address sender, address recipient, uint256 amount) public override(ICustomToken, ERC20Upgradeable) returns (bool) {
        return super.transferFrom(sender, recipient, amount);
    }

    /// @dev See {ERC20-balanceOf}
    function balanceOf(address account) public view override(ICustomToken, ERC20Upgradeable) returns (uint256) {
        return super.balanceOf(account);
    }
}

// SPDX-License-Identifier: GPL-2.0-or-later
// (C) Florence Finance, 2022 - https://florence.finance/
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "./FlorinToken.sol";
import "./Util.sol";

contract FlorinTreasury is AccessControlUpgradeable, PausableUpgradeable {
    bytes32 private constant LOAN_VAULT_ROLE = keccak256("LOAN_VAULT_ROLE");

    event Mint(address sender, address receiver, uint256 florinTokens);
    event Redeem(address redeemer, uint256 florinTokens, uint256 eurTokens);
    event DepositEUR(address from, uint256 eurTokens);

    FlorinToken public florinToken;

    IERC20Upgradeable public eurToken;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {} // solhint-disable-line

    function initialize(FlorinToken florinToken_, IERC20Upgradeable eurToken_) external initializer {
        __AccessControl_init_unchained();
        __Pausable_init_unchained();

        _grantRole(DEFAULT_ADMIN_ROLE, _msgSender());

        florinToken = florinToken_;
        eurToken = eurToken_;

        _pause();
    }

    /// @dev Pauses the Florin Treasury (only by DEFAULT_ADMIN_ROLE)
    function pause() external {
        _checkRole(DEFAULT_ADMIN_ROLE, _msgSender());
        _pause();
    }

    /// @dev Unpauses the Florin Treasury (only by DEFAULT_ADMIN_ROLE)
    function unpause() external {
        _checkRole(DEFAULT_ADMIN_ROLE, _msgSender());
        _unpause();
    }

    function setEurToken(IERC20Upgradeable eurToken_) external {
        _checkRole(DEFAULT_ADMIN_ROLE, _msgSender());

        if (address(eurToken_) != address(0)) {
            eurToken = eurToken_;
        }
    }

    function setFlorinToken(FlorinToken florinToken_) external {
        _checkRole(DEFAULT_ADMIN_ROLE, _msgSender());

        if (address(florinToken_) != address(0)) {
            florinToken = florinToken_;
        }
    }

    /// @dev Mint Florin Token to receiver address (only by LOAN_VAULT_ROLE && when not paused)
    /// @param receiver receiver address
    /// @param florinTokens amount of Florin Token to be minted
    function mint(address receiver, uint256 florinTokens) external whenNotPaused {
        _checkRole(LOAN_VAULT_ROLE, _msgSender());
        florinToken.mint(receiver, florinTokens);
        emit Mint(_msgSender(), receiver, florinTokens);
    }

    /// @dev Redeem (burn) Florin Token to Florin Treasury and receive eurToken (only when not paused)
    /// @param florinTokens amount of Florin Token to be burned
    function redeem(uint256 florinTokens) external whenNotPaused {
        florinToken.burnFrom(_msgSender(), florinTokens);
        uint256 eurTokens = Util.convertDecimalsERC20(florinTokens, florinToken, eurToken);
        SafeERC20Upgradeable.safeTransfer(eurToken, _msgSender(), eurTokens);
        emit Redeem(_msgSender(), florinTokens, eurTokens);
    }

    /// @dev Deposit eurToken to Florin Treasury
    /// @param eurTokens amount of eurToken to be deposited [18 decimals]
    function depositEUR(uint256 eurTokens) external whenNotPaused {
        eurTokens = Util.convertDecimals(eurTokens, 18, Util.getERC20Decimals(eurToken));

        if (eurTokens == 0) {
            revert Errors.TransferAmountMustBeGreaterThanZero();
        }

        SafeERC20Upgradeable.safeTransferFrom(eurToken, _msgSender(), address(this), eurTokens);
        emit DepositEUR(_msgSender(), eurTokens);
    }

    /// @dev Transfer the ownership of the Deposit eurToken to Florin Treasury (requires a previous approval by 'from')
    /// @param newOwner address of the new owner of the Florin Token
    function transferFlorinTokenOwnership(address newOwner) external {
        _checkRole(DEFAULT_ADMIN_ROLE, _msgSender());
        florinToken.transferOwnership(newOwner);
    }
}

// SPDX-License-Identifier: Apache-2.0

/*
 * Copyright 2020, Offchain Labs, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;

interface ArbitrumEnabledToken {
    /// @notice should return `0xb1` if token is enabled for arbitrum gateways
    function isArbitrumEnabled() external view returns (uint8);
}

/**
 * @title Minimum expected interface for L1 custom token
 */
interface ICustomToken is ArbitrumEnabledToken {
    /**
     * @notice Should make an external call to L1CustomGateway.registerTokenToL2 and L2GatewayRouter.setGateway
     */
    function registerTokenOnL2(
        address l2CustomTokenAddress,
        uint256 maxSubmissionCostForCustomBridge,
        uint256 maxSubmissionCostForRouter,
        uint256 maxGasForCustomBridge,
        uint256 maxGasForRouter,
        uint256 gasPriceBid,
        uint256 valueForGateway,
        uint256 valueForRouter,
        address creditBackAddress
    ) external payable;

    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    function balanceOf(address account) external view returns (uint256);
}

interface L1MintableToken is ICustomToken {
    function bridgeMint(address account, uint256 amount) external;
}

interface L1ReverseToken is L1MintableToken {
    function bridgeBurn(address account, uint256 amount) external;
}

// SPDX-License-Identifier: GPL-2.0-or-later
// (C) Florence Finance, 2022 - https://florence.finance/
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";

library Util {
    /// @dev Return the decimals of an ERC20 token (if the implementations offers it)
    /// @param _token (IERC20) the ERC20 token
    /// @return  (uint8) the decimals
    function getERC20Decimals(IERC20Upgradeable _token) internal view returns (uint8) {
        return IERC20MetadataUpgradeable(address(_token)).decimals();
    }

    /// @dev Converts a number from one decimal precision to the other
    /// @param _number (uint256) the number
    /// @param _currentDecimals (uint256) the current decimals of the number
    /// @param _targetDecimals (uint256) the desired decimals for the number
    /// @return  (uint256) the number with _targetDecimals decimals
    function convertDecimals(uint256 _number, uint256 _currentDecimals, uint256 _targetDecimals) internal pure returns (uint256) {
        uint256 diffDecimals;

        uint256 amountCorrected = _number;

        if (_targetDecimals < _currentDecimals) {
            diffDecimals = _currentDecimals - _targetDecimals;
            amountCorrected = _number / (uint256(10) ** diffDecimals);
        } else if (_targetDecimals > _currentDecimals) {
            diffDecimals = _targetDecimals - _currentDecimals;
            amountCorrected = _number * (uint256(10) ** diffDecimals);
        }

        return (amountCorrected);
    }

    /// @dev Converts a number from one decimal precision to the other based on two ERC20 Tokens
    /// @param _number (uint256) the number
    /// @param _sourceToken (address) the source ERC20 Token
    /// @param _targetToken (address) the target ERC20 Token
    /// @return  (uint256) the number with _targetDecimals decimals
    function convertDecimalsERC20(uint256 _number, IERC20Upgradeable _sourceToken, IERC20Upgradeable _targetToken) internal view returns (uint256) {
        return convertDecimals(_number, getERC20Decimals(_sourceToken), getERC20Decimals(_targetToken));
    }

    function removeValueFromArray(IERC20Upgradeable value, IERC20Upgradeable[] storage array) internal {
        bool shift = false;
        uint256 i = 0;
        while (i < array.length - 1) {
            if (array[i] == value) shift = true;
            if (shift) {
                array[i] = array[i + 1];
            }
            i++;
        }
        array.pop();
    }
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AmountRequestedMustBeGreaterThanZero","type":"error"},{"inputs":[],"name":"AprOutOfBounds","type":"error"},{"inputs":[],"name":"CallerMustBeDelegate","type":"error"},{"inputs":[],"name":"CallerMustBeFundApprover","type":"error"},{"inputs":[],"name":"CallerMustBeOwnerOrDelegate","type":"error"},{"inputs":[],"name":"CallerMustBePrimaryFunder","type":"error"},{"inputs":[],"name":"ChainLinkFeedHeartBeatOutOfBoundary","type":"error"},{"inputs":[],"name":"DefiniteDefaultAmountMustBeLessOrEqualLoanWriteDown","type":"error"},{"inputs":[],"name":"DelegateCanOnlyCancelOpenFundingRequests","type":"error"},{"inputs":[],"name":"EffectiveRewardAmountMustBeGreaterThanZero","type":"error"},{"inputs":[],"name":"EstimatedDefaultAmountMustBeLessOrEqualLoansOutstanding","type":"error"},{"inputs":[],"name":"FundingAmountMustBeGreaterThanZero","type":"error"},{"inputs":[],"name":"FundingAttemptDoesNotExist","type":"error"},{"inputs":[],"name":"FundingAttemptNotPending","type":"error"},{"inputs":[],"name":"FundingFeeOutOfBounds","type":"error"},{"inputs":[],"name":"FundingRequestDoesNotExist","type":"error"},{"inputs":[],"name":"InsufficientAllowance","type":"error"},{"inputs":[],"name":"LoanAmountMustBeLessOrEqualLoansOutstanding","type":"error"},{"inputs":[],"name":"NoChainLinkFeedAvailable","type":"error"},{"inputs":[],"name":"NoOpenFundingRequest","type":"error"},{"inputs":[],"name":"RecoveredAmountMustBeLessOrEqualLoanWriteDown","type":"error"},{"inputs":[],"name":"TransferAmountMustBeGreaterThanZero","type":"error"},{"inputs":[],"name":"UnrecognizedFundingToken","type":"error"},{"inputs":[],"name":"ZeroOrNegativeExchangeRate","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fundingRequestId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"florinTokens","type":"uint256"}],"name":"AddFundingRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fundingAttemptId","type":"uint256"}],"name":"ApproveFundingAttempt","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fundingRequestId","type":"uint256"}],"name":"CancelFundingRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"funder","type":"address"},{"indexed":false,"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"fundingTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"florinTokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"CreateFundingAttempt","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewards","type":"uint256"}],"name":"DepositRewards","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"funder","type":"address"},{"indexed":false,"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"fundingTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"florinTokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"ExecuteFundingAttempt","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"definiteDefaultAmount","type":"uint256"}],"name":"FinalizeDefault","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fundId","type":"uint256"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"FundingAttemptFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fundingAttemptId","type":"uint256"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"RejectFundingAttempt","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"loanAmount","type":"uint256"}],"name":"RepayLoan","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"apr","type":"uint256"}],"name":"SetApr","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"}],"name":"SetDelegate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"funderApprover","type":"address"}],"name":"SetFundApprover","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fundingFee","type":"uint256"}],"name":"SetFundingFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20Upgradeable","name":"token","type":"address"},{"indexed":false,"internalType":"bool","name":"accepted","type":"bool"}],"name":"SetFundingToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"indexed":false,"internalType":"contract AggregatorV3Interface","name":"fundingTokenChainLinkFeed","type":"address"},{"indexed":false,"internalType":"bool","name":"invertFundingTokenChainLinkFeedAnswer_","type":"bool"},{"indexed":false,"internalType":"uint256","name":"chainLinkFeedHeartBeat_","type":"uint256"}],"name":"SetFundingTokenChainLinkFeed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"primaryFunder","type":"address"},{"indexed":false,"internalType":"bool","name":"accepted","type":"bool"}],"name":"SetPrimaryFunder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","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":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"estimatedDefaultAmount","type":"uint256"}],"name":"WriteDownLoan","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"recoveredAmount","type":"uint256"}],"name":"WriteUpLoan","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountRequested","type":"uint256"}],"name":"addFundingRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fundingAttemptId","type":"uint256"}],"name":"approveFundingAttempt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"apr","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calculateOutstandingRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"fundingRequestId","type":"uint256"}],"name":"cancelFundingRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"internalType":"uint256","name":"fundingTokenAmount","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"}],"name":"createFundingAttempt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"debt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"delegate","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rewards","type":"uint256"}],"name":"depositRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"definiteDefaultAmount","type":"uint256"}],"name":"finalizeDefault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"florinTreasury","outputs":[{"internalType":"contract FlorinTreasury","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fundApprover","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"fundingAttempts","outputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"funder","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"internalType":"uint256","name":"fundingTokenAmount","type":"uint256"},{"internalType":"uint256","name":"flrFundingAmount","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"fillableFundingTokenAmount","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"enum LoanVault.FundingAttemptState","name":"state","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fundingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"fundingRequests","outputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"uint256","name":"amountRequested","type":"uint256"},{"internalType":"uint256","name":"amountFilled","type":"uint256"},{"internalType":"enum LoanVault.FundingRequestState","name":"state","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"fundingAttemptId","type":"uint256"}],"name":"getFundingAttempt","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"funder","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"internalType":"uint256","name":"fundingTokenAmount","type":"uint256"},{"internalType":"uint256","name":"flrFundingAmount","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"fillableFundingTokenAmount","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"enum LoanVault.FundingAttemptState","name":"state","type":"uint8"}],"internalType":"struct LoanVault.FundingAttempt","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFundingAttempts","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"funder","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"internalType":"uint256","name":"fundingTokenAmount","type":"uint256"},{"internalType":"uint256","name":"flrFundingAmount","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"fillableFundingTokenAmount","type":"uint256"},{"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"internalType":"enum LoanVault.FundingAttemptState","name":"state","type":"uint8"}],"internalType":"struct LoanVault.FundingAttempt[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"fundingRequestId","type":"uint256"}],"name":"getFundingRequest","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"uint256","name":"amountRequested","type":"uint256"},{"internalType":"uint256","name":"amountFilled","type":"uint256"},{"internalType":"enum LoanVault.FundingRequestState","name":"state","type":"uint8"}],"internalType":"struct LoanVault.FundingRequest","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFundingRequests","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"uint256","name":"amountRequested","type":"uint256"},{"internalType":"uint256","name":"amountFilled","type":"uint256"},{"internalType":"enum LoanVault.FundingRequestState","name":"state","type":"uint8"}],"internalType":"struct LoanVault.FundingRequest[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"}],"name":"getFundingTokenChainLinkFeed","outputs":[{"internalType":"contract AggregatorV3Interface","name":"","type":"address"},{"internalType":"bool","name":"","type":"bool"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"}],"name":"getFundingTokenExchangeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFundingTokens","outputs":[{"internalType":"contract IERC20Upgradeable[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastFundingRequestId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNextFundingRequestId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"id","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"contract FlorinTreasury","name":"florinTreasury_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"}],"name":"isFundingToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"primaryFunder","type":"address"}],"name":"isPrimaryFunder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastProcessedFundingRequestId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"loanWriteDown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"loansOutstanding","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"outstandingRewardsSnapshot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"outstandingRewardsSnapshotTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"wallet","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"internalType":"uint256","name":"fundingTokenAmount","type":"uint256"}],"name":"previewFund","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fundingAttemptId","type":"uint256"},{"internalType":"string","name":"reason","type":"string"}],"name":"rejectFundingAttempt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"loanAmount","type":"uint256"}],"name":"repayLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_apr","type":"uint256"}],"name":"setApr","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegate_","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"fundApprover_","type":"address"}],"name":"setFundApprover","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fundingFee","type":"uint256"}],"name":"setFundingFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"internalType":"bool","name":"accepted","type":"bool"}],"name":"setFundingToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"fundingToken","type":"address"},{"internalType":"contract AggregatorV3Interface","name":"fundingTokenChainLinkFeed","type":"address"},{"internalType":"bool","name":"invertFundingTokenChainLinkFeedAnswer_","type":"bool"},{"internalType":"uint256","name":"chainLinkFeedHeartBeat_","type":"uint256"}],"name":"setFundingTokenChainLinkFeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"setLoansOutstanding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"primaryFunder","type":"address"},{"internalType":"bool","name":"accepted","type":"bool"}],"name":"setPrimaryFunder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"estimatedDefaultAmount","type":"uint256"}],"name":"writeDownLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"recoveredAmount","type":"uint256"}],"name":"writeUpLoan","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b50600054610100900460ff1615808015620000335750600054600160ff909116105b8062000063575062000050306200013d60201b62002ef01760201c565b15801562000063575060005460ff166001145b620000cb5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b6000805460ff191660011790558015620000ef576000805461ff0019166101001790555b801562000136576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b506200014c565b6001600160a01b03163b151590565b61566b806200015c6000396000f3fe608060405234801561001057600080fd5b50600436106104b55760003560e01c806383a86d2711610272578063c3e096b011610161578063d066555c116100de578063dd62ed3e116100a2578063effd18bf1161007c578063effd18bf14610b16578063f2fde38b14610b29578063fbeeb85814610b3c57600080fd5b8063dd62ed3e14610aca578063ee02204114610b03578063ef8b30f7146109fd57600080fd5b8063d066555c14610a68578063d079d3e014610a7c578063d505accf14610a91578063d905777e14610aa4578063db41207014610ab757600080fd5b8063c78d9c1711610125578063c78d9c1714610a10578063c89e436114610a1a578063ca5eb5e114610a2e578063cd0c0d0414610a41578063ce96cb7714610a5557600080fd5b8063c3e096b014610950578063c416a07214610963578063c63d75b614610978578063c6987f501461098d578063c6e6f592146109fd57600080fd5b8063ae306319116101ef578063b61d8037116101b3578063b61d8037146108e9578063ba087652146108f3578063ba56148614610906578063baf248451461092a578063c25121b01461093d57600080fd5b8063ae30631914610895578063af640d0f146108a8578063b1ca7ff9146108b0578063b3d7f6b9146108c3578063b460af94146108d657600080fd5b806395d89b411161023657806395d89b411461083f5780639c6d4fab14610847578063a457c2d71461085c578063a9059cbb1461086f578063ab7b1c891461088257600080fd5b806383a86d27146107f65780638456cb59146108005780638bdf67f2146108085780638da5cb5b1461081b57806394bf804d1461082c57600080fd5b80633644e515116103a957806357ded9c9116103265780636467f9b0116102ea578063715018a6116102c4578063715018a6146107c857806373dc52aa146107d05780637ecebe00146107e357600080fd5b80636467f9b0146107795780636e553f651461078c57806370a082311461079f57600080fd5b806357ded9c91461072657806359cee29c146107305780635c975abb146107435780635d16e1201461074f5780635f8d60941461075957600080fd5b8063405f57a51161036d578063405f57a5146106c057806348a838d9146106d35780634cdad506146105075780634df20310146106e6578063511761361461071357600080fd5b80633644e5151461066557806338d52e0f1461066d57806339509351146106925780633f4ba83a146106a5578063402d267d146106ad57600080fd5b80631647bce01161043757806323b872dd116103fb57806323b872dd146105e8578063262e49a9146105fb5780632fd4fe6414610623578063313ce56714610643578063362e864f1461065257600080fd5b80631647bce0146105975780631732c0f0146105c457806318160ddd146105cc57806319b9432a146105d45780631ad1870d146105de57600080fd5b8063095ea7b31161047e578063095ea7b31461051a5780630a28a4771461053d5780630daf694c146105505780630dca59c114610563578063122fe9551461056d57600080fd5b8062e3d05d146104ba57806301e1d114146104d557806306fdde03146104dd578063077f224a146104f257806307a2d13a14610507575b600080fd5b6104c2610b44565b6040519081526020015b60405180910390f35b6104c2610c61565b6104e5610cf0565b6040516104cc9190614afa565b610505610500366004614b8b565b610d82565b005b6104c2610515366004614c0f565b611012565b61052d610528366004614c28565b611025565b60405190151581526020016104cc565b6104c261054b366004614c0f565b61103d565b61050561055e366004614c62565b61104a565b6104c26101645481565b61058061057b366004614cb3565b6110f4565b6040805192835260ff9091166020830152016104cc565b61052d6105a5366004614cb3565b6001600160a01b0316600090815261016d602052604090205460ff1690565b6104c2611325565b6035546104c2565b6104c261016c5481565b6104c26101675481565b61052d6105f6366004614cd0565b611371565b61060e610609366004614c0f565b611397565b6040516104cc99989796959493929190614d45565b610636610631366004614c0f565b611403565b6040516104cc9190614dea565b604051601281526020016104cc565b610505610660366004614c0f565b6114c8565b6104c261159b565b6065546001600160a01b03165b6040516001600160a01b0390911681526020016104cc565b61052d6106a0366004614c28565b6115a5565b6105056115e4565b6104c26106bb366004614cb3565b6115f6565b6105056106ce366004614c0f565b611645565b6105056106e1366004614c0f565b611891565b61052d6106f4366004614cb3565b6001600160a01b0316600090815261016a602052604090205460ff1690565b610505610721366004614c0f565b6119b1565b6104c26101685481565b61050561073e366004614c0f565b611a51565b6101305460ff1661052d565b6104c26101745481565b61076c610767366004614c0f565b611ad6565b6040516104cc9190614e6a565b6104c2610787366004614cd0565b611bb0565b6104c261079a366004614e79565b611bcb565b6104c26107ad366004614cb3565b6001600160a01b031660009081526033602052604090205490565b610505611c3e565b6105056107de366004614c0f565b611c50565b6104c26107f1366004614cb3565b611e3f565b6104c26101665481565b610505611e5d565b610505610816366004614c0f565b611e6d565b60fe546001600160a01b031661067a565b6104c261083a366004614e79565b611f0e565b6104e5611f28565b61084f611f37565b6040516104cc9190614ea9565b61052d61086a366004614c28565b611ffc565b61052d61087d366004614c28565b612099565b610505610890366004614c0f565b6120a7565b6105056108a3366004614c0f565b612159565b6104e56121d6565b6105056108be366004614ef7565b6121e0565b6104c26108d1366004614c0f565b612434565b6104c26108e4366004614f2c565b612441565b6104c26101655481565b6104c2610901366004614f2c565b6124bd565b610919610914366004614c0f565b612531565b6040516104cc959493929190614f6e565b610505610938366004614c0f565b612580565b61050561094b366004614fab565b61274e565b61050561095e366004614cb3565b612843565b61096b61289a565b6040516104cc9190614fd9565b6104c2610986366004614cb3565b5060001990565b6109d861099b366004614cb3565b6001600160a01b03908116600090815261016f6020908152604080832054610170835281842054610171909352922054919092169260ff90921691565b604080516001600160a01b0390941684529115156020840152908201526060016104cc565b6104c2610a0b366004614c0f565b612985565b6104c26101635481565b6101695461067a906001600160a01b031681565b610505610a3c366004614cb3565b612992565b6101735461067a906001600160a01b031681565b6104c2610a63366004614cb3565b6129ff565b6101625461067a906001600160a01b031681565b610a84612a23565b6040516104cc919061501c565b610505610a9f36600461506c565b612a85565b6104c2610ab2366004614cb3565b612be9565b610505610ac53660046150dd565b612c07565b6104c2610ad8366004615129565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b610505610b11366004614fab565b612cd4565b610505610b24366004614c0f565b612d60565b610505610b37366004614cb3565b612d6e565b6104c2612de4565b600080610b596065546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610b9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc39190615157565b905060006101665442610bd69190615186565b90506101635460001480610be8575081155b80610bf4575061016854155b80610bfd575080155b15610c0d57610167549250505090565b6000610c1c8361016354612eff565b61016854909150600090610c3e9083906a1a1601fc4ea7109e00000084612f15565b9050610c4a8382615199565b61016754610c5891906151b0565b94505050505090565b6000610c6b610b44565b6065546001600160a01b03166040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610cbd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce19190615157565b610ceb91906151b0565b905090565b606060368054610cff906151c3565b80601f0160208091040260200160405190810160405280929190818152602001828054610d2b906151c3565b8015610d785780601f10610d4d57610100808354040283529160200191610d78565b820191906000526020600020905b815481529060010190602001808311610d5b57829003601f168201915b5050505050905090565b600054610100900460ff1615808015610da25750600054600160ff909116105b80610dbc5750303b158015610dbc575060005460ff166001145b610e335760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084015b60405180910390fd5b6000805460ff191660011790558015610e56576000805461ff0019166101001790555b61016280546001600160a01b0319166001600160a01b0384161790554261016655604080516020601f8801819004810282018101909252868152610ee891889088908190840183828082843760009201919091525050604080516020601f8a018190048102820181019092528881529250889150879081908401838280828437600092019190915250612f7292505050565b610f2786868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612fb792505050565b610f2f613001565b610f37613028565b610f3f613058565b610162546040805163b0f1c7e360e01b81529051610fb4926001600160a01b03169163b0f1c7e39160048083019260209291908290030181865afa158015610f8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610faf91906151f7565b61308c565b610fbc61311f565b610fc4613175565b801561100a576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b600061101f8260006131d0565b92915050565b600033611033818585613203565b5060019392505050565b600061101f826001613327565b611052613359565b6001600160a01b03848116600081815261016f6020908152604080832080546001600160a01b03191695891695861790556101708252808320805460ff191688151590811790915561017183529281902086905580519384529083019390935291810191909152606081018290527f19f8037573a6f1dca8dd47019e81324d6c71bf3d173626d5216ab311c119a977906080015b60405180910390a150505050565b6001600160a01b038116600090815261016d6020526040812054819060ff16611130576040516319e8d85b60e31b815260040160405180910390fd5b6001600160a01b03838116600090815261016f60205260409020541661116957604051634b2872f760e01b815260040160405180910390fd5b6001600160a01b03808416600090815261016f6020526040808220548151633fabe5a360e21b815291519293849391169163feaf968c9160048083019260a09291908290030181865afa1580156111c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e89190615233565b509350509250506000821361121057604051634d9c03cd60e01b815260040160405180910390fd5b6001600160a01b038516600090815261017160205260409020546112349042615186565b81101561125457604051633ad1a1c760e11b815260040160405180910390fd5b6001600160a01b03808616600090815261016f6020908152604080832054815163313ce56760e01b815291519394169263313ce567926004808401939192918290030181865afa1580156112ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d09190615283565b6001600160a01b0387166000908152610170602052604090205490915060ff161561131957826113018260026152a0565b61130c90600a6153a7565b61131691906153cc565b92505b91959194509092505050565b61016b546000908103611339575060001990565b61016b805461134a90600190615186565b8154811061135a5761135a6153fa565b906000526020600020906005020160000154905090565b60003361137f8582856133b3565b61138a858585613445565b60019150505b9392505050565b61017281815481106113a857600080fd5b60009182526020909120600990910201805460018201546002830154600384015460048501546005860154600687015460078801546008909801549698506001600160a01b0395861697949095169592949193909260ff1689565b61140b614a25565b61016b54821061142e576040516351178ec360e11b815260040160405180910390fd5b61016b8281548110611442576114426153fa565b60009182526020918290206040805160a08101825260059093029091018054835260018101546001600160a01b03169383019390935260028301549082015260038083015460608301526004830154919291608084019160ff909116908111156114ae576114ae614d11565b60038111156114bf576114bf614d11565b90525092915050565b610169546001600160a01b031633146114f457604051635d20756160e11b815260040160405180910390fd5b6114fc6135f0565b610165548111156115205760405163dc6cb44760e01b815260040160405180910390fd5b611528613644565b80610163600082825461153b91906151b0565b925050819055508061016560008282546115559190615186565b90915550611564905081613657565b6040518181527f8bcaf54fdd58f77929668a4fb080c72d97ef0af355f34139addb6dddaec09d17906020015b60405180910390a150565b6000610ceb61370d565b3360008181526034602090815260408083206001600160a01b038716845290915281205490919061103390829086906115df9087906151b0565b613203565b6115ec613359565b6115f4613788565b565b6000611600610c61565b610163541115806116145750600061016454115b8061162257506101305460ff165b1561162f57506000919050565b611637610c61565b6101635461101f9190615186565b610169546001600160a01b0316331461167157604051635d20756160e11b815260040160405180910390fd5b6116796135f0565b6101635481111561169d576040516301c650ef60e61b815260040160405180910390fd5b6116a5613644565b600061172c826116bd6065546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611703573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117279190615157565b612eff565b905061016260009054906101000a90046001600160a01b03166001600160a01b031663b0f1c7e36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611782573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a691906151f7565b6001600160a01b03166342966c68826040518263ffffffff1660e01b81526004016117d391815260200190565b600060405180830381600087803b1580156117ed57600080fd5b505af1158015611801573d6000803e3d6000fd5b505050508161016360008282546118189190615186565b9091555061182890508183615186565b610164600082825461183a91906151b0565b9250508190555081610165600082825461185491906151b0565b90915550506040518281527f57862a4c7c9609bb49b8647efa7e361d1d46b3592a92bcbc155ff14e63d008ca906020015b60405180910390a15050565b6118996135f0565b61016b5481106118bc576040516351178ec360e11b815260040160405180910390fd5b600061016b82815481106118d2576118d26153fa565b906000526020600020906005020190506118f460fe546001600160a01b031690565b6001600160a01b0316336001600160a01b0316146119725760018101546001600160a01b031633146119395760405163f1895cc160e01b815260040160405180910390fd5b6000600482015460ff16600381111561195457611954614d11565b14611972576040516376fbfcc160e01b815260040160405180910390fd5b60048101805460ff191660031790556040518281527ff7c1cb19948ba96610f64144245e5d6ea4101c96aa87e6a7631ed37c7166f8f290602001611885565b610169546001600160a01b031633146119dd57604051635d20756160e11b815260040160405180910390fd5b6119e56135f0565b61016554811115611a0957604051630d8f3fc760e01b815260040160405180910390fd5b806101656000828254611a1c9190615186565b90915550506040518181527f82bf380f1b586a2cb47c47dff78d7909ab424b5b53484897342a6cdcc44a615090602001611590565b611a59613359565b8015611a9857655af3107a4000811080611a7a5750670de0b6b3a764000081115b15611a98576040516306e6abbd60e31b815260040160405180910390fd5b611aa0613644565b6101688190556040518181527ff1de0feffe91b255ad9cc1bf8cc8c88801936a593711b57df4d8e2bae3c2409c90602001611590565b611ade614a6d565b610172548210611b015760405163629bd69760e11b815260040160405180910390fd5b6101728281548110611b1557611b156153fa565b6000918252602091829020604080516101208101825260099093029091018054835260018101546001600160a01b0390811694840194909452600281015490931690820152600380830154606083015260048301546080830152600583015460a0830152600683015460c0830152600783015460e0830152600883015491929161010084019160ff909116908111156114ae576114ae614d11565b600080611bbe8585856137c2565b5098975050505050505050565b6000611bd6826115f6565b831115611c255760405162461bcd60e51b815260206004820152601e60248201527f455243343632363a206465706f736974206d6f7265207468616e206d617800006044820152606401610e2a565b6000611c3084612985565b905061139033848684613ab7565b611c46613359565b6115f46000613ad3565b610173546001600160a01b03163314611c7c5760405163382c53d160e01b815260040160405180910390fd5b60006101728281548110611c9257611c926153fa565b6000918252602082206009909102019150600882015460ff166003811115611cbc57611cbc614d11565b14611cda576040516305781a7560e21b815260040160405180910390fd5b600181015460028201546003830154600092611d04926001600160a01b03918216929116906137c2565b5050509150508160040154811015611dd1576004820154600090611d3083670de0b6b3a7640000615199565b611d3a9190615410565b611d4c90670de0b6b3a7640000615186565b905082600701548110611dcf5760088301805460ff1916600317905560408051858152602081018290526011918101919091527f736c69707061676520746f6f206869676800000000000000000000000000000060608201527ff13b80e80ca0d024284bc86c58b4582daa1ca17e5f5bf9419ea73617e72b0899906080016110e6565b505b600282015460038301546001840154611df7926001600160a01b03908116929116613b25565b60088201805460ff191660011790556040518381527f67a15bfa8401d8d00a1d0821edd3a314f2b79e25b94a3cadd5d32822c44049959060200160405180910390a150505b50565b6001600160a01b038116600090815260cb602052604081205461101f565b611e65613359565b6115f4613175565b611e756135f0565b611e7d613644565b611e8a6101675482612eff565b9050806101676000828254611e9f9190615186565b90915550506000819003611ec65760405163681f819160e11b815260040160405180910390fd5b611ecf81613657565b611ed881613cc5565b60408051338152602081018390527fb9ad861b752f80117b35bea6dec99933d8a5ae360f2839ee8784b750d56134099101611590565b600080611f1a84612434565b905061139033848387613ab7565b606060378054610cff906151c3565b606061016b805480602002602001604051908101604052809291908181526020016000905b82821015611ff35760008481526020908190206040805160a081018252600586029092018054835260018101546001600160a01b03169383019390935260028301549082015260038083015460608301526004830154919291608084019160ff90911690811115611fcf57611fcf614d11565b6003811115611fe057611fe0614d11565b8152505081526020019060010190611f5c565b50505050905090565b3360008181526034602090815260408083206001600160a01b0387168452909152812054909190838110156120815760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610e2a565b61208e8286868403613203565b506001949350505050565b600033611033818585613445565b610169546001600160a01b031633146120d357604051635d20756160e11b815260040160405180910390fd5b6120db6135f0565b610163548111156120ff57604051636cd97a3360e01b815260040160405180910390fd5b612107613644565b80610163600082825461211a9190615186565b90915550612129905081613cc5565b6040518181527fc33e186e013ab6a7cffd5fd742b9eb61ded715b75fb3a853c3e4c7b056e3e33f90602001611590565b612161613359565b80156121a057655af3107a4000811080612182575067016345785d8a000081115b156121a057604051636463506f60e11b815260040160405180910390fd5b6101748190556040518181527f123cff73d38fa797c2397390c45254c0d254c405ab670bb25804ceb5a857d40490602001611590565b6060610ceb611f28565b6121e86135f0565b600080806121f73387876137c2565b945094505093505080866001600160a01b031663dd62ed3e6122163390565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152306024820152604401602060405180830381865afa158015612260573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122849190615157565b10156122a3576040516313be252b60e01b815260040160405180910390fd5b610172805460408051610120810190915281815290919060208101336001600160a01b03168152602001896001600160a01b031681526020018881526020018681526020018581526020018481526020018781526020016000600381111561230d5761230d614d11565b9052815460018181018455600093845260209384902083516009909302019182559282015181840180546001600160a01b039283166001600160a01b031991821617909155604084015160028401805491909316911617905560608201516003808301919091556080830151600483015560a0830151600583015560c0830151600683015560e08301516007830155610100830151600883018054949593949193909260ff199092169184908111156123c8576123c8614d11565b021790555050506123d63390565b604080516001600160a01b038a8116825260208201869052918101879052606081018690529116907f2b3af6af3538582951321c20d48abba6ec9480eb26f2c5a077a3a132cb7f433a9060800160405180910390a250505050505050565b600061101f8260016131d0565b600061244c826129ff565b84111561249b5760405162461bcd60e51b815260206004820152601f60248201527f455243343632363a207769746864726177206d6f7265207468616e206d6178006044820152606401610e2a565b60006124a68561103d565b90506124b53385858885613d8a565b949350505050565b60006124c882612be9565b8411156125175760405162461bcd60e51b815260206004820152601d60248201527f455243343632363a2072656465656d206d6f7265207468616e206d61780000006044820152606401610e2a565b600061252285611012565b90506124b53385858489613d8a565b61016b818154811061254257600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b0390911692909160ff1685565b610169546001600160a01b031633146125ac57604051635d20756160e11b815260040160405180910390fd5b6125b46135f0565b806000036125d5576040516363555d5760e01b815260040160405180910390fd5b61016b80546040805160a081018252828152336020820190815291810185815260006060830181815260808401828152600180880189559790925283517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f46005880290810191825595517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f5870180546001600160a01b0319166001600160a01b0390921691909117905592517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f6860155517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f7850155517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f8909301805494959294919392909160ff19169083600381111561271157612711614d11565b02179055505060408051838152602081018590527ffacaaf1ea31830f024c7e2228efe6d49994f6b1ac543f2f1ed66ba564f6154f8925001611885565b612756613359565b6001600160a01b038216600090815261016d602052604090205460ff1615158115151461283f576001600160a01b038216600081815261016d6020908152604091829020805460ff19168515159081179091558251938452908301527fd7d0b811a185af1abebe234a3b8499c04eb6aab5b16dccd673eec1802eb82094910160405180910390a180156128335761016e80546001810182556000919091527ff82fbbf6ecba5c6bca8ffdb165c351ca78f1011f756f9b1202212482fd7d83130180546001600160a01b0319166001600160a01b0384161790555050565b61283f8261016e613dae565b5050565b61284b613359565b61017380546001600160a01b0319166001600160a01b0383169081179091556040519081527f6740fd697b663f1b0205268614c357288bd270d247caa465da67a2d62e5b9f5690602001611590565b6060610172805480602002602001604051908101604052809291908181526020016000905b82821015611ff35760008481526020908190206040805161012081018252600986029092018054835260018101546001600160a01b0390811694840194909452600281015490931690820152600380830154606083015260048301546080830152600583015460a0830152600683015460c0830152600783015460e0830152600883015491929161010084019160ff9091169081111561296157612961614d11565b600381111561297257612972614d11565b81525050815260200190600101906128bf565b600061101f826000613327565b61299a613359565b610169546001600160a01b03828116911614611e3c5761016980546001600160a01b0319166001600160a01b0383169081179091556040519081527fe04946a482d4e81124cf46321be733aca4133ddfc19ce89a6106b4de11d33c8b90602001611590565b6001600160a01b03811660009081526033602052604081205461101f9060006131d0565b606061016e805480602002602001604051908101604052809291908181526020018280548015610d7857602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612a5e575050505050905090565b83421115612ad55760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610e2a565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9888888612b048c613ecd565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000612b5f82613ef5565b90506000612b6f82878787613f43565b9050896001600160a01b0316816001600160a01b031614612bd25760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610e2a565b612bdd8a8a8a613203565b50505050505050505050565b6001600160a01b03811660009081526033602052604081205461101f565b610173546001600160a01b03163314612c335760405163382c53d160e01b815260040160405180910390fd5b60006101728481548110612c4957612c496153fa565b6000918252602082206009909102019150600882015460ff166003811115612c7357612c73614d11565b14612c91576040516305781a7560e21b815260040160405180910390fd5b60088101805460ff191660021790556040517f4f673bc8b0a3897f9318f64f136112be2c3e9accff5908bc497a16c0b9b61532906110e690869086908690615424565b612cdc613359565b6001600160a01b038216600090815261016a602052604090205460ff1615158115151461283f576001600160a01b038216600081815261016a6020908152604091829020805460ff19168515159081179091558251938452908301527fda8ea5b9387cad120a4ab700c57a328a62a82f8b2bee3337ae0fc4276858a8cd9101611885565b612d68613359565b61016355565b612d76613359565b6001600160a01b038116612ddb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610e2a565b611e3c81613ad3565b61016c546000905b61016b54811015612ee757600061016b8281548110612e0d57612e0d6153fa565b60009182526020918290206040805160a08101825260059093029091018054835260018101546001600160a01b03169383019390935260028301549082015260038083015460608301526004830154919291608084019160ff90911690811115612e7957612e79614d11565b6003811115612e8a57612e8a614d11565b9052509050600081608001516003811115612ea757612ea7614d11565b1480612ec85750600281608001516003811115612ec657612ec6614d11565b145b15612ed4575192915050565b5080612edf8161545a565b915050612dec565b50600019905090565b6001600160a01b03163b151590565b6000818310612f0e5781611390565b5090919050565b600080612f23868686613f6b565b90506001836002811115612f3957612f39614d11565b148015612f56575060008480612f5157612f516153b6565b868809115b15612f6957612f666001826151b0565b90505b95945050505050565b600054610100900460ff16612f995760405162461bcd60e51b8152600401610e2a90615473565b6036612fa5838261551a565b506037612fb2828261551a565b505050565b600054610100900460ff16612fde5760405162461bcd60e51b8152600401610e2a90615473565b611e3c81604051806040016040528060018152602001603160f81b81525061401a565b600054610100900460ff166115f45760405162461bcd60e51b8152600401610e2a90615473565b600054610100900460ff1661304f5760405162461bcd60e51b8152600401610e2a90615473565b6115f433613ad3565b600054610100900460ff1661307f5760405162461bcd60e51b8152600401610e2a90615473565b610130805460ff19169055565b600054610100900460ff166130b35760405162461bcd60e51b8152600401610e2a90615473565b6000806130bf8361405b565b91509150816130cf5760126130d1565b805b606580546001600160a01b039095166001600160a01b031960ff93909316600160a01b029290921674ffffffffffffffffffffffffffffffffffffffffff1990951694909417179092555050565b61313130670de0b6b3a7640000614139565b670de0b6b3a7640000610167600082825461314c91906151b0565b92505081905550670de0b6b3a7640000610163600082825461316e91906151b0565b9091555050565b61317d6135f0565b610130805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586131b33390565b6040516001600160a01b03909116815260200160405180910390a1565b6000806131dc60355490565b905080156131fd576131f86131ef610c61565b85908386612f15565b6124b5565b836124b5565b6001600160a01b0383166132655760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610e2a565b6001600160a01b0382166132c65760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610e2a565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60008061333360355490565b9050831580613340575080155b6131fd576131f881613350610c61565b86919086612f15565b60fe546001600160a01b031633146115f45760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610e2a565b6001600160a01b03838116600090815260346020908152604080832093861683529290522054600019811461343f57818110156134325760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610e2a565b61343f8484848403613203565b50505050565b6001600160a01b0383166134a95760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610e2a565b6001600160a01b03821661350b5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610e2a565b6001600160a01b038316600090815260336020526040902054818110156135835760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610e2a565b6001600160a01b0380851660008181526033602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906135e39086815260200190565b60405180910390a361343f565b6101305460ff16156115f45760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610e2a565b61364c610b44565b610167554261016655565b806101645410156136f25761016254610164546001600160a01b03909116906340c10f199030906136889085615186565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b1580156136ce57600080fd5b505af11580156136e2573d6000803e3d6000fd5b505060006101645550611e3c9050565b8061016460008282546137059190615186565b909155505050565b6000610ceb7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f61373c60975490565b6098546040805160208101859052908101839052606081018290524660808201523060a082015260009060c0016040516020818303038152906040528051906020012090509392505050565b6137906141fa565b610130805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336131b3565b60008060008060006137ed886001600160a01b0316600090815261016a602052604090205460ff1690565b61380a5760405163cf83886b60e01b815260040160405180910390fd5b8560000361382b5760405163101f9d0560e21b815260040160405180910390fd5b6001600160a01b038716600090815261016d602052604090205460ff16613865576040516319e8d85b60e31b815260040160405180910390fd5b600019613870612de4565b0361388e57604051631ff5456560e11b815260040160405180910390fd5b600061016b61389b612de4565b815481106138ab576138ab6153fa565b906000526020600020906005020190506000806138c78a6110f4565b90925060ff16905060006138dc82600a6155da565b83613972866003015487600201546138f49190615186565b61016260009054906101000a90046001600160a01b03166001600160a01b031663b0f1c7e36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613948573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061396c91906151f7565b8f61424d565b61397c9190615199565b6139869190615410565b90506000818b11156139b057819a50846003015485600201546139a99190615186565b9050613a55565b836139bc84600a6155da565b613a3e8d8f61016260009054906101000a90046001600160a01b03166001600160a01b031663b0f1c7e36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613a15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a3991906151f7565b61424d565b613a489190615199565b613a529190615410565b90505b6000670de0b6b3a764000061017454670de0b6b3a7640000613a779190615186565b613a819084615199565b613a8b9190615410565b86549091508183613a9b82612985565b8f9a509a509a509a509a50505050505050939792965093509350565b613abf6135f0565b613ac7613644565b61343f84848484614268565b60fe80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000806000806000613b388689896137c2565b94509450945094509450600061016b8681548110613b5857613b586153fa565b600091825260208220600590910201805461016c5560048101805460ff1916600217905560038101805491935086929091613b949084906151b0565b90915550506003810154600282015403613bb85760048101805460ff191660011790555b613bc0613644565b836101636000828254613bd391906151b0565b90915550613be390508784614139565b610162546040516340c10f1960e01b8152306004820152602481018790526001600160a01b03909116906340c10f1990604401600060405180830381600087803b158015613c3057600080fd5b505af1158015613c44573d6000803e3d6000fd5b5050506001820154613c6491508a9089906001600160a01b0316856142e6565b604080516001600160a01b038b811682526020820185905291810187905260608101859052908816907f659989dc822d0d5e17512d0b34ae3f3521dd6d18c7dc83c1a94a8ba7bafa3bf09060800160405180910390a2505050505050505050565b6101625460408051630634faaf60e51b815290516000926001600160a01b03169163c69f55e09160048083019260209291908290030181865afa158015613d10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d3491906151f7565b90506000613d4f836012613d4785614351565b60ff166143b5565b905080600003613d725760405163feca61db60e01b815260040160405180910390fd5b612fb28233610162546001600160a01b0316846142e6565b613d926135f0565b613d9a613644565b613da78585858585614412565b5050505050565b6000805b8254613dc090600190615186565b811015613e9557836001600160a01b0316838281548110613de357613de36153fa565b6000918252602090912001546001600160a01b031603613e0257600191505b8115613e835782613e148260016151b0565b81548110613e2457613e246153fa565b9060005260206000200160009054906101000a90046001600160a01b0316838281548110613e5457613e546153fa565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b031602179055505b80613e8d8161545a565b915050613db2565b82805480613ea557613ea56155e6565b600082815260209020810160001990810180546001600160a01b031916905501905550505050565b6001600160a01b038116600090815260cb602052604090208054600181018255905b50919050565b600061101f613f0261370d565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6000806000613f54878787876144be565b91509150613f6181614582565b5095945050505050565b6000808060001985870985870292508281108382030391505080600003613fa557838281613f9b57613f9b6153b6565b0492505050611390565b808411613fb157600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b600054610100900460ff166140415760405162461bcd60e51b8152600401610e2a90615473565b815160209283012081519190920120609791909155609855565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290516000918291829182916001600160a01b038716916140a2916155fc565b6000604051808303816000865af19150503d80600081146140df576040519150601f19603f3d011682016040523d82523d6000602084013e6140e4565b606091505b50915091508180156140f857506020815110155b1561412c576000818060200190518101906141139190615157565b905060ff811161412a576001969095509350505050565b505b5060009485945092505050565b6001600160a01b03821661418f5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610e2a565b80603560008282546141a191906151b0565b90915550506001600160a01b0382166000818152603360209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6101305460ff166115f45760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610e2a565b60006124b58461425c85614351565b60ff16613d4785614351565b606554614280906001600160a01b03168530856142e6565b61428a8382614139565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d784846040516142d8929190918252602082015260400190565b60405180910390a350505050565b6040516001600160a01b038085166024830152831660448201526064810182905261343f9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526146cc565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614391573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061101f9190615283565b60008084848410156143e9576143cb8486615186565b91506143d882600a6155da565b6143e29087615410565b9050612f69565b84841115612f69576143fb8585615186565b915061440882600a6155da565b612f669087615199565b826001600160a01b0316856001600160a01b031614614436576144368386836133b3565b614440838261479e565b606554614457906001600160a01b031685846148d2565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db85856040516144af929190918252602082015260400190565b60405180910390a45050505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156144f55750600090506003614579565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614549573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661457257600060019250925050614579565b9150600090505b94509492505050565b600081600481111561459657614596614d11565b0361459e5750565b60018160048111156145b2576145b2614d11565b036145ff5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610e2a565b600281600481111561461357614613614d11565b036146605760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610e2a565b600381600481111561467457614674614d11565b03611e3c5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610e2a565b6000614721826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149029092919063ffffffff16565b805190915015612fb2578080602001905181019061473f9190615618565b612fb25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610e2a565b6001600160a01b0382166147fe5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610e2a565b6001600160a01b038216600090815260336020526040902054818110156148725760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610e2a565b6001600160a01b03831660008181526033602090815260408083208686039055603580548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6040516001600160a01b038316602482015260448101829052612fb290849063a9059cbb60e01b9060640161431a565b60606124b5848460008585600080866001600160a01b0316858760405161492991906155fc565b60006040518083038185875af1925050503d8060008114614966576040519150601f19603f3d011682016040523d82523d6000602084013e61496b565b606091505b509150915061497c87838387614987565b979650505050505050565b606083156149f65782516000036149ef576001600160a01b0385163b6149ef5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610e2a565b50816124b5565b6124b58383815115614a0b5781518083602001fd5b8060405162461bcd60e51b8152600401610e2a9190614afa565b6040518060a001604052806000815260200160006001600160a01b03168152602001600081526020016000815260200160006003811115614a6857614a68614d11565b905290565b6040518061012001604052806000815260200160006001600160a01b0316815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600081526020016000815260200160006003811115614a6857614a68614d11565b60005b83811015614af1578181015183820152602001614ad9565b50506000910152565b6020815260008251806020840152614b19816040850160208701614ad6565b601f01601f19169190910160400192915050565b60008083601f840112614b3f57600080fd5b50813567ffffffffffffffff811115614b5757600080fd5b602083019150836020828501011115614b6f57600080fd5b9250929050565b6001600160a01b0381168114611e3c57600080fd5b600080600080600060608688031215614ba357600080fd5b853567ffffffffffffffff80821115614bbb57600080fd5b614bc789838a01614b2d565b90975095506020880135915080821115614be057600080fd5b50614bed88828901614b2d565b9094509250506040860135614c0181614b76565b809150509295509295909350565b600060208284031215614c2157600080fd5b5035919050565b60008060408385031215614c3b57600080fd5b8235614c4681614b76565b946020939093013593505050565b8015158114611e3c57600080fd5b60008060008060808587031215614c7857600080fd5b8435614c8381614b76565b93506020850135614c9381614b76565b92506040850135614ca381614c54565b9396929550929360600135925050565b600060208284031215614cc557600080fd5b813561139081614b76565b600080600060608486031215614ce557600080fd5b8335614cf081614b76565b92506020840135614d0081614b76565b929592945050506040919091013590565b634e487b7160e01b600052602160045260246000fd5b60048110611e3c57634e487b7160e01b600052602160045260246000fd5b6000610120820190508a82526001600160a01b03808b166020840152808a166040840152508760608301528660808301528560a08301528460c08301528360e0830152614d9183614d27565b826101008301529a9950505050505050505050565b805182526001600160a01b03602082015116602083015260408101516040830152606081015160608301526080810151614ddf81614d27565b806080840152505050565b60a0810161101f8284614da6565b8051825260208101516001600160a01b0380821660208501528060408401511660408501525050606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151614e6181614d27565b92019190915250565b610120810161101f8284614df8565b60008060408385031215614e8c57600080fd5b823591506020830135614e9e81614b76565b809150509250929050565b6020808252825182820181905260009190848201906040850190845b81811015614eeb57614ed8838551614da6565b9284019260a09290920191600101614ec5565b50909695505050505050565b600080600060608486031215614f0c57600080fd5b8335614f1781614b76565b95602085013595506040909401359392505050565b600080600060608486031215614f4157600080fd5b833592506020840135614f5381614b76565b91506040840135614f6381614b76565b809150509250925092565b8581526001600160a01b0385166020820152604081018490526060810183905260a08101614f9b83614d27565b8260808301529695505050505050565b60008060408385031215614fbe57600080fd5b8235614fc981614b76565b91506020830135614e9e81614c54565b6020808252825182820181905260009190848201906040850190845b81811015614eeb57615008838551614df8565b928401926101209290920191600101614ff5565b6020808252825182820181905260009190848201906040850190845b81811015614eeb5783516001600160a01b031683529284019291840191600101615038565b60ff81168114611e3c57600080fd5b600080600080600080600060e0888a03121561508757600080fd5b873561509281614b76565b965060208801356150a281614b76565b9550604088013594506060880135935060808801356150c08161505d565b9699959850939692959460a0840135945060c09093013592915050565b6000806000604084860312156150f257600080fd5b83359250602084013567ffffffffffffffff81111561511057600080fd5b61511c86828701614b2d565b9497909650939450505050565b6000806040838503121561513c57600080fd5b823561514781614b76565b91506020830135614e9e81614b76565b60006020828403121561516957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561101f5761101f615170565b808202811582820484141761101f5761101f615170565b8082018082111561101f5761101f615170565b600181811c908216806151d757607f821691505b602082108103613eef57634e487b7160e01b600052602260045260246000fd5b60006020828403121561520957600080fd5b815161139081614b76565b805169ffffffffffffffffffff8116811461522e57600080fd5b919050565b600080600080600060a0868803121561524b57600080fd5b61525486615214565b945060208601519350604086015192506060860151915061527760808701615214565b90509295509295909350565b60006020828403121561529557600080fd5b81516113908161505d565b60ff81811683821602908116908181146152bc576152bc615170565b5092915050565b600181815b808511156152fe5781600019048211156152e4576152e4615170565b808516156152f157918102915b93841c93908002906152c8565b509250929050565b6000826153155750600161101f565b816153225750600061101f565b816001811461533857600281146153425761535e565b600191505061101f565b60ff84111561535357615353615170565b50506001821b61101f565b5060208310610133831016604e8410600b8410161715615381575081810a61101f565b61538b83836152c3565b806000190482111561539f5761539f615170565b029392505050565b600061139060ff841683615306565b634e487b7160e01b600052601260045260246000fd5b6000826153db576153db6153b6565b600160ff1b8214600019841416156153f5576153f5615170565b500590565b634e487b7160e01b600052603260045260246000fd5b60008261541f5761541f6153b6565b500490565b83815260406020820152816040820152818360608301376000818301606090810191909152601f909201601f1916010192915050565b60006001820161546c5761546c615170565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b634e487b7160e01b600052604160045260246000fd5b601f821115612fb257600081815260208120601f850160051c810160208610156154fb5750805b601f850160051c820191505b8181101561100a57828155600101615507565b815167ffffffffffffffff811115615534576155346154be565b6155488161554284546151c3565b846154d4565b602080601f83116001811461557d57600084156155655750858301515b600019600386901b1c1916600185901b17855561100a565b600085815260208120601f198616915b828110156155ac5788860151825594840194600190910190840161558d565b50858210156155ca5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60006113908383615306565b634e487b7160e01b600052603160045260246000fd5b6000825161560e818460208701614ad6565b9190910192915050565b60006020828403121561562a57600080fd5b815161139081614c5456fea2646970667358221220b3fcc682d38a75717c4f9a57798be23798d46d1d33e8ce3a5621c10a4746357564736f6c63430008110033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106104b55760003560e01c806383a86d2711610272578063c3e096b011610161578063d066555c116100de578063dd62ed3e116100a2578063effd18bf1161007c578063effd18bf14610b16578063f2fde38b14610b29578063fbeeb85814610b3c57600080fd5b8063dd62ed3e14610aca578063ee02204114610b03578063ef8b30f7146109fd57600080fd5b8063d066555c14610a68578063d079d3e014610a7c578063d505accf14610a91578063d905777e14610aa4578063db41207014610ab757600080fd5b8063c78d9c1711610125578063c78d9c1714610a10578063c89e436114610a1a578063ca5eb5e114610a2e578063cd0c0d0414610a41578063ce96cb7714610a5557600080fd5b8063c3e096b014610950578063c416a07214610963578063c63d75b614610978578063c6987f501461098d578063c6e6f592146109fd57600080fd5b8063ae306319116101ef578063b61d8037116101b3578063b61d8037146108e9578063ba087652146108f3578063ba56148614610906578063baf248451461092a578063c25121b01461093d57600080fd5b8063ae30631914610895578063af640d0f146108a8578063b1ca7ff9146108b0578063b3d7f6b9146108c3578063b460af94146108d657600080fd5b806395d89b411161023657806395d89b411461083f5780639c6d4fab14610847578063a457c2d71461085c578063a9059cbb1461086f578063ab7b1c891461088257600080fd5b806383a86d27146107f65780638456cb59146108005780638bdf67f2146108085780638da5cb5b1461081b57806394bf804d1461082c57600080fd5b80633644e515116103a957806357ded9c9116103265780636467f9b0116102ea578063715018a6116102c4578063715018a6146107c857806373dc52aa146107d05780637ecebe00146107e357600080fd5b80636467f9b0146107795780636e553f651461078c57806370a082311461079f57600080fd5b806357ded9c91461072657806359cee29c146107305780635c975abb146107435780635d16e1201461074f5780635f8d60941461075957600080fd5b8063405f57a51161036d578063405f57a5146106c057806348a838d9146106d35780634cdad506146105075780634df20310146106e6578063511761361461071357600080fd5b80633644e5151461066557806338d52e0f1461066d57806339509351146106925780633f4ba83a146106a5578063402d267d146106ad57600080fd5b80631647bce01161043757806323b872dd116103fb57806323b872dd146105e8578063262e49a9146105fb5780632fd4fe6414610623578063313ce56714610643578063362e864f1461065257600080fd5b80631647bce0146105975780631732c0f0146105c457806318160ddd146105cc57806319b9432a146105d45780631ad1870d146105de57600080fd5b8063095ea7b31161047e578063095ea7b31461051a5780630a28a4771461053d5780630daf694c146105505780630dca59c114610563578063122fe9551461056d57600080fd5b8062e3d05d146104ba57806301e1d114146104d557806306fdde03146104dd578063077f224a146104f257806307a2d13a14610507575b600080fd5b6104c2610b44565b6040519081526020015b60405180910390f35b6104c2610c61565b6104e5610cf0565b6040516104cc9190614afa565b610505610500366004614b8b565b610d82565b005b6104c2610515366004614c0f565b611012565b61052d610528366004614c28565b611025565b60405190151581526020016104cc565b6104c261054b366004614c0f565b61103d565b61050561055e366004614c62565b61104a565b6104c26101645481565b61058061057b366004614cb3565b6110f4565b6040805192835260ff9091166020830152016104cc565b61052d6105a5366004614cb3565b6001600160a01b0316600090815261016d602052604090205460ff1690565b6104c2611325565b6035546104c2565b6104c261016c5481565b6104c26101675481565b61052d6105f6366004614cd0565b611371565b61060e610609366004614c0f565b611397565b6040516104cc99989796959493929190614d45565b610636610631366004614c0f565b611403565b6040516104cc9190614dea565b604051601281526020016104cc565b610505610660366004614c0f565b6114c8565b6104c261159b565b6065546001600160a01b03165b6040516001600160a01b0390911681526020016104cc565b61052d6106a0366004614c28565b6115a5565b6105056115e4565b6104c26106bb366004614cb3565b6115f6565b6105056106ce366004614c0f565b611645565b6105056106e1366004614c0f565b611891565b61052d6106f4366004614cb3565b6001600160a01b0316600090815261016a602052604090205460ff1690565b610505610721366004614c0f565b6119b1565b6104c26101685481565b61050561073e366004614c0f565b611a51565b6101305460ff1661052d565b6104c26101745481565b61076c610767366004614c0f565b611ad6565b6040516104cc9190614e6a565b6104c2610787366004614cd0565b611bb0565b6104c261079a366004614e79565b611bcb565b6104c26107ad366004614cb3565b6001600160a01b031660009081526033602052604090205490565b610505611c3e565b6105056107de366004614c0f565b611c50565b6104c26107f1366004614cb3565b611e3f565b6104c26101665481565b610505611e5d565b610505610816366004614c0f565b611e6d565b60fe546001600160a01b031661067a565b6104c261083a366004614e79565b611f0e565b6104e5611f28565b61084f611f37565b6040516104cc9190614ea9565b61052d61086a366004614c28565b611ffc565b61052d61087d366004614c28565b612099565b610505610890366004614c0f565b6120a7565b6105056108a3366004614c0f565b612159565b6104e56121d6565b6105056108be366004614ef7565b6121e0565b6104c26108d1366004614c0f565b612434565b6104c26108e4366004614f2c565b612441565b6104c26101655481565b6104c2610901366004614f2c565b6124bd565b610919610914366004614c0f565b612531565b6040516104cc959493929190614f6e565b610505610938366004614c0f565b612580565b61050561094b366004614fab565b61274e565b61050561095e366004614cb3565b612843565b61096b61289a565b6040516104cc9190614fd9565b6104c2610986366004614cb3565b5060001990565b6109d861099b366004614cb3565b6001600160a01b03908116600090815261016f6020908152604080832054610170835281842054610171909352922054919092169260ff90921691565b604080516001600160a01b0390941684529115156020840152908201526060016104cc565b6104c2610a0b366004614c0f565b612985565b6104c26101635481565b6101695461067a906001600160a01b031681565b610505610a3c366004614cb3565b612992565b6101735461067a906001600160a01b031681565b6104c2610a63366004614cb3565b6129ff565b6101625461067a906001600160a01b031681565b610a84612a23565b6040516104cc919061501c565b610505610a9f36600461506c565b612a85565b6104c2610ab2366004614cb3565b612be9565b610505610ac53660046150dd565b612c07565b6104c2610ad8366004615129565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b610505610b11366004614fab565b612cd4565b610505610b24366004614c0f565b612d60565b610505610b37366004614cb3565b612d6e565b6104c2612de4565b600080610b596065546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610b9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc39190615157565b905060006101665442610bd69190615186565b90506101635460001480610be8575081155b80610bf4575061016854155b80610bfd575080155b15610c0d57610167549250505090565b6000610c1c8361016354612eff565b61016854909150600090610c3e9083906a1a1601fc4ea7109e00000084612f15565b9050610c4a8382615199565b61016754610c5891906151b0565b94505050505090565b6000610c6b610b44565b6065546001600160a01b03166040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610cbd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce19190615157565b610ceb91906151b0565b905090565b606060368054610cff906151c3565b80601f0160208091040260200160405190810160405280929190818152602001828054610d2b906151c3565b8015610d785780601f10610d4d57610100808354040283529160200191610d78565b820191906000526020600020905b815481529060010190602001808311610d5b57829003601f168201915b5050505050905090565b600054610100900460ff1615808015610da25750600054600160ff909116105b80610dbc5750303b158015610dbc575060005460ff166001145b610e335760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084015b60405180910390fd5b6000805460ff191660011790558015610e56576000805461ff0019166101001790555b61016280546001600160a01b0319166001600160a01b0384161790554261016655604080516020601f8801819004810282018101909252868152610ee891889088908190840183828082843760009201919091525050604080516020601f8a018190048102820181019092528881529250889150879081908401838280828437600092019190915250612f7292505050565b610f2786868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612fb792505050565b610f2f613001565b610f37613028565b610f3f613058565b610162546040805163b0f1c7e360e01b81529051610fb4926001600160a01b03169163b0f1c7e39160048083019260209291908290030181865afa158015610f8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610faf91906151f7565b61308c565b610fbc61311f565b610fc4613175565b801561100a576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b600061101f8260006131d0565b92915050565b600033611033818585613203565b5060019392505050565b600061101f826001613327565b611052613359565b6001600160a01b03848116600081815261016f6020908152604080832080546001600160a01b03191695891695861790556101708252808320805460ff191688151590811790915561017183529281902086905580519384529083019390935291810191909152606081018290527f19f8037573a6f1dca8dd47019e81324d6c71bf3d173626d5216ab311c119a977906080015b60405180910390a150505050565b6001600160a01b038116600090815261016d6020526040812054819060ff16611130576040516319e8d85b60e31b815260040160405180910390fd5b6001600160a01b03838116600090815261016f60205260409020541661116957604051634b2872f760e01b815260040160405180910390fd5b6001600160a01b03808416600090815261016f6020526040808220548151633fabe5a360e21b815291519293849391169163feaf968c9160048083019260a09291908290030181865afa1580156111c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e89190615233565b509350509250506000821361121057604051634d9c03cd60e01b815260040160405180910390fd5b6001600160a01b038516600090815261017160205260409020546112349042615186565b81101561125457604051633ad1a1c760e11b815260040160405180910390fd5b6001600160a01b03808616600090815261016f6020908152604080832054815163313ce56760e01b815291519394169263313ce567926004808401939192918290030181865afa1580156112ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d09190615283565b6001600160a01b0387166000908152610170602052604090205490915060ff161561131957826113018260026152a0565b61130c90600a6153a7565b61131691906153cc565b92505b91959194509092505050565b61016b546000908103611339575060001990565b61016b805461134a90600190615186565b8154811061135a5761135a6153fa565b906000526020600020906005020160000154905090565b60003361137f8582856133b3565b61138a858585613445565b60019150505b9392505050565b61017281815481106113a857600080fd5b60009182526020909120600990910201805460018201546002830154600384015460048501546005860154600687015460078801546008909801549698506001600160a01b0395861697949095169592949193909260ff1689565b61140b614a25565b61016b54821061142e576040516351178ec360e11b815260040160405180910390fd5b61016b8281548110611442576114426153fa565b60009182526020918290206040805160a08101825260059093029091018054835260018101546001600160a01b03169383019390935260028301549082015260038083015460608301526004830154919291608084019160ff909116908111156114ae576114ae614d11565b60038111156114bf576114bf614d11565b90525092915050565b610169546001600160a01b031633146114f457604051635d20756160e11b815260040160405180910390fd5b6114fc6135f0565b610165548111156115205760405163dc6cb44760e01b815260040160405180910390fd5b611528613644565b80610163600082825461153b91906151b0565b925050819055508061016560008282546115559190615186565b90915550611564905081613657565b6040518181527f8bcaf54fdd58f77929668a4fb080c72d97ef0af355f34139addb6dddaec09d17906020015b60405180910390a150565b6000610ceb61370d565b3360008181526034602090815260408083206001600160a01b038716845290915281205490919061103390829086906115df9087906151b0565b613203565b6115ec613359565b6115f4613788565b565b6000611600610c61565b610163541115806116145750600061016454115b8061162257506101305460ff165b1561162f57506000919050565b611637610c61565b6101635461101f9190615186565b610169546001600160a01b0316331461167157604051635d20756160e11b815260040160405180910390fd5b6116796135f0565b6101635481111561169d576040516301c650ef60e61b815260040160405180910390fd5b6116a5613644565b600061172c826116bd6065546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015611703573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117279190615157565b612eff565b905061016260009054906101000a90046001600160a01b03166001600160a01b031663b0f1c7e36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611782573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a691906151f7565b6001600160a01b03166342966c68826040518263ffffffff1660e01b81526004016117d391815260200190565b600060405180830381600087803b1580156117ed57600080fd5b505af1158015611801573d6000803e3d6000fd5b505050508161016360008282546118189190615186565b9091555061182890508183615186565b610164600082825461183a91906151b0565b9250508190555081610165600082825461185491906151b0565b90915550506040518281527f57862a4c7c9609bb49b8647efa7e361d1d46b3592a92bcbc155ff14e63d008ca906020015b60405180910390a15050565b6118996135f0565b61016b5481106118bc576040516351178ec360e11b815260040160405180910390fd5b600061016b82815481106118d2576118d26153fa565b906000526020600020906005020190506118f460fe546001600160a01b031690565b6001600160a01b0316336001600160a01b0316146119725760018101546001600160a01b031633146119395760405163f1895cc160e01b815260040160405180910390fd5b6000600482015460ff16600381111561195457611954614d11565b14611972576040516376fbfcc160e01b815260040160405180910390fd5b60048101805460ff191660031790556040518281527ff7c1cb19948ba96610f64144245e5d6ea4101c96aa87e6a7631ed37c7166f8f290602001611885565b610169546001600160a01b031633146119dd57604051635d20756160e11b815260040160405180910390fd5b6119e56135f0565b61016554811115611a0957604051630d8f3fc760e01b815260040160405180910390fd5b806101656000828254611a1c9190615186565b90915550506040518181527f82bf380f1b586a2cb47c47dff78d7909ab424b5b53484897342a6cdcc44a615090602001611590565b611a59613359565b8015611a9857655af3107a4000811080611a7a5750670de0b6b3a764000081115b15611a98576040516306e6abbd60e31b815260040160405180910390fd5b611aa0613644565b6101688190556040518181527ff1de0feffe91b255ad9cc1bf8cc8c88801936a593711b57df4d8e2bae3c2409c90602001611590565b611ade614a6d565b610172548210611b015760405163629bd69760e11b815260040160405180910390fd5b6101728281548110611b1557611b156153fa565b6000918252602091829020604080516101208101825260099093029091018054835260018101546001600160a01b0390811694840194909452600281015490931690820152600380830154606083015260048301546080830152600583015460a0830152600683015460c0830152600783015460e0830152600883015491929161010084019160ff909116908111156114ae576114ae614d11565b600080611bbe8585856137c2565b5098975050505050505050565b6000611bd6826115f6565b831115611c255760405162461bcd60e51b815260206004820152601e60248201527f455243343632363a206465706f736974206d6f7265207468616e206d617800006044820152606401610e2a565b6000611c3084612985565b905061139033848684613ab7565b611c46613359565b6115f46000613ad3565b610173546001600160a01b03163314611c7c5760405163382c53d160e01b815260040160405180910390fd5b60006101728281548110611c9257611c926153fa565b6000918252602082206009909102019150600882015460ff166003811115611cbc57611cbc614d11565b14611cda576040516305781a7560e21b815260040160405180910390fd5b600181015460028201546003830154600092611d04926001600160a01b03918216929116906137c2565b5050509150508160040154811015611dd1576004820154600090611d3083670de0b6b3a7640000615199565b611d3a9190615410565b611d4c90670de0b6b3a7640000615186565b905082600701548110611dcf5760088301805460ff1916600317905560408051858152602081018290526011918101919091527f736c69707061676520746f6f206869676800000000000000000000000000000060608201527ff13b80e80ca0d024284bc86c58b4582daa1ca17e5f5bf9419ea73617e72b0899906080016110e6565b505b600282015460038301546001840154611df7926001600160a01b03908116929116613b25565b60088201805460ff191660011790556040518381527f67a15bfa8401d8d00a1d0821edd3a314f2b79e25b94a3cadd5d32822c44049959060200160405180910390a150505b50565b6001600160a01b038116600090815260cb602052604081205461101f565b611e65613359565b6115f4613175565b611e756135f0565b611e7d613644565b611e8a6101675482612eff565b9050806101676000828254611e9f9190615186565b90915550506000819003611ec65760405163681f819160e11b815260040160405180910390fd5b611ecf81613657565b611ed881613cc5565b60408051338152602081018390527fb9ad861b752f80117b35bea6dec99933d8a5ae360f2839ee8784b750d56134099101611590565b600080611f1a84612434565b905061139033848387613ab7565b606060378054610cff906151c3565b606061016b805480602002602001604051908101604052809291908181526020016000905b82821015611ff35760008481526020908190206040805160a081018252600586029092018054835260018101546001600160a01b03169383019390935260028301549082015260038083015460608301526004830154919291608084019160ff90911690811115611fcf57611fcf614d11565b6003811115611fe057611fe0614d11565b8152505081526020019060010190611f5c565b50505050905090565b3360008181526034602090815260408083206001600160a01b0387168452909152812054909190838110156120815760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610e2a565b61208e8286868403613203565b506001949350505050565b600033611033818585613445565b610169546001600160a01b031633146120d357604051635d20756160e11b815260040160405180910390fd5b6120db6135f0565b610163548111156120ff57604051636cd97a3360e01b815260040160405180910390fd5b612107613644565b80610163600082825461211a9190615186565b90915550612129905081613cc5565b6040518181527fc33e186e013ab6a7cffd5fd742b9eb61ded715b75fb3a853c3e4c7b056e3e33f90602001611590565b612161613359565b80156121a057655af3107a4000811080612182575067016345785d8a000081115b156121a057604051636463506f60e11b815260040160405180910390fd5b6101748190556040518181527f123cff73d38fa797c2397390c45254c0d254c405ab670bb25804ceb5a857d40490602001611590565b6060610ceb611f28565b6121e86135f0565b600080806121f73387876137c2565b945094505093505080866001600160a01b031663dd62ed3e6122163390565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152306024820152604401602060405180830381865afa158015612260573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122849190615157565b10156122a3576040516313be252b60e01b815260040160405180910390fd5b610172805460408051610120810190915281815290919060208101336001600160a01b03168152602001896001600160a01b031681526020018881526020018681526020018581526020018481526020018781526020016000600381111561230d5761230d614d11565b9052815460018181018455600093845260209384902083516009909302019182559282015181840180546001600160a01b039283166001600160a01b031991821617909155604084015160028401805491909316911617905560608201516003808301919091556080830151600483015560a0830151600583015560c0830151600683015560e08301516007830155610100830151600883018054949593949193909260ff199092169184908111156123c8576123c8614d11565b021790555050506123d63390565b604080516001600160a01b038a8116825260208201869052918101879052606081018690529116907f2b3af6af3538582951321c20d48abba6ec9480eb26f2c5a077a3a132cb7f433a9060800160405180910390a250505050505050565b600061101f8260016131d0565b600061244c826129ff565b84111561249b5760405162461bcd60e51b815260206004820152601f60248201527f455243343632363a207769746864726177206d6f7265207468616e206d6178006044820152606401610e2a565b60006124a68561103d565b90506124b53385858885613d8a565b949350505050565b60006124c882612be9565b8411156125175760405162461bcd60e51b815260206004820152601d60248201527f455243343632363a2072656465656d206d6f7265207468616e206d61780000006044820152606401610e2a565b600061252285611012565b90506124b53385858489613d8a565b61016b818154811061254257600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294506001600160a01b0390911692909160ff1685565b610169546001600160a01b031633146125ac57604051635d20756160e11b815260040160405180910390fd5b6125b46135f0565b806000036125d5576040516363555d5760e01b815260040160405180910390fd5b61016b80546040805160a081018252828152336020820190815291810185815260006060830181815260808401828152600180880189559790925283517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f46005880290810191825595517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f5870180546001600160a01b0319166001600160a01b0390921691909117905592517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f6860155517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f7850155517f45c4c4b2842a4a2a717cf0ddf6c6d1dee52b7fd8d9da97eb519765c7a27020f8909301805494959294919392909160ff19169083600381111561271157612711614d11565b02179055505060408051838152602081018590527ffacaaf1ea31830f024c7e2228efe6d49994f6b1ac543f2f1ed66ba564f6154f8925001611885565b612756613359565b6001600160a01b038216600090815261016d602052604090205460ff1615158115151461283f576001600160a01b038216600081815261016d6020908152604091829020805460ff19168515159081179091558251938452908301527fd7d0b811a185af1abebe234a3b8499c04eb6aab5b16dccd673eec1802eb82094910160405180910390a180156128335761016e80546001810182556000919091527ff82fbbf6ecba5c6bca8ffdb165c351ca78f1011f756f9b1202212482fd7d83130180546001600160a01b0319166001600160a01b0384161790555050565b61283f8261016e613dae565b5050565b61284b613359565b61017380546001600160a01b0319166001600160a01b0383169081179091556040519081527f6740fd697b663f1b0205268614c357288bd270d247caa465da67a2d62e5b9f5690602001611590565b6060610172805480602002602001604051908101604052809291908181526020016000905b82821015611ff35760008481526020908190206040805161012081018252600986029092018054835260018101546001600160a01b0390811694840194909452600281015490931690820152600380830154606083015260048301546080830152600583015460a0830152600683015460c0830152600783015460e0830152600883015491929161010084019160ff9091169081111561296157612961614d11565b600381111561297257612972614d11565b81525050815260200190600101906128bf565b600061101f826000613327565b61299a613359565b610169546001600160a01b03828116911614611e3c5761016980546001600160a01b0319166001600160a01b0383169081179091556040519081527fe04946a482d4e81124cf46321be733aca4133ddfc19ce89a6106b4de11d33c8b90602001611590565b6001600160a01b03811660009081526033602052604081205461101f9060006131d0565b606061016e805480602002602001604051908101604052809291908181526020018280548015610d7857602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612a5e575050505050905090565b83421115612ad55760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610e2a565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9888888612b048c613ecd565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000612b5f82613ef5565b90506000612b6f82878787613f43565b9050896001600160a01b0316816001600160a01b031614612bd25760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610e2a565b612bdd8a8a8a613203565b50505050505050505050565b6001600160a01b03811660009081526033602052604081205461101f565b610173546001600160a01b03163314612c335760405163382c53d160e01b815260040160405180910390fd5b60006101728481548110612c4957612c496153fa565b6000918252602082206009909102019150600882015460ff166003811115612c7357612c73614d11565b14612c91576040516305781a7560e21b815260040160405180910390fd5b60088101805460ff191660021790556040517f4f673bc8b0a3897f9318f64f136112be2c3e9accff5908bc497a16c0b9b61532906110e690869086908690615424565b612cdc613359565b6001600160a01b038216600090815261016a602052604090205460ff1615158115151461283f576001600160a01b038216600081815261016a6020908152604091829020805460ff19168515159081179091558251938452908301527fda8ea5b9387cad120a4ab700c57a328a62a82f8b2bee3337ae0fc4276858a8cd9101611885565b612d68613359565b61016355565b612d76613359565b6001600160a01b038116612ddb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610e2a565b611e3c81613ad3565b61016c546000905b61016b54811015612ee757600061016b8281548110612e0d57612e0d6153fa565b60009182526020918290206040805160a08101825260059093029091018054835260018101546001600160a01b03169383019390935260028301549082015260038083015460608301526004830154919291608084019160ff90911690811115612e7957612e79614d11565b6003811115612e8a57612e8a614d11565b9052509050600081608001516003811115612ea757612ea7614d11565b1480612ec85750600281608001516003811115612ec657612ec6614d11565b145b15612ed4575192915050565b5080612edf8161545a565b915050612dec565b50600019905090565b6001600160a01b03163b151590565b6000818310612f0e5781611390565b5090919050565b600080612f23868686613f6b565b90506001836002811115612f3957612f39614d11565b148015612f56575060008480612f5157612f516153b6565b868809115b15612f6957612f666001826151b0565b90505b95945050505050565b600054610100900460ff16612f995760405162461bcd60e51b8152600401610e2a90615473565b6036612fa5838261551a565b506037612fb2828261551a565b505050565b600054610100900460ff16612fde5760405162461bcd60e51b8152600401610e2a90615473565b611e3c81604051806040016040528060018152602001603160f81b81525061401a565b600054610100900460ff166115f45760405162461bcd60e51b8152600401610e2a90615473565b600054610100900460ff1661304f5760405162461bcd60e51b8152600401610e2a90615473565b6115f433613ad3565b600054610100900460ff1661307f5760405162461bcd60e51b8152600401610e2a90615473565b610130805460ff19169055565b600054610100900460ff166130b35760405162461bcd60e51b8152600401610e2a90615473565b6000806130bf8361405b565b91509150816130cf5760126130d1565b805b606580546001600160a01b039095166001600160a01b031960ff93909316600160a01b029290921674ffffffffffffffffffffffffffffffffffffffffff1990951694909417179092555050565b61313130670de0b6b3a7640000614139565b670de0b6b3a7640000610167600082825461314c91906151b0565b92505081905550670de0b6b3a7640000610163600082825461316e91906151b0565b9091555050565b61317d6135f0565b610130805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586131b33390565b6040516001600160a01b03909116815260200160405180910390a1565b6000806131dc60355490565b905080156131fd576131f86131ef610c61565b85908386612f15565b6124b5565b836124b5565b6001600160a01b0383166132655760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610e2a565b6001600160a01b0382166132c65760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610e2a565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60008061333360355490565b9050831580613340575080155b6131fd576131f881613350610c61565b86919086612f15565b60fe546001600160a01b031633146115f45760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610e2a565b6001600160a01b03838116600090815260346020908152604080832093861683529290522054600019811461343f57818110156134325760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610e2a565b61343f8484848403613203565b50505050565b6001600160a01b0383166134a95760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610e2a565b6001600160a01b03821661350b5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610e2a565b6001600160a01b038316600090815260336020526040902054818110156135835760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610e2a565b6001600160a01b0380851660008181526033602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906135e39086815260200190565b60405180910390a361343f565b6101305460ff16156115f45760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610e2a565b61364c610b44565b610167554261016655565b806101645410156136f25761016254610164546001600160a01b03909116906340c10f199030906136889085615186565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b1580156136ce57600080fd5b505af11580156136e2573d6000803e3d6000fd5b505060006101645550611e3c9050565b8061016460008282546137059190615186565b909155505050565b6000610ceb7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f61373c60975490565b6098546040805160208101859052908101839052606081018290524660808201523060a082015260009060c0016040516020818303038152906040528051906020012090509392505050565b6137906141fa565b610130805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa336131b3565b60008060008060006137ed886001600160a01b0316600090815261016a602052604090205460ff1690565b61380a5760405163cf83886b60e01b815260040160405180910390fd5b8560000361382b5760405163101f9d0560e21b815260040160405180910390fd5b6001600160a01b038716600090815261016d602052604090205460ff16613865576040516319e8d85b60e31b815260040160405180910390fd5b600019613870612de4565b0361388e57604051631ff5456560e11b815260040160405180910390fd5b600061016b61389b612de4565b815481106138ab576138ab6153fa565b906000526020600020906005020190506000806138c78a6110f4565b90925060ff16905060006138dc82600a6155da565b83613972866003015487600201546138f49190615186565b61016260009054906101000a90046001600160a01b03166001600160a01b031663b0f1c7e36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613948573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061396c91906151f7565b8f61424d565b61397c9190615199565b6139869190615410565b90506000818b11156139b057819a50846003015485600201546139a99190615186565b9050613a55565b836139bc84600a6155da565b613a3e8d8f61016260009054906101000a90046001600160a01b03166001600160a01b031663b0f1c7e36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613a15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a3991906151f7565b61424d565b613a489190615199565b613a529190615410565b90505b6000670de0b6b3a764000061017454670de0b6b3a7640000613a779190615186565b613a819084615199565b613a8b9190615410565b86549091508183613a9b82612985565b8f9a509a509a509a509a50505050505050939792965093509350565b613abf6135f0565b613ac7613644565b61343f84848484614268565b60fe80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000806000806000613b388689896137c2565b94509450945094509450600061016b8681548110613b5857613b586153fa565b600091825260208220600590910201805461016c5560048101805460ff1916600217905560038101805491935086929091613b949084906151b0565b90915550506003810154600282015403613bb85760048101805460ff191660011790555b613bc0613644565b836101636000828254613bd391906151b0565b90915550613be390508784614139565b610162546040516340c10f1960e01b8152306004820152602481018790526001600160a01b03909116906340c10f1990604401600060405180830381600087803b158015613c3057600080fd5b505af1158015613c44573d6000803e3d6000fd5b5050506001820154613c6491508a9089906001600160a01b0316856142e6565b604080516001600160a01b038b811682526020820185905291810187905260608101859052908816907f659989dc822d0d5e17512d0b34ae3f3521dd6d18c7dc83c1a94a8ba7bafa3bf09060800160405180910390a2505050505050505050565b6101625460408051630634faaf60e51b815290516000926001600160a01b03169163c69f55e09160048083019260209291908290030181865afa158015613d10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d3491906151f7565b90506000613d4f836012613d4785614351565b60ff166143b5565b905080600003613d725760405163feca61db60e01b815260040160405180910390fd5b612fb28233610162546001600160a01b0316846142e6565b613d926135f0565b613d9a613644565b613da78585858585614412565b5050505050565b6000805b8254613dc090600190615186565b811015613e9557836001600160a01b0316838281548110613de357613de36153fa565b6000918252602090912001546001600160a01b031603613e0257600191505b8115613e835782613e148260016151b0565b81548110613e2457613e246153fa565b9060005260206000200160009054906101000a90046001600160a01b0316838281548110613e5457613e546153fa565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b031602179055505b80613e8d8161545a565b915050613db2565b82805480613ea557613ea56155e6565b600082815260209020810160001990810180546001600160a01b031916905501905550505050565b6001600160a01b038116600090815260cb602052604090208054600181018255905b50919050565b600061101f613f0261370d565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6000806000613f54878787876144be565b91509150613f6181614582565b5095945050505050565b6000808060001985870985870292508281108382030391505080600003613fa557838281613f9b57613f9b6153b6565b0492505050611390565b808411613fb157600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b600054610100900460ff166140415760405162461bcd60e51b8152600401610e2a90615473565b815160209283012081519190920120609791909155609855565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290516000918291829182916001600160a01b038716916140a2916155fc565b6000604051808303816000865af19150503d80600081146140df576040519150601f19603f3d011682016040523d82523d6000602084013e6140e4565b606091505b50915091508180156140f857506020815110155b1561412c576000818060200190518101906141139190615157565b905060ff811161412a576001969095509350505050565b505b5060009485945092505050565b6001600160a01b03821661418f5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610e2a565b80603560008282546141a191906151b0565b90915550506001600160a01b0382166000818152603360209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6101305460ff166115f45760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610e2a565b60006124b58461425c85614351565b60ff16613d4785614351565b606554614280906001600160a01b03168530856142e6565b61428a8382614139565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d784846040516142d8929190918252602082015260400190565b60405180910390a350505050565b6040516001600160a01b038085166024830152831660448201526064810182905261343f9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526146cc565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614391573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061101f9190615283565b60008084848410156143e9576143cb8486615186565b91506143d882600a6155da565b6143e29087615410565b9050612f69565b84841115612f69576143fb8585615186565b915061440882600a6155da565b612f669087615199565b826001600160a01b0316856001600160a01b031614614436576144368386836133b3565b614440838261479e565b606554614457906001600160a01b031685846148d2565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db85856040516144af929190918252602082015260400190565b60405180910390a45050505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156144f55750600090506003614579565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614549573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661457257600060019250925050614579565b9150600090505b94509492505050565b600081600481111561459657614596614d11565b0361459e5750565b60018160048111156145b2576145b2614d11565b036145ff5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610e2a565b600281600481111561461357614613614d11565b036146605760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610e2a565b600381600481111561467457614674614d11565b03611e3c5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610e2a565b6000614721826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149029092919063ffffffff16565b805190915015612fb2578080602001905181019061473f9190615618565b612fb25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610e2a565b6001600160a01b0382166147fe5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610e2a565b6001600160a01b038216600090815260336020526040902054818110156148725760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610e2a565b6001600160a01b03831660008181526033602090815260408083208686039055603580548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6040516001600160a01b038316602482015260448101829052612fb290849063a9059cbb60e01b9060640161431a565b60606124b5848460008585600080866001600160a01b0316858760405161492991906155fc565b60006040518083038185875af1925050503d8060008114614966576040519150601f19603f3d011682016040523d82523d6000602084013e61496b565b606091505b509150915061497c87838387614987565b979650505050505050565b606083156149f65782516000036149ef576001600160a01b0385163b6149ef5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610e2a565b50816124b5565b6124b58383815115614a0b5781518083602001fd5b8060405162461bcd60e51b8152600401610e2a9190614afa565b6040518060a001604052806000815260200160006001600160a01b03168152602001600081526020016000815260200160006003811115614a6857614a68614d11565b905290565b6040518061012001604052806000815260200160006001600160a01b0316815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600081526020016000815260200160006003811115614a6857614a68614d11565b60005b83811015614af1578181015183820152602001614ad9565b50506000910152565b6020815260008251806020840152614b19816040850160208701614ad6565b601f01601f19169190910160400192915050565b60008083601f840112614b3f57600080fd5b50813567ffffffffffffffff811115614b5757600080fd5b602083019150836020828501011115614b6f57600080fd5b9250929050565b6001600160a01b0381168114611e3c57600080fd5b600080600080600060608688031215614ba357600080fd5b853567ffffffffffffffff80821115614bbb57600080fd5b614bc789838a01614b2d565b90975095506020880135915080821115614be057600080fd5b50614bed88828901614b2d565b9094509250506040860135614c0181614b76565b809150509295509295909350565b600060208284031215614c2157600080fd5b5035919050565b60008060408385031215614c3b57600080fd5b8235614c4681614b76565b946020939093013593505050565b8015158114611e3c57600080fd5b60008060008060808587031215614c7857600080fd5b8435614c8381614b76565b93506020850135614c9381614b76565b92506040850135614ca381614c54565b9396929550929360600135925050565b600060208284031215614cc557600080fd5b813561139081614b76565b600080600060608486031215614ce557600080fd5b8335614cf081614b76565b92506020840135614d0081614b76565b929592945050506040919091013590565b634e487b7160e01b600052602160045260246000fd5b60048110611e3c57634e487b7160e01b600052602160045260246000fd5b6000610120820190508a82526001600160a01b03808b166020840152808a166040840152508760608301528660808301528560a08301528460c08301528360e0830152614d9183614d27565b826101008301529a9950505050505050505050565b805182526001600160a01b03602082015116602083015260408101516040830152606081015160608301526080810151614ddf81614d27565b806080840152505050565b60a0810161101f8284614da6565b8051825260208101516001600160a01b0380821660208501528060408401511660408501525050606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151614e6181614d27565b92019190915250565b610120810161101f8284614df8565b60008060408385031215614e8c57600080fd5b823591506020830135614e9e81614b76565b809150509250929050565b6020808252825182820181905260009190848201906040850190845b81811015614eeb57614ed8838551614da6565b9284019260a09290920191600101614ec5565b50909695505050505050565b600080600060608486031215614f0c57600080fd5b8335614f1781614b76565b95602085013595506040909401359392505050565b600080600060608486031215614f4157600080fd5b833592506020840135614f5381614b76565b91506040840135614f6381614b76565b809150509250925092565b8581526001600160a01b0385166020820152604081018490526060810183905260a08101614f9b83614d27565b8260808301529695505050505050565b60008060408385031215614fbe57600080fd5b8235614fc981614b76565b91506020830135614e9e81614c54565b6020808252825182820181905260009190848201906040850190845b81811015614eeb57615008838551614df8565b928401926101209290920191600101614ff5565b6020808252825182820181905260009190848201906040850190845b81811015614eeb5783516001600160a01b031683529284019291840191600101615038565b60ff81168114611e3c57600080fd5b600080600080600080600060e0888a03121561508757600080fd5b873561509281614b76565b965060208801356150a281614b76565b9550604088013594506060880135935060808801356150c08161505d565b9699959850939692959460a0840135945060c09093013592915050565b6000806000604084860312156150f257600080fd5b83359250602084013567ffffffffffffffff81111561511057600080fd5b61511c86828701614b2d565b9497909650939450505050565b6000806040838503121561513c57600080fd5b823561514781614b76565b91506020830135614e9e81614b76565b60006020828403121561516957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561101f5761101f615170565b808202811582820484141761101f5761101f615170565b8082018082111561101f5761101f615170565b600181811c908216806151d757607f821691505b602082108103613eef57634e487b7160e01b600052602260045260246000fd5b60006020828403121561520957600080fd5b815161139081614b76565b805169ffffffffffffffffffff8116811461522e57600080fd5b919050565b600080600080600060a0868803121561524b57600080fd5b61525486615214565b945060208601519350604086015192506060860151915061527760808701615214565b90509295509295909350565b60006020828403121561529557600080fd5b81516113908161505d565b60ff81811683821602908116908181146152bc576152bc615170565b5092915050565b600181815b808511156152fe5781600019048211156152e4576152e4615170565b808516156152f157918102915b93841c93908002906152c8565b509250929050565b6000826153155750600161101f565b816153225750600061101f565b816001811461533857600281146153425761535e565b600191505061101f565b60ff84111561535357615353615170565b50506001821b61101f565b5060208310610133831016604e8410600b8410161715615381575081810a61101f565b61538b83836152c3565b806000190482111561539f5761539f615170565b029392505050565b600061139060ff841683615306565b634e487b7160e01b600052601260045260246000fd5b6000826153db576153db6153b6565b600160ff1b8214600019841416156153f5576153f5615170565b500590565b634e487b7160e01b600052603260045260246000fd5b60008261541f5761541f6153b6565b500490565b83815260406020820152816040820152818360608301376000818301606090810191909152601f909201601f1916010192915050565b60006001820161546c5761546c615170565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b634e487b7160e01b600052604160045260246000fd5b601f821115612fb257600081815260208120601f850160051c810160208610156154fb5750805b601f850160051c820191505b8181101561100a57828155600101615507565b815167ffffffffffffffff811115615534576155346154be565b6155488161554284546151c3565b846154d4565b602080601f83116001811461557d57600084156155655750858301515b600019600386901b1c1916600185901b17855561100a565b600085815260208120601f198616915b828110156155ac5788860151825594840194600190910190840161558d565b50858210156155ca5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60006113908383615306565b634e487b7160e01b600052603160045260246000fd5b6000825161560e818460208701614ad6565b9190910192915050565b60006020828403121561562a57600080fd5b815161139081614c5456fea2646970667358221220b3fcc682d38a75717c4f9a57798be23798d46d1d33e8ce3a5621c10a4746357564736f6c63430008110033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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.