false
false
0
The new Blockscout UI is now open source! Learn how to deploy it here

Contract Address Details

0x24f6225b84Bd6DEfb2BC90E3b566f26586Feb885

Contract Name
FeeDistributor
Creator
0x20a2af–32477c at 0x4e1c1b–1634a7
Balance
0 Haven
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
7495804
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
FeeDistributor




Optimization enabled
true
Compiler version
v0.8.19+commit.7dd6d404




Optimization runs
200
EVM Version
default




Verified at
2024-06-04T00:50:30.448705Z

contracts/governance/FeeDistributor.sol

Sol2uml
new
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.4;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";

import "../h1-native-application/H1NativeApplicationUpgradeable.sol";
import "./interfaces/IFeeDistributor.sol";
import "./interfaces/IVotingEscrow.sol";

/**
 * @title Fee Distributor
 * @author Balancer Labs. Original version:
 * https://github.com/balancer/balancer-v2-monorepo/blob/master/pkg
 * /liquidity-mining/contracts/fee-distribution/FeeDistributor.sol
 *
 * @notice Distributes any tokens transferred to the contract (e.g. Protocol fees)
 * among veH1 holders proportionally based on a snapshot of the week at which the
 * tokens are sent to the FeeDistributor contract.
 *
 * @dev Supports distributing arbitrarily many different tokens. In order to
 * start distributing a new token to veH1 holders call `depositToken`.
 */
