ETH Price: $2,934.85 (-0.74%)

Contract

0x2D1c0FcE3D1DE5f71eAB9A30223ad68bfB94664A

Overview

ETH Balance

Linea Mainnet LogoLinea Mainnet LogoLinea Mainnet Logo0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

> 10 Internal Transactions found.

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
274484072026-01-05 10:01:0619 days ago1767607266
0x2D1c0FcE...bfB94664A
0 ETH
274484072026-01-05 10:01:0619 days ago1767607266
0x2D1c0FcE...bfB94664A
0 ETH
274484072026-01-05 10:01:0619 days ago1767607266
0x2D1c0FcE...bfB94664A
0 ETH
274483962026-01-05 10:00:4419 days ago1767607244
0x2D1c0FcE...bfB94664A
0 ETH
274483962026-01-05 10:00:4419 days ago1767607244
0x2D1c0FcE...bfB94664A
0 ETH
274483962026-01-05 10:00:4419 days ago1767607244
0x2D1c0FcE...bfB94664A
0 ETH
272835352026-01-01 0:16:1224 days ago1767226572
0x2D1c0FcE...bfB94664A
0 ETH
272835332026-01-01 0:16:0824 days ago1767226568
0x2D1c0FcE...bfB94664A
0 ETH
272835312026-01-01 0:16:0424 days ago1767226564
0x2D1c0FcE...bfB94664A
0 ETH
272835282026-01-01 0:15:5824 days ago1767226558
0x2D1c0FcE...bfB94664A
0 ETH
272835262026-01-01 0:15:5424 days ago1767226554
0x2D1c0FcE...bfB94664A
0 ETH
272835242026-01-01 0:15:5024 days ago1767226550
0x2D1c0FcE...bfB94664A
0 ETH
272835202026-01-01 0:15:4224 days ago1767226542
0x2D1c0FcE...bfB94664A
0 ETH
272835172026-01-01 0:15:3624 days ago1767226536
0x2D1c0FcE...bfB94664A
0 ETH
272835142026-01-01 0:15:3024 days ago1767226530
0x2D1c0FcE...bfB94664A
0 ETH
272835122026-01-01 0:15:2624 days ago1767226526
0x2D1c0FcE...bfB94664A
0 ETH
272835092026-01-01 0:15:2024 days ago1767226520
0x2D1c0FcE...bfB94664A
0 ETH
272835052026-01-01 0:15:1224 days ago1767226512
0x2D1c0FcE...bfB94664A
0 ETH
272835032026-01-01 0:15:0824 days ago1767226508
0x2D1c0FcE...bfB94664A
0 ETH
272835002026-01-01 0:15:0224 days ago1767226502
0x2D1c0FcE...bfB94664A
0 ETH
272827492025-12-31 23:45:0624 days ago1767224706
0x2D1c0FcE...bfB94664A
0 ETH
272827482025-12-31 23:45:0224 days ago1767224702
0x2D1c0FcE...bfB94664A
0 ETH
272663772025-12-31 12:45:0624 days ago1767185106
0x2D1c0FcE...bfB94664A
0 ETH
272663762025-12-31 12:45:0224 days ago1767185102
0x2D1c0FcE...bfB94664A
0 ETH
270480932025-12-25 0:15:3031 days ago1766621730
0x2D1c0FcE...bfB94664A
0 ETH
View All Internal Transactions
Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
VotingEscrowManager

Compiler Version
v0.8.13+commit.abaa5c0e

Optimization Enabled:
Yes with 10 runs

Other Settings:
default evmVersion
File 1 of 53 : VotingEscrowManager.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import "./interfaces/IVotingEscrowV2.sol";
import "./interfaces/IVoterV5/IVoterV5.sol";
import "./interfaces/IRewardsDistributor.sol";
import "./interfaces/IMinter.sol";
import "./interfaces/IBribe.sol";
import "./libraries/VeHelper.sol";
import "./libraries/CallLib.sol";
import "./access/VeAccessControlUpgradeable.sol";
import "./interfaces/IVotingEscrowVault.sol";
import "./interfaces/IBribeOptionTokenV2.sol";

/**
 * @title VotingEscrowManager
 * @notice Manages VE NFTs and automation for VotingEscrowVault
 * @dev Handles all VE operations: merging, splitting, voting, reward claiming
 */
