creation_sourcecode: {{
    "language": "Solidity",
    "settings": {
      "evmVersion": "london",
      "libraries": {},
      "metadata": {
        "bytecodeHash": "ipfs",
        "useLiteralContent": true
      },
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "remappings": [],
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    },
    "sources": {
      "@openzeppelin/contracts-upgradeable/access/IAccessControlEnumerableUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlUpgradeable.sol\";\n\n/**\n * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.\n */\ninterface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable {\n    /**\n     * @dev Returns one of the accounts that have `role`. `index` must be a\n     * value between 0 and {getRoleMemberCount}, non-inclusive.\n     *\n     * Role bearers are not sorted in any particular way, and their ordering may\n     * change at any point.\n     *\n     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n     * you perform all queries on the same block. See the following\n     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n     * for more information.\n     */\n    function getRoleMember(bytes32 role, uint256 index) external view returns (address);\n\n    /**\n     * @dev Returns the number of accounts that have `role`. Can be used\n     * together with {getRoleMember} to enumerate all bearers of a role.\n     */\n    function getRoleMemberCount(bytes32 role) external view returns (uint256);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControlUpgradeable {\n    /**\n     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n     *\n     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n     * {RoleAdminChanged} not being emitted signaling this.\n     *\n     * _Available since v3.1._\n     */\n    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n    /**\n     * @dev Emitted when `account` is granted `role`.\n     *\n     * `sender` is the account that originated the contract call, an admin role\n     * bearer except when using {AccessControl-_setupRole}.\n     */\n    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Emitted when `account` is revoked `role`.\n     *\n     * `sender` is the account that originated the contract call:\n     *   - if using `revokeRole`, it is the admin role bearer\n     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)\n     */\n    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Returns `true` if `account` has been granted `role`.\n     */\n    function hasRole(bytes32 role, address account) external view returns (bool);\n\n    /**\n     * @dev Returns the admin role that controls `role`. See {grantRole} and\n     * {revokeRole}.\n     *\n     * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n     */\n    function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function grantRole(bytes32 role, address account) external;\n\n    /**\n     * @dev Revokes `role` from `account`.\n     *\n     * If `account` had been granted `role`, emits a {RoleRevoked} event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function revokeRole(bytes32 role, address account) external;\n\n    /**\n     * @dev Revokes `role` from the calling account.\n     *\n     * Roles are often managed via {grantRole} and {revokeRole}: this function's\n     * purpose is to provide a mechanism for accounts to lose their privileges\n     * if they are compromised (such as when a trusted device is misplaced).\n     *\n     * If the calling account had been granted `role`, emits a {RoleRevoked}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must be `account`.\n     */\n    function renounceRole(bytes32 role, address account) external;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/governance/utils/IVotesUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (governance/utils/IVotes.sol)\npragma solidity ^0.8.0;\n\n/**\n * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.\n *\n * _Available since v4.5._\n */\ninterface IVotesUpgradeable {\n    /**\n     * @dev Emitted when an account changes their delegate.\n     */\n    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n    /**\n     * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.\n     */\n    event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);\n\n    /**\n     * @dev Returns the current amount of votes that `account` has.\n     */\n    function getVotes(address account) external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`).\n     */\n    function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);\n\n    /**\n     * @dev Returns the total supply of votes available at the end of a past block (`blockNumber`).\n     *\n     * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.\n     * Votes that have not been delegated are still part of total supply, even though they would not participate in a\n     * vote.\n     */\n    function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);\n\n    /**\n     * @dev Returns the delegate that `account` has chosen.\n     */\n    function delegates(address account) external view returns (address);\n\n    /**\n     * @dev Delegates votes from the sender to `delegatee`.\n     */\n    function delegate(address delegatee) external;\n\n    /**\n     * @dev Delegates votes from signer to `delegatee`.\n     */\n    function delegateBySig(\n        address delegatee,\n        uint256 nonce,\n        uint256 expiry,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized < type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Internal function that returns the initialized version. Returns `_initialized`\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Internal function that returns the initialized version. Returns `_initializing`\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    function __ReentrancyGuard_init() internal onlyInitializing {\n        __ReentrancyGuard_init_unchained();\n    }\n\n    function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        _nonReentrantBefore();\n        _;\n        _nonReentrantAfter();\n    }\n\n    function _nonReentrantBefore() private {\n        // On the first call to nonReentrant, _status will be _NOT_ENTERED\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n    }\n\n    function _nonReentrantAfter() private {\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165Upgradeable.sol\";\n\n/**\n * @dev Required interface of an ERC1155 compliant contract, as defined in the\n * https://eips.ethereum.org/EIPS/eip-1155[EIP].\n *\n * _Available since v3.1._\n */\ninterface IERC1155Upgradeable is IERC165Upgradeable {\n    /**\n     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.\n     */\n    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\n\n    /**\n     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all\n     * transfers.\n     */\n    event TransferBatch(\n        address indexed operator,\n        address indexed from,\n        address indexed to,\n        uint256[] ids,\n        uint256[] values\n    );\n\n    /**\n     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to\n     * `approved`.\n     */\n    event ApprovalForAll(address indexed account, address indexed operator, bool approved);\n\n    /**\n     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.\n     *\n     * If an {URI} event was emitted for `id`, the standard\n     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value\n     * returned by {IERC1155MetadataURI-uri}.\n     */\n    event URI(string value, uint256 indexed id);\n\n    /**\n     * @dev Returns the amount of tokens of token type `id` owned by `account`.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function balanceOf(address account, uint256 id) external view returns (uint256);\n\n    /**\n     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.\n     *\n     * Requirements:\n     *\n     * - `accounts` and `ids` must have the same length.\n     */\n    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)\n        external\n        view\n        returns (uint256[] memory);\n\n    /**\n     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,\n     *\n     * Emits an {ApprovalForAll} event.\n     *\n     * Requirements:\n     *\n     * - `operator` cannot be the caller.\n     */\n    function setApprovalForAll(address operator, bool approved) external;\n\n    /**\n     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.\n     *\n     * See {setApprovalForAll}.\n     */\n    function isApprovedForAll(address account, address operator) external view returns (bool);\n\n    /**\n     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.\n     *\n     * Emits a {TransferSingle} event.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.\n     * - `from` must have a balance of tokens of type `id` of at least `amount`.\n     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the\n     * acceptance magic value.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 id,\n        uint256 amount,\n        bytes calldata data\n    ) external;\n\n    /**\n     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.\n     *\n     * Emits a {TransferBatch} event.\n     *\n     * Requirements:\n     *\n     * - `ids` and `amounts` must have the same length.\n     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the\n     * acceptance magic value.\n     */\n    function safeBatchTransferFrom(\n        address from,\n        address to,\n        uint256[] calldata ids,\n        uint256[] calldata amounts,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20Upgradeable.sol\";\nimport \"./extensions/IERC20MetadataUpgradeable.sol\";\nimport \"../../utils/ContextUpgradeable.sol\";\nimport \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {\n    mapping(address => uint256) private _balances;\n\n    mapping(address => mapping(address => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}.\n     *\n     * The default value of {decimals} is 18. To select a different value for\n     * {decimals} you should overload it.\n     *\n     * All two of these values are immutable: they can only be set once during\n     * construction.\n     */\n    function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {\n        __ERC20_init_unchained(name_, symbol_);\n    }\n\n    function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual override returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual override returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the value {ERC20} uses, unless this function is\n     * overridden;\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual override returns (uint8) {\n        return 18;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address to, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _transfer(owner, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n     * `transferFrom`. This is semantically equivalent to an infinite approval.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * NOTE: Does not update the allowance if the current allowance\n     * is the maximum `uint256`.\n     *\n     * Requirements:\n     *\n     * - `from` and `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``from``'s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) public virtual override returns (bool) {\n        address spender = _msgSender();\n        _spendAllowance(from, spender, amount);\n        _transfer(from, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, allowance(owner, spender) + addedValue);\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        uint256 currentAllowance = allowance(owner, spender);\n        require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n        unchecked {\n            _approve(owner, spender, currentAllowance - subtractedValue);\n        }\n\n        return true;\n    }\n\n    /**\n     * @dev Moves `amount` of tokens from `from` to `to`.\n     *\n     * This internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     */\n    function _transfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {\n        require(from != address(0), \"ERC20: transfer from the zero address\");\n        require(to != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(from, to, amount);\n\n        uint256 fromBalance = _balances[from];\n        require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n        unchecked {\n            _balances[from] = fromBalance - amount;\n            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n            // decrementing then incrementing.\n            _balances[to] += amount;\n        }\n\n        emit Transfer(from, to, amount);\n\n        _afterTokenTransfer(from, to, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply += amount;\n        unchecked {\n            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n            _balances[account] += amount;\n        }\n        emit Transfer(address(0), account, amount);\n\n        _afterTokenTransfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        uint256 accountBalance = _balances[account];\n        require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n        unchecked {\n            _balances[account] = accountBalance - amount;\n            // Overflow not possible: amount <= accountBalance <= totalSupply.\n            _totalSupply -= amount;\n        }\n\n        emit Transfer(account, address(0), amount);\n\n        _afterTokenTransfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(\n        address owner,\n        address spender,\n        uint256 amount\n    ) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n     *\n     * Does not update the allowance amount in case of infinite allowance.\n     * Revert if not enough allowance is available.\n     *\n     * Might emit an {Approval} event.\n     */\n    function _spendAllowance(\n        address owner,\n        address spender,\n        uint256 amount\n    ) internal virtual {\n        uint256 currentAllowance = allowance(owner, spender);\n        if (currentAllowance != type(uint256).max) {\n            require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n            unchecked {\n                _approve(owner, spender, currentAllowance - amount);\n            }\n        }\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {}\n\n    /**\n     * @dev Hook that is called after any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * has been transferred to `to`.\n     * - when `from` is zero, `amount` tokens have been minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _afterTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {}\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[45] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20Upgradeable {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20CappedUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Capped.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../ERC20Upgradeable.sol\";\nimport \"../../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Extension of {ERC20} that adds a cap to the supply of tokens.\n *\n * @custom:storage-size 51\n */\nabstract contract ERC20CappedUpgradeable is Initializable, ERC20Upgradeable {\n    uint256 private _cap;\n\n    /**\n     * @dev Sets the value of the `cap`. This value is immutable, it can only be\n     * set once during construction.\n     */\n    function __ERC20Capped_init(uint256 cap_) internal onlyInitializing {\n        __ERC20Capped_init_unchained(cap_);\n    }\n\n    function __ERC20Capped_init_unchained(uint256 cap_) internal onlyInitializing {\n        require(cap_ > 0, \"ERC20Capped: cap is 0\");\n        _cap = cap_;\n    }\n\n    /**\n     * @dev Returns the cap on the token's total supply.\n     */\n    function cap() public view virtual returns (uint256) {\n        return _cap;\n    }\n\n    /**\n     * @dev See {ERC20-_mint}.\n     */\n    function _mint(address account, uint256 amount) internal virtual override {\n        require(ERC20Upgradeable.totalSupply() + amount <= cap(), \"ERC20Capped: cap exceeded\");\n        super._mint(account, amount);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/extensions/ERC20Votes.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./draft-ERC20PermitUpgradeable.sol\";\nimport \"../../../utils/math/MathUpgradeable.sol\";\nimport \"../../../governance/utils/IVotesUpgradeable.sol\";\nimport \"../../../utils/math/SafeCastUpgradeable.sol\";\nimport \"../../../utils/cryptography/ECDSAUpgradeable.sol\";\nimport \"../../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound's,\n * and supports token supply up to 2^224^ - 1, while COMP is limited to 2^96^ - 1.\n *\n * NOTE: If exact COMP compatibility is required, use the {ERC20VotesComp} variant of this module.\n *\n * This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either\n * by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting\n * power can be queried through the public accessors {getVotes} and {getPastVotes}.\n *\n * By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it\n * requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.\n *\n * _Available since v4.2._\n */\nabstract contract ERC20VotesUpgradeable is Initializable, IVotesUpgradeable, ERC20PermitUpgradeable {\n    function __ERC20Votes_init() internal onlyInitializing {\n    }\n\n    function __ERC20Votes_init_unchained() internal onlyInitializing {\n    }\n    struct Checkpoint {\n        uint32 fromBlock;\n        uint224 votes;\n    }\n\n    bytes32 private constant _DELEGATION_TYPEHASH =\n        keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n    mapping(address => address) private _delegates;\n    mapping(address => Checkpoint[]) private _checkpoints;\n    Checkpoint[] private _totalSupplyCheckpoints;\n\n    /**\n     * @dev Get the `pos`-th checkpoint for `account`.\n     */\n    function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoint memory) {\n        return _checkpoints[account][pos];\n    }\n\n    /**\n     * @dev Get number of checkpoints for `account`.\n     */\n    function numCheckpoints(address account) public view virtual returns (uint32) {\n        return SafeCastUpgradeable.toUint32(_checkpoints[account].length);\n    }\n\n    /**\n     * @dev Get the address `account` is currently delegating to.\n     */\n    function delegates(address account) public view virtual override returns (address) {\n        return _delegates[account];\n    }\n\n    /**\n     * @dev Gets the current votes balance for `account`\n     */\n    function getVotes(address account) public view virtual override returns (uint256) {\n        uint256 pos = _checkpoints[account].length;\n        return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes;\n    }\n\n    /**\n     * @dev Retrieve the number of votes for `account` at the end of `blockNumber`.\n     *\n     * Requirements:\n     *\n     * - `blockNumber` must have been already mined\n     */\n    function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {\n        require(blockNumber < block.number, \"ERC20Votes: block not yet mined\");\n        return _checkpointsLookup(_checkpoints[account], blockNumber);\n    }\n\n    /**\n     * @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances.\n     * It is but NOT the sum of all the delegated votes!\n     *\n     * Requirements:\n     *\n     * - `blockNumber` must have been already mined\n     */\n    function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256) {\n        require(blockNumber < block.number, \"ERC20Votes: block not yet mined\");\n        return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);\n    }\n\n    /**\n     * @dev Lookup a value in a list of (sorted) checkpoints.\n     */\n    function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 blockNumber) private view returns (uint256) {\n        // We run a binary search to look for the earliest checkpoint taken after `blockNumber`.\n        //\n        // Initially we check if the block is recent to narrow the search range.\n        // During the loop, the index of the wanted checkpoint remains in the range [low-1, high).\n        // With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the invariant.\n        // - If the middle checkpoint is after `blockNumber`, we look in [low, mid)\n        // - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high)\n        // Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not\n        // out of bounds (in which case we're looking too far in the past and the result is 0).\n        // Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is\n        // past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out\n        // the same.\n        uint256 length = ckpts.length;\n\n        uint256 low = 0;\n        uint256 high = length;\n\n        if (length > 5) {\n            uint256 mid = length - MathUpgradeable.sqrt(length);\n            if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {\n                high = mid;\n            } else {\n                low = mid + 1;\n            }\n        }\n\n        while (low < high) {\n            uint256 mid = MathUpgradeable.average(low, high);\n            if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {\n                high = mid;\n            } else {\n                low = mid + 1;\n            }\n        }\n\n        return high == 0 ? 0 : _unsafeAccess(ckpts, high - 1).votes;\n    }\n\n    /**\n     * @dev Delegate votes from the sender to `delegatee`.\n     */\n    function delegate(address delegatee) public virtual override {\n        _delegate(_msgSender(), delegatee);\n    }\n\n    /**\n     * @dev Delegates votes from signer to `delegatee`\n     */\n    function delegateBySig(\n        address delegatee,\n        uint256 nonce,\n        uint256 expiry,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) public virtual override {\n        require(block.timestamp <= expiry, \"ERC20Votes: signature expired\");\n        address signer = ECDSAUpgradeable.recover(\n            _hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),\n            v,\n            r,\n            s\n        );\n        require(nonce == _useNonce(signer), \"ERC20Votes: invalid nonce\");\n        _delegate(signer, delegatee);\n    }\n\n    /**\n     * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).\n     */\n    function _maxSupply() internal view virtual returns (uint224) {\n        return type(uint224).max;\n    }\n\n    /**\n     * @dev Snapshots the totalSupply after it has been increased.\n     */\n    function _mint(address account, uint256 amount) internal virtual override {\n        super._mint(account, amount);\n        require(totalSupply() <= _maxSupply(), \"ERC20Votes: total supply risks overflowing votes\");\n\n        _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);\n    }\n\n    /**\n     * @dev Snapshots the totalSupply after it has been decreased.\n     */\n    function _burn(address account, uint256 amount) internal virtual override {\n        super._burn(account, amount);\n\n        _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);\n    }\n\n    /**\n     * @dev Move voting power when tokens are transferred.\n     *\n     * Emits a {IVotes-DelegateVotesChanged} event.\n     */\n    function _afterTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual override {\n        super._afterTokenTransfer(from, to, amount);\n\n        _moveVotingPower(delegates(from), delegates(to), amount);\n    }\n\n    /**\n     * @dev Change delegation for `delegator` to `delegatee`.\n     *\n     * Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.\n     */\n    function _delegate(address delegator, address delegatee) internal virtual {\n        address currentDelegate = delegates(delegator);\n        uint256 delegatorBalance = balanceOf(delegator);\n        _delegates[delegator] = delegatee;\n\n        emit DelegateChanged(delegator, currentDelegate, delegatee);\n\n        _moveVotingPower(currentDelegate, delegatee, delegatorBalance);\n    }\n\n    function _moveVotingPower(\n        address src,\n        address dst,\n        uint256 amount\n    ) private {\n        if (src != dst && amount > 0) {\n            if (src != address(0)) {\n                (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);\n                emit DelegateVotesChanged(src, oldWeight, newWeight);\n            }\n\n            if (dst != address(0)) {\n                (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);\n                emit DelegateVotesChanged(dst, oldWeight, newWeight);\n            }\n        }\n    }\n\n    function _writeCheckpoint(\n        Checkpoint[] storage ckpts,\n        function(uint256, uint256) view returns (uint256) op,\n        uint256 delta\n    ) private returns (uint256 oldWeight, uint256 newWeight) {\n        uint256 pos = ckpts.length;\n\n        Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0) : _unsafeAccess(ckpts, pos - 1);\n\n        oldWeight = oldCkpt.votes;\n        newWeight = op(oldWeight, delta);\n\n        if (pos > 0 && oldCkpt.fromBlock == block.number) {\n            _unsafeAccess(ckpts, pos - 1).votes = SafeCastUpgradeable.toUint224(newWeight);\n        } else {\n            ckpts.push(Checkpoint({fromBlock: SafeCastUpgradeable.toUint32(block.number), votes: SafeCastUpgradeable.toUint224(newWeight)}));\n        }\n    }\n\n    function _add(uint256 a, uint256 b) private pure returns (uint256) {\n        return a + b;\n    }\n\n    function _subtract(uint256 a, uint256 b) private pure returns (uint256) {\n        return a - b;\n    }\n\n    function _unsafeAccess(Checkpoint[] storage ckpts, uint256 pos) private pure returns (Checkpoint storage result) {\n        assembly {\n            mstore(0, ckpts.slot)\n            result.slot := add(keccak256(0, 0x20), pos)\n        }\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[47] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20Upgradeable.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20MetadataUpgradeable is IERC20Upgradeable {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/extensions/draft-ERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./draft-IERC20PermitUpgradeable.sol\";\nimport \"../ERC20Upgradeable.sol\";\nimport \"../../../utils/cryptography/ECDSAUpgradeable.sol\";\nimport \"../../../utils/cryptography/EIP712Upgradeable.sol\";\nimport \"../../../utils/CountersUpgradeable.sol\";\nimport \"../../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * _Available since v3.4._\n *\n * @custom:storage-size 51\n */\nabstract contract ERC20PermitUpgradeable is Initializable, ERC20Upgradeable, IERC20PermitUpgradeable, EIP712Upgradeable {\n    using CountersUpgradeable for CountersUpgradeable.Counter;\n\n    mapping(address => CountersUpgradeable.Counter) private _nonces;\n\n    // solhint-disable-next-line var-name-mixedcase\n    bytes32 private constant _PERMIT_TYPEHASH =\n        keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\n    /**\n     * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.\n     * However, to ensure consistency with the upgradeable transpiler, we will continue\n     * to reserve a slot.\n     * @custom:oz-renamed-from _PERMIT_TYPEHASH\n     */\n    // solhint-disable-next-line var-name-mixedcase\n    bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;\n\n    /**\n     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `\"1\"`.\n     *\n     * It's a good idea to use the same `name` that is defined as the ERC20 token name.\n     */\n    function __ERC20Permit_init(string memory name) internal onlyInitializing {\n        __EIP712_init_unchained(name, \"1\");\n    }\n\n    function __ERC20Permit_init_unchained(string memory) internal onlyInitializing {}\n\n    /**\n     * @dev See {IERC20Permit-permit}.\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) public virtual override {\n        require(block.timestamp <= deadline, \"ERC20Permit: expired deadline\");\n\n        bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));\n\n        bytes32 hash = _hashTypedDataV4(structHash);\n\n        address signer = ECDSAUpgradeable.recover(hash, v, r, s);\n        require(signer == owner, \"ERC20Permit: invalid signature\");\n\n        _approve(owner, spender, value);\n    }\n\n    /**\n     * @dev See {IERC20Permit-nonces}.\n     */\n    function nonces(address owner) public view virtual override returns (uint256) {\n        return _nonces[owner].current();\n    }\n\n    /**\n     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view override returns (bytes32) {\n        return _domainSeparatorV4();\n    }\n\n    /**\n     * @dev \"Consume a nonce\": return the current value and increment.\n     *\n     * _Available since v4.1._\n     */\n    function _useNonce(address owner) internal virtual returns (uint256 current) {\n        CountersUpgradeable.Counter storage nonce = _nonces[owner];\n        current = nonce.current();\n        nonce.increment();\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20PermitUpgradeable {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/ArraysUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Arrays.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./StorageSlotUpgradeable.sol\";\nimport \"./math/MathUpgradeable.sol\";\n\n/**\n * @dev Collection of functions related to array types.\n */\nlibrary ArraysUpgradeable {\n    using StorageSlotUpgradeable for bytes32;\n\n    /**\n     * @dev Searches a sorted `array` and returns the first index that contains\n     * a value greater or equal to `element`. If no such index exists (i.e. all\n     * values in the array are strictly less than `element`), the array length is\n     * returned. Time complexity O(log n).\n     *\n     * `array` is expected to be sorted in ascending order, and to contain no\n     * repeated elements.\n     */\n    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {\n        if (array.length == 0) {\n            return 0;\n        }\n\n        uint256 low = 0;\n        uint256 high = array.length;\n\n        while (low < high) {\n            uint256 mid = MathUpgradeable.average(low, high);\n\n            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)\n            // because Math.average rounds down (it does integer division with truncation).\n            if (unsafeAccess(array, mid).value > element) {\n                high = mid;\n            } else {\n                low = mid + 1;\n            }\n        }\n\n        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.\n        if (low > 0 && unsafeAccess(array, low - 1).value == element) {\n            return low - 1;\n        } else {\n            return low;\n        }\n    }\n\n    /**\n     * @dev Access an array in an \"unsafe\" way. Skips solidity \"index-out-of-range\" check.\n     *\n     * WARNING: Only use if you are certain `pos` is lower than the array length.\n     */\n    function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlotUpgradeable.AddressSlot storage) {\n        bytes32 slot;\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0, arr.slot)\n            slot := add(keccak256(0, 0x20), pos)\n        }\n        return slot.getAddressSlot();\n    }\n\n    /**\n     * @dev Access an array in an \"unsafe\" way. Skips solidity \"index-out-of-range\" check.\n     *\n     * WARNING: Only use if you are certain `pos` is lower than the array length.\n     */\n    function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlotUpgradeable.Bytes32Slot storage) {\n        bytes32 slot;\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0, arr.slot)\n            slot := add(keccak256(0, 0x20), pos)\n        }\n        return slot.getBytes32Slot();\n    }\n\n    /**\n     * @dev Access an array in an \"unsafe\" way. Skips solidity \"index-out-of-range\" check.\n     *\n     * WARNING: Only use if you are certain `pos` is lower than the array length.\n     */\n    function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlotUpgradeable.Uint256Slot storage) {\n        bytes32 slot;\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0, arr.slot)\n            slot := add(keccak256(0, 0x20), pos)\n        }\n        return slot.getUint256Slot();\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title Counters\n * @author Matt Condon (@shrugs)\n * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number\n * of elements in a mapping, issuing ERC721 ids, or counting request ids.\n *\n * Include with `using Counters for Counters.Counter;`\n */\nlibrary CountersUpgradeable {\n    struct Counter {\n        // This variable should never be directly accessed by users of the library: interactions must be restricted to\n        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n        // this feature: see https://github.com/ethereum/solidity/issues/4637\n        uint256 _value; // default: 0\n    }\n\n    function current(Counter storage counter) internal view returns (uint256) {\n        return counter._value;\n    }\n\n    function increment(Counter storage counter) internal {\n        unchecked {\n            counter._value += 1;\n        }\n    }\n\n    function decrement(Counter storage counter) internal {\n        uint256 value = counter._value;\n        require(value > 0, \"Counter: decrement overflow\");\n        unchecked {\n            counter._value = value - 1;\n        }\n    }\n\n    function reset(Counter storage counter) internal {\n        counter._value = 0;\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```\n * contract ERC1967 {\n *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n *     function _getImplementation() internal view returns (address) {\n *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n *     }\n *\n *     function _setImplementation(address newImplementation) internal {\n *         require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n *     }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\n */\nlibrary StorageSlotUpgradeable {\n    struct AddressSlot {\n        address value;\n    }\n\n    struct BooleanSlot {\n        bool value;\n    }\n\n    struct Bytes32Slot {\n        bytes32 value;\n    }\n\n    struct Uint256Slot {\n        uint256 value;\n    }\n\n    /**\n     * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n     */\n    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n     */\n    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n     */\n    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n     */\n    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/MathUpgradeable.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary StringsUpgradeable {\n    bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n    uint8 private constant _ADDRESS_LENGTH = 20;\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            uint256 length = MathUpgradeable.log10(value) + 1;\n            string memory buffer = new string(length);\n            uint256 ptr;\n            /// @solidity memory-safe-assembly\n            assembly {\n                ptr := add(buffer, add(32, length))\n            }\n            while (true) {\n                ptr--;\n                /// @solidity memory-safe-assembly\n                assembly {\n                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n                }\n                value /= 10;\n                if (value == 0) break;\n            }\n            return buffer;\n        }\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            return toHexString(value, MathUpgradeable.log256(value) + 1);\n        }\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n     */\n    function toHexString(address addr) internal pure returns (string memory) {\n        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../StringsUpgradeable.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSAUpgradeable {\n    enum RecoverError {\n        NoError,\n        InvalidSignature,\n        InvalidSignatureLength,\n        InvalidSignatureS,\n        InvalidSignatureV // Deprecated in v4.8\n    }\n\n    function _throwError(RecoverError error) private pure {\n        if (error == RecoverError.NoError) {\n            return; // no error: do nothing\n        } else if (error == RecoverError.InvalidSignature) {\n            revert(\"ECDSA: invalid signature\");\n        } else if (error == RecoverError.InvalidSignatureLength) {\n            revert(\"ECDSA: invalid signature length\");\n        } else if (error == RecoverError.InvalidSignatureS) {\n            revert(\"ECDSA: invalid signature 's' value\");\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature` or error string. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     *\n     * Documentation for signature generation:\n     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n        if (signature.length == 65) {\n            bytes32 r;\n            bytes32 s;\n            uint8 v;\n            // ecrecover takes the signature parameters, and the only way to get them\n            // currently is to use assembly.\n            /// @solidity memory-safe-assembly\n            assembly {\n                r := mload(add(signature, 0x20))\n                s := mload(add(signature, 0x40))\n                v := byte(0, mload(add(signature, 0x60)))\n            }\n            return tryRecover(hash, v, r, s);\n        } else {\n            return (address(0), RecoverError.InvalidSignatureLength);\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature`. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     */\n    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, signature);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n     *\n     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address, RecoverError) {\n        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n        uint8 v = uint8((uint256(vs) >> 255) + 27);\n        return tryRecover(hash, v, r, s);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n     *\n     * _Available since v4.2._\n     */\n    function recover(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address, RecoverError) {\n        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n        // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n        //\n        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n        // these malleable signatures as well.\n        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n            return (address(0), RecoverError.InvalidSignatureS);\n        }\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        if (signer == address(0)) {\n            return (address(0), RecoverError.InvalidSignature);\n        }\n\n        return (signer, RecoverError.NoError);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     */\n    function recover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n        // 32 is the length in bytes of hash,\n        // enforced by the type signature above\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from `s`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", StringsUpgradeable.toString(s.length), s));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Typed Data, created from a\n     * `domainSeparator` and a `structHash`. This produces hash corresponding\n     * to the one signed with the\n     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n     * JSON-RPC method as part of EIP-712.\n     *\n     * See {recover}.\n     */\n    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./ECDSAUpgradeable.sol\";\nimport \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,\n * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding\n * they need in their contracts using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * _Available since v3.4._\n *\n * @custom:storage-size 52\n */\nabstract contract EIP712Upgradeable is Initializable {\n    /* solhint-disable var-name-mixedcase */\n    bytes32 private _HASHED_NAME;\n    bytes32 private _HASHED_VERSION;\n    bytes32 private constant _TYPE_HASH = keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n    /* solhint-enable var-name-mixedcase */\n\n    /**\n     * @dev Initializes the domain separator and parameter caches.\n     *\n     * The meaning of `name` and `version` is specified in\n     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:\n     *\n     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n     * - `version`: the current major version of the signing domain.\n     *\n     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n     * contract upgrade].\n     */\n    function __EIP712_init(string memory name, string memory version) internal onlyInitializing {\n        __EIP712_init_unchained(name, version);\n    }\n\n    function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing {\n        bytes32 hashedName = keccak256(bytes(name));\n        bytes32 hashedVersion = keccak256(bytes(version));\n        _HASHED_NAME = hashedName;\n        _HASHED_VERSION = hashedVersion;\n    }\n\n    /**\n     * @dev Returns the domain separator for the current chain.\n     */\n    function _domainSeparatorV4() internal view returns (bytes32) {\n        return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash());\n    }\n\n    function _buildDomainSeparator(\n        bytes32 typeHash,\n        bytes32 nameHash,\n        bytes32 versionHash\n    ) private view returns (bytes32) {\n        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));\n    }\n\n    /**\n     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n     * function returns the hash of the fully encoded EIP712 message for this domain.\n     *\n     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n     *\n     * ```solidity\n     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n     *     keccak256(\"Mail(address to,string contents)\"),\n     *     mailTo,\n     *     keccak256(bytes(mailContents))\n     * )));\n     * address signer = ECDSA.recover(digest, signature);\n     * ```\n     */\n    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n        return ECDSAUpgradeable.toTypedDataHash(_domainSeparatorV4(), structHash);\n    }\n\n    /**\n     * @dev The hash of the name parameter for the EIP712 domain.\n     *\n     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs\n     * are a concern.\n     */\n    function _EIP712NameHash() internal virtual view returns (bytes32) {\n        return _HASHED_NAME;\n    }\n\n    /**\n     * @dev The hash of the version parameter for the EIP712 domain.\n     *\n     * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs\n     * are a concern.\n     */\n    function _EIP712VersionHash() internal virtual view returns (bytes32) {\n        return _HASHED_VERSION;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165Upgradeable {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary MathUpgradeable {\n    enum Rounding {\n        Down, // Toward negative infinity\n        Up, // Toward infinity\n        Zero // Toward zero\n    }\n\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds up instead\n     * of rounding down.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a == 0 ? 0 : (a - 1) / b + 1;\n    }\n\n    /**\n     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n     * with further edits by Uniswap Labs also under MIT license.\n     */\n    function mulDiv(\n        uint256 x,\n        uint256 y,\n        uint256 denominator\n    ) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod0 := mul(x, y)\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            require(denominator > prod1);\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n            // See https://cs.stackexchange.com/q/138556/92363.\n\n            // Does not overflow because the denominator cannot be zero at this stage in the function.\n            uint256 twos = denominator & (~denominator + 1);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n            // in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(\n        uint256 x,\n        uint256 y,\n        uint256 denominator,\n        Rounding rounding\n    ) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10**64) {\n                value /= 10**64;\n                result += 64;\n            }\n            if (value >= 10**32) {\n                value /= 10**32;\n                result += 32;\n            }\n            if (value >= 10**16) {\n                value /= 10**16;\n                result += 16;\n            }\n            if (value >= 10**8) {\n                value /= 10**8;\n                result += 8;\n            }\n            if (value >= 10**4) {\n                value /= 10**4;\n                result += 4;\n            }\n            if (value >= 10**2) {\n                value /= 10**2;\n                result += 2;\n            }\n            if (value >= 10**1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCastUpgradeable {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value <= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value <= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value <= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value <= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value <= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value <= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value <= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value <= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value <= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value <= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value <= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value <= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value <= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value <= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value <= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value <= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value <= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value <= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value <= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value <= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value <= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value <= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value <= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value <= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value <= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value <= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value <= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value <= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value <= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value <= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value <= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value >= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value <= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n"
      },
      "contracts/Token.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20CappedUpgradeable.sol\";\r\nimport \"./utils/ERC20VotesWithBalanceSnapshot.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\r\nimport \"./interfaces/IService.sol\";\r\nimport \"./interfaces/IToken.sol\";\r\nimport \"./interfaces/ITGE.sol\";\r\nimport \"./interfaces/IIDRegistry.sol\";\r\nimport \"./interfaces/IPool.sol\";\r\nimport \"./interfaces/registry/IRegistry.sol\";\r\nimport \"./libraries/ExceptionsLibrary.sol\";\r\nimport \"./interfaces/IPausable.sol\";\r\n\r\n/**\r\n * @title Company (Pool) Token\r\n * @notice Tokens are the primary quantitative characteristic of all entities within the protocol. In addition to their inherent function as a unit of calculation, tokens can also be used as votes and as a unit indicating the degree of participation of an address in an off-chain or on-chain pool project. Tokens of any type can only be issued within the framework of a TGE (Token Generation Event), and by using vesting settings, such a TGE can divide the issuance of purchased or airdropped tokens into stages, as well as temporarily block the ability to transfer them from one address to another.\r\n * @dev An expanded ERC20 contract, based on which tokens of various types are issued. At the moment, the protocol provides for 2 types of tokens: Governance, which must be created simultaneously with the pool, existing for the pool only in the singular and participating in voting, and Preference, which may be several for one pool and which do not participate in voting in any way.\r\n */\r\ncontract Token is\r\n    ERC20CappedUpgradeable,\r\n    ERC20VotesWithBalanceSnapshot,\r\n    IToken,\r\n    ReentrancyGuardUpgradeable\r\n{\r\n    /// @dev Service contract address\r\n    IService public service;\r\n\r\n    /// @dev Pool contract address\r\n    address public pool;\r\n\r\n    /**\r\n    * @notice Token type code\r\n    * @dev Code \"1\" - Governance Token is the main token of the pool, compatible with the ERC20 standard. One such token is equal to one vote. One pool can only have one contract of this type of token. When the primary TGE is launched, dedicated to the distribution of this type of token, the token is only a candidate for the Governance role.\r\n    In case of a successful TGE, it remains the Governance token of the pool forever.\r\n    In case of a failed TGE, it carries no weight and voting power for Governance procedures; another token can be appointed in its place through a repeated primary TGE. The cap is set once during the launch of the primary TGE.\r\n    During each TGE, an additional issuance of Service:ProtocolTokenFee percent of the total volume of tokens distributed during the event takes place and is transferred to the balance of the Service:ProtocolTreasury address.\r\n    * @dev Code \"2\" - Preference Token is an additional pool token, compatible with the ERC20 standard. It does not have voting power. One pool can have multiple independent and non-interacting tokens of this type.\r\n    In case of a successful TGE, it is recognized by the pool as a Preference token forever.\r\n    In case of a failed TGE, the pool forgets about such a token, not recognizing it as a Preference token.\r\n    The cap is set once during the launch of the primary TGE.\r\n    */\r\n    TokenType public tokenType;\r\n\r\n    /// @dev Preference token description, allows up to 5000 characters, for others - \"\"\r\n    string public description;\r\n\r\n    /// @notice All TGEs associated with this token\r\n    /// @dev A list of TGE contract addresses that have been launched to distribute this token. If any of the elements in the list have a \"Successful\" state, it means that the token is valid and used by the pool. If there are no such TGEs, the token can be considered unsuccessful, meaning it is detached from the pool.\r\n    address[] public tgeList;\r\n\r\n    /// @notice Token decimals\r\n    /// @dev This parameter is mandatory for all ERC20 tokens and is set to 18 by default. It indicates the precision applied when calculating a particular token. It can also be said that 10 raised to the power of minus decimal is the minimum indivisible amount of the token.\r\n    uint8 private _decimals;\r\n\r\n    /// @dev Total Vested tokens for all TGEs\r\n    uint256 private totalVested;\r\n\r\n    /// @dev List of all TGEs with locked tokens\r\n    address[] private tgeWithLockedTokensList;\r\n\r\n    /// @dev Total amount of tokens reserved for the minting protocol fee\r\n    uint256 private totalProtocolFeeReserved;\r\n\r\n    mapping(address => address[]) public tseList;\r\n\r\n    bytes32 public compliance;\r\n\r\n    event Transferred(address account);\r\n\r\n    /// Examples: 1% = 10000, 100% = 1000000, 0.1% = 1000\r\n    uint256 public partnerFee;\r\n\r\n    address public partnerAddress;\r\n\r\n    struct Dividend {\r\n        uint256 amount;\r\n        uint256 snapshotId;\r\n        address tokenAddress; // Address of the ERC20 token or address(0) for Ether\r\n    }\r\n\r\n    Dividend[] public dividends;\r\n\r\n    mapping(address => uint256) public lastDividendsClaimedIndex;\r\n\r\n    // Mapping to record failed dividend transfers\r\n    mapping(address => mapping(address => uint256)) public failedTransfers;\r\n\r\n    mapping(address => uint256) public totalClaimedDividends;\r\n\r\n    mapping(address => uint256) public totalDepositedDividends;\r\n\r\n    event DividendsDeposited(\r\n        address indexed depositor,\r\n        uint256 amount,\r\n        address tokenAddress\r\n    );\r\n    event DividendsClaimed(\r\n        address indexed claimant,\r\n        uint256 amount,\r\n        address tokenAddress\r\n    );\r\n\r\n    // INITIALIZER AND CONSTRUCTOR\r\n\r\n    /**\r\n     * @notice Contract constructor.\r\n     * @dev This contract uses OpenZeppelin upgrades and has no need for a constructor function.\r\n     * The constructor is replaced with an initializer function.\r\n     * This method disables the initializer feature of the OpenZeppelin upgrades plugin, preventing the initializer methods from being misused.\r\n     * @custom:oz-upgrades-unsafe-allow constructor\r\n     */\r\n    constructor() {\r\n        _disableInitializers();\r\n    }\r\n\r\n    /**\r\n     * @dev Token creation, can only be started once. At the same time, the TGE contract, which sells the created token, is necessarily simultaneously deployed and receives an entry in the Registry. For the Governance token, the Name field for the ERC20 standard is taken from the trademark of the Pool contract to which the deployed token belongs. For Preference tokens, you can set an arbitrary value of the Name field.\r\n     * @param service_ The address of the Service contract\r\n     * @param pool_ The address of the pool contract\r\n     * @param info The token parameters, including its type, in the form of a structure described in the TokenInfo method\r\n     * @param primaryTGE_ The address of the primary TGE for this token\r\n     */\r\n    function initialize(\r\n        IService service_,\r\n        address pool_,\r\n        TokenInfo memory info,\r\n        address primaryTGE_\r\n    ) external initializer {\r\n        __ReentrancyGuard_init();\r\n        __ERC20Capped_init(info.cap);\r\n\r\n        description = info.description;\r\n\r\n        if (info.tokenType == TokenType.Preference) {\r\n            __ERC20_init(info.name, info.symbol);\r\n            _decimals = info.decimals;\r\n        } else {\r\n            __ERC20_init(info.name, info.symbol);\r\n        }\r\n        tgeList.push(primaryTGE_);\r\n        tgeWithLockedTokensList.push(primaryTGE_);\r\n        tokenType = info.tokenType;\r\n        service = service_;\r\n        pool = pool_;\r\n    }\r\n\r\n    receive() external payable {}\r\n\r\n    // RESTRICTED FUNCTIONS\r\n\r\n    /**\r\n     * @dev Minting of new tokens. Only the TGE or Vesting contract can mint tokens, there is no other way to get an additional issue. If the user who is being minted does not have tokens, they are sent to delegation on his behalf.\r\n     * @param to The address of the account for which new token units are being minted\r\n     * @param amount The number of tokens being minted\r\n     */\r\n    function mint(address to, uint256 amount) external onlyTGEOrVesting {\r\n        // Delegate to self if first mint\r\n        if (balanceOf(to) == 0 && delegates(to) == address(0))\r\n            _delegate(to, to);\r\n\r\n        // Mint tokens\r\n        _mint(to, amount);\r\n    }\r\n\r\n    /**\r\n     * @dev Method for burning tokens. It can be called by both the token owner and the TGE contract to burn returned tokens during redeeming.\r\n     * @param from The address of the account\r\n     * @param amount The amount of tokens\r\n     */\r\n    function burn(address from, uint256 amount) external whenPoolNotPaused {\r\n        // Check that sender is valid\r\n        require(\r\n            service.registry().typeOf(msg.sender) ==\r\n                IRecordsRegistry.ContractType.TGE ||\r\n                msg.sender == from,\r\n            ExceptionsLibrary.INVALID_USER\r\n        );\r\n\r\n        // Burn tokens\r\n        _burn(from, amount);\r\n    }\r\n\r\n    /**\r\n     * @dev This method adds the TGE contract address to the TGEList of this token.\r\n     * @param tge The TGE address\r\n     */\r\n    function addTGE(address tge) external onlyTGEFactory {\r\n        tgeList.push(tge);\r\n        tgeWithLockedTokensList.push(tge);\r\n    }\r\n\r\n    function addTSE(address account, address tse) external onlyTGEFactory {\r\n        tseList[account].push(tse);\r\n    }\r\n\r\n    function setCompliance(bytes32 compliance_) external {\r\n        require(\r\n            msg.sender == address(service.tgeFactory()) ||\r\n                service.hasRole(service.ADMIN_ROLE(), msg.sender) ||\r\n                service.hasRole(service.SERVICE_MANAGER_ROLE(), msg.sender),\r\n            ExceptionsLibrary.NOT_SERVICE\r\n        );\r\n        compliance = compliance_;\r\n\r\n        service.registry().log(\r\n            msg.sender,\r\n            address(this),\r\n            0,\r\n            abi.encodeWithSelector(IToken.setCompliance.selector, compliance_)\r\n        );\r\n    }\r\n\r\n    function setPartnerFee(\r\n        address _partnerAddress,\r\n        uint256 _partnerFee\r\n    ) external {\r\n        require(\r\n            msg.sender == address(service.tgeFactory()) ||\r\n                service.hasRole(service.ADMIN_ROLE(), msg.sender) ||\r\n                service.hasRole(service.SERVICE_MANAGER_ROLE(), msg.sender),\r\n            ExceptionsLibrary.NOT_SERVICE\r\n        );\r\n        partnerFee = _partnerFee;\r\n        partnerAddress = _partnerAddress;\r\n    }\r\n\r\n    /**\r\n     * @dev This method modifies the number of token units that are vested and reserved for claiming by users.\r\n     * @param amount The amount of tokens\r\n     */\r\n    function setTGEVestedTokens(uint256 amount) external onlyTGEOrVesting {\r\n        totalVested = amount;\r\n    }\r\n\r\n    /**\r\n     * @dev This method modifies the number of token units that are reserved as protocol fee.\r\n     * @param amount The amount of tokens\r\n     */\r\n    function setProtocolFeeReserved(uint256 amount) external onlyTGE {\r\n        totalProtocolFeeReserved = amount;\r\n    }\r\n\r\n    // PUBLIC VIEW FUNCTIONS\r\n\r\n    /**\r\n     * @dev This method returns the precision level for the fractional parts of this token.\r\n     * @return Decimals\r\n     */\r\n    function decimals()\r\n        public\r\n        view\r\n        override(ERC20Upgradeable, IToken)\r\n        returns (uint8)\r\n    {\r\n        if (tokenType == TokenType.Governance) {\r\n            return 18;\r\n        } else {\r\n            return _decimals;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev This method returns the maximum allowable token emission.\r\n     * @return The number of tokens taking into account the Decimals parameter\r\n     */\r\n    function cap()\r\n        public\r\n        view\r\n        override(IToken, ERC20CappedUpgradeable)\r\n        returns (uint256)\r\n    {\r\n        return super.cap();\r\n    }\r\n\r\n    /**\r\n     * @dev This method returns the short name of the token, its ticker for listing.\r\n     * @return A string with the name\r\n     */\r\n    function symbol()\r\n        public\r\n        view\r\n        override(IToken, ERC20Upgradeable)\r\n        returns (string memory)\r\n    {\r\n        return super.symbol();\r\n    }\r\n\r\n    /**\r\n     * @dev The given getter returns the total balance of the address that is not locked for transfer, taking into account all the TGEs with which this token was distributed.\r\n     * @dev It is the difference between the actual balance of the account and its locked portion.\r\n     * @param account The address of the account\r\n     * @return Unlocked balance of the account\r\n     */\r\n    function unlockedBalanceOf(address account) public view returns (uint256) {\r\n        // Get total account balance\r\n        uint256 balance = balanceOf(account);\r\n\r\n        // Iterate through TGE With Locked Tokens List to get locked balance\r\n        address[] memory _tgeWithLockedTokensList = tgeWithLockedTokensList;\r\n        uint256 totalLocked = 0;\r\n        for (uint256 i; i < _tgeWithLockedTokensList.length; i++) {\r\n            totalLocked += ITGE(_tgeWithLockedTokensList[i]).lockedBalanceOf(\r\n                account\r\n            );\r\n        }\r\n\r\n        // Return difference\r\n        return balance - totalLocked;\r\n    }\r\n\r\n    /**\r\n     * @dev This method indicates whether a successful TGE has been conducted for this token. To determine this, it is sufficient to check the first event from the list of all TGEs. If it ended in failure, then this token cannot be considered active for its pool.\r\n     * @return bool Is any TGE successful\r\n     */\r\n    function isPrimaryTGESuccessful() external view returns (bool) {\r\n        return (ITGE(tgeList[0]).state() == ITGE.State.Successful);\r\n    }\r\n\r\n    /**\r\n     * @dev This method returns the list of addresses of all TGE contracts ever deployed for this token.\r\n     * @return array An array of contract addresses\r\n     */\r\n    function getTGEList() external view returns (address[] memory) {\r\n        return tgeList;\r\n    }\r\n\r\n    /**\r\n     * @dev This method returns the list of addresses of all TGE contracts ever deployed for this token and having active token transfer restrictions.\r\n     * @return array An array of contract addresses\r\n     */\r\n\r\n    function getTgeWithLockedTokensList()\r\n        external\r\n        view\r\n        returns (address[] memory)\r\n    {\r\n        return tgeWithLockedTokensList;\r\n    }\r\n\r\n    /**\r\n     * @dev This method returns the address of the last conducted TGE for this token. Sorting is based on the starting block of the TGE, not the ending block (i.e., even if an earlier TGE contract is still active and the most recent one by creation time has already ended, the method will still return the address of the most recent contract).\r\n     * @return address The contract address\r\n     */\r\n    function lastTGE() external view returns (address) {\r\n        return tgeList[tgeList.length - 1];\r\n    }\r\n\r\n    /**\r\n     * @dev This method returns the accumulated value stored in the contract's memory, which represents the number of token units that are in vesting at the time of the request.\r\n     * @return uint256 The sum of tokens in vesting\r\n     */\r\n    function getTotalTGEVestedTokens() public view returns (uint256) {\r\n        return totalVested;\r\n    }\r\n\r\n    /**\r\n     * @dev This method returns the accumulated value stored in the contract's memory, which represents the number of token units that are reserved and should be issued and sent as the contract's fee.\r\n     * @return uint256 The sum of tokens for the fee\r\n     */\r\n    function getTotalProtocolFeeReserved() public view returns (uint256) {\r\n        return totalProtocolFeeReserved;\r\n    }\r\n\r\n    /**\r\n     * @dev This method calculates the total supply for the token taking into account the reserved but not yet issued units (for vesting and protocol fee).\r\n     * @return uint256 The sum of reserved tokens\r\n     */\r\n    function totalSupplyWithReserves() public view returns (uint256) {\r\n        uint256 _totalSupplyWithReserves = totalSupply() +\r\n            getTotalTGEVestedTokens() +\r\n            getTotalProtocolFeeReserved();\r\n\r\n        return _totalSupplyWithReserves;\r\n    }\r\n\r\n    function isERC1155() public pure returns (bool) {\r\n        return false;\r\n    }\r\n\r\n    // INTERNAL FUNCTIONS\r\n\r\n    /**\r\n     * @notice Overriding the transfer method of the ERC20 token contract.\r\n     * @dev When tokens are being transferred, a check is performed to ensure that the sender's balance has a sufficient amount of tokens that are not locked up. This is a stricter condition compared to the normal balance check.\r\n     * @dev Each such transaction also triggers the check of all TGE contracts for the end of lockup and removes such contracts from the tgeWithLockedTokensList.\r\n     * @param from The address of the sender\r\n     * @param to The address of the recipient\r\n     * @param amount Amount of tokens\r\n     */\r\n    function _transfer(\r\n        address from,\r\n        address to,\r\n        uint256 amount\r\n    ) internal override whenPoolNotPaused {\r\n        // Update list of TGEs with locked tokens\r\n        updateTgeWithLockedTokensList();\r\n\r\n        // Check that locked tokens are not transferred\r\n        require(\r\n            amount <= unlockedBalanceOf(from),\r\n            ExceptionsLibrary.LOW_UNLOCKED_BALANCE\r\n        );\r\n\r\n        if (balanceOf(to) == 0 && delegates(to) == address(0))\r\n            _delegate(to, to);\r\n\r\n        // Execute transfer\r\n        super._transfer(from, to, amount);\r\n    }\r\n\r\n    /**\r\n     * @dev Hook that is called after any transfer of tokens. This includes\r\n     * minting and burning.\r\n     */\r\n    function _afterTokenTransfer(\r\n        address from,\r\n        address to,\r\n        uint256 amount\r\n    ) internal override(ERC20Upgradeable, ERC20VotesUpgradeable) {\r\n        emit Transferred(to);\r\n        require(\r\n            IIDRegistry(service.idRegistry()).isWhitelisted(from, compliance),\r\n            ExceptionsLibrary.NOT_WHITELISTED\r\n        );\r\n\r\n        require(\r\n            IIDRegistry(service.idRegistry()).isWhitelisted(to, compliance),\r\n            ExceptionsLibrary.NOT_WHITELISTED\r\n        );\r\n\r\n        super._afterTokenTransfer(from, to, amount);\r\n    }\r\n\r\n    function _beforeTokenTransfer(\r\n        address from,\r\n        address to,\r\n        uint256 amount\r\n    ) internal override(ERC20Upgradeable, ERC20VotesWithBalanceSnapshot) {\r\n        super._beforeTokenTransfer(from, to, amount);\r\n    }\r\n\r\n    function delegate(\r\n        address delegatee\r\n    ) public override(ERC20VotesUpgradeable, IToken) {\r\n        service.registry().log(\r\n            msg.sender,\r\n            address(this),\r\n            0,\r\n            abi.encodeWithSelector(IToken.delegate.selector, delegatee)\r\n        );\r\n\r\n        super.delegate(delegatee);\r\n    }\r\n\r\n    function transfer(\r\n        address to,\r\n        uint256 amount\r\n    ) public override(ERC20Upgradeable, IToken) returns (bool) {\r\n        service.registry().log(\r\n            msg.sender,\r\n            address(this),\r\n            0,\r\n            abi.encodeWithSelector(IToken.transfer.selector, to, amount)\r\n        );\r\n\r\n        return super.transfer(to, amount);\r\n    }\r\n\r\n    function transferFrom(\r\n        address from,\r\n        address to,\r\n        uint256 amount\r\n    ) public override(ERC20Upgradeable, IToken) returns (bool) {\r\n        service.registry().log(\r\n            msg.sender,\r\n            address(this),\r\n            0,\r\n            abi.encodeWithSelector(\r\n                IToken.transferFrom.selector,\r\n                from,\r\n                to,\r\n                amount\r\n            )\r\n        );\r\n\r\n        return super.transferFrom(from, to, amount);\r\n    }\r\n\r\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\r\n     * the total supply.\r\n     */\r\n    function _mint(\r\n        address account,\r\n        uint256 amount\r\n    ) internal override(ERC20VotesUpgradeable, ERC20CappedUpgradeable) {\r\n        super._mint(account, amount);\r\n    }\r\n\r\n    /**\r\n     * @notice Burning a specified amount of tokens that are held in the account's balance\r\n     * @dev Burning a specified amount of units of the token from the specified account.\r\n     * @param account The address from which tokens are deducted for destruction\r\n     * @param amount The amount of tokens to be destroyed\r\n     */\r\n    function _burn(\r\n        address account,\r\n        uint256 amount\r\n    ) internal override(ERC20Upgradeable, ERC20VotesUpgradeable) {\r\n        super._burn(account, amount);\r\n    }\r\n\r\n    // PRIVATE FUNCTIONS\r\n\r\n    /**\r\n     * @notice Update the list of TGEs with locked tokens\r\n     * @dev It is crucial to keep this list up to date to have accurate information at any given time on how much of their token balance each user can dispose of, taking into account the locks imposed by the TGEs in which the user participated.\r\n     */\r\n    function updateTgeWithLockedTokensList() private {\r\n        uint256 i = tgeWithLockedTokensList.length;\r\n        while (i > 0) {\r\n            i--;\r\n            // Check if transfer is unlocked\r\n            if (ITGE(tgeWithLockedTokensList[i]).transferUnlocked()) {\r\n                // Remove tge from tgeWithLockedTokensList when transfer is unlocked\r\n                tgeWithLockedTokensList[i] = tgeWithLockedTokensList[\r\n                    tgeWithLockedTokensList.length - 1\r\n                ];\r\n                tgeWithLockedTokensList.pop();\r\n            }\r\n        }\r\n    }\r\n\r\n    // DIVIDENDS BLOCK\r\n\r\n    /**\r\n     * @notice Deposits dividends in either Ether or ERC20 tokens.\r\n     * @dev Records the deposited amount and token address. For ERC20, the amount is transferred from the sender.\r\n     * @param tokenAddress The address of the ERC20 token, or address(0) for Ether.\r\n     * @param amount The amount of ERC20 tokens to deposit. For Ether deposits, this is ignored.\r\n     */\r\n    function depositDividends(\r\n        address tokenAddress,\r\n        uint256 amount\r\n    ) public payable nonReentrant {\r\n        uint256 depositAmount;\r\n        if (tokenAddress == address(0)) {\r\n            // Ether deposit\r\n            require(msg.value > 0, \"No Ether to deposit\");\r\n            depositAmount = msg.value;\r\n        } else {\r\n            // ERC20 token deposit\r\n            require(amount > 0, \"Amount must be greater than 0\");\r\n            uint256 balanceBefore = IERC20Upgradeable(tokenAddress).balanceOf(\r\n                address(this)\r\n            );\r\n            IERC20Upgradeable(tokenAddress).transferFrom(\r\n                msg.sender,\r\n                address(this),\r\n                amount\r\n            );\r\n            uint256 balanceAfter = IERC20Upgradeable(tokenAddress).balanceOf(\r\n                address(this)\r\n            );\r\n            depositAmount = balanceAfter - balanceBefore;\r\n            require(depositAmount == amount, \"Deposit amount mismatch\");\r\n        }\r\n        totalDepositedDividends[tokenAddress] += depositAmount;\r\n        _addDividendsRecord(tokenAddress, depositAmount);\r\n    }\r\n\r\n    /**\r\n     * @dev Updates the dividend records with new deposits for the specified token.\r\n     * This method should be called to ensure the dividend records accurately reflect the current state.\r\n     *\r\n     * @param tokenAddress The address of the ERC20 token or address(0) for Ether.\r\n     */\r\n    function updateDividendDeposits(address tokenAddress) public nonReentrant {\r\n        uint256 currentBalance = 0;\r\n        if (tokenAddress == address(0)) {\r\n            currentBalance = address(this).balance;\r\n        } else {\r\n            currentBalance = IERC20Upgradeable(tokenAddress).balanceOf(\r\n                address(this)\r\n            );\r\n        }\r\n\r\n        uint256 expectedBalance = totalDepositedDividends[tokenAddress] -\r\n            totalClaimedDividends[tokenAddress];\r\n\r\n        // Calculate the new dividends based on the current balance and expected balance\r\n        uint256 newDividends = currentBalance > expectedBalance\r\n            ? currentBalance - expectedBalance\r\n            : 0;\r\n\r\n        require(newDividends > 0, \"No new dividends to deposit\");\r\n\r\n        // Update total deposited dividends\r\n        totalDepositedDividends[tokenAddress] += newDividends;\r\n\r\n        // Call _addDividendsRecord to handle the new dividends\r\n        _addDividendsRecord(tokenAddress, newDividends);\r\n    }\r\n\r\n    /**\r\n     * @dev Adds a record of deposited dividends to the contract's storage. This function is an internal utility used\r\n     * by other functions in the contract to record dividend deposits. It creates a new Dividend struct and adds it to\r\n     * the dividends array. This function is not meant to be called externally but is used internally to handle\r\n     * dividend deposits.\r\n     *\r\n     * @notice Internal function to record a new dividend deposit.\r\n     *\r\n     * @param tokenAddress The address of the ERC20 token for which dividends are being deposited, or address(0) for Ether.\r\n     * @param amount The amount of dividends being deposited. For Ether, this is the value sent with the transaction;\r\n     * for ERC20 tokens, this is the amount transferred to the contract.\r\n     *\r\n     * Emits a `DividendsDeposited` event indicating the depositor, the amount, and the token address.\r\n     */\r\n    function _addDividendsRecord(address tokenAddress, uint256 amount) private {\r\n        uint256 currentSnapshotId = _snapshot(); // Snapshot is taken at deposit\r\n\r\n        // Add new dividend record\r\n        dividends.push(\r\n            Dividend({\r\n                amount: amount,\r\n                snapshotId: currentSnapshotId,\r\n                tokenAddress: tokenAddress\r\n            })\r\n        );\r\n\r\n        // Log the dividend deposit\r\n        service.registry().log(\r\n            msg.sender,\r\n            address(this),\r\n            0,\r\n            abi.encodeWithSelector(\r\n                IToken.depositDividends.selector,\r\n                tokenAddress,\r\n                amount\r\n            )\r\n        );\r\n\r\n        emit DividendsDeposited(msg.sender, amount, tokenAddress);\r\n    }\r\n\r\n    /**\r\n     * @notice Allows a shareholder to claim their dividends within a specified range.\r\n     * @dev Claims dividends for the caller based on the specified offset and limit.\r\n     * If a transfer fails, it records the amount for a later retry.\r\n     * @param limit The maximum number of dividends to claim.\r\n     */\r\n    function claimDividends(uint256 limit) public nonReentrant {\r\n        uint256 totalClaimable = 0;\r\n        Dividend[] memory claimableDividends = getFullClaimableDividends(\r\n            msg.sender,\r\n            dividends.length - lastDividendsClaimedIndex[_msgSender()]\r\n        );\r\n        uint256 counter = 0;\r\n        for (uint256 i = 0; counter < limit; i++) {\r\n            Dividend memory dividend = claimableDividends[i];\r\n            if (dividend.amount > 0) {\r\n                counter++;\r\n                if (dividend.tokenAddress == address(0)) {\r\n                    payable(msg.sender).transfer(dividend.amount);\r\n                } else {\r\n                    try\r\n                        IERC20Upgradeable(dividend.tokenAddress).transfer(\r\n                            msg.sender,\r\n                            dividend.amount\r\n                        )\r\n                    {\r\n                        totalClaimedDividends[dividend.tokenAddress] += dividend\r\n                            .amount;\r\n                    } catch {\r\n                        failedTransfers[msg.sender][\r\n                            dividend.tokenAddress\r\n                        ] += dividend.amount;\r\n                    }\r\n                }\r\n                totalClaimable += dividend.amount;\r\n            }\r\n            lastDividendsClaimedIndex[msg.sender]++;\r\n        }\r\n\r\n        emit DividendsClaimed(msg.sender, totalClaimable, address(0));\r\n    }\r\n\r\n    /**\r\n     * @notice Calculates and returns an array of claimable dividends for a specific shareholder,\r\n     * within the specified range defined by offset and limit.\r\n     * @dev Iterates through the dividends array starting from the last claimed index for the shareholder\r\n     * plus the offset, and processes up to the specified limit of dividends.\r\n     * @param shareholder The address of the shareholder for whom to calculate claimable dividends.\r\n     * @param limit The maximum number of dividends to include in the calculation.\r\n     * @return claimableDividends An array of Dividend structures containing the details of each claimable dividend.\r\n     */\r\n    function getClaimableDividends(\r\n        address shareholder,\r\n        uint256 limit\r\n    ) public view returns (Dividend[] memory) {\r\n        uint256 owedDividends = getOwedDividends(shareholder);\r\n        uint256 resultLength = MathUpgradeable.min(limit, owedDividends);\r\n        Dividend[] memory claimableDividends = new Dividend[](resultLength);\r\n        uint256 counter = 0;\r\n\r\n        for (\r\n            uint256 i = lastDividendsClaimedIndex[shareholder];\r\n            counter < resultLength;\r\n            i++\r\n        ) {\r\n            Dividend storage dividend = dividends[i];\r\n            uint256 balanceAtDividend = balanceOfAt(\r\n                shareholder,\r\n                dividend.snapshotId\r\n            );\r\n            uint256 claimable = (balanceAtDividend * dividend.amount) /\r\n                totalSupplyAtSnapshotId(dividend.snapshotId);\r\n\r\n            if (claimable > 0) {\r\n                claimableDividends[counter] = Dividend({\r\n                    amount: claimable,\r\n                    snapshotId: dividend.snapshotId,\r\n                    tokenAddress: dividend.tokenAddress\r\n                });\r\n                counter++;\r\n            }\r\n        }\r\n\r\n        return claimableDividends;\r\n    }\r\n\r\n    function getFullClaimableDividends(\r\n        address shareholder,\r\n        uint256 limit\r\n    ) public view returns (Dividend[] memory) {\r\n        uint256 totalDividends = dividends.length -\r\n            lastDividendsClaimedIndex[shareholder];\r\n        uint256 resultLength = MathUpgradeable.min(limit, totalDividends);\r\n        Dividend[] memory claimableDividends = new Dividend[](limit);\r\n        uint256 counter = 0;\r\n\r\n        for (\r\n            uint256 i = lastDividendsClaimedIndex[shareholder];\r\n            counter < resultLength;\r\n            i++\r\n        ) {\r\n            Dividend storage dividend = dividends[i];\r\n            uint256 balanceAtDividend = balanceOfAt(\r\n                shareholder,\r\n                dividend.snapshotId\r\n            );\r\n            uint256 claimable = (balanceAtDividend * dividend.amount) /\r\n                totalSupplyAtSnapshotId(dividend.snapshotId);\r\n\r\n            claimableDividends[counter] = Dividend({\r\n                amount: claimable,\r\n                snapshotId: dividend.snapshotId,\r\n                tokenAddress: dividend.tokenAddress\r\n            });\r\n\r\n            counter++;\r\n        }\r\n\r\n        return claimableDividends;\r\n    }\r\n\r\n    /**\r\n     * @notice Allows a user to retry claiming dividends that previously failed to transfer.\r\n     * @param tokenAddress The address of the token for which to claim failed transfers.\r\n     */\r\n    function retryFailedTransfers(address tokenAddress) public nonReentrant {\r\n        uint256 amount = failedTransfers[msg.sender][tokenAddress];\r\n        require(amount > 0, \"No failed transfers for this token\");\r\n\r\n        // Attempt the transfer again\r\n        IERC20Upgradeable(tokenAddress).transfer(msg.sender, amount);\r\n\r\n        // Reset the failed transfer amount\r\n        failedTransfers[msg.sender][tokenAddress] = 0;\r\n    }\r\n\r\n    /**\r\n     * @notice Retrieves the total dividends owed to a shareholder.\r\n     * @param shareholder The address of the shareholder.\r\n     * @return totalOwed The total amount of dividends owed to the shareholder.\r\n     */\r\n    function getOwedDividends(\r\n        address shareholder\r\n    ) public view returns (uint256) {\r\n        uint256 totalOwed = 0;\r\n        for (\r\n            uint256 i = lastDividendsClaimedIndex[shareholder];\r\n            i < dividends.length;\r\n            i++\r\n        ) {\r\n            Dividend memory dividend = dividends[i];\r\n            uint256 balanceAtDividend = balanceOfAt(\r\n                shareholder,\r\n                dividend.snapshotId\r\n            );\r\n            uint256 owed = (balanceAtDividend * dividend.amount) /\r\n                totalSupplyAtSnapshotId(dividend.snapshotId);\r\n            if (owed > 0) totalOwed += 1;\r\n        }\r\n        return totalOwed;\r\n    }\r\n\r\n    /**\r\n     * @notice Retrieves the total token supply at a given block number.\r\n     * @param blockNumber The block number to check the total supply at.\r\n     * @return The total token supply at the given block number.\r\n     */\r\n    function totalSupplyAt(uint256 blockNumber) public view returns (uint256) {\r\n        return getPastTotalSupply(blockNumber);\r\n    }\r\n\r\n    // MODIFIERS\r\n\r\n    /// @notice Modifier that allows the method to be called only by the Pool contract.\r\n    modifier onlyPool() {\r\n        require(msg.sender == pool, ExceptionsLibrary.NOT_POOL);\r\n        _;\r\n    }\r\n\r\n    /// @notice Modifier that allows the method to be called only by the TGEFactory contract.\r\n    modifier onlyTGEFactory() {\r\n        require(\r\n            msg.sender == address(service.tgeFactory()),\r\n            ExceptionsLibrary.NOT_TGE_FACTORY\r\n        );\r\n        _;\r\n    }\r\n\r\n    /// @notice Modifier that allows the method to be called only by the TGE contract.\r\n    modifier onlyTGE() {\r\n        require(\r\n            service.registry().typeOf(msg.sender) ==\r\n                IRecordsRegistry.ContractType.TGE,\r\n            ExceptionsLibrary.NOT_TGE\r\n        );\r\n        _;\r\n    }\r\n\r\n    /// @notice Modifier that allows the method to be called only by the TGE or Vesting contract.\r\n    modifier onlyTGEOrVesting() {\r\n        bool isTGE = service.registry().typeOf(msg.sender) ==\r\n            IRecordsRegistry.ContractType.TGE;\r\n        bool isVesting = address(service.vesting()) == msg.sender;\r\n        require(isTGE || isVesting, ExceptionsLibrary.NOT_TGE);\r\n        _;\r\n    }\r\n\r\n    /// @notice Modifier that allows the method to be called only if the Pool contract is not paused.\r\n    modifier whenPoolNotPaused() {\r\n        require(!IPausable(pool).paused(), ExceptionsLibrary.SERVICE_PAUSED);\r\n        _;\r\n    }\r\n}\r\n"
      },
      "contracts/interfaces/ICustomProposal.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"./ITGE.sol\";\r\n\r\nimport \"./governor/IGovernanceSettings.sol\";\r\n\r\ninterface ICustomProposal {}\r\n"
      },
      "contracts/interfaces/IIDRegistry.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\ninterface IIDRegistry {\r\n    function isWhitelisted(\r\n        address account,\r\n        bytes32 compliance\r\n    ) external view returns (bool);\r\n\r\n    function addToWhitelist(\r\n        address[] calldata accounts,\r\n        bytes32 compliance\r\n    ) external;\r\n\r\n    function removeFromWhitelist(\r\n        address[] calldata accounts,\r\n        bytes32 compliance\r\n    ) external;\r\n}\r\n"
      },
      "contracts/interfaces/IInvoice.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n/**\r\n * @title Invoice Interface\r\n * @notice These structures are used to describe an instance of an invoice.\r\n * @dev The storage of invoices is managed in Invoice.sol in the `invoices` variable.\r\n*/\r\ninterface IInvoice {\r\n    /** \r\n    * @notice This interface contains a data structure that describes the payment rules for an invoice. \r\n    * @dev This data is used to validate the payment transaction, determine the state of the invoice, and so on. This data is formed from the input of the invoice creator.\r\n    * @param amount Amount to be paid\r\n    * @param unitOfAccount The address of the token contract that can be used to make the payment (a zero address assumes payment in native ETH)\r\n    * @param expirationBlock The block at which the invoice expires\r\n    * @param description Description of the invoice\r\n    * @param whitelist A whitelist of payers. An empty array denotes a public invoice.\r\n    */\r\n    struct InvoiceCore {\r\n        uint256 amount;\r\n        address unitOfAccount;\r\n        uint256 expirationBlock;\r\n        string description;\r\n        address[] whitelist;\r\n    }\r\n    /**\r\n    * @notice This interface is used to store complete records of invoices, including their current state, metadata, and payment rules.\r\n    * @dev This data is automatically formed when the invoice is created and changes when state-changing transactions are executed.\r\n    * @param core Payment rules (user input)\r\n    * @param invoiceId Invoice identifier\r\n    * @param createdBy The creator of the invoice\r\n    * @param isPaid Flag indicating whether the invoice has been successfully paid\r\n    * @param isCanceled Flag indicating whether the invoice has been canceled\r\n    */\r\n    struct InvoiceInfo {\r\n        InvoiceCore core;\r\n        uint256 invoiceId;\r\n        address createdBy;\r\n        bool isPaid;\r\n        bool isCanceled;\r\n    }\r\n    /**\r\n    * @notice Encoding the states of an individual invoice\r\n    * @dev None - for a non-existent invoice, Paid, Expired, Canceled - are completed invoice states where payment is not possible.\r\n    */\r\n    enum InvoiceState {\r\n        None,\r\n        Active,\r\n        Paid,\r\n        Expired,\r\n        Canceled\r\n    }\r\n\r\n    function createInvoice(address pool, InvoiceCore memory core) external;\r\n\r\n    function payInvoice(address pool, uint256 invoiceId) external payable;\r\n\r\n    function cancelInvoice(address pool, uint256 invoiceId) external;\r\n\r\n    function setInvoiceCanceled(address pool, uint256 invoiceId) external;\r\n}\r\n"
      },
      "contracts/interfaces/IPausable.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\ninterface IPausable {\r\n    function paused() external view returns (bool);\r\n\r\n    function isPoolSecretary(address account) external view returns (bool);\r\n}\r\n"
      },
      "contracts/interfaces/IPool.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"./IToken.sol\";\r\nimport \"./registry/IRegistry.sol\";\r\nimport \"./registry/ICompaniesRegistry.sol\";\r\n\r\nimport \"./governor/IGovernor.sol\";\r\nimport \"./governor/IGovernanceSettings.sol\";\r\nimport \"./governor/IGovernorProposals.sol\";\r\n\r\ninterface IPool is IGovernorProposals {\r\n    function initialize(\r\n        ICompaniesRegistry.CompanyInfo memory companyInfo_\r\n    ) external;\r\n\r\n    function setNewOwnerWithSettings(\r\n        address owner_,\r\n        string memory trademark_,\r\n        IGovernanceSettings.NewGovernanceSettings memory governanceSettings_\r\n    ) external;\r\n\r\n    function propose(\r\n        address proposer,\r\n        uint256 proposalType,\r\n        IGovernor.ProposalCoreData memory core,\r\n        IGovernor.ProposalMetaData memory meta\r\n    ) external returns (uint256 proposalId);\r\n\r\n    function setToken(address token_, IToken.TokenType tokenType_) external;\r\n\r\n    function setProposalIdToTGE(address tge) external;\r\n\r\n    //function cancelProposal(uint256 proposalId) external;\r\n\r\n    function setSettings(\r\n        IGovernanceSettings.NewGovernanceSettings memory governanceSettings_,\r\n        address[] memory secretary,\r\n        address[] memory executor\r\n    ) external;\r\n\r\n    function owner() external view returns (address);\r\n\r\n    function isDAO() external view returns (bool);\r\n\r\n    function trademark() external view returns (string memory);\r\n\r\n    function getGovernanceToken() external view returns (IToken);\r\n\r\n    function tokenExists(IToken token_) external view returns (bool);\r\n\r\n    function tokenTypeByAddress(\r\n        address token_\r\n    ) external view returns (IToken.TokenType);\r\n\r\n    function isValidProposer(address account) external view returns (bool);\r\n\r\n    function isPoolSecretary(address account) external view returns (bool);\r\n\r\n    function isLastProposalIdByTypeActive(\r\n        uint256 type_\r\n    ) external view returns (bool);\r\n\r\n    function validateGovernanceSettings(\r\n        IGovernanceSettings.NewGovernanceSettings memory settings\r\n    ) external pure;\r\n\r\n    function getPoolSecretary() external view returns (address[] memory);\r\n\r\n    function getPoolExecutor() external view returns (address[] memory);\r\n\r\n    function setCompanyInfo(\r\n        uint256 _fee,\r\n        uint256 _jurisdiction,\r\n        uint256 _entityType,\r\n        string memory _ein,\r\n        string memory _dateOfIncorporation,\r\n        string memory _OAuri\r\n    ) external;\r\n\r\n    function castVote(uint256 proposalId, bool support) external;\r\n\r\n    function externalCastVote(\r\n        address account,\r\n        uint256 proposalId,\r\n        bool support\r\n    ) external;\r\n\r\n    function externalTransferByOwner(\r\n        address to,\r\n        uint256 amount,\r\n        address unitOfAccount\r\n    ) external;\r\n\r\n    function executeProposal(uint256 proposalId) external;\r\n\r\n    function getCompanyFee() external returns (uint256);\r\n}\r\n"
      },
      "contracts/interfaces/IService.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"@openzeppelin/contracts-upgradeable/access/IAccessControlEnumerableUpgradeable.sol\";\r\nimport \"./ITGE.sol\";\r\nimport \"./ICustomProposal.sol\";\r\nimport \"./registry/IRecordsRegistry.sol\";\r\nimport \"./registry/ICompaniesRegistry.sol\";\r\nimport \"./registry/IRegistry.sol\";\r\nimport \"./IToken.sol\";\r\nimport \"./IInvoice.sol\";\r\nimport \"./IVesting.sol\";\r\nimport \"./ITokenFactory.sol\";\r\nimport \"./ITGEFactory.sol\";\r\nimport \"./IPool.sol\";\r\nimport \"./governor/IGovernanceSettings.sol\";\r\n\r\ninterface IService is IAccessControlEnumerableUpgradeable {\r\n    function ADMIN_ROLE() external view returns (bytes32);\r\n\r\n    function WHITELISTED_USER_ROLE() external view returns (bytes32);\r\n\r\n    function SERVICE_MANAGER_ROLE() external view returns (bytes32);\r\n\r\n    function EXECUTOR_ROLE() external view returns (bytes32);\r\n\r\n    function createPool(\r\n        ICompaniesRegistry.CompanyInfo memory companyInfo\r\n    ) external returns (address);\r\n\r\n    function addProposal(uint256 proposalId) external;\r\n\r\n    function addEvent(\r\n        IRecordsRegistry.EventType eventType,\r\n        uint256 proposalId,\r\n        string calldata metaHash\r\n    ) external;\r\n\r\n    function setProtocolCollectedFee(\r\n        address _token,\r\n        uint256 _protocolTokenFee\r\n    ) external;\r\n\r\n    function registry() external view returns (IRegistry);\r\n\r\n    function vesting() external view returns (IVesting);\r\n\r\n    function tokenFactory() external view returns (ITokenFactory);\r\n\r\n    function tgeFactory() external view returns (ITGEFactory);\r\n\r\n    function invoice() external view returns (IInvoice);\r\n\r\n    function protocolTreasury() external view returns (address);\r\n\r\n    function protocolTokenFee() external view returns (uint256);\r\n\r\n    function serviceFee() external view returns (uint256);\r\n\r\n    function getMinSoftCap() external view returns (uint256);\r\n\r\n    function getProtocolTokenFee(\r\n        uint256 amount\r\n    ) external view returns (uint256);\r\n\r\n\r\n    function getProtocolCollectedFee(\r\n        address token_\r\n    ) external view returns (uint256);\r\n\r\n    function poolBeacon() external view returns (address);\r\n\r\n    function tgeBeacon() external view returns (address);\r\n\r\n    function tseBeacon() external view returns (address);\r\n\r\n    function idRegistry() external view returns (address);\r\n\r\n    function tokenBeacon() external view returns (address);\r\n\r\n    function tokenERC1155Beacon() external view returns (address);\r\n\r\n    function customProposal() external view returns (ICustomProposal);\r\n\r\n    function validateTGEInfo(\r\n        ITGE.TGEInfo calldata info,\r\n        uint256 cap,\r\n        uint256 totalSupply,\r\n        IToken.TokenType tokenType\r\n    ) external view;\r\n\r\n    function paused() external view returns (bool);\r\n\r\n    function addInvoiceEvent(\r\n        address pool,\r\n        uint256 invoiceId\r\n    ) external returns (uint256);\r\n\r\n    function purchasePool(\r\n        uint256 jurisdiction,\r\n        uint256 entityType,\r\n        string memory trademark,\r\n        IGovernanceSettings.NewGovernanceSettings memory governanceSettings\r\n    ) external payable;\r\n\r\n    function transferPurchasedPoolByService(\r\n        address newowner,\r\n        uint256 jurisdiction,\r\n        uint256 entityType,\r\n        string memory trademark,\r\n        IGovernanceSettings.NewGovernanceSettings memory governanceSettings\r\n    ) external;\r\n\r\n    function getTrustedForwarder() external view returns (address);\r\n}\r\n"
      },
      "contracts/interfaces/ITGE.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"./IToken.sol\";\r\nimport \"./ITokenERC1155.sol\";\r\nimport \"./IVesting.sol\";\r\n\r\ninterface ITGE {\r\n    /**\r\n     * @notice This structure defines comprehensive TGE settings, including Vesting, Lockup, and distribution rules for these tokens.\r\n     * @dev Initially, such a structure appears as a parameter when creating a proposal in CustomProposal, after which the data from the structure is placed in the storage of the deployed TGE contract.\r\n     * @dev In addition, these data are used as an argument in its original form in the TGEFactory contract, including when creating the initial TGE by the pool owner without a proposal.\r\n     * @param price The price of one token in the smallest unitOfAccount (1 wei when defining the price in ETH, 0.000001 USDT when defining the price in USDT, etc.)\r\n     * @param hardcap The maximum number of tokens that can be sold (note the ProtocolTokenFee for Governance Tokens)\r\n     * @param softcap The minimum number of tokens that buyers must acquire for the TGE to be considered successful\r\n     * @param minPurchase The minimum number of tokens that can be purchased by a single account (minimum one-time purchase)\r\n     * @param maxPurchase The maximum number of tokens that can be purchased by a single account in total during the launched TGE\r\n     * @param duration The duration of the event in blocks, after which the TGE status will be forcibly changed from Active to another\r\n     * @param vestingParams Vesting settings for tokens acquired during this TGE\r\n     * @param userWhiteList A list of addresses allowed to participate in this TGE. Leave the list empty to make the TGE public.\r\n     * @param unitOfAccount The address of the ERC20 or compatible token contract, in the smallest units of which the price of one token is determined\r\n     * @param lockupDuration The duration of token lockup (in blocks), one of two independent lockup conditions.\r\n     * @param lockupTVL The minimum total pool balance in USD, one of two independent lockup conditions.\r\n     */\r\n\r\n    struct TGEInfo {\r\n        uint256 price;\r\n        uint256 hardcap;\r\n        uint256 softcap;\r\n        uint256 minPurchase;\r\n        uint256 maxPurchase;\r\n        uint256 duration;\r\n        IVesting.VestingParams vestingParams;\r\n        address[] userWhitelist;\r\n        uint256[] userWhitelistMin;\r\n        uint256[] userWhitelistMax;\r\n        address unitOfAccount;\r\n        uint256 lockupDuration;\r\n        uint256 lockupTVL;\r\n        address whitelistAdmin;\r\n    }\r\n\r\n    function initialize(\r\n        address _service,\r\n        address _token,\r\n        uint256 _tokenId,\r\n        string memory _uri,\r\n        TGEInfo calldata _info,\r\n        uint256 _protocolFee\r\n    ) external;\r\n\r\n    enum State {\r\n        Active,\r\n        Failed,\r\n        Successful\r\n    }\r\n\r\n    function token() external view returns (address);\r\n\r\n    function tokenId() external view returns (uint256);\r\n\r\n    function state() external view returns (State);\r\n\r\n    function getInfo() external view returns (TGEInfo memory);\r\n\r\n    function transferUnlocked() external view returns (bool);\r\n\r\n    function purchaseOf(address user) external view returns (uint256);\r\n\r\n    function redeemableBalanceOf(address user) external view returns (uint256);\r\n\r\n    function lockedBalanceOf(address account) external view returns (uint256);\r\n\r\n    function getEnd() external view returns (uint256);\r\n\r\n    function totalPurchased() external view returns (uint256);\r\n\r\n    function isERC1155TGE() external view returns (bool);\r\n\r\n    function purchase(uint256 amount) external payable;\r\n\r\n    function transferFunds() external;\r\n\r\n    function setWhitelist(\r\n        address[] memory accounts,\r\n        uint256[] memory mins,\r\n        uint256[] memory maxs\r\n    ) external;\r\n\r\n    function finishTGE() external;\r\n}\r\n"
      },
      "contracts/interfaces/ITGEFactory.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"./ITGE.sol\";\r\nimport \"./ITSE.sol\";\r\nimport \"./IToken.sol\";\r\nimport \"./governor/IGovernanceSettings.sol\";\r\n\r\ninterface ITGEFactory {\r\n    function createSecondaryTGE(\r\n        address token,\r\n        ITGE.TGEInfo calldata tgeInfo,\r\n        IToken.TokenInfo calldata tokenInfo,\r\n        string memory metadataURI\r\n    ) external;\r\n\r\n    function createSecondaryTGEERC1155(\r\n        address token,\r\n        uint256 tokenId,\r\n        string memory uri,\r\n        ITGE.TGEInfo calldata tgeInfo,\r\n        IToken.TokenInfo calldata tokenInfo,\r\n        string memory metadataURI\r\n    ) external;\r\n\r\n    function createPrimaryTGE(\r\n        address poolAddress,\r\n        IToken.TokenInfo memory tokenInfo,\r\n        ITGE.TGEInfo memory tgeInfo,\r\n        string memory metadataURI,\r\n        IGovernanceSettings.NewGovernanceSettings memory governanceSettings_,\r\n        address[] memory secretary,\r\n        address[] memory executor\r\n    ) external;\r\n\r\n     function createTSE(\r\n        address token,\r\n        uint256 tokenId,\r\n        ITSE.TSEInfo calldata tseInfo,\r\n        string memory metadataURI,\r\n        address recipient\r\n    ) external;\r\n}\r\n"
      },
      "contracts/interfaces/ITSE.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"./IToken.sol\";\r\nimport \"./ITokenERC1155.sol\";\r\nimport \"./IVesting.sol\";\r\n\r\ninterface ITSE {\r\n    struct TSEInfo {\r\n        uint256 amount;\r\n        uint256 price;\r\n        uint256 minPurchase;\r\n        uint256 maxPurchase;\r\n        uint256 duration;\r\n        address[] userWhitelist;\r\n        uint256[] userWhitelistMin;\r\n        uint256[] userWhitelistMax;\r\n        address unitOfAccount;\r\n    }\r\n\r\n    function initialize(\r\n        address _token,\r\n        uint256 _tokenId,\r\n        TSEInfo calldata _info,\r\n        address _seller,\r\n        address _recipient\r\n    ) external;\r\n\r\n    enum State {\r\n        Active,\r\n        Failed,\r\n        Successful\r\n    }\r\n\r\n    function token() external view returns (address);\r\n\r\n    function tokenId() external view returns (uint256);\r\n\r\n    function state() external view returns (State);\r\n\r\n    function getInfo() external view returns (TSEInfo memory);\r\n\r\n    function purchaseOf(address user) external view returns (uint256);\r\n\r\n    function getEnd() external view returns (uint256);\r\n\r\n    function totalPurchased() external view returns (uint256);\r\n\r\n    function isERC1155TSE() external view returns (bool);\r\n\r\n    function purchase(uint256 amount) external payable;\r\n\r\n    function setWhitelist(\r\n        address[] memory accounts,\r\n        uint256[] memory mins,\r\n        uint256[] memory maxs\r\n    ) external;\r\n\r\n    function finishTSE() external;\r\n}\r\n"
      },
      "contracts/interfaces/IToken.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/governance/utils/IVotesUpgradeable.sol\";\r\nimport \"./IService.sol\";\r\n\r\ninterface IToken is IVotesUpgradeable, IERC20Upgradeable {\r\n    /**\r\n     * @notice This structure is used to define the parameters of ERC20 tokens issued by the protocol for pools.\r\n     * @dev This structure is suitable for both Governance and Preference tokens if they are based on ERC20.\r\n     * @param tokenType Numeric code for the token type\r\n     * @param name Full name of the token\r\n     * @param symbol Ticker symbol (short name) of the token\r\n     * @param description Description of the token\r\n     * @param cap Maximum allowable token issuance\r\n     * @param decimals Number of decimal places for the token (precision)\r\n     */\r\n    struct TokenInfo {\r\n        TokenType tokenType;\r\n        string name;\r\n        string symbol;\r\n        string description;\r\n        uint256 cap;\r\n        uint8 decimals;\r\n    }\r\n    /**\r\n     * @notice Token type encoding\r\n     */\r\n    enum TokenType {\r\n        None,\r\n        Governance,\r\n        Preference\r\n    }\r\n\r\n    function initialize(\r\n        IService service_,\r\n        address pool_,\r\n        TokenInfo memory info,\r\n        address primaryTGE_\r\n    ) external;\r\n\r\n    function mint(address to, uint256 amount) external;\r\n\r\n    function burn(address from, uint256 amount) external;\r\n\r\n    function cap() external view returns (uint256);\r\n\r\n    function unlockedBalanceOf(address account) external view returns (uint256);\r\n\r\n    function pool() external view returns (address);\r\n\r\n    function service() external view returns (IService);\r\n\r\n    function decimals() external view returns (uint8);\r\n\r\n    function symbol() external view returns (string memory);\r\n\r\n    function tokenType() external view returns (TokenType);\r\n\r\n    function lastTGE() external view returns (address);\r\n\r\n    function getTGEList() external view returns (address[] memory);\r\n\r\n    function isPrimaryTGESuccessful() external view returns (bool);\r\n\r\n    function addTGE(address tge) external;\r\n\r\n    function addTSE(address account, address tse) external;\r\n\r\n    function setTGEVestedTokens(uint256 amount) external;\r\n\r\n    function setProtocolFeeReserved(uint256 amount) external;\r\n\r\n    function getTotalTGEVestedTokens() external view returns (uint256);\r\n\r\n    function getTotalProtocolFeeReserved() external view returns (uint256);\r\n\r\n    function totalSupplyWithReserves() external view returns (uint256);\r\n\r\n    function transferFrom(\r\n        address from,\r\n        address to,\r\n        uint256 amount\r\n    ) external returns (bool);\r\n\r\n    function transfer(address to, uint256 amount) external returns (bool);\r\n\r\n    function delegate(address delegatee) external;\r\n\r\n    function setCompliance(bytes32 compliance_) external;\r\n\r\n    function partnerFee() external view returns (uint256);\r\n\r\n    function partnerAddress() external view returns (address);\r\n\r\n    function depositDividends(\r\n        address tokenAddress,\r\n        uint256 amount\r\n    ) external payable;\r\n\r\n    function claimDividends( uint256 limit) external;\r\n}\r\n"
      },
      "contracts/interfaces/ITokenERC1155.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol\";\r\nimport \"./IService.sol\";\r\nimport \"./IToken.sol\";\r\n\r\ninterface ITokenERC1155 is IERC1155Upgradeable {\r\n    function initialize(\r\n        IService service_,\r\n        address pool_,\r\n        IToken.TokenInfo memory info,\r\n        address primaryTGE_\r\n    ) external;\r\n\r\n    function mint(address to, uint256 tokenId, uint256 amount) external;\r\n\r\n    function burn(address from, uint256 tokenId, uint256 amount) external;\r\n\r\n    function cap(uint256 tokenId) external view returns (uint256);\r\n\r\n    function unlockedBalanceOf(\r\n        address account,\r\n        uint256 tokenId\r\n    ) external view returns (uint256);\r\n\r\n    function pool() external view returns (address);\r\n\r\n    function service() external view returns (IService);\r\n\r\n    function decimals() external view returns (uint8);\r\n\r\n    function lastTokenId() external view returns (uint256);\r\n\r\n    function symbol() external view returns (string memory);\r\n\r\n    function tokenType() external view returns (IToken.TokenType);\r\n\r\n    function lastTGE(uint256 tokenId) external view returns (address);\r\n\r\n    function getTGEList(\r\n        uint256 tokenId\r\n    ) external view returns (address[] memory);\r\n\r\n    function isPrimaryTGESuccessful(\r\n        uint256 tokenId\r\n    ) external view returns (bool);\r\n\r\n    function addTGE(address tge, uint256 tokenId) external;\r\n\r\n    function addTSE(address account, uint256 tokenId, address tse) external;\r\n\r\n    function setTGEVestedTokens(uint256 amount, uint256 tokenId) external;\r\n\r\n    function setProtocolFeeReserved(uint256 amount, uint256 tokenId) external;\r\n\r\n    function getTotalTGEVestedTokens(\r\n        uint256 tokenId\r\n    ) external view returns (uint256);\r\n\r\n    function getTotalProtocolFeeReserved(\r\n        uint256 tokenId\r\n    ) external view returns (uint256);\r\n\r\n    function totalSupplyWithReserves(\r\n        uint256 tokenId\r\n    ) external view returns (uint256);\r\n\r\n    function setURI(uint256 tokenId, string memory tokenURI) external;\r\n\r\n    function setTokenIdCap(uint256 _tokenId, uint256 _cap) external;\r\n\r\n    function transfer(\r\n        address from,\r\n        address to,\r\n        uint256 tokenId,\r\n        uint256 amount\r\n    ) external;\r\n\r\n    function setLastTokenId(uint256 tokenId) external;\r\n\r\n    function setCompliance(bytes32 compliance_) external;\r\n\r\n    function partnerFee() external view returns (uint256);\r\n\r\n    function partnerAddress() external view returns (address);\r\n\r\n    function depositDividendsERC1155(\r\n        uint256 tokenId,\r\n        address tokenAddress,\r\n        uint256 amount\r\n    ) external payable;\r\n\r\n    function claimDividendsERC1155(\r\n        uint256 tokenId,\r\n        uint256 limit\r\n    ) external;\r\n}\r\n"
      },
      "contracts/interfaces/ITokenFactory.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.17;\n\nimport \"./IToken.sol\";\nimport \"./ITokenERC1155.sol\";\n\ninterface ITokenFactory {\n    function createToken(\n        address pool,\n        IToken.TokenInfo memory info,\n        address primaryTGE\n    ) external returns (address token);\n\n    function createTokenERC1155(\n        address pool,\n        IToken.TokenInfo memory info,\n        address primaryTGE\n    ) external returns (address token);\n}\n"
      },
      "contracts/interfaces/IVesting.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\ninterface IVesting {\r\n    /**\r\n     * @notice This interface describes a vesting program for tokens distributed within a specific TGE.\r\n     * @dev Such data is stored in the TGE contracts in the TGEInfo public info.\r\n     * @param vestedShare The percentage of tokens that participate in the vesting program (not distributed until conditions are met)\r\n     * @param cliff Cliff period (in blocks)\r\n     * @param cliffShare The portion of tokens that are distributed\r\n     * @param spans The number of periods for distributing the remaining tokens in vesting in equal shares\r\n     * @param spanDuration The duration of one such period (in blocks)\r\n     * @param spanShare The percentage of the total number of tokens in vesting that corresponds to one such period\r\n     * @param claimTVL The minimum required TVL of the pool after which it will be possible to claim tokens from vesting. Optional parameter (0 if this condition is not needed)\r\n     * @param resolvers A list of addresses that can cancel the vesting program for any address from the TGE participants list\r\n     */\r\n    struct VestingParams {\r\n        uint256 vestedShare;\r\n        uint256 cliff;\r\n        uint256 cliffShare;\r\n        uint256 spans;\r\n        uint256 spanDuration;\r\n        uint256 spanShare;\r\n        uint256 claimTVL;\r\n        address[] resolvers;\r\n    }\r\n\r\n    function vest(address to, uint256 amount) external;\r\n\r\n    function cancel(address tge, address account) external;\r\n\r\n    function validateParams(\r\n        VestingParams memory params\r\n    ) external pure returns (bool);\r\n\r\n    function vested(\r\n        address tge,\r\n        address account\r\n    ) external view returns (uint256);\r\n\r\n    function totalVested(address tge) external view returns (uint256);\r\n\r\n    function vestedBalanceOf(\r\n        address tge,\r\n        address account\r\n    ) external view returns (uint256);\r\n\r\n    function claim(address tge) external;\r\n}\r\n"
      },
      "contracts/interfaces/governor/IGovernanceSettings.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\ninterface IGovernanceSettings {\r\n    /**\r\n     * @notice This structure specifies and stores the Governance settings for each individual pool.\r\n     * @dev More information on the thresholds (proposal, quorum, decision) and creating proposals can be found in the \"Other Entities\" section.\r\n     * @param proposalThreshold_ The proposal threshold (specified in token units with decimals taken into account)\r\n     * @param quorumThreshold_ The quorum threshold (specified as a percentage)\r\n     * @param decisionThreshold_ The decision threshold (specified as a percentage)\r\n     * @param votingDuration_ The duration of the voting period (specified in blocks)\r\n     * @param transferValueForDelay_ The minimum amount in USD for which a transfer from the pool wallet will be subject to a del\r\n     * @param executionDelays_ List of execution delays specified in blocks for different types of proposals\r\n     * @param votingStartDelay The delay before voting starts for newly created proposals, specified in blocks\r\n     */\r\n    struct NewGovernanceSettings {\r\n        uint256 proposalThreshold;\r\n        uint256 quorumThreshold;\r\n        uint256 decisionThreshold;\r\n        uint256 votingDuration;\r\n        uint256 transferValueForDelay;\r\n        uint256[4] executionDelays;\r\n        uint256 votingStartDelay;\r\n    }\r\n\r\n    function setGovernanceSettings(\r\n        NewGovernanceSettings memory settings\r\n    ) external;\r\n}\r\n"
      },
      "contracts/interfaces/governor/IGovernor.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"../../interfaces/registry/IRecordsRegistry.sol\";\r\n\r\ninterface IGovernor {\r\n    /**\r\n     * @notice Struct with proposal core data\r\n     * @dev This interface specifies the Governance settings that existed in the pool at the time of proposal creation, as well as the service data (to which addresses and with what messages and amounts of ETH should be sent) of the scenario that should be executed in case of a positive voting outcome.\r\n     * @param targets A list of addresses to be called in case of a positive voting outcome\r\n     * @param values The amounts of wei to be sent to the addresses from targets\r\n     * @param callDatas The 'calldata' messages to be attached to transactions\r\n     * @param quorumThreshold The quorum, expressed as a percentage with DENOM taken into account\r\n     * @param decisionThreshold The decision-making threshold, expressed as a percentage with DENOM taken into account\r\n     * @param executionDelay The number of blocks that must pass since the creation of the proposal for it to be considered launched\r\n     */\r\n    struct ProposalCoreData {\r\n        address[] targets;\r\n        uint256[] values;\r\n        bytes[] callDatas;\r\n        uint256 quorumThreshold;\r\n        uint256 decisionThreshold;\r\n        uint256 executionDelay;\r\n    }\r\n\r\n    /**\r\n     * @notice This interface specifies information about the subject of the voting, intended for human perception.\r\n     * @dev Struct with proposal metadata\r\n     * @param proposalType The digital code of the proposal type\r\n     * @param description The public description of the proposal\r\n     * @param metaHash The identifier of the private proposal description stored on the backend\r\n     */\r\n    struct ProposalMetaData {\r\n        IRecordsRegistry.EventType proposalType;\r\n        string description;\r\n        string metaHash;\r\n    }\r\n\r\n    function proposalState(uint256 proposalId)\r\n        external\r\n        view\r\n        returns (uint256 state);\r\n}\r\n"
      },
      "contracts/interfaces/governor/IGovernorProposals.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.17;\n\nimport \"../IService.sol\";\n\ninterface IGovernorProposals {\n    function service() external view returns (IService);\n}\n"
      },
      "contracts/interfaces/registry/ICompaniesRegistry.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"../ITGE.sol\";\r\nimport \"../IToken.sol\";\r\n\r\ninterface ICompaniesRegistry {\r\n    /**\r\n    * @notice This is how immutable data about companies is stored\r\n    * @dev For companies listed for sale, this data is stored in the Registry in mapping(uint256 => CompanyInfo) public companies. Additionally, this data is duplicated in the Pool contract in IRegistry.CompanyInfo public companyInfo.\r\n    * @param jurisdiction Numeric code for the jurisdiction (region where the company is registered)\r\n    * @param entityType Numeric code for the type of organization\r\n    * @param ein Unique registration number (uniqueness is checked within a single jurisdiction)\r\n    * @param dateOfIncorporation Date of company registration (in the format provided by the jurisdiction)\r\n    * @param fee Fost of the company in wei ETH\r\n    */ \r\n    struct CompanyInfo {\r\n        uint256 jurisdiction;\r\n        uint256 entityType;\r\n        string ein;\r\n        string dateOfIncorporation;\r\n        uint256 fee;\r\n    }\r\n\r\n    function lockCompany(\r\n        uint256 jurisdiction,\r\n        uint256 entityType\r\n    ) external returns (CompanyInfo memory);\r\n\r\n    function createCompany(\r\n        CompanyInfo calldata info\r\n    ) external;\r\n}\r\n"
      },
      "contracts/interfaces/registry/IRecordsRegistry.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\ninterface IRecordsRegistry {\r\n    /**\r\n     * @notice In the section of the Registry contract that contains records of the type of deployed user contract, the following numeric encoding of contract types is used.\r\n     * @dev TGE is both a type of user contract and an event for which the contract was deployed.\r\n     **/\r\n    enum ContractType {\r\n        None,\r\n        Pool,\r\n        GovernanceToken,\r\n        PreferenceToken,\r\n        TGE\r\n    }\r\n    /**\r\n     * @notice Encoding of the registered event type\r\n     */\r\n    enum EventType {\r\n        None,\r\n        Transfer,\r\n        TGE,\r\n        GovernanceSettings\r\n    }\r\n\r\n    /**\r\n     * @notice This structure is used for contracts storing in the CompanyDAO ecosystem.\r\n     * @dev The Registry contract stores data about deployed user contracts in `ContractInfo[] public contractRecords`, where records receive a sequential and pool-independent numbering.\r\n     * @param addr Deployed contract address\r\n     * @param contractType Digital code of contract type\r\n     * @param description Contract description\r\n     */\r\n    struct ContractInfo {\r\n        address addr;\r\n        ContractType contractType;\r\n        string description;\r\n    }\r\n\r\n    /**\r\n     * @notice Using this data, you can refer to the contract of a specific pool to get more detailed information about the proposal.\r\n     * @dev The Registry contract stores data about proposals launched by users in `ProposalInfo[] public proposalRecords`, where records receive a sequential and pool-independent numbering.\r\n     * @param pool Pool contract in which the proposal was launched\r\n     * @param proposalId Internal proposal identifier for the pool\r\n     * @param description Proposal description\r\n     */\r\n    struct ProposalInfo {\r\n        address pool;\r\n        uint256 proposalId;\r\n        string description;\r\n    }\r\n\r\n    /**\r\n     * @dev The Registry contract stores data about all events that have taken place in `Event[] public events`, where records receive a sequential and pool-independent numbering.\r\n     * @param eventType Code of event type\r\n     * @param pool Address of the pool to which this event relates\r\n     * @param eventContract Address of the event contract, if the event type implies the deployment of a separate contract\r\n     * @param proposalId Internal proposal identifier for the pool, the execution of which led to the launch of this event\r\n     * @param metaHash Hash identifier of the private description stored on the backend\r\n     */\r\n    struct Event {\r\n        EventType eventType;\r\n        address pool;\r\n        address eventContract;\r\n        uint256 proposalId;\r\n        string metaHash;\r\n    }\r\n\r\n    function addContractRecord(\r\n        address addr,\r\n        ContractType contractType,\r\n        string memory description\r\n    ) external returns (uint256 index);\r\n\r\n    function addProposalRecord(\r\n        address pool,\r\n        uint256 proposalId\r\n    ) external returns (uint256 index);\r\n\r\n    function addEventRecord(\r\n        address pool,\r\n        EventType eventType,\r\n        address eventContract,\r\n        uint256 proposalId,\r\n        string calldata metaHash\r\n    ) external returns (uint256 index);\r\n\r\n    function typeOf(address addr) external view returns (ContractType);\r\n}\r\n"
      },
      "contracts/interfaces/registry/IRegistry.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nimport \"./ICompaniesRegistry.sol\";\r\nimport \"./ITokensRegistry.sol\";\r\nimport \"./IRecordsRegistry.sol\";\r\nimport \"../IService.sol\";\r\n\r\ninterface IRegistry is ITokensRegistry, ICompaniesRegistry, IRecordsRegistry {\r\n    function service() external view returns (IService);\r\n\r\n    function COMPANIES_MANAGER_ROLE() external view returns (bytes32);\r\n\r\n    function hasRole(\r\n        bytes32 role,\r\n        address account\r\n    ) external view returns (bool);\r\n\r\n    function log(\r\n        address sender,\r\n        address receiver,\r\n        uint256 value,\r\n        bytes memory data\r\n    ) external;\r\n\r\n    function getPoolAddressByIndex(uint256 index) external view returns (address);\r\n\r\n    function getAvailableCompanyAddress(\r\n        uint256 jurisdiction,\r\n        uint256 entityType\r\n    ) external view returns (address);\r\n}"
      },
      "contracts/interfaces/registry/ITokensRegistry.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.17;\n\ninterface ITokensRegistry {\n    function isTokenWhitelisted(address token) external view returns (bool);\n}\n"
      },
      "contracts/libraries/ExceptionsLibrary.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity 0.8.17;\r\n\r\nlibrary ExceptionsLibrary {\r\n    string public constant ADDRESS_ZERO = \"ADDRESS_ZERO\";\r\n    string public constant INCORRECT_ETH_PASSED = \"INCORRECT_ETH_PASSED\";\r\n    string public constant NO_COMPANY = \"NO_COMPANY\";\r\n    string public constant INVALID_TOKEN = \"INVALID_TOKEN\";\r\n    string public constant NOT_POOL = \"NOT_POOL\";\r\n    string public constant NOT_TGE = \"NOT_TGE\";\r\n    string public constant NOT_Registry = \"NOT_Registry\";\r\n    string public constant NOT_POOL_OWNER = \"NOT_POOL_OWNER\";\r\n    string public constant NOT_SERVICE_OWNER = \"NOT_SERVICE_OWNER\";\r\n    string public constant IS_DAO = \"IS_DAO\";\r\n    string public constant NOT_DAO = \"NOT_DAO\";\r\n    string public constant NOT_WHITELISTED = \"NOT_WHITELISTED\";\r\n    string public constant NOT_SERVICE = \"NOT_SERVICE\";\r\n    string public constant WRONG_STATE = \"WRONG_STATE\";\r\n    string public constant TRANSFER_FAILED = \"TRANSFER_FAILED\";\r\n    string public constant CLAIM_NOT_AVAILABLE = \"CLAIM_NOT_AVAILABLE\";\r\n    string public constant NO_LOCKED_BALANCE = \"NO_LOCKED_BALANCE\";\r\n    string public constant LOCKUP_TVL_REACHED = \"LOCKUP_TVL_REACHED\";\r\n    string public constant HARDCAP_OVERFLOW = \"HARDCAP_OVERFLOW\";\r\n    string public constant MAX_PURCHASE_OVERFLOW = \"MAX_PURCHASE_OVERFLOW\";\r\n    string public constant HARDCAP_OVERFLOW_REMAINING_SUPPLY =\r\n        \"HARDCAP_OVERFLOW_REMAINING_SUPPLY\";\r\n    string public constant HARDCAP_AND_PROTOCOL_FEE_OVERFLOW_REMAINING_SUPPLY =\r\n        \"HARDCAP_AND_PROTOCOL_FEE_OVERFLOW_REMAINING_SUPPLY\";\r\n    string public constant MIN_PURCHASE_UNDERFLOW = \"MIN_PURCHASE_UNDERFLOW\";\r\n    string public constant LOW_UNLOCKED_BALANCE = \"LOW_UNLOCKED_BALANCE\";\r\n    string public constant ZERO_PURCHASE_AMOUNT = \"ZERO_PURCHASE_AMOUNTs\";\r\n    string public constant NOTHING_TO_REDEEM = \"NOTHING_TO_REDEEM\";\r\n    string public constant RECORD_IN_USE = \"RECORD_IN_USE\";\r\n    string public constant INVALID_EIN = \"INVALID_EIN\";\r\n    string public constant VALUE_ZERO = \"VALUE_ZERO\";\r\n    string public constant ALREADY_SET = \"ALREADY_SET\";\r\n    string public constant VOTING_FINISHED = \"VOTING_FINISHED\";\r\n    string public constant ALREADY_EXECUTED = \"ALREADY_EXECUTED\";\r\n    string public constant ACTIVE_TGE_EXISTS = \"ACTIVE_TGE_EXISTS\";\r\n    string public constant INVALID_VALUE = \"INVALID_VALUE\";\r\n    string public constant INVALID_CAP = \"INVALID_CAP\";\r\n    string public constant INVALID_HARDCAP = \"INVALID_HARDCAP\";\r\n    string public constant ONLY_POOL = \"ONLY_POOL\";\r\n    string public constant ETH_TRANSFER_FAIL = \"ETH_TRANSFER_FAIL\";\r\n    string public constant TOKEN_TRANSFER_FAIL = \"TOKEN_TRANSFER_FAIL\";\r\n    string public constant SERVICE_PAUSED = \"SERVICE_PAUSED\";\r\n    string public constant INVALID_PROPOSAL_TYPE = \"INVALID_PROPOSAL_TYPE\";\r\n    string public constant EXECUTION_FAILED = \"EXECUTION_FAILED\";\r\n    string public constant INVALID_USER = \"INVALID_USER\";\r\n    string public constant NOT_LAUNCHED = \"NOT_LAUNCHED\";\r\n    string public constant LAUNCHED = \"LAUNCHED\";\r\n    string public constant VESTING_TVL_REACHED = \"VESTING_TVL_REACHED\";\r\n    string public constant WRONG_TOKEN_ADDRESS = \"WRONG_TOKEN_ADDRESS\";\r\n    string public constant GOVERNANCE_TOKEN_EXISTS = \"GOVERNANCE_TOKEN_EXISTS\";\r\n    string public constant THRESHOLD_NOT_REACHED = \"THRESHOLD_NOT_REACHED\";\r\n    string public constant UNSUPPORTED_TOKEN_TYPE = \"UNSUPPORTED_TOKEN_TYPE\";\r\n    string public constant ALREADY_VOTED = \"ALREADY_VOTED\";\r\n    string public constant ZERO_VOTES = \"ZERO_VOTES\";\r\n    string public constant ACTIVE_GOVERNANCE_SETTINGS_PROPOSAL_EXISTS =\r\n        \"ACTIVE_GOVERNANCE_SETTINGS_PROPOSAL_EXISTS\";\r\n    string public constant EMPTY_ADDRESS = \"EMPTY_ADDRESS\";\r\n    string public constant NOT_VALID_PROPOSER = \"NOT_VALID_PROPOSER\";\r\n    string public constant SHARES_SUM_EXCEEDS_ONE = \"SHARES_SUM_EXCEEDS_ONE\";\r\n    string public constant NOT_RESOLVER = \"NOT_RESOLVER\";\r\n    string public constant NOT_REGISTRY = \"NOT_REGISTRY\";\r\n    string public constant INVALID_TARGET = \"INVALID_TARGET\";\r\n    string public constant NOT_TGE_FACTORY = \"NOT_TGE_FACTORY\";\r\n    string public constant WRONG_AMOUNT = \"WRONG_AMOUNT\";\r\n    string public constant WRONG_BLOCK_NUMBER = \"WRONG_BLOCK_NUMBER\";\r\n    string public constant NOT_VALID_EXECUTOR = \"NOT_VALID_EXECUTOR\";\r\n    string public constant POOL_PAUSED = \"POOL_PAUSED\";\r\n    string public constant NOT_INVOICE_MANAGER = \"NOT_INVOICE_MANAGER\";\r\n    string public constant WRONG_RESOLVER = \"WRONG_RESOLVER\";\r\n    string public constant INVALID_PURCHASE_AMOUNT = \"INVALID_PURCHASE_AMOUNT\";\r\n    string public constant NOT_SERVICE_ADMIN = \"NOT_SERVICE_ADMIN\";\r\n}\r\n"
      },
      "contracts/utils/ERC20VotesWithBalanceSnapshot.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity ^0.8.17;\r\n\r\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/utils/ArraysUpgradeable.sol\";\r\nimport \"@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol\";\r\n\r\nabstract contract ERC20VotesWithBalanceSnapshot is ERC20VotesUpgradeable {\r\n    using ArraysUpgradeable for uint256[];\r\n    using CountersUpgradeable for CountersUpgradeable.Counter;\r\n\r\n    // Struct to store snapshot data\r\n    struct Snapshots {\r\n        uint256[] ids;\r\n        uint256[] values;\r\n    }\r\n\r\n    // Mapping of user address to snapshots\r\n    mapping(address => Snapshots) private _accountBalanceSnapshots;\r\n    // Mapping of snapshot id to total supply at that snapshot\r\n    mapping(uint256 => Snapshots) private _totalSupplySnapshots;\r\n\r\n    // Counter for current snapshot id\r\n    CountersUpgradeable.Counter private _currentSnapshotId;\r\n\r\n    // Event to emit when a snapshot is created\r\n    event Snapshot(uint256 id);\r\n\r\n    function _snapshot() internal virtual returns (uint256) {\r\n        _currentSnapshotId.increment();\r\n        uint256 currentId = _currentSnapshotId.current();\r\n\r\n        // if the last snapshot was in the current block, do not create a new one\r\n        if (_lastSnapshotId(_totalSupplySnapshots[currentId].ids) == block.number) {\r\n            return currentId;\r\n        }\r\n\r\n        _updateSnapshot(_totalSupplySnapshots[currentId], totalSupply());\r\n\r\n        emit Snapshot(currentId);\r\n        return currentId;\r\n    }\r\n\r\n    function balanceOfAt(address account, uint256 snapshotId) public view returns (uint256) {\r\n        require(snapshotId > 0 && snapshotId <= _currentSnapshotId.current(), \"ERC20Snapshot: invalid snapshot id\");\r\n\r\n        (bool snapshotted, uint256 value) = _valueAt(\r\n            snapshotId,\r\n            _accountBalanceSnapshots[account]\r\n        );\r\n        return snapshotted ? value : balanceOf(account);\r\n    }\r\n\r\n     function totalSupplyAtSnapshotId(uint256 snapshotId) public view virtual returns (uint256) {\r\n        require(snapshotId > 0 && snapshotId <= _currentSnapshotId.current(), \"ERC20Snapshot: invalid snapshot id\");\r\n\r\n        (bool snapshotted, uint256 value) = _valueAt(\r\n            snapshotId,\r\n            _totalSupplySnapshots[snapshotId]\r\n        );\r\n        return snapshotted ? value : totalSupply();\r\n    }\r\n\r\n    function _beforeTokenTransfer(address from, address to, uint256 amount)\r\n        internal virtual override(ERC20Upgradeable) // Specify the correct parent contract here\r\n    {\r\n        super._beforeTokenTransfer(from, to, amount); // Call the parent implementation\r\n\r\n        if (from == address(0)) {\r\n            // Minting tokens\r\n            _updateAccountSnapshot(to);\r\n        } else if (to == address(0)) {\r\n            // Burning tokens\r\n            _updateAccountSnapshot(from);\r\n        } else {\r\n            // Normal transfer\r\n            _updateAccountSnapshot(from);\r\n            _updateAccountSnapshot(to);\r\n        }\r\n    }\r\n\r\n    function _updateAccountSnapshot(address account) private {\r\n        _updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));\r\n    }\r\n\r\n    function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {\r\n        uint256 currentId = _currentSnapshotId.current();\r\n        if (_lastSnapshotId(snapshots.ids) < currentId) {\r\n            snapshots.ids.push(currentId);\r\n            snapshots.values.push(currentValue);\r\n        } \r\n    }\r\n\r\n    function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {\r\n        if (ids.length == 0) {\r\n            return 0;\r\n        } else {\r\n            return ids[ids.length - 1];\r\n        }\r\n    }\r\n\r\n    function _valueAt(\r\n        uint256 snapshotId,\r\n        Snapshots storage snapshots\r\n    ) private view returns (bool, uint256) {\r\n        uint256 index = snapshots.ids.findUpperBound(snapshotId);\r\n\r\n        if (index == snapshots.ids.length) {\r\n            return (false, 0);\r\n        } else {\r\n            return (true, snapshots.values[index]);\r\n        }\r\n    }\r\n}\r\n"
      }
    }
  }}