contract FeeDistributor is
    IFeeDistributor,
    Initializable,
    AccessControlUpgradeable,
    H1NativeApplicationUpgradable,
    ReentrancyGuardUpgradeable,
    UUPSUpgradeable
{
    using SafeMathUpgradeable for uint256;
    using SafeERC20Upgradeable for IERC20Upgradeable;

    // gas optimization
    uint256 private constant WEEK_MINUS_SECOND = 1 weeks - 1;

    IVotingEscrow private _votingEscrow;

    uint256 private _startTime;

    // Global State
    uint256 private _timeCursor;
    mapping(uint256 => uint256) private _veSupplyCache;

    // Token State

    // `startTime` and `timeCursor` are both timestamps so comfortably fit in a
    // uint64.
    //
    // `cachedBalance` will comfortably fit the total supply of any meaningful
    // token.
    //
    // Should more than 2^128 tokens be sent to this contract then checkpointing
    // this token will fail until enough tokens have been claimed to bring the
    // total balance back below 2^128.
    struct TokenState {
        uint64 startTime;
        uint64 timeCursor;
        uint128 cachedBalance;
    }
    mapping(IERC20Upgradeable => TokenState) private _tokenState;
    mapping(IERC20Upgradeable => mapping(uint256 => uint256))
        private _tokensPerWeek;
    mapping(IERC20Upgradeable => bool) private _tokenClaimingEnabled;

    // User State

    // `startTime` and `timeCursor` are timestamps so will comfortably fit in a
    // uint64.
    // For `lastEpochCheckpointed` to overflow would need over 2^128 transactions
    // to the VotingEscrow contract.
    struct UserState {
        uint64 startTime;
        uint64 timeCursor;
        uint128 lastEpochCheckpointed;
    }
    mapping(address => UserState) internal _userState;
    mapping(address => mapping(uint256 => uint256))
        private _userBalanceAtTimestamp;
    mapping(address => mapping(IERC20Upgradeable => uint256))
        private _userTokenTimeCursor;
    mapping(address => bool) private _onlyVeHolderClaimingEnabled;

    // ------------------------------------------------------------------------
    // New State

    /**
     * @dev Mapping of reward token address to bool. Indicates whether a given
     * token has ever been a reward token.
     */
    mapping(address => bool) private _isHistoricalRewardToken;

    /**
     * @dev List of all tokens used as rewards for this contract. Tokens can be
     * pulled from here and then passed into `nPeriodRewards` to help with
     * generating UI metrics.
     */
    address[] private _historicalRewardTokens;

    // ------------------------------------------------------------------------

    /**
     * @dev Reverts if only the VotingEscrow holder can claim their rewards and
     * the given address is a third-party caller.
     * @param user - The address to validate as the only allowed caller.
     */
    modifier userAllowedToClaim(address user) {
        if (_onlyVeHolderClaimingEnabled[user]) {
            require(msg.sender == user, "Claiming is not allowed");
        }
        _;
    }

    /**
     * @dev Reverts if the given token cannot be claimed.
     * @param token - The token to check.
     */
    modifier tokenCanBeClaimed(IERC20Upgradeable token) {
        _checkIfClaimingEnabled(token);
        _;
    }

    /**
     * @dev Reverts if the given tokens cannot be claimed.
     * @param tokens - The tokens to check.
     */
    modifier tokensCanBeClaimed(IERC20Upgradeable[] calldata tokens) {
        uint256 tokensLength = tokens.length;
        for (uint256 i = 0; i < tokensLength; ++i) {
            _checkIfClaimingEnabled(tokens[i]);
        }
        _;
    }

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize(
        IVotingEscrow votingEscrow,
        uint256 startTime,
        address feeContract,
        address havenAssociation
    ) external initializer {
        __AccessControl_init();
        __ReentrancyGuard_init();
        __UUPSUpgradeable_init();
        _initializeBase(feeContract, havenAssociation);

        _grantRole(DEFAULT_ADMIN_ROLE, havenAssociation);

        _votingEscrow = votingEscrow;

        startTime = _roundDownTimestamp(startTime);
        uint256 currentWeek = _roundDownTimestamp(block.timestamp);
        require(startTime >= currentWeek, "Cannot start before current week");

        IVotingEscrow.Point memory pt = votingEscrow.point_history(0);
        require(
            startTime > pt.ts,
            "Cannot start before VotingEscrow first epoch"
        );

        _startTime = startTime;
        _timeCursor = startTime;
    }

    /**
     * @notice Returns the VotingEscrow (veH1) token contract
     */
    function getVotingEscrow() external view returns (IVotingEscrow) {
        return _votingEscrow;
    }

    /**
     * @notice Returns the time when fee distribution starts.
     */
    function getStartTime() external view returns (uint256) {
        return _startTime;
    }

    /**
     * @notice Returns the global time cursor representing the most earliest
     * uncheckpointed week.
     */
    function getTimeCursor() external view returns (uint256) {
        return _timeCursor;
    }

    /**
     * @notice Returns the user-level start time representing the first week
     * they're eligible to claim tokens.
     * @param user - The address of the user to query.
     */
    function getUserStartTime(address user) external view returns (uint256) {
        return _userState[user].startTime;
    }

    /**
     * @notice Returns the user-level time cursor representing the most earliest
     * uncheckpointed week.
     * @param user - The address of the user to query.
     */
    function getUserTimeCursor(address user) external view returns (uint256) {
        return _userState[user].timeCursor;
    }

    /**
     * @notice Returns the user-level last checkpointed epoch.
     * @param user - The address of the user to query.
     */
    function getUserLastEpochCheckpointed(
        address user
    ) external view returns (uint256) {
        return _userState[user].lastEpochCheckpointed;
    }

    /**
     * @notice True if the given token can be claimed, false otherwise.
     * @param token - The ERC20 token address to query.
     */
    function canTokenBeClaimed(
        IERC20Upgradeable token
    ) external view returns (bool) {
        return _tokenClaimingEnabled[token];
    }

    /**
     * @notice Returns the token-level start time representing the timestamp
     * users could start claiming this token
     * @param token - The ERC20 token address to query.
     */
    function getTokenStartTime(
        IERC20Upgradeable token
    ) external view returns (uint256) {
        return _tokenState[token].startTime;
    }

    /**
     * @notice Returns the token-level time cursor storing the timestamp at up
     * to which tokens have been distributed.
     * @param token - The ERC20 token address to query.
     */
    function getTokenTimeCursor(
        IERC20Upgradeable token
    ) external view returns (uint256) {
        return _tokenState[token].timeCursor;
    }

    /**
     * @notice Returns the token-level cached balance.
     * @param token - The ERC20 token address to query.
     */
    function getTokenCachedBalance(
        IERC20Upgradeable token
    ) external view returns (uint256) {
        return _tokenState[token].cachedBalance;
    }

    /**
     * @notice Returns the user-level time cursor storing the timestamp of the
     * latest token distribution claimed.
     * @param user - The address of the user to query.
     * @param token - The ERC20 token address to query.
     */
    function getUserTokenTimeCursor(
        address user,
        IERC20Upgradeable token
    ) external view returns (uint256) {
        return _getUserTokenTimeCursor(user, token);
    }

    /**
     * @notice Returns the user's cached balance of veH1 as of the provided
     * timestamp.
     *
     * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return
     * correct values. This function requires `user` to have been checkpointed
     * past `timestamp` so that their balance is cached.
     *
     * @param user - The address of the user of which to read the cached balance
     * of.
     *
     * @param timestamp - The timestamp at which to read the `user`'s cached
     * balance at.
     */
    function getUserBalanceAtTimestamp(
        address user,
        uint256 timestamp
    ) external view returns (uint256) {
        return _userBalanceAtTimestamp[user][timestamp];
    }

    /**
     * @notice Returns the cached total supply of veH1 as of the provided
     * timestamp.
     *
     * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return
     * correct values. This function requires the contract to have been
     * checkpointed past `timestamp` so that the supply is cached.
     *
     * @param timestamp - The timestamp at which to read the cached total supply
     * at.
     */
    function getTotalSupplyAtTimestamp(
        uint256 timestamp
    ) external view returns (uint256) {
        return _veSupplyCache[timestamp];
    }

    /**
     * @notice Returns the amount of `token` which the FeeDistributor received
     * in the week beginning at `timestamp`.
     *
     * @param token - The ERC20 token address to query.
     *
     * @param timestamp - The timestamp corresponding to the beginning of the
     * week of interest.
     */
    function getTokensDistributedInWeek(
        IERC20Upgradeable token,
        uint256 timestamp
    ) external view returns (uint256) {
        return _tokensPerWeek[token][timestamp];
    }

    // Preventing third-party claiming

    /**
     * @notice Enables / disables rewards claiming only by the VotingEscrow
     * holder for the message sender.
     *
     * @param enabled - True if only the VotingEscrow holder can claim their
     * rewards, false otherwise.
     */
    function enableOnlyVeHolderClaiming(bool enabled) external {
        _onlyVeHolderClaimingEnabled[msg.sender] = enabled;
        emit OnlyVeHolderClaimingEnabled(msg.sender, enabled);
    }

    /**
     * @notice Returns true if only the VotingEscrow holder can claim their
     * rewards, false otherwise.
     */
    function onlyVeHolderClaimingEnabled(
        address user
    ) external view returns (bool) {
        return _onlyVeHolderClaimingEnabled[user];
    }

    // Depositing

    /**
     * @notice Deposits tokens to be distributed in the current week.
     * @dev Sending tokens directly to the FeeDistributor instead of using
     * `depositToken` may result in tokens being retroactively distributed to
     * past weeks, or for the distribution to carry over to future weeks.
     *
     * If for some reason `depositToken` cannot be called, in order to ensure
     * that all tokens are correctly distributed manually call `checkpointToken`
     *  before and after the token transfer.
     *
     * @param token - The ERC20 token address to distribute.
     * @param amount - The amount of tokens to deposit.
     */
    function depositToken(
        IERC20Upgradeable token,
        uint256 amount
    ) external nonReentrant tokenCanBeClaimed(token) {
        _checkpointToken(token, false);
        token.safeTransferFrom(msg.sender, address(this), amount);
        _checkpointToken(token, true);
    }

    /**
     * @notice Deposits tokens to be distributed in the current week.
     *
     * @dev A version of `depositToken` which supports depositing multiple
     * `tokens` at once. See `depositToken` for more details.
     *
     * @param tokens - An array of ERC20 token addresses to distribute.
     * @param amounts - An array of token amounts to deposit.
     */
    function depositTokens(
        IERC20Upgradeable[] calldata tokens,
        uint256[] calldata amounts
    ) external nonReentrant {
        require(tokens.length == amounts.length, "Input length mismatch");

        uint256 length = tokens.length;
        for (uint256 i = 0; i < length; ++i) {
            _checkIfClaimingEnabled(tokens[i]);
            _checkpointToken(tokens[i], false);
            tokens[i].safeTransferFrom(msg.sender, address(this), amounts[i]);
            _checkpointToken(tokens[i], true);
        }
    }

    // Checkpointing

    /**
     * @notice Caches the total supply of veH1 at the beginning of each week.
     * This function will be called automatically before claiming tokens to
     * ensure the contract is properly updated.
     */
    function checkpoint() external nonReentrant {
        _checkpointTotalSupply();
    }

    /**
     * @notice Caches the user's balance of veH1 at the beginning of each week.
     * This function will be called automatically before claiming tokens to
     * ensure the contract is properly updated.
     * @param user - The address of the user to be checkpointed.
     */
    function checkpointUser(address user) external nonReentrant {
        _checkpointUserBalance(user);
    }

    /**
     * @notice Assigns any newly-received tokens held by the FeeDistributor to
     * weekly distributions.
     *
     * @dev Any `token` balance held by the FeeDistributor above that which is
     * returned by `getTokenLastBalance` will be distributed evenly across the
     * time period since `token` was last checkpointed.
     *
     * This function will be called automatically before claiming tokens to
     * ensure the contract is properly updated.
     *
     * @param token - The ERC20 token address to be checkpointed.
     */
    function checkpointToken(
        IERC20Upgradeable token
    ) external nonReentrant tokenCanBeClaimed(token) {
        _checkpointToken(token, true);
    }

    /**
     * @notice Assigns any newly-received tokens held by the FeeDistributor to
     * weekly distributions.
     *
     * @dev A version of `checkpointToken` which supports checkpointing multiple
     * tokens.
     *
     * See `checkpointToken` for more details.
     *
     * @param tokens - An array of ERC20 token addresses to be checkpointed.
     */
    function checkpointTokens(
        IERC20Upgradeable[] calldata tokens
    ) external nonReentrant {
        uint256 tokensLength = tokens.length;
        for (uint256 i = 0; i < tokensLength; ++i) {
            _checkIfClaimingEnabled(tokens[i]);
            _checkpointToken(tokens[i], true);
        }
    }

    // Claiming

    /**
     * @notice Claims all pending distributions of the provided token for a user.
     *
     * @dev It's not necessary to explicitly checkpoint before calling this
     * function, it will ensure the FeeDistributor is up to date before
     * calculating the amount of tokens to be claimed.
     *
     * @param user - The user on behalf of which to claim.
     * @param token - The ERC20 token address to be claimed.
     * @return The amount of `token` sent to `user` as a result of claiming.
     */
    function claimToken(
        address user,
        IERC20Upgradeable token
    )
        external
        payable
        nonReentrant
        userAllowedToClaim(user)
        tokenCanBeClaimed(token)
        applicationFee(false, true)
        returns (uint256)
    {
        _checkpointTotalSupply();
        _checkpointUserBalance(user);
        _checkpointToken(token, false);

        return _claimToken(user, token, false);
    }

    /**
     * @notice Claims a number of tokens on behalf of a user.
     * @dev A version of `claimToken` which supports claiming multiple `tokens`
     * on behalf of `user`.
     *
     * See `claimToken` for more details.
     *
     * @param user - The user on behalf of which to claim.
     * @param tokens - An array of ERC20 token addresses to be claimed.
     *
     * @return An array of the amounts of each token in `tokens` sent to `user`
     * as a result of claiming.
     */
    function claimTokens(
        address user,
        IERC20Upgradeable[] calldata tokens
    )
        external
        payable
        nonReentrant
        userAllowedToClaim(user)
        tokensCanBeClaimed(tokens)
        applicationFee(false, true)
        returns (uint256[] memory)
    {
        _checkpointTotalSupply();
        _checkpointUserBalance(user);

        uint256 tokensLength = tokens.length;
        uint256[] memory amounts = new uint256[](tokensLength);
        for (uint256 i = 0; i < tokensLength; ++i) {
            _checkpointToken(tokens[i], false);
            amounts[i] = _claimToken(user, tokens[i], false);
        }

        return amounts;
    }

    // Governance

    /**
     * @notice Withdraws the specified `amount` of the `token` from the contract
     * to the `recipient`. Can be called only by the Haven1 Association.
     *
     * @param token - The token to withdraw.
     * @param amount - The amount to withdraw.
     * @param recipient - The address to transfer the tokens to.
     */
    function withdrawToken(
        IERC20Upgradeable token,
        uint256 amount,
        address recipient
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        token.safeTransfer(recipient, amount);
        emit TokenWithdrawn(token, amount, recipient);
    }

    /**
     * @notice Enables or disables claiming of the given token. Can be called
     * only by the Haven1 Association.
     *
     * @param token - The token to enable or disable claiming.
     * @param enable - True if the token can be claimed, false otherwise.
     */
    function enableTokenClaiming(
        IERC20Upgradeable token,
        bool enable
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        _tokenClaimingEnabled[token] = enable;

        // only need to add if being enabled.
        // _addHistoricalRewardToken will check if the token already exists in
        // the list.
        if (enable) {
            _addHistoricalRewardToken(address(token));
        }

        emit TokenClaimingEnabled(token, enable);
    }

    // Internal functions

    /**
     * @dev It is required that both the global, token and user state have been
     * properly checkpointed before calling this function.
     * Breaking change from original: If `compound` is `true`, rather than
     * sending the tokens directly to the user, it will compound the rewards
     * into the `VotingEscrow` contract.
     * Note that for this to be successful, the user must have approved this
     * `FeeDistributor` contract to deposit on their behalf and have an active
     * lock. If neither of these are true, the transaction will revert.
     */
    function _claimToken(
        address user,
        IERC20Upgradeable token,
        bool compound
    ) internal returns (uint256) {
        TokenState storage tokenState = _tokenState[token];
        uint256 nextUserTokenWeekToClaim = _getUserTokenTimeCursor(user, token);

        // The first week which cannot be correctly claimed is the earliest of:
        // - A) The global or user time cursor (whichever is earliest), rounded
        //      up to the end of the week.
        // - B) The token time cursor, rounded down to the beginning of the week.
        //
        // This prevents the two failure modes:
        // - A) A user may claim a week for which we have not processed their
        //      balance, resulting in tokens being locked.
        // - B) A user may claim a week which then receives more tokens to be
        //      distributed. However the user has already claimed for that week
        //      so their share of these new tokens are lost.
        uint256 firstUnclaimableWeek = MathUpgradeable.min(
            _roundUpTimestamp(
                MathUpgradeable.min(_timeCursor, _userState[user].timeCursor)
            ),
            _roundDownTimestamp(tokenState.timeCursor)
        );

        mapping(uint256 => uint256) storage tokensPerWeek = _tokensPerWeek[
            token
        ];
        mapping(uint256 => uint256)
            storage userBalanceAtTimestamp = _userBalanceAtTimestamp[user];

        uint256 amount;
        for (uint256 i = 0; i < 20; ++i) {
            // We clearly cannot claim for `firstUnclaimableWeek` and so we break
            // here.
            if (nextUserTokenWeekToClaim >= firstUnclaimableWeek) break;

            amount +=
                (tokensPerWeek[nextUserTokenWeekToClaim] *
                    userBalanceAtTimestamp[nextUserTokenWeekToClaim]) /
                _veSupplyCache[nextUserTokenWeekToClaim];

            nextUserTokenWeekToClaim += 1 weeks;
        }

        // Update the stored user-token time cursor to prevent this user claiming
        // this week again.
        _userTokenTimeCursor[user][token] = nextUserTokenWeekToClaim;

        // If the amount to claim is greater than zero we either need to send
        // the amount of reward tokens to the user or deposit them into the
        // ve contract on the user's behalf.
        if (amount > 0) {
            // For a token to be claimable it must have been added to the cached
            // balance so this is safe.
            tokenState.cachedBalance = uint128(
                tokenState.cachedBalance - amount
            );

            if (compound) {
                _compoundRewards(user, token, amount);
            } else {
                token.safeTransfer(user, amount);
            }
        }

        emit TokensClaimed(
            user,
            token,
            amount,
            nextUserTokenWeekToClaim,
            compound
        );

        return amount;
    }

    /**
     * @dev Calculate the amount of `token` to be distributed to `_votingEscrow`
     * holders since the last checkpoint.
     */
    function _checkpointToken(IERC20Upgradeable token, bool force) internal {
        TokenState storage tokenState = _tokenState[token];
        uint256 lastTokenTime = tokenState.timeCursor;
        uint256 timeSinceLastCheckpoint;
        if (lastTokenTime == 0) {
            // Prevent someone from assigning tokens to an inaccessible week.
            require(
                block.timestamp > _startTime,
                "Fee distribution has not started yet"
            );

            // If it's the first time we're checkpointing this token then start
            // distributing from now.
            //
            // Also mark at which timestamp users should start attempts to claim
            //this token from.
            lastTokenTime = block.timestamp;
            tokenState.startTime = uint64(_roundDownTimestamp(block.timestamp));
        } else {
            timeSinceLastCheckpoint = block.timestamp - lastTokenTime;

            if (!force) {
                // Checkpointing N times within a single week is completely
                // equivalent to checkpointing once at the end.
                // We then want to get as close as possible to a single
                // checkpoint every Wed 23:59 UTC to save gas.

                // We then skip checkpointing if we're in the same week as the
                // previous checkpoint.
                bool alreadyCheckpointedThisWeek = _roundDownTimestamp(
                    block.timestamp
                ) == _roundDownTimestamp(lastTokenTime);
                // However we want to ensure that all of this week's fees are
                // assigned to the current week without overspilling into the
                // next week. To mitigate this, we checkpoint if we're near the
                // end of the week.
                bool nearingEndOfWeek = _roundUpTimestamp(block.timestamp) -
                    block.timestamp <
                    1 days;

                // This ensures that we checkpoint once at the beginning of the
                // week and again for each user interaction towards the end of
                // the week to give an accurate final reading of the balance.
                if (alreadyCheckpointedThisWeek && !nearingEndOfWeek) {
                    return;
                }
            }
        }

        tokenState.timeCursor = uint64(block.timestamp);

        uint256 tokenBalance = token.balanceOf(address(this));
        uint256 newTokensToDistribute = tokenBalance.sub(
            tokenState.cachedBalance
        );
        if (newTokensToDistribute == 0) return;
        require(
            tokenBalance <= type(uint128).max,
            "Maximum token balance exceeded"
        );
        tokenState.cachedBalance = uint128(tokenBalance);

        uint256 firstIncompleteWeek = _roundDownTimestamp(lastTokenTime);
        uint256 nextWeek = 0;

        // Distribute `newTokensToDistribute` evenly across the time period from
        // `lastTokenTime` to now.
        // These tokens are assigned to weeks proportionally to how much of this
        // period falls into each week.
        mapping(uint256 => uint256) storage tokensPerWeek = _tokensPerWeek[
            token
        ];

        for (uint256 i = 0; i < 20; ++i) {
            // This is safe as we're incrementing a timestamp.
            nextWeek = firstIncompleteWeek + 1 weeks;
            if (block.timestamp < nextWeek) {
                // `firstIncompleteWeek` is now the beginning of the current
                // week, i.e. this is the final iteration.
                if (
                    timeSinceLastCheckpoint == 0 &&
                    block.timestamp == lastTokenTime
                ) {
                    tokensPerWeek[firstIncompleteWeek] += newTokensToDistribute;
                } else {
                    // block.timestamp >= lastTokenTime by definition.
                    tokensPerWeek[firstIncompleteWeek] +=
                        (newTokensToDistribute *
                            (block.timestamp - lastTokenTime)) /
                        timeSinceLastCheckpoint;
                }
                // As we've caught up to the present then we should now break.
                break;
            } else {
                // We've gone a full week or more without checkpointing so need
                // to distribute tokens to previous weeks.
                if (timeSinceLastCheckpoint == 0 && nextWeek == lastTokenTime) {
                    // It shouldn't be possible to enter this block
                    tokensPerWeek[firstIncompleteWeek] += newTokensToDistribute;
                } else {
                    // nextWeek > lastTokenTime by definition.
                    tokensPerWeek[firstIncompleteWeek] +=
                        (newTokensToDistribute * (nextWeek - lastTokenTime)) /
                        timeSinceLastCheckpoint;
                }
            }

            // We've now "checkpointed" up to the beginning of next week so must
            // update timestamps appropriately.
            lastTokenTime = nextWeek;
            firstIncompleteWeek = nextWeek;
        }

        emit TokenCheckpointed(token, newTokensToDistribute, lastTokenTime);
    }

    /**
     * @dev Cache the `user`'s balance of `_votingEscrow` at the beginning of
     * each new week
     */
    function _checkpointUserBalance(address user) internal {
        uint256 maxUserEpoch = _votingEscrow.user_point_epoch(user);

        // If user has no epochs then they have never locked H1.
        // They clearly will not then receive fees.
        require(maxUserEpoch > 0, "veH1 balance is zero");

        UserState storage userState = _userState[user];

        // `nextWeekToCheckpoint` represents the timestamp of the beginning of
        // the first week which we haven't checkpointed the user's VotingEscrow
        // balance yet.
        uint256 nextWeekToCheckpoint = userState.timeCursor;

        uint256 userEpoch;
        if (nextWeekToCheckpoint == 0) {
            // First checkpoint for user so need to do the initial binary search
            userEpoch = _findTimestampUserEpoch(
                user,
                _startTime,
                0,
                maxUserEpoch
            );
        } else {
            if (nextWeekToCheckpoint >= block.timestamp) {
                // User has checkpointed the current week already so perform
                // early return.
                // This prevents a user from processing epochs created later in
                // this week, however this is not an issue as if a significant
                // number of these builds up then the user will skip past them
                // with a binary search.
                return;
            }

            // Otherwise use the value saved from last time
            userEpoch = userState.lastEpochCheckpointed;

            // This optimizes a scenario common for power users, which have
            // frequent `VotingEscrow` interactions in the same week. We assume
            // that any such user is also claiming fees every week, and so we
            // only perform a binary search here rather than integrating it into
            // the main search algorithm, effectively skipping most of the
            // week's irrelevant checkpoints. The slight tradeoff is that users
            // who have multiple infrequent `VotingEscrow` interactions and also
            // don't claim frequently will also perform the binary search,
            // despite it not leading to gas savings.
            if (maxUserEpoch - userEpoch > 20) {
                userEpoch = _findTimestampUserEpoch(
                    user,
                    nextWeekToCheckpoint,
                    userEpoch,
                    maxUserEpoch
                );
            }
        }

        // Epoch 0 is always empty so bump onto the next one so that we start
        // on a valid epoch.
        if (userEpoch == 0) {
            userEpoch = 1;
        }

        IVotingEscrow.Point memory nextUserPoint = _votingEscrow
            .user_point_history(user, userEpoch);

        // If this is the first checkpoint for the user, calculate the first
        // week they're eligible for. i.e. the timestamp of the first Thursday
        // after they locked. If this is earlier then the first distribution
        // then fast forward to then.
        if (nextWeekToCheckpoint == 0) {
            // Disallow checkpointing before `startTime`.
            require(
                block.timestamp > _startTime,
                "Fee distribution has not started yet"
            );
            nextWeekToCheckpoint = MathUpgradeable.max(
                _startTime,
                _roundUpTimestamp(nextUserPoint.ts)
            );
            userState.startTime = uint64(nextWeekToCheckpoint);
        }

        // It's safe to increment `userEpoch` and `nextWeekToCheckpoint` in this
        // loop as epochs and timestamps are always much smaller than 2^256 and
        // are being incremented by small values.
        IVotingEscrow.Point memory currentUserPoint;
        for (uint256 i = 0; i < 50; ++i) {
            if (
                nextWeekToCheckpoint >= nextUserPoint.ts &&
                userEpoch <= maxUserEpoch
            ) {
                // The week being considered is contained in a user epoch after
                // that described by `currentUserPoint`. We then shift
                // `nextUserPoint` into `currentUserPoint` and query the Point
                // for the next user epoch. We do this in order to step though
                // epochs until we find the first epoch starting after
                // `nextWeekToCheckpoint`, making the previous epoch the one
                // that contains `nextWeekToCheckpoint`.
                userEpoch += 1;
                currentUserPoint = nextUserPoint;
                if (userEpoch > maxUserEpoch) {
                    nextUserPoint = IVotingEscrow.Point(0, 0, 0, 0);
                } else {
                    nextUserPoint = _votingEscrow.user_point_history(
                        user,
                        userEpoch
                    );
                }
            } else {
                // The week being considered lies inside the user epoch
                // described by `oldUserPoint` we can then use it to calculate
                // the user's balance at the beginning of the week.
                if (nextWeekToCheckpoint >= block.timestamp) {
                    // Break if we're trying to cache the user's balance at a
                    // timestamp in the future. We only perform this check here
                    // to ensure that we can still process checkpoints created
                    // in the current week.
                    break;
                }

                int128 dt = _u256ToI128(
                    nextWeekToCheckpoint - currentUserPoint.ts
                );

                uint256 userBalance = currentUserPoint.bias >
                    currentUserPoint.slope * dt
                    ? _i128ToU256(
                        currentUserPoint.bias - currentUserPoint.slope * dt
                    )
                    : 0;

                // User's lock has expired and they haven't relocked yet.
                if (userBalance == 0 && userEpoch > maxUserEpoch) {
                    nextWeekToCheckpoint = _roundUpTimestamp(block.timestamp);
                    break;
                }

                // User had a nonzero lock and so is eligible to collect fees.
                _userBalanceAtTimestamp[user][
                    nextWeekToCheckpoint
                ] = userBalance;

                nextWeekToCheckpoint += 1 weeks;
            }
        }

        // We subtract off 1 from the userEpoch to step back once so that on
        // the next attempt to checkpoint the current `currentUserPoint` will
        // be loaded as `nextUserPoint`. This ensures that we can't skip over
        // the user epoch containing `nextWeekToCheckpoint`.
        // userEpoch > 0 so this is safe.
        userState.lastEpochCheckpointed = uint64(userEpoch - 1);
        userState.timeCursor = uint64(nextWeekToCheckpoint);
    }

    /**
     * @dev Cache the totalSupply of VotingEscrow token at the beginning of
     * each new week
     */
    function _checkpointTotalSupply() internal {
        uint256 nextWeekToCheckpoint = _timeCursor;
        uint256 weekStart = _roundDownTimestamp(block.timestamp);

        // We expect `timeCursor == weekStart + 1 weeks` when fully up to date.
        if (nextWeekToCheckpoint > weekStart || weekStart == block.timestamp) {
            // We've already checkpointed up to this week so perform early return
            return;
        }

        _votingEscrow.checkpoint();

        // Step through each week and cache the total supply at beginning of
        // the week on this contract
        for (uint256 i = 0; i < 20; ++i) {
            if (nextWeekToCheckpoint > weekStart) break;

            // NOTE: Replaced Balancer's logic with Solidly/Velodrome
            // implementation due to the differences in the VotingEscrow
            // totalSupply function.
            // See https://github.com/velodrome-finance/v1/blob/master/contracts/RewardsDistributor.sol#L143

            uint256 epoch = _findTimestampEpoch(nextWeekToCheckpoint);

            IVotingEscrow.Point memory pt = _votingEscrow.point_history(epoch);

            int128 dt = nextWeekToCheckpoint > pt.ts
                ? _u256ToI128(nextWeekToCheckpoint - pt.ts)
                : int128(0);
            int128 supply = pt.bias - pt.slope * dt;

            _veSupplyCache[nextWeekToCheckpoint] = supply > 0
                ? _i128ToU256(supply)
                : 0;

            // This is safe as we're incrementing a timestamp
            nextWeekToCheckpoint += 1 weeks;
        }
        // Update state to the end of the current week (`weekStart` + 1 weeks)
        _timeCursor = nextWeekToCheckpoint;
    }

    // Helper functions

    /**
     * @dev Wrapper around `_userTokenTimeCursor` which returns the start
     * timestamp for `token` if `user` has not attempted to interact with it
     * previously.
     */
    function _getUserTokenTimeCursor(
        address user,
        IERC20Upgradeable token
    ) internal view returns (uint256) {
        uint256 userTimeCursor = _userTokenTimeCursor[user][token];
        if (userTimeCursor > 0) return userTimeCursor;
        // This is the first time that the user has interacted with this token.
        // We then start from the latest out of either when `user` first locked
        // veH1 or `token` was first checkpointed.
        return
            MathUpgradeable.max(
                _userState[user].startTime,
                _tokenState[token].startTime
            );
    }

    /**
     * @dev Return the user epoch number for `user` corresponding to the
     *  provided `timestamp`
     */
    function _findTimestampUserEpoch(
        address user,
        uint256 timestamp,
        uint256 minUserEpoch,
        uint256 maxUserEpoch
    ) internal view returns (uint256) {
        uint256 min = minUserEpoch;
        uint256 max = maxUserEpoch;

        // Perform binary search through epochs to find epoch containing
        // `timestamp`
        for (uint256 i = 0; i < 128; ++i) {
            if (min >= max) break;

            // Algorithm assumes that inputs are less than 2^128 so this
            // operation is safe.
            // +2 avoids getting stuck in min == mid < max
            uint256 mid = (min + max + 2) / 2;
            IVotingEscrow.Point memory pt = _votingEscrow.user_point_history(
                user,
                mid
            );
            if (pt.ts <= timestamp) {
                min = mid;
            } else {
                // max > min so this is safe.
                max = mid - 1;
            }
        }
        return min;
    }

    /**
     * @dev Return the global epoch number corresponding to the provided
     * `timestamp`
     */
    function _findTimestampEpoch(
        uint256 timestamp
    ) internal view returns (uint256) {
        uint256 min = 0;
        uint256 max = _votingEscrow.epoch();

        // Perform binary search through epochs to find epoch containing
        // `timestamp`
        for (uint256 i = 0; i < 128; i++) {
            if (min >= max) break;

            // Algorithm assumes that inputs are less than 2^128 so this
            // operation is safe.
            // +2 avoids getting stuck in min == mid < max
            uint256 mid = (min + max + 2) / 2;
            IVotingEscrow.Point memory pt = _votingEscrow.point_history(mid);
            if (pt.ts <= timestamp) {
                min = mid;
            } else {
                max = mid - 1;
            }
        }
        return min;
    }

    /**
     * @dev Rounds the provided timestamp down to the beginning of the previous
     * week (Thurs 00:00 UTC)
     */
    function _roundDownTimestamp(
        uint256 timestamp
    ) private pure returns (uint256) {
        // Division by zero or overflows are impossible here.
        return (timestamp / 1 weeks) * 1 weeks;
    }

    /**
     * @dev Rounds the provided timestamp up to the beginning of the next week
     * (Thurs 00:00 UTC)
     */
    function _roundUpTimestamp(
        uint256 timestamp
    ) private pure returns (uint256) {
        // Overflows are impossible here for all realistic inputs.
        return _roundDownTimestamp(timestamp + WEEK_MINUS_SECOND);
    }

    /**
     * @dev Reverts if the provided token cannot be claimed.
     */
    function _checkIfClaimingEnabled(IERC20Upgradeable token) private view {
        require(_tokenClaimingEnabled[token], "Token is not allowed");
    }

    // ------------------------------------------------------------------------
    // New Functions

    /**
     * @notice Disallows native H1 to be sent to the contract.
     *
     * @dev As the Native Application Fee is set to refund excess H1, we do
     * not want to be in the position where H1 is sent directly into this
     * contract and mistakingly refund it.
     */
    receive() external payable {
        revert("Cannot receive native H1");
    }

    /**
     * @notice Disallows native H1 to be sent to the contract.
     *
     * @dev As the Native Application Fee is set to refund excess H1, we do
     * not want to be in the position where H1 is sent directly into this
     * contract and mistakingly refund it.
     */
    fallback() external payable {
        revert("Cannot receive native H1");
    }

    /**
     * @notice Like `claimToken` but rather than sending the reward token to the
     * user, it will compound the reward token in the `VotingEscrow` contract.
     * Does not incur a Native Application Fee.
     *
     * @param user - The user on behalf of which to claim.
     * @param token - The ERC20 token address to be claimed.
     *
     * @return The amount of `token` compounded into the `user`'s ve balance.
     *
     * @dev Note that for this call to be successful, the following statements
     * must be true:
     * -    the token being claimed is a valid deposit token on the
     *      `VotingEscrow` contract;
     * -    the user must have approved this `FeeDistributor` contract to
     *      deposit on their behalf; and
     * -    the user must have have an active lock.
     *
     * If any of these are not true, the transaction will revert.
     */
    function claimTokenAndCompound(
        address user,
        IERC20Upgradeable token
    )
        external
        nonReentrant
        userAllowedToClaim(user)
        tokenCanBeClaimed(token)
        returns (uint256)
    {
        _checkpointTotalSupply();
        _checkpointUserBalance(user);
        _checkpointToken(token, false);

        return _claimToken(user, token, true);
    }

    /**
     * @notice Like `claimTokens` but rather than sending the reward tokens to
     * the user, it will compound the reward token in the `VotingEscrow`
     * contract. Does not incur a Native Application Fee.
     *
     * @param user - The user on behalf of which to claim.
     * @param tokens - An array of ERC20 token addresses to be claimed.
     *
     * @return An array of the amounts of each token in `tokens` sent to `user`
     * as a result of claiming.
     *
     * @dev Note that for this call to be successful, the following statements
     * must be true:
     * -    the token being claimed is a valid deposit token on the
     *      `VotingEscrow` contract;
     * -    the user must have approved this `FeeDistributor` contract to
     *      deposit on their behalf; and
     * -    the user must have have an active lock.
     *
     * If any of these are not true, the transaction will revert.
     */
    function claimTokensAndCompound(
        address user,
        IERC20Upgradeable[] calldata tokens
    )
        external
        nonReentrant
        userAllowedToClaim(user)
        tokensCanBeClaimed(tokens)
        returns (uint256[] memory)
    {
        _checkpointTotalSupply();
        _checkpointUserBalance(user);

        uint256 tokensLength = tokens.length;
        uint256[] memory amounts = new uint256[](tokensLength);
        for (uint256 i = 0; i < tokensLength; ++i) {
            _checkpointToken(tokens[i], false);
            amounts[i] = _claimToken(user, tokens[i], true);
        }

        return amounts;
    }

    /**
     * @notice Returns the estimated pending rewards for a given user and
     * token combination. Note that this value is _purely_ an estimate and
     * _does not_ represent the amount of tokens that a user will receive if
     * they claim.
     *
     * @param user The address of the user to check.
     * @param tkn The address of the token to check.
     *
     * @return The estimated amount of `tkn` tokens claimable for the `user`.
     *
     * @dev Note that for this estimate to work, _at minimum_ the token
     * checkpoints must have occurred.
     */
    function estimatedPendingRewards(
        address user,
        IERC20Upgradeable tkn
    ) external view returns (uint256) {
        uint256 currentWeek = _roundDownTimestamp(block.timestamp);
        uint256 latestClaimableWeek = currentWeek - 1 weeks;
        uint256 nextClaimableWeek = _getUserTokenTimeCursor(user, tkn);

        // If the latest claimable week is before the earliest claimable week
        // then there is nothing to claim.
        if (latestClaimableWeek < nextClaimableWeek) {
            return 0;
        }

        uint256 pending = 0;

        // To keep logic commensurate with _claimToken, look back is 20 weeks.
        // For this use case, we cannot assume that the correct total supply or
        // user checkpoints have occurred. At minimum, the token checkpoints
        // must have occurred. It is for this reason that the result of this
        // function is purely an estimate.
        for (uint256 i; i < 20; i++) {
            // If the next week to claim is greater than the latest week that is
            // claimable then we are done.
            if (nextClaimableWeek > latestClaimableWeek) {
                break;
            }

            uint256 tokens = _tokensPerWeek[tkn][nextClaimableWeek];
            uint256 bal = _votingEscrow.balanceOfAtT(user, nextClaimableWeek);
            uint256 supply = _calcTotalSupply(nextClaimableWeek);

            // Advance to next week here to avoid duplicate logic
            nextClaimableWeek = nextClaimableWeek + 1 weeks;

            if (tokens == 0 || bal == 0 || supply == 0) {
                continue;
            }

            // supply is known now to be greater than zero
            pending += (tokens * bal) / supply;
        }

        return pending;
    }

    /**
     * @notice Returns whether a given token has been used as a reward token
     * in this contract.
     *
     * @param tkn The token to check.
     *
     * @return True if the token has been used as a reward token, false
     * otherwise.
     */
    function isHistoricalRewardToken(address tkn) external view returns (bool) {
        return _isHistoricalRewardToken[tkn];
    }

    /**
     * @notice Returns the list of historical reward tokens.
     * @return List of historical reward tokens.
     *
     * @dev List of all tokens used as rewards for this contract. Tokens can be
     * pulled from here and then passed into `nPeriodRewards` to help with
     * generating UI metrics.
     */
    function historicalRewardTokens() external view returns (address[] memory) {
        return _historicalRewardTokens;
    }

    /**
     * @notice Returns the total amount of a given reward token distributed
     * over a period. Note that the max look back period is 52 weeks.
     *
     * @param tkn The address of the token to check.
     * @param lookbackWeeks The amount of weeks to look back for. Max 52.
     *
     * @return The amount of `tkn` distributed over the period.
     */
    function nPeriodRewards(
        IERC20Upgradeable tkn,
        uint256 lookbackWeeks
    ) external view returns (uint256) {
        // no need to continue if the token was never used as a reward token.
        if (!_isHistoricalRewardToken[address(tkn)]) {
            return 0;
        }

        uint256 maxLookback = 52;
        uint256 lookback = lookbackWeeks;
        if (lookbackWeeks > maxLookback) {
            lookback = maxLookback;
        }

        uint256 currentWeek = _roundDownTimestamp(block.timestamp);
        uint256 endWeek = currentWeek - 1 weeks; // exclude the current week.
        uint256 startWeek = endWeek - lookback * 1 weeks;

        uint256 out = 0;
        for (uint256 i; i < lookback; i++) {
            out += _tokensPerWeek[tkn][startWeek];
            startWeek += 1 weeks;
        }

        return out;
    }

    /**
     * @notice Compounds a given amount of reward tokens into a user's active
     * position.
     *
     * @param user The address of the user.
     * @param token The token to be compounded.
     * @param amount The amount of reward tokens to be compounded.
     *
     * @dev Note that for this call to be successful, the following statements
     * must be true:
     * -    the token being claimed is a valid deposit token on the
     *      `VotingEscrow` contract;
     * -    the user must have approved this `FeeDistributor` contract to
     *      deposit on their behalf; and
     * -    the user must have have an active lock.
     *
     * If any of these are not true, the transaction will revert.
     * Asserts that the start and finish allowance is correct.
     */
    function _compoundRewards(
        address user,
        IERC20Upgradeable token,
        uint256 amount
    ) internal {
        token.approve(address(_votingEscrow), amount);

        _votingEscrow.deposit_for_admin(
            user,
            amount,
            address(token),
            address(this)
        );

        uint256 allowance = token.allowance(
            address(this),
            address(_votingEscrow)
        );

        assert(allowance == 0);
    }

    /**
     * @notice Adds a given token to the historical reward tokens list.
     * @param token The token to add.
     */
    function _addHistoricalRewardToken(address token) internal {
        bool found = _isHistoricalRewardToken[token];

        if (!found) {
            _isHistoricalRewardToken[token] = true;
            _historicalRewardTokens.push(address(token));
        }
    }

    /**
     * @notice `_authorizeUpgrade` this function is overridden to protect the
     * contract by only allowing the admin to upgrade it.
     * @param newImplementation new implementation address.
     */
    function _authorizeUpgrade(
        address newImplementation
    ) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

    /**
     * @notice Unsafe conversion of a uint256 to a int128.
     *
     * @param x The uint256 value to be converted.
     * @return The converted int128 value.
     *
     * @dev This function takes a uint256 and converts it to a int128, with
     * no overflow checks / guardrails. It is this way to mimic the Solidity
     * 0.7.x explicit type conversion of int128(uint256) as is used in the
     * original Fee Distributor contract.
     */
    function _u256ToI128(uint256 x) private pure returns (int128) {
        return int128(uint128(x));
    }

    /**
     * @notice Unsafe conversion of a int128 to a uint256.
     *
     * @param x The int128 value to be converted.
     * @return The converted u256 value.
     *
     * @dev This function takes a int128 and converts it to a uint256, with
     * no overflow checks / guardrails. It is this way to mimic the Solidity
     * 0.7.x explicit type conversion of uint256(int128) as is used in the
     * original Fee Distributor contract.
     */
    function _i128ToU256(int128 x) private pure returns (uint256) {
        return uint256(uint128(x));
    }

    /**
     * @notice Returns the estimated total supply of ve tokens at a given week
     * start.
     * @param weekStart The timestamp of the start of the week to check.
     */
    function _calcTotalSupply(
        uint256 weekStart
    ) internal view returns (uint256) {
        uint256 epoch = _findTimestampEpoch(weekStart);
        IVotingEscrow.Point memory pt = _votingEscrow.point_history(epoch);

        int128 dt = 0;
        if (weekStart > pt.ts) {
            dt = _u256ToI128(weekStart - pt.ts);
        }

        int128 supply = pt.bias - pt.slope * dt;
        if (supply < 0) {
            supply = 0;
        }

        return _i128ToU256(supply);
    }
}
        