contract VotingEscrowManager is VeAccessControlUpgradeable, IERC721ReceiverUpgradeable {
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using VeHelper for IVotingEscrowV2;

    /// -----------------------------------------------------------------------
    /// Structs
    /// -----------------------------------------------------------------------

    struct VoteRecord {
        uint256 epoch;
        address[] pools;
        uint256[] weights;
        uint256 timestamp;
    }

    /// -----------------------------------------------------------------------
    /// State Variables
    /// -----------------------------------------------------------------------

    /// @notice VE token contract interface
    IVotingEscrowV2 public veToken;

    /// @notice Voter contract address
    address public voter;

    /// @notice Rewards distributor for rebase claims
    address public rewardsDistributor;

    /// @notice Main VE token ID owned by this contract
    uint256 public veTokenId;

    /// @notice Address of the vault that can call deposit/withdraw functions
    address public vault;

    /// @notice Mapping of trusted call targets
    mapping(address => bool) public trustedCallTargets;

    /// @notice Fee in basis points (out of 10_000) applied to reward notifications
    uint256 public feeBps;

    /// @notice Address receiving the fee portion of rewards
    address public feeRecipient;

    /// @notice Mapping of vote records by epoch
    mapping(uint256 => VoteRecord) public voteRecords;

    /// @notice Last vote epoch
    uint256 public lastVoteEpoch;

    /// @notice Optional BribeOptionTokenV2 contract address
    address public bveToken;

    /// @dev Gap for future storage variables
    uint256[50] private __gap;

    /// -----------------------------------------------------------------------
    /// Events
    /// -----------------------------------------------------------------------

    event VoteExecuted(uint256 indexed epoch, address[] pools, uint256[] weights);
    event BribesClaimed(address[] bribes);
    event FeesClaimed(address[] fees);
    event RebaseClaimed(uint256 amount);
    event CallExecuted(address indexed target, bytes data, bytes result);
    event VeNftDeposited(uint256 indexed veTokenId, uint256 lockedAmount);
    event VeNftWithdrawn(uint256 indexed newTokenId, uint256 amount, address indexed receiver);
    event VeNftMerged(uint256 indexed fromTokenId, uint256 indexed toTokenId);
    event VaultUpdated(address indexed oldVault, address indexed newVault);
    event TrustedCallTargetUpdated(address indexed target, bool indexed trusted);
    event RewardNotified(uint256 delta);
    event RewardsClaimed(uint256 indexed epoch, uint256 indexed veTokenId);
    event RewardsClaimedForRange(uint256 indexed epoch, uint256 indexed startIndex, uint256 endIndex);
    event SweepWithdrawToken(address indexed to, IERC20 indexed token, uint256 amount);
    event SweepWithdrawNft(address indexed to, address indexed nft, uint256 indexed veTokenId);
    event FeeParametersUpdated(uint256 feeBps, address indexed feeRecipient);
    event BveTokenExercised(uint256 indexed amount, uint256 indexed newTokenId, uint256 indexed mergedTokenId);
    event BveTokenUpdated(address indexed oldBveToken, address indexed newBveToken);

    /// -----------------------------------------------------------------------
    /// Errors
    /// -----------------------------------------------------------------------

    error Unauthorized();
    error InvalidArrayLength();
    error InvalidTokenId();
    error CallFailed();
    error ZeroAddress();
    error ZeroAmount();
    error OnlyVault();
    error InvalidTarget();
    error InvalidFee();
    error VoteRecordNotFound();
    error BveTokenNotSet();
    error AmountMismatch();
    error ArrayLengthMismatch();
    error InsufficientTokenBalance();
    error InvalidRange();

    /// -----------------------------------------------------------------------
    /// Modifiers
    /// -----------------------------------------------------------------------

    modifier onlyVault() {
        if (msg.sender != vault) revert OnlyVault();
        _;
    }

    /// -----------------------------------------------------------------------
    /// Constructor
    /// -----------------------------------------------------------------------

    constructor() {
        _disableInitializers();
    }

    function initialize(
        address _veToken,
        address _voter,
        address _rewardsDistributor,
        address _bveToken,
        address _admin,
        address _automationAddress,
        address[] memory _operators
    ) external initializer {
        __VeAccessControlUpgradeable_init(_admin, _automationAddress, _operators);

        if (_veToken == address(0) || _voter == address(0) || _rewardsDistributor == address(0)) {
            revert ZeroAddress();
        }

        veToken = IVotingEscrowV2(_veToken);
        voter = _voter;
        rewardsDistributor = _rewardsDistributor;
        bveToken = _bveToken;
        feeBps = 0;
        feeRecipient = owner();
    }

    /// -----------------------------------------------------------------------
    /// Vault Interface Functions
    /// -----------------------------------------------------------------------

    /**
     * @notice Deposit VE NFT from vault
     * @param _veTokenId VE NFT token ID to manage
     * @param _expectedAmount Expected locked amount for validation
     */
    function depositNft(uint256 _veTokenId, uint256 _expectedAmount) external onlyVault {
        // Validate the NFT
        IVotingEscrowV2.LockDetails memory lockDetails = veToken.lockDetails(_veTokenId);
        if (lockDetails.amount != _expectedAmount) revert AmountMismatch();

        // Merge VE NFT into main position
        if (!lockDetails.isPermanent) {
            veToken.lockPermanent(_veTokenId);
        }
        if (veTokenId == 0) {
            veTokenId = _veTokenId;
        } else {
            veToken.merge(_veTokenId, veTokenId);
            emit VeNftMerged(_veTokenId, veTokenId);
        }

        emit VeNftDeposited(veTokenId, _expectedAmount);
    }

    /**
     * @notice Withdraw VE NFT for vault
     * @param amount Amount of underlying tokens to withdraw
     * @param receiver Address to receive the new VE NFT
     * @return newTokenId ID of the newly created VE NFT
     */
    function withdrawNft(uint256 amount, address receiver) external onlyVault returns (uint256 newTokenId) {
        if (veTokenId == 0) revert InvalidTokenId();
        if (amount == 0) revert ZeroAmount();

        // Split VE NFT and send to receiver
        newTokenId = veToken.splitAndSend(veTokenId, amount, receiver);

        emit VeNftWithdrawn(newTokenId, amount, receiver);

        return newTokenId;
    }

    /// -----------------------------------------------------------------------
    /// Automation Functions
    /// -----------------------------------------------------------------------

    /**
     * @notice Vote for pools with specified weights
     */
    function vote(address[] calldata pools, uint256[] calldata weights) external onlyOwnerOrRole(OPERATIONS_ROLE) {
        if (veTokenId == 0) revert InvalidTokenId();
        if (pools.length != weights.length) {
            revert InvalidArrayLength();
        }
        uint256 epoch = IMinter(IVoterV5(voter).minter()).active_period();
        IVoterV5(voter).vote(pools, weights);
        IVotingEscrowVault(vault).disableRedeem();
        lastVoteEpoch = epoch;
        voteRecords[epoch] = VoteRecord({epoch: epoch, pools: pools, weights: weights, timestamp: block.timestamp});
        emit VoteExecuted(epoch, pools, weights);
    }

    function claimRebase() external onlyOwnerOrRole(OPERATIONS_ROLE) {
        if (veTokenId == 0) revert InvalidTokenId();

        uint256 rebaseAmount = IRewardsDistributor(rewardsDistributor).claim(veTokenId);
        IVotingEscrowVault(vault).enableRedeem();

        emit RebaseClaimed(rebaseAmount);
    }

    function claimBribes(
        address[] calldata bribes,
        address[][] calldata tokens
    ) external onlyOwnerOrRole(OPERATIONS_ROLE) {
        if (veTokenId == 0) revert InvalidTokenId();
        IVoterV5(voter).claimBribes(bribes, tokens, veTokenId);
        emit BribesClaimed(bribes);
    }

    function claimRewardsForEpoch(uint256 epoch) external onlyOwnerOrRole(OPERATIONS_ROLE) {
        VoteRecord memory r = voteRecords[epoch];
        if (r.epoch == 0) revert VoteRecordNotFound();
        _claimRewardsForPools(r.pools);
        emit RewardsClaimed(epoch, veTokenId);
    }

    /**
     * @notice Claim rewards for a specific range of pools from a vote record
     * @param epoch Epoch to claim rewards for
     * @param startIndex Start index of the pools array
     * @param endIndex End index of the pools array
     */
    function claimRewardsForEpochByRange(
        uint256 epoch,
        uint256 startIndex,
        uint256 endIndex
    ) external onlyOwnerOrRole(OPERATIONS_ROLE) {
        VoteRecord memory r = voteRecords[epoch];
        if (r.epoch == 0) revert VoteRecordNotFound();
        if (startIndex > endIndex || endIndex >= r.pools.length) revert InvalidRange();

        uint256 rangeSize = endIndex - startIndex + 1;
        address[] memory poolsSlice = new address[](rangeSize);
        for (uint256 i = 0; i < rangeSize; i++) {
            poolsSlice[i] = r.pools[startIndex + i];
        }

        _claimRewardsForPools(poolsSlice);
        emit RewardsClaimedForRange(epoch, startIndex, endIndex);
    }

    /**
     * @notice Execute custom swaps via call to whitelisted router
     * @param target Router target (must be whitelisted)
     * @param data Array of encoded call payloads to the router
     * @param tokens Tokens to approve to the router
     * @param amounts Required amounts for allowance checks (approve max if insufficient)
     * @return results Return data from each call
     */
    function executeCustomSwaps(
        address target,
        bytes[] calldata data,
        address[] calldata tokens,
        uint256[] calldata amounts
    ) public onlyOwnerOrRole(OPERATIONS_ROLE) returns (bytes[] memory results) {
        if (!trustedCallTargets[target]) revert Unauthorized();
        if (tokens.length != amounts.length) revert InvalidArrayLength();

        // Ensure approvals to target
        for (uint256 i = 0; i < tokens.length; i++) {
            IERC20Upgradeable token = IERC20Upgradeable(tokens[i]);
            uint256 current = token.allowance(address(this), target);
            if (current < amounts[i]) {
                token.safeApprove(target, 0);
                token.safeApprove(target, amounts[i]);
            }
        }

        // Execute call swaps
        results = new bytes[](data.length);
        for (uint256 j = 0; j < data.length; j++) {
            results[j] = _executeCallWhitelist(target, data[j]);
        }

        return results;
    }

    /**
     * @notice Notify rewards to vault from current balance
     * @return rewardAmount Amount of rewards notified to vault
     */
    function notifyRewardsToVault() public onlyOwnerOrRole(OPERATIONS_ROLE) returns (uint256 rewardAmount) {
        address rewardTokenAddr = IVotingEscrowVault(vault).rewardOutputToken();
        rewardAmount = IERC20Upgradeable(rewardTokenAddr).balanceOf(address(this));

        if (rewardAmount > 0) {
            uint256 fee = (rewardAmount * feeBps) / 10_000;
            uint256 net = rewardAmount - fee;

            if (fee > 0) {
                IERC20Upgradeable(rewardTokenAddr).safeTransfer(feeRecipient, fee);
            }

            if (net > 0) {
                IERC20Upgradeable(rewardTokenAddr).safeTransfer(vault, net);
                IVotingEscrowVault(vault).notifyReward(net);
            }

            emit RewardNotified(rewardAmount);
        }

        return rewardAmount;
    }

    /**
     * @notice Execute all post-epoch operations in sequence
     * @param swapTarget Router target for custom swaps (can be address(0) to skip)
     * @param swapData Array of encoded call payloads to the router
     * @param swapTokens Tokens to approve to the router
     * @param swapAmounts Required amounts for allowance checks
     * @return swapResults Return data from swap operations (empty if no swaps)
     */
    function executeSwapsAndNotifyRewards(
        address swapTarget,
        bytes[] calldata swapData,
        address[] calldata swapTokens,
        uint256[] calldata swapAmounts
    ) external onlyOwnerOrRole(OPERATIONS_ROLE) returns (bytes[] memory swapResults) {
        if (swapData.length > 0 && swapTarget != address(0)) {
            swapResults = executeCustomSwaps(swapTarget, swapData, swapTokens, swapAmounts);
        }

        notifyRewardsToVault();
    }

    /**
     * @notice Exercise BribeOptionTokenV2 and merge resulting VE NFT with main position
     * @param amount Amount of bveToken to exercise
     * @return newTokenId ID of the newly created VE NFT from exercise
     */
    function exerciseBveToken(uint256 amount) external onlyOwnerOrRole(OPERATIONS_ROLE) returns (uint256 newTokenId) {
        if (bveToken == address(0)) revert BveTokenNotSet();
        if (amount == 0) revert ZeroAmount();
        if (veTokenId == 0) revert InvalidTokenId();

        // Exercise the bveToken to get a new VE NFT
        try IBribeOptionTokenV2(bveToken).exerciseVe(amount, address(this)) returns (uint256 newId) {
            newTokenId = newId;
        } catch {
            // Fallback to the other exerciseVe function if the first one fails
            newTokenId = IBribeOptionTokenV2(bveToken).exerciseVe(amount, amount, address(this), block.timestamp);
        }

        // Merge the new VE NFT with the main position
        IVotingEscrowV2.LockDetails memory lockDetails = veToken.lockDetails(newTokenId);
        if (!lockDetails.isPermanent) {
            veToken.lockPermanent(newTokenId);
        }
        veToken.merge(newTokenId, veTokenId);
        emit VeNftMerged(newTokenId, veTokenId);
        emit BveTokenExercised(amount, newTokenId, veTokenId);

        return newTokenId;
    }

    /// -----------------------------------------------------------------------
    /// Delegate Call Functions
    /// -----------------------------------------------------------------------

    function executeCall(address target, bytes calldata data) external onlyOwner returns (bytes memory result) {
        result = _executeCallWhitelist(target, data);
        return result;
    }

    function executeCallMulti(
        address[] calldata targets,
        bytes[] calldata data
    ) external onlyOwner returns (bytes[] memory results) {
        if (targets.length != data.length) revert InvalidArrayLength();
        results = new bytes[](targets.length);
        for (uint256 i = 0; i < targets.length; i++) {
            results[i] = _executeCallWhitelist(targets[i], data[i]);
        }
        return results;
    }

    /// -----------------------------------------------------------------------
    /// Admin Functions
    /// -----------------------------------------------------------------------

    /**
     * @notice Update vault address
     * @param _newVault New vault address
     */
    function setVault(address _newVault) external onlyOwner {
        if (_newVault == address(0)) revert ZeroAddress();

        address oldVault = vault;
        vault = _newVault;

        emit VaultUpdated(oldVault, _newVault);
    }

    /**
     * @notice Set trusted call target status
     * @param target Target contract address
     * @param trusted Whether the target should be trusted
     */
    function setTrustedCallTarget(address target, bool trusted) external onlyOwner {
        trustedCallTargets[target] = trusted;
        emit TrustedCallTargetUpdated(target, trusted);
    }

    /**
     * @notice Set fee in basis points (out of 10_000)
     * @param _feeBps New fee basis points
     */
    function setFeeBps(uint256 _feeBps) external onlyOwner {
        if (_feeBps > 5000) revert InvalidFee();
        feeBps = _feeBps;
        emit FeeParametersUpdated(feeBps, feeRecipient);
    }

    /**
     * @notice Set fee recipient address
     * @param _feeRecipient New fee recipient (cannot be zero)
     */
    function setFeeRecipient(address _feeRecipient) external onlyOwner {
        if (_feeRecipient == address(0)) revert ZeroAddress();
        feeRecipient = _feeRecipient;
        emit FeeParametersUpdated(feeBps, feeRecipient);
    }

    /**
     * @notice Set BribeOptionTokenV2 contract address
     * @param _bveToken New bveToken address (can be zero to disable)
     */
    function setBveToken(address _bveToken) external onlyOwner {
        address oldBveToken = bveToken;
        bveToken = _bveToken;
        emit BveTokenUpdated(oldBveToken, _bveToken);
    }

    /// -----------------------------------------------------------------------
    /// Internal Implementation Functions
    /// -----------------------------------------------------------------------

    function _claimRewardsForPools(address[] memory _pools) internal {
        (
            address[] memory externalBribes,
            address[] memory internalBribes,
            address[][] memory externalTokens,
            address[][] memory internalTokens
        ) = _buildBribeDataForPools(_pools);

        uint256 managedTokenId = veTokenId;
        IVoterV5(voter).claimBribes(externalBribes, externalTokens, managedTokenId);
        IVoterV5(voter).claimFees(internalBribes, internalTokens, managedTokenId);
    }

    /**
     * @notice Build bribe arrays and token arrays from vote record
     * @param _pools Array of pools to process
     * @return externalBribes Array of external bribe addresses
     * @return internalBribes Array of internal bribe addresses
     * @return externalTokens Array of token arrays for external bribes
     * @return internalTokens Array of token arrays for internal bribes
     */
    function _buildBribeDataForPools(
        address[] memory _pools
    )
        internal
        view
        returns (
            address[] memory externalBribes,
            address[] memory internalBribes,
            address[][] memory externalTokens,
            address[][] memory internalTokens
        )
    {
        // Build bribe arrays from pools
        externalBribes = new address[](_pools.length);
        internalBribes = new address[](_pools.length);

        for (uint256 i = 0; i < _pools.length; i++) {
            address gauge = IVoterV5(voter).gauges(_pools[i]);
            internalBribes[i] = IVoterV5(voter).internal_bribes(gauge);
            externalBribes[i] = IVoterV5(voter).external_bribes(gauge);
        }

        // External bribes tokens enumeration
        externalTokens = new address[][](externalBribes.length);
        for (uint256 bi = 0; bi < externalBribes.length; bi++) {
            address br = externalBribes[bi];
            if (br == address(0)) {
                externalTokens[bi] = new address[](0);
                continue;
            }
            uint256 numRewards = IBribe(br).rewardsListLength();
            address[] memory tokens = new address[](numRewards);
            for (uint256 ri = 0; ri < numRewards; ri++) {
                tokens[ri] = IBribe(br).rewardTokens(ri);
            }
            externalTokens[bi] = tokens;
        }

        // Internal fees tokens enumeration
        internalTokens = new address[][](internalBribes.length);
        for (uint256 bj = 0; bj < internalBribes.length; bj++) {
            address br2 = internalBribes[bj];
            if (br2 == address(0)) {
                internalTokens[bj] = new address[](0);
                continue;
            }
            uint256 numRewards2 = IBribe(br2).rewardsListLength();
            address[] memory tokens2 = new address[](numRewards2);
            for (uint256 rj = 0; rj < numRewards2; rj++) {
                tokens2[rj] = IBribe(br2).rewardTokens(rj);
            }
            internalTokens[bj] = tokens2;
        }
    }

    /**
     * @notice Get all unique token addresses from bribes and fees for a vote record
     * @param _pools Array of pools to get tokens for
     * @return tokens Array of unique token addresses
     */
    function _getVoteTokensForPools(address[] memory _pools) internal view returns (address[] memory tokens) {
        (
            ,
            ,
            // externalBribes - unused
            // internalBribes - unused
            address[][] memory externalTokens,
            address[][] memory internalTokens
        ) = _buildBribeDataForPools(_pools);

        // Collect all tokens first (with potential duplicates)
        address[] memory tempTokens = new address[](1000); // Max 1000 tokens
        uint256 tokenCount = 0;

        // Collect external bribe tokens
        for (uint256 bi = 0; bi < externalTokens.length; bi++) {
            for (uint256 ri = 0; ri < externalTokens[bi].length; ri++) {
                tempTokens[tokenCount] = externalTokens[bi][ri];
                tokenCount++;
            }
        }

        // Collect internal fee tokens
        for (uint256 bj = 0; bj < internalTokens.length; bj++) {
            for (uint256 rj = 0; rj < internalTokens[bj].length; rj++) {
                tempTokens[tokenCount] = internalTokens[bj][rj];
                tokenCount++;
            }
        }

        // Deduplicate using nested loops
        address[] memory uniqueTokens = new address[](tokenCount);
        uint256 uniqueCount = 0;

        for (uint256 i = 0; i < tokenCount; i++) {
            address token = tempTokens[i];
            bool exists = false;

            // Check if token already exists in uniqueTokens
            for (uint256 j = 0; j < uniqueCount; j++) {
                if (uniqueTokens[j] == token) {
                    exists = true;
                    break;
                }
            }

            if (!exists) {
                uniqueTokens[uniqueCount] = token;
                uniqueCount++;
            }
        }

        // Create final array with exact size
        tokens = new address[](uniqueCount);
        for (uint256 i = 0; i < uniqueCount; i++) {
            tokens[i] = uniqueTokens[i];
        }
    }

    /**
     * @notice Execute arbitrary delegate call for maximum flexibility
     * @param target Target contract address
     * @param data Encoded function call data
     * @return result Return data from the delegate call
     */
    function _executeCallWhitelist(address target, bytes calldata data) internal returns (bytes memory result) {
        if (!trustedCallTargets[target]) revert Unauthorized();
        if (target == address(0)) revert InvalidTarget();
        (bool success, bytes memory returnData) = target.call(data);
        result = CallLib.handleCallResult(success, returnData);
        emit CallExecuted(target, data, result);
        return result;
    }

    /// -----------------------------------------------------------------------
    /// View Functions
    /// -----------------------------------------------------------------------

    /**
     * @notice Get VE voting power
     */
    function getVeVotingPower() external view returns (uint256) {
        uint256 epoch = IMinter(IVoterV5(voter).minter()).active_period();
        return veToken.getVotingPower(veTokenId, epoch);
    }

    /**
     * @notice Get VE lock details
     */
    function getVeLockDetails() external view returns (IVotingEscrowV2.LockDetails memory) {
        return veToken.getLockDetails(veTokenId);
    }

    /**
     * @notice Get total locked amount
     */
    function getTotalLockedAmount() external view returns (uint256) {
        return veToken.getLockDetails(veTokenId).amount;
    }

    /**
     * @notice Get claimable rebase amount
     */
    function getClaimableRebase() external view returns (uint256) {
        if (veTokenId == 0 || rewardsDistributor == address(0)) return 0;
        return IRewardsDistributor(rewardsDistributor).claimable(veTokenId);
    }

    /**
     * @notice Return the current epoch from the voter minter
     */
    function getCurrentEpoch() public view returns (uint256) {
        return IMinter(IVoterV5(voter).minter()).active_period();
    }

    /**
     * @notice Fetch a stored vote record for an epoch
     */
    function getVoteRecord(uint256 epoch) external view returns (VoteRecord memory) {
        return voteRecords[epoch];
    }

    /**
     * @notice Get the number of pools voted for in a specific epoch
     * @param epoch Epoch to get pool count for
     * @return uint256 Number of pools
     */
    function getVotePoolCount(uint256 epoch) external view returns (uint256) {
        VoteRecord memory r = voteRecords[epoch];
        if (r.epoch == 0) revert VoteRecordNotFound();
        return r.pools.length;
    }

    /**
     * @notice Return the last epoch this manager voted for
     */
    function getLastVoteEpoch() external view returns (uint256) {
        return lastVoteEpoch;
    }

    /**
     * @notice Get all unique token addresses from bribes and fees for a specific vote record
     * @param epoch Epoch to get tokens for
     * @return tokens Flat array of unique token addresses
     */
    function getVoteTokens(uint256 epoch) external view returns (address[] memory tokens) {
        VoteRecord memory r = voteRecords[epoch];
        if (r.epoch == 0) revert VoteRecordNotFound();
        return _getVoteTokensForPools(r.pools);
    }

    /**
     * @notice Get vote tokens with their current balances in this contract
     * @param epoch Epoch to get tokens for
     * @return tokens Array of token addresses
     * @return balances Array of current token balances in this contract
     */
    function getVoteTokensWithBalances(
        uint256 epoch
    ) external view returns (address[] memory tokens, uint256[] memory balances) {
        VoteRecord memory r = voteRecords[epoch];
        if (r.epoch == 0) revert VoteRecordNotFound();

        tokens = _getVoteTokensForPools(r.pools);
        balances = new uint256[](tokens.length);

        for (uint256 i = 0; i < tokens.length; i++) {
            balances[i] = IERC20Upgradeable(tokens[i]).balanceOf(address(this));
        }
    }

    /**
     * @notice Get current bveToken balance in this contract
     * @return balance Current balance of bveToken
     */
    function getBveTokenBalance() external view returns (uint256 balance) {
        if (bveToken == address(0)) return 0;
        return IERC20Upgradeable(bveToken).balanceOf(address(this));
    }

    /// -----------------------------------------------------------------------
    /// ERC721 Receiver
    /// -----------------------------------------------------------------------

    function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4) {
        return IERC721ReceiverUpgradeable.onERC721Received.selector;
    }

    /// -----------------------------------------------------------------------
    /// Recovery Functions (Owner-only)
    /// -----------------------------------------------------------------------

    function sweepTokens(IERC20[] memory tokens, uint256[] memory amounts, address to) public onlyOwner {
        if (tokens.length != amounts.length) revert ArrayLengthMismatch();
        for (uint256 i = 0; i < tokens.length; i++) {
            IERC20 token = tokens[i];
            uint256 amount = amounts[i];
            uint256 balance = token.balanceOf(address(this));
            if (balance < amount) revert InsufficientTokenBalance();
            token.transfer(to, amount);
            emit SweepWithdrawToken(to, token, amount);
        }
    }

    function sweepNfts(address[] calldata nfts, uint256[] calldata tokenIds, address to) external onlyOwner {
        if (nfts.length != tokenIds.length) revert ArrayLengthMismatch();
        for (uint256 i = 0; i < nfts.length; i++) {
            address nft = nfts[i];
            uint256 nftTokenId = tokenIds[i];
            IERC721Upgradeable(nft).safeTransferFrom(address(this), to, nftTokenId);
            emit SweepWithdrawNft(to, nft, nftTokenId);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerableUpgradeable.sol";
import "./AccessControlUpgradeable.sol";
import "../utils/structs/EnumerableSetUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable {
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;

    mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers;

    function __AccessControlEnumerable_init() internal onlyInitializing {
    }

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

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }

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

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

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

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

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

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC721Upgradeable.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721EnumerableUpgradeable is IERC721Upgradeable {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSetUpgradeable {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

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

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

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

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

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

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

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

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

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

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

// 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 IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

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

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

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

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

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

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

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

File 23 of 53 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol)

pragma solidity ^0.8.0;

import "../utils/introspection/IERC165.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 IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * 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);
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/**
 * @title VeAccessControlUpgradeable
 * @notice Access control contract for VE vault system based on ApeBond pattern
 * @dev Manages ownership and role-based access for VE vault contracts
 */
contract VeAccessControlUpgradeable is OwnableUpgradeable, AccessControlEnumerableUpgradeable {
    /* ======== STATE ======== */

    /// @notice Operations role, used to adjust specific settings on the vault
    bytes32 public constant OPERATIONS_ROLE = keccak256("OPERATIONS_ROLE");

    /// @notice Automation role, used to manage automation and strategy execution
    bytes32 public constant AUTOMATION_ROLE = keccak256("AUTOMATION_ROLE");

    /// @notice Voting role, used for governance voting operations
    bytes32 public constant VOTING_ROLE = keccak256("VOTING_ROLE");

    /* ======== INITIALIZATION ======== */

    function __VeAccessControlUpgradeable_init(
        address _initialOwner,
        address _automationAddress,
        address[] memory _operators
    ) internal onlyInitializing {
        __Ownable_init();
        _transferOwnership(_initialOwner);
        _grantRole(AUTOMATION_ROLE, _automationAddress);
        for (uint256 i = 0; i < _operators.length; i++) {
            _grantRole(OPERATIONS_ROLE, _operators[i]);
        }
    }

    /* ======== MODIFIERS ======== */

    modifier onlyOwnerOrRole(bytes32 role1) {
        require(msg.sender == owner() || hasRole(role1, msg.sender), "Caller is not owner or has required role");
        _;
    }

    modifier onlyOwnerOrRoles(bytes32 role1, bytes32 role2) {
        require(
            msg.sender == owner() || hasRole(role1, msg.sender) || hasRole(role2, msg.sender),
            "Caller is not owner or has required role"
        );
        _;
    }

    modifier onlyOwnerOrRoles3(
        bytes32 role1,
        bytes32 role2,
        bytes32 role3
    ) {
        require(
            msg.sender == owner() ||
                hasRole(role1, msg.sender) ||
                hasRole(role2, msg.sender) ||
                hasRole(role3, msg.sender),
            "Caller is not owner or has required role"
        );
        _;
    }

    /* ======== onlyOwner FUNCTIONS ======== */

    /**
     * @notice Grant a role
     * @param role The role to grant
     * @param account The address to grant the role to
     */
    function grantRole(
        bytes32 role,
        address account
    ) public override(AccessControlUpgradeable, IAccessControlUpgradeable) onlyOwner {
        _grantRole(role, account);
    }

    /**
     * @notice Revoke a role
     * @param role The role to revoke
     * @param account The address to revoke the role from
     */
    function revokeRole(
        bytes32 role,
        address account
    ) public override(AccessControlUpgradeable, IAccessControlUpgradeable) onlyOwner {
        _revokeRole(role, account);
    }

    /* ======== VIEW FUNCTIONS ======== */

    /**
     * @notice Get all addresses with a specific role
     * @param role The role to query
     * @return addresses Array of addresses with the role
     */
    function getRoleMembers(bytes32 role) external view returns (address[] memory addresses) {
        uint256 memberCount = getRoleMemberCount(role);
        addresses = new address[](memberCount);
        for (uint256 i = 0; i < memberCount; i++) {
            addresses[i] = getRoleMember(role, i);
        }
    }
}

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

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

interface IBribe is IERC165 {
    function deposit(uint amount, address account) external;

    function withdraw(uint amount, address account) external;

    function getRewardForOwner(uint tokenId, address[] memory tokens) external;

    function getRewardForAddress(address _owner, address[] memory tokens) external;

    function notifyRewardAmount(address token, uint amount) external;

    function addRewardToken(address _rewardsToken) external;

    function addRewardTokens(address[] memory _rewardsToken) external;

    function setVoter(address _Voter) external;

    function setMinter(address _Voter) external;

    function setOwner(address _Voter) external;

    function emergencyRecoverERC20(address tokenAddress, uint256 tokenAmount) external;

    function recoverERC20AndUpdateData(address tokenAddress, uint256 tokenAmount) external;

    function rewardsListLength() external view returns (uint256);

    function rewardTokens(uint256) external view returns (address);
}

interface IBribe_Init is IBribe {
    function initialize(address _owner, address _voter, address _bribeFactory, string memory _type) external;
}

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

/**
 * @title BribeOptionTokenV2
 * @notice Interface for the BribeOptionTokenV2 contract
 */
interface IBribeOptionTokenV2 {
    function exerciseVe(uint256 _amount, address _recipient) external returns (uint256 nftId);
    function exerciseVe(
        uint256 _amount,
        uint256 _maxPaymentAmount,
        address _recipient,
        uint256 _deadline
    ) external returns (uint256 nftId);
}

File 32 of 53 : ICheckpoints.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ICheckpoints {
    /**
     * @dev Struct to keep track of the voting power over time.
     */
    struct Point {
        /// @dev The voting power at a specific time
        /// - MUST never be negative.
        int128 bias;
        /// @dev The rate at which the voting power decreases over time.
        int128 slope;
        /// @dev The value of tokens which do not decrease over time, representing permanent voting power
        /// - MUST never be negative.
        int128 permanent;
    }
}

// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.7.0;

interface IDynamicTwapOracle {
    /**
     * @notice Get the address of the pool
     * @return The address of the pool
     */
    function pool() external view returns (address);

    /**
     * @notice Get the address of the first token in the pool
     * @return The address of the first token
     */
    function token0() external view returns (address);

    /**
     * @notice Get the address of the second token in the pool
     * @return The address of the second token
     */
    function token1() external view returns (address);

    /**
     * @notice Estimate the output amount of a trade
     * @param tokenIn The address of the input token
     * @param amountIn The amount of the input token
     * @param secondsAgo The number of seconds ago to start the TWAP
     * @return amountOut The estimated output amount
     */
    function estimateAmountOut(
        address tokenIn,
        uint128 amountIn,
        uint32 secondsAgo
    ) external view returns (uint amountOut);
}

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
/**
 * @title Non-Fungible Vesting Token Standard.
 * @notice A non-fungible token standard used to vest ERC-20 tokens over a vesting release curve
 *  scheduled using timestamps.
 * @dev Because this standard relies on timestamps for the vesting schedule, it's important to keep track of the
 *  tokens claimed per Vesting NFT so that a user cannot withdraw more tokens than allotted for a specific Vesting NFT.
 * @custom:interface-id 0xbd3a202b
 */
interface IERC5725Upgradeable is IERC721Upgradeable {
    /**
     *  This event is emitted when the payout is claimed through the claim function.
     *  @param tokenId the NFT tokenId of the assets being claimed.
     *  @param recipient The address which is receiving the payout.
     *  @param claimAmount The amount of tokens being claimed.
     */
    event PayoutClaimed(uint256 indexed tokenId, address indexed recipient, uint256 claimAmount);

    /**
     *  This event is emitted when an `owner` sets an address to manage token claims for all tokens.
     *  @param owner The address setting a manager to manage all tokens.
     *  @param spender The address being permitted to manage all tokens.
     *  @param approved A boolean indicating whether the spender is approved to claim for all tokens.
     */
    event ClaimApprovalForAll(address indexed owner, address indexed spender, bool approved);

    /**
     *  This event is emitted when an `owner` sets an address to manage token claims for a `tokenId`.
     *  @param owner The `owner` of `tokenId`.
     *  @param spender The address being permitted to manage a tokenId.
     *  @param tokenId The unique identifier of the token being managed.
     *  @param approved A boolean indicating whether the spender is approved to claim for `tokenId`.
     */
    event ClaimApproval(address indexed owner, address indexed spender, uint256 indexed tokenId, bool approved);

    /**
     * @notice Claim the pending payout for the NFT.
     * @dev MUST grant the claimablePayout value at the time of claim being called to `msg.sender`.
     *  MUST revert if not called by the token owner or approved users.
     *  MUST emit PayoutClaimed.
     *  SHOULD revert if there is nothing to claim.
     * @param tokenId The NFT token id.
     */
    function claim(uint256 tokenId) external;

    /**
     * @notice Number of tokens for the NFT which have been claimed at the current timestamp.
     * @param tokenId The NFT token id.
     * @return payout The total amount of payout tokens claimed for this NFT.
     */
    function claimedPayout(uint256 tokenId) external view returns (uint256 payout);

    /**
     * @notice Number of tokens for the NFT which can be claimed at the current timestamp.
     * @dev It is RECOMMENDED that this is calculated as the `vestedPayout()` subtracted from `payoutClaimed()`.
     * @param tokenId The NFT token id.
     * @return payout The amount of unlocked payout tokens for the NFT which have not yet been claimed.
     */
    function claimablePayout(uint256 tokenId) external view returns (uint256 payout);

    /**
     * @notice Total amount of tokens which have been vested at the current timestamp.
     *  This number also includes vested tokens which have been claimed.
     * @dev It is RECOMMENDED that this function calls `vestedPayoutAtTime`
     *  with `block.timestamp` as the `timestamp` parameter.
     * @param tokenId The NFT token id.
     * @return payout Total amount of tokens which have been vested at the current timestamp.
     */
    function vestedPayout(uint256 tokenId) external view returns (uint256 payout);

    /**
     * @notice Total amount of vested tokens at the provided timestamp.
     *  This number also includes vested tokens which have been claimed.
     * @dev `timestamp` MAY be both in the future and in the past.
     *  Zero MUST be returned if the timestamp is before the token was minted.
     * @param tokenId The NFT token id.
     * @param timestamp The timestamp to check on, can be both in the past and the future.
     * @return payout Total amount of tokens which have been vested at the provided timestamp.
     */
    function vestedPayoutAtTime(uint256 tokenId, uint256 timestamp) external view returns (uint256 payout);

    /**
     * @notice Number of tokens for an NFT which are currently vesting.
     * @dev The sum of vestedPayout and vestingPayout SHOULD always be the total payout.
     * @param tokenId The NFT token id.
     * @return payout The number of tokens for the NFT which are vesting until a future date.
     */
    function vestingPayout(uint256 tokenId) external view returns (uint256 payout);

    /**
     * @notice The start and end timestamps for the vesting of the provided NFT.
     *  MUST return the timestamp where no further increase in vestedPayout occurs for `vestingEnd`.
     * @param tokenId The NFT token id.
     * @return vestingStart The beginning of the vesting as a unix timestamp.
     * @return vestingEnd The ending of the vesting as a unix timestamp.
     */
    function vestingPeriod(uint256 tokenId) external view returns (uint256 vestingStart, uint256 vestingEnd);

    /**
     * @notice Token which is used to pay out the vesting claims.
     * @param tokenId The NFT token id.
     * @return token The token which is used to pay out the vesting claims.
     */
    function payoutToken(uint256 tokenId) external view returns (address token);

    /**
     * @notice Sets a global `operator` with permission to manage all tokens owned by the current `msg.sender`.
     * @param operator The address to let manage all tokens.
     * @param approved A boolean indicating whether the spender is approved to claim for all tokens.
     */
    function setClaimApprovalForAll(address operator, bool approved) external;

    /**
     * @notice Sets a tokenId `operator` with permission to manage a single `tokenId` owned by the `msg.sender`.
     * @param operator The address to let manage a single `tokenId`.
     * @param tokenId the `tokenId` to be managed.
     * @param approved A boolean indicating whether the spender is approved to claim for all tokens.
     */
    function setClaimApproval(address operator, bool approved, uint256 tokenId) external;

    /**
     * @notice Returns true if `owner` has set `operator` to manage all `tokenId`s.
     * @param owner The owner allowing `operator` to manage all `tokenId`s.
     * @param operator The address who is given permission to spend tokens on behalf of the `owner`.
     */
    function isClaimApprovedForAll(address owner, address operator) external view returns (bool isClaimApproved);

    /**
     * @notice Returns the operating address for a `tokenId`.
     *  If `tokenId` is not managed, then returns the zero address.
     * @param tokenId The NFT `tokenId` to query for a `tokenId` manager.
     */
    function getClaimApproved(uint256 tokenId) external view returns (address operator);
}

interface IERC5725_ExtendedApproval is IERC5725Upgradeable {
    /**
     * @notice Returns true if `operator` is allowed to transfer the `tokenId` NFT.
     * @param operator The address to check if it is approved for the transfer
     * @param tokenId The token id to check if the operator is approved for
     */
    function isApprovedOrOwner(address operator, uint tokenId) external view returns (bool);

    /**
     * @notice Returns true if `operator` is allowed to claim for the provided tokenId
     * @param operator The address to check if it is approved for the claim or owner of the token
     * @param tokenId The token id to check if the operator is approved for
     */
    function isApprovedClaimOrOwner(address operator, uint256 tokenId) external view returns (bool);
}

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

interface IGauge {
    function notifyRewardAmount(address token, uint amount) external;

    function getReward(address account, address[] memory tokens) external;

    function getReward(address account) external;

    function claimFees() external returns (uint claimed0, uint claimed1);

    function rewardRate(address _pair) external view returns (uint);

    function balanceOf(address _account) external view returns (uint);

    function isForPair() external view returns (bool);

    function totalSupply() external view returns (uint);

    function earned(address token, address account) external view returns (uint);

    function stakeToken() external view returns (address);

    function setDistribution(address _distro) external;

    function addRewardToken(address _rewardToken) external;

    function removeRewardToken(address _rewardToken) external;

    function updateRewardToken() external;

    function activateEmergencyMode() external;

    function stopEmergencyMode() external;

    function setInternalBribe(address intbribe) external;

    function setGaugeRewarder(address _gr) external;

    function setFeeVault(address _feeVault) external;

    function depositWithLock(address account, uint256 amount, uint256 _lockDuration) external;

    function sweepTokens(address[] memory tokens, uint256[] memory amounts, address to) external;

    function initialize(
        address _rewardToken,
        address _ve,
        address _stakeToken,
        address _distribution,
        address _internal_bribe,
        address _external_bribe,
        bool _isForPair
    ) external;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

interface IMinter {
    function update_period() external returns (uint256);
    function check() external view returns (bool);
    function period() external view returns (uint256);
    function active_period() external view returns (uint256);
    function WEEK() external view returns (uint256);
}

// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.13;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";

interface IOption is IAccessControl {
    function paymentToken() external view returns (IERC20);

    function getPaymentAmount(uint256 _amount, bytes calldata _data) external view returns (uint256);

    function exercise(uint256 _amount, address sender, bytes calldata _data) external returns (uint256);
}

// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

interface IOptionFeeDistributor {
    function distribute(address token, uint256 amount) external;
}

File 39 of 53 : IOptionTokenV3.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {IDynamicTwapOracle} from "./IDynamicTwapOracle.sol";
import {IOptionFeeDistributor} from "./IOptionFeeDistributor.sol";
import {IPair} from "./IPair.sol";
import {IOption} from "./IOption.sol";

interface IOptionTokenV3 is IERC20, IAccessControl {
    function ADMIN_ROLE() external view returns (bytes32);

    function MINTER_ROLE() external view returns (bytes32);

    function PAUSER_ROLE() external view returns (bytes32);

    function paymentToken() external view returns (IERC20);

    function UNDERLYING_TOKEN() external view returns (IERC20);

    function voter() external view returns (address);

    function mint(address _to, uint256 _amount) external;

    function exercise(uint256 _amount, uint256 _maxPaymentAmount, address _recipient) external returns (uint256);

    function exercise(
        uint256 _amount,
        uint256 _maxPaymentAmount,
        address _recipient,
        uint256 _deadline
    ) external returns (uint256);

    function exerciseVe(
        uint256 _amount,
        uint256 _maxPaymentAmount,
        address _recipient,
        uint256 _discount,
        uint256 _deadline
    ) external returns (uint256, uint256);

    function exerciseLp(
        uint256 _amount,
        uint256 _maxPaymentAmount,
        uint256 _maxLPAmount,
        address _recipient,
        uint256 _discount,
        uint256 _deadline
    ) external returns (uint256, uint256);

    function exerciseExternal(
        IOption _option,
        uint256 _amount,
        uint256 _deadline,
        bytes calldata _data
    ) external returns (uint256);

    function getVotingEscrow() external view returns (address votingEscrow);

    function getLockDurationForVeDiscount(uint256 _discount) external view returns (uint256 duration);

    function getSlopeInterceptForVeDiscount() external view returns (int256 slope, int256 intercept);

    function togglePermissionedMint() external;

    function toggleOption(address option, bool enabled) external;

    function getDiscountedPrice(uint256 _amount) external view returns (uint256);

    function getDiscountedPrice(uint256 _amount, uint256 _discount) external view returns (uint256);

    function getLockDurationForLpDiscount(uint256 _amount) external view returns (uint256);

    function getPaymentTokenAmountForExerciseLp(
        uint256 _amount,
        uint256 _discount
    ) external view returns (uint256, uint256);

    function getSlopeInterceptForLpDiscount() external view returns (int256, int256);

    function getTimeWeightedAveragePrice(uint256 _amount) external view returns (uint256);

    function setTwapOracleAndPaymentToken(IDynamicTwapOracle _twapOracle, address _paymentToken) external;

    function setPairAndPaymentToken(IPair _pair, address _paymentToken) external;

    function setFeeDistributor(IOptionFeeDistributor _feeDistributor) external;

    function setDiscount(uint256 _discount) external;

    function setVeDiscount(uint256 _veDiscount) external;

    function setMinLPDiscount(uint256 _lpMinDiscount) external;

    function setMaxLPDiscount(uint256 _lpMaxDiscount) external;

    function setLockDurationForMaxLpDiscount(uint256 _duration) external;

    function setLockDurationForMinLpDiscount(uint256 _duration) external;

    function setTwapSeconds(uint32 _twapSeconds) external;

    function burn(uint256 _amount) external;

    function updateGauge() external;

    function setGauge(address _gauge) external;

    function setRouter(address _router) external;

    function unPause() external;

    function pause() external;
}

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

interface IPair {
    function metadata() external view returns (uint dec0, uint dec1, uint r0, uint r1, bool st, address t0, address t1);
    function claimFees() external returns (uint, uint);
    function tokens() external view returns (address, address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function fees() external view returns (address);
    function transferFrom(address src, address dst, uint amount) external returns (bool);
    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function burn(address to) external returns (uint amount0, uint amount1);
    function mint(address to) external returns (uint liquidity);
    function getReserves() external view returns (uint _reserve0, uint _reserve1, uint _blockTimestampLast);
    function getAmountOut(uint amountIn, address tokenIn) external view returns (uint);

    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function totalSupply() external view returns (uint);
    function decimals() external view returns (uint8);

    function claimable0(address _user) external view returns (uint);
    function claimable1(address _user) external view returns (uint);

    function isStable() external view returns (bool);

    function quote(address tokenIn, uint amountIn, uint granularity) external view returns (uint amountOut);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

interface IPermissionsRegistry {
    function adminMultisig() external view returns (address);

    function teamMultisig() external view returns (address);

    function emergencyCouncil() external view returns (address);

    /// @notice Check if an address has a bytes role
    function hasRole(bytes memory role, address caller) external view returns (bool);

    /// @notice Check if an address has a role
    function hasRoleString(string memory role, address _user) external view returns (bool);

    /// @notice Read roles and return array of role strings
    function rolesToString() external view returns (string[] memory __roles);

    /// @notice Read roles return an array of roles in bytes
    function roles() external view returns (bytes[] memory);

    /// @notice Read the number of roles
    function rolesLength() external view returns (uint);

    /// @notice Return addresses for a given role
    function roleToAddresses(string memory role) external view returns (address[] memory _addresses);

    /// @notice Return roles for a given address
    function addressToRole(address _user) external view returns (string[] memory);
}

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

interface IRewardsDistributor {
    function checkpoint_token() external;
    function voting_escrow() external view returns (address);
    function checkpoint_total_supply() external;
    function claimable(uint _tokenId) external view returns (uint);
    function claim(uint _tokenId) external returns (uint);
}

File 43 of 53 : IVersionable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IVersionable {
    function VERSION() external view returns (string memory);
}

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

/**
 * @title IVoterV5_ClaimHelper
 * @notice Interface to claim rewards from LP gauges and bribes from VoterV5
 */
interface IVoterV5_ClaimHelper {
    /// @notice claim LP gauge rewards
    function claimRewards(address[] memory _gauges) external;

    /// @notice claim LP gauge rewards for a given address
    function claimRewardsFor(address[] memory _gauges, address _claimFor) external;

    /// @notice claim specific reward tokens from LP gauges
    function claimRewardTokens(address[] memory _gauges, address[][] memory _tokens) external;

    /// @notice claim specific reward tokens from LP gauges for a given address
    function claimRewardTokensFor(address[] memory _gauges, address[][] memory _tokens, address _claimFor) external;

    /// @notice claim bribes rewards given a TokenID
    function claimBribes(address[] memory _bribes, address[][] memory _tokens, uint256 _tokenId) external;

    /// @notice claim fees rewards given a TokenID
    function claimFees(address[] memory _fees, address[][] memory _tokens, uint256 _tokenId) external;

    /// @notice claim bribes rewards given an address
    function claimBribes(address[] memory _bribes, address[][] memory _tokens) external;

    /// @notice claim fees rewards given an address
    function claimFees(address[] memory _fees, address[][] memory _tokens) external;
}

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

import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";

/// @title IVoterV5_GaugeLogic
interface IVoterV5_GaugeLogic is IERC165 {
    function createGauge(
        address _pool,
        uint256 _gaugeType
    ) external returns (address _gauge, address _internal_bribe, address _external_bribe);

    function isValidGaugeType(uint256 _gaugeType) external pure returns (bool);

    function MAX_GAUGE_TYPE() external pure returns (uint256);
}

File 46 of 53 : IVoterV5_Logic.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IVoterV5_GaugeLogic} from "./IVoterV5_GaugeLogic.sol";
import {IVoterV5_ClaimHelper} from "./IVoterV5_ClaimHelper.sol";
import {IBribe} from "../IBribe.sol";
import {IGauge} from "../IGauge.sol";
import {IOptionTokenV3} from "../IOptionTokenV3.sol";
import {IMinter} from "../IMinter.sol";
import {IPermissionsRegistry} from "../IPermissionsRegistry.sol";
import {IVotingEscrowV2} from "../IVotingEscrowV2.sol";

/// @title IVoterV5_Logic
/// @notice Interface to manage the functionality of the VoterV5 contract
/// @custom:version 2.0.0
/// - Replace addFactory, removeFactory, replaceFactory with setFactory to support GaugeType enum
interface IVoterV5_Logic is IVoterV5_ClaimHelper {
    // Initialization
    function initialize(
        address __ve,
        address _pairFactory,
        address _gaugeFactory,
        address _bribes,
        address _gaugeLogic,
        string memory _protocolName
    ) external;

    function _init(address[] memory _tokens, address _permissionsRegistry, address _minter, address _oToken) external;

    // Role Management
    function setVoteDelay(uint256 _delay) external;

    function setMinter(address _minter) external;

    function setOptionsToken(address _oToken) external;

    function refreshApprovals(uint256 start, uint256 finish, address _oldOtoken) external;

    function setGaugeDepositor(address _depositor, bool _enabled) external;

    function setBribeFactory(address _bribeFactory) external;

    function setPermissionsRegistry(address _permissionRegistry) external;

    function setNewBribes(address _gauge, address _internal, address _external) external;

    function setInternalBribeFor(address _gauge, address _internal) external;

    function setExternalBribeFor(address _gauge, address _external) external;

    function setFactory(uint256 _gaugeType, address _pairFactory, address _gaugeFactory) external;

    // Governance
    function updateWhitelistToken(address[] memory _tokens, bool _whitelist) external;

    function updateWhitelistPool(address[] memory _pools, bool _whitelist) external;

    function killGauge(address _gauge) external;

    function reviveGauge(address _gauge) external;

    // User Interaction
    function reset() external;

    function poke() external;

    function vote(address[] calldata _poolVote, uint256[] calldata _weights) external;

    // Gauge Management
    function createGauges(
        address[] memory _pool,
        uint256[] memory _gaugeTypes
    ) external returns (address[] memory, address[] memory, address[] memory);

    function createGauge(
        address _pool,
        uint256 _gaugeType
    ) external returns (address _gauge, address _internal_bribe, address _external_bribe);

    // View Functions
    function length() external view returns (uint256);

    function poolVoteLength(address voter) external view returns (uint256);

    function factories() external view returns (address[] memory);

    function factoryLength() external view returns (uint256);

    function gaugeFactories() external view returns (address[] memory);

    function gaugeFactoriesLength() external view returns (uint256);

    function weights(address _pool) external view returns (uint256);

    function weightsAt(address _pool, uint256 _time) external view returns (uint256);

    function totalWeight() external view returns (uint256);

    function totalWeightAt(uint256 _time) external view returns (uint256);

    function _epochTimestamp() external view returns (uint256);

    function ve() external view returns (address);

    // Distribution
    function notifyRewardAmount(uint256 amount) external;

    function distributeFees(address[] memory _gauges) external;

    function distributeAll() external;

    function distribute(uint256 start, uint256 finish) external;

    function distribute(address[] memory _gauges) external;
}

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

import {IVoterV5_GaugeLogic} from "./IVoterV5_GaugeLogic.sol";

/// @title IVoterV5_Storage
/// @notice Interface for accessing public and external variables of the VoterV5_Storage contract
interface IVoterV5_Storage {
    /// @notice Returns the address of the ve token
    function _ve() external view returns (address);

    /// @notice Returns the address of the base token
    function base() external view returns (address);

    /// @notice Returns the address of the option token
    function oToken() external view returns (address);

    /// @notice Returns the address of the bribe factory
    function bribefactory() external view returns (address);

    /// @notice Returns the address of the minter
    function minter() external view returns (address);

    /// @notice Returns the address of the permission registry
    function permissionRegistry() external view returns (address);

    /// @notice Returns the address of a pool at a given index
    /// @param index The index of the pool in the pools array
    function pools(uint256 index) external view returns (address);

    /// @notice Returns the global gauge index
    function index() external view returns (uint256);

    /// @notice Returns the delay between votes in seconds
    function VOTE_DELAY() external view returns (uint256);

    /// @notice Returns the maximum vote delay allowed
    function MAX_VOTE_DELAY() external view returns (uint256);

    /// @notice Returns the claimable amount for a given account
    /// @param account The address of the account
    function claimable(address account) external view returns (uint256);

    /// @notice Returns the gauge address for a given pool
    /// @param pool The address of the pool
    function gauges(address pool) external view returns (address);

    /// @notice Returns the last distribution timestamp for a given gauge
    /// @param gauge The address of the gauge
    function gaugesDistributionTimestamp(address gauge) external view returns (uint256);

    /// @notice Returns the pool address for a given gauge
    /// @param gauge The address of the gauge
    function poolForGauge(address gauge) external view returns (address);

    /// @notice Returns the internal bribe address for a given gauge
    /// @param gauge The address of the gauge
    function internal_bribes(address gauge) external view returns (address);

    /// @notice Returns the external bribe address for a given gauge
    /// @param gauge The address of the gauge
    function external_bribes(address gauge) external view returns (address);

    /// @notice Returns the votes for a given NFT and pool
    /// @param nft The address of the NFT
    /// @param pool The address of the pool
    function votes(address nft, address pool) external view returns (uint256);

    /// @notice Returns the pool address at a given index for a given NFT
    /// @param nft The address of the NFT
    /// @param index The index of the pool in the poolVote array
    function poolVote(address nft, uint256 index) external view returns (address);

    /// @notice Returns the timestamp of the last vote for a given NFT
    /// @param nft The address of the NFT
    function lastVoted(address nft) external view returns (uint256);

    /// @notice Returns whether a given address is a gauge
    /// @param gauge The address of the gauge
    function isGauge(address gauge) external view returns (bool);

    /// @notice Returns whether a given token is whitelisted
    /// @param token The address of the token
    function isWhitelisted(address token) external view returns (bool);

    /// @notice Returns whether a given pool is whitelisted
    /// @param token The address of the pool token
    function isWhitelistedPool(address token) external view returns (bool);

    /// @notice Returns whether a given gauge is alive
    /// @param gauge The address of the gauge
    function isAlive(address gauge) external view returns (bool);

    /// @notice Returns the factory status of a given address
    /// @param factory The address of the factory
    function isFactory(address factory) external view returns (uint8);

    /// @notice Returns whether a given address is a gauge factory
    /// @param gaugeFactory The address of the gauge factory
    /// @dev in 5.4.1, this returns a uint8 instead of a bool
    ///      This allows the same gauge factory to be used across multiple gauge types.
    ///      Storage-safe: bool and uint8 both occupy 1 byte, existing true/false values
    ///      become 1/0 counters seamlessly during upgrades.
    function isGaugeFactory(address gaugeFactory) external view returns (uint8);

    /// @notice Returns whether a given address is a gauge depositor
    /// @param gaugeFactory The address of the gauge factory
    function isGaugeDepositor(address gaugeFactory) external view returns (bool);

    /// @notice Returns the address of the gauge logic contract
    function gaugeLogic() external view returns (IVoterV5_GaugeLogic);

    /// @notice Returns the epoch timestamp when a given gauge was killed
    /// @param gauge The address of the gauge
    function gaugeKilledEpoch(address gauge) external view returns (uint256);
}

File 48 of 53 : IVoterV5.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IVoterV5_Logic} from "./IVoterV5_Logic.sol";
import {IVoterV5_Storage} from "./IVoterV5_Storage.sol";

/// @title IVoterV5
/// @dev This interface is a composition of the IVoterV5_Logic and IVoterV5_Storage interfaces.
/// By composing these two interfaces, any contract that integrates IVoterV5 gains access to both the logic operations
/// and storage getters defined in IVoterV5_Logic and IVoterV5_Storage respectively. This design also
/// circumvents the need for the VoterV5_GaugeLogic to be abstract, as it separates the concerns of
/// logic handling and state management into distinct interfaces.
interface IVoterV5 is IVoterV5_Logic, IVoterV5_Storage {}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (governance/utils/IVotes.sol)
pragma solidity ^0.8.0;

/**
 * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
 *
 * _Available since v4.5._
 */
interface IVotes {
    /**
     * @dev Emitted when an account changes their delegate.
     */
    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);

    /**
     * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
     */
    event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);

    /**
     * @dev Returns the current amount of votes that `account` has.
     */
    function getVotes(address account) external view returns (uint256);

    /**
     * @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is
     * configured to use block numbers, this will return the value at the end of the corresponding block.
     */
    function getPastVotes(address account, uint256 timepoint) external view returns (uint256);

    /**
     * @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is
     * configured to use block numbers, this will return the value at the end of the corresponding block.
     *
     * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
     * Votes that have not been delegated are still part of total supply, even though they would not participate in a
     * vote.
     */
    function getPastTotalSupply(uint256 timepoint) external view returns (uint256);

    /**
     * @dev Returns the delegate that `account` has chosen.
     */
    function delegates(address account) external view returns (address);

    /**
     * @dev Delegates votes from the sender to `delegatee`.
     */
    function delegate(address delegatee) external;

    /**
     * @notice Removed from the interface to avoid signature conflicts.
     * @dev Delegates votes from signer to `delegatee`.
     */
    // function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external;
}

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

import {IVotes} from "./IVotes.sol";
import {ICheckpoints} from "./ICheckpoints.sol";
import {IERC5725_ExtendedApproval} from "./IERC5725Upgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {IERC721EnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721EnumerableUpgradeable.sol";
import {IVersionable} from "./IVersionable.sol";

/**
 * @title Voting Escrow V2 Interface for Upgrades
 */
interface IVotingEscrowV2 is IVotes, IERC5725_ExtendedApproval, IERC721EnumerableUpgradeable, IVersionable {
    struct LockDetails {
        uint256 amount; /// @dev amount of tokens locked
        uint256 startTime; /// @dev when locking started
        uint256 endTime; /// @dev when locking ends
        bool isPermanent; /// @dev if its a permanent lock
    }

    /// -----------------------------------------------------------------------
    /// Events
    /// -----------------------------------------------------------------------

    event SupplyUpdated(uint256 oldSupply, uint256 newSupply);
    /// @notice Lock events
    event LockCreated(uint256 indexed tokenId, address indexed to, uint256 value, uint256 unlockTime, bool isPermanent);
    event LockUpdated(uint256 indexed tokenId, uint256 value, uint256 unlockTime, bool isPermanent);
    event LockMerged(
        uint256 indexed fromTokenId,
        uint256 indexed toTokenId,
        uint256 totalValue,
        uint256 unlockTime,
        bool isPermanent
    );
    event LockSplit(uint256[] splitWeights, uint256 indexed _tokenId);
    event LockDurationExtended(uint256 indexed tokenId, uint256 newUnlockTime, bool isPermanent);
    event LockAmountIncreased(uint256 indexed tokenId, uint256 value);
    event UnlockPermanent(uint256 indexed tokenId, address indexed sender, uint256 unlockTime);
    /// @notice Delegate events
    event LockDelegateChanged(
        uint256 indexed tokenId,
        address indexed delegator,
        address fromDelegate,
        address indexed toDelegate
    );

    /// -----------------------------------------------------------------------
    /// Errors
    /// -----------------------------------------------------------------------

    error AlreadyVoted();
    error InvalidNonce();
    error InvalidDelegatee();
    error InvalidSignature();
    error InvalidSignatureS();
    error InvalidWeights();
    error LockDurationNotInFuture();
    error LockDurationTooLong();
    error LockExpired();
    error LockNotExpired();
    error LockHoldsValue();
    error LockModifiedDelay();
    error NotPermanentLock();
    error PermanentLock();
    error PermanentLockMismatch();
    error SameNFT();
    error SignatureExpired();
    error ZeroAmount();
    error NotLockOwner();

    function supply() external view returns (uint);

    function token() external view returns (IERC20Upgradeable);

    function totalNftsMinted() external view returns (uint256);

    function balanceOfNFT(uint256 _tokenId) external view returns (uint256);

    function balanceOfNFTAt(uint256 _tokenId, uint256 _timestamp) external view returns (uint256);

    function delegates(uint256 tokenId, uint48 timestamp) external view returns (address);

    function lockDetails(uint256 tokenId) external view returns (LockDetails calldata);

    function getPastEscrowPoint(
        uint256 _tokenId,
        uint256 _timePoint
    ) external view returns (ICheckpoints.Point memory, uint48);

    function getFirstEscrowPoint(uint256 _tokenId) external view returns (ICheckpoints.Point memory, uint48);

    function checkpoint() external;

    function increaseAmount(uint256 _tokenId, uint256 _value) external;

    function increaseUnlockTime(uint256 _tokenId, uint256 _lockDuration, bool _permanent) external;

    function createLockFor(
        uint256 _value,
        uint256 _lockDuration,
        address _to,
        bool _permanent
    ) external returns (uint256);

    function createDelegatedLockFor(
        uint256 _value,
        uint256 _lockDuration,
        address _to,
        address _delegatee,
        bool _permanent
    ) external returns (uint256);

    function split(uint256[] memory _weights, uint256 _tokenId) external;

    function merge(uint256 _from, uint256 _to) external;

    function burn(uint256 _tokenId) external;

    function decimals() external view returns (uint8);
}

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

interface IVotingEscrowVault {
    function rewardOutputToken() external view returns (address);
    function notifyReward(uint256 amount) external;
    function enableRedeem() external;
    function disableRedeem() external;
    function lastTimeRewardApplicable() external view returns (uint256);
    function rewardForDuration() external view returns (uint256);
    function getPeriodFinish() external view returns (uint256);
    function left() external view returns (uint256);
}

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

library CallLib {
    /**
     * @dev Handles the result of a call and reverts with the revert reason if the call failed.
     * @param success The success flag returned by the call.
     * @param result The result bytes returned by the call.
     * @return The result bytes if the call was successful.
     */
    function handleCallResult(bool success, bytes memory result) internal pure returns (bytes memory) {
        if (success) {
            return result;
        } else {
            // If the result length is less than 68, then the transaction failed silently (without a revert reason)
            if (result.length < 68) revert("call failed without a revert reason");

            assembly {
                // Slice the sighash to remove the function selector
                result := add(result, 0x04)
            }
            // All that remains is the revert string
            revert(abi.decode(result, (string)));
        }
    }
}

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../interfaces/IVotingEscrowV2.sol";

/**
 * @title VeHelper
 * @notice Library for voting escrow operations
 * @dev Provides stateless utility functions for VE token management
 */
library VeHelper {
    using SafeERC20 for IERC20;

    /// -----------------------------------------------------------------------
    /// Events
    /// -----------------------------------------------------------------------

    event LockCreated(address indexed veToken, uint256 indexed tokenId, uint256 amount, uint256 unlockTime);
    event LockIncreased(address indexed veToken, uint256 indexed tokenId, uint256 amount);
    event VeNftMerged(address indexed veToken, uint256 indexed fromTokenId, uint256 indexed toTokenId);
    event VeNftSplit(address indexed veToken, uint256 indexed fromTokenId, uint256 newTokenId, uint256 splitAmount);
    event VeNftBurned(address indexed veToken, uint256 indexed tokenId, uint256 releasedAmount);

    /// -----------------------------------------------------------------------
    /// Errors
    /// -----------------------------------------------------------------------

    error InvalidAmount();
    error InvalidTokenId();
    error InsufficientBalance();
    error SplitFailed();
    error MergeFailed();
    error CannotBurnNftWithLockedAmount();

    /// -----------------------------------------------------------------------
    /// Core VE Operations
    /// -----------------------------------------------------------------------

    /**
     * @notice Create a new VE lock
     * @param veToken Address of the VE token contract
     * @param underlyingToken Address of the underlying token
     * @param amount Amount of tokens to lock
     * @param unlockTime Unlock timestamp
     * @return tokenId The created token ID
     */
    function createLock(
        IVotingEscrowV2 veToken,
        address underlyingToken,
        uint256 amount,
        uint256 unlockTime,
        bool permanent
    ) internal returns (uint256 tokenId) {
        if (amount == 0) revert InvalidAmount();

        // Approve and create lock
        IERC20(underlyingToken).safeApprove(address(veToken), 0);
        IERC20(underlyingToken).safeApprove(address(veToken), amount);

        tokenId = veToken.createLockFor(amount, unlockTime, address(this), permanent);

        emit LockCreated(address(veToken), tokenId, amount, unlockTime);
    }

    /**
     * @notice Increase the amount of an existing VE lock
     * @param veToken Address of the VE token contract
     * @param underlyingToken Address of the underlying token
     * @param tokenId Token ID to increase
     * @param amount Amount to add to the lock
     */
    function increaseAmount(
        IVotingEscrowV2 veToken,
        address underlyingToken,
        uint256 tokenId,
        uint256 amount
    ) internal {
        if (amount == 0) revert InvalidAmount();
        if (tokenId == 0) revert InvalidTokenId();

        // Approve and increase amount
        IERC20(underlyingToken).safeApprove(address(veToken), 0);
        IERC20(underlyingToken).safeApprove(address(veToken), amount);

        veToken.increaseAmount(tokenId, amount);

        emit LockIncreased(address(veToken), tokenId, amount);
    }

    /**
     * @notice Permanently lock a VE token
     * @param veToken Address of the VE token contract
     * @param tokenId Token ID to permanently lock
     * @dev Note: This function may not be supported by all VE implementations
     */
    function lockPermanent(IVotingEscrowV2 veToken, uint256 tokenId) internal {
        if (tokenId == 0) revert InvalidTokenId();

        veToken.increaseUnlockTime(tokenId, 0, true);
    }

    /**
     * @notice Split a VE NFT and send the split portion to a recipient
     * @param veToken Address of the VE token contract
     * @param tokenId Token ID to split
     * @param splitAmount Amount to split off
     * @param recipient Address to receive the split NFT
     * @return newTokenId The ID of the newly created split NFT
     */
    function splitAndSend(
        IVotingEscrowV2 veToken,
        uint256 tokenId,
        uint256 splitAmount,
        address recipient
    ) internal returns (uint256 newTokenId) {
        if (tokenId == 0) revert InvalidTokenId();
        if (splitAmount == 0) revert InvalidAmount();

        uint256 totalNftsBefore = veToken.balanceOf(address(this));

        // Use actual locked amount, not voting power
        uint256 totalBalance = veToken.lockDetails(tokenId).amount;

        if (splitAmount > totalBalance) revert InsufficientBalance();

        uint256 remainingBalance = totalBalance - splitAmount;

        uint256[] memory amounts = new uint256[](2);
        amounts[0] = remainingBalance;
        amounts[1] = splitAmount;

        // Split the NFT
        veToken.split(amounts, tokenId);

        uint256 totalNftsAfter = veToken.balanceOf(address(this));
        if (totalNftsAfter != totalNftsBefore + 1) revert SplitFailed();

        // Get the new split token ID (should be the last one)
        newTokenId = veToken.tokenOfOwnerByIndex(address(this), totalNftsAfter - 1);

        // Transfer the split NFT to recipient
        veToken.transferFrom(address(this), recipient, newTokenId);

        emit VeNftSplit(address(veToken), tokenId, newTokenId, splitAmount);
    }

    /**
     * @notice Burn a VE NFT (only works if lock amount is 0)
     * @param veToken Address of the VE token contract
     * @param tokenId Token ID to burn
     * @dev NFT can only be burned when lockDetails.amount == 0
     */
    function burnNft(IVotingEscrowV2 veToken, uint256 tokenId) internal {
        if (tokenId == 0) revert InvalidTokenId();

        // Verify that the NFT has no locked amount before burning
        IVotingEscrowV2.LockDetails memory lockDetails = veToken.lockDetails(tokenId);
        if (lockDetails.amount > 0) revert CannotBurnNftWithLockedAmount();

        // Burn the empty NFT
        veToken.burn(tokenId);

        emit VeNftBurned(address(veToken), tokenId, 0);
    }

    /// -----------------------------------------------------------------------
    /// View Functions
    /// -----------------------------------------------------------------------

    /**
     * @notice Get the actual locked token amount for a VE NFT (not voting power)
     * @param veToken Address of the VE token contract
     * @param tokenId Token ID to query
     * @return amount Actual locked token amount
     */
    function getLockedAmount(IVotingEscrowV2 veToken, uint256 tokenId) internal view returns (uint256 amount) {
        if (tokenId == 0) return 0;
        return veToken.lockDetails(tokenId).amount;
    }

    /**
     * @notice Get lock details for a VE NFT
     * @param veToken Address of the VE token contract
     * @param tokenId Token ID to query
     * @return lockDetails Lock details struct
     */
    function getLockDetails(
        IVotingEscrowV2 veToken,
        uint256 tokenId
    ) internal view returns (IVotingEscrowV2.LockDetails memory lockDetails) {
        if (tokenId == 0) {
            return IVotingEscrowV2.LockDetails(0, 0, 0, false);
        }
        return veToken.lockDetails(tokenId);
    }

    /**
     * @notice Check if a VE NFT is owned by the given address
     * @param veToken Address of the VE token contract
     * @param tokenId Token ID to check
     * @param owner Address to check ownership for
     * @return isOwner True if the address owns the NFT
     */
    function isOwner(IVotingEscrowV2 veToken, uint256 tokenId, address owner) internal view returns (bool) {
        if (tokenId == 0) return false;
        try veToken.ownerOf(tokenId) returns (address actualOwner) {
            return actualOwner == owner;
        } catch {
            return false;
        }
    }

    /**
     * @notice Get the VE voting power for a token ID at a specific epoch
     * @param veToken Address of the VE token contract
     * @param tokenId Token ID to query
     * @param epoch Epoch timestamp to get voting power for
     * @return votingPower Voting power of the NFT at the specified epoch
     */
    function getVotingPower(
        IVotingEscrowV2 veToken,
        uint256 tokenId,
        uint256 epoch
    ) internal view returns (uint256 votingPower) {
        if (tokenId == 0) return 0;
        address owner = veToken.ownerOf(tokenId);
        return veToken.getPastVotes(owner, epoch);
    }

    /**
     * @notice Get the underlying token address for a VE token
     * @param veToken Address of the VE token contract
     * @return underlyingToken Address of the underlying token
     */
    function getUnderlyingToken(IVotingEscrowV2 veToken) internal view returns (address underlyingToken) {
        return address(veToken.token());
    }
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AmountMismatch","type":"error"},{"inputs":[],"name":"ArrayLengthMismatch","type":"error"},{"inputs":[],"name":"BveTokenNotSet","type":"error"},{"inputs":[],"name":"CallFailed","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InsufficientTokenBalance","type":"error"},{"inputs":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"InvalidArrayLength","type":"error"},{"inputs":[],"name":"InvalidFee","type":"error"},{"inputs":[],"name":"InvalidRange","type":"error"},{"inputs":[],"name":"InvalidTarget","type":"error"},{"inputs":[],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"OnlyVault","type":"error"},{"inputs":[],"name":"SplitFailed","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"VoteRecordNotFound","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[],"name":"ZeroAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"bribes","type":"address[]"}],"name":"BribesClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newTokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"mergedTokenId","type":"uint256"}],"name":"BveTokenExercised","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldBveToken","type":"address"},{"indexed":true,"internalType":"address","name":"newBveToken","type":"address"}],"name":"BveTokenUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"result","type":"bytes"}],"name":"CallExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feeBps","type":"uint256"},{"indexed":true,"internalType":"address","name":"feeRecipient","type":"address"}],"name":"FeeParametersUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"fees","type":"address[]"}],"name":"FeesClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RebaseClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"delta","type":"uint256"}],"name":"RewardNotified","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"veTokenId","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"startIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endIndex","type":"uint256"}],"name":"RewardsClaimedForRange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"address","name":"nft","type":"address"},{"indexed":true,"internalType":"uint256","name":"veTokenId","type":"uint256"}],"name":"SweepWithdrawNft","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"SweepWithdrawToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"bool","name":"trusted","type":"bool"}],"name":"TrustedCallTargetUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldVault","type":"address"},{"indexed":true,"internalType":"address","name":"newVault","type":"address"}],"name":"VaultUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"veTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lockedAmount","type":"uint256"}],"name":"VeNftDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"fromTokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"toTokenId","type":"uint256"}],"name":"VeNftMerged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"newTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"}],"name":"VeNftWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"pools","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"weights","type":"uint256[]"}],"name":"VoteExecuted","type":"event"},{"inputs":[],"name":"AUTOMATION_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATIONS_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VOTING_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bveToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"bribes","type":"address[]"},{"internalType":"address[][]","name":"tokens","type":"address[][]"}],"name":"claimBribes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimRebase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"claimRewardsForEpoch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"startIndex","type":"uint256"},{"internalType":"uint256","name":"endIndex","type":"uint256"}],"name":"claimRewardsForEpochByRange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_veTokenId","type":"uint256"},{"internalType":"uint256","name":"_expectedAmount","type":"uint256"}],"name":"depositNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"executeCall","outputs":[{"internalType":"bytes","name":"result","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"executeCallMulti","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes[]","name":"data","type":"bytes[]"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"executeCustomSwaps","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"swapTarget","type":"address"},{"internalType":"bytes[]","name":"swapData","type":"bytes[]"},{"internalType":"address[]","name":"swapTokens","type":"address[]"},{"internalType":"uint256[]","name":"swapAmounts","type":"uint256[]"}],"name":"executeSwapsAndNotifyRewards","outputs":[{"internalType":"bytes[]","name":"swapResults","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"exerciseBveToken","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBveTokenBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getClaimableRebase","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastVoteEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMembers","outputs":[{"internalType":"address[]","name":"addresses","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalLockedAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVeLockDetails","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"bool","name":"isPermanent","type":"bool"}],"internalType":"struct IVotingEscrowV2.LockDetails","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVeVotingPower","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"getVotePoolCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"getVoteRecord","outputs":[{"components":[{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"address[]","name":"pools","type":"address[]"},{"internalType":"uint256[]","name":"weights","type":"uint256[]"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"internalType":"struct VotingEscrowManager.VoteRecord","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"getVoteTokens","outputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"getVoteTokensWithBalances","outputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_veToken","type":"address"},{"internalType":"address","name":"_voter","type":"address"},{"internalType":"address","name":"_rewardsDistributor","type":"address"},{"internalType":"address","name":"_bveToken","type":"address"},{"internalType":"address","name":"_admin","type":"address"},{"internalType":"address","name":"_automationAddress","type":"address"},{"internalType":"address[]","name":"_operators","type":"address[]"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastVoteEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"notifyRewardsToVault","outputs":[{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardsDistributor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_bveToken","type":"address"}],"name":"setBveToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feeBps","type":"uint256"}],"name":"setFeeBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeRecipient","type":"address"}],"name":"setFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bool","name":"trusted","type":"bool"}],"name":"setTrustedCallTarget","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newVault","type":"address"}],"name":"setVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"nfts","type":"address[]"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"internalType":"address","name":"to","type":"address"}],"name":"sweepNfts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address","name":"to","type":"address"}],"name":"sweepTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"trustedCallTargets","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"veToken","outputs":[{"internalType":"contract IVotingEscrowV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"veTokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"pools","type":"address[]"},{"internalType":"uint256[]","name":"weights","type":"uint256[]"}],"name":"vote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"voteRecords","outputs":[{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"voter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"withdrawNft","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b506200001c62000022565b620000e3565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811614620000e1576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b615c2a80620000f36000396000f3fe608060405234801561001057600080fd5b50600436106102b45760003560e01c806301ffc9a7146102b9578063106fffe9146102e157806312a70f0b14610302578063150b7a0214610329578063154cb5a814610361578063177f3389146103815780632488d909146103a5578063248a9ca3146103c557806324a9d853146103e857806324c20eec146103f2578063268b8c691461040757806328df5d46146104445780632f2ff15d1461045757806336568abe1461046c5780633b92eb231461047f5780633f2a55401461049f57806342a82b4f146104b2578063460258c9146104c557806346904840146104e657806346c73397146104fa57806346c96aac14610504578063507436231461051757806357b2a88b1461051f57806358396580146105325780636817031b1461053a5780636f054a3d1461054d5780636f816a201461058a578063715018a61461059d57806372c27b62146105a557806378a6cc09146105b857806379347371146105cd5780637ad559d0146105e05780638da5cb5b146105f35780639010d07c146105fb57806391d148541461060e57806391d2b32e14610621578063991ba73114610629578063a217fddf1461063c578063a3246ad314610644578063b3aa527d14610664578063b4cd143a14610677578063b8d3d3081461067f578063b97dd9e214610692578063b9bf8a0a1461069a578063bca8c7b5146106a2578063c2606476146106c2578063c2b79e98146106d5578063ca15c873146106e8578063d547741f146106fb578063d753dcc81461070e578063d907b13014610717578063de97674f1461072a578063e59171d014610732578063e74b981b14610745578063e93900a314610758578063f25d8a4414610761578063f2fde38b14610774578063f66e311b14610787578063fbfa77cf1461079b578063fef27b02146107ae575b600080fd5b6102cc6102c7366004614cfd565b6107c1565b60405190151581526020015b60405180910390f35b6102f46102ef366004614d27565b6107ec565b6040519081526020016102d8565b6102f47fa0cc82bfc6a0e1fd4746daa2c96f2cbac6feca4912d2b7f78808a14ff40807db81565b610348610337366004614dad565b630a85bd0160e11b95945050505050565b6040516001600160e01b031990911681526020016102d8565b61037461036f366004614e63565b610901565b6040516102d89190614f67565b6102cc61038f366004614fc9565b6101006020526000908152604090205460ff1681565b6103b86103b3366004614d27565b610ba9565b6040516102d8919061505a565b6102f46103d3366004614d27565b60009081526097602052604090206001015490565b6102f46101015481565b6102f4600080516020615b9583398151915281565b61042f610415366004614d27565b610103602052600090815260409020805460039091015482565b604080519283526020830191909152016102d8565b6103746104523660046150b4565b610cbd565b61046a61046536600461511f565b610db6565b005b61046a61047a36600461511f565b610dcc565b60fb54610492906001600160a01b031681565b6040516102d8919061514f565b60fd54610492906001600160a01b031681565b61046a6104c03660046151cc565b610e46565b6104d86104d3366004614d27565b61102f565b6040516102d89291906152dc565b61010254610492906001600160a01b031681565b6102f46101045481565b60fc54610492906001600160a01b031681565b6102f4611264565b61046a61052d366004614d27565b6112f5565b6102f4611495565b61046a610548366004614fc9565b6116de565b61055561175f565b6040516102d8919081518152602080830151908201526040808301519082015260609182015115159181019190915260800190565b61046a6105983660046150b4565b611782565b61046a611ae3565b61046a6105b3366004614d27565b611af7565b6102f4600080516020615bb583398151915281565b61046a6105db366004615301565b611b5d565b61046a6105ee366004615323565b611d10565b610492611fbc565b610492610609366004615301565b611fcb565b6102cc61061c36600461511f565b611fea565b6102f4612015565b6102f4610637366004614d27565b612037565b6102f4600081565b610657610652366004614d27565b61234a565b6040516102d8919061534f565b61046a6106723660046153c8565b6123f5565b61046a6125d4565b61046a61068d3660046154a7565b612769565b6102f46127c6565b6102f4612871565b6106b56106b03660046154d5565b6128cd565b6040516102d89190615529565b6103746106d0366004614e63565b6128e2565b61046a6106e33660046150b4565b612971565b6102f46106f6366004614d27565b612a96565b61046a61070936600461511f565b612aad565b610104546102f4565b6102f461072536600461511f565b612ab5565b6102f4612b90565b61046a610740366004614fc9565b612c8e565b61046a610753366004614fc9565b612ce9565b6102f460fe5481565b61046a61076f36600461553c565b612d59565b61046a610782366004614fc9565b612e94565b61010554610492906001600160a01b031681565b60ff54610492906001600160a01b031681565b6106576107bc366004614d27565b612f0d565b60006001600160e01b03198216635a05180f60e01b14806107e657506107e682613026565b92915050565b60008181526101036020908152604080832081516080810183528154815260018201805484518187028101870190955280855286959294858401939092919083018282801561086457602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610846575b50505050508152602001600282018054806020026020016040519081016040528092919081815260200182805480156108bc57602002820191906000526020600020905b8154815260200190600101908083116108a8575b50505050508152602001600382015481525050905080600001516000036108f657604051632f05f46960e21b815260040160405180910390fd5b602001515192915050565b6060600080516020615bb583398151915261091a611fbc565b6001600160a01b0316336001600160a01b0316148061093e575061093e8133611fea565b6109635760405162461bcd60e51b815260040161095a906155bf565b60405180910390fd5b6001600160a01b0389166000908152610100602052604090205460ff1661099c576040516282b42960e81b815260040160405180910390fd5b8483146109bc57604051634ec4810560e11b815260040160405180910390fd5b60005b85811015610ae55760008787838181106109db576109db615607565b90506020020160208101906109f09190614fc9565b90506000816001600160a01b031663dd62ed3e308e6040518363ffffffff1660e01b8152600401610a2292919061561d565b602060405180830381865afa158015610a3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a639190615637565b9050868684818110610a7757610a77615607565b90506020020135811015610ad057610a9a6001600160a01b0383168d600061305b565b610ad08c888886818110610ab057610ab0615607565b90506020020135846001600160a01b031661305b9092919063ffffffff16565b50508080610add90615666565b9150506109bf565b50866001600160401b03811115610afe57610afe615163565b604051908082528060200260200182016040528015610b3157816020015b6060815260200190600190039081610b1c5790505b50915060005b87811015610b9c57610b6c8a8a8a84818110610b5557610b55615607565b9050602002810190610b67919061567f565b61319a565b838281518110610b7e57610b7e615607565b60200260200101819052508080610b9490615666565b915050610b37565b5050979650505050505050565b610bd46040518060800160405280600081526020016060815260200160608152602001600081525090565b6000828152610103602090815260409182902082516080810184528154815260018201805485518186028101860190965280865291949293858101939290830182828015610c4b57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610c2d575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015610ca357602002820191906000526020600020905b815481526020019060010190808311610c8f575b505050505081526020016003820154815250509050919050565b6060610cc76132bb565b838214610ce757604051634ec4810560e11b815260040160405180910390fd5b836001600160401b03811115610cff57610cff615163565b604051908082528060200260200182016040528015610d3257816020015b6060815260200190600190039081610d1d5790505b50905060005b84811015610dac57610d7c868683818110610d5557610d55615607565b9050602002016020810190610d6a9190614fc9565b858584818110610b5557610b55615607565b828281518110610d8e57610d8e615607565b60200260200101819052508080610da490615666565b915050610d38565b505b949350505050565b610dbe6132bb565b610dc8828261331a565b5050565b6001600160a01b0381163314610e3c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161095a565b610dc8828261333c565b600054610100900460ff1615808015610e665750600054600160ff909116105b80610e875750610e753061335e565b158015610e87575060005460ff166001145b610eea5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161095a565b6000805460ff191660011790558015610f0d576000805461ff0019166101001790555b610f1884848461336d565b6001600160a01b0388161580610f3557506001600160a01b038716155b80610f4757506001600160a01b038616155b15610f655760405163d92e233d60e01b815260040160405180910390fd5b60fb80546001600160a01b03808b166001600160a01b03199283161790925560fc80548a841690831617905560fd8054898416908316179055610105805492881692909116919091179055600061010155610fbe611fbc565b61010280546001600160a01b0319166001600160a01b03929092169190911790558015611025576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050505050565b6060806000610103600085815260200190815260200160002060405180608001604052908160008201548152602001600182018054806020026020016040519081016040528092919081815260200182805480156110b657602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611098575b505050505081526020016002820180548060200260200160405190810160405280929190818152602001828054801561110e57602002820191906000526020600020905b8154815260200190600101908083116110fa575b505050505081526020016003820154815250509050806000015160000361114857604051632f05f46960e21b815260040160405180910390fd5b611155816020015161340c565b925082516001600160401b0381111561117057611170615163565b604051908082528060200260200182016040528015611199578160200160208202803683370190505b50915060005b835181101561125d578381815181106111ba576111ba615607565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016111ed919061514f565b602060405180830381865afa15801561120a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122e9190615637565b83828151811061124057611240615607565b60209081029190910101528061125581615666565b91505061119f565b5050915091565b610105546000906001600160a01b031661127e5750600090565b610105546040516370a0823160e01b81526001600160a01b03909116906370a08231906112af90309060040161514f565b602060405180830381865afa1580156112cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112f09190615637565b905090565b600080516020615bb583398151915261130c611fbc565b6001600160a01b0316336001600160a01b0316148061133057506113308133611fea565b61134c5760405162461bcd60e51b815260040161095a906155bf565b60008281526101036020908152604080832081516080810183528154815260018201805484518187028101870190955280855291949293858401939092908301828280156113c357602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116113a5575b505050505081526020016002820180548060200260200160405190810160405280929190818152602001828054801561141b57602002820191906000526020600020905b815481526020019060010190808311611407575b505050505081526020016003820154815250509050806000015160000361145557604051632f05f46960e21b815260040160405180910390fd5b611462816020015161379e565b60fe5460405184907f38be9b012e428704c0fb2b81dfd53444b76ac4cd45c46cfd2d661f73d97cf47b90600090a3505050565b6000600080516020615bb58339815191526114ae611fbc565b6001600160a01b0316336001600160a01b031614806114d257506114d28133611fea565b6114ee5760405162461bcd60e51b815260040161095a906155bf565b60ff5460408051632fbe4c6560e11b815290516000926001600160a01b031691635f7c98ca9160048083019260209291908290030181865afa158015611538573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155c91906156c5565b6040516370a0823160e01b81529091506001600160a01b038216906370a082319061158b90309060040161514f565b602060405180830381865afa1580156115a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115cc9190615637565b925082156116d857600061271061010154856115e891906156e2565b6115f29190615701565b905060006116008286615723565b905081156116235761010254611623906001600160a01b03858116911684613890565b80156116a25760ff54611643906001600160a01b03858116911683613890565b60ff546040516360993b5b60e01b8152600481018390526001600160a01b03909116906360993b5b90602401600060405180830381600087803b15801561168957600080fd5b505af115801561169d573d6000803e3d6000fd5b505050505b6040518581527ff9a5da3a173eca8cd77c02ece3ff1467b8aa461ed3822201817f2d72fbc542839060200160405180910390a150505b505b5090565b6116e66132bb565b6001600160a01b03811661170d5760405163d92e233d60e01b815260040160405180910390fd5b60ff80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f483bdedaaf23706a9800ac1af0d852b34927780d79f9d6ba60a80c7cad75ea3990600090a35050565b611767614c22565b60fe5460fb546112f0916001600160a01b03909116906138af565b600080516020615bb5833981519152611799611fbc565b6001600160a01b0316336001600160a01b031614806117bd57506117bd8133611fea565b6117d95760405162461bcd60e51b815260040161095a906155bf565b60fe546000036117fc576040516307ed98ed60e31b815260040160405180910390fd5b83821461181c57604051634ec4810560e11b815260040160405180910390fd5b60fc54604080516303aa30b960e11b815290516000926001600160a01b03169163075461729160048083019260209291908290030181865afa158015611866573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188a91906156c5565b6001600160a01b031663d13996086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118eb9190615637565b60fc5460405163037c0b5160e51b81529192506001600160a01b031690636f816a2090611922908990899089908990600401615778565b600060405180830381600087803b15801561193c57600080fd5b505af1158015611950573d6000803e3d6000fd5b5050505060ff60009054906101000a90046001600160a01b03166001600160a01b031663b59ca7996040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156119a457600080fd5b505af11580156119b8573d6000803e3d6000fd5b50505050806101048190555060405180608001604052808281526020018787808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505050908252506040805160208781028281018201909352878252928301929091889188918291850190849080828437600092018290525093855250504260209384015250838152610103825260409020825181558282015180519192611a7392600185019290910190614c4c565b5060408201518051611a8f916002840191602090910190614cad565b5060608201518160030155905050807f1383afe130223102b4c91dedfa02425285670061011d89d4fc94945a36175df387878787604051611ad39493929190615778565b60405180910390a2505050505050565b611aeb6132bb565b611af56000613956565b565b611aff6132bb565b611388811115611b22576040516358d620b360e01b815260040160405180910390fd5b610101819055610102546040518281526001600160a01b0390911690600080516020615bd5833981519152906020015b60405180910390a250565b60ff546001600160a01b03163314611b8857604051638d1af8bd60e01b815260040160405180910390fd5b60fb54604051636318523760e01b8152600481018490526000916001600160a01b031690636318523790602401608060405180830381865afa158015611bd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf691906157ca565b80519091508214611c1a576040516355e97b0d60e01b815260040160405180910390fd5b8060600151611c395760fb54611c39906001600160a01b0316846139a8565b60fe54600003611c4d5760fe839055611cd5565b60fb5460fe5460405163d1c2babb60e01b81526004810186905260248101919091526001600160a01b039091169063d1c2babb90604401600060405180830381600087803b158015611c9e57600080fd5b505af1158015611cb2573d6000803e3d6000fd5b5050505060fe5483600080516020615b7583398151915260405160405180910390a35b60fe546040518381527f7c2fb9c31dd32c6d7ef4e5cfd9b9b881983baf79919f2cef97485cd0d79cae299060200160405180910390a2505050565b600080516020615bb5833981519152611d27611fbc565b6001600160a01b0316336001600160a01b03161480611d4b5750611d4b8133611fea565b611d675760405162461bcd60e51b815260040161095a906155bf565b6000848152610103602090815260408083208151608081018352815481526001820180548451818702810187019095528085529194929385840193909290830182828015611dde57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611dc0575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015611e3657602002820191906000526020600020905b815481526020019060010190808311611e22575b5050505050815260200160038201548152505090508060000151600003611e7057604051632f05f46960e21b815260040160405180910390fd5b82841180611e8357508060200151518310155b15611ea15760405163561ce9bb60e01b815260040160405180910390fd5b6000611ead8585615723565b611eb8906001615835565b90506000816001600160401b03811115611ed457611ed4615163565b604051908082528060200260200182016040528015611efd578160200160208202803683370190505b50905060005b82811015611f6e576020840151611f1a8289615835565b81518110611f2a57611f2a615607565b6020026020010151828281518110611f4457611f44615607565b6001600160a01b039092166020928302919091019091015280611f6681615666565b915050611f03565b50611f788161379e565b85877fe8f47b8ff1a31cd79215962a688b3481eda9173260e1bdb9eac4bad798f393cf87604051611fab91815260200190565b60405180910390a350505050505050565b6033546001600160a01b031690565b600082815260c960205260408120611fe39083613a2d565b9392505050565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60fe5460fb54600091612031916001600160a01b0316906138af565b51919050565b6000600080516020615bb5833981519152612050611fbc565b6001600160a01b0316336001600160a01b0316148061207457506120748133611fea565b6120905760405162461bcd60e51b815260040161095a906155bf565b610105546001600160a01b03166120ba5760405163811d56f560e01b815260040160405180910390fd5b826000036120db57604051631f2a200560e01b815260040160405180910390fd5b60fe546000036120fe576040516307ed98ed60e31b815260040160405180910390fd5b61010554604051639130325d60e01b8152600481018590523060248201526001600160a01b0390911690639130325d906044016020604051808303816000875af192505050801561216c575060408051601f3d908101601f1916820190925261216991810190615637565b60015b6121fa57610105546040516362994c0560e01b815260048101859052602481018590523060448201524260648201526001600160a01b03909116906362994c05906084016020604051808303816000875af11580156121cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121f39190615637565b91506121fd565b91505b60fb54604051636318523760e01b8152600481018490526000916001600160a01b031690636318523790602401608060405180830381865afa158015612247573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226b91906157ca565b9050806060015161228c5760fb5461228c906001600160a01b0316846139a8565b60fb5460fe5460405163d1c2babb60e01b81526004810186905260248101919091526001600160a01b039091169063d1c2babb90604401600060405180830381600087803b1580156122dd57600080fd5b505af11580156122f1573d6000803e3d6000fd5b5050505060fe5483600080516020615b7583398151915260405160405180910390a360fe54604051849086907f4d2378e9171b6731df583e9292af6746a367188bbb37d26519ff76c490779a8c90600090a45050919050565b6060600061235783612a96565b9050806001600160401b0381111561237157612371615163565b60405190808252806020026020018201604052801561239a578160200160208202803683370190505b50915060005b818110156123ee576123b28482611fcb565b8382815181106123c4576123c4615607565b6001600160a01b0390921660209283029190910190910152806123e681615666565b9150506123a0565b5050919050565b6123fd6132bb565b815183511461241f5760405163512509d360e11b815260040160405180910390fd5b60005b83518110156125ce57600084828151811061243f5761243f615607565b60200260200101519050600084838151811061245d5761245d615607565b602002602001015190506000826001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401612495919061514f565b602060405180830381865afa1580156124b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d69190615637565b9050818110156124f957604051637222ae5760e11b815260040160405180910390fd5b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb90612527908890869060040161584d565b6020604051808303816000875af1158015612546573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061256a9190615866565b50826001600160a01b0316856001600160a01b03167f5bf76ef0db3550a96f76d3c13dfa002b5e1df9e4c4d65dce31f074c670b8b648846040516125b091815260200190565b60405180910390a350505080806125c690615666565b915050612422565b50505050565b600080516020615bb58339815191526125eb611fbc565b6001600160a01b0316336001600160a01b0316148061260f575061260f8133611fea565b61262b5760405162461bcd60e51b815260040161095a906155bf565b60fe5460000361264e576040516307ed98ed60e31b815260040160405180910390fd5b60fd5460fe5460405163379607f560e01b815260048101919091526000916001600160a01b03169063379607f5906024016020604051808303816000875af115801561269e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126c29190615637565b905060ff60009054906101000a90046001600160a01b03166001600160a01b031663061873e86040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561271457600080fd5b505af1158015612728573d6000803e3d6000fd5b505050507f27a045625d038b408c8245a43e31996b4872a3f33f53e35b0b83613bf609f2748160405161275d91815260200190565b60405180910390a15050565b6127716132bb565b6001600160a01b03821660008181526101006020526040808220805460ff191685151590811790915590519092917f65c0bffcbb5931f33f25b196feb56c4ff24d6389e20dc395d702d6bd80b7c6b591a35050565b60fc54604080516303aa30b960e11b815290516000926001600160a01b03169163075461729160048083019260209291908290030181865afa158015612810573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061283491906156c5565b6001600160a01b031663d13996086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112cc573d6000803e3d6000fd5b600060fe546000148061288d575060fd546001600160a01b0316155b156128985750600090565b60fd5460fe5460405163d1d58b2560e01b81526001600160a01b039092169163d1d58b25916112af9160040190815260200190565b60606128d76132bb565b610dae84848461319a565b6060600080516020615bb58339815191526128fb611fbc565b6001600160a01b0316336001600160a01b0316148061291f575061291f8133611fea565b61293b5760405162461bcd60e51b815260040161095a906155bf565b861580159061295257506001600160a01b03891615155b156129695761296689898989898989610901565b91505b610b9c611495565b600080516020615bb5833981519152612988611fbc565b6001600160a01b0316336001600160a01b031614806129ac57506129ac8133611fea565b6129c85760405162461bcd60e51b815260040161095a906155bf565b60fe546000036129eb576040516307ed98ed60e31b815260040160405180910390fd5b60fc5460fe54604051637715ee7560e01b81526001600160a01b0390921691637715ee7591612a24918991899189918991600401615883565b600060405180830381600087803b158015612a3e57600080fd5b505af1158015612a52573d6000803e3d6000fd5b505050507f1a9f7513e27a97076aedd1dfbdba6c5a81d7eedccb0aa97b35f5749760b00dde8585604051612a87929190615940565b60405180910390a15050505050565b600081815260c9602052604081206107e690613a39565b610e3c6132bb565b60ff546000906001600160a01b03163314612ae357604051638d1af8bd60e01b815260040160405180910390fd5b60fe54600003612b06576040516307ed98ed60e31b815260040160405180910390fd5b82600003612b2757604051631f2a200560e01b815260040160405180910390fd5b60fe5460fb54612b44916001600160a01b03909116908585613a43565b9050816001600160a01b0316817fb07b8038c5b2bb672154286657edc7c53071ad9f68734047d2801242dc2884ef85604051612b8291815260200190565b60405180910390a392915050565b60008060fc60009054906101000a90046001600160a01b03166001600160a01b031663075461726040518163ffffffff1660e01b8152600401602060405180830381865afa158015612be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c0a91906156c5565b6001600160a01b031663d13996086040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6b9190615637565b60fe5460fb54919250612c88916001600160a01b03169083613e28565b91505090565b612c966132bb565b61010580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f4d5f70ee0a8d3a711838d85eb70ec92b2bc31064955ea4d5396b5f594e2eff7390600090a35050565b612cf16132bb565b6001600160a01b038116612d185760405163d92e233d60e01b815260040160405180910390fd5b61010280546001600160a01b0319166001600160a01b03831690811790915561010154604051908152600080516020615bd583398151915290602001611b52565b612d616132bb565b838214612d815760405163512509d360e11b815260040160405180910390fd5b60005b84811015612e8c576000868683818110612da057612da0615607565b9050602002016020810190612db59190614fc9565b90506000858584818110612dcb57612dcb615607565b905060200201359050816001600160a01b03166342842e0e3086846040518463ffffffff1660e01b8152600401612e0493929190615954565b600060405180830381600087803b158015612e1e57600080fd5b505af1158015612e32573d6000803e3d6000fd5b5050505080826001600160a01b0316856001600160a01b03167f69b434f0c9b48c374f0df0e5a473dcb0b5a1fe6ba4319b3837577d1d87bdbedf60405160405180910390a450508080612e8490615666565b915050612d84565b505050505050565b612e9c6132bb565b6001600160a01b038116612f015760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161095a565b612f0a81613956565b50565b6000818152610103602090815260408083208151608081018352815481526001820180548451818702810187019095528085526060969592948584019390929190830182828015612f8757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612f69575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015612fdf57602002820191906000526020600020905b815481526020019060010190808311612fcb575b505050505081526020016003820154815250509050806000015160000361301957604051632f05f46960e21b815260040160405180910390fd5b611fe3816020015161340c565b60006001600160e01b03198216637965db0b60e01b14806107e657506301ffc9a760e01b6001600160e01b03198316146107e6565b8015806130d45750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90613091903090869060040161561d565b602060405180830381865afa1580156130ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130d29190615637565b155b61313f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161095a565b6131958363095ea7b360e01b848460405160240161315e92919061584d565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613f21565b505050565b6001600160a01b0383166000908152610100602052604090205460609060ff166131d6576040516282b42960e81b815260040160405180910390fd5b6001600160a01b0384166131fd5760405163416aebb560e11b815260040160405180910390fd5b600080856001600160a01b0316858560405161321a929190615978565b6000604051808303816000865af19150503d8060008114613257576040519150601f19603f3d011682016040523d82523d6000602084013e61325c565b606091505b509150915061326b8282613ff6565b9250856001600160a01b03167fb4c5e06eecc8733d1cabe0b2ce47f8a78f693bba8868ac567558478e33db9ee58686866040516132aa93929190615988565b60405180910390a250509392505050565b336132c4611fbc565b6001600160a01b031614611af55760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161095a565b6133248282614096565b600082815260c960205260409020613195908261411c565b6133468282614131565b600082815260c9602052604090206131959082614198565b6001600160a01b03163b151590565b600054610100900460ff166133945760405162461bcd60e51b815260040161095a906159d0565b61339c6141ad565b6133a583613956565b6133bd600080516020615b958339815191528361331a565b60005b81518110156125ce576133fa600080516020615bb58339815191528383815181106133ed576133ed615607565b602002602001015161331a565b8061340481615666565b9150506133c0565b606060008061341a846141dc565b604080516103e8808252617d2082019092529296509094506000935090915060208201617d00803683370190505090506000805b845181101561350c5760005b85828151811061346c5761346c615607565b6020026020010151518110156134f95785828151811061348e5761348e615607565b602002602001015181815181106134a7576134a7615607565b60200260200101518484815181106134c1576134c1615607565b6001600160a01b0390921660209283029190910190910152826134e381615666565b93505080806134f190615666565b91505061345a565b508061350481615666565b91505061344e565b5060005b83518110156135ce5760005b84828151811061352e5761352e615607565b6020026020010151518110156135bb5784828151811061355057613550615607565b6020026020010151818151811061356957613569615607565b602002602001015184848151811061358357613583615607565b6001600160a01b0390921660209283029190910190910152826135a581615666565b93505080806135b390615666565b91505061351c565b50806135c681615666565b915050613510565b506000816001600160401b038111156135e9576135e9615163565b604051908082528060200260200182016040528015613612578160200160208202803683370190505b5090506000805b838110156136ec57600085828151811061363557613635615607565b602002602001015190506000805b8481101561369857826001600160a01b031686828151811061366757613667615607565b60200260200101516001600160a01b0316036136865760019150613698565b8061369081615666565b915050613643565b50806136d757818585815181106136b1576136b1615607565b6001600160a01b0390921660209283029190910190910152836136d381615666565b9450505b505080806136e490615666565b915050613619565b50806001600160401b0381111561370557613705615163565b60405190808252806020026020018201604052801561372e578160200160208202803683370190505b50965060005b818110156137925782818151811061374e5761374e615607565b602002602001015188828151811061376857613768615607565b6001600160a01b03909216602092830291909101909101528061378a81615666565b915050613734565b50505050505050919050565b6000806000806137ad856141dc565b60fe5460fc54604051637715ee7560e01b81529599509397509195509350916001600160a01b0390911690637715ee75906137f090889087908690600401615a1b565b600060405180830381600087803b15801561380a57600080fd5b505af115801561381e573d6000803e3d6000fd5b505060fc546040516333312b5560e11b81526001600160a01b03909116925063666256aa915061385690879086908690600401615a1b565b600060405180830381600087803b15801561387057600080fd5b505af1158015613884573d6000803e3d6000fd5b50505050505050505050565b6131958363a9059cbb60e01b848460405160240161315e92919061584d565b6138b7614c22565b816000036138ed5760405180608001604052806000815260200160008152602001600081526020016000151581525090506107e6565b604051636318523760e01b8152600481018390526001600160a01b03841690636318523790602401608060405180830381865afa158015613932573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fe391906157ca565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b806000036139c9576040516307ed98ed60e31b815260040160405180910390fd5b604051634f8ca21160e11b81526004810182905260006024820152600160448201526001600160a01b03831690639f19442290606401600060405180830381600087803b158015613a1957600080fd5b505af1158015612e8c573d6000803e3d6000fd5b6000611fe38383614900565b60006107e6825490565b600083600003613a66576040516307ed98ed60e31b815260040160405180910390fd5b82600003613a875760405163162908e360e11b815260040160405180910390fd5b6040516370a0823160e01b81526000906001600160a01b038716906370a0823190613ab690309060040161514f565b602060405180830381865afa158015613ad3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613af79190615637565b604051636318523760e01b8152600481018790529091506000906001600160a01b03881690636318523790602401608060405180830381865afa158015613b42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b6691906157ca565b51905080851115613b8a57604051631e9acf1760e31b815260040160405180910390fd5b6000613b968683615723565b60408051600280825260608201835292935060009290916020830190803683370190505090508181600081518110613bd057613bd0615607565b6020026020010181815250508681600181518110613bf057613bf0615607565b60209081029190910101526040516315abf9d160e21b81526001600160a01b038a16906356afe74490613c299084908c90600401615a96565b600060405180830381600087803b158015613c4357600080fd5b505af1158015613c57573d6000803e3d6000fd5b50506040516370a0823160e01b8152600092506001600160a01b038c1691506370a0823190613c8a90309060040161514f565b602060405180830381865afa158015613ca7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ccb9190615637565b9050613cd8856001615835565b8114613cf75760405163870ecf4160e01b815260040160405180910390fd5b6001600160a01b038a16632f745c5930613d12600185615723565b6040518363ffffffff1660e01b8152600401613d2f92919061584d565b602060405180830381865afa158015613d4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d709190615637565b6040516323b872dd60e01b81529096506001600160a01b038b16906323b872dd90613da39030908b908b90600401615954565b600060405180830381600087803b158015613dbd57600080fd5b505af1158015613dd1573d6000803e3d6000fd5b505060408051898152602081018c90528c93506001600160a01b038e1692507f802bea4dd8c92d836bcfa2ba92a8c7547dbc3e882fe032eb62c6ec8d4e707d4e910160405180910390a35050505050949350505050565b600082600003613e3a57506000611fe3565b6040516331a9108f60e11b8152600481018490526000906001600160a01b03861690636352211e90602401602060405180830381865afa158015613e82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ea691906156c5565b604051630748d63560e31b81529091506001600160a01b03861690633a46b1a890613ed7908490879060040161584d565b602060405180830381865afa158015613ef4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f189190615637565b95945050505050565b6000613f76826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661492a9092919063ffffffff16565b9050805160001480613f97575080806020019051810190613f979190615866565b6131955760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161095a565b606082156140055750806107e6565b6044825110156140635760405162461bcd60e51b815260206004820152602360248201527f63616c6c206661696c656420776974686f75742061207265766572742072656160448201526239b7b760e91b606482015260840161095a565b6004820191508180602001905181019061407d9190615ab8565b60405162461bcd60e51b815260040161095a9190615529565b6140a08282611fea565b610dc85760008281526097602090815260408083206001600160a01b03851684529091529020805460ff191660011790556140d83390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000611fe3836001600160a01b038416614939565b61413b8282611fea565b15610dc85760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000611fe3836001600160a01b038416614988565b600054610100900460ff166141d45760405162461bcd60e51b815260040161095a906159d0565b611af5614a7b565b60608060608084516001600160401b038111156141fb576141fb615163565b604051908082528060200260200182016040528015614224578160200160208202803683370190505b50935084516001600160401b0381111561424057614240615163565b604051908082528060200260200182016040528015614269578160200160208202803683370190505b50925060005b85518110156144465760fc5486516000916001600160a01b03169063b9a09fd5908990859081106142a2576142a2615607565b60200260200101516040518263ffffffff1660e01b81526004016142c6919061514f565b602060405180830381865afa1580156142e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061430791906156c5565b60fc54604051637572079360e11b81529192506001600160a01b03169063eae40f269061433890849060040161514f565b602060405180830381865afa158015614355573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061437991906156c5565b85838151811061438b5761438b615607565b6001600160a01b03928316602091820292909201015260fc5460405163ae21c4cb60e01b815291169063ae21c4cb906143c890849060040161514f565b602060405180830381865afa1580156143e5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061440991906156c5565b86838151811061441b5761441b615607565b6001600160a01b0390921660209283029190910190910152508061443e81615666565b91505061426f565b5083516001600160401b0381111561446057614460615163565b60405190808252806020026020018201604052801561449357816020015b606081526020019060019003908161447e5790505b50915060005b845181101561469f5760008582815181106144b6576144b6615607565b6020026020010151905060006001600160a01b0316816001600160a01b03160361450e5760408051600081526020810190915284518590849081106144fd576144fd615607565b60200260200101819052505061468d565b6000816001600160a01b031663e68863966040518163ffffffff1660e01b8152600401602060405180830381865afa15801561454e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145729190615637565b90506000816001600160401b0381111561458e5761458e615163565b6040519080825280602002602001820160405280156145b7578160200160208202803683370190505b50905060005b8281101561466a57604051637bb7bed160e01b8152600481018290526001600160a01b03851690637bb7bed190602401602060405180830381865afa15801561460a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061462e91906156c5565b82828151811061464057614640615607565b6001600160a01b03909216602092830291909101909101528061466281615666565b9150506145bd565b508086858151811061467e5761467e615607565b60200260200101819052505050505b8061469781615666565b915050614499565b5082516001600160401b038111156146b9576146b9615163565b6040519080825280602002602001820160405280156146ec57816020015b60608152602001906001900390816146d75790505b50905060005b83518110156148f857600084828151811061470f5761470f615607565b6020026020010151905060006001600160a01b0316816001600160a01b03160361476757604080516000815260208101909152835184908490811061475657614756615607565b6020026020010181905250506148e6565b6000816001600160a01b031663e68863966040518163ffffffff1660e01b8152600401602060405180830381865afa1580156147a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147cb9190615637565b90506000816001600160401b038111156147e7576147e7615163565b604051908082528060200260200182016040528015614810578160200160208202803683370190505b50905060005b828110156148c357604051637bb7bed160e01b8152600481018290526001600160a01b03851690637bb7bed190602401602060405180830381865afa158015614863573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061488791906156c5565b82828151811061489957614899615607565b6001600160a01b0390921660209283029190910190910152806148bb81615666565b915050614816565b50808585815181106148d7576148d7615607565b60200260200101819052505050505b806148f081615666565b9150506146f2565b509193509193565b600082600001828154811061491757614917615607565b9060005260206000200154905092915050565b6060610dae8484600085614aab565b6000818152600183016020526040812054614980575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556107e6565b5060006107e6565b60008181526001830160205260408120548015614a715760006149ac600183615723565b85549091506000906149c090600190615723565b9050818114614a255760008660000182815481106149e0576149e0615607565b9060005260206000200154905080876000018481548110614a0357614a03615607565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614a3657614a36615b42565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506107e6565b60009150506107e6565b600054610100900460ff16614aa25760405162461bcd60e51b815260040161095a906159d0565b611af533613956565b606082471015614b0c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161095a565b600080866001600160a01b03168587604051614b289190615b58565b60006040518083038185875af1925050503d8060008114614b65576040519150601f19603f3d011682016040523d82523d6000602084013e614b6a565b606091505b5091509150614b7b87838387614b86565b979650505050505050565b60608315614bf3578251600003614bec57614ba08561335e565b614bec5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161095a565b5081610dae565b610dae8383815115614c085781518083602001fd5b8060405162461bcd60e51b815260040161095a9190615529565b60405180608001604052806000815260200160008152602001600081526020016000151581525090565b828054828255906000526020600020908101928215614ca1579160200282015b82811115614ca157825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190614c6c565b506116da929150614ce8565b828054828255906000526020600020908101928215614ca1579160200282015b82811115614ca1578251825591602001919060010190614ccd565b5b808211156116da5760008155600101614ce9565b600060208284031215614d0f57600080fd5b81356001600160e01b031981168114611fe357600080fd5b600060208284031215614d3957600080fd5b5035919050565b6001600160a01b0381168114612f0a57600080fd5b8035614d6081614d40565b919050565b60008083601f840112614d7757600080fd5b5081356001600160401b03811115614d8e57600080fd5b602083019150836020828501011115614da657600080fd5b9250929050565b600080600080600060808688031215614dc557600080fd5b8535614dd081614d40565b94506020860135614de081614d40565b93506040860135925060608601356001600160401b03811115614e0257600080fd5b614e0e88828901614d65565b969995985093965092949392505050565b60008083601f840112614e3157600080fd5b5081356001600160401b03811115614e4857600080fd5b6020830191508360208260051b8501011115614da657600080fd5b60008060008060008060006080888a031215614e7e57600080fd5b8735614e8981614d40565b965060208801356001600160401b0380821115614ea557600080fd5b614eb18b838c01614e1f565b909850965060408a0135915080821115614eca57600080fd5b614ed68b838c01614e1f565b909650945060608a0135915080821115614eef57600080fd5b50614efc8a828b01614e1f565b989b979a50959850939692959293505050565b60005b83811015614f2a578181015183820152602001614f12565b838111156125ce5750506000910152565b60008151808452614f53816020860160208601614f0f565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015614fbc57603f19888603018452614faa858351614f3b565b94509285019290850190600101614f8e565b5092979650505050505050565b600060208284031215614fdb57600080fd5b8135611fe381614d40565b600081518084526020808501945080840160005b8381101561501f5781516001600160a01b031687529582019590820190600101614ffa565b509495945050505050565b600081518084526020808501945080840160005b8381101561501f5781518752958201959082019060010161503e565b6020815281516020820152600060208301516080604084015261508060a0840182614fe6565b90506040840151601f1984830301606085015261509d828261502a565b915050606084015160808401528091505092915050565b600080600080604085870312156150ca57600080fd5b84356001600160401b03808211156150e157600080fd5b6150ed88838901614e1f565b9096509450602087013591508082111561510657600080fd5b5061511387828801614e1f565b95989497509550505050565b6000806040838503121561513257600080fd5b82359150602083013561514481614d40565b809150509250929050565b6001600160a01b0391909116815260200190565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156151a1576151a1615163565b604052919050565b60006001600160401b038211156151c2576151c2615163565b5060051b60200190565b600080600080600080600060e0888a0312156151e757600080fd5b87356151f281614d40565b965060208881013561520381614d40565b9650604089013561521381614d40565b9550606089013561522381614d40565b9450608089013561523381614d40565b935060a089013561524381614d40565b925060c08901356001600160401b0381111561525e57600080fd5b8901601f81018b1361526f57600080fd5b803561528261527d826151a9565b615179565b81815260059190911b8201830190838101908d8311156152a157600080fd5b928401925b828410156152c85783356152b981614d40565b825292840192908401906152a6565b809550505050505092959891949750929550565b6040815260006152ef6040830185614fe6565b8281036020840152613f18818561502a565b6000806040838503121561531457600080fd5b50508035926020909101359150565b60008060006060848603121561533857600080fd5b505081359360208301359350604090920135919050565b602081526000611fe36020830184614fe6565b600082601f83011261537357600080fd5b8135602061538361527d836151a9565b82815260059290921b840181019181810190868411156153a257600080fd5b8286015b848110156153bd57803583529183019183016153a6565b509695505050505050565b6000806000606084860312156153dd57600080fd5b83356001600160401b03808211156153f457600080fd5b818601915086601f83011261540857600080fd5b8135602061541861527d836151a9565b82815260059290921b8401810191818101908a84111561543757600080fd5b948201945b8386101561545e57853561544f81614d40565b8252948201949082019061543c565b9750508701359250508082111561547457600080fd5b5061548186828701615362565b92505061549060408501614d55565b90509250925092565b8015158114612f0a57600080fd5b600080604083850312156154ba57600080fd5b82356154c581614d40565b9150602083013561514481615499565b6000806000604084860312156154ea57600080fd5b83356154f581614d40565b925060208401356001600160401b0381111561551057600080fd5b61551c86828701614d65565b9497909650939450505050565b602081526000611fe36020830184614f3b565b60008060008060006060868803121561555457600080fd5b85356001600160401b038082111561556b57600080fd5b61557789838a01614e1f565b9097509550602088013591508082111561559057600080fd5b5061559d88828901614e1f565b90945092505060408601356155b181614d40565b809150509295509295909350565b60208082526028908201527f43616c6c6572206973206e6f74206f776e6572206f722068617320726571756960408201526772656420726f6c6560c01b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0392831681529116602082015260400190565b60006020828403121561564957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60006001820161567857615678615650565b5060010190565b6000808335601e1984360301811261569657600080fd5b8301803591506001600160401b038211156156b057600080fd5b602001915036819003821315614da657600080fd5b6000602082840312156156d757600080fd5b8151611fe381614d40565b60008160001904831182151516156156fc576156fc615650565b500290565b60008261571e57634e487b7160e01b600052601260045260246000fd5b500490565b60008282101561573557615735615650565b500390565b8183526000602080850194508260005b8581101561501f57813561575d81614d40565b6001600160a01b03168752958201959082019060010161574a565b60408152600061578c60408301868861573a565b82810360208401528381526001600160fb1b038411156157ab57600080fd5b8360051b80866020840137600091016020019081529695505050505050565b6000608082840312156157dc57600080fd5b604051608081016001600160401b03811182821017156157fe576157fe615163565b8060405250825181526020830151602082015260408301516040820152606083015161582981615499565b60608201529392505050565b6000821982111561584857615848615650565b500190565b6001600160a01b03929092168252602082015260400190565b60006020828403121561587857600080fd5b8151611fe381615499565b60608152600061589760608301878961573a565b60208382038185015281868352818301905060058288821b8501018960005b8a81101561592657868303601f190185528135368d9003601e190181126158dc57600080fd5b8c0180356001600160401b038111156158f457600080fd5b80861b36038e131561590557600080fd5b61591285828a850161573a565b9688019694505050908501906001016158b6565b505080955050505050508260408301529695505050505050565b602081526000610dae60208301848661573a565b6001600160a01b039384168152919092166020820152604081019190915260600190565b8183823760009101908152919050565b60408152826040820152828460608301376000606084830101526000601f19601f850116820160608382030160208401526159c66060820185614f3b565b9695505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b606081526000615a2e6060830186614fe6565b6020838203818501528186518084528284019150828160051b85010183890160005b83811015615a7e57601f19878403018552615a6c838351614fe6565b94860194925090850190600101615a50565b50508095505050505050826040830152949350505050565b604081526000615aa9604083018561502a565b90508260208301529392505050565b600060208284031215615aca57600080fd5b81516001600160401b0380821115615ae157600080fd5b818401915084601f830112615af557600080fd5b815181811115615b0757615b07615163565b615b1a601f8201601f1916602001615179565b9150808252856020828501011115615b3157600080fd5b610dac816020840160208601614f0f565b634e487b7160e01b600052603160045260246000fd5b60008251615b6a818460208701614f0f565b919091019291505056fec9abff9563eddda3f468d65834853d56c489df02bd5ac658dddd56505f0f9dfe85d36e3b488c35c2a15344b305cb84e2000f26d4f3a7c1e8a516f0e82aee752ae3723f41c074e25ac45636a7cd631386f2e15f8583ade05d0b710b41251f5c7b2cf325792651b724d47f21230be0dd9729866cadd370618845e23a48555ef042a2646970667358221220fb3ccf01d2652335ed3ad4c0d9ba1d1238ccc9de7e3fb123f16135bbf15960b264736f6c634300080d0033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102b45760003560e01c806301ffc9a7146102b9578063106fffe9146102e157806312a70f0b14610302578063150b7a0214610329578063154cb5a814610361578063177f3389146103815780632488d909146103a5578063248a9ca3146103c557806324a9d853146103e857806324c20eec146103f2578063268b8c691461040757806328df5d46146104445780632f2ff15d1461045757806336568abe1461046c5780633b92eb231461047f5780633f2a55401461049f57806342a82b4f146104b2578063460258c9146104c557806346904840146104e657806346c73397146104fa57806346c96aac14610504578063507436231461051757806357b2a88b1461051f57806358396580146105325780636817031b1461053a5780636f054a3d1461054d5780636f816a201461058a578063715018a61461059d57806372c27b62146105a557806378a6cc09146105b857806379347371146105cd5780637ad559d0146105e05780638da5cb5b146105f35780639010d07c146105fb57806391d148541461060e57806391d2b32e14610621578063991ba73114610629578063a217fddf1461063c578063a3246ad314610644578063b3aa527d14610664578063b4cd143a14610677578063b8d3d3081461067f578063b97dd9e214610692578063b9bf8a0a1461069a578063bca8c7b5146106a2578063c2606476146106c2578063c2b79e98146106d5578063ca15c873146106e8578063d547741f146106fb578063d753dcc81461070e578063d907b13014610717578063de97674f1461072a578063e59171d014610732578063e74b981b14610745578063e93900a314610758578063f25d8a4414610761578063f2fde38b14610774578063f66e311b14610787578063fbfa77cf1461079b578063fef27b02146107ae575b600080fd5b6102cc6102c7366004614cfd565b6107c1565b60405190151581526020015b60405180910390f35b6102f46102ef366004614d27565b6107ec565b6040519081526020016102d8565b6102f47fa0cc82bfc6a0e1fd4746daa2c96f2cbac6feca4912d2b7f78808a14ff40807db81565b610348610337366004614dad565b630a85bd0160e11b95945050505050565b6040516001600160e01b031990911681526020016102d8565b61037461036f366004614e63565b610901565b6040516102d89190614f67565b6102cc61038f366004614fc9565b6101006020526000908152604090205460ff1681565b6103b86103b3366004614d27565b610ba9565b6040516102d8919061505a565b6102f46103d3366004614d27565b60009081526097602052604090206001015490565b6102f46101015481565b6102f4600080516020615b9583398151915281565b61042f610415366004614d27565b610103602052600090815260409020805460039091015482565b604080519283526020830191909152016102d8565b6103746104523660046150b4565b610cbd565b61046a61046536600461511f565b610db6565b005b61046a61047a36600461511f565b610dcc565b60fb54610492906001600160a01b031681565b6040516102d8919061514f565b60fd54610492906001600160a01b031681565b61046a6104c03660046151cc565b610e46565b6104d86104d3366004614d27565b61102f565b6040516102d89291906152dc565b61010254610492906001600160a01b031681565b6102f46101045481565b60fc54610492906001600160a01b031681565b6102f4611264565b61046a61052d366004614d27565b6112f5565b6102f4611495565b61046a610548366004614fc9565b6116de565b61055561175f565b6040516102d8919081518152602080830151908201526040808301519082015260609182015115159181019190915260800190565b61046a6105983660046150b4565b611782565b61046a611ae3565b61046a6105b3366004614d27565b611af7565b6102f4600080516020615bb583398151915281565b61046a6105db366004615301565b611b5d565b61046a6105ee366004615323565b611d10565b610492611fbc565b610492610609366004615301565b611fcb565b6102cc61061c36600461511f565b611fea565b6102f4612015565b6102f4610637366004614d27565b612037565b6102f4600081565b610657610652366004614d27565b61234a565b6040516102d8919061534f565b61046a6106723660046153c8565b6123f5565b61046a6125d4565b61046a61068d3660046154a7565b612769565b6102f46127c6565b6102f4612871565b6106b56106b03660046154d5565b6128cd565b6040516102d89190615529565b6103746106d0366004614e63565b6128e2565b61046a6106e33660046150b4565b612971565b6102f46106f6366004614d27565b612a96565b61046a61070936600461511f565b612aad565b610104546102f4565b6102f461072536600461511f565b612ab5565b6102f4612b90565b61046a610740366004614fc9565b612c8e565b61046a610753366004614fc9565b612ce9565b6102f460fe5481565b61046a61076f36600461553c565b612d59565b61046a610782366004614fc9565b612e94565b61010554610492906001600160a01b031681565b60ff54610492906001600160a01b031681565b6106576107bc366004614d27565b612f0d565b60006001600160e01b03198216635a05180f60e01b14806107e657506107e682613026565b92915050565b60008181526101036020908152604080832081516080810183528154815260018201805484518187028101870190955280855286959294858401939092919083018282801561086457602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610846575b50505050508152602001600282018054806020026020016040519081016040528092919081815260200182805480156108bc57602002820191906000526020600020905b8154815260200190600101908083116108a8575b50505050508152602001600382015481525050905080600001516000036108f657604051632f05f46960e21b815260040160405180910390fd5b602001515192915050565b6060600080516020615bb583398151915261091a611fbc565b6001600160a01b0316336001600160a01b0316148061093e575061093e8133611fea565b6109635760405162461bcd60e51b815260040161095a906155bf565b60405180910390fd5b6001600160a01b0389166000908152610100602052604090205460ff1661099c576040516282b42960e81b815260040160405180910390fd5b8483146109bc57604051634ec4810560e11b815260040160405180910390fd5b60005b85811015610ae55760008787838181106109db576109db615607565b90506020020160208101906109f09190614fc9565b90506000816001600160a01b031663dd62ed3e308e6040518363ffffffff1660e01b8152600401610a2292919061561d565b602060405180830381865afa158015610a3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a639190615637565b9050868684818110610a7757610a77615607565b90506020020135811015610ad057610a9a6001600160a01b0383168d600061305b565b610ad08c888886818110610ab057610ab0615607565b90506020020135846001600160a01b031661305b9092919063ffffffff16565b50508080610add90615666565b9150506109bf565b50866001600160401b03811115610afe57610afe615163565b604051908082528060200260200182016040528015610b3157816020015b6060815260200190600190039081610b1c5790505b50915060005b87811015610b9c57610b6c8a8a8a84818110610b5557610b55615607565b9050602002810190610b67919061567f565b61319a565b838281518110610b7e57610b7e615607565b60200260200101819052508080610b9490615666565b915050610b37565b5050979650505050505050565b610bd46040518060800160405280600081526020016060815260200160608152602001600081525090565b6000828152610103602090815260409182902082516080810184528154815260018201805485518186028101860190965280865291949293858101939290830182828015610c4b57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610c2d575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015610ca357602002820191906000526020600020905b815481526020019060010190808311610c8f575b505050505081526020016003820154815250509050919050565b6060610cc76132bb565b838214610ce757604051634ec4810560e11b815260040160405180910390fd5b836001600160401b03811115610cff57610cff615163565b604051908082528060200260200182016040528015610d3257816020015b6060815260200190600190039081610d1d5790505b50905060005b84811015610dac57610d7c868683818110610d5557610d55615607565b9050602002016020810190610d6a9190614fc9565b858584818110610b5557610b55615607565b828281518110610d8e57610d8e615607565b60200260200101819052508080610da490615666565b915050610d38565b505b949350505050565b610dbe6132bb565b610dc8828261331a565b5050565b6001600160a01b0381163314610e3c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161095a565b610dc8828261333c565b600054610100900460ff1615808015610e665750600054600160ff909116105b80610e875750610e753061335e565b158015610e87575060005460ff166001145b610eea5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161095a565b6000805460ff191660011790558015610f0d576000805461ff0019166101001790555b610f1884848461336d565b6001600160a01b0388161580610f3557506001600160a01b038716155b80610f4757506001600160a01b038616155b15610f655760405163d92e233d60e01b815260040160405180910390fd5b60fb80546001600160a01b03808b166001600160a01b03199283161790925560fc80548a841690831617905560fd8054898416908316179055610105805492881692909116919091179055600061010155610fbe611fbc565b61010280546001600160a01b0319166001600160a01b03929092169190911790558015611025576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050505050565b6060806000610103600085815260200190815260200160002060405180608001604052908160008201548152602001600182018054806020026020016040519081016040528092919081815260200182805480156110b657602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611098575b505050505081526020016002820180548060200260200160405190810160405280929190818152602001828054801561110e57602002820191906000526020600020905b8154815260200190600101908083116110fa575b505050505081526020016003820154815250509050806000015160000361114857604051632f05f46960e21b815260040160405180910390fd5b611155816020015161340c565b925082516001600160401b0381111561117057611170615163565b604051908082528060200260200182016040528015611199578160200160208202803683370190505b50915060005b835181101561125d578381815181106111ba576111ba615607565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016111ed919061514f565b602060405180830381865afa15801561120a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061122e9190615637565b83828151811061124057611240615607565b60209081029190910101528061125581615666565b91505061119f565b5050915091565b610105546000906001600160a01b031661127e5750600090565b610105546040516370a0823160e01b81526001600160a01b03909116906370a08231906112af90309060040161514f565b602060405180830381865afa1580156112cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112f09190615637565b905090565b600080516020615bb583398151915261130c611fbc565b6001600160a01b0316336001600160a01b0316148061133057506113308133611fea565b61134c5760405162461bcd60e51b815260040161095a906155bf565b60008281526101036020908152604080832081516080810183528154815260018201805484518187028101870190955280855291949293858401939092908301828280156113c357602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116113a5575b505050505081526020016002820180548060200260200160405190810160405280929190818152602001828054801561141b57602002820191906000526020600020905b815481526020019060010190808311611407575b505050505081526020016003820154815250509050806000015160000361145557604051632f05f46960e21b815260040160405180910390fd5b611462816020015161379e565b60fe5460405184907f38be9b012e428704c0fb2b81dfd53444b76ac4cd45c46cfd2d661f73d97cf47b90600090a3505050565b6000600080516020615bb58339815191526114ae611fbc565b6001600160a01b0316336001600160a01b031614806114d257506114d28133611fea565b6114ee5760405162461bcd60e51b815260040161095a906155bf565b60ff5460408051632fbe4c6560e11b815290516000926001600160a01b031691635f7c98ca9160048083019260209291908290030181865afa158015611538573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155c91906156c5565b6040516370a0823160e01b81529091506001600160a01b038216906370a082319061158b90309060040161514f565b602060405180830381865afa1580156115a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115cc9190615637565b925082156116d857600061271061010154856115e891906156e2565b6115f29190615701565b905060006116008286615723565b905081156116235761010254611623906001600160a01b03858116911684613890565b80156116a25760ff54611643906001600160a01b03858116911683613890565b60ff546040516360993b5b60e01b8152600481018390526001600160a01b03909116906360993b5b90602401600060405180830381600087803b15801561168957600080fd5b505af115801561169d573d6000803e3d6000fd5b505050505b6040518581527ff9a5da3a173eca8cd77c02ece3ff1467b8aa461ed3822201817f2d72fbc542839060200160405180910390a150505b505b5090565b6116e66132bb565b6001600160a01b03811661170d5760405163d92e233d60e01b815260040160405180910390fd5b60ff80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f483bdedaaf23706a9800ac1af0d852b34927780d79f9d6ba60a80c7cad75ea3990600090a35050565b611767614c22565b60fe5460fb546112f0916001600160a01b03909116906138af565b600080516020615bb5833981519152611799611fbc565b6001600160a01b0316336001600160a01b031614806117bd57506117bd8133611fea565b6117d95760405162461bcd60e51b815260040161095a906155bf565b60fe546000036117fc576040516307ed98ed60e31b815260040160405180910390fd5b83821461181c57604051634ec4810560e11b815260040160405180910390fd5b60fc54604080516303aa30b960e11b815290516000926001600160a01b03169163075461729160048083019260209291908290030181865afa158015611866573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188a91906156c5565b6001600160a01b031663d13996086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118eb9190615637565b60fc5460405163037c0b5160e51b81529192506001600160a01b031690636f816a2090611922908990899089908990600401615778565b600060405180830381600087803b15801561193c57600080fd5b505af1158015611950573d6000803e3d6000fd5b5050505060ff60009054906101000a90046001600160a01b03166001600160a01b031663b59ca7996040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156119a457600080fd5b505af11580156119b8573d6000803e3d6000fd5b50505050806101048190555060405180608001604052808281526020018787808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505050908252506040805160208781028281018201909352878252928301929091889188918291850190849080828437600092018290525093855250504260209384015250838152610103825260409020825181558282015180519192611a7392600185019290910190614c4c565b5060408201518051611a8f916002840191602090910190614cad565b5060608201518160030155905050807f1383afe130223102b4c91dedfa02425285670061011d89d4fc94945a36175df387878787604051611ad39493929190615778565b60405180910390a2505050505050565b611aeb6132bb565b611af56000613956565b565b611aff6132bb565b611388811115611b22576040516358d620b360e01b815260040160405180910390fd5b610101819055610102546040518281526001600160a01b0390911690600080516020615bd5833981519152906020015b60405180910390a250565b60ff546001600160a01b03163314611b8857604051638d1af8bd60e01b815260040160405180910390fd5b60fb54604051636318523760e01b8152600481018490526000916001600160a01b031690636318523790602401608060405180830381865afa158015611bd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf691906157ca565b80519091508214611c1a576040516355e97b0d60e01b815260040160405180910390fd5b8060600151611c395760fb54611c39906001600160a01b0316846139a8565b60fe54600003611c4d5760fe839055611cd5565b60fb5460fe5460405163d1c2babb60e01b81526004810186905260248101919091526001600160a01b039091169063d1c2babb90604401600060405180830381600087803b158015611c9e57600080fd5b505af1158015611cb2573d6000803e3d6000fd5b5050505060fe5483600080516020615b7583398151915260405160405180910390a35b60fe546040518381527f7c2fb9c31dd32c6d7ef4e5cfd9b9b881983baf79919f2cef97485cd0d79cae299060200160405180910390a2505050565b600080516020615bb5833981519152611d27611fbc565b6001600160a01b0316336001600160a01b03161480611d4b5750611d4b8133611fea565b611d675760405162461bcd60e51b815260040161095a906155bf565b6000848152610103602090815260408083208151608081018352815481526001820180548451818702810187019095528085529194929385840193909290830182828015611dde57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611dc0575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015611e3657602002820191906000526020600020905b815481526020019060010190808311611e22575b5050505050815260200160038201548152505090508060000151600003611e7057604051632f05f46960e21b815260040160405180910390fd5b82841180611e8357508060200151518310155b15611ea15760405163561ce9bb60e01b815260040160405180910390fd5b6000611ead8585615723565b611eb8906001615835565b90506000816001600160401b03811115611ed457611ed4615163565b604051908082528060200260200182016040528015611efd578160200160208202803683370190505b50905060005b82811015611f6e576020840151611f1a8289615835565b81518110611f2a57611f2a615607565b6020026020010151828281518110611f4457611f44615607565b6001600160a01b039092166020928302919091019091015280611f6681615666565b915050611f03565b50611f788161379e565b85877fe8f47b8ff1a31cd79215962a688b3481eda9173260e1bdb9eac4bad798f393cf87604051611fab91815260200190565b60405180910390a350505050505050565b6033546001600160a01b031690565b600082815260c960205260408120611fe39083613a2d565b9392505050565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60fe5460fb54600091612031916001600160a01b0316906138af565b51919050565b6000600080516020615bb5833981519152612050611fbc565b6001600160a01b0316336001600160a01b0316148061207457506120748133611fea565b6120905760405162461bcd60e51b815260040161095a906155bf565b610105546001600160a01b03166120ba5760405163811d56f560e01b815260040160405180910390fd5b826000036120db57604051631f2a200560e01b815260040160405180910390fd5b60fe546000036120fe576040516307ed98ed60e31b815260040160405180910390fd5b61010554604051639130325d60e01b8152600481018590523060248201526001600160a01b0390911690639130325d906044016020604051808303816000875af192505050801561216c575060408051601f3d908101601f1916820190925261216991810190615637565b60015b6121fa57610105546040516362994c0560e01b815260048101859052602481018590523060448201524260648201526001600160a01b03909116906362994c05906084016020604051808303816000875af11580156121cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121f39190615637565b91506121fd565b91505b60fb54604051636318523760e01b8152600481018490526000916001600160a01b031690636318523790602401608060405180830381865afa158015612247573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226b91906157ca565b9050806060015161228c5760fb5461228c906001600160a01b0316846139a8565b60fb5460fe5460405163d1c2babb60e01b81526004810186905260248101919091526001600160a01b039091169063d1c2babb90604401600060405180830381600087803b1580156122dd57600080fd5b505af11580156122f1573d6000803e3d6000fd5b5050505060fe5483600080516020615b7583398151915260405160405180910390a360fe54604051849086907f4d2378e9171b6731df583e9292af6746a367188bbb37d26519ff76c490779a8c90600090a45050919050565b6060600061235783612a96565b9050806001600160401b0381111561237157612371615163565b60405190808252806020026020018201604052801561239a578160200160208202803683370190505b50915060005b818110156123ee576123b28482611fcb565b8382815181106123c4576123c4615607565b6001600160a01b0390921660209283029190910190910152806123e681615666565b9150506123a0565b5050919050565b6123fd6132bb565b815183511461241f5760405163512509d360e11b815260040160405180910390fd5b60005b83518110156125ce57600084828151811061243f5761243f615607565b60200260200101519050600084838151811061245d5761245d615607565b602002602001015190506000826001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401612495919061514f565b602060405180830381865afa1580156124b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d69190615637565b9050818110156124f957604051637222ae5760e11b815260040160405180910390fd5b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb90612527908890869060040161584d565b6020604051808303816000875af1158015612546573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061256a9190615866565b50826001600160a01b0316856001600160a01b03167f5bf76ef0db3550a96f76d3c13dfa002b5e1df9e4c4d65dce31f074c670b8b648846040516125b091815260200190565b60405180910390a350505080806125c690615666565b915050612422565b50505050565b600080516020615bb58339815191526125eb611fbc565b6001600160a01b0316336001600160a01b0316148061260f575061260f8133611fea565b61262b5760405162461bcd60e51b815260040161095a906155bf565b60fe5460000361264e576040516307ed98ed60e31b815260040160405180910390fd5b60fd5460fe5460405163379607f560e01b815260048101919091526000916001600160a01b03169063379607f5906024016020604051808303816000875af115801561269e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126c29190615637565b905060ff60009054906101000a90046001600160a01b03166001600160a01b031663061873e86040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561271457600080fd5b505af1158015612728573d6000803e3d6000fd5b505050507f27a045625d038b408c8245a43e31996b4872a3f33f53e35b0b83613bf609f2748160405161275d91815260200190565b60405180910390a15050565b6127716132bb565b6001600160a01b03821660008181526101006020526040808220805460ff191685151590811790915590519092917f65c0bffcbb5931f33f25b196feb56c4ff24d6389e20dc395d702d6bd80b7c6b591a35050565b60fc54604080516303aa30b960e11b815290516000926001600160a01b03169163075461729160048083019260209291908290030181865afa158015612810573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061283491906156c5565b6001600160a01b031663d13996086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112cc573d6000803e3d6000fd5b600060fe546000148061288d575060fd546001600160a01b0316155b156128985750600090565b60fd5460fe5460405163d1d58b2560e01b81526001600160a01b039092169163d1d58b25916112af9160040190815260200190565b60606128d76132bb565b610dae84848461319a565b6060600080516020615bb58339815191526128fb611fbc565b6001600160a01b0316336001600160a01b0316148061291f575061291f8133611fea565b61293b5760405162461bcd60e51b815260040161095a906155bf565b861580159061295257506001600160a01b03891615155b156129695761296689898989898989610901565b91505b610b9c611495565b600080516020615bb5833981519152612988611fbc565b6001600160a01b0316336001600160a01b031614806129ac57506129ac8133611fea565b6129c85760405162461bcd60e51b815260040161095a906155bf565b60fe546000036129eb576040516307ed98ed60e31b815260040160405180910390fd5b60fc5460fe54604051637715ee7560e01b81526001600160a01b0390921691637715ee7591612a24918991899189918991600401615883565b600060405180830381600087803b158015612a3e57600080fd5b505af1158015612a52573d6000803e3d6000fd5b505050507f1a9f7513e27a97076aedd1dfbdba6c5a81d7eedccb0aa97b35f5749760b00dde8585604051612a87929190615940565b60405180910390a15050505050565b600081815260c9602052604081206107e690613a39565b610e3c6132bb565b60ff546000906001600160a01b03163314612ae357604051638d1af8bd60e01b815260040160405180910390fd5b60fe54600003612b06576040516307ed98ed60e31b815260040160405180910390fd5b82600003612b2757604051631f2a200560e01b815260040160405180910390fd5b60fe5460fb54612b44916001600160a01b03909116908585613a43565b9050816001600160a01b0316817fb07b8038c5b2bb672154286657edc7c53071ad9f68734047d2801242dc2884ef85604051612b8291815260200190565b60405180910390a392915050565b60008060fc60009054906101000a90046001600160a01b03166001600160a01b031663075461726040518163ffffffff1660e01b8152600401602060405180830381865afa158015612be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c0a91906156c5565b6001600160a01b031663d13996086040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6b9190615637565b60fe5460fb54919250612c88916001600160a01b03169083613e28565b91505090565b612c966132bb565b61010580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f4d5f70ee0a8d3a711838d85eb70ec92b2bc31064955ea4d5396b5f594e2eff7390600090a35050565b612cf16132bb565b6001600160a01b038116612d185760405163d92e233d60e01b815260040160405180910390fd5b61010280546001600160a01b0319166001600160a01b03831690811790915561010154604051908152600080516020615bd583398151915290602001611b52565b612d616132bb565b838214612d815760405163512509d360e11b815260040160405180910390fd5b60005b84811015612e8c576000868683818110612da057612da0615607565b9050602002016020810190612db59190614fc9565b90506000858584818110612dcb57612dcb615607565b905060200201359050816001600160a01b03166342842e0e3086846040518463ffffffff1660e01b8152600401612e0493929190615954565b600060405180830381600087803b158015612e1e57600080fd5b505af1158015612e32573d6000803e3d6000fd5b5050505080826001600160a01b0316856001600160a01b03167f69b434f0c9b48c374f0df0e5a473dcb0b5a1fe6ba4319b3837577d1d87bdbedf60405160405180910390a450508080612e8490615666565b915050612d84565b505050505050565b612e9c6132bb565b6001600160a01b038116612f015760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161095a565b612f0a81613956565b50565b6000818152610103602090815260408083208151608081018352815481526001820180548451818702810187019095528085526060969592948584019390929190830182828015612f8757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311612f69575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015612fdf57602002820191906000526020600020905b815481526020019060010190808311612fcb575b505050505081526020016003820154815250509050806000015160000361301957604051632f05f46960e21b815260040160405180910390fd5b611fe3816020015161340c565b60006001600160e01b03198216637965db0b60e01b14806107e657506301ffc9a760e01b6001600160e01b03198316146107e6565b8015806130d45750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90613091903090869060040161561d565b602060405180830381865afa1580156130ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130d29190615637565b155b61313f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161095a565b6131958363095ea7b360e01b848460405160240161315e92919061584d565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613f21565b505050565b6001600160a01b0383166000908152610100602052604090205460609060ff166131d6576040516282b42960e81b815260040160405180910390fd5b6001600160a01b0384166131fd5760405163416aebb560e11b815260040160405180910390fd5b600080856001600160a01b0316858560405161321a929190615978565b6000604051808303816000865af19150503d8060008114613257576040519150601f19603f3d011682016040523d82523d6000602084013e61325c565b606091505b509150915061326b8282613ff6565b9250856001600160a01b03167fb4c5e06eecc8733d1cabe0b2ce47f8a78f693bba8868ac567558478e33db9ee58686866040516132aa93929190615988565b60405180910390a250509392505050565b336132c4611fbc565b6001600160a01b031614611af55760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161095a565b6133248282614096565b600082815260c960205260409020613195908261411c565b6133468282614131565b600082815260c9602052604090206131959082614198565b6001600160a01b03163b151590565b600054610100900460ff166133945760405162461bcd60e51b815260040161095a906159d0565b61339c6141ad565b6133a583613956565b6133bd600080516020615b958339815191528361331a565b60005b81518110156125ce576133fa600080516020615bb58339815191528383815181106133ed576133ed615607565b602002602001015161331a565b8061340481615666565b9150506133c0565b606060008061341a846141dc565b604080516103e8808252617d2082019092529296509094506000935090915060208201617d00803683370190505090506000805b845181101561350c5760005b85828151811061346c5761346c615607565b6020026020010151518110156134f95785828151811061348e5761348e615607565b602002602001015181815181106134a7576134a7615607565b60200260200101518484815181106134c1576134c1615607565b6001600160a01b0390921660209283029190910190910152826134e381615666565b93505080806134f190615666565b91505061345a565b508061350481615666565b91505061344e565b5060005b83518110156135ce5760005b84828151811061352e5761352e615607565b6020026020010151518110156135bb5784828151811061355057613550615607565b6020026020010151818151811061356957613569615607565b602002602001015184848151811061358357613583615607565b6001600160a01b0390921660209283029190910190910152826135a581615666565b93505080806135b390615666565b91505061351c565b50806135c681615666565b915050613510565b506000816001600160401b038111156135e9576135e9615163565b604051908082528060200260200182016040528015613612578160200160208202803683370190505b5090506000805b838110156136ec57600085828151811061363557613635615607565b602002602001015190506000805b8481101561369857826001600160a01b031686828151811061366757613667615607565b60200260200101516001600160a01b0316036136865760019150613698565b8061369081615666565b915050613643565b50806136d757818585815181106136b1576136b1615607565b6001600160a01b0390921660209283029190910190910152836136d381615666565b9450505b505080806136e490615666565b915050613619565b50806001600160401b0381111561370557613705615163565b60405190808252806020026020018201604052801561372e578160200160208202803683370190505b50965060005b818110156137925782818151811061374e5761374e615607565b602002602001015188828151811061376857613768615607565b6001600160a01b03909216602092830291909101909101528061378a81615666565b915050613734565b50505050505050919050565b6000806000806137ad856141dc565b60fe5460fc54604051637715ee7560e01b81529599509397509195509350916001600160a01b0390911690637715ee75906137f090889087908690600401615a1b565b600060405180830381600087803b15801561380a57600080fd5b505af115801561381e573d6000803e3d6000fd5b505060fc546040516333312b5560e11b81526001600160a01b03909116925063666256aa915061385690879086908690600401615a1b565b600060405180830381600087803b15801561387057600080fd5b505af1158015613884573d6000803e3d6000fd5b50505050505050505050565b6131958363a9059cbb60e01b848460405160240161315e92919061584d565b6138b7614c22565b816000036138ed5760405180608001604052806000815260200160008152602001600081526020016000151581525090506107e6565b604051636318523760e01b8152600481018390526001600160a01b03841690636318523790602401608060405180830381865afa158015613932573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fe391906157ca565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b806000036139c9576040516307ed98ed60e31b815260040160405180910390fd5b604051634f8ca21160e11b81526004810182905260006024820152600160448201526001600160a01b03831690639f19442290606401600060405180830381600087803b158015613a1957600080fd5b505af1158015612e8c573d6000803e3d6000fd5b6000611fe38383614900565b60006107e6825490565b600083600003613a66576040516307ed98ed60e31b815260040160405180910390fd5b82600003613a875760405163162908e360e11b815260040160405180910390fd5b6040516370a0823160e01b81526000906001600160a01b038716906370a0823190613ab690309060040161514f565b602060405180830381865afa158015613ad3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613af79190615637565b604051636318523760e01b8152600481018790529091506000906001600160a01b03881690636318523790602401608060405180830381865afa158015613b42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b6691906157ca565b51905080851115613b8a57604051631e9acf1760e31b815260040160405180910390fd5b6000613b968683615723565b60408051600280825260608201835292935060009290916020830190803683370190505090508181600081518110613bd057613bd0615607565b6020026020010181815250508681600181518110613bf057613bf0615607565b60209081029190910101526040516315abf9d160e21b81526001600160a01b038a16906356afe74490613c299084908c90600401615a96565b600060405180830381600087803b158015613c4357600080fd5b505af1158015613c57573d6000803e3d6000fd5b50506040516370a0823160e01b8152600092506001600160a01b038c1691506370a0823190613c8a90309060040161514f565b602060405180830381865afa158015613ca7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ccb9190615637565b9050613cd8856001615835565b8114613cf75760405163870ecf4160e01b815260040160405180910390fd5b6001600160a01b038a16632f745c5930613d12600185615723565b6040518363ffffffff1660e01b8152600401613d2f92919061584d565b602060405180830381865afa158015613d4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d709190615637565b6040516323b872dd60e01b81529096506001600160a01b038b16906323b872dd90613da39030908b908b90600401615954565b600060405180830381600087803b158015613dbd57600080fd5b505af1158015613dd1573d6000803e3d6000fd5b505060408051898152602081018c90528c93506001600160a01b038e1692507f802bea4dd8c92d836bcfa2ba92a8c7547dbc3e882fe032eb62c6ec8d4e707d4e910160405180910390a35050505050949350505050565b600082600003613e3a57506000611fe3565b6040516331a9108f60e11b8152600481018490526000906001600160a01b03861690636352211e90602401602060405180830381865afa158015613e82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ea691906156c5565b604051630748d63560e31b81529091506001600160a01b03861690633a46b1a890613ed7908490879060040161584d565b602060405180830381865afa158015613ef4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f189190615637565b95945050505050565b6000613f76826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661492a9092919063ffffffff16565b9050805160001480613f97575080806020019051810190613f979190615866565b6131955760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161095a565b606082156140055750806107e6565b6044825110156140635760405162461bcd60e51b815260206004820152602360248201527f63616c6c206661696c656420776974686f75742061207265766572742072656160448201526239b7b760e91b606482015260840161095a565b6004820191508180602001905181019061407d9190615ab8565b60405162461bcd60e51b815260040161095a9190615529565b6140a08282611fea565b610dc85760008281526097602090815260408083206001600160a01b03851684529091529020805460ff191660011790556140d83390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000611fe3836001600160a01b038416614939565b61413b8282611fea565b15610dc85760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000611fe3836001600160a01b038416614988565b600054610100900460ff166141d45760405162461bcd60e51b815260040161095a906159d0565b611af5614a7b565b60608060608084516001600160401b038111156141fb576141fb615163565b604051908082528060200260200182016040528015614224578160200160208202803683370190505b50935084516001600160401b0381111561424057614240615163565b604051908082528060200260200182016040528015614269578160200160208202803683370190505b50925060005b85518110156144465760fc5486516000916001600160a01b03169063b9a09fd5908990859081106142a2576142a2615607565b60200260200101516040518263ffffffff1660e01b81526004016142c6919061514f565b602060405180830381865afa1580156142e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061430791906156c5565b60fc54604051637572079360e11b81529192506001600160a01b03169063eae40f269061433890849060040161514f565b602060405180830381865afa158015614355573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061437991906156c5565b85838151811061438b5761438b615607565b6001600160a01b03928316602091820292909201015260fc5460405163ae21c4cb60e01b815291169063ae21c4cb906143c890849060040161514f565b602060405180830381865afa1580156143e5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061440991906156c5565b86838151811061441b5761441b615607565b6001600160a01b0390921660209283029190910190910152508061443e81615666565b91505061426f565b5083516001600160401b0381111561446057614460615163565b60405190808252806020026020018201604052801561449357816020015b606081526020019060019003908161447e5790505b50915060005b845181101561469f5760008582815181106144b6576144b6615607565b6020026020010151905060006001600160a01b0316816001600160a01b03160361450e5760408051600081526020810190915284518590849081106144fd576144fd615607565b60200260200101819052505061468d565b6000816001600160a01b031663e68863966040518163ffffffff1660e01b8152600401602060405180830381865afa15801561454e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145729190615637565b90506000816001600160401b0381111561458e5761458e615163565b6040519080825280602002602001820160405280156145b7578160200160208202803683370190505b50905060005b8281101561466a57604051637bb7bed160e01b8152600481018290526001600160a01b03851690637bb7bed190602401602060405180830381865afa15801561460a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061462e91906156c5565b82828151811061464057614640615607565b6001600160a01b03909216602092830291909101909101528061466281615666565b9150506145bd565b508086858151811061467e5761467e615607565b60200260200101819052505050505b8061469781615666565b915050614499565b5082516001600160401b038111156146b9576146b9615163565b6040519080825280602002602001820160405280156146ec57816020015b60608152602001906001900390816146d75790505b50905060005b83518110156148f857600084828151811061470f5761470f615607565b6020026020010151905060006001600160a01b0316816001600160a01b03160361476757604080516000815260208101909152835184908490811061475657614756615607565b6020026020010181905250506148e6565b6000816001600160a01b031663e68863966040518163ffffffff1660e01b8152600401602060405180830381865afa1580156147a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147cb9190615637565b90506000816001600160401b038111156147e7576147e7615163565b604051908082528060200260200182016040528015614810578160200160208202803683370190505b50905060005b828110156148c357604051637bb7bed160e01b8152600481018290526001600160a01b03851690637bb7bed190602401602060405180830381865afa158015614863573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061488791906156c5565b82828151811061489957614899615607565b6001600160a01b0390921660209283029190910190910152806148bb81615666565b915050614816565b50808585815181106148d7576148d7615607565b60200260200101819052505050505b806148f081615666565b9150506146f2565b509193509193565b600082600001828154811061491757614917615607565b9060005260206000200154905092915050565b6060610dae8484600085614aab565b6000818152600183016020526040812054614980575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556107e6565b5060006107e6565b60008181526001830160205260408120548015614a715760006149ac600183615723565b85549091506000906149c090600190615723565b9050818114614a255760008660000182815481106149e0576149e0615607565b9060005260206000200154905080876000018481548110614a0357614a03615607565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080614a3657614a36615b42565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506107e6565b60009150506107e6565b600054610100900460ff16614aa25760405162461bcd60e51b815260040161095a906159d0565b611af533613956565b606082471015614b0c5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161095a565b600080866001600160a01b03168587604051614b289190615b58565b60006040518083038185875af1925050503d8060008114614b65576040519150601f19603f3d011682016040523d82523d6000602084013e614b6a565b606091505b5091509150614b7b87838387614b86565b979650505050505050565b60608315614bf3578251600003614bec57614ba08561335e565b614bec5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161095a565b5081610dae565b610dae8383815115614c085781518083602001fd5b8060405162461bcd60e51b815260040161095a9190615529565b60405180608001604052806000815260200160008152602001600081526020016000151581525090565b828054828255906000526020600020908101928215614ca1579160200282015b82811115614ca157825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190614c6c565b506116da929150614ce8565b828054828255906000526020600020908101928215614ca1579160200282015b82811115614ca1578251825591602001919060010190614ccd565b5b808211156116da5760008155600101614ce9565b600060208284031215614d0f57600080fd5b81356001600160e01b031981168114611fe357600080fd5b600060208284031215614d3957600080fd5b5035919050565b6001600160a01b0381168114612f0a57600080fd5b8035614d6081614d40565b919050565b60008083601f840112614d7757600080fd5b5081356001600160401b03811115614d8e57600080fd5b602083019150836020828501011115614da657600080fd5b9250929050565b600080600080600060808688031215614dc557600080fd5b8535614dd081614d40565b94506020860135614de081614d40565b93506040860135925060608601356001600160401b03811115614e0257600080fd5b614e0e88828901614d65565b969995985093965092949392505050565b60008083601f840112614e3157600080fd5b5081356001600160401b03811115614e4857600080fd5b6020830191508360208260051b8501011115614da657600080fd5b60008060008060008060006080888a031215614e7e57600080fd5b8735614e8981614d40565b965060208801356001600160401b0380821115614ea557600080fd5b614eb18b838c01614e1f565b909850965060408a0135915080821115614eca57600080fd5b614ed68b838c01614e1f565b909650945060608a0135915080821115614eef57600080fd5b50614efc8a828b01614e1f565b989b979a50959850939692959293505050565b60005b83811015614f2a578181015183820152602001614f12565b838111156125ce5750506000910152565b60008151808452614f53816020860160208601614f0f565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015614fbc57603f19888603018452614faa858351614f3b565b94509285019290850190600101614f8e565b5092979650505050505050565b600060208284031215614fdb57600080fd5b8135611fe381614d40565b600081518084526020808501945080840160005b8381101561501f5781516001600160a01b031687529582019590820190600101614ffa565b509495945050505050565b600081518084526020808501945080840160005b8381101561501f5781518752958201959082019060010161503e565b6020815281516020820152600060208301516080604084015261508060a0840182614fe6565b90506040840151601f1984830301606085015261509d828261502a565b915050606084015160808401528091505092915050565b600080600080604085870312156150ca57600080fd5b84356001600160401b03808211156150e157600080fd5b6150ed88838901614e1f565b9096509450602087013591508082111561510657600080fd5b5061511387828801614e1f565b95989497509550505050565b6000806040838503121561513257600080fd5b82359150602083013561514481614d40565b809150509250929050565b6001600160a01b0391909116815260200190565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156151a1576151a1615163565b604052919050565b60006001600160401b038211156151c2576151c2615163565b5060051b60200190565b600080600080600080600060e0888a0312156151e757600080fd5b87356151f281614d40565b965060208881013561520381614d40565b9650604089013561521381614d40565b9550606089013561522381614d40565b9450608089013561523381614d40565b935060a089013561524381614d40565b925060c08901356001600160401b0381111561525e57600080fd5b8901601f81018b1361526f57600080fd5b803561528261527d826151a9565b615179565b81815260059190911b8201830190838101908d8311156152a157600080fd5b928401925b828410156152c85783356152b981614d40565b825292840192908401906152a6565b809550505050505092959891949750929550565b6040815260006152ef6040830185614fe6565b8281036020840152613f18818561502a565b6000806040838503121561531457600080fd5b50508035926020909101359150565b60008060006060848603121561533857600080fd5b505081359360208301359350604090920135919050565b602081526000611fe36020830184614fe6565b600082601f83011261537357600080fd5b8135602061538361527d836151a9565b82815260059290921b840181019181810190868411156153a257600080fd5b8286015b848110156153bd57803583529183019183016153a6565b509695505050505050565b6000806000606084860312156153dd57600080fd5b83356001600160401b03808211156153f457600080fd5b818601915086601f83011261540857600080fd5b8135602061541861527d836151a9565b82815260059290921b8401810191818101908a84111561543757600080fd5b948201945b8386101561545e57853561544f81614d40565b8252948201949082019061543c565b9750508701359250508082111561547457600080fd5b5061548186828701615362565b92505061549060408501614d55565b90509250925092565b8015158114612f0a57600080fd5b600080604083850312156154ba57600080fd5b82356154c581614d40565b9150602083013561514481615499565b6000806000604084860312156154ea57600080fd5b83356154f581614d40565b925060208401356001600160401b0381111561551057600080fd5b61551c86828701614d65565b9497909650939450505050565b602081526000611fe36020830184614f3b565b60008060008060006060868803121561555457600080fd5b85356001600160401b038082111561556b57600080fd5b61557789838a01614e1f565b9097509550602088013591508082111561559057600080fd5b5061559d88828901614e1f565b90945092505060408601356155b181614d40565b809150509295509295909350565b60208082526028908201527f43616c6c6572206973206e6f74206f776e6572206f722068617320726571756960408201526772656420726f6c6560c01b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0392831681529116602082015260400190565b60006020828403121561564957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60006001820161567857615678615650565b5060010190565b6000808335601e1984360301811261569657600080fd5b8301803591506001600160401b038211156156b057600080fd5b602001915036819003821315614da657600080fd5b6000602082840312156156d757600080fd5b8151611fe381614d40565b60008160001904831182151516156156fc576156fc615650565b500290565b60008261571e57634e487b7160e01b600052601260045260246000fd5b500490565b60008282101561573557615735615650565b500390565b8183526000602080850194508260005b8581101561501f57813561575d81614d40565b6001600160a01b03168752958201959082019060010161574a565b60408152600061578c60408301868861573a565b82810360208401528381526001600160fb1b038411156157ab57600080fd5b8360051b80866020840137600091016020019081529695505050505050565b6000608082840312156157dc57600080fd5b604051608081016001600160401b03811182821017156157fe576157fe615163565b8060405250825181526020830151602082015260408301516040820152606083015161582981615499565b60608201529392505050565b6000821982111561584857615848615650565b500190565b6001600160a01b03929092168252602082015260400190565b60006020828403121561587857600080fd5b8151611fe381615499565b60608152600061589760608301878961573a565b60208382038185015281868352818301905060058288821b8501018960005b8a81101561592657868303601f190185528135368d9003601e190181126158dc57600080fd5b8c0180356001600160401b038111156158f457600080fd5b80861b36038e131561590557600080fd5b61591285828a850161573a565b9688019694505050908501906001016158b6565b505080955050505050508260408301529695505050505050565b602081526000610dae60208301848661573a565b6001600160a01b039384168152919092166020820152604081019190915260600190565b8183823760009101908152919050565b60408152826040820152828460608301376000606084830101526000601f19601f850116820160608382030160208401526159c66060820185614f3b565b9695505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b606081526000615a2e6060830186614fe6565b6020838203818501528186518084528284019150828160051b85010183890160005b83811015615a7e57601f19878403018552615a6c838351614fe6565b94860194925090850190600101615a50565b50508095505050505050826040830152949350505050565b604081526000615aa9604083018561502a565b90508260208301529392505050565b600060208284031215615aca57600080fd5b81516001600160401b0380821115615ae157600080fd5b818401915084601f830112615af557600080fd5b815181811115615b0757615b07615163565b615b1a601f8201601f1916602001615179565b9150808252856020828501011115615b3157600080fd5b610dac816020840160208601614f0f565b634e487b7160e01b600052603160045260246000fd5b60008251615b6a818460208701614f0f565b919091019291505056fec9abff9563eddda3f468d65834853d56c489df02bd5ac658dddd56505f0f9dfe85d36e3b488c35c2a15344b305cb84e2000f26d4f3a7c1e8a516f0e82aee752ae3723f41c074e25ac45636a7cd631386f2e15f8583ade05d0b710b41251f5c7b2cf325792651b724d47f21230be0dd9729866cadd370618845e23a48555ef042a2646970667358221220fb3ccf01d2652335ed3ad4c0d9ba1d1238ccc9de7e3fb123f16135bbf15960b264736f6c634300080d0033

Block Transaction Gas Used Reward
view all blocks sequenced

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

Validator Index Block Amount
View All Withdrawals

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

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