ETH Price: $3,330.96 (-4.37%)
Gas: 4 Gwei

Contract

0x1D4AEBcAE926bc775D80bd5a91252DA6ce5D7d89
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x60e06040169616002023-04-02 13:07:35479 days ago1680440855IN
 Create: SegmentManagement
0 ETH0.0809884322.33384875

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SegmentManagement

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 10 runs

Other Settings:
default evmVersion
File 1 of 38 : SegmentManagement.sol
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/MerkleProofUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
import "./Auth.sol";
import "./Constants.sol";
import "./VaultFactory.sol";
import "./interfaces/ISegmentManagement.sol";

pragma solidity 0.8.17;

contract SegmentManagement is
    Auth,
    VaultFactory,
    ReentrancyGuardUpgradeable,
    UUPSUpgradeable,
    ISegmentManagement
{
    IgNFT public immutable gNFT;
    IComptroller public immutable TONPOUND_COMPTROLLER;

    uint256 private _totalInactiveSegments;
    bytes32 private _airdropMerkleRoot;

    mapping(bytes32 => bool) private _discountUsed;

    function initialize(address vault_, address manager_, address pauser_) external initializer {
        if (vault_ == address(0)) revert ZeroAddress();
        __Auth_init(manager_, pauser_);
        __VaultFactory_init(vault_);
        __UUPSUpgradeable_init();
    }

    function mint(address[] memory markets) external whenNotPaused nonReentrant {
        _checkLiquidity(markets, IgNFT.TokenType.Topaz);
        _mintInternal(msg.sender, IgNFT.TokenType.Topaz, 0, 0);
    }

    function mint(
        address[] memory markets,
        IgNFT.TokenType tokenType,
        uint256[] calldata proofIds
    ) external whenNotPaused nonReentrant {
        _checkTokenType(tokenType, proofIds);
        _checkLiquidity(markets, tokenType);
        _mintInternal(msg.sender, tokenType, 0, 0);
    }

    function _mintInternal(
        address to,
        IgNFT.TokenType tokenType,
        uint48 completionTimestamp,
        uint8 segments
    ) internal {
        IgNFT.TokenData memory tokenData = IgNFT.TokenData({
            slot0: IgNFT.Slot0({
                tokenType: tokenType,
                activeSegment: segments,
                voteWeight: uint8(_getTypeParameter(tokenType, Constants.ParameterType.VoteWeight)),
                rewardWeight: uint8(
                    _getTypeParameter(tokenType, Constants.ParameterType.RewardWeight)
                ),
                usedForMint: false,
                completionTimestamp: completionTimestamp,
                lockedMarket: address(0)
            }),
            slot1: IgNFT.Slot1({lockedVaultShares: 0})
        });
        _totalInactiveSegments += Constants.SEGMENTS_NUMBER - segments;
        gNFT.mint(to, tokenData);
    }

    function _checkTokenType(IgNFT.TokenType tokenType, uint256[] calldata proofIds) internal {
        IgNFT.Slot0 memory data0;
        uint256 numTopaz;
        uint256 numEmerald;
        uint256 numDiamond;
        uint256 len = proofIds.length;
        uint256 proofId;
        uint256 requiredTopazes = _getTypeParameter(
            tokenType,
            Constants.ParameterType.RequiredTopazes
        );
        uint256 requiredEmeralds = _getTypeParameter(
            tokenType,
            Constants.ParameterType.RequiredEmeralds
        );
        uint256 requiredDiamonds = _getTypeParameter(
            tokenType,
            Constants.ParameterType.RequiredDiamonds
        );

        for (uint256 i; i < len; ) {
            proofId = proofIds[i];
            _requireOwnership(proofId);
            data0 = _getSlot0(proofId);
            if (data0.activeSegment != Constants.SEGMENTS_NUMBER) {
                revert InvalidSegmentsNumber();
            }
            unchecked {
                if (!data0.usedForMint) {
                    bool used = false;
                    if (data0.tokenType == IgNFT.TokenType.Topaz && numTopaz < requiredTopazes) {
                        numTopaz++;
                        used = true;
                    } else if (
                        data0.tokenType == IgNFT.TokenType.Emerald && numEmerald < requiredEmeralds
                    ) {
                        numEmerald++;
                        used = true;
                    } else if (numDiamond < requiredDiamonds) {
                        numDiamond++;
                        used = true;
                    }
                    if (used) {
                        data0.usedForMint = true;
                        _updateSlot0(proofId, data0);
                    }
                }
                i++;
            }
        }
        if (
            numTopaz < requiredTopazes ||
            numEmerald < requiredEmeralds ||
            numDiamond < requiredDiamonds
        ) revert MintingRequirementsNotMet();
    }

    function _checkLiquidity(address[] memory markets, IgNFT.TokenType tokenType) internal {
        IOracle oracle = _getOracle();
        IComptroller comptroller = TONPOUND_COMPTROLLER;
        uint256 liquidityValue = _getTypeParameter(
            tokenType,
            Constants.ParameterType.MintingLiquidity
        );
        uint256 len = markets.length;
        uint256 totalValue;
        address market;
        for (uint256 i; i < len; ) {
            market = markets[i];
            _checkMarketListed(market, comptroller);
            totalValue += _quoteLiquiditySingle(
                market,
                oracle,
                ICToken(market).balanceOf(msg.sender),
                false
            );
            if (totalValue >= liquidityValue) {
                return;
            }
            unchecked {
                i++;
            }
        }
        revert FailedLiquidityCheck();
    }

    function _checkMarketListed(address market, IComptroller comptroller) internal view {
        if (!comptroller.markets(market).isListed) {
            revert InvalidMarket();
        }
    }

    function _quoteLiquiditySingle(
        address market,
        IOracle oracle,
        uint256 amount,
        bool reverse
    ) internal returns (uint256) {
        uint256 eval = oracle.getEvaluation(market, amount, reverse);
        if (eval == 0) revert OracleFailed();
        return eval;
    }

    function getActivationPrice(
        uint256 tokenId,
        uint8 segmentsToOpen,
        bool discounted
    ) external view returns (uint256) {
        IgNFT.Slot0 memory data0 = _getSlot0(tokenId);
        if (Constants.SEGMENTS_NUMBER - data0.activeSegment < segmentsToOpen)
            revert InvalidSegmentsNumber();
        return _getActivationPrice(data0, segmentsToOpen, _totalInactiveSegments, discounted);
    }

    function _getActivationPrice(
        IgNFT.Slot0 memory data0,
        uint8 numberOfSegments,
        uint256 totalInactiveSegments,
        bool discounted
    ) internal view returns (uint256) {
        uint256 avgPrice;
        if (totalInactiveSegments > 0) {
            try TPI().getCirculatingSupply() returns (uint256 supply) {
                avgPrice = MathUpgradeable.min(supply / totalInactiveSegments, Constants.ACTIVATION_MAX_PRICE);
            } catch {}
        }
        avgPrice = MathUpgradeable.max(avgPrice, Constants.ACTIVATION_MIN_PRICE) * numberOfSegments;
        if (discounted) {
            avgPrice =
                (avgPrice * Constants.AIRDROP_DISCOUNT_NOMINATOR) /
                Constants.AIRDROP_DISCOUNT_DENOMINATOR;
        }
        uint256 typeNominator = _getTypeParameter(
            data0.tokenType,
            Constants.ParameterType.ActivationNominator
        );
        return (avgPrice * typeNominator);
    }

    function activateSegments(
        uint256 tokenId,
        uint8 segments,
        address market
    ) external whenNotPaused validUser(msg.sender) nonReentrant {
        _requireOwnership(tokenId);
        _activateSegmentsInternal(tokenId, segments, market, msg.sender, false);
    }

    function activateSegmentWithProof(
        uint256 tokenId,
        address account,
        uint256 nonce,
        bytes32[] memory proof,
        address market
    ) external whenNotPaused validUser(account) nonReentrant {
        (bytes32 leaf, bytes32 root) = _validateProof(account, nonce, proof);
        _activateSegmentsInternal(tokenId, 1, market, account, true);
        emit Discounted(leaf, root);
    }

    function _activateSegmentsInternal(
        uint256 tokenId,
        uint8 segments,
        address market,
        address account,
        bool discounted
    ) internal {
        IgNFT.Slot0 memory data0 = _getSlot0(tokenId);
        uint8 availableSegments = Constants.SEGMENTS_NUMBER - data0.activeSegment;
        if (availableSegments == 0) {
            revert AlreadyFullyActivated();
        } else if (segments > availableSegments) {
            revert ExceedingMaxSegments();
        } else if (segments == availableSegments) {
            data0 = _completeSegments(tokenId, data0, market, account);
        }
        uint256 totalInactive = _totalInactiveSegments;
        uint256 activationPrice = _getActivationPrice(data0, segments, totalInactive, discounted);
        uint8 newSegment;
        unchecked {
            newSegment = data0.activeSegment + segments;
            data0.activeSegment = newSegment;
            _totalInactiveSegments = totalInactive - segments;
        }
        _updateSlot0(tokenId, data0);
        TPI().burnFrom(msg.sender, activationPrice);
        emit ActivatedSegments(tokenId, newSegment);
    }

    function _validateProof(
        address account,
        uint256 nonce,
        bytes32[] memory proof
    ) internal returns (bytes32, bytes32) {
        bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, nonce))));
        if (_discountUsed[leaf]) revert DiscountUsed();
        _discountUsed[leaf] = true;
        bytes32 root = _airdropMerkleRoot;
        if (!MerkleProofUpgradeable.verify(proof, root, leaf)) revert InvalidProof();
        return (leaf, root);
    }

    function _completeSegments(
        uint256 tokenId,
        IgNFT.Slot0 memory data0,
        address market,
        address account
    ) internal returns (IgNFT.Slot0 memory) {
        if (!_treasuryReleased()) {
            if (market == address(0)) revert MarketForLockNotSpecified();
            uint256 liquidity = _getTypeParameter(
                data0.tokenType,
                Constants.ParameterType.RewardsLiquidity
            );
            (data0) = _lockLiquidityInternal(tokenId, data0, market, account, liquidity);
        }
        _getTreasury().registerTokenId(tokenId, true);
        data0.completionTimestamp = uint48(block.timestamp);
        emit TokenCompleted(tokenId, msg.sender);
        return data0;
    }

    function _treasuryReleased() internal view returns (bool) {
        return _getTreasury().rewardsClaimRemaining() == 0;
    }

    function _lockLiquidityInternal(
        uint256 tokenId,
        IgNFT.Slot0 memory data0,
        address market,
        address account,
        uint256 value
    ) internal returns (IgNFT.Slot0 memory) {
        if (value > 0) {
            uint256 amountToLock = _quoteLiquiditySingle(market, _getOracle(), value, true);
            uint256 vaultShares = _vaultLock(tokenId, market, amountToLock, account);
            data0.lockedMarket = market;
            IgNFT.Slot1 memory data1 = _getSlot1(tokenId);
            data1.lockedVaultShares = vaultShares;
            _updateSlot1(tokenId, data1);
        }
        _getTreasury().registerTokenId(tokenId, true);
        return (data0);
    }

    function lockLiquidity(uint256 tokenId, address market) external whenNotPaused nonReentrant {
        _requireOwnership(tokenId);
        if (!_treasuryReleased()) {
            IgNFT.TokenData memory data = _getTokenData(tokenId);
            if (data.slot1.lockedVaultShares > 0) revert TokenAlreadyLocked();
            if (market == address(0)) revert MarketForLockNotSpecified();
            uint256 liquidity = _getTypeParameter(
                data.slot0.tokenType,
                Constants.ParameterType.RewardsLiquidity
            );
            _lockLiquidityInternal(tokenId, data.slot0, market, msg.sender, liquidity);
        }
        _getTreasury().registerTokenId(tokenId, true);
    }

    function unlockLiquidity(uint256 tokenId) external whenNotPaused nonReentrant {
        _requireOwnership(tokenId);
        ITreasury treasury = _getTreasury();
        if (treasury.rewardsClaimRemaining() > 0) {
            treasury.registerTokenId(tokenId, false);
        }
        _unlockLiquidityInternal(tokenId, msg.sender);
    }

    function _unlockLiquidityInternal(uint256 tokenId, address account) internal {
        IgNFT.Slot0 memory data0 = _getSlot0(tokenId);
        IgNFT.Slot1 memory data1 = _getSlot1(tokenId);
        _vaultUnlock(tokenId, data0.lockedMarket, data1.lockedVaultShares, account);
        data0.lockedMarket = address(0);
        data1.lockedVaultShares = 0;
        _updateSlot0(tokenId, data0);
        _updateSlot1(tokenId, data1);
    }

    function quoteLiquidityForLock(
        address market,
        IgNFT.TokenType tokenType
    ) external view returns (uint256) {
        uint256 liquidity = _getTypeParameter(tokenType, Constants.ParameterType.RewardsLiquidity);
        return _getOracle().getEvaluationStored(market, liquidity, true);
    }

    function _getTokenData(uint256 tokenId) internal view returns (IgNFT.TokenData memory) {
        return gNFT.getTokenData(tokenId);
    }

    function _getSlot0(uint256 tokenId) internal view returns (IgNFT.Slot0 memory) {
        return gNFT.getTokenSlot0(tokenId);
    }

    function _getSlot1(uint256 tokenId) internal view returns (IgNFT.Slot1 memory) {
        return gNFT.getTokenSlot1(tokenId);
    }

    function _updateSlot0(uint256 tokenId, IgNFT.Slot0 memory data) internal {
        gNFT.updateTokenDataSlot0(tokenId, data);
    }

    function _updateSlot1(uint256 tokenId, IgNFT.Slot1 memory data) internal {
        gNFT.updateTokenDataSlot1(tokenId, data);
    }

    function _requireOwnership(uint256 tokenId) internal view {
        if (IERC721Upgradeable(address(gNFT)).ownerOf(tokenId) != msg.sender)
            revert InvalidTokenOwnership(tokenId);
    }

    function _getTypeParameter(
        IgNFT.TokenType col,
        Constants.ParameterType row
    ) internal pure returns (uint256) {
        uint256 param = Constants.TYPE_PARAMETERS(uint256(col), uint256(row));
        if (
            row == Constants.ParameterType.RewardsLiquidity ||
            row == Constants.ParameterType.MintingLiquidity
        ) {
            unchecked {
                param *= Constants.EXP_LIQUIDITY;
            }
        }
        return param;
    }

    function _getOracle() internal view returns (IOracle) {
        return IOracle(TONPOUND_COMPTROLLER.oracle());
    }

    function _getTreasury() internal view returns (ITreasury) {
        return ITreasury(TONPOUND_COMPTROLLER.treasury());
    }

    function TPI() public view override returns (ITPIToken) {
        return ITPIToken(TONPOUND_COMPTROLLER.getCompAddress());
    }

    function setMerkleRoot(bytes32 root) external onlyRole(MANAGER_ROLE) {
        emit AirdropMerkleRootChanged(_airdropMerkleRoot, root);
        _airdropMerkleRoot = root;
    }

    function updateVaultImplementation(
        address implementation
    ) external onlyRole(Constants.DEFAULT_ADMIN_ROLE) {
        _updateImplementation(implementation);
    }

    function _authorizeUpgrade(
        address newImplementation
    ) internal override onlyRole(Constants.DEFAULT_ADMIN_ROLE) {}

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor(address gnft_, address comptroller_) VaultFactory() {
        if (gnft_ == address(0) || comptroller_ == address(0))
            revert ZeroAddress();
        TONPOUND_COMPTROLLER = IComptroller(comptroller_);
        gNFT = IgNFT(gnft_);
        _disableInitializers();
    }
}