@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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 {Initializable} from "../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:
 *
 * ```solidity
 * 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}:
 *
 * ```solidity
 * 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. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControlUpgradeable is
    Initializable,
    ContextUpgradeable,
    IAccessControlUpgradeable,
    ERC165Upgradeable
{
    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);
        _;
    }

    function __AccessControl_init() internal onlyInitializing {}

    function __AccessControl_init_unchained() internal onlyInitializing {}

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

@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

@openzeppelin/contracts-upgradeable/interfaces/IERC1967Upgradeable.sol

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

pragma solidity ^0.8.0;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 *
 * _Available since v4.8.3._
 */
interface IERC1967Upgradeable {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}
          

@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)

pragma solidity ^0.8.0;

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

@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822ProxiableUpgradeable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}
          

@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import {Initializable} from "../utils/Initializable.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    function __ERC1967Upgrade_init() internal onlyInitializing {
    }

    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
        // Upgrades from old implementations will perform a rollback test. This test requires the new
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
        // this special case will break upgrade paths from old UUPS implementation to new ones.
        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
            _setImplementation(newImplementation);
        } else {
            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
            } catch {
                revert("ERC1967Upgrade: new implementation is not UUPS");
            }
            _upgradeToAndCall(newImplementation, data, forceCall);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), 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;
}
          

@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeaconUpgradeable {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}
          

@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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]
 * ```solidity
 * 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 Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}
          

@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol

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

pragma solidity ^0.8.0;

import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
        return _IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeTo(address newImplementation) public virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) 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[50] private __gap;
}
          

@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol

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

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

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

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

    uint256 private _status;

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

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

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

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

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

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

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

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

@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface 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);
}
          

@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
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].
     *
     * CAUTION: See Security Considerations above.
     */
    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);
}
          

@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol

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

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/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;

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

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(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));
    }

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

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

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

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

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        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");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

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

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

@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol

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

pragma solidity ^0.8.0;
import {Initializable} from "../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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 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[50] private __gap;
}
          

@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlotUpgradeable {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}
          

@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol

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

pragma solidity ^0.8.0;

import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.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 `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, 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);
    }

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

@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol

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

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import {Initializable} from "../../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;
}
          

@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol

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

pragma solidity ^0.8.0;

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

@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol

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

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library 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) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts-upgradeable/utils/math/SignedMathUpgradeable.sol

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

pragma solidity ^0.8.0;

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

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

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

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

contracts/fee/interfaces/IFeeContract.sol

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

/**
 * @title IFeeContract
 * @dev The interface for the FeeContract
 */
interface IFeeContract {
    /**
     * @notice Returns the timestamp for when the oracle can next update.
     * @return Timestamp for when the oracle can next update.
     */
    function nextResetTime() external view returns (uint256);

    /**
     * @notice Returns the fee amount an address should receive.
     * @param index The index in the array of channels/weights.
     * @return The intended fee.
     */
    function amountPaidToUponNextDistribution(
        uint8 index
    ) external view returns (uint256);

    /**
     * @notice Returns the `_fee`.
     * @return The current fee.
     */
    function getFee() external view returns (uint256);

    /**
     * @notice Updates the fee in the fee contract to match the oracle value.
     */
    function updateFee() external;

    /**
     * @notice Returns all channels.
     * @return The channels.
     */
    function getChannels() external view returns (address[] memory);

    /**
     * @notice Return all the weights.
     * @return The weights.
     */
    function getWeights() external view returns (uint256[] memory);

    /**
     * @notice Returns the fee oracle address.
     * @return The fee oracle address.
     */
    function getOracleAddress() external view returns (address);

    /**
     * @notice Returns a channel's address and its weight.
     * @param index The index in the array of channels/weights.
     * @return The channel's address and its weight.
     */
    function getChannelWeightByIndex(
        uint8 index
    ) external view returns (address, uint256);

    /**
     * @notice Returns the contract shares.
     * @return The contract shares.
     */
    function getTotalContractShares() external view returns (uint256);

    /**
     * @notice Returns the block timestamp that the most recent fee distribution occurred.
     * @return The timestamp of the most recent fee distribution.
     */
    function getLastDistribution() external view returns (uint256);

    /**
     * @notice Returns the min fee, in USD, that a developer may charge.
     * @return The min fee, in USD, that a developer may charge.
     */
    function getMinDevFee() external view returns (uint256);

    /**
     * @notice Returns the max fee, in USD, that a developer may charge.
     * @return The max fee, in USD, that a developer may charge.
     */
    function getMaxDevFee() external view returns (uint256);

    /**
     * @notice Returns the current fee, denominated in USD.
     * @return The fee, denominated in USD.
     */
    function queryOracle() external view returns (uint256);

    /**
     * @notice Distributes fees to channels.
     */
    function distributeFees() external;

    /**
     * @notice Forces a fee distribution.
     */
    function forceDistributeFees() external;

    /**
     * @notice Sets the minimum fee for developer applications. __Must__ be to a
     * precision of 18 decimals.
     *
     * @param fee The minimum fee, in USD, that a developer may charge.
     */
    function setMinFee(uint256 fee) external;

    /**
     * @notice Sets the maximum fee for developer applications. __Must__ be to a
     * precision of 18 decimals.
     *
     * @param fee The highest fee, in USD, that a developer may charge.
     */
    function setMaxFee(uint256 fee) external;

    /**
     * @notice Updates the `_feeUSD` value.
     * @param feeUSD_ The new fee, in USD. __Must__ be to a precision of 18
     * decimals.
     * @dev Example:
     * -    1.75 USD: `1750000000000000000`
     * -    1.00 USD: `1000000000000000000`
     * -    0.50 USD: `500000000000000000`
     */
    function setFeeUSD(uint256 feeUSD_) external;

    /**
     * @notice Updates the `_asscShare` value.
     * @param asscShare_ The new share of the developer fee that the Association
     * will receive. __Must__ be to a precision of 18 decimals.
     * @dev Example:
     * -    10%: `100000000000000000`
     * -    15%: `150000000000000000`
     */
    function setAsscShare(uint256 asscShare_) external;

    /**
     * @notice Returns the current fee value in USD to a precision of 18
     * decimals.
     * @return The current fee value in USD to a precision of 18 decimals.
     */
    function getFeeUSD() external view returns (uint256);

    /**
     * @notice Returns the `_h1USD` value. To be used in H1 Developed
     * Applications.
     * @return The current `_h1USD` value.
     */
    function getDevH1USD() external view returns (uint256);

    /**
     * @notice Returns the current share the Association receives of the
     * developer fee to a precision of 18 decimals.
     * @return The current share the Association receives of the developer fee
     * to a precision of 18 decimals.
     */
    function getAsscShare() external view returns (uint256);

    /**
     * @notice Sets the oracle address.
     * @param newOracle The new oracle address.
     */
    function setOracle(address newOracle) external;

    /**
     * @notice Adds a new channel with a given weight.
     * @param _newChannelAddress The new channel to add.
     * @param _weight The weight for the new channel.
     */
    function addChannel(address _newChannelAddress, uint256 _weight) external;

    /**
     * @notice Adjusts a channel and its weight.
     * @param _oldChannelAddress The address of the channel to update.
     * @param _newChannelAddress The address of the channel that replaces the old one.
     * @param _newWeight The amount of total shares the new address will receive.
     */
    function adjustChannel(
        address _oldChannelAddress,
        address _newChannelAddress,
        uint256 _newWeight
    ) external;

    /**
     * @notice Removes a channel and it's weight.
     * @param _channel The address being removed.
     */
    function removeChannel(address _channel) external;

    /**
     * @notice set contracts that accesses grace fee.
     */
    function setGraceContract(bool enterGrace) external;

    /**
     * @notice enables admins to update the grace period.
     * @param gracePeriod the new grace period in seconds.
     */
    function setGracePeriod(uint256 gracePeriod) external;
}
          

contracts/governance/interfaces/IFeeDistributor.sol

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.4;

import "@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol";
import "./IVotingEscrow.sol";

/**
 * @title Fee Distributor
 * @author Balancer Labs. Original version:
 * https://github.com/balancer/balancer-v2-monorepo/blob/master/pkg
 * /liquidity-mining/contracts/fee-distribution/FeeDistributor.sol
 *
 * @notice Distributes any tokens transferred to the contract (e.g. Protocol fees)
 * among veH1 holders proportionally based on a snapshot of the week at which the
 * tokens are sent to the FeeDistributor contract.
 *
 * @dev Supports distributing arbitrarily many different tokens. In order to
 * start distributing a new token to veH1 holders call `depositToken`.
 */
interface IFeeDistributor {
    event TokenCheckpointed(
        IERC20Upgradeable indexed token,
        uint256 amount,
        uint256 lastCheckpointTimestamp
    );