File 2 of 38 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

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

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

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

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

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

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

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

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

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

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

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

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

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

        _revokeRole(role, account);
    }

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

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

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

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

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

File 3 of 38 : IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

File 5 of 38 : IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

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

File 6 of 38 : ClonesUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/Clones.sol)

pragma solidity ^0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 *
 * _Available since v3.4._
 */
library ClonesUpgradeable {
    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create(0, 0x09, 0x37)
        }
        require(instance != address(0), "ERC1167: create failed");
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create2(0, 0x09, 0x37, salt)
        }
        require(instance != address(0), "ERC1167: create2 failed");
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(add(ptr, 0x38), deployer)
            mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
            mstore(add(ptr, 0x14), implementation)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
            mstore(add(ptr, 0x58), salt)
            mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
            predicted := keccak256(add(ptr, 0x43), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(address implementation, bytes32 salt)
        internal
        view
        returns (address predicted)
    {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}

File 7 of 38 : ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

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

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 *
 * @custom:oz-upgrades-unsafe-allow delegatecall
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable {
    function __ERC1967Upgrade_init() internal onlyInitializing {
    }

    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
    }
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

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

    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @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) private returns (bytes memory) {
        require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed");
    }

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

File 8 of 38 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

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

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

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

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

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

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

File 9 of 38 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.0;

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

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

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

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

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

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

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     */
    function upgradeTo(address newImplementation) external virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

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

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

File 10 of 38 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

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

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

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

    bool private _paused;

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

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

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

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

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

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

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

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

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

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

File 11 of 38 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

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

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

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

    uint256 private _status;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/draft-IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";

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

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

    function safeTransferFrom(
        IERC20Upgradeable token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

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

    function safeDecreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

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

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

File 16 of 38 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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);
}

File 17 of 38 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

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

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

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

File 19 of 38 : MerkleProofUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/MerkleProof.sol)

pragma solidity ^0.8.0;

/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The tree and the proofs can be generated using our
 * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
 * You will find a quickstart guide in the readme.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the merkle tree could be reinterpreted as a leaf value.
 * OpenZeppelin's JavaScript library generates merkle trees that are safe
 * against this attack out of the box.
 */
library MerkleProofUpgradeable {
    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     */
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Calldata version of {verify}
     *
     * _Available since v4.7._
     */
    function verifyCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leafs & pre-images are assumed to be sorted.
     *
     * _Available since v4.4._
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Calldata version of {processProof}
     *
     * _Available since v4.7._
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * _Available since v4.7._
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Calldata version of {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
        return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
    }

    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 23 of 38 : StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)

pragma solidity ^0.8.0;

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

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

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

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

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

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

File 24 of 38 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/MathUpgradeable.sol";

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

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

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

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

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

File 25 of 38 : EnumerableSetUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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.
 *
 * ```
 * 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;
    }
}

File 26 of 38 : Auth.sol
// SPDX-License-Identifier: UNLICENSED

import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "./interfaces/IAuth.sol";

pragma solidity ^0.8.4;

abstract contract Auth is AccessControlUpgradeable, PausableUpgradeable, IAuth {
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
    bytes32 public constant BLACKLISTED_ROLE = keccak256("VALIDATOR_ROLE");

    function __Auth_init(address manager_, address pauser_) internal onlyInitializing {
        if (manager_ == address(0) || pauser_ == address(0)) revert ZeroAddress();
        __AccessControl_init();
        __Pausable_init();

        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(MANAGER_ROLE, manager_);
        _setupRole(PAUSER_ROLE, pauser_);

        _setRoleAdmin(BLACKLISTED_ROLE, MANAGER_ROLE);
    }

    modifier validUser(address account) {
        if (hasRole(BLACKLISTED_ROLE, account)) revert BlacklistedUser(account);
        _;
    }

    function isValidUser(address account) external view returns (bool) {
        return !hasRole(BLACKLISTED_ROLE, account);
    }

    function isAdmin(address user) external view returns (bool) {
        return hasRole(DEFAULT_ADMIN_ROLE, user);
    }

    function setPause(bool newState) external onlyRole(PAUSER_ROLE) {
        newState ? _pause() : _unpause();
    }
}

File 27 of 38 : Constants.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

library Constants {
    // gNFT constants
    uint8 internal constant VOTE_WEIGHT_TOPAZ = 1;
    uint8 internal constant VOTE_WEIGHT_EMERALD = 2;
    uint8 internal constant VOTE_WEIGHT_DIAMOND = 3;

    uint8 internal constant REWARD_WEIGHT_TOPAZ = 1;
    uint8 internal constant REWARD_WEIGHT_EMERALD = 11;
    uint8 internal constant REWARD_WEIGHT_DIAMOND = 120;

    uint8 internal constant LIQUIDITY_FOR_MINTING_TOPAZ = 1; // mul by EXP_1E20
    uint8 internal constant LIQUIDITY_FOR_MINTING_EMERALD = 1; // mul by EXP_1E20
    uint8 internal constant LIQUIDITY_FOR_MINTING_DIAMOND = 1; // mul by EXP_1E20

    uint8 internal constant ACTIVATION_TOPAZ_NOMINATOR = 1;
    uint8 internal constant ACTIVATION_EMERALD_NOMINATOR = 10;
    uint8 internal constant ACTIVATION_DIAMOND_NOMINATOR = 100;

    uint8 internal constant LIQUIDITY_FOR_REWARDS_TOPAZ = 1; // mul by EXP_1E20
    uint8 internal constant LIQUIDITY_FOR_REWARDS_EMERALD = 0; // mul by EXP_1E20
    uint8 internal constant LIQUIDITY_FOR_REWARDS_DIAMOND = 0; // mul by EXP_1E20

    uint8 internal constant REQUIRE_TOPAZES_FOR_TOPAZ = 0;
    uint8 internal constant REQUIRE_TOPAZES_FOR_EMERALD = 10;
    uint8 internal constant REQUIRE_TOPAZES_FOR_DIAMOND = 10;

    uint8 internal constant REQUIRE_EMERALDS_FOR_TOPAZ = 0;
    uint8 internal constant REQUIRE_EMERALDS_FOR_EMERALD = 0;
    uint8 internal constant REQUIRE_EMERALDS_FOR_DIAMOND = 1;

    uint8 internal constant REQUIRE_DIAMONDS_FOR_TOPAZ = 0;
    uint8 internal constant REQUIRE_DIAMONDS_FOR_EMERALD = 0;
    uint8 internal constant REQUIRE_DIAMONDS_FOR_DIAMOND = 0;

    uint8 internal constant SEGMENTS_NUMBER = 12;
    uint256 internal constant REWARD_ACCUMULATING_PERIOD = 365 days;
    uint256 internal constant ACTIVATION_MIN_PRICE = 1000e18;
    uint256 internal constant ACTIVATION_MAX_PRICE = 5000e18;
    uint256 internal constant ACTIVATION_DENOMINATOR = 1;
    uint256 internal constant AIRDROP_DISCOUNT_NOMINATOR = 0;
    uint256 internal constant AIRDROP_DISCOUNT_DENOMINATOR = 1e6;
    uint256 internal constant EXP_ORACLE = 1e18;
    uint256 internal constant EXP_LIQUIDITY = 1e20;
    string internal constant BASE_URI = "https://tonpound.com/api/token-data/metadata/";

    //@notice uint8 parameters packed into bytes constant
    bytes internal constant M = hex"010203010b78010101010a64010000000a0a000001000000";

    // Treasury constants
    uint256 internal constant EXP_REWARD_PER_SHARE = 1e12;
    uint256 internal constant REWARD_PER_SHARE_MULTIPLIER = 1e12;
    uint256 internal constant MAX_RESERVE_BPS = 5e3;
    uint256 internal constant DENOM_BPS = 1e4;

    // Common constants
    uint256 internal constant DEFAULT_DECIMALS = 18;
    bytes32 internal constant DEFAULT_ADMIN_ROLE = 0x00;

    function TYPE_PARAMETERS(uint256 col, uint256 row) internal pure returns (uint8) {
        unchecked {
            return uint8(M[row * 3 + col]);
        }
    }

    enum ParameterType {
        VoteWeight,
        RewardWeight,
        MintingLiquidity,
        ActivationNominator,
        RewardsLiquidity,
        RequiredTopazes,
        RequiredEmeralds,
        RequiredDiamonds
    }
}

File 28 of 38 : IAuth.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

/// @title  Interface for Auth contract, which is a part of gNFT token
/// @notice Authorization model is based on AccessControl and Pausable contracts from OpenZeppelin:
///         (https://docs.openzeppelin.com/contracts/4.x/api/access#AccessControl) and
///         (https://docs.openzeppelin.com/contracts/4.x/api/security#Pausable)
///         Blacklisting implemented with BLACKLISTED_ROLE, managed by MANAGER_ROLE
interface IAuth {
    /// @notice Revert reason for unwanted input zero addresses
    error ZeroAddress();

    /// @notice Revert reason for protected functions being called by blacklisted address
    error BlacklistedUser(address account);

    /// @notice             Check for admin role
    /// @param user         User to check for role bearing
    /// @return             True if user has the DEFAULT_ADMIN_ROLE role
    function isAdmin(address user) external view returns (bool);

    /// @notice             Check for not being in blacklist
    /// @param user         User to check for
    /// @return             True if user is not blacklisted
    function isValidUser(address user) external view returns (bool);

    /// @notice             Control function of OpenZeppelin's Pausable contract
    ///                     Restricted to PAUSER_ROLE bearers only
    /// @param newState     New boolean status for affected whenPaused/whenNotPaused functions
    function setPause(bool newState) external;
}

File 29 of 38 : IComptroller.sol
// SPDX-License-Identifier: UNLICENSED

import "./ICToken.sol";

pragma solidity ^0.8.4;

/// @title  Partial interface for Tonpound Comptroller contract
/// @notice Based on Comptroller from Compound Finance with different governance model
///         (https://docs.compound.finance/v2/comptroller/)
///         Modified Comptroller stores gNFT and Treasury addresses
///         Unmodified descriptions are copied from Compound Finance GitHub repo:
///         (https://github.com/compound-finance/compound-protocol/blob/v2.8.1/contracts/Comptroller.sol)
interface IComptroller {
    /// @notice         Returns whether the given account is entered in the given asset
    /// @param account  The address of the account to check
    /// @param market   The market(cToken) to check
    /// @return         True if the account is in the asset, otherwise false
    function checkMembership(address account, address market) external view returns (bool);

    /// @notice         Claim all rewards accrued by the holders
    /// @param holders  The addresses to claim for
    /// @param markets  The list of markets to claim in
    /// @param bor      Whether or not to claim rewards earned by borrowing
    /// @param sup      Whether or not to claim rewards earned by supplying
    function claimComp(
        address[] memory holders,
        address[] memory markets,
        bool bor,
        bool sup
    ) external;

    /// @notice         Returns rewards accrued but not yet transferred to the user
    /// @param account  User address to get accrued rewards for
    /// @return         Value stored in compAccrued[account] mapping
    function compAccrued(address account) external view returns (uint256);

    /// @notice         Add assets to be included in account liquidity calculation
    /// @param markets  The list of addresses of the markets to be enabled
    /// @return         Success indicator for whether each corresponding market was entered
    function enterMarkets(address[] memory markets) external returns (uint256[] memory);

    /// @notice             Determine the current account liquidity wrt collateral requirements
    /// @return err         (possible error code (semi-opaque)
    ///         liquidity   account liquidity in excess of collateral requirements
    ///         shortfall   account shortfall below collateral requirements)
    function getAccountLiquidity(
        address account
    ) external view returns (uint256 err, uint256 liquidity, uint256 shortfall);

    /// @notice Return all of the markets
    /// @dev    The automatic getter may be used to access an individual market.
    /// @return The list of market addresses
    function getAllMarkets() external view returns (address[] memory);

    /// @notice         Returns the assets an account has entered
    /// @param  account The address of the account to pull assets for
    /// @return         A dynamic list with the assets the account has entered
    function getAssetsIn(address account) external view returns (address[] memory);

    /// @notice Return the address of the TPI token
    /// @return The address of TPI
    function getCompAddress() external view returns (address);

    /// @notice Return the address of the governance gNFT token
    /// @return The address of gNFT
    function gNFT() external view returns (address);

    /// @notice View function to read 'markets' mapping separately
    /// @return Market structure without nested 'accountMembership'
    function markets(address market) external view returns (Market calldata);

    /// @notice Return the address of the system Oracle
    /// @return The address of Oracle
    function oracle() external view returns (address);

    /// @notice Return the address of the Treasury
    /// @return The address of Treasury
    function treasury() external view returns (address);

    struct Market {
        bool isListed;
        uint256 collateralFactorMantissa;
        bool isComped;
    }
}

File 30 of 38 : ICToken.sol
// SPDX-License-Identifier: UNLICENSED

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

pragma solidity ^0.8.4;

/// @title  Partial interface for Tonpound cToken market
/// @notice Extension of IERC20 standard interface from OpenZeppelin
///         (https://docs.openzeppelin.com/contracts/4.x/api/token/erc20#IERC20)
interface ICToken is IERC20MetadataUpgradeable {
    /**
     * @notice Accrues interest and reduces reserves by transferring to admin
     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function _reduceReserves() external returns (uint256);

    /**
     * @notice Get the underlying balance of the `owner`
     * @dev This also accrues interest in a transaction
     * @param owner The address of the account to query
     * @return The amount of underlying owned by `owner`
     */
    function balanceOfUnderlying(address owner) external returns (uint256);

    /**
     * @notice Accrue interest then return the up-to-date exchange rate
     * @return Calculated exchange rate scaled by 1e18
     */
    function exchangeRateCurrent() external returns (uint256);

    /**
     * @notice Calculates the exchange rate from the underlying to the CToken
     * @dev This function does not accrue interest before calculating the exchange rate
     * @return Calculated exchange rate scaled by 1e18
     */
    function exchangeRateStored() external view returns (uint256);

    /**
     * @notice Underlying asset for this CToken
     */
    function underlying() external view returns (address);
}

File 31 of 38 : IgNFT.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

import "./ISegmentManagement.sol";

/// @title  gNFT governance token for Tonpound protocol
/// @notice Built on ERC721Votes extension from OpenZeppelin Upgradeable library
///         (https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#ERC721Votes)
///         Supports Permit approvals (see IERC721Permit.sol) and Multicall
///         (https://docs.openzeppelin.com/contracts/4.x/api/utils#Multicall)
interface IgNFT {
    /// @notice Revert reason for unauthorized access to protected functions
    error Auth();

    /// @notice Revert reason for protected functions being called by blacklisted address
    error BlacklistedUser(address account);

    /// @notice Revert reason for accessing protected functions during pause
    error Paused();

    /// @notice Revert reason for unwanted input zero addresses
    error ZeroAddress();

    /// @notice              Emitted during minting
    /// @param tokenId       tokenId of minted token
    /// @param data          Metadata of minted token
    event MintData(uint256 tokenId, TokenData data);

    /// @notice              Emitted during slot0 of metadata updating
    /// @param tokenId       tokenId of updated token
    /// @param data          New Slot0 of metadata of updated token
    event UpdatedTokenDataSlot0(uint256 tokenId, Slot0 data);

    /// @notice              Emitted during slot1 of metadata updating
    /// @param tokenId       tokenId of updated token
    /// @param data          New Slot1 of metadata of updated token
    event UpdatedTokenDataSlot1(uint256 tokenId, Slot1 data);

    /// @notice              View method to read SegmentManagement contract address
    /// @return              Address of SegmentManagement contract
    function SEGMENT_MANAGEMENT() external view returns (ISegmentManagement);

    /// @notice               View method to get total vote weight of minted tokens,
    ///                       only gNFTs with fully activated segments participates in the voting
    /// @return               Value of Votes._getTotalSupply(), i.e. latest total checkpoints
    function getTotalVotePower() external view returns (uint256);

    /// @notice               View method to read 'tokenDataById' mapping of extended token metadata
    /// @param tokenId        tokenId to read mapping for
    /// @return               Stored value of 'tokenDataById[tokenId]' of IgNFT.TokenData type
    function getTokenData(uint256 tokenId) external view returns (TokenData memory);

    /// @notice               View method to read first slot of extended token metadata
    /// @param tokenId        tokenId to read mapping for
    /// @return               Stored value of 'tokenDataById[tokenId].slot0' of IgNFT.Slot0 type
    function getTokenSlot0(uint256 tokenId) external view returns (Slot0 memory);

    /// @notice               View method to read second slot of extended token metadata
    /// @param tokenId        tokenId to read mapping for
    /// @return               Stored value of 'tokenDataById[tokenId].slot1' of IgNFT.Slot1 type
    function getTokenSlot1(uint256 tokenId) external view returns (Slot1 memory);

    /// @notice               Minting new gNFT token
    ///                       Restricted only to SEGMENT_MANAGEMENT contract
    /// @param to             Address of recipient
    /// @param data           Parameters of new token to be minted
    function mint(address to, TokenData memory data) external;

    /// @notice               Update IgNFT.Slot0 parameters of IgNFT.TokenData of a token
    ///                       Restricted only to SEGMENT_MANAGEMENT contract
    /// @param tokenId        Token to be updated
    /// @param data           Slot0 structure to update existed
    function updateTokenDataSlot0(uint256 tokenId, Slot0 memory data) external;

    /// @notice               Update IgNFT.Slot1 parameters of IgNFT.TokenData of a token
    ///                       Restricted only to SEGMENT_MANAGEMENT contract
    /// @param tokenId        Token to be updated
    /// @param data           Slot1 structure to update existed
    function updateTokenDataSlot1(uint256 tokenId, Slot1 memory data) external;

    struct TokenData {
        Slot0 slot0;
        Slot1 slot1;
    }

    struct Slot0 {
        TokenType tokenType;
        uint8 activeSegment;
        uint8 voteWeight;
        uint8 rewardWeight;
        bool usedForMint;
        uint48 completionTimestamp;
        address lockedMarket;
    }

    struct Slot1 {
        uint256 lockedVaultShares;
    }

    enum TokenType {
        Topaz,
        Emerald,
        Diamond
    }
}

File 32 of 38 : IOracle.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

/// @title  Partial interface for Oracle contract
/// @notice Based on PriceOracle from Compound Finance
///         (https://github.com/compound-finance/compound-protocol/blob/v2.8.1/contracts/PriceOracle.sol)
interface IOracle {
    /// @notice         Get the underlying price of a market(cToken) asset
    /// @param market   The market to get the underlying price of
    /// @return         The underlying asset price mantissa (scaled by 1e18).
    ///                 Zero means the price is unavailable.
    function getUnderlyingPrice(address market) external view returns (uint256);

    /// @notice         Evaluates input amount according to stored price, accrues interest
    /// @param cToken   Market to evaluate
    /// @param amount   Amount of tokens to evaluate according to 'reverse' order
    /// @param reverse  Order of evaluation
    /// @return         Depending on 'reverse' order:
    ///                     false - return USD amount equal to 'amount' of 'cToken'
    ///                     true - return cTokens equal to 'amount' of USD
    function getEvaluation(address cToken, uint256 amount, bool reverse) external returns (uint256);

    /// @notice         Evaluates input amount according to stored price, doesn't accrue interest
    /// @param cToken   Market to evaluate
    /// @param amount   Amount of tokens to evaluate according to 'reverse' order
    /// @param reverse  Order of evaluation
    /// @return         Depending on 'reverse' order:
    ///                     false - return USD amount equal to 'amount' of 'cToken'
    ///                     true - return cTokens equal to 'amount' of USD
    function getEvaluationStored(
        address cToken,
        uint256 amount,
        bool reverse
    ) external view returns (uint256);
}

File 33 of 38 : ISegmentManagement.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

import "./IgNFT.sol";
import "./IComptroller.sol";
import "./ITPIToken.sol";
import "./ITreasury.sol";
import "./IOracle.sol";

/// @title  Segment management contract for gNFT governance token for Tonpound protocol
interface ISegmentManagement {
    /// @notice Revert reason for activating segments for a fully activated token
    error AlreadyFullyActivated();

    /// @notice Revert reason for repeating discount activation
    error DiscountUsed();

    /// @notice Revert reason for minting over the max segment number
    error ExceedingMaxSegments();

    /// @notice Revert reason for minting without liquidity in Tonpound protocol
    error FailedLiquidityCheck();

    /// @notice Revert reason for minting token with a market without membership
    error InvalidMarket();

    /// @notice Revert reason for activating segment with invalid Merkle proof for given account
    error InvalidProof();

    /// @notice Revert reason for activating more segments than available
    error InvalidSegmentsNumber();

    /// @notice Revert reason for operating tokens without ownership
    error InvalidTokenOwnership(uint256 tokenId);

    /// @notice Revert reason for activating last segment without specified liquidity for lock
    error MarketForLockNotSpecified();

    /// @notice Revert reason for minting high tier gNFT without providing proof of ownership
    error MintingRequirementsNotMet();

    /// @notice Revert reason for zero returned price from Oracle contract
    error OracleFailed();

    /// @notice Revert reason for trying to lock already locked token
    error TokenAlreadyLocked();

    /// @notice              Emitted during NFT segments activation
    /// @param tokenId       tokenId of activated token
    /// @param segment       New active segment after performed activation
    event ActivatedSegments(uint256 indexed tokenId, uint8 segment);

    /// @notice              Emitted after the last segment of gNFT token is activated
    /// @param tokenId       tokenId of completed token
    /// @param user          Address of the user who completed the token
    event TokenCompleted(uint256 indexed tokenId, address indexed user);

    /// @notice              Emitted when whitelisted users activate their segments with discount
    /// @param leaf          Leaf of Merkle tree being used in activation
    /// @param root          Root of Merkle tree being used in activation
    event Discounted(bytes32 leaf, bytes32 root);

    /// @notice             Emitted to notify about airdrop Merkle root change
    /// @param oldRoot      Old root
    /// @param newRoot      New updated root to be used after this tx
    event AirdropMerkleRootChanged(bytes32 oldRoot, bytes32 newRoot);

    /// @notice              View method to read Tonpound Comptroller address
    /// @return              Address of Tonpound Comptroller contract
    function TONPOUND_COMPTROLLER() external view returns (IComptroller);

    /// @notice View method to read gNFT
    /// @return Address of gNFT contract
    function gNFT() external view returns (IgNFT);

    /// @notice View method to read Tonpound TPI token
    /// @return Address of TPI token contract
    function TPI() external view returns (ITPIToken);

    /// @notice               View method to get price in TPI tokens to activate segments of gNFT token
    /// @param tokenId        tokenId of the token to activate segments of
    /// @param segmentsToOpen Number of segments to activate, fails if this number exceeds available segments
    /// @param discounted     Whether the user is eligible for activation discount
    /// @return               Price in TPI tokens to be burned from caller to activate specified number of segments
    function getActivationPrice(
        uint256 tokenId,
        uint8 segmentsToOpen,
        bool discounted
    ) external view returns (uint256);

    /// @notice              View method to get amount of liquidity to be provided for lock in order to
    ///                      complete last segment and make gNFT eligible for reward distribution in Treasury
    /// @param market        Tonpound Comptroller market (cToken) to be locked
    /// @param tokenType     Type of token to quote lock for
    /// @return              Amount of specified market tokens to be provided for lock
    function quoteLiquidityForLock(
        address market,
        IgNFT.TokenType tokenType
    ) external view returns (uint256);

    /// @notice              Minting new gNFT token with zero active segments and no voting power
    ///                      Minter must have total assets in Tonpound protocol over the threshold nominated in USD
    /// @param markets       User provided markets of Tonpound Comptroller to be checked for liquidity
    function mint(address[] memory markets) external;

    /// @notice              Minting new gNFT token of given type with zero active segments and no voting power
    ///                      Minter must have assets in given markets of Tonpound protocol over the threshold in USD
    ///                      Minter must own number of fully activated lower tier gNFTs to mint Emerald or Diamond
    /// @param markets       User provided markets of Tonpound Comptroller to be checked for liquidity
    /// @param tokenType     Token type to mint: Topaz, Emerald, or Diamond
    /// @param proofIds      List of tokenIds to be checked for ownership, activation, and type
    function mint(
        address[] memory markets,
        IgNFT.TokenType tokenType,
        uint256[] calldata proofIds
    ) external;

    /// @notice              Activating number of segments of given gNFT token
    ///                      Caller must be the owner, token may be completed with this function if
    ///                      caller provides enough liquidity for lock in specified Tonpound 'market'
    /// @param tokenId       tokenId to be activated for number of segments
    /// @param segments      Number of segments to be activated, must not exceed available segments of tokenId
    /// @param market        Optional address of Tonpound market to lock liquidity in order to complete gNFT
    function activateSegments(uint256 tokenId, uint8 segments, address market) external;

    /// @notice              Activating 1 segment of given gNFT token
    ///                      Caller must provide valid Merkle proof, token may be completed with this function if
    ///                      'account' provides enough liquidity for lock in specified Tonpound 'market'
    /// @param tokenId       tokenId to be activated for a single segment
    /// @param account       Address of whitelisted account, which is included in leaf of Merkle tree
    /// @param nonce         Nonce parameter included in leaf of Merkle tree
    /// @param proof         bytes32[] array of Merkle tree proof for whitelisted account
    /// @param market        Optional address of Tonpound market to lock liquidity in order to complete gNFT
    function activateSegmentWithProof(
        uint256 tokenId,
        address account,
        uint256 nonce,
        bytes32[] memory proof,
        address market
    ) external;

    /// @notice              Unlocking liquidity of a fully activated gNFT
    ///                      Caller must be the owner. If function is called before start of reward claiming,
    ///                      the given tokenId is de-registered in Treasury contract and stops acquiring rewards
    ///                      Any rewards acquired before unlocking will be available once claiming starts
    /// @param tokenId       tokenId to unlock liquidity for
    function unlockLiquidity(uint256 tokenId) external;

    /// @notice              Locking liquidity of a fully activated gNFT (reverting result of unlockLiquidity())
    ///                      Caller must be the owner. If function is called before start of reward claiming,
    ///                      the given tokenId is registered in Treasury contract and starts acquiring rewards
    ///                      Any rewards acquired before remains accounted and will be available once claiming starts
    /// @param tokenId       tokenId to lock liquidity for
    /// @param market        Address of Tonpound market to lock liquidity in
    function lockLiquidity(uint256 tokenId, address market) external;

    /// @notice             Updating Merkle root for whitelisting airdropped accounts
    ///                     Restricted to MANAGER_ROLE bearers only
    /// @param root         New root of Merkle tree of whitelisted addresses
    function setMerkleRoot(bytes32 root) external;
}

File 34 of 38 : ITPIToken.sol
// SPDX-License-Identifier: UNLICENSED

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

pragma solidity ^0.8.4;

/// @title  Partial interface for Tonpound TPI token
/// @notice Extension of IERC20 standard interface from OpenZeppelin
///         (https://docs.openzeppelin.com/contracts/4.x/api/token/erc20#IERC20)
interface ITPIToken is IERC20Upgradeable {
    /// @notice View function to get current active circulating supply,
    ///         used to calculate price of gNFT segment activation
    /// @return Total supply without specific TPI storing address, e.g. vesting
    function getCirculatingSupply() external view returns (uint256);

    /// @notice         Function to be used for gNFT segment activation
    /// @param account  Address, whose token to be burned
    /// @param amount   Amount to be burned
    function burnFrom(address account, uint256 amount) external;
}

File 35 of 38 : ITreasury.sol
// SPDX-License-Identifier: UNLICENSED

import "./IComptroller.sol";
import "./IgNFT.sol";
import "./IAuth.sol";

pragma solidity ^0.8.4;

/// @title  Interface for Tonpound Treasury contract, which is a part of gNFT token
/// @notice Authorization model is based on AccessControl and Pausable contracts from OpenZeppelin:
///         (https://docs.openzeppelin.com/contracts/4.x/api/access#AccessControl) and
///         (https://docs.openzeppelin.com/contracts/4.x/api/security#Pausable)
///         Blacklisting implemented with BLACKLISTED_ROLE, managed by MANAGER_ROLE
interface ITreasury {
    /// @notice Revert reason for unauthorized access to protected functions
    error Auth();

    /// @notice Revert reason claiming rewards before start of claiming period
    error ClaimingNotStarted();

    /// @notice Revert reason claiming unregistered reward token
    error InvalidRewardToken();

    /// @notice Revert reason for distributing rewards in unsupported reward token
    error InvalidMarket();

    /// @notice Revert reason for setting too high parameter value
    error InvalidParameter();

    /// @notice Revert reason for claiming reward for not-owned gNFT token
    error InvalidTokenOwnership();

    /// @notice Revert reason for accessing protected functions during pause
    error Paused();

    /// @notice Revert reason for unwanted input zero addresses
    error ZeroAddress();

    /// @notice Emitted in governance function when reserveBPS variable is updated
    event ReserveFactorUpdated(uint256 oldValue, uint256 newValue);

    /// @notice Emitted in governance function when reserveFund variable is updated
    event ReserveFundUpdated(address oldValue, address newValue);

    /// @notice             View method to read all supported reward tokens
    /// @return             Array of addresses of registered reward tokens
    function getRewardTokens() external view returns (address[] memory);

    /// @notice             View method to read number of supported reward tokens
    /// @return             Number of registered reward tokens
    function getRewardTokensLength() external view returns (uint256);

    /// @notice             View method to read a single reward token address
    /// @param index        Index of reward token in array to return
    /// @return             Address of reward token at given index in array
    function getRewardTokensAtIndex(uint256 index) external view returns (address);

    /// @notice             View method to read 'lastClaimForTokenId' mapping
    ///                     storing 'rewardPerShare' parameter for 'tokenId'
    ///                     from time of registration or last claiming event
    /// @param rewardToken  Address of reward token to read mapping for
    /// @param tokenId      gNFT tokenId to read mapping for
    /// @return             Stored value of 'lastClaimForTokenId[rewardToken][tokenId]',
    ///                     last claim value of reward per share multiplied by REWARD_PER_SHARE_MULTIPLIER = 1e12
    function lastClaimForTokenId(
        address rewardToken,
        uint256 tokenId
    ) external view returns (uint256);

    /// @notice             View method to get pending rewards for given
    ///                     reward token and gNFT token, contains fixed part for
    ///                     de-registered tokens and calculated part of distributed rewards
    /// @param rewardToken  Address of reward token to calculate pending rewards
    /// @param tokenId      gNFT tokenId to calculate pending rewards for
    /// @return             Value of rewards in rewardToken that would be claimed if claim is available
    function pendingReward(address rewardToken, uint256 tokenId) external view returns (uint256);

    /// @notice             View method to read 'registeredTokenIds' mapping of
    ///                     tracked registered gNFT tokens
    /// @param tokenId      tokenId of gNFT token to read
    /// @return             Stored bool value of 'registeredTokenIds[tokenId]', true if registered
    function registeredTokenIds(uint256 tokenId) external view returns (bool);

    /// @notice             View method to read 'rewardPerShare' mapping of
    ///                     tracked balances of Treasury contract to properly distribute rewards
    /// @param rewardToken  Address of reward token to read mapping for
    /// @return             Stored value of 'rewardPerShare[rewardToken]',
    ///                     reward per share multiplied by REWARD_PER_SHARE_MULTIPLIER = 1e12
    function rewardPerShare(address rewardToken) external view returns (uint256);

    /// @notice             View method to read 'rewardBalance' mapping of distributed rewards
    ///                     in specified rewardToken stored to properly account fresh rewards
    /// @param rewardToken  Address of reward token to read mapping for
    /// @return             Stored value of 'rewardBalance[rewardToken]'
    function rewardBalance(address rewardToken) external view returns (uint256);

    /// @notice             View method to get the remaining time until start of claiming period
    /// @return             Seconds until claiming is available, zero if claiming has started
    function rewardsClaimRemaining() external view returns (uint256);

    /// @notice             View method to read Tonpound Comptroller address
    /// @return             Address of Tonpound Comptroller contract
    function TONPOUND_COMPTROLLER() external view returns (IComptroller);

    /// @notice             View method to read total weight of registered gNFT tokens,
    ///                     eligible for rewards distribution
    /// @return             Stored value of 'totalRegisteredWeight'
    function totalRegisteredWeight() external view returns (uint256);

    /// @notice             Register and distribute incoming rewards in form of all tokens
    ///                     supported by the Tonpound Comptroller contract
    ///                     Rewards must be re-distributed if there's no users to receive at the moment
    function distributeRewards() external;

    /// @notice             Register and distribute incoming rewards in form of underlying of 'market'
    ///                     Market address must be listed in the Tonpound Comptroller
    ///                     Rewards must be re-distributed if there's no users to receive at the moment
    /// @param market       Address of market cToken to try to distribute
    function distributeReward(address market) external;

    /// @notice             Claim all supported pending rewards for given gNFT token
    ///                     Claimable only after rewardsClaimRemaining() == 0 and
    ///                     only by the owner of given tokenId
    /// @param tokenId      gNFT tokenId to claim rewards for
    function claimRewards(uint256 tokenId) external;

    /// @notice             Claim pending rewards for given gNFT token in form of single 'rewardToken'
    ///                     Claimable only after rewardsClaimRemaining() == 0 and
    ///                     only by the owner of given tokenId
    /// @param tokenId      gNFT tokenId to claim rewards for
    /// @param rewardToken  Address of reward token to claim rewards in
    function claimReward(uint256 tokenId, address rewardToken) external;

    /// @notice             Register or de-register tokenId for rewards distribution
    ///                     De-registering saves acquired rewards in fixed part for claiming when available
    ///                     Restricted for gNFT contract only
    /// @param tokenId      gNFT tokenId to update registration status for
    /// @param state        New boolean registration status
    function registerTokenId(uint256 tokenId, bool state) external;

    /// @notice             Updating reserveBPS factor for reserve fund part of rewards
    /// @param newFactor    New value to be less than 5000
    function setReserveFactor(uint256 newFactor) external;

    /// @notice             Updating reserve fund address
    /// @param newFund      New address to receive future reserve rewards
    function setReserveFund(address newFund) external;

    struct RewardInfo {
        address market;
        uint256 amount;
    }
}

File 36 of 38 : IVault.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

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

/// @title  Interface for Tonpound gNFT Vault contract, which is a part of gNFT token
/// @notice VaultFactory is called by VaultFactory contract to store underlying Tonpound liquidity tokens
///         Vault contract is based on ERC4626 Vault from OpenZeppelin's library:
///         (https://docs.openzeppelin.com/contracts/4.x/api/token/erc20#ERC4626)
interface IVault {
    /// @notice         Revert reason for unauthorized access to protected functions
    error Auth();

    /// @notice         Revert reason for unwanted input zero addresses
    error ZeroAddress();

    /// @notice         Emitted when problem in TPI calculation arises
    event NotEnoughTPI();

    /// @notice         Emitted with each deposit act
    /// @param tokenId  Deposit is linked to gNFT tokenId
    /// @param assets   Tonpound market cToken amount being deposited
    /// @param shares   Equivalent amount of shares calculated at the moment
    event Deposited(uint256 tokenId, uint256 assets, uint256 shares);

    /// @notice         Emitted with each withdraw act
    /// @param tokenId  Withdraw is linked to gNFT tokenId
    /// @param shares   Amount of shares to be withdrawn
    /// @param assets   Market cToken amount calculated at the moment
    event Withdrawn(uint256 tokenId, uint256 shares, uint256 assets);

    /// @notice         Method to be called by VaultFactory when locking is requested by gNFT
    /// @param tokenId  gNFT tokenId to deposit for
    /// @param assets   Amount of Tonpound market tokens to be deposited
    /// @return shares  Amount of shares acquired from 'assets' amount
    function deposit(uint256 tokenId, uint256 assets) external returns (uint256 shares);

    /// @notice         Method to be called by VaultFactory when unlocking is requested by gNFT
    /// @param tokenId  gNFT tokenId to withdraw for
    /// @param shares   Amount of Vault shares to be redeemed
    /// @return assets  Amount of assets acquired from 'shares' amount
    function withdraw(
        uint256 tokenId,
        uint256 shares,
        address receiver
    ) external returns (uint256 assets);

    /// @notice         View method to get shares from assets
    /// @param assets   Amount of underlying asset tokens
    /// @return shares  Amount of shares to be acquired from 'assets'
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /// @notice         View method to get assets from shares
    /// @param shares   Amount of Vault shares
    /// @return assets  Amount of underlying assets to be acquired from 'shares'
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /// @notice         View method to get total stored assets
    /// @return         Underlying assets balance of Vault contract
    function totalAssets() external view returns (uint256);

    /// @notice         View method to get total shares
    /// @return         Total amount of minted Vault shares
    function totalShares() external view returns (uint256);

    /// @notice         View method to get underlying asset address
    /// @return         Address of Tonpound market used as storing asset
    function market() external view returns (IERC20Upgradeable);

    /// @notice         View method to get Tonpound gNFT SegmentManagement contract
    /// @return         Address of SegmentManagement contract, which has access to restricted functions
    function factory() external view returns (ISegmentManagement);

    /// @notice         View method to get TPI reward per share
    /// @return         Stored accumulated TPI reward per share
    function accRewardPerShare() external view returns (uint256);

    /// @notice         View method to get stored TPI rewards
    /// @return         Total amount of TPI rewards stored with the last update
    function totalTPIStored() external view returns (uint256);

    /// @notice         View method to get already paid TPI
    /// @return         Total amount of TPI rewards paid to unlocked gNFTs
    function rewardPaid() external view returns (uint256);

    /// @notice         View method to get Vault shares by gNFT tokenID
    /// @return         Amount of shares in the Vault
    function sharesByID(uint256) external view returns (uint256);

    /// @notice         View method to get reward debt by gNFT tokenID,
    ///                 i.e. accRewardPerShare at the moment of balance update
    ///                 Can be negative, so rewards are claimable even after shares withdrawal
    /// @return         rewardDebt = SUM_OF (sharesDiff * accRewardPerShare)_i
    function rewardDebtByID(uint256) external view returns (int256);

    /// @notice         Restricted initializer to be called right after Vault creation
    /// @param market   Address of Tonpound market used as storing asset
    function initialize(address market) external;
}

File 37 of 38 : IVaultFactory.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

import "./IgNFT.sol";
import "./ITPIToken.sol";
import "./IVault.sol";

/// @title  Interface for VaultFactory contract, which is a part of SegmentManagement of Tonpound gNFT token
/// @notice VaultFactory is a factory contract to store liquidity tokens in individual Vaults,
///         since Tonpound market tokens are rebasing ERC20 and TPI rewards are accrued per holder
///         Based on EIP-1167 Minimal Proxy implementation from OpenZeppelin: 
///         (https://docs.openzeppelin.com/contracts/4.x/api/proxy#Clones)
interface IVaultFactory {
    /// @notice Revert reason for unauthorized access to protected functions
    error Auth();

    /// @notice Revert reason for trying to lock not supported Tonpound market
    error NotSupported();

    /// @notice Revert reason for updating implementation for address without bytecode
    error WrongImplementation();

    /// @notice Emitted with a creation of a new Vault contract to store Tonpound liquidity tokens
    /// @param market         Address of Tonpound liquidity token
    /// @param instance       Address of Vault contract to store 'market' tokens
    /// @param implementation Address of used implementation of Vault contract
    event MarketAdded(address market, address instance, address implementation);

    /// @notice Emitted when gNFT contract requests a lock of liquidity
    /// @param tokenId        gNFT tokenId to lock for
    /// @param market         Address of Tonpound market locked
    /// @param assets         Amount of Tonpound market tokens locked
    /// @param shares         Amount of shares acquired in corresponding Vault
    event Locked(uint256 indexed tokenId, address market, uint256 assets, uint256 shares);

    /// @notice Emitted when gNFT contract requests an unlock of liquidity
    /// @param tokenId        gNFT tokenId to unlock for
    /// @param market         Address of Tonpound market unlocked
    /// @param assets         Amount of Tonpound market tokens unlocked
    /// @param shares         Amount of Vault shares unlocked
    /// @param receiver       Address of receiver of unlocked liquidity
    event Unlocked(
        uint256 indexed tokenId,
        address market,
        uint256 assets,
        uint256 shares,
        address indexed receiver
    );

    /// @notice         View method to read Vault by Tonpound market
    /// @param market   Address of Tonpound market to be get Vault for
    /// @return         Vault address storing 'market' tokens (zero if not created yet)
    function vaultsByMarket(address market) external view returns (IVault);

    /// @notice         View method to get all supported markets
    /// @return         Array of supported markets, which have deployed Vaults
    function allMarkets() external view returns (address[] memory);

    /// @notice         View method to get supported market at index
    /// @return         Address of supported market at index in all markets array
    function marketAt(uint256 index) external view returns (address);

    /// @notice         View method to get number of supported numbers
    /// @return         Length of supported markets array
    function marketsLength() external view returns (uint256);

    /// @notice         View method to check if market is supported
    /// @return         True if market is supported and has Vault, False - if not
    function marketSupported(address market) external view returns (bool);
}

File 38 of 38 : VaultFactory.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.4;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "./Constants.sol";
import "./interfaces/IVaultFactory.sol";

abstract contract VaultFactory is Initializable, IVaultFactory {
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;

    IVault public vaultImplementation;

    EnumerableSetUpgradeable.AddressSet private _markets;
    mapping(address => IVault) public vaultsByMarket;

    function __VaultFactory_init(address vault_) internal onlyInitializing {
        vaultImplementation = IVault(vault_);
    }

    function _getVault(address market) internal returns (IVault) {
        IVault vault;
        if (market == _getTPIAddress()) revert NotSupported();
        if (_markets.add(market)) {
            address implementation = address(vaultImplementation);
            vault = IVault(ClonesUpgradeable.clone(implementation));
            vault.initialize(market);
            vaultsByMarket[market] = vault;

            emit MarketAdded(market, address(vault), implementation);
        } else {
            vault = vaultsByMarket[market];
        }
        return vault;
    }

    function _vaultLock(
        uint256 tokenId,
        address market,
        uint256 assets,
        address sender
    ) internal returns (uint256) {
        IVault vault = _getVault(market);
        uint256 shares = vault.deposit(tokenId, assets);
        SafeERC20Upgradeable.safeTransferFrom(
            IERC20Upgradeable(market),
            sender,
            address(vault),
            assets
        );

        emit Locked(tokenId, market, assets, shares);
        return shares;
    }

    function _vaultUnlock(
        uint256 tokenId,
        address market,
        uint256 shares,
        address receiver
    ) internal returns (uint256) {
        IVault vault = _getVault(market);
        uint256 assets = vault.withdraw(tokenId, shares, receiver);

        emit Unlocked(tokenId, market, assets, shares, receiver);
        return assets;
    }

    function allMarkets() external view returns (address[] memory) {
        return _markets.values();
    }

    function marketAt(uint256 index) external view returns (address) {
        return _markets.at(index);
    }

    function marketsLength() external view returns (uint256) {
        return _markets.length();
    }

    function marketSupported(address market) external view returns (bool) {
        return _markets.contains(market);
    }

    function _getTPIAddress() internal view virtual returns (address) {}

    function _updateImplementation(address implementation) internal {
        if (!AddressUpgradeable.isContract(implementation)) revert WrongImplementation();
        vaultImplementation = IVault(implementation);
    }

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

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"gnft_","type":"address"},{"internalType":"address","name":"comptroller_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyFullyActivated","type":"error"},{"inputs":[],"name":"Auth","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"BlacklistedUser","type":"error"},{"inputs":[],"name":"DiscountUsed","type":"error"},{"inputs":[],"name":"ExceedingMaxSegments","type":"error"},{"inputs":[],"name":"FailedLiquidityCheck","type":"error"},{"inputs":[],"name":"InvalidMarket","type":"error"},{"inputs":[],"name":"InvalidProof","type":"error"},{"inputs":[],"name":"InvalidSegmentsNumber","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"InvalidTokenOwnership","type":"error"},{"inputs":[],"name":"MarketForLockNotSpecified","type":"error"},{"inputs":[],"name":"MintingRequirementsNotMet","type":"error"},{"inputs":[],"name":"NotSupported","type":"error"},{"inputs":[],"name":"OracleFailed","type":"error"},{"inputs":[],"name":"TokenAlreadyLocked","type":"error"},{"inputs":[],"name":"WrongImplementation","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint8","name":"segment","type":"uint8"}],"name":"ActivatedSegments","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"oldRoot","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"AirdropMerkleRootChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"leaf","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"root","type":"bytes32"}],"name":"Discounted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"market","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Locked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"market","type":"address"},{"indexed":false,"internalType":"address","name":"instance","type":"address"},{"indexed":false,"internalType":"address","name":"implementation","type":"address"}],"name":"MarketAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","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":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"TokenCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"market","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"}],"name":"Unlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"BLACKLISTED_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":"MANAGER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TONPOUND_COMPTROLLER","outputs":[{"internalType":"contract IComptroller","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TPI","outputs":[{"internalType":"contract ITPIToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"},{"internalType":"address","name":"market","type":"address"}],"name":"activateSegmentWithProof","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint8","name":"segments","type":"uint8"},{"internalType":"address","name":"market","type":"address"}],"name":"activateSegments","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allMarkets","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gNFT","outputs":[{"internalType":"contract IgNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint8","name":"segmentsToOpen","type":"uint8"},{"internalType":"bool","name":"discounted","type":"bool"}],"name":"getActivationPrice","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":"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":"vault_","type":"address"},{"internalType":"address","name":"manager_","type":"address"},{"internalType":"address","name":"pauser_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isValidUser","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"market","type":"address"}],"name":"lockLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"marketAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"}],"name":"marketSupported","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"markets","type":"address[]"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"markets","type":"address[]"},{"internalType":"enum IgNFT.TokenType","name":"tokenType","type":"uint8"},{"internalType":"uint256[]","name":"proofIds","type":"uint256[]"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum IgNFT.TokenType","name":"tokenType","type":"uint8"}],"name":"quoteLiquidityForLock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"root","type":"bytes32"}],"name":"setMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"newState","type":"bool"}],"name":"setPause","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":"uint256","name":"tokenId","type":"uint256"}],"name":"unlockLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"updateVaultImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"vaultImplementation","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultsByMarket","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60e0604052306080523480156200001557600080fd5b506040516200427a3803806200427a833981016040819052620000389162000183565b62000042620000a4565b6001600160a01b03821615806200006057506001600160a01b038116155b156200007f5760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0380821660c052821660a0526200009c620000a4565b5050620001bb565b600054610100900460ff1615620001115760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff908116101562000164576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b80516001600160a01b03811681146200017e57600080fd5b919050565b600080604083850312156200019757600080fd5b620001a28362000166565b9150620001b26020840162000166565b90509250929050565b60805160a05160c05161402662000254600039600081816103cb01528181610da601528181611a2801528181611c78015261220a0152600081816101f60152818161173b0152818161185f01528181611af001528181611e5d0152818161241801528181612793015261281b01526000818161085b0152818161089b015281816109340152818161097401526109ec01526140266000f3fe6080604052600436106101aa5760003560e01c806301ffc9a7146101af57806314b8194c146101e4578063174ef86a14610225578063248a9ca31461024757806324d7806c146102755780632f2ff15d14610295578063343a5962146102b557806336568abe146102d55780633659cfe6146102f5578063375a7cba146103155780634f1ef2861461033757806352d1902d1461034a5780635c975abb1461035f57806362b199c514610377578063684fe77914610399578063700cd58a146103b95780637394507e146103ed5780637cb647591461040d5780638efb3f4f1461042d57806391d148541461046357806396e83924146104835780639b5d2e78146104a3578063a217fddf146104b8578063a42fd192146104cd578063a5402544146104ed578063bba48a9014610502578063bd075b8414610522578063bedb86fb14610542578063c0c53b8b14610562578063c772356914610582578063cc10b9b3146105a2578063cd170311146105c2578063d547741f146105e2578063e63ab1e914610602578063ec87621c14610624578063f3c5400614610646578063f3c95c6014610666575b600080fd5b3480156101bb57600080fd5b506101cf6101ca366004613386565b610686565b60405190151581526020015b60405180910390f35b3480156101f057600080fd5b506102187f000000000000000000000000000000000000000000000000000000000000000081565b6040516101db91906133b0565b34801561023157600080fd5b506102456102403660046133e4565b6106bd565b005b34801561025357600080fd5b50610267610262366004613401565b6106d5565b6040519081526020016101db565b34801561028157600080fd5b506101cf6102903660046133e4565b6106ea565b3480156102a157600080fd5b506102456102b036600461341a565b6106f6565b3480156102c157600080fd5b506102456102d03660046134b3565b610717565b3480156102e157600080fd5b506102456102f036600461341a565b6107d7565b34801561030157600080fd5b506102456103103660046133e4565b610851565b34801561032157600080fd5b5061032a610919565b6040516101db9190613581565b6102456103453660046135ce565b61092a565b34801561035657600080fd5b506102676109df565b34801561036b57600080fd5b5060975460ff166101cf565b34801561038357600080fd5b50610267600080516020613f2a83398151915281565b3480156103a557600080fd5b506102456103b4366004613684565b610a8d565b3480156103c557600080fd5b506102187f000000000000000000000000000000000000000000000000000000000000000081565b3480156103f957600080fd5b5061024561040836600461341a565b610afd565b34801561041957600080fd5b50610245610428366004613401565b610c15565b34801561043957600080fd5b506102186104483660046133e4565b60cc602052600090815260409020546001600160a01b031681565b34801561046f57600080fd5b506101cf61047e36600461341a565b610c71565b34801561048f57600080fd5b5061024561049e366004613401565b610c9c565b3480156104af57600080fd5b50610218610da2565b3480156104c457600080fd5b50610267600081565b3480156104d957600080fd5b506102676104e83660046136d4565b610e26565b3480156104f957600080fd5b50610267610e85565b34801561050e57600080fd5b5060c954610218906001600160a01b031681565b34801561052e57600080fd5b5061024561053d36600461377a565b610e91565b34801561054e57600080fd5b5061024561055d3660046137ae565b610ec4565b34801561056e57600080fd5b5061024561057d3660046137cb565b610ef1565b34801561058e57600080fd5b5061024561059d366004613808565b611045565b3480156105ae57600080fd5b506102676105bd3660046138b0565b611077565b3480156105ce57600080fd5b506101cf6105dd3660046133e4565b611108565b3480156105ee57600080fd5b506102456105fd36600461341a565b611115565b34801561060e57600080fd5b50610267600080516020613faa83398151915281565b34801561063057600080fd5b50610267600080516020613f8a83398151915281565b34801561065257600080fd5b50610218610661366004613401565b611131565b34801561067257600080fd5b506101cf6106813660046133e4565b61113e565b60006001600160e01b03198216637965db0b60e01b14806106b757506301ffc9a760e01b6001600160e01b03198316145b92915050565b60006106c88161115f565b6106d182611169565b5050565b60009081526065602052604090206001015490565b60006106b78183610c71565b6106ff826106d5565b6107088161115f565b61071283836111b1565b505050565b61071f611237565b83610738600080516020613f2a83398151915282610c71565b1561076157806040516339edf4c360e11b815260040161075891906133b0565b60405180910390fd5b61076961127f565b6000806107778787876112d8565b9150915061078a886001868a60016113a9565b60408051838152602081018390527f7d85331eec197ef05ed037cf88fe5937a220c6b65b6ea665bbf09736aef62c47910160405180910390a150506107cf600160cd55565b505050505050565b6001600160a01b03811633146108475760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610758565b6106d18282611515565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036108995760405162461bcd60e51b8152600401610758906138de565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166108cb61157c565b6001600160a01b0316146108f15760405162461bcd60e51b815260040161075890613918565b6108fa81611598565b60408051600080825260208201909252610916918391906115a3565b50565b606061092560ca61170e565b905090565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036109725760405162461bcd60e51b8152600401610758906138de565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166109a461157c565b6001600160a01b0316146109ca5760405162461bcd60e51b815260040161075890613918565b6109d382611598565b6106d1828260016115a3565b6000306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610a7a5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608401610758565b50600080516020613f6a83398151915290565b610a95611237565b33610aae600080516020613f2a83398151915282610c71565b15610ace57806040516339edf4c360e11b815260040161075891906133b0565b610ad661127f565b610adf8461171b565b610aed8484843360006113a9565b610af7600160cd55565b50505050565b610b05611237565b610b0d61127f565b610b168261171b565b610b1e6117d0565b610ba3576000610b2d83611841565b60208101515190915015610b5457604051637cca156760e11b815260040160405180910390fd5b6001600160a01b038216610b7b57604051631c0eb28960e11b815260040160405180910390fd5b805151600090610b8c9060046118d3565b9050610b9f84836000015185338561194f565b5050505b610bab611a24565b6001600160a01b031663c1450c7e8360016040518363ffffffff1660e01b8152600401610bd9929190613952565b600060405180830381600087803b158015610bf357600080fd5b505af1158015610c07573d6000803e3d6000fd5b505050506106d1600160cd55565b600080516020613f8a833981519152610c2d8161115f565b6101645460408051918252602082018490527f341ccafbcebf06bf65a4c2db1a85106ad3c0d9421c1f3207d7d1f76791e479c9910160405180910390a15061016455565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b610ca4611237565b610cac61127f565b610cb58161171b565b6000610cbf611a24565b90506000816001600160a01b0316634579661d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d259190613962565b1115610d8d576040516360a2863f60e11b81526001600160a01b0382169063c1450c7e90610d5a908590600090600401613952565b600060405180830381600087803b158015610d7457600080fd5b505af1158015610d88573d6000803e3d6000fd5b505050505b610d978233611a84565b50610916600160cd55565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316639d1b5a0a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e02573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109259190613986565b600080610e3285611ad2565b90508360ff168160200151600c610e4991906139b9565b60ff161015610e6b57604051637142e1e560e11b815260040160405180910390fd5b610e7a81856101635486611b63565b9150505b9392505050565b600061092560ca611c60565b610e99611237565b610ea161127f565b610eac816000611c6a565b610eba336000806000611d95565b610916600160cd55565b600080516020613faa833981519152610edc8161115f565b81610ee9576106d1611ecd565b6106d1611f19565b600054610100900460ff1615808015610f115750600054600160ff909116105b80610f325750610f2030611f56565b158015610f32575060005460ff166001145b610f955760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610758565b6000805460ff191660011790558015610fb8576000805461ff0019166101001790555b6001600160a01b038416610fdf5760405163d92e233d60e01b815260040160405180910390fd5b610fe98383611f65565b610ff284612038565b610ffa61205f565b8015610af7576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150505050565b61104d611237565b61105561127f565b611060838383612086565b61106a8484611c6a565b610aed3384600080611d95565b6000806110858360046118d3565b905061108f612206565b6001600160a01b031663ad3d19d5858360016040518463ffffffff1660e01b81526004016110bf939291906139d2565b602060405180830381865afa1580156110dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111009190613962565b949350505050565b60006106b760ca83612266565b61111e826106d5565b6111278161115f565b6107128383611515565b60006106b760ca8361227b565b6000611158600080516020613f2a83398151915283610c71565b1592915050565b6109168133612287565b61117281611f56565b61118f57604051630747d8c560e31b815260040160405180910390fd5b60c980546001600160a01b0319166001600160a01b0392909216919091179055565b6111bb8282610c71565b6106d15760008281526065602090815260408083206001600160a01b03851684529091529020805460ff191660011790556111f33390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60975460ff161561127d5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610758565b565b600260cd54036112d15760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610758565b600260cd55565b600080600085856040516020016112f09291906139f5565b60408051601f198184030181528282528051602091820120908301520160408051601f198184030181529181528151602092830120600081815261016590935291205490915060ff161561135757604051637242b99b60e11b815260040160405180910390fd5b600081815261016560205260409020805460ff19166001179055610164546113808582846122e0565b61139d576040516309bde33960e01b815260040160405180910390fd5b90969095509350505050565b60006113b486611ad2565b905060008160200151600c6113c991906139b9565b90508060ff166000036113ef57604051630ec173f160e21b815260040160405180910390fd5b8060ff168660ff16111561141657604051633bf077a560e11b815260040160405180910390fd5b8060ff168660ff16036114325761142f878387876122f6565b91505b61016354600061144484898488611b63565b60208501805160ff908b018181169092528a1684036101635590915061146a8a86612401565b611472610da2565b6001600160a01b03166379cc679033846040518363ffffffff1660e01b815260040161149f9291906139f5565b600060405180830381600087803b1580156114b957600080fd5b505af11580156114cd573d6000803e3d6000fd5b505060405160ff841681528c92507fa07fb4b6c67d359d0ff55194b0ae712344245d43c9ab85ccbab7a56c2c26067a915060200160405180910390a250505050505050505050565b61151f8282610c71565b156106d15760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600080516020613f6a833981519152546001600160a01b031690565b60006106d18161115f565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156115d6576107128361247d565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611630575060408051601f3d908101601f1916820190925261162d91810190613962565b60015b6116935760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610758565b600080516020613f6a83398151915281146117025760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610758565b50610712838383612517565b60606000610e7e8361253c565b6040516331a9108f60e11b81526004810182905233906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636352211e90602401602060405180830381865afa158015611782573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a69190613986565b6001600160a01b0316146109165760405163d6c86cb560e01b815260048101829052602401610758565b60006117da611a24565b6001600160a01b0316634579661d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611817573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183b9190613962565b15919050565b611849613315565b60405163b09afec160e01b8152600481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b09afec19060240161010060405180830381865afa1580156118af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b79190613b2c565b6000806119028460028111156118eb576118eb613b89565b8460078111156118fd576118fd613b89565b612598565b60ff169050600483600781111561191b5761191b613b89565b14806119385750600283600781111561193657611936613b89565b145b15610e7e5768056bc75e2d63100000029392505050565b611957613348565b81156119b25760006119738561196b612206565b8560016125ee565b9050600061198388878488612690565b6001600160a01b03871660c08901529050600061199f89612768565b82815290506119ae89826127fe565b5050505b6119ba611a24565b6001600160a01b031663c1450c7e8760016040518363ffffffff1660e01b81526004016119e8929190613952565b600060405180830381600087803b158015611a0257600080fd5b505af1158015611a16573d6000803e3d6000fd5b509698975050505050505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166361d027b36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e02573d6000803e3d6000fd5b6000611a8f83611ad2565b90506000611a9c84612768565b9050611ab2848360c00151836000015186612852565b50600060c083018190528152611ac88483612401565b610af784826127fe565b611ada613348565b604051637cdc4c2f60e11b8152600481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063f9b8985e9060240160e060405180830381865afa158015611b3f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b79190613b9f565b6000808315611bf357611b74610da2565b6001600160a01b0316632b112e496040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611bcd575060408051601f3d908101601f19168201909252611bca91810190613962565b60015b15611bf357611bef611bdf8683613bbb565b69010f0cf064dd59200000612930565b9150505b8460ff16611c0a82683635c9adc5dea00000612946565b611c149190613bdd565b90508215611c3857620f4240611c2b600083613bdd565b611c359190613bbb565b90505b6000611c49876000015160036118d3565b9050611c558183613bdd565b979650505050505050565b60006106b7825490565b6000611c74612206565b90507f00000000000000000000000000000000000000000000000000000000000000006000611ca48460026118d3565b8551909150600080805b83811015611d7b57888181518110611cc857611cc8613bf4565b60200260200101519150611cdc8287612955565b611d558288846001600160a01b03166370a08231336040518263ffffffff1660e01b8152600401611d0d91906133b0565b602060405180830381865afa158015611d2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d4e9190613962565b60006125ee565b611d5f9084613c0a565b9250848310611d7357505050505050505050565b600101611cae565b506040516374c9171160e01b815260040160405180910390fd5b60408051610120810182526000918190810180876002811115611dba57611dba613b89565b81526020018560ff168152602001611dd38860006118d3565b60ff168152602001611de68860016118d3565b60ff1681526000602080830182905265ffffffffffff89166040808501919091526060909301829052928452815180840190925281529101529050611e2c82600c6139b9565b60ff166101636000828254611e419190613c0a565b909155505060405163ce3f506f60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063ce3f506f90611e949088908590600401613cc0565b600060405180830381600087803b158015611eae57600080fd5b505af1158015611ec2573d6000803e3d6000fd5b505050505050505050565b611ed56129e0565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051611f0f91906133b0565b60405180910390a1565b611f21611237565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611f023390565b6001600160a01b03163b151590565b600054610100900460ff16611f8c5760405162461bcd60e51b815260040161075890613cf5565b6001600160a01b0382161580611fa957506001600160a01b038116155b15611fc75760405163d92e233d60e01b815260040160405180910390fd5b611fcf61205f565b611fd7612a29565b611fe2600033612a58565b611ffa600080516020613f8a83398151915283612a58565b612012600080516020613faa83398151915282612a58565b6106d1600080516020613f2a833981519152600080516020613f8a833981519152612a62565b600054610100900460ff1661118f5760405162461bcd60e51b815260040161075890613cf5565b600054610100900460ff1661127d5760405162461bcd60e51b815260040161075890613cf5565b61208e613348565b600080808481806120a08a60056118d3565b905060006120af8b60066118d3565b905060006120be8c60076118d3565b905060005b858110156121c2578b8b828181106120dd576120dd613bf4565b9050602002013594506120ef8561171b565b6120f885611ad2565b6020810151909a5060ff16600c1461212357604051637142e1e560e11b815260040160405180910390fd5b89608001516121ba576000808b51600281111561214257612142613b89565b14801561214e5750848a105b1561215f57506001988901986121a1565b60018b51600281111561217457612174613b89565b14801561218057508389105b1561219157506001978801976121a1565b828810156121a157506001968701965b80156121b857600160808c01526121b8868c612401565b505b6001016120c3565b50828810806121d057508187105b806121da57508086105b156121f8576040516309a734db60e31b815260040160405180910390fd5b505050505050505050505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637dc0d1d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e02573d6000803e3d6000fd5b6000610e7e836001600160a01b038416612ab5565b6000610e7e8383612acd565b6122918282610c71565b6106d15761229e81612af7565b6122a9836020612b09565b6040516020016122ba929190613d64565b60408051601f198184030181529082905262461bcd60e51b825261075891600401613dd3565b6000826122ed8584612ca4565b14949350505050565b6122fe613348565b6123066117d0565b612355576001600160a01b03831661233157604051631c0eb28960e11b815260040160405180910390fd5b6000612342856000015160046118d3565b9050612351868686868561194f565b9450505b61235d611a24565b6001600160a01b031663c1450c7e8660016040518363ffffffff1660e01b815260040161238b929190613952565b600060405180830381600087803b1580156123a557600080fd5b505af11580156123b9573d6000803e3d6000fd5b50505065ffffffffffff421660a086015250604051339086907fe7e38e098beb1732df08ee49549910543e4ecb953da8d895cb6a19ef0a76fb7590600090a350919392505050565b60405163d4bef91b60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063d4bef91b9061244f9085908590600401613e06565b600060405180830381600087803b15801561246957600080fd5b505af11580156107cf573d6000803e3d6000fd5b61248681611f56565b6124e85760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610758565b600080516020613f6a83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61252083612cf1565b60008251118061252d5750805b1561071257610af78383612d31565b60608160000180548060200260200160405190810160405280929190818152602001828054801561258c57602002820191906000526020600020905b815481526020019060010190808311612578575b50505050509050919050565b600060405180604001604052806018815260200174010203010b78010101010a64010000000a0a00000160581b815250838360030201815181106125de576125de613bf4565b016020015160f81c905092915050565b600080846001600160a01b031663616b3c278786866040518463ffffffff1660e01b8152600401612621939291906139d2565b6020604051808303816000875af1158015612640573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126649190613962565b905080600003612687576040516391248c2f60e01b815260040160405180910390fd5b95945050505050565b60008061269c85612e1a565b604051631c57762b60e31b815260048101889052602481018690529091506000906001600160a01b0383169063e2bbb158906044016020604051808303816000875af11580156126f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127149190613962565b905061272286858488612f5f565b867fdb9f4f483629adc742ab3c617347f30d312040977540207f893353c316e41e6587878460405161275693929190613e1b565b60405180910390a29695505050505050565b60408051602081018252600081529051632e6faca960e11b8152600481018390526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690635cdf595290602401602060405180830381865afa1580156127da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b79190613e3c565b6040516351d53f8560e11b815260048101839052815160248201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a3aa7f0a9060440161244f565b60008061285e85612e1a565b604051630ad58d2f60e01b815260048101889052602481018690526001600160a01b038581166044830152919250600091831690630ad58d2f906064016020604051808303816000875af11580156128ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128de9190613962565b9050836001600160a01b0316877f9be1e46e992af75de5e2885a61decbd9d034da8f92db4912730192a7f358c07088848960405161291e93929190613e1b565b60405180910390a39695505050505050565b600081831061293f5781610e7e565b5090919050565b600081831161293f5781610e7e565b604051638e8f294b60e01b81526001600160a01b03821690638e8f294b906129819085906004016133b0565b606060405180830381865afa15801561299e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129c29190613e58565b516106d157604051639db8d5b160e01b815260040160405180910390fd5b60975460ff1661127d5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610758565b600054610100900460ff16612a505760405162461bcd60e51b815260040161075890613cf5565b61127d612fb9565b6106d182826111b1565b6000612a6d836106d5565b600084815260656020526040808220600101859055519192508391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b60009081526001919091016020526040902054151590565b6000826000018281548110612ae457612ae4613bf4565b9060005260206000200154905092915050565b60606106b76001600160a01b03831660145b60606000612b18836002613bdd565b612b23906002613c0a565b6001600160401b03811115612b3a57612b3a61344a565b6040519080825280601f01601f191660200182016040528015612b64576020820181803683370190505b509050600360fc1b81600081518110612b7f57612b7f613bf4565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612bae57612bae613bf4565b60200101906001600160f81b031916908160001a9053506000612bd2846002613bdd565b612bdd906001613c0a565b90505b6001811115612c55576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612c1157612c11613bf4565b1a60f81b828281518110612c2757612c27613bf4565b60200101906001600160f81b031916908160001a90535060049490941c93612c4e81613ec0565b9050612be0565b508315610e7e5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610758565b600081815b8451811015612ce957612cd582868381518110612cc857612cc8613bf4565b6020026020010151612fec565b915080612ce181613ed7565b915050612ca9565b509392505050565b612cfa8161247d565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060612d3c83611f56565b612d975760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610758565b600080846001600160a01b031684604051612db29190613ef0565b600060405180830381855af49150503d8060008114612ded576040519150601f19603f3d011682016040523d82523d6000602084013e612df2565b606091505b50915091506126878282604051806060016040528060278152602001613fca6027913961301b565b6000806001600160a01b038316612e4457604051630280e1e560e61b815260040160405180910390fd5b612e4f60ca84613034565b15612f3f5760c9546001600160a01b0316612e6981613049565b60405163189acdbd60e31b81529092506001600160a01b0383169063c4d66de890612e989087906004016133b0565b600060405180830381600087803b158015612eb257600080fd5b505af1158015612ec6573d6000803e3d6000fd5b505050506001600160a01b03848116600081815260cc602090815260409182902080548786166001600160a01b031990911681179091558251938452908301529183168183015290517f78081ad49eb559c54c054262ee36c97f89c82901fb5dd734427fe3a664d14c8a9181900360600190a1506106b7565b50506001600160a01b03908116600090815260cc60205260409020541690565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610af79085906130e3565b600054610100900460ff16612fe05760405162461bcd60e51b815260040161075890613cf5565b6097805460ff19169055565b6000818310613008576000828152602084905260409020610e7e565b6000838152602083905260409020610e7e565b6060831561302a575081610e7e565b610e7e83836131b5565b6000610e7e836001600160a01b0384166131df565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008260601b60e81c176000526e5af43d82803e903d91602b57fd5bf38260781b17602052603760096000f090506001600160a01b0381166130de5760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b6044820152606401610758565b919050565b6000613138826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166132299092919063ffffffff16565b80519091501561071257808060200190518101906131569190613f0c565b6107125760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610758565b8151156131c55781518083602001fd5b8060405162461bcd60e51b81526004016107589190613dd3565b60006131eb8383612ab5565b613221575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556106b7565b5060006106b7565b6060611100848460008585600080866001600160a01b031685876040516132509190613ef0565b60006040518083038185875af1925050503d806000811461328d576040519150601f19603f3d011682016040523d82523d6000602084013e613292565b606091505b5091509150611c55878383876060831561330b578251600003613304576132b885611f56565b6133045760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610758565b5081611100565b61110083836131b5565b6040518060400160405280613328613348565b81526020016133436040518060200160405280600081525090565b905290565b6040805160e08101909152806000815260006020820181905260408201819052606082018190526080820181905260a0820181905260c09091015290565b60006020828403121561339857600080fd5b81356001600160e01b031981168114610e7e57600080fd5b6001600160a01b0391909116815260200190565b6001600160a01b038116811461091657600080fd5b80356130de816133c4565b6000602082840312156133f657600080fd5b8135610e7e816133c4565b60006020828403121561341357600080fd5b5035919050565b6000806040838503121561342d57600080fd5b82359150602083013561343f816133c4565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156134885761348861344a565b604052919050565b60006001600160401b038211156134a9576134a961344a565b5060051b60200190565b600080600080600060a086880312156134cb57600080fd5b853594506020808701356134de816133c4565b94506040870135935060608701356001600160401b0381111561350057600080fd5b8701601f8101891361351157600080fd5b803561352461351f82613490565b613460565b81815260059190911b8201830190838101908b83111561354357600080fd5b928401925b8284101561356157833582529284019290840190613548565b8096505050505050613575608087016133d9565b90509295509295909350565b6020808252825182820181905260009190848201906040850190845b818110156135c25783516001600160a01b03168352928401929184019160010161359d565b50909695505050505050565b600080604083850312156135e157600080fd5b82356135ec816133c4565b91506020838101356001600160401b038082111561360957600080fd5b818601915086601f83011261361d57600080fd5b81358181111561362f5761362f61344a565b613641601f8201601f19168501613460565b9150808252878482850101111561365757600080fd5b80848401858401376000848284010152508093505050509250929050565b60ff8116811461091657600080fd5b60008060006060848603121561369957600080fd5b8335925060208401356136ab81613675565b915060408401356136bb816133c4565b809150509250925092565b801515811461091657600080fd5b6000806000606084860312156136e957600080fd5b8335925060208401356136fb81613675565b915060408401356136bb816136c6565b600082601f83011261371c57600080fd5b8135602061372c61351f83613490565b82815260059290921b8401810191818101908684111561374b57600080fd5b8286015b8481101561376f578035613762816133c4565b835291830191830161374f565b509695505050505050565b60006020828403121561378c57600080fd5b81356001600160401b038111156137a257600080fd5b6111008482850161370b565b6000602082840312156137c057600080fd5b8135610e7e816136c6565b6000806000606084860312156137e057600080fd5b83356137eb816133c4565b925060208401356136ab816133c4565b6003811061091657600080fd5b6000806000806060858703121561381e57600080fd5b84356001600160401b038082111561383557600080fd5b6138418883890161370b565b955060208701359150613853826137fb565b9093506040860135908082111561386957600080fd5b818701915087601f83011261387d57600080fd5b81358181111561388c57600080fd5b8860208260051b85010111156138a157600080fd5b95989497505060200194505050565b600080604083850312156138c357600080fd5b82356138ce816133c4565b9150602083013561343f816137fb565b6020808252602c90820152600080516020613f4a83398151915260408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c90820152600080516020613f4a83398151915260408201526b6163746976652070726f787960a01b606082015260800190565b9182521515602082015260400190565b60006020828403121561397457600080fd5b5051919050565b80516130de816133c4565b60006020828403121561399857600080fd5b8151610e7e816133c4565b634e487b7160e01b600052601160045260246000fd5b60ff82811682821603908111156106b7576106b76139a3565b6001600160a01b0393909316835260208301919091521515604082015260600190565b6001600160a01b03929092168252602082015260400190565b80516130de816136c6565b805165ffffffffffff811681146130de57600080fd5b600060e08284031215613a4157600080fd5b60405160e081016001600160401b0381118282101715613a6357613a6361344a565b80604052508091508251613a76816137fb565b81526020830151613a8681613675565b60208201526040830151613a9981613675565b60408201526060830151613aac81613675565b6060820152613abd60808401613a0e565b6080820152613ace60a08401613a19565b60a0820152613adf60c0840161397b565b60c08201525092915050565b600060208284031215613afd57600080fd5b604051602081016001600160401b0381118282101715613b1f57613b1f61344a565b6040529151825250919050565b60006101008284031215613b3f57600080fd5b604080519081016001600160401b0381118282101715613b6157613b6161344a565b604052613b6e8484613a2f565b8152613b7d8460e08501613aeb565b60208201529392505050565b634e487b7160e01b600052602160045260246000fd5b600060e08284031215613bb157600080fd5b610e7e8383613a2f565b600082613bd857634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176106b7576106b76139a3565b634e487b7160e01b600052603260045260246000fd5b808201808211156106b7576106b76139a3565b805160038110613c3d57634e487b7160e01b600052602160045260246000fd5b8083525060ff60208201511660208301526040810151613c62604084018260ff169052565b506060810151613c77606084018260ff169052565b506080810151613c8b608084018215159052565b5060a0810151613ca560a084018265ffffffffffff169052565b5060c081015161071260c08401826001600160a01b03169052565b6001600160a01b03831681528151610120820190613ce2906020840190613c1d565b6020830151516101008301529392505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60005b83811015613d5b578181015183820152602001613d43565b50506000910152565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351613d96816017850160208801613d40565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351613dc7816028840160208801613d40565b01602801949350505050565b6020815260008251806020840152613df2816040850160208701613d40565b601f01601f19169190910160400192915050565b8281526101008101610e7e6020830184613c1d565b6001600160a01b039390931683526020830191909152604082015260600190565b600060208284031215613e4e57600080fd5b610e7e8383613aeb565b600060608284031215613e6a57600080fd5b604051606081016001600160401b0381118282101715613e8c57613e8c61344a565b6040528251613e9a816136c6565b8152602083810151908201526040830151613eb4816136c6565b60408201529392505050565b600081613ecf57613ecf6139a3565b506000190190565b600060018201613ee957613ee96139a3565b5060010190565b60008251613f02818460208701613d40565b9190910192915050565b600060208284031215613f1e57600080fd5b8151610e7e816136c656fe21702c8af46127c7fa207f89d0b0a8441bb32959a0ac7df790e9ab1a25c9892646756e6374696f6e206d7573742062652063616c6c6564207468726f75676820360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc241ecf16d79d0f8dbfb92cbc07fe17840425976cf0667f022fe9877caa831b0865d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212209128a604cfbce17dbbfbf64b7d8ac6c650a8cd235fea78666bfe0e319ac80dbb64736f6c634300081100330000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a80000000000000000000000001775286cbe9db126a95abf52c58a3214fca26803

Deployed Bytecode

0x6080604052600436106101aa5760003560e01c806301ffc9a7146101af57806314b8194c146101e4578063174ef86a14610225578063248a9ca31461024757806324d7806c146102755780632f2ff15d14610295578063343a5962146102b557806336568abe146102d55780633659cfe6146102f5578063375a7cba146103155780634f1ef2861461033757806352d1902d1461034a5780635c975abb1461035f57806362b199c514610377578063684fe77914610399578063700cd58a146103b95780637394507e146103ed5780637cb647591461040d5780638efb3f4f1461042d57806391d148541461046357806396e83924146104835780639b5d2e78146104a3578063a217fddf146104b8578063a42fd192146104cd578063a5402544146104ed578063bba48a9014610502578063bd075b8414610522578063bedb86fb14610542578063c0c53b8b14610562578063c772356914610582578063cc10b9b3146105a2578063cd170311146105c2578063d547741f146105e2578063e63ab1e914610602578063ec87621c14610624578063f3c5400614610646578063f3c95c6014610666575b600080fd5b3480156101bb57600080fd5b506101cf6101ca366004613386565b610686565b60405190151581526020015b60405180910390f35b3480156101f057600080fd5b506102187f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a881565b6040516101db91906133b0565b34801561023157600080fd5b506102456102403660046133e4565b6106bd565b005b34801561025357600080fd5b50610267610262366004613401565b6106d5565b6040519081526020016101db565b34801561028157600080fd5b506101cf6102903660046133e4565b6106ea565b3480156102a157600080fd5b506102456102b036600461341a565b6106f6565b3480156102c157600080fd5b506102456102d03660046134b3565b610717565b3480156102e157600080fd5b506102456102f036600461341a565b6107d7565b34801561030157600080fd5b506102456103103660046133e4565b610851565b34801561032157600080fd5b5061032a610919565b6040516101db9190613581565b6102456103453660046135ce565b61092a565b34801561035657600080fd5b506102676109df565b34801561036b57600080fd5b5060975460ff166101cf565b34801561038357600080fd5b50610267600080516020613f2a83398151915281565b3480156103a557600080fd5b506102456103b4366004613684565b610a8d565b3480156103c557600080fd5b506102187f0000000000000000000000001775286cbe9db126a95abf52c58a3214fca2680381565b3480156103f957600080fd5b5061024561040836600461341a565b610afd565b34801561041957600080fd5b50610245610428366004613401565b610c15565b34801561043957600080fd5b506102186104483660046133e4565b60cc602052600090815260409020546001600160a01b031681565b34801561046f57600080fd5b506101cf61047e36600461341a565b610c71565b34801561048f57600080fd5b5061024561049e366004613401565b610c9c565b3480156104af57600080fd5b50610218610da2565b3480156104c457600080fd5b50610267600081565b3480156104d957600080fd5b506102676104e83660046136d4565b610e26565b3480156104f957600080fd5b50610267610e85565b34801561050e57600080fd5b5060c954610218906001600160a01b031681565b34801561052e57600080fd5b5061024561053d36600461377a565b610e91565b34801561054e57600080fd5b5061024561055d3660046137ae565b610ec4565b34801561056e57600080fd5b5061024561057d3660046137cb565b610ef1565b34801561058e57600080fd5b5061024561059d366004613808565b611045565b3480156105ae57600080fd5b506102676105bd3660046138b0565b611077565b3480156105ce57600080fd5b506101cf6105dd3660046133e4565b611108565b3480156105ee57600080fd5b506102456105fd36600461341a565b611115565b34801561060e57600080fd5b50610267600080516020613faa83398151915281565b34801561063057600080fd5b50610267600080516020613f8a83398151915281565b34801561065257600080fd5b50610218610661366004613401565b611131565b34801561067257600080fd5b506101cf6106813660046133e4565b61113e565b60006001600160e01b03198216637965db0b60e01b14806106b757506301ffc9a760e01b6001600160e01b03198316145b92915050565b60006106c88161115f565b6106d182611169565b5050565b60009081526065602052604090206001015490565b60006106b78183610c71565b6106ff826106d5565b6107088161115f565b61071283836111b1565b505050565b61071f611237565b83610738600080516020613f2a83398151915282610c71565b1561076157806040516339edf4c360e11b815260040161075891906133b0565b60405180910390fd5b61076961127f565b6000806107778787876112d8565b9150915061078a886001868a60016113a9565b60408051838152602081018390527f7d85331eec197ef05ed037cf88fe5937a220c6b65b6ea665bbf09736aef62c47910160405180910390a150506107cf600160cd55565b505050505050565b6001600160a01b03811633146108475760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610758565b6106d18282611515565b6001600160a01b037f0000000000000000000000001d4aebcae926bc775d80bd5a91252da6ce5d7d891630036108995760405162461bcd60e51b8152600401610758906138de565b7f0000000000000000000000001d4aebcae926bc775d80bd5a91252da6ce5d7d896001600160a01b03166108cb61157c565b6001600160a01b0316146108f15760405162461bcd60e51b815260040161075890613918565b6108fa81611598565b60408051600080825260208201909252610916918391906115a3565b50565b606061092560ca61170e565b905090565b6001600160a01b037f0000000000000000000000001d4aebcae926bc775d80bd5a91252da6ce5d7d891630036109725760405162461bcd60e51b8152600401610758906138de565b7f0000000000000000000000001d4aebcae926bc775d80bd5a91252da6ce5d7d896001600160a01b03166109a461157c565b6001600160a01b0316146109ca5760405162461bcd60e51b815260040161075890613918565b6109d382611598565b6106d1828260016115a3565b6000306001600160a01b037f0000000000000000000000001d4aebcae926bc775d80bd5a91252da6ce5d7d891614610a7a5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608401610758565b50600080516020613f6a83398151915290565b610a95611237565b33610aae600080516020613f2a83398151915282610c71565b15610ace57806040516339edf4c360e11b815260040161075891906133b0565b610ad661127f565b610adf8461171b565b610aed8484843360006113a9565b610af7600160cd55565b50505050565b610b05611237565b610b0d61127f565b610b168261171b565b610b1e6117d0565b610ba3576000610b2d83611841565b60208101515190915015610b5457604051637cca156760e11b815260040160405180910390fd5b6001600160a01b038216610b7b57604051631c0eb28960e11b815260040160405180910390fd5b805151600090610b8c9060046118d3565b9050610b9f84836000015185338561194f565b5050505b610bab611a24565b6001600160a01b031663c1450c7e8360016040518363ffffffff1660e01b8152600401610bd9929190613952565b600060405180830381600087803b158015610bf357600080fd5b505af1158015610c07573d6000803e3d6000fd5b505050506106d1600160cd55565b600080516020613f8a833981519152610c2d8161115f565b6101645460408051918252602082018490527f341ccafbcebf06bf65a4c2db1a85106ad3c0d9421c1f3207d7d1f76791e479c9910160405180910390a15061016455565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b610ca4611237565b610cac61127f565b610cb58161171b565b6000610cbf611a24565b90506000816001600160a01b0316634579661d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d259190613962565b1115610d8d576040516360a2863f60e11b81526001600160a01b0382169063c1450c7e90610d5a908590600090600401613952565b600060405180830381600087803b158015610d7457600080fd5b505af1158015610d88573d6000803e3d6000fd5b505050505b610d978233611a84565b50610916600160cd55565b60007f0000000000000000000000001775286cbe9db126a95abf52c58a3214fca268036001600160a01b0316639d1b5a0a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e02573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109259190613986565b600080610e3285611ad2565b90508360ff168160200151600c610e4991906139b9565b60ff161015610e6b57604051637142e1e560e11b815260040160405180910390fd5b610e7a81856101635486611b63565b9150505b9392505050565b600061092560ca611c60565b610e99611237565b610ea161127f565b610eac816000611c6a565b610eba336000806000611d95565b610916600160cd55565b600080516020613faa833981519152610edc8161115f565b81610ee9576106d1611ecd565b6106d1611f19565b600054610100900460ff1615808015610f115750600054600160ff909116105b80610f325750610f2030611f56565b158015610f32575060005460ff166001145b610f955760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610758565b6000805460ff191660011790558015610fb8576000805461ff0019166101001790555b6001600160a01b038416610fdf5760405163d92e233d60e01b815260040160405180910390fd5b610fe98383611f65565b610ff284612038565b610ffa61205f565b8015610af7576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150505050565b61104d611237565b61105561127f565b611060838383612086565b61106a8484611c6a565b610aed3384600080611d95565b6000806110858360046118d3565b905061108f612206565b6001600160a01b031663ad3d19d5858360016040518463ffffffff1660e01b81526004016110bf939291906139d2565b602060405180830381865afa1580156110dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111009190613962565b949350505050565b60006106b760ca83612266565b61111e826106d5565b6111278161115f565b6107128383611515565b60006106b760ca8361227b565b6000611158600080516020613f2a83398151915283610c71565b1592915050565b6109168133612287565b61117281611f56565b61118f57604051630747d8c560e31b815260040160405180910390fd5b60c980546001600160a01b0319166001600160a01b0392909216919091179055565b6111bb8282610c71565b6106d15760008281526065602090815260408083206001600160a01b03851684529091529020805460ff191660011790556111f33390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60975460ff161561127d5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610758565b565b600260cd54036112d15760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610758565b600260cd55565b600080600085856040516020016112f09291906139f5565b60408051601f198184030181528282528051602091820120908301520160408051601f198184030181529181528151602092830120600081815261016590935291205490915060ff161561135757604051637242b99b60e11b815260040160405180910390fd5b600081815261016560205260409020805460ff19166001179055610164546113808582846122e0565b61139d576040516309bde33960e01b815260040160405180910390fd5b90969095509350505050565b60006113b486611ad2565b905060008160200151600c6113c991906139b9565b90508060ff166000036113ef57604051630ec173f160e21b815260040160405180910390fd5b8060ff168660ff16111561141657604051633bf077a560e11b815260040160405180910390fd5b8060ff168660ff16036114325761142f878387876122f6565b91505b61016354600061144484898488611b63565b60208501805160ff908b018181169092528a1684036101635590915061146a8a86612401565b611472610da2565b6001600160a01b03166379cc679033846040518363ffffffff1660e01b815260040161149f9291906139f5565b600060405180830381600087803b1580156114b957600080fd5b505af11580156114cd573d6000803e3d6000fd5b505060405160ff841681528c92507fa07fb4b6c67d359d0ff55194b0ae712344245d43c9ab85ccbab7a56c2c26067a915060200160405180910390a250505050505050505050565b61151f8282610c71565b156106d15760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600080516020613f6a833981519152546001600160a01b031690565b60006106d18161115f565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156115d6576107128361247d565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611630575060408051601f3d908101601f1916820190925261162d91810190613962565b60015b6116935760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610758565b600080516020613f6a83398151915281146117025760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610758565b50610712838383612517565b60606000610e7e8361253c565b6040516331a9108f60e11b81526004810182905233906001600160a01b037f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a81690636352211e90602401602060405180830381865afa158015611782573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117a69190613986565b6001600160a01b0316146109165760405163d6c86cb560e01b815260048101829052602401610758565b60006117da611a24565b6001600160a01b0316634579661d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611817573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183b9190613962565b15919050565b611849613315565b60405163b09afec160e01b8152600481018390527f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a86001600160a01b03169063b09afec19060240161010060405180830381865afa1580156118af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b79190613b2c565b6000806119028460028111156118eb576118eb613b89565b8460078111156118fd576118fd613b89565b612598565b60ff169050600483600781111561191b5761191b613b89565b14806119385750600283600781111561193657611936613b89565b145b15610e7e5768056bc75e2d63100000029392505050565b611957613348565b81156119b25760006119738561196b612206565b8560016125ee565b9050600061198388878488612690565b6001600160a01b03871660c08901529050600061199f89612768565b82815290506119ae89826127fe565b5050505b6119ba611a24565b6001600160a01b031663c1450c7e8760016040518363ffffffff1660e01b81526004016119e8929190613952565b600060405180830381600087803b158015611a0257600080fd5b505af1158015611a16573d6000803e3d6000fd5b509698975050505050505050565b60007f0000000000000000000000001775286cbe9db126a95abf52c58a3214fca268036001600160a01b03166361d027b36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e02573d6000803e3d6000fd5b6000611a8f83611ad2565b90506000611a9c84612768565b9050611ab2848360c00151836000015186612852565b50600060c083018190528152611ac88483612401565b610af784826127fe565b611ada613348565b604051637cdc4c2f60e11b8152600481018390527f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a86001600160a01b03169063f9b8985e9060240160e060405180830381865afa158015611b3f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b79190613b9f565b6000808315611bf357611b74610da2565b6001600160a01b0316632b112e496040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611bcd575060408051601f3d908101601f19168201909252611bca91810190613962565b60015b15611bf357611bef611bdf8683613bbb565b69010f0cf064dd59200000612930565b9150505b8460ff16611c0a82683635c9adc5dea00000612946565b611c149190613bdd565b90508215611c3857620f4240611c2b600083613bdd565b611c359190613bbb565b90505b6000611c49876000015160036118d3565b9050611c558183613bdd565b979650505050505050565b60006106b7825490565b6000611c74612206565b90507f0000000000000000000000001775286cbe9db126a95abf52c58a3214fca268036000611ca48460026118d3565b8551909150600080805b83811015611d7b57888181518110611cc857611cc8613bf4565b60200260200101519150611cdc8287612955565b611d558288846001600160a01b03166370a08231336040518263ffffffff1660e01b8152600401611d0d91906133b0565b602060405180830381865afa158015611d2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d4e9190613962565b60006125ee565b611d5f9084613c0a565b9250848310611d7357505050505050505050565b600101611cae565b506040516374c9171160e01b815260040160405180910390fd5b60408051610120810182526000918190810180876002811115611dba57611dba613b89565b81526020018560ff168152602001611dd38860006118d3565b60ff168152602001611de68860016118d3565b60ff1681526000602080830182905265ffffffffffff89166040808501919091526060909301829052928452815180840190925281529101529050611e2c82600c6139b9565b60ff166101636000828254611e419190613c0a565b909155505060405163ce3f506f60e01b81526001600160a01b037f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a8169063ce3f506f90611e949088908590600401613cc0565b600060405180830381600087803b158015611eae57600080fd5b505af1158015611ec2573d6000803e3d6000fd5b505050505050505050565b611ed56129e0565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051611f0f91906133b0565b60405180910390a1565b611f21611237565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611f023390565b6001600160a01b03163b151590565b600054610100900460ff16611f8c5760405162461bcd60e51b815260040161075890613cf5565b6001600160a01b0382161580611fa957506001600160a01b038116155b15611fc75760405163d92e233d60e01b815260040160405180910390fd5b611fcf61205f565b611fd7612a29565b611fe2600033612a58565b611ffa600080516020613f8a83398151915283612a58565b612012600080516020613faa83398151915282612a58565b6106d1600080516020613f2a833981519152600080516020613f8a833981519152612a62565b600054610100900460ff1661118f5760405162461bcd60e51b815260040161075890613cf5565b600054610100900460ff1661127d5760405162461bcd60e51b815260040161075890613cf5565b61208e613348565b600080808481806120a08a60056118d3565b905060006120af8b60066118d3565b905060006120be8c60076118d3565b905060005b858110156121c2578b8b828181106120dd576120dd613bf4565b9050602002013594506120ef8561171b565b6120f885611ad2565b6020810151909a5060ff16600c1461212357604051637142e1e560e11b815260040160405180910390fd5b89608001516121ba576000808b51600281111561214257612142613b89565b14801561214e5750848a105b1561215f57506001988901986121a1565b60018b51600281111561217457612174613b89565b14801561218057508389105b1561219157506001978801976121a1565b828810156121a157506001968701965b80156121b857600160808c01526121b8868c612401565b505b6001016120c3565b50828810806121d057508187105b806121da57508086105b156121f8576040516309a734db60e31b815260040160405180910390fd5b505050505050505050505050565b60007f0000000000000000000000001775286cbe9db126a95abf52c58a3214fca268036001600160a01b0316637dc0d1d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e02573d6000803e3d6000fd5b6000610e7e836001600160a01b038416612ab5565b6000610e7e8383612acd565b6122918282610c71565b6106d15761229e81612af7565b6122a9836020612b09565b6040516020016122ba929190613d64565b60408051601f198184030181529082905262461bcd60e51b825261075891600401613dd3565b6000826122ed8584612ca4565b14949350505050565b6122fe613348565b6123066117d0565b612355576001600160a01b03831661233157604051631c0eb28960e11b815260040160405180910390fd5b6000612342856000015160046118d3565b9050612351868686868561194f565b9450505b61235d611a24565b6001600160a01b031663c1450c7e8660016040518363ffffffff1660e01b815260040161238b929190613952565b600060405180830381600087803b1580156123a557600080fd5b505af11580156123b9573d6000803e3d6000fd5b50505065ffffffffffff421660a086015250604051339086907fe7e38e098beb1732df08ee49549910543e4ecb953da8d895cb6a19ef0a76fb7590600090a350919392505050565b60405163d4bef91b60e01b81526001600160a01b037f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a8169063d4bef91b9061244f9085908590600401613e06565b600060405180830381600087803b15801561246957600080fd5b505af11580156107cf573d6000803e3d6000fd5b61248681611f56565b6124e85760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610758565b600080516020613f6a83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61252083612cf1565b60008251118061252d5750805b1561071257610af78383612d31565b60608160000180548060200260200160405190810160405280929190818152602001828054801561258c57602002820191906000526020600020905b815481526020019060010190808311612578575b50505050509050919050565b600060405180604001604052806018815260200174010203010b78010101010a64010000000a0a00000160581b815250838360030201815181106125de576125de613bf4565b016020015160f81c905092915050565b600080846001600160a01b031663616b3c278786866040518463ffffffff1660e01b8152600401612621939291906139d2565b6020604051808303816000875af1158015612640573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126649190613962565b905080600003612687576040516391248c2f60e01b815260040160405180910390fd5b95945050505050565b60008061269c85612e1a565b604051631c57762b60e31b815260048101889052602481018690529091506000906001600160a01b0383169063e2bbb158906044016020604051808303816000875af11580156126f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127149190613962565b905061272286858488612f5f565b867fdb9f4f483629adc742ab3c617347f30d312040977540207f893353c316e41e6587878460405161275693929190613e1b565b60405180910390a29695505050505050565b60408051602081018252600081529051632e6faca960e11b8152600481018390526001600160a01b037f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a81690635cdf595290602401602060405180830381865afa1580156127da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b79190613e3c565b6040516351d53f8560e11b815260048101839052815160248201527f0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a86001600160a01b03169063a3aa7f0a9060440161244f565b60008061285e85612e1a565b604051630ad58d2f60e01b815260048101889052602481018690526001600160a01b038581166044830152919250600091831690630ad58d2f906064016020604051808303816000875af11580156128ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128de9190613962565b9050836001600160a01b0316877f9be1e46e992af75de5e2885a61decbd9d034da8f92db4912730192a7f358c07088848960405161291e93929190613e1b565b60405180910390a39695505050505050565b600081831061293f5781610e7e565b5090919050565b600081831161293f5781610e7e565b604051638e8f294b60e01b81526001600160a01b03821690638e8f294b906129819085906004016133b0565b606060405180830381865afa15801561299e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129c29190613e58565b516106d157604051639db8d5b160e01b815260040160405180910390fd5b60975460ff1661127d5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610758565b600054610100900460ff16612a505760405162461bcd60e51b815260040161075890613cf5565b61127d612fb9565b6106d182826111b1565b6000612a6d836106d5565b600084815260656020526040808220600101859055519192508391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b60009081526001919091016020526040902054151590565b6000826000018281548110612ae457612ae4613bf4565b9060005260206000200154905092915050565b60606106b76001600160a01b03831660145b60606000612b18836002613bdd565b612b23906002613c0a565b6001600160401b03811115612b3a57612b3a61344a565b6040519080825280601f01601f191660200182016040528015612b64576020820181803683370190505b509050600360fc1b81600081518110612b7f57612b7f613bf4565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612bae57612bae613bf4565b60200101906001600160f81b031916908160001a9053506000612bd2846002613bdd565b612bdd906001613c0a565b90505b6001811115612c55576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612c1157612c11613bf4565b1a60f81b828281518110612c2757612c27613bf4565b60200101906001600160f81b031916908160001a90535060049490941c93612c4e81613ec0565b9050612be0565b508315610e7e5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610758565b600081815b8451811015612ce957612cd582868381518110612cc857612cc8613bf4565b6020026020010151612fec565b915080612ce181613ed7565b915050612ca9565b509392505050565b612cfa8161247d565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060612d3c83611f56565b612d975760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610758565b600080846001600160a01b031684604051612db29190613ef0565b600060405180830381855af49150503d8060008114612ded576040519150601f19603f3d011682016040523d82523d6000602084013e612df2565b606091505b50915091506126878282604051806060016040528060278152602001613fca6027913961301b565b6000806001600160a01b038316612e4457604051630280e1e560e61b815260040160405180910390fd5b612e4f60ca84613034565b15612f3f5760c9546001600160a01b0316612e6981613049565b60405163189acdbd60e31b81529092506001600160a01b0383169063c4d66de890612e989087906004016133b0565b600060405180830381600087803b158015612eb257600080fd5b505af1158015612ec6573d6000803e3d6000fd5b505050506001600160a01b03848116600081815260cc602090815260409182902080548786166001600160a01b031990911681179091558251938452908301529183168183015290517f78081ad49eb559c54c054262ee36c97f89c82901fb5dd734427fe3a664d14c8a9181900360600190a1506106b7565b50506001600160a01b03908116600090815260cc60205260409020541690565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610af79085906130e3565b600054610100900460ff16612fe05760405162461bcd60e51b815260040161075890613cf5565b6097805460ff19169055565b6000818310613008576000828152602084905260409020610e7e565b6000838152602083905260409020610e7e565b6060831561302a575081610e7e565b610e7e83836131b5565b6000610e7e836001600160a01b0384166131df565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008260601b60e81c176000526e5af43d82803e903d91602b57fd5bf38260781b17602052603760096000f090506001600160a01b0381166130de5760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b6044820152606401610758565b919050565b6000613138826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166132299092919063ffffffff16565b80519091501561071257808060200190518101906131569190613f0c565b6107125760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610758565b8151156131c55781518083602001fd5b8060405162461bcd60e51b81526004016107589190613dd3565b60006131eb8383612ab5565b613221575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556106b7565b5060006106b7565b6060611100848460008585600080866001600160a01b031685876040516132509190613ef0565b60006040518083038185875af1925050503d806000811461328d576040519150601f19603f3d011682016040523d82523d6000602084013e613292565b606091505b5091509150611c55878383876060831561330b578251600003613304576132b885611f56565b6133045760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610758565b5081611100565b61110083836131b5565b6040518060400160405280613328613348565b81526020016133436040518060200160405280600081525090565b905290565b6040805160e08101909152806000815260006020820181905260408201819052606082018190526080820181905260a0820181905260c09091015290565b60006020828403121561339857600080fd5b81356001600160e01b031981168114610e7e57600080fd5b6001600160a01b0391909116815260200190565b6001600160a01b038116811461091657600080fd5b80356130de816133c4565b6000602082840312156133f657600080fd5b8135610e7e816133c4565b60006020828403121561341357600080fd5b5035919050565b6000806040838503121561342d57600080fd5b82359150602083013561343f816133c4565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156134885761348861344a565b604052919050565b60006001600160401b038211156134a9576134a961344a565b5060051b60200190565b600080600080600060a086880312156134cb57600080fd5b853594506020808701356134de816133c4565b94506040870135935060608701356001600160401b0381111561350057600080fd5b8701601f8101891361351157600080fd5b803561352461351f82613490565b613460565b81815260059190911b8201830190838101908b83111561354357600080fd5b928401925b8284101561356157833582529284019290840190613548565b8096505050505050613575608087016133d9565b90509295509295909350565b6020808252825182820181905260009190848201906040850190845b818110156135c25783516001600160a01b03168352928401929184019160010161359d565b50909695505050505050565b600080604083850312156135e157600080fd5b82356135ec816133c4565b91506020838101356001600160401b038082111561360957600080fd5b818601915086601f83011261361d57600080fd5b81358181111561362f5761362f61344a565b613641601f8201601f19168501613460565b9150808252878482850101111561365757600080fd5b80848401858401376000848284010152508093505050509250929050565b60ff8116811461091657600080fd5b60008060006060848603121561369957600080fd5b8335925060208401356136ab81613675565b915060408401356136bb816133c4565b809150509250925092565b801515811461091657600080fd5b6000806000606084860312156136e957600080fd5b8335925060208401356136fb81613675565b915060408401356136bb816136c6565b600082601f83011261371c57600080fd5b8135602061372c61351f83613490565b82815260059290921b8401810191818101908684111561374b57600080fd5b8286015b8481101561376f578035613762816133c4565b835291830191830161374f565b509695505050505050565b60006020828403121561378c57600080fd5b81356001600160401b038111156137a257600080fd5b6111008482850161370b565b6000602082840312156137c057600080fd5b8135610e7e816136c6565b6000806000606084860312156137e057600080fd5b83356137eb816133c4565b925060208401356136ab816133c4565b6003811061091657600080fd5b6000806000806060858703121561381e57600080fd5b84356001600160401b038082111561383557600080fd5b6138418883890161370b565b955060208701359150613853826137fb565b9093506040860135908082111561386957600080fd5b818701915087601f83011261387d57600080fd5b81358181111561388c57600080fd5b8860208260051b85010111156138a157600080fd5b95989497505060200194505050565b600080604083850312156138c357600080fd5b82356138ce816133c4565b9150602083013561343f816137fb565b6020808252602c90820152600080516020613f4a83398151915260408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c90820152600080516020613f4a83398151915260408201526b6163746976652070726f787960a01b606082015260800190565b9182521515602082015260400190565b60006020828403121561397457600080fd5b5051919050565b80516130de816133c4565b60006020828403121561399857600080fd5b8151610e7e816133c4565b634e487b7160e01b600052601160045260246000fd5b60ff82811682821603908111156106b7576106b76139a3565b6001600160a01b0393909316835260208301919091521515604082015260600190565b6001600160a01b03929092168252602082015260400190565b80516130de816136c6565b805165ffffffffffff811681146130de57600080fd5b600060e08284031215613a4157600080fd5b60405160e081016001600160401b0381118282101715613a6357613a6361344a565b80604052508091508251613a76816137fb565b81526020830151613a8681613675565b60208201526040830151613a9981613675565b60408201526060830151613aac81613675565b6060820152613abd60808401613a0e565b6080820152613ace60a08401613a19565b60a0820152613adf60c0840161397b565b60c08201525092915050565b600060208284031215613afd57600080fd5b604051602081016001600160401b0381118282101715613b1f57613b1f61344a565b6040529151825250919050565b60006101008284031215613b3f57600080fd5b604080519081016001600160401b0381118282101715613b6157613b6161344a565b604052613b6e8484613a2f565b8152613b7d8460e08501613aeb565b60208201529392505050565b634e487b7160e01b600052602160045260246000fd5b600060e08284031215613bb157600080fd5b610e7e8383613a2f565b600082613bd857634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176106b7576106b76139a3565b634e487b7160e01b600052603260045260246000fd5b808201808211156106b7576106b76139a3565b805160038110613c3d57634e487b7160e01b600052602160045260246000fd5b8083525060ff60208201511660208301526040810151613c62604084018260ff169052565b506060810151613c77606084018260ff169052565b506080810151613c8b608084018215159052565b5060a0810151613ca560a084018265ffffffffffff169052565b5060c081015161071260c08401826001600160a01b03169052565b6001600160a01b03831681528151610120820190613ce2906020840190613c1d565b6020830151516101008301529392505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60005b83811015613d5b578181015183820152602001613d43565b50506000910152565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351613d96816017850160208801613d40565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351613dc7816028840160208801613d40565b01602801949350505050565b6020815260008251806020840152613df2816040850160208701613d40565b601f01601f19169190910160400192915050565b8281526101008101610e7e6020830184613c1d565b6001600160a01b039390931683526020830191909152604082015260600190565b600060208284031215613e4e57600080fd5b610e7e8383613aeb565b600060608284031215613e6a57600080fd5b604051606081016001600160401b0381118282101715613e8c57613e8c61344a565b6040528251613e9a816136c6565b8152602083810151908201526040830151613eb4816136c6565b60408201529392505050565b600081613ecf57613ecf6139a3565b506000190190565b600060018201613ee957613ee96139a3565b5060010190565b60008251613f02818460208701613d40565b9190910192915050565b600060208284031215613f1e57600080fd5b8151610e7e816136c656fe21702c8af46127c7fa207f89d0b0a8441bb32959a0ac7df790e9ab1a25c9892646756e6374696f6e206d7573742062652063616c6c6564207468726f75676820360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc241ecf16d79d0f8dbfb92cbc07fe17840425976cf0667f022fe9877caa831b0865d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212209128a604cfbce17dbbfbf64b7d8ac6c650a8cd235fea78666bfe0e319ac80dbb64736f6c63430008110033

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

0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a80000000000000000000000001775286cbe9db126a95abf52c58a3214fca26803

-----Decoded View---------------
Arg [0] : gnft_ (address): 0x2e86fA4440d93b1BFfEa5cA673314ef54216D0a8
Arg [1] : comptroller_ (address): 0x1775286Cbe9db126a95AbF52c58a3214FCA26803

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000002e86fa4440d93b1bffea5ca673314ef54216d0a8
Arg [1] : 0000000000000000000000001775286cbe9db126a95abf52c58a3214fca26803


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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