    event TokensClaimed(
        address indexed user,
        IERC20Upgradeable indexed token,
        uint256 amount,
        uint256 userTokenTimeCursor,
        bool indexed compounded
    );

    event TokenWithdrawn(
        IERC20Upgradeable indexed token,
        uint256 amount,
        address indexed recipient
    );

    event TokenClaimingEnabled(IERC20Upgradeable indexed token, bool enabled);
    event OnlyVeHolderClaimingEnabled(address indexed user, bool enabled);

    /**
     * @notice Returns the VotingEscrow (veH1) token contract
     */
    function getVotingEscrow() external view returns (IVotingEscrow);

    /**
     * @notice Returns the time when fee distribution starts.
     */
    function getStartTime() external view returns (uint256);

    /**
     * @notice Returns the global time cursor representing the most earliest
     * uncheckpointed week.
     */
    function getTimeCursor() external view returns (uint256);

    /**
     * @notice Returns the user-level start time representing the first week
     * they're eligible to claim tokens.
     * @param user - The address of the user to query.
     */
    function getUserStartTime(address user) external view returns (uint256);

    /**
     * @notice Returns the user-level time cursor representing the most earliest
     * uncheckpointed week.
     * @param user - The address of the user to query.
     */
    function getUserTimeCursor(address user) external view returns (uint256);

    /**
     * @notice Returns the user-level last checkpointed epoch.
     * @param user - The address of the user to query.
     */
    function getUserLastEpochCheckpointed(
        address user
    ) external view returns (uint256);

    /**
     * @notice True if the given token can be claimed, false otherwise.
     * @param token - The ERC20 token address to query.
     */
    function canTokenBeClaimed(
        IERC20Upgradeable token
    ) external view returns (bool);

    /**
     * @notice Returns the token-level start time representing the timestamp
     * users could start claiming this token
     * @param token - The ERC20 token address to query.
     */
    function getTokenStartTime(
        IERC20Upgradeable token
    ) external view returns (uint256);

    /**
     * @notice Returns the token-level time cursor storing the timestamp at up
     * to which tokens have been distributed.
     * @param token - The ERC20 token address to query.
     */
    function getTokenTimeCursor(
        IERC20Upgradeable token
    ) external view returns (uint256);

    /**
     * @notice Returns the token-level cached balance.
     * @param token - The ERC20 token address to query.
     */
    function getTokenCachedBalance(
        IERC20Upgradeable token
    ) external view returns (uint256);

    /**
     * @notice Returns the user-level time cursor storing the timestamp of the
     * latest token distribution claimed.
     * @param user - The address of the user to query.
     * @param token - The ERC20 token address to query.
     */
    function getUserTokenTimeCursor(
        address user,
        IERC20Upgradeable token
    ) external view returns (uint256);

    /**
     * @notice Returns the user's cached balance of veH1 as of the provided
     * timestamp.
     *
     * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return
     * correct values. This function requires `user` to have been checkpointed
     * past `timestamp` so that their balance is cached.
     *
     * @param user - The address of the user of which to read the cached balance
     * of.
     *
     * @param timestamp - The timestamp at which to read the `user`'s cached
     * balance at.
     */
    function getUserBalanceAtTimestamp(
        address user,
        uint256 timestamp
    ) external view returns (uint256);

    /**
     * @notice Returns the cached total supply of veH1 as of the provided
     * timestamp.
     *
     * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return
     * correct values. This function requires the contract to have been
     * checkpointed past `timestamp` so that the supply is cached.
     *
     * @param timestamp - The timestamp at which to read the cached total supply
     * at.
     */
    function getTotalSupplyAtTimestamp(
        uint256 timestamp
    ) external view returns (uint256);

    /**
     * @notice Returns the amount of `token` which the FeeDistributor received
     * in the week beginning at `timestamp`.
     *
     * @param token - The ERC20 token address to query.
     *
     * @param timestamp - The timestamp corresponding to the beginning of the
     * week of interest.
     */
    function getTokensDistributedInWeek(
        IERC20Upgradeable token,
        uint256 timestamp
    ) external view returns (uint256);

    // Preventing third-party claiming

    /**
     * @notice Enables / disables rewards claiming only by the VotingEscrow
     * holder for the message sender.
     *
     * @param enabled - True if only the VotingEscrow holder can claim their
     * rewards, false otherwise.
     */
    function enableOnlyVeHolderClaiming(bool enabled) external;

    /**
     * @notice Returns true if only the VotingEscrow holder can claim their
     * rewards, false otherwise.
     */
    function onlyVeHolderClaimingEnabled(
        address user
    ) external view returns (bool);

    // Depositing

    /**
     * @notice Deposits tokens to be distributed in the current week.
     * @dev Sending tokens directly to the FeeDistributor instead of using
     * `depositToken` may result in tokens being retroactively distributed to
     * past weeks, or for the distribution to carry over to future weeks.
     *
     * If for some reason `depositToken` cannot be called, in order to ensure
     * that all tokens are correctly distributed manually call `checkpointToken`
     *  before and after the token transfer.
     *
     * @param token - The ERC20 token address to distribute.
     * @param amount - The amount of tokens to deposit.
     */
    function depositToken(IERC20Upgradeable token, uint256 amount) external;

    /**
     * @notice Deposits tokens to be distributed in the current week.
     *
     * @dev A version of `depositToken` which supports depositing multiple
     * `tokens` at once. See `depositToken` for more details.
     *
     * @param tokens - An array of ERC20 token addresses to distribute.
     * @param amounts - An array of token amounts to deposit.
     */
    function depositTokens(
        IERC20Upgradeable[] calldata tokens,
        uint256[] calldata amounts
    ) external;

    // Checkpointing

    /**
     * @notice Caches the total supply of veH1 at the beginning of each week.
     * This function will be called automatically before claiming tokens to
     * ensure the contract is properly updated.
     */
    function checkpoint() external;

    /**
     * @notice Caches the user's balance of veH1 at the beginning of each week.
     * This function will be called automatically before claiming tokens to
     * ensure the contract is properly updated.
     * @param user - The address of the user to be checkpointed.
     */
    function checkpointUser(address user) external;

    /**
     * @notice Assigns any newly-received tokens held by the FeeDistributor to
     * weekly distributions.
     *
     * @dev Any `token` balance held by the FeeDistributor above that which is
     * returned by `getTokenLastBalance` will be distributed evenly across the
     * time period since `token` was last checkpointed.
     *
     * This function will be called automatically before claiming tokens to
     * ensure the contract is properly updated.
     *
     * @param token - The ERC20 token address to be checkpointed.
     */
    function checkpointToken(IERC20Upgradeable token) external;

    /**
     * @notice Assigns any newly-received tokens held by the FeeDistributor to
     * weekly distributions.
     *
     * @dev A version of `checkpointToken` which supports checkpointing multiple
     * tokens.
     *
     * See `checkpointToken` for more details.
     *
     * @param tokens - An array of ERC20 token addresses to be checkpointed.
     */
    function checkpointTokens(IERC20Upgradeable[] calldata tokens) external;

    // Claiming

    /**
     * @notice Claims all pending distributions of the provided token for a user.
     *
     * @dev It's not necessary to explicitly checkpoint before calling this
     * function, it will ensure the FeeDistributor is up to date before
     * calculating the amount of tokens to be claimed.
     *
     * @param user - The user on behalf of which to claim.
     * @param token - The ERC20 token address to be claimed.
     * @return The amount of `token` sent to `user` as a result of claiming.
     */
    function claimToken(
        address user,
        IERC20Upgradeable token
    ) external payable returns (uint256);

    /**
     * @notice Claims a number of tokens on behalf of a user.
     * @dev A version of `claimToken` which supports claiming multiple `tokens`
     * on behalf of `user`.
     *
     * See `claimToken` for more details.
     *
     * @param user - The user on behalf of which to claim.
     * @param tokens - An array of ERC20 token addresses to be claimed.
     *
     * @return An array of the amounts of each token in `tokens` sent to `user`
     * as a result of claiming.
     */
    function claimTokens(
        address user,
        IERC20Upgradeable[] calldata tokens
    ) external payable returns (uint256[] memory);

    // Governance

    /**
     * @notice Withdraws the specified `amount` of the `token` from the contract
     * to the `recipient`. Can be called only by the Haven1 Association.
     *
     * @param token - The token to withdraw.
     * @param amount - The amount to withdraw.
     * @param recipient - The address to transfer the tokens to.
     */
    function withdrawToken(
        IERC20Upgradeable token,
        uint256 amount,
        address recipient
    ) external;

    /**
     * @notice Enables or disables claiming of the given token. Can be called
     * only by the Haven1 Association.
     *
     * @param token - The token to enable or disable claiming.
     * @param enable - True if the token can be claimed, false otherwise.
     */
    function enableTokenClaiming(IERC20Upgradeable token, bool enable) external;
}
          

contracts/governance/interfaces/IVotingEscrow.sol

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

interface IVotingEscrow {
    struct Point {
        int128 bias;
        int128 slope; // # -dweight / dt
        uint256 ts;
        uint256 blk; // block
    }

    function point_history(
        uint256 timestamp
    ) external view returns (Point memory);

    function user_point_history(
        address user,
        uint256 timestamp
    ) external view returns (Point memory);

    function epoch() external view returns (uint256);

    function user_point_epoch(address user) external view returns (uint256);

    /// @notice Add address to whitelist smart contract depositors `addr`
    /// @param addr Address to be whitelisted
    function add_to_whitelist(address addr) external;

    /// @notice Remove a smart contract address from whitelist
    /// @param addr Address to be removed from whitelist
    function remove_from_whitelist(address addr) external;

    /// @notice Unlock all locked balances
    function unlock() external;

    /// @notice Get the most recently recorded rate of voting power decrease for `_addr`
    /// @param addr Address of the user wallet
    /// @return Value of the slope
    function get_last_user_slope(address addr) external view returns (int128);

    /// @notice Get the timestamp for checkpoint `_idx` for `_addr`
    /// @param _addr User wallet address
    /// @param _idx User epoch number
    /// @return Epoch time of the checkpoint
    function user_point_history__ts(
        address _addr,
        uint256 _idx
    ) external view returns (uint);

    /// @notice Get timestamp when `_addr`'s lock finishes
    /// @param _addr User wallet address
    /// @return Epoch time of the lock end
    function locked__end(address _addr) external view returns (uint);

    /// @notice Record global data to checkpoint
    function checkpoint() external;

    /// @notice Deposit `_value` tokens for `_addr` and add to the lock
    /// @dev Anyone (even a smart contract) can deposit for someone else, but
    ///      cannot extend their locktime and deposit for a brand new user
    /// @param _addr User's wallet address
    /// @param _value Amount to add to user's lock
    /// @param _deposit_token The token to be deposited.
    function deposit_for(
        address _addr,
        uint256 _value,
        address _deposit_token
    ) external payable;

    /// @notice Deposit `_value` tokens for `_addr` and add to the lock
    /// @dev Anyone (even a smart contract) can deposit for someone else, but
    ///      cannot extend their locktime and deposit for a brand new user
    /// @dev Like `deposit_for` expect it does not require the fee.
    /// @param _addr User's wallet address
    /// @param _value Amount to add to user's lock
    /// @param _deposit_token The token to be deposited.
    /// @param _transfer_from The address from which the token will be transferred.
    function deposit_for_admin(
        address _addr,
        uint256 _value,
        address _deposit_token,
        address _transfer_from
    ) external payable;

    /// @notice External function for _create_lock
    /// @param _value Amount to deposit
    /// @param _unlock_time Epoch time when tokens unlock, rounded down to whole weeks
    /// @param _deposit_token The token to be deposited.
    function create_lock(
        uint256 _value,
        uint256 _unlock_time,
        address _deposit_token
    ) external payable;

    /// @notice Deposit `_value` additional tokens for `msg.sender` without modifying the unlock time
    /// @param _value Amount of tokens to deposit and add to the lock
    /// @param _deposit_token The token to be deposited.
    function increase_amount(
        uint256 _value,
        address _deposit_token
    ) external payable;

    /// @notice Extend the unlock time for `msg.sender` to `_unlock_time`
    /// @param _unlock_time New epoch time for unlocking
    function increase_unlock_time(uint256 _unlock_time) external payable;

    /// @notice Extend the unlock time and/or for `msg.sender` to `_unlock_time`
    /// @param _unlock_time New epoch time for unlocking
    /// @param _deposit_token The token to be deposited.
    function increase_amount_and_time(
        uint256 _value,
        uint256 _unlock_time,
        address _deposit_token
    ) external payable;

    /// @notice Withdraw all tokens for `msg.sender`.
    function withdraw() external payable;

    /// @notice Deposit `_value` tokens for `msg.sender` and lock until `_unlock_time`
    /// @param _value Amount to deposit
    /// @param _unlock_time Epoch time when tokens unlock, rounded down to whole weeks
    /// @param _deposit_token The token to be deposited.
    function withdraw_and_create_lock(
        uint256 _value,
        uint256 _unlock_time,
        address _deposit_token
    ) external payable;

    /// @notice Returns the voting power of an address at time `_t`.
    /// @param addr The address to check.
    /// @param _t The ts to check.
    /// @return The voting power of `addr` at time `_t`.
    function balanceOfAtT(
        address addr,
        uint256 _t
    ) external view returns (uint);

    /// @notice Returns the voting power of `addr`.
    /// @param addr The address to check.
    /// @return The voting power of `addr`.
    function balanceOf(address addr) external view returns (uint);

    /// @notice Measure voting power of `addr` at block height `_block`
    /// @dev Adheres to MiniMe `balanceOfAt` interface: https://github.com/Giveth/minime
    /// @param addr User's wallet address
    /// @param _block Block to calculate the voting power at
    /// @return Voting power
    function balanceOfAt(
        address addr,
        uint256 _block
    ) external view returns (uint);

    /// @notice Calculates the total voting power at time `t` in the past.
    /// @param t The ts in the past to check.
    /// @return Total voting power at some time `t` in the past.
    function totalSupplyAtT(uint256 t) external view returns (uint);

    /// @notice Calculates the current total voting power.
    /// @return The current total voting power.
    function totalSupply() external view returns (uint);

    /// @notice Calculate total voting power at some point in the past
    /// @param _block Block to calculate the total voting power at
    /// @return Total voting power at `_block`
    function totalSupplyAt(uint256 _block) external view returns (uint);

    /// @notice Adds `addr` as an approved deposit token.
    /// @param addr The token address to add.
    function add_deposit_token(address addr) external;

    /// @notice Removes `addr` as an approved deposit token.
    /// @param addr The token address to add.
    function remove_deposit_token(address addr) external;

    /// @notice Returns the list of currently active deposit token addresses.
    /// @return The list of currently active deposit token addresses.
    function active_deposit_tokens() external view returns (address[] memory);

    /// @notice Whitelist of tokens that can be deposited.
    /// @param tkn The token address to check.
    /// @return True if the token is a valid deposit token, false otherwise.
    function deposit_tokens(address tkn) external view returns (bool);

    /// @notice A historical list of all deposit token addresses.
    /// @return The historical list of all deposit token addresses.
    function historical_deposit_tokens()
        external
        view
        returns (address[] memory);
}
          

contracts/h1-native-application/H1NativeApplicationUpgradeable.sol

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

import "./H1NativeBase.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

contract H1NativeApplicationUpgradable is
    H1NativeBase,
    AccessControlUpgradeable
{
    function _initializeBase(
        address feeContract,
        address association
    ) internal {
        _grantRole(DEFAULT_ADMIN_ROLE, association);
        _h1NativeBase_init(feeContract);
    }

    function _authorizeFeeContractAddressUpdate()
        internal
        override
        onlyRole(DEFAULT_ADMIN_ROLE)
    {}
}
          

contracts/h1-native-application/H1NativeBase.sol

// SPDX-License-Identifier: ISC

pragma solidity ^0.8.0;

import "../fee/interfaces/IFeeContract.sol";

/**
 * @title H1NativeBase
 * @author Haven1 Development Team
 *
 * @notice This contract's purpose is to provide modifiers to functions that
 * ensure fees are sent to the FeeContract. This is the base contract that holds
 * all the logic while the application contracts are the ones used for
 * implementation.
 *
 * @dev The primary function of this contract is to be used as an import for
 * application building on Haven1.
 */
abstract contract H1NativeBase {
    /* TYPE DECLARATIONS
    ==================================================*/
    struct H1NativeBaseStorage {
        /**
         * @dev The FeeContract to interact with for fee payments and updates.
         */
        IFeeContract feeContract;
        /**
         * @dev The remaining msg.value after the fee has been paid.
         */
        uint256 msgValueAfterFee;
    }

    /* STATE VARIABLES
    ==================================================*/
    /**
     * @dev
     *   ```solidity
     *   keccak256(
     *       abi.encode(uint256(keccak256("h1.storage.H1NativeBase")) - 1)
     *   ) & ~bytes32(uint256(0xff));
     * ```
     */
    bytes32 private constant H1NATIVE_STORAGE =
        0x8e7ec97a86b55b46cf58cbcd08faba09d3e8d3aec4d6bf8802477f1aa7a4c700;

    /* EVENTS
    ==================================================*/
    /**
     * @notice Emits when the feeAddress was updated by the admin.
     * @param feeContractAddressNew The new feeContract address.
     * @param feeContractAddressPrev The previous feeContract address.
     */
    event FeeAddressUpdated(
        address indexed feeContractAddressNew,
        address feeContractAddressPrev
    );

    /* ERRORS
    ==================================================*/
    /**
     * @notice This error is thrown when trying to initialize the contract after
     * it has already been initialized.
     */
    error H1NativeBase__AlreadyInitialized();

    /**
     * @notice This error is thrown when trying to initialize the contract with
     * an invalid FeeContract address.
     */
    error H1NativeBase__InvalidFeeContract();

    /**
     * @notice This error is thrown when there are insufficient funds send to
     * pay the fee.
     *
     * @param fundsInContract The current balance of the contract
     * @param currentFee The current fee amount
     */
    error H1NativeBase__InsufficientFunds(
        uint256 fundsInContract,
        uint256 currentFee
    );

    /* MODIFIERS
    ==================================================*/
    /**
     * @notice This modifier handles the payment of the application fee.
     * It should be used in functions that need to pay the fee.
     *
     * @param payableFunction If true, the function using this modifier is by
     * default payable and `msg.value` should be reduced by the fee.
     *
     * @param refundRemainingBalance Whether the remaining balance after the
     * function execution should be refunded to the sender.
     *
     * @dev checks if fee is not only send via msg.value, but also available as
     * balance in the contract to correctly return underfunded multicalls via
     * delegatecall with InsufficientFunds error (see uniswap v3).
     */
    modifier applicationFee(bool payableFunction, bool refundRemainingBalance) {
        _updateFee();
        uint256 fee = _feeContract().getFee();

        if (msg.value < fee || (address(this).balance < fee)) {
            revert H1NativeBase__InsufficientFunds(address(this).balance, fee);
        }

        H1NativeBaseStorage storage $ = _getH1NativeStorage();
        if (payableFunction) $.msgValueAfterFee = (msg.value - fee);

        _payFee(fee);

        _;

        if (refundRemainingBalance && address(this).balance > 0) {
            _safeTransfer(msg.sender, address(this).balance);
        }

        delete $.msgValueAfterFee;
    }

    /* FUNCTIONS
    ==================================================*/
    /* External
    ========================================*/
    /**
     * @dev Change the feeContract after deployment
     * @param feeContract the new fee contract address
     */
    function updateFeeContractAddress(address feeContract) external {
        _authorizeFeeContractAddressUpdate();
        address feeAddressPrev = address(_feeContract());
        _getH1NativeStorage().feeContract = IFeeContract(feeContract);
        IFeeContract(feeContract).setGraceContract(true);
        emit FeeAddressUpdated(feeContract, feeAddressPrev);
    }

    /* Internal
    ========================================*/
    /**
     * @notice Initializes the contract with the given FeeContract.
     * @param feeContract The address of the FeeContract
     * @dev This function should be called once after contract deployment to set
     * the FeeContract.
     */
    function _h1NativeBase_init(address feeContract) internal {
        if (address(_feeContract()) != address(0))
            revert H1NativeBase__AlreadyInitialized();
        if (feeContract == address(0))
            revert H1NativeBase__InvalidFeeContract();
        _getH1NativeStorage().feeContract = IFeeContract(feeContract);
        IFeeContract(feeContract).setGraceContract(true);
    }

    /**
     * @notice Pays the fee to the FeeContract.
     */
    function _payFee(uint256 fee) internal {
        _safeTransfer(address(_feeContract()), fee);
    }

    /**
     * @notice Updates the fee from the FeeContract.
     * @dev This will call the update function in the FeeContract, as well as
     * check if it is time to update the local fee because the time threshold
     * was exceeded.
     */
    function _updateFee() internal {
        _feeContract().updateFee();
    }

    /**
     * @dev safeTransfer function copied from OpenZeppelin TransferHelper.sol
     * May revert with "STE".
     */
    function _safeTransfer(address to, uint256 amount) internal {
        (bool success, ) = to.call{value: amount}(new bytes(0));
        require(success, "STE");
    }

    /**
     * @dev ensures the person updating the feeContract address is authorized
     */
    function _authorizeFeeContractAddressUpdate() internal virtual {}

    /**
     * @notice Returns the `msgValueAfterFee`.
     * @return The `msgValueAfterFee`.
     */
    function _msgValueAfterFee() internal view returns (uint256) {
        return _getH1NativeStorage().msgValueAfterFee;
    }

    /* Private
    ========================================*/
    /**
     * @notice Returns the `feeContract`.
     * @return The `feeContract`.
     */
    function _feeContract() private view returns (IFeeContract) {
        return _getH1NativeStorage().feeContract;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    function _getH1NativeStorage()
        private
        pure
        returns (H1NativeBaseStorage storage $)
    {
        assembly {
            $.slot := H1NATIVE_STORAGE
        }
    }
}
          

Compiler Settings

{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true,"details":{"yul":true}},"libraries":{}}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"error","name":"H1NativeBase__AlreadyInitialized","inputs":[]},{"type":"error","name":"H1NativeBase__InsufficientFunds","inputs":[{"type":"uint256","name":"fundsInContract","internalType":"uint256"},{"type":"uint256","name":"currentFee","internalType":"uint256"}]},{"type":"error","name":"H1NativeBase__InvalidFeeContract","inputs":[]},{"type":"event","name":"AdminChanged","inputs":[{"type":"address","name":"previousAdmin","internalType":"address","indexed":false},{"type":"address","name":"newAdmin","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"BeaconUpgraded","inputs":[{"type":"address","name":"beacon","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"FeeAddressUpdated","inputs":[{"type":"address","name":"feeContractAddressNew","internalType":"address","indexed":true},{"type":"address","name":"feeContractAddressPrev","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"OnlyVeHolderClaimingEnabled","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"bool","name":"enabled","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"TokenCheckpointed","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"lastCheckpointTimestamp","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TokenClaimingEnabled","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable","indexed":true},{"type":"bool","name":"enabled","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"TokenWithdrawn","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"address","name":"recipient","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"TokensClaimed","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"address","name":"token","internalType":"contract IERC20Upgradeable","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"userTokenTimeCursor","internalType":"uint256","indexed":false},{"type":"bool","name":"compounded","internalType":"bool","indexed":true}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"implementation","internalType":"address","indexed":true}],"anonymous":false},{"type":"fallback","stateMutability":"payable"},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"canTokenBeClaimed","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"checkpoint","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"checkpointToken","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"checkpointTokens","inputs":[{"type":"address[]","name":"tokens","internalType":"contract IERC20Upgradeable[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"checkpointUser","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"claimToken","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"claimTokenAndCompound","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"claimTokens","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"address[]","name":"tokens","internalType":"contract IERC20Upgradeable[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"claimTokensAndCompound","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"address[]","name":"tokens","internalType":"contract IERC20Upgradeable[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"depositToken","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"depositTokens","inputs":[{"type":"address[]","name":"tokens","internalType":"contract IERC20Upgradeable[]"},{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"enableOnlyVeHolderClaiming","inputs":[{"type":"bool","name":"enabled","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"enableTokenClaiming","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"},{"type":"bool","name":"enable","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"estimatedPendingRewards","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"address","name":"tkn","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getStartTime","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTimeCursor","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTokenCachedBalance","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTokenStartTime","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTokenTimeCursor","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTokensDistributedInWeek","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTotalSupplyAtTimestamp","inputs":[{"type":"uint256","name":"timestamp","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getUserBalanceAtTimestamp","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"uint256","name":"timestamp","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getUserLastEpochCheckpointed","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getUserStartTime","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getUserTimeCursor","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getUserTokenTimeCursor","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IVotingEscrow"}],"name":"getVotingEscrow","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"historicalRewardTokens","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"votingEscrow","internalType":"contract IVotingEscrow"},{"type":"uint256","name":"startTime","internalType":"uint256"},{"type":"address","name":"feeContract","internalType":"address"},{"type":"address","name":"havenAssociation","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isHistoricalRewardToken","inputs":[{"type":"address","name":"tkn","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"nPeriodRewards","inputs":[{"type":"address","name":"tkn","internalType":"contract IERC20Upgradeable"},{"type":"uint256","name":"lookbackWeeks","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"onlyVeHolderClaimingEnabled","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"proxiableUUID","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateFeeContractAddress","inputs":[{"type":"address","name":"feeContract","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"upgradeTo","inputs":[{"type":"address","name":"newImplementation","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"upgradeToAndCall","inputs":[{"type":"address","name":"newImplementation","internalType":"address"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawToken","inputs":[{"type":"address","name":"token","internalType":"contract IERC20Upgradeable"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"recipient","internalType":"address"}]},{"type":"receive","stateMutability":"payable"}]
              

Contract Creation Code

Verify & Publish
0x60a0604052306080523480156200001557600080fd5b506200002062000026565b620000e7565b600054610100900460ff1615620000935760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811614620000e5576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b60805161457a6200011f60003960008181611062015281816110a2015281816111c1015281816112010152611279015261457a6000f3fe60806040526004361061026b5760003560e01c8063876e69a111610144578063c8a0f2d5116100b6578063d3dc4ca11161007a578063d3dc4ca1146108c8578063d547741f1461090c578063de2283ab1461092c578063de681faf14610966578063dfcf3c2c146109aa578063f14045ac146109cc576102b8565b8063c8a0f2d5146107f4578063ca31879d1461083b578063cc0873641461084e578063cfa29d3e1461086e578063d2a0a446146108a8576102b8565b8063a217fddf11610108578063a217fddf14610713578063a3208f8214610728578063acbc142814610762578063afad584c146107a9578063c2c4c5c1146107c9578063c828371e146107de576102b8565b8063876e69a114610639578063887204671461068057806389d11a5914610693578063905d10ac146106d357806391d14854146106f3576102b8565b806336568abe116101dd5780634f3c5090116101a15780634f3c50901461058057806352d1902d146105ae578063648d6ccc146105c35780637b8d6221146105e35780638050a7ee1461060357806382aa5ad414610623576102b8565b806336568abe146104ed5780633659cfe61461050d5780633902b9bc1461052d5780633ccdbb281461054d5780634f1ef2861461056d576102b8565b80631a347f5d1161022f5780631a347f5d146103f6578063248a9ca314610416578063286d5e7f146104465780632f2ff15d1461048d578063338b5dea146104ad578063358394d8146104cd576102b8565b806301ffc9a7146102fb57806308b0308a146103305780630c59ef341461035957806314866e08146103a75780631a018fd5146103c9576102b8565b366102b85760405162461bcd60e51b815260206004820152601860248201527743616e6e6f742072656365697665206e617469766520483160401b60448201526064015b60405180910390fd5b60405162461bcd60e51b815260206004820152601860248201527743616e6e6f742072656365697665206e617469766520483160401b60448201526064016102af565b34801561030757600080fd5b5061031b610316366004613c04565b6109ec565b60405190151581526020015b60405180910390f35b34801561033c57600080fd5b5061012d546040516001600160a01b039091168152602001610327565b34801561036557600080fd5b50610399610374366004613c43565b6001600160a01b0316600090815261013460205260409020546001600160401b031690565b604051908152602001610327565b3480156103b357600080fd5b506103c76103c2366004613c43565b610a23565b005b3480156103d557600080fd5b506103e96103e4366004613cab565b610a41565b6040516103279190613cff565b34801561040257600080fd5b506103c7610411366004613c43565b610bf1565b34801561042257600080fd5b50610399610431366004613d37565b60009081526065602052604090206001015490565b34801561045257600080fd5b50610399610461366004613c43565b6001600160a01b031660009081526101346020526040902054600160801b90046001600160801b031690565b34801561049957600080fd5b506103c76104a8366004613d50565b610cc6565b3480156104b957600080fd5b506103c76104c8366004613d80565b610cf0565b3480156104d957600080fd5b506103c76104e8366004613dac565b610d3c565b3480156104f957600080fd5b506103c7610508366004613d50565b610fde565b34801561051957600080fd5b506103c7610528366004613c43565b611058565b34801561053957600080fd5b506103c7610548366004613c43565b61111d565b34801561055957600080fd5b506103c7610568366004613dff565b611145565b6103c761057b366004613e87565b6111b7565b34801561058c57600080fd5b5061039961059b366004613d37565b6000908152610130602052604090205490565b3480156105ba57600080fd5b5061039961126c565b3480156105cf57600080fd5b506103996105de366004613d80565b61131f565b3480156105ef57600080fd5b506103c76105fe366004613f2e565b6113fa565b34801561060f57600080fd5b5061039961061e366004613f99565b611528565b34801561062f57600080fd5b5061012f54610399565b34801561064557600080fd5b50610399610654366004613c43565b6001600160a01b031660009081526101346020526040902054600160401b90046001600160401b031690565b6103e961068e366004613cab565b611534565b34801561069f57600080fd5b506103996106ae366004613c43565b6001600160a01b0316600090815261013160205260409020546001600160401b031690565b3480156106df57600080fd5b506103c76106ee366004613fc7565b6117a8565b3480156106ff57600080fd5b5061031b61070e366004613d50565b611802565b34801561071f57600080fd5b50610399600081565b34801561073457600080fd5b5061031b610743366004613c43565b6001600160a01b03166000908152610137602052604090205460ff1690565b34801561076e57600080fd5b5061039961077d366004613c43565b6001600160a01b031660009081526101316020526040902054600160401b90046001600160401b031690565b3480156107b557600080fd5b506103996107c4366004613f99565b61182d565b3480156107d557600080fd5b506103c761199a565b3480156107ea57600080fd5b5061012e54610399565b34801561080057600080fd5b5061039961080f366004613c43565b6001600160a01b031660009081526101316020526040902054600160801b90046001600160801b031690565b610399610849366004613f99565b6119b6565b34801561085a57600080fd5b506103c7610869366004614016565b611b4d565b34801561087a57600080fd5b5061031b610889366004613c43565b6001600160a01b03166000908152610138602052604090205460ff1690565b3480156108b457600080fd5b506103996108c3366004613f99565b611ba3565b3480156108d457600080fd5b506103996108e3366004613d80565b6001600160a01b0391909116600090815261013260209081526040808320938352929052205490565b34801561091857600080fd5b506103c7610927366004613d50565b611c39565b34801561093857600080fd5b5061031b610947366004613c43565b6001600160a01b03166000908152610133602052604090205460ff1690565b34801561097257600080fd5b50610399610981366004613d80565b6001600160a01b0391909116600090815261013560209081526040808320938352929052205490565b3480156109b657600080fd5b506109bf611c5e565b6040516103279190614033565b3480156109d857600080fd5b506103c76109e7366004614074565b611cc1565b60006001600160e01b03198216637965db0b60e01b1480610a1d57506301ffc9a760e01b6001600160e01b03198316145b92915050565b610a2b611d4d565b610a3481611da6565b610a3e6001609755565b50565b6060610a4b611d4d565b6001600160a01b03841660009081526101376020526040902054849060ff1615610a9757336001600160a01b03821614610a975760405162461bcd60e51b81526004016102af906140a2565b83838060005b81811015610ae457610ad4848483818110610aba57610aba6140d9565b9050602002016020810190610acf9190613c43565b61221c565b610add81614105565b9050610a9d565b50610aed61227c565b610af688611da6565b856000816001600160401b03811115610b1157610b11613e41565b604051908082528060200260200182016040528015610b3a578160200160208202803683370190505b50905060005b82811015610bd857610b798a8a83818110610b5d57610b5d6140d9565b9050602002016020810190610b729190613c43565b6000612442565b610bab8b8b8b84818110610b8f57610b8f6140d9565b9050602002016020810190610ba49190613c43565b6001612803565b828281518110610bbd57610bbd6140d9565b6020908102919091010152610bd181614105565b9050610b40565b5095505050505050610bea6001609755565b9392505050565b610bf9612a28565b6000610c03612a33565b9050816000805160206144fe83398151915280546001600160a01b0319166001600160a01b039283161790556040516393ae190760e01b815260016004820152908316906393ae190790602401600060405180830381600087803b158015610c6a57600080fd5b505af1158015610c7e573d6000803e3d6000fd5b50506040516001600160a01b038481168252851692507f11f35a22548bcd4c3788ab4a7e4fba427a2014f02e5d5e2da9af62212c03183f915060200160405180910390a25050565b600082815260656020526040902060010154610ce181612a54565b610ceb8383612a5e565b505050565b610cf8611d4d565b81610d028161221c565b610d0d836000612442565b610d226001600160a01b038416333085612ae4565b610d2d836001612442565b50610d386001609755565b5050565b600054610100900460ff1615808015610d5c5750600054600160ff909116105b80610d765750303b158015610d76575060005460ff166001145b610dd95760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016102af565b6000805460ff191660011790558015610dfc576000805461ff0019166101001790555b610e04612b4f565b610e0c612b76565b610e14612b4f565b610e1e8383612ba5565b610e29600083612a5e565b61012d80546001600160a01b0319166001600160a01b038716179055610e4e84612bb9565b93506000610e5b42612bb9565b905080851015610ead5760405162461bcd60e51b815260206004820181905260248201527f43616e6e6f74207374617274206265666f72652063757272656e74207765656b60448201526064016102af565b60405163d1febfb960e01b8152600060048201819052906001600160a01b0388169063d1febfb990602401608060405180830381865afa158015610ef5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f199190614135565b905080604001518611610f835760405162461bcd60e51b815260206004820152602c60248201527f43616e6e6f74207374617274206265666f726520566f74696e67457363726f7760448201526b040ccd2e4e6e840cae0dec6d60a31b60648201526084016102af565b505061012e84905561012f8490558015610fd7576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b6001600160a01b038116331461104e5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016102af565b610d388282612bd5565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036110a05760405162461bcd60e51b81526004016102af906141a6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166110d2612c3c565b6001600160a01b0316146110f85760405162461bcd60e51b81526004016102af906141f2565b61110181612c52565b60408051600080825260208201909252610a3e91839190612c5d565b611125611d4d565b8061112f8161221c565b61113a826001612442565b50610a3e6001609755565b600061115081612a54565b6111646001600160a01b0385168385612dc8565b816001600160a01b0316846001600160a01b03167fa0524ee0fd8662d6c046d199da2a6d3dc49445182cec055873a5bb9c2843c8e0856040516111a991815260200190565b60405180910390a350505050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036111ff5760405162461bcd60e51b81526004016102af906141a6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611231612c3c565b6001600160a01b0316146112575760405162461bcd60e51b81526004016102af906141f2565b61126082612c52565b610d3882826001612c5d565b6000306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461130c5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c000000000000000060648201526084016102af565b506000805160206144de83398151915290565b6001600160a01b0382166000908152610138602052604081205460ff1661134857506000610a1d565b603482818111156113565750805b600061136142612bb9565b9050600061137262093a808361423e565b905060006113838462093a80614251565b61138d908361423e565b90506000805b858110156113ed576001600160a01b038a166000908152610132602090815260408083208684529091529020546113ca9083614268565b91506113d962093a8084614268565b9250806113e581614105565b915050611393565b5098975050505050505050565b611402611d4d565b8281146114495760405162461bcd60e51b8152602060048201526015602482015274092dce0eae840d8cadccee8d040dad2e6dac2e8c6d605b1b60448201526064016102af565b8260005b818110156115165761146a868683818110610aba57610aba6140d9565b61147f868683818110610b5d57610b5d6140d9565b6114d53330868685818110611496576114966140d9565b905060200201358989868181106114af576114af6140d9565b90506020020160208101906114c49190613c43565b6001600160a01b0316929190612ae4565b6115068686838181106114ea576114ea6140d9565b90506020020160208101906114ff9190613c43565b6001612442565b61150f81614105565b905061144d565b50506115226001609755565b50505050565b6000610bea8383612df8565b606061153e611d4d565b6001600160a01b03841660009081526101376020526040902054849060ff161561158a57336001600160a01b0382161461158a5760405162461bcd60e51b81526004016102af906140a2565b83838060005b818110156115bd576115ad848483818110610aba57610aba6140d9565b6115b681614105565b9050611590565b50600060016115ca612e78565b60006115d4612a33565b6001600160a01b031663ced72f876040518163ffffffff1660e01b8152600401602060405180830381865afa158015611611573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611635919061427b565b90508034108061164457508047105b1561166b5760405163ef2a9fa960e01b8152476004820152602481018290526044016102af565b6000805160206144fe83398151915283156116905761168a823461423e565b60018201555b61169982612ece565b6116a161227c565b6116aa8c611da6565b896000816001600160401b038111156116c5576116c5613e41565b6040519080825280602002602001820160405280156116ee578160200160208202803683370190505b50905060005b82811015611770576117118e8e83818110610b5d57610b5d6140d9565b6117438f8f8f84818110611727576117276140d9565b905060200201602081019061173c9190613c43565b6000612803565b828281518110611755576117556140d9565b602090810291909101015261176981614105565b90506116f4565b509950508280156117815750600047115b15611790576117903347612edb565b600060019182015560975550610bea95505050505050565b6117b0611d4d565b8060005b818110156117f6576117d1848483818110610aba57610aba6140d9565b6117e68484838181106114ea576114ea6140d9565b6117ef81614105565b90506117b4565b5050610d386001609755565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60008061183942612bb9565b9050600061184a62093a808361423e565b905060006118588686612df8565b90508082101561186e5760009350505050610a1d565b6000805b601481101561198f5783831161198f576001600160a01b038781166000908152610132602090815260408083208784529091528082205461012d54915163d07b705f60e01b81528c85166004820152602481018890529093919091169063d07b705f90604401602060405180830381865afa1580156118f5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611919919061427b565b9050600061192686612f7e565b90506119358662093a80614268565b9550821580611942575081155b8061194b575080155b156119585750505061197d565b806119638385614251565b61196d9190614294565b6119779086614268565b94505050505b8061198781614105565b915050611872565b509695505050505050565b6119a2611d4d565b6119aa61227c565b6119b46001609755565b565b60006119c0611d4d565b6001600160a01b03831660009081526101376020526040902054839060ff1615611a0c57336001600160a01b03821614611a0c5760405162461bcd60e51b81526004016102af906140a2565b82611a168161221c565b60006001611a22612e78565b6000611a2c612a33565b6001600160a01b031663ced72f876040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8d919061427b565b905080341080611a9c57508047105b15611ac35760405163ef2a9fa960e01b8152476004820152602481018290526044016102af565b6000805160206144fe8339815191528315611ae857611ae2823461423e565b60018201555b611af182612ece565b611af961227c565b611b0289611da6565b611b0d886000612442565b611b1989896000612803565b9650828015611b285750600047115b15611b3757611b373347612edb565b600060019182015560975550610a1d9350505050565b3360008181526101376020908152604091829020805460ff191685151590811790915591519182527f5df4db5082ff794d02e809cecb2c56f2ac683e734a0b4d1e03fd82b3da056c71910160405180910390a250565b6000611bad611d4d565b6001600160a01b03831660009081526101376020526040902054839060ff1615611bf957336001600160a01b03821614611bf95760405162461bcd60e51b81526004016102af906140a2565b82611c038161221c565b611c0b61227c565b611c1485611da6565b611c1f846000612442565b611c2b85856001612803565b92505050610a1d6001609755565b600082815260656020526040902060010154611c5481612a54565b610ceb8383612bd5565b6060610139805480602002602001604051908101604052809291908181526020018280548015611cb757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611c99575b5050505050905090565b6000611ccc81612a54565b6001600160a01b038316600090815261013360205260409020805460ff19168315801591909117909155611d0357611d0383613069565b826001600160a01b03167f359cee3647456cdac70428f1f028ea08d4bafdc5703fc14df9625b49f4398c9d83604051611d40911515815260200190565b60405180910390a2505050565b600260975403611d9f5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016102af565b6002609755565b61012d5460405163010ae75760e01b81526001600160a01b038381166004830152600092169063010ae75790602401602060405180830381865afa158015611df2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e16919061427b565b905060008111611e5f5760405162461bcd60e51b8152602060048201526014602482015273766548312062616c616e6365206973207a65726f60601b60448201526064016102af565b6001600160a01b03821660009081526101346020526040812080549091600160401b9091046001600160401b031690818103611eac57611ea58561012e546000876130f4565b9050611eee565b428210611eba575050505050565b508154600160801b90046001600160801b03166014611ed9828661423e565b1115611eee57611eeb858383876130f4565b90505b80600003611efa575060015b61012d546040516328d09d4760e01b81526001600160a01b0387811660048301526024820184905260009216906328d09d4790604401608060405180830381865afa158015611f4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f719190614135565b905082600003611fd35761012e544211611f9d5760405162461bcd60e51b81526004016102af906142b6565b611fb661012e54611fb183604001516131ec565b613203565b845467ffffffffffffffff19166001600160401b03821617855592505b6040805160808101825260008082526020820181905291810182905260608101829052905b60328110156121c657826040015185101580156120155750868411155b156120e157612025600185614268565b9350829150868411156120645760405180608001604052806000600f0b81526020016000600f0b815260200160008152602001600081525092506121b6565b61012d546040516328d09d4760e01b81526001600160a01b038a8116600483015260248201879052909116906328d09d4790604401608060405180830381865afa1580156120b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120da9190614135565b92506121b6565b428510156121c65760006121018360400151876120fe919061423e565b90565b9050600081846020015161211591906142fa565b600f0b8460000151600f0b1361212c576000612157565b61215782856020015161213f91906142fa565b855161214b9190614321565b6001600160801b031690565b90508015801561216657508886115b1561217d57612174426131ec565b965050506121c6565b6001600160a01b038a166000908152610135602090815260408083208a845290915290208190556121b162093a8088614268565b965050505b6121bf81614105565b9050611ff8565b506121d260018461423e565b85546001600160401b03908116918116600160801b0267ffffffffffffffff60401b191691909117600160401b9590911694909402939093179093555050505050565b6001609755565b6001600160a01b0381166000908152610133602052604090205460ff16610a3e5760405162461bcd60e51b8152602060048201526014602482015273151bdad95b881a5cc81b9bdd08185b1b1bddd95960621b60448201526064016102af565b61012f54600061228b42612bb9565b90508082118061229a57504281145b156122a3575050565b61012d60009054906101000a90046001600160a01b03166001600160a01b031663c2c4c5c16040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156122f457600080fd5b505af1158015612308573d6000803e3d6000fd5b5050505060005b601481101561243a5781831161243a57600061232a84613219565b61012d5460405163d1febfb960e01b8152600481018390529192506000916001600160a01b039091169063d1febfb990602401608060405180830381865afa15801561237a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061239e9190614135565b90506000816040015186116123b45760006123c7565b6123c78260400151876120fe919061423e565b905060008183602001516123db91906142fa565b83516123e79190614321565b9050600081600f0b136123fb576000612406565b6001600160801b0381165b6000888152610130602052604090205561242362093a8088614268565b9650505050508061243390614105565b905061230f565b505061012f55565b6001600160a01b03821660009081526101316020526040812080549091600160401b9091046001600160401b0316908181036124c75761012e54421161249a5760405162461bcd60e51b81526004016102af906142b6565b4291506124a642612bb9565b835467ffffffffffffffff19166001600160401b0391909116178355612528565b6124d1824261423e565b9050836125285760006124e383612bb9565b6124ec42612bb9565b149050600062015180426124ff426131ec565b612509919061423e565b109050818015612517575080155b156125255750505050505050565b50505b825467ffffffffffffffff60401b1916600160401b426001600160401b0316021783556040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa158015612592573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125b6919061427b565b84549091506000906125d9908390600160801b90046001600160801b0316613388565b9050806000036125ec5750505050505050565b6001600160801b038211156126435760405162461bcd60e51b815260206004820152601e60248201527f4d6178696d756d20746f6b656e2062616c616e6365206578636565646564000060448201526064016102af565b84546001600160801b03808416600160801b029116178555600061266685612bb9565b6001600160a01b03891660009081526101326020526040812091925090815b60148110156127b25761269b8462093a80614268565b92508242101561271d57861580156126b257508742145b156126e057600084815260208390526040812080548792906126d5908490614268565b909155506127b29050565b866126eb894261423e565b6126f59087614251565b6126ff9190614294565b600085815260208490526040812080549091906126d5908490614268565b8615801561272a57508783145b15612758576000848152602083905260408120805487929061274d908490614268565b9091555061279b9050565b86612763898561423e565b61276d9087614251565b6127779190614294565b60008581526020849052604081208054909190612795908490614268565b90915550505b829750829350806127ab90614105565b9050612685565b5060408051858152602081018990526001600160a01b038c16917f9b7f1a85a4c9b4e59e1b6527d9969c50cdfb3a1a467d0c4a51fb0ed8bf07f130910160405180910390a250505050505050505050565b6001600160a01b038216600090815261013160205260408120816128278686612df8565b61012f546001600160a01b0388166000908152610134602052604081205492935091612890916128709161286b9190600160401b90046001600160401b0316613394565b6131ec565b845461288b90600160401b90046001600160401b0316612bb9565b613394565b6001600160a01b03808816600090815261013260209081526040808320938c1683526101359091528120929350909190805b60148110156129335784861015612933576000868152610130602090815260408083205486835281842054928890529220546128fe9190614251565b6129089190614294565b6129129083614268565b915061292162093a8087614268565b955061292c81614105565b90506128c2565b506001600160a01b03808b16600090815261013660209081526040808320938d1683529290522085905580156129c2578554612980908290600160801b90046001600160801b031661423e565b86546001600160801b03918216600160801b02911617865587156129ae576129a98a8a836133a3565b6129c2565b6129c26001600160a01b038a168b83612dc8565b871515896001600160a01b03168b6001600160a01b03167f94bfe57e720d48f67fc7e4ed45b1eb24eafb3553d169324ce954234c3f9d98ff8489604051612a13929190918252602082015260400190565b60405180910390a49998505050505050505050565b6000610a3e81612a54565b60006000805160206144fe8339815191525b546001600160a01b0316919050565b610a3e8133613519565b612a688282611802565b610d385760008281526065602090815260408083206001600160a01b03851684529091529020805460ff19166001179055612aa03390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6040516001600160a01b03808516602483015283166044820152606481018290526115229085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613572565b600054610100900460ff166119b45760405162461bcd60e51b81526004016102af90614360565b600054610100900460ff16612b9d5760405162461bcd60e51b81526004016102af90614360565b6119b4613647565b612bb0600082612a5e565b610d388261366e565b6000612bc862093a8083614294565b610a1d9062093a80614251565b612bdf8282611802565b15610d385760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60006000805160206144de833981519152612a45565b6000610d3881612a54565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615612c9057610ceb8361373f565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612cea575060408051601f3d908101601f19168201909252612ce79181019061427b565b60015b612d4d5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b60648201526084016102af565b6000805160206144de8339815191528114612dbc5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b60648201526084016102af565b50610ceb8383836137db565b6040516001600160a01b038316602482015260448101829052610ceb90849063a9059cbb60e01b90606401612b18565b6001600160a01b038083166000908152610136602090815260408083209385168352929052908120548015612e2e579050610a1d565b6001600160a01b03808516600090815261013460209081526040808320549387168352610131909152902054612e70916001600160401b039081169116613203565b949350505050565b612e80612a33565b6001600160a01b031663758cdcf06040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612eba57600080fd5b505af1158015611522573d6000803e3d6000fd5b610a3e612ed9612a33565b825b604080516000808252602082019092526001600160a01b038416908390604051612f0591906143cf565b60006040518083038185875af1925050503d8060008114612f42576040519150601f19603f3d011682016040523d82523d6000602084013e612f47565b606091505b5050905080610ceb5760405162461bcd60e51b815260206004820152600360248201526253544560e81b60448201526064016102af565b600080612f8a83613219565b61012d5460405163d1febfb960e01b8152600481018390529192506000916001600160a01b039091169063d1febfb990602401608060405180830381865afa158015612fda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ffe9190614135565b905060008160400151851115613024576130218260400151866120fe919061423e565b90505b600081836020015161303691906142fa565b83516130429190614321565b9050600081600f0b1215613054575060005b6001600160801b0381165b9695505050505050565b6001600160a01b0381166000908152610138602052604090205460ff1680610d3857506001600160a01b0316600081815261013860205260408120805460ff19166001908117909155610139805491820181559091527f22d66071756d4d57920b8322c1a903a27bd75b44065e925d5f9f1c08908d28f60180546001600160a01b0319169091179055565b60008282825b60808110156131e057818310156131e057600060026131198486614268565b613124906002614268565b61312e9190614294565b61012d546040516328d09d4760e01b81526001600160a01b038c8116600483015260248201849052929350600092909116906328d09d4790604401608060405180830381865afa158015613186573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131aa9190614135565b9050888160400151116131bf578194506131cd565b6131ca60018361423e565b93505b5050806131d990614105565b90506130fa565b50909695505050505050565b6000610a1d6131fe62093a7f84614268565b612bb9565b60008183116132125781610bea565b5090919050565b60008060009050600061012d60009054906101000a90046001600160a01b03166001600160a01b031663900cf0cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613276573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061329a919061427b565b905060005b608081101561337f578183101561337f57600060026132be8486614268565b6132c9906002614268565b6132d39190614294565b61012d5460405163d1febfb960e01b8152600481018390529192506000916001600160a01b039091169063d1febfb990602401608060405180830381865afa158015613323573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133479190614135565b90508681604001511161335c5781945061336a565b61336760018361423e565b93505b5050808061337790614105565b91505061329f565b50909392505050565b6000610bea828461423e565b60008183106132125781610bea565b61012d5460405163095ea7b360e01b81526001600160a01b039182166004820152602481018390529083169063095ea7b3906044016020604051808303816000875af11580156133f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341b91906143eb565b5061012d5460405163978919c560e01b81526001600160a01b0385811660048301526024820184905284811660448301523060648301529091169063978919c590608401600060405180830381600087803b15801561347957600080fd5b505af115801561348d573d6000803e3d6000fd5b505061012d54604051636eb1769f60e11b81523060048201526001600160a01b03918216602482015260009350908516915063dd62ed3e90604401602060405180830381865afa1580156134e5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613509919061427b565b9050801561152257611522614408565b6135238282611802565b610d385761353081613800565b61353b836020613812565b60405160200161354c92919061441e565b60408051601f198184030181529082905262461bcd60e51b82526102af91600401614493565b60006135c7826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166139ad9092919063ffffffff16565b90508051600014806135e85750808060200190518101906135e891906143eb565b610ceb5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016102af565b600054610100900460ff166122155760405162461bcd60e51b81526004016102af90614360565b6000613678612a33565b6001600160a01b03161461369f5760405163bbd9617760e01b815260040160405180910390fd5b6001600160a01b0381166136c65760405163110626eb60e01b815260040160405180910390fd5b806000805160206144fe83398151915280546001600160a01b0319166001600160a01b039283161790556040516393ae190760e01b815260016004820152908216906393ae190790602401600060405180830381600087803b15801561372b57600080fd5b505af1158015610fd7573d6000803e3d6000fd5b6001600160a01b0381163b6137ac5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084016102af565b6000805160206144de83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6137e4836139bc565b6000825111806137f15750805b15610ceb5761152283836139fc565b6060610a1d6001600160a01b03831660145b60606000613821836002614251565b61382c906002614268565b6001600160401b0381111561384357613843613e41565b6040519080825280601f01601f19166020018201604052801561386d576020820181803683370190505b509050600360fc1b81600081518110613888576138886140d9565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106138b7576138b76140d9565b60200101906001600160f81b031916908160001a90535060006138db846002614251565b6138e6906001614268565b90505b600181111561395e576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061391a5761391a6140d9565b1a60f81b828281518110613930576139306140d9565b60200101906001600160f81b031916908160001a90535060049490941c93613957816144c6565b90506138e9565b508315610bea5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016102af565b6060612e708484600085613a21565b6139c58161373f565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060610bea838360405180606001604052806027815260200161451e60279139613afc565b606082471015613a825760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016102af565b600080866001600160a01b03168587604051613a9e91906143cf565b60006040518083038185875af1925050503d8060008114613adb576040519150601f19603f3d011682016040523d82523d6000602084013e613ae0565b606091505b5091509150613af187838387613b66565b979650505050505050565b6060600080856001600160a01b031685604051613b1991906143cf565b600060405180830381855af49150503d8060008114613b54576040519150601f19603f3d011682016040523d82523d6000602084013e613b59565b606091505b509150915061305f868383875b60608315613bd5578251600003613bce576001600160a01b0385163b613bce5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016102af565b5081612e70565b612e708383815115613bea5781518083602001fd5b8060405162461bcd60e51b81526004016102af9190614493565b600060208284031215613c1657600080fd5b81356001600160e01b031981168114610bea57600080fd5b6001600160a01b0381168114610a3e57600080fd5b600060208284031215613c5557600080fd5b8135610bea81613c2e565b60008083601f840112613c7257600080fd5b5081356001600160401b03811115613c8957600080fd5b6020830191508360208260051b8501011115613ca457600080fd5b9250929050565b600080600060408486031215613cc057600080fd5b8335613ccb81613c2e565b925060208401356001600160401b03811115613ce657600080fd5b613cf286828701613c60565b9497909650939450505050565b6020808252825182820181905260009190848201906040850190845b818110156131e057835183529284019291840191600101613d1b565b600060208284031215613d4957600080fd5b5035919050565b60008060408385031215613d6357600080fd5b823591506020830135613d7581613c2e565b809150509250929050565b60008060408385031215613d9357600080fd5b8235613d9e81613c2e565b946020939093013593505050565b60008060008060808587031215613dc257600080fd5b8435613dcd81613c2e565b9350602085013592506040850135613de481613c2e565b91506060850135613df481613c2e565b939692955090935050565b600080600060608486031215613e1457600080fd5b8335613e1f81613c2e565b9250602084013591506040840135613e3681613c2e565b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613e7f57613e7f613e41565b604052919050565b60008060408385031215613e9a57600080fd5b8235613ea581613c2e565b91506020838101356001600160401b0380821115613ec257600080fd5b818601915086601f830112613ed657600080fd5b813581811115613ee857613ee8613e41565b613efa601f8201601f19168501613e57565b91508082528784828501011115613f1057600080fd5b80848401858401376000848284010152508093505050509250929050565b60008060008060408587031215613f4457600080fd5b84356001600160401b0380821115613f5b57600080fd5b613f6788838901613c60565b90965094506020870135915080821115613f8057600080fd5b50613f8d87828801613c60565b95989497509550505050565b60008060408385031215613fac57600080fd5b8235613fb781613c2e565b91506020830135613d7581613c2e565b60008060208385031215613fda57600080fd5b82356001600160401b03811115613ff057600080fd5b613ffc85828601613c60565b90969095509350505050565b8015158114610a3e57600080fd5b60006020828403121561402857600080fd5b8135610bea81614008565b6020808252825182820181905260009190848201906040850190845b818110156131e05783516001600160a01b03168352928401929184019160010161404f565b6000806040838503121561408757600080fd5b823561409281613c2e565b91506020830135613d7581614008565b60208082526017908201527f436c61696d696e67206973206e6f7420616c6c6f776564000000000000000000604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201614117576141176140ef565b5060010190565b8051600f81900b811461413057600080fd5b919050565b60006080828403121561414757600080fd5b604051608081018181106001600160401b038211171561416957614169613e41565b6040526141758361411e565b81526141836020840161411e565b602082015260408301516040820152606083015160608201528091505092915050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b81810381811115610a1d57610a1d6140ef565b8082028115828204841417610a1d57610a1d6140ef565b80820180821115610a1d57610a1d6140ef565b60006020828403121561428d57600080fd5b5051919050565b6000826142b157634e487b7160e01b600052601260045260246000fd5b500490565b60208082526024908201527f46656520646973747269627574696f6e20686173206e6f742073746172746564604082015263081e595d60e21b606082015260800190565b600082600f0b82600f0b0280600f0b915080821461431a5761431a6140ef565b5092915050565b600f82810b9082900b036f7fffffffffffffffffffffffffffffff1981126f7fffffffffffffffffffffffffffffff82131715610a1d57610a1d6140ef565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60005b838110156143c65781810151838201526020016143ae565b50506000910152565b600082516143e18184602087016143ab565b9190910192915050565b6000602082840312156143fd57600080fd5b8151610bea81614008565b634e487b7160e01b600052600160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516144568160178501602088016143ab565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516144878160288401602088016143ab565b01602801949350505050565b60208152600082518060208401526144b28160408501602087016143ab565b601f01601f19169190910160400192915050565b6000816144d5576144d56140ef565b50600019019056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8e7ec97a86b55b46cf58cbcd08faba09d3e8d3aec4d6bf8802477f1aa7a4c700416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212206bae59dc80756441cc46e6965dea4c0f2a357b2b1a7935f8b889dba2eea9a4d764736f6c63430008130033

Deployed ByteCode

0x60806040526004361061026b5760003560e01c8063876e69a111610144578063c8a0f2d5116100b6578063d3dc4ca11161007a578063d3dc4ca1146108c8578063d547741f1461090c578063de2283ab1461092c578063de681faf14610966578063dfcf3c2c146109aa578063f14045ac146109cc576102b8565b8063c8a0f2d5146107f4578063ca31879d1461083b578063cc0873641461084e578063cfa29d3e1461086e578063d2a0a446146108a8576102b8565b8063a217fddf11610108578063a217fddf14610713578063a3208f8214610728578063acbc142814610762578063afad584c146107a9578063c2c4c5c1146107c9578063c828371e146107de576102b8565b8063876e69a114610639578063887204671461068057806389d11a5914610693578063905d10ac146106d357806391d14854146106f3576102b8565b806336568abe116101dd5780634f3c5090116101a15780634f3c50901461058057806352d1902d146105ae578063648d6ccc146105c35780637b8d6221146105e35780638050a7ee1461060357806382aa5ad414610623576102b8565b806336568abe146104ed5780633659cfe61461050d5780633902b9bc1461052d5780633ccdbb281461054d5780634f1ef2861461056d576102b8565b80631a347f5d1161022f5780631a347f5d146103f6578063248a9ca314610416578063286d5e7f146104465780632f2ff15d1461048d578063338b5dea146104ad578063358394d8146104cd576102b8565b806301ffc9a7146102fb57806308b0308a146103305780630c59ef341461035957806314866e08146103a75780631a018fd5146103c9576102b8565b366102b85760405162461bcd60e51b815260206004820152601860248201527743616e6e6f742072656365697665206e617469766520483160401b60448201526064015b60405180910390fd5b60405162461bcd60e51b815260206004820152601860248201527743616e6e6f742072656365697665206e617469766520483160401b60448201526064016102af565b34801561030757600080fd5b5061031b610316366004613c04565b6109ec565b60405190151581526020015b60405180910390f35b34801561033c57600080fd5b5061012d546040516001600160a01b039091168152602001610327565b34801561036557600080fd5b50610399610374366004613c43565b6001600160a01b0316600090815261013460205260409020546001600160401b031690565b604051908152602001610327565b3480156103b357600080fd5b506103c76103c2366004613c43565b610a23565b005b3480156103d557600080fd5b506103e96103e4366004613cab565b610a41565b6040516103279190613cff565b34801561040257600080fd5b506103c7610411366004613c43565b610bf1565b34801561042257600080fd5b50610399610431366004613d37565b60009081526065602052604090206001015490565b34801561045257600080fd5b50610399610461366004613c43565b6001600160a01b031660009081526101346020526040902054600160801b90046001600160801b031690565b34801561049957600080fd5b506103c76104a8366004613d50565b610cc6565b3480156104b957600080fd5b506103c76104c8366004613d80565b610cf0565b3480156104d957600080fd5b506103c76104e8366004613dac565b610d3c565b3480156104f957600080fd5b506103c7610508366004613d50565b610fde565b34801561051957600080fd5b506103c7610528366004613c43565b611058565b34801561053957600080fd5b506103c7610548366004613c43565b61111d565b34801561055957600080fd5b506103c7610568366004613dff565b611145565b6103c761057b366004613e87565b6111b7565b34801561058c57600080fd5b5061039961059b366004613d37565b6000908152610130602052604090205490565b3480156105ba57600080fd5b5061039961126c565b3480156105cf57600080fd5b506103996105de366004613d80565b61131f565b3480156105ef57600080fd5b506103c76105fe366004613f2e565b6113fa565b34801561060f57600080fd5b5061039961061e366004613f99565b611528565b34801561062f57600080fd5b5061012f54610399565b34801561064557600080fd5b50610399610654366004613c43565b6001600160a01b031660009081526101346020526040902054600160401b90046001600160401b031690565b6103e961068e366004613cab565b611534565b34801561069f57600080fd5b506103996106ae366004613c43565b6001600160a01b0316600090815261013160205260409020546001600160401b031690565b3480156106df57600080fd5b506103c76106ee366004613fc7565b6117a8565b3480156106ff57600080fd5b5061031b61070e366004613d50565b611802565b34801561071f57600080fd5b50610399600081565b34801561073457600080fd5b5061031b610743366004613c43565b6001600160a01b03166000908152610137602052604090205460ff1690565b34801561076e57600080fd5b5061039961077d366004613c43565b6001600160a01b031660009081526101316020526040902054600160401b90046001600160401b031690565b3480156107b557600080fd5b506103996107c4366004613f99565b61182d565b3480156107d557600080fd5b506103c761199a565b3480156107ea57600080fd5b5061012e54610399565b34801561080057600080fd5b5061039961080f366004613c43565b6001600160a01b031660009081526101316020526040902054600160801b90046001600160801b031690565b610399610849366004613f99565b6119b6565b34801561085a57600080fd5b506103c7610869366004614016565b611b4d565b34801561087a57600080fd5b5061031b610889366004613c43565b6001600160a01b03166000908152610138602052604090205460ff1690565b3480156108b457600080fd5b506103996108c3366004613f99565b611ba3565b3480156108d457600080fd5b506103996108e3366004613d80565b6001600160a01b0391909116600090815261013260209081526040808320938352929052205490565b34801561091857600080fd5b506103c7610927366004613d50565b611c39565b34801561093857600080fd5b5061031b610947366004613c43565b6001600160a01b03166000908152610133602052604090205460ff1690565b34801561097257600080fd5b50610399610981366004613d80565b6001600160a01b0391909116600090815261013560209081526040808320938352929052205490565b3480156109b657600080fd5b506109bf611c5e565b6040516103279190614033565b3480156109d857600080fd5b506103c76109e7366004614074565b611cc1565b60006001600160e01b03198216637965db0b60e01b1480610a1d57506301ffc9a760e01b6001600160e01b03198316145b92915050565b610a2b611d4d565b610a3481611da6565b610a3e6001609755565b50565b6060610a4b611d4d565b6001600160a01b03841660009081526101376020526040902054849060ff1615610a9757336001600160a01b03821614610a975760405162461bcd60e51b81526004016102af906140a2565b83838060005b81811015610ae457610ad4848483818110610aba57610aba6140d9565b9050602002016020810190610acf9190613c43565b61221c565b610add81614105565b9050610a9d565b50610aed61227c565b610af688611da6565b856000816001600160401b03811115610b1157610b11613e41565b604051908082528060200260200182016040528015610b3a578160200160208202803683370190505b50905060005b82811015610bd857610b798a8a83818110610b5d57610b5d6140d9565b9050602002016020810190610b729190613c43565b6000612442565b610bab8b8b8b84818110610b8f57610b8f6140d9565b9050602002016020810190610ba49190613c43565b6001612803565b828281518110610bbd57610bbd6140d9565b6020908102919091010152610bd181614105565b9050610b40565b5095505050505050610bea6001609755565b9392505050565b610bf9612a28565b6000610c03612a33565b9050816000805160206144fe83398151915280546001600160a01b0319166001600160a01b039283161790556040516393ae190760e01b815260016004820152908316906393ae190790602401600060405180830381600087803b158015610c6a57600080fd5b505af1158015610c7e573d6000803e3d6000fd5b50506040516001600160a01b038481168252851692507f11f35a22548bcd4c3788ab4a7e4fba427a2014f02e5d5e2da9af62212c03183f915060200160405180910390a25050565b600082815260656020526040902060010154610ce181612a54565b610ceb8383612a5e565b505050565b610cf8611d4d565b81610d028161221c565b610d0d836000612442565b610d226001600160a01b038416333085612ae4565b610d2d836001612442565b50610d386001609755565b5050565b600054610100900460ff1615808015610d5c5750600054600160ff909116105b80610d765750303b158015610d76575060005460ff166001145b610dd95760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016102af565b6000805460ff191660011790558015610dfc576000805461ff0019166101001790555b610e04612b4f565b610e0c612b76565b610e14612b4f565b610e1e8383612ba5565b610e29600083612a5e565b61012d80546001600160a01b0319166001600160a01b038716179055610e4e84612bb9565b93506000610e5b42612bb9565b905080851015610ead5760405162461bcd60e51b815260206004820181905260248201527f43616e6e6f74207374617274206265666f72652063757272656e74207765656b60448201526064016102af565b60405163d1febfb960e01b8152600060048201819052906001600160a01b0388169063d1febfb990602401608060405180830381865afa158015610ef5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f199190614135565b905080604001518611610f835760405162461bcd60e51b815260206004820152602c60248201527f43616e6e6f74207374617274206265666f726520566f74696e67457363726f7760448201526b040ccd2e4e6e840cae0dec6d60a31b60648201526084016102af565b505061012e84905561012f8490558015610fd7576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b6001600160a01b038116331461104e5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016102af565b610d388282612bd5565b6001600160a01b037f00000000000000000000000024f6225b84bd6defb2bc90e3b566f26586feb8851630036110a05760405162461bcd60e51b81526004016102af906141a6565b7f00000000000000000000000024f6225b84bd6defb2bc90e3b566f26586feb8856001600160a01b03166110d2612c3c565b6001600160a01b0316146110f85760405162461bcd60e51b81526004016102af906141f2565b61110181612c52565b60408051600080825260208201909252610a3e91839190612c5d565b611125611d4d565b8061112f8161221c565b61113a826001612442565b50610a3e6001609755565b600061115081612a54565b6111646001600160a01b0385168385612dc8565b816001600160a01b0316846001600160a01b03167fa0524ee0fd8662d6c046d199da2a6d3dc49445182cec055873a5bb9c2843c8e0856040516111a991815260200190565b60405180910390a350505050565b6001600160a01b037f00000000000000000000000024f6225b84bd6defb2bc90e3b566f26586feb8851630036111ff5760405162461bcd60e51b81526004016102af906141a6565b7f00000000000000000000000024f6225b84bd6defb2bc90e3b566f26586feb8856001600160a01b0316611231612c3c565b6001600160a01b0316146112575760405162461bcd60e51b81526004016102af906141f2565b61126082612c52565b610d3882826001612c5d565b6000306001600160a01b037f00000000000000000000000024f6225b84bd6defb2bc90e3b566f26586feb885161461130c5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c000000000000000060648201526084016102af565b506000805160206144de83398151915290565b6001600160a01b0382166000908152610138602052604081205460ff1661134857506000610a1d565b603482818111156113565750805b600061136142612bb9565b9050600061137262093a808361423e565b905060006113838462093a80614251565b61138d908361423e565b90506000805b858110156113ed576001600160a01b038a166000908152610132602090815260408083208684529091529020546113ca9083614268565b91506113d962093a8084614268565b9250806113e581614105565b915050611393565b5098975050505050505050565b611402611d4d565b8281146114495760405162461bcd60e51b8152602060048201526015602482015274092dce0eae840d8cadccee8d040dad2e6dac2e8c6d605b1b60448201526064016102af565b8260005b818110156115165761146a868683818110610aba57610aba6140d9565b61147f868683818110610b5d57610b5d6140d9565b6114d53330868685818110611496576114966140d9565b905060200201358989868181106114af576114af6140d9565b90506020020160208101906114c49190613c43565b6001600160a01b0316929190612ae4565b6115068686838181106114ea576114ea6140d9565b90506020020160208101906114ff9190613c43565b6001612442565b61150f81614105565b905061144d565b50506115226001609755565b50505050565b6000610bea8383612df8565b606061153e611d4d565b6001600160a01b03841660009081526101376020526040902054849060ff161561158a57336001600160a01b0382161461158a5760405162461bcd60e51b81526004016102af906140a2565b83838060005b818110156115bd576115ad848483818110610aba57610aba6140d9565b6115b681614105565b9050611590565b50600060016115ca612e78565b60006115d4612a33565b6001600160a01b031663ced72f876040518163ffffffff1660e01b8152600401602060405180830381865afa158015611611573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611635919061427b565b90508034108061164457508047105b1561166b5760405163ef2a9fa960e01b8152476004820152602481018290526044016102af565b6000805160206144fe83398151915283156116905761168a823461423e565b60018201555b61169982612ece565b6116a161227c565b6116aa8c611da6565b896000816001600160401b038111156116c5576116c5613e41565b6040519080825280602002602001820160405280156116ee578160200160208202803683370190505b50905060005b82811015611770576117118e8e83818110610b5d57610b5d6140d9565b6117438f8f8f84818110611727576117276140d9565b905060200201602081019061173c9190613c43565b6000612803565b828281518110611755576117556140d9565b602090810291909101015261176981614105565b90506116f4565b509950508280156117815750600047115b15611790576117903347612edb565b600060019182015560975550610bea95505050505050565b6117b0611d4d565b8060005b818110156117f6576117d1848483818110610aba57610aba6140d9565b6117e68484838181106114ea576114ea6140d9565b6117ef81614105565b90506117b4565b5050610d386001609755565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60008061183942612bb9565b9050600061184a62093a808361423e565b905060006118588686612df8565b90508082101561186e5760009350505050610a1d565b6000805b601481101561198f5783831161198f576001600160a01b038781166000908152610132602090815260408083208784529091528082205461012d54915163d07b705f60e01b81528c85166004820152602481018890529093919091169063d07b705f90604401602060405180830381865afa1580156118f5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611919919061427b565b9050600061192686612f7e565b90506119358662093a80614268565b9550821580611942575081155b8061194b575080155b156119585750505061197d565b806119638385614251565b61196d9190614294565b6119779086614268565b94505050505b8061198781614105565b915050611872565b509695505050505050565b6119a2611d4d565b6119aa61227c565b6119b46001609755565b565b60006119c0611d4d565b6001600160a01b03831660009081526101376020526040902054839060ff1615611a0c57336001600160a01b03821614611a0c5760405162461bcd60e51b81526004016102af906140a2565b82611a168161221c565b60006001611a22612e78565b6000611a2c612a33565b6001600160a01b031663ced72f876040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8d919061427b565b905080341080611a9c57508047105b15611ac35760405163ef2a9fa960e01b8152476004820152602481018290526044016102af565b6000805160206144fe8339815191528315611ae857611ae2823461423e565b60018201555b611af182612ece565b611af961227c565b611b0289611da6565b611b0d886000612442565b611b1989896000612803565b9650828015611b285750600047115b15611b3757611b373347612edb565b600060019182015560975550610a1d9350505050565b3360008181526101376020908152604091829020805460ff191685151590811790915591519182527f5df4db5082ff794d02e809cecb2c56f2ac683e734a0b4d1e03fd82b3da056c71910160405180910390a250565b6000611bad611d4d565b6001600160a01b03831660009081526101376020526040902054839060ff1615611bf957336001600160a01b03821614611bf95760405162461bcd60e51b81526004016102af906140a2565b82611c038161221c565b611c0b61227c565b611c1485611da6565b611c1f846000612442565b611c2b85856001612803565b92505050610a1d6001609755565b600082815260656020526040902060010154611c5481612a54565b610ceb8383612bd5565b6060610139805480602002602001604051908101604052809291908181526020018280548015611cb757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611c99575b5050505050905090565b6000611ccc81612a54565b6001600160a01b038316600090815261013360205260409020805460ff19168315801591909117909155611d0357611d0383613069565b826001600160a01b03167f359cee3647456cdac70428f1f028ea08d4bafdc5703fc14df9625b49f4398c9d83604051611d40911515815260200190565b60405180910390a2505050565b600260975403611d9f5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016102af565b6002609755565b61012d5460405163010ae75760e01b81526001600160a01b038381166004830152600092169063010ae75790602401602060405180830381865afa158015611df2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e16919061427b565b905060008111611e5f5760405162461bcd60e51b8152602060048201526014602482015273766548312062616c616e6365206973207a65726f60601b60448201526064016102af565b6001600160a01b03821660009081526101346020526040812080549091600160401b9091046001600160401b031690818103611eac57611ea58561012e546000876130f4565b9050611eee565b428210611eba575050505050565b508154600160801b90046001600160801b03166014611ed9828661423e565b1115611eee57611eeb858383876130f4565b90505b80600003611efa575060015b61012d546040516328d09d4760e01b81526001600160a01b0387811660048301526024820184905260009216906328d09d4790604401608060405180830381865afa158015611f4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f719190614135565b905082600003611fd35761012e544211611f9d5760405162461bcd60e51b81526004016102af906142b6565b611fb661012e54611fb183604001516131ec565b613203565b845467ffffffffffffffff19166001600160401b03821617855592505b6040805160808101825260008082526020820181905291810182905260608101829052905b60328110156121c657826040015185101580156120155750868411155b156120e157612025600185614268565b9350829150868411156120645760405180608001604052806000600f0b81526020016000600f0b815260200160008152602001600081525092506121b6565b61012d546040516328d09d4760e01b81526001600160a01b038a8116600483015260248201879052909116906328d09d4790604401608060405180830381865afa1580156120b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120da9190614135565b92506121b6565b428510156121c65760006121018360400151876120fe919061423e565b90565b9050600081846020015161211591906142fa565b600f0b8460000151600f0b1361212c576000612157565b61215782856020015161213f91906142fa565b855161214b9190614321565b6001600160801b031690565b90508015801561216657508886115b1561217d57612174426131ec565b965050506121c6565b6001600160a01b038a166000908152610135602090815260408083208a845290915290208190556121b162093a8088614268565b965050505b6121bf81614105565b9050611ff8565b506121d260018461423e565b85546001600160401b03908116918116600160801b0267ffffffffffffffff60401b191691909117600160401b9590911694909402939093179093555050505050565b6001609755565b6001600160a01b0381166000908152610133602052604090205460ff16610a3e5760405162461bcd60e51b8152602060048201526014602482015273151bdad95b881a5cc81b9bdd08185b1b1bddd95960621b60448201526064016102af565b61012f54600061228b42612bb9565b90508082118061229a57504281145b156122a3575050565b61012d60009054906101000a90046001600160a01b03166001600160a01b031663c2c4c5c16040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156122f457600080fd5b505af1158015612308573d6000803e3d6000fd5b5050505060005b601481101561243a5781831161243a57600061232a84613219565b61012d5460405163d1febfb960e01b8152600481018390529192506000916001600160a01b039091169063d1febfb990602401608060405180830381865afa15801561237a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061239e9190614135565b90506000816040015186116123b45760006123c7565b6123c78260400151876120fe919061423e565b905060008183602001516123db91906142fa565b83516123e79190614321565b9050600081600f0b136123fb576000612406565b6001600160801b0381165b6000888152610130602052604090205561242362093a8088614268565b9650505050508061243390614105565b905061230f565b505061012f55565b6001600160a01b03821660009081526101316020526040812080549091600160401b9091046001600160401b0316908181036124c75761012e54421161249a5760405162461bcd60e51b81526004016102af906142b6565b4291506124a642612bb9565b835467ffffffffffffffff19166001600160401b0391909116178355612528565b6124d1824261423e565b9050836125285760006124e383612bb9565b6124ec42612bb9565b149050600062015180426124ff426131ec565b612509919061423e565b109050818015612517575080155b156125255750505050505050565b50505b825467ffffffffffffffff60401b1916600160401b426001600160401b0316021783556040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa158015612592573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125b6919061427b565b84549091506000906125d9908390600160801b90046001600160801b0316613388565b9050806000036125ec5750505050505050565b6001600160801b038211156126435760405162461bcd60e51b815260206004820152601e60248201527f4d6178696d756d20746f6b656e2062616c616e6365206578636565646564000060448201526064016102af565b84546001600160801b03808416600160801b029116178555600061266685612bb9565b6001600160a01b03891660009081526101326020526040812091925090815b60148110156127b25761269b8462093a80614268565b92508242101561271d57861580156126b257508742145b156126e057600084815260208390526040812080548792906126d5908490614268565b909155506127b29050565b866126eb894261423e565b6126f59087614251565b6126ff9190614294565b600085815260208490526040812080549091906126d5908490614268565b8615801561272a57508783145b15612758576000848152602083905260408120805487929061274d908490614268565b9091555061279b9050565b86612763898561423e565b61276d9087614251565b6127779190614294565b60008581526020849052604081208054909190612795908490614268565b90915550505b829750829350806127ab90614105565b9050612685565b5060408051858152602081018990526001600160a01b038c16917f9b7f1a85a4c9b4e59e1b6527d9969c50cdfb3a1a467d0c4a51fb0ed8bf07f130910160405180910390a250505050505050505050565b6001600160a01b038216600090815261013160205260408120816128278686612df8565b61012f546001600160a01b0388166000908152610134602052604081205492935091612890916128709161286b9190600160401b90046001600160401b0316613394565b6131ec565b845461288b90600160401b90046001600160401b0316612bb9565b613394565b6001600160a01b03808816600090815261013260209081526040808320938c1683526101359091528120929350909190805b60148110156129335784861015612933576000868152610130602090815260408083205486835281842054928890529220546128fe9190614251565b6129089190614294565b6129129083614268565b915061292162093a8087614268565b955061292c81614105565b90506128c2565b506001600160a01b03808b16600090815261013660209081526040808320938d1683529290522085905580156129c2578554612980908290600160801b90046001600160801b031661423e565b86546001600160801b03918216600160801b02911617865587156129ae576129a98a8a836133a3565b6129c2565b6129c26001600160a01b038a168b83612dc8565b871515896001600160a01b03168b6001600160a01b03167f94bfe57e720d48f67fc7e4ed45b1eb24eafb3553d169324ce954234c3f9d98ff8489604051612a13929190918252602082015260400190565b60405180910390a49998505050505050505050565b6000610a3e81612a54565b60006000805160206144fe8339815191525b546001600160a01b0316919050565b610a3e8133613519565b612a688282611802565b610d385760008281526065602090815260408083206001600160a01b03851684529091529020805460ff19166001179055612aa03390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6040516001600160a01b03808516602483015283166044820152606481018290526115229085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613572565b600054610100900460ff166119b45760405162461bcd60e51b81526004016102af90614360565b600054610100900460ff16612b9d5760405162461bcd60e51b81526004016102af90614360565b6119b4613647565b612bb0600082612a5e565b610d388261366e565b6000612bc862093a8083614294565b610a1d9062093a80614251565b612bdf8282611802565b15610d385760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60006000805160206144de833981519152612a45565b6000610d3881612a54565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615612c9057610ceb8361373f565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612cea575060408051601f3d908101601f19168201909252612ce79181019061427b565b60015b612d4d5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b60648201526084016102af565b6000805160206144de8339815191528114612dbc5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b60648201526084016102af565b50610ceb8383836137db565b6040516001600160a01b038316602482015260448101829052610ceb90849063a9059cbb60e01b90606401612b18565b6001600160a01b038083166000908152610136602090815260408083209385168352929052908120548015612e2e579050610a1d565b6001600160a01b03808516600090815261013460209081526040808320549387168352610131909152902054612e70916001600160401b039081169116613203565b949350505050565b612e80612a33565b6001600160a01b031663758cdcf06040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612eba57600080fd5b505af1158015611522573d6000803e3d6000fd5b610a3e612ed9612a33565b825b604080516000808252602082019092526001600160a01b038416908390604051612f0591906143cf565b60006040518083038185875af1925050503d8060008114612f42576040519150601f19603f3d011682016040523d82523d6000602084013e612f47565b606091505b5050905080610ceb5760405162461bcd60e51b815260206004820152600360248201526253544560e81b60448201526064016102af565b600080612f8a83613219565b61012d5460405163d1febfb960e01b8152600481018390529192506000916001600160a01b039091169063d1febfb990602401608060405180830381865afa158015612fda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ffe9190614135565b905060008160400151851115613024576130218260400151866120fe919061423e565b90505b600081836020015161303691906142fa565b83516130429190614321565b9050600081600f0b1215613054575060005b6001600160801b0381165b9695505050505050565b6001600160a01b0381166000908152610138602052604090205460ff1680610d3857506001600160a01b0316600081815261013860205260408120805460ff19166001908117909155610139805491820181559091527f22d66071756d4d57920b8322c1a903a27bd75b44065e925d5f9f1c08908d28f60180546001600160a01b0319169091179055565b60008282825b60808110156131e057818310156131e057600060026131198486614268565b613124906002614268565b61312e9190614294565b61012d546040516328d09d4760e01b81526001600160a01b038c8116600483015260248201849052929350600092909116906328d09d4790604401608060405180830381865afa158015613186573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131aa9190614135565b9050888160400151116131bf578194506131cd565b6131ca60018361423e565b93505b5050806131d990614105565b90506130fa565b50909695505050505050565b6000610a1d6131fe62093a7f84614268565b612bb9565b60008183116132125781610bea565b5090919050565b60008060009050600061012d60009054906101000a90046001600160a01b03166001600160a01b031663900cf0cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613276573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061329a919061427b565b905060005b608081101561337f578183101561337f57600060026132be8486614268565b6132c9906002614268565b6132d39190614294565b61012d5460405163d1febfb960e01b8152600481018390529192506000916001600160a01b039091169063d1febfb990602401608060405180830381865afa158015613323573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133479190614135565b90508681604001511161335c5781945061336a565b61336760018361423e565b93505b5050808061337790614105565b91505061329f565b50909392505050565b6000610bea828461423e565b60008183106132125781610bea565b61012d5460405163095ea7b360e01b81526001600160a01b039182166004820152602481018390529083169063095ea7b3906044016020604051808303816000875af11580156133f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341b91906143eb565b5061012d5460405163978919c560e01b81526001600160a01b0385811660048301526024820184905284811660448301523060648301529091169063978919c590608401600060405180830381600087803b15801561347957600080fd5b505af115801561348d573d6000803e3d6000fd5b505061012d54604051636eb1769f60e11b81523060048201526001600160a01b03918216602482015260009350908516915063dd62ed3e90604401602060405180830381865afa1580156134e5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613509919061427b565b9050801561152257611522614408565b6135238282611802565b610d385761353081613800565b61353b836020613812565b60405160200161354c92919061441e565b60408051601f198184030181529082905262461bcd60e51b82526102af91600401614493565b60006135c7826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166139ad9092919063ffffffff16565b90508051600014806135e85750808060200190518101906135e891906143eb565b610ceb5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016102af565b600054610100900460ff166122155760405162461bcd60e51b81526004016102af90614360565b6000613678612a33565b6001600160a01b03161461369f5760405163bbd9617760e01b815260040160405180910390fd5b6001600160a01b0381166136c65760405163110626eb60e01b815260040160405180910390fd5b806000805160206144fe83398151915280546001600160a01b0319166001600160a01b039283161790556040516393ae190760e01b815260016004820152908216906393ae190790602401600060405180830381600087803b15801561372b57600080fd5b505af1158015610fd7573d6000803e3d6000fd5b6001600160a01b0381163b6137ac5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b60648201526084016102af565b6000805160206144de83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6137e4836139bc565b6000825111806137f15750805b15610ceb5761152283836139fc565b6060610a1d6001600160a01b03831660145b60606000613821836002614251565b61382c906002614268565b6001600160401b0381111561384357613843613e41565b6040519080825280601f01601f19166020018201604052801561386d576020820181803683370190505b509050600360fc1b81600081518110613888576138886140d9565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106138b7576138b76140d9565b60200101906001600160f81b031916908160001a90535060006138db846002614251565b6138e6906001614268565b90505b600181111561395e576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061391a5761391a6140d9565b1a60f81b828281518110613930576139306140d9565b60200101906001600160f81b031916908160001a90535060049490941c93613957816144c6565b90506138e9565b508315610bea5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016102af565b6060612e708484600085613a21565b6139c58161373f565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060610bea838360405180606001604052806027815260200161451e60279139613afc565b606082471015613a825760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016102af565b600080866001600160a01b03168587604051613a9e91906143cf565b60006040518083038185875af1925050503d8060008114613adb576040519150601f19603f3d011682016040523d82523d6000602084013e613ae0565b606091505b5091509150613af187838387613b66565b979650505050505050565b6060600080856001600160a01b031685604051613b1991906143cf565b600060405180830381855af49150503d8060008114613b54576040519150601f19603f3d011682016040523d82523d6000602084013e613b59565b606091505b509150915061305f868383875b60608315613bd5578251600003613bce576001600160a01b0385163b613bce5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016102af565b5081612e70565b612e708383815115613bea5781518083602001fd5b8060405162461bcd60e51b81526004016102af9190614493565b600060208284031215613c1657600080fd5b81356001600160e01b031981168114610bea57600080fd5b6001600160a01b0381168114610a3e57600080fd5b600060208284031215613c5557600080fd5b8135610bea81613c2e565b60008083601f840112613c7257600080fd5b5081356001600160401b03811115613c8957600080fd5b6020830191508360208260051b8501011115613ca457600080fd5b9250929050565b600080600060408486031215613cc057600080fd5b8335613ccb81613c2e565b925060208401356001600160401b03811115613ce657600080fd5b613cf286828701613c60565b9497909650939450505050565b6020808252825182820181905260009190848201906040850190845b818110156131e057835183529284019291840191600101613d1b565b600060208284031215613d4957600080fd5b5035919050565b60008060408385031215613d6357600080fd5b823591506020830135613d7581613c2e565b809150509250929050565b60008060408385031215613d9357600080fd5b8235613d9e81613c2e565b946020939093013593505050565b60008060008060808587031215613dc257600080fd5b8435613dcd81613c2e565b9350602085013592506040850135613de481613c2e565b91506060850135613df481613c2e565b939692955090935050565b600080600060608486031215613e1457600080fd5b8335613e1f81613c2e565b9250602084013591506040840135613e3681613c2e565b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613e7f57613e7f613e41565b604052919050565b60008060408385031215613e9a57600080fd5b8235613ea581613c2e565b91506020838101356001600160401b0380821115613ec257600080fd5b818601915086601f830112613ed657600080fd5b813581811115613ee857613ee8613e41565b613efa601f8201601f19168501613e57565b91508082528784828501011115613f1057600080fd5b80848401858401376000848284010152508093505050509250929050565b60008060008060408587031215613f4457600080fd5b84356001600160401b0380821115613f5b57600080fd5b613f6788838901613c60565b90965094506020870135915080821115613f8057600080fd5b50613f8d87828801613c60565b95989497509550505050565b60008060408385031215613fac57600080fd5b8235613fb781613c2e565b91506020830135613d7581613c2e565b60008060208385031215613fda57600080fd5b82356001600160401b03811115613ff057600080fd5b613ffc85828601613c60565b90969095509350505050565b8015158114610a3e57600080fd5b60006020828403121561402857600080fd5b8135610bea81614008565b6020808252825182820181905260009190848201906040850190845b818110156131e05783516001600160a01b03168352928401929184019160010161404f565b6000806040838503121561408757600080fd5b823561409281613c2e565b91506020830135613d7581614008565b60208082526017908201527f436c61696d696e67206973206e6f7420616c6c6f776564000000000000000000604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201614117576141176140ef565b5060010190565b8051600f81900b811461413057600080fd5b919050565b60006080828403121561414757600080fd5b604051608081018181106001600160401b038211171561416957614169613e41565b6040526141758361411e565b81526141836020840161411e565b602082015260408301516040820152606083015160608201528091505092915050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b81810381811115610a1d57610a1d6140ef565b8082028115828204841417610a1d57610a1d6140ef565b80820180821115610a1d57610a1d6140ef565b60006020828403121561428d57600080fd5b5051919050565b6000826142b157634e487b7160e01b600052601260045260246000fd5b500490565b60208082526024908201527f46656520646973747269627574696f6e20686173206e6f742073746172746564604082015263081e595d60e21b606082015260800190565b600082600f0b82600f0b0280600f0b915080821461431a5761431a6140ef565b5092915050565b600f82810b9082900b036f7fffffffffffffffffffffffffffffff1981126f7fffffffffffffffffffffffffffffff82131715610a1d57610a1d6140ef565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60005b838110156143c65781810151838201526020016143ae565b50506000910152565b600082516143e18184602087016143ab565b9190910192915050565b6000602082840312156143fd57600080fd5b8151610bea81614008565b634e487b7160e01b600052600160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516144568160178501602088016143ab565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516144878160288401602088016143ab565b01602801949350505050565b60208152600082518060208401526144b28160408501602087016143ab565b601f01601f19169190910160400192915050565b6000816144d5576144d56140ef565b50600019019056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8e7ec97a86b55b46cf58cbcd08faba09d3e8d3aec4d6bf8802477f1aa7a4c700416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212206bae59dc80756441cc46e6965dea4c0f2a357b2b1a7935f8b889dba2eea9a4d764736f6c63430008130033