ETH Price: $2,501.61 (+4.26%)

Transaction Decoder

Block:
19946969 at May-25-2024 12:43:47 PM +UTC
Transaction Fee:
0.00037938130445545 ETH $0.95
Gas Used:
69,575 Gas / 5.452839446 Gwei

Emitted Events:

401 BeaconProxy.0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925( 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925, 0x000000000000000000000000554b9dbd1f4fb9d0f10ffa1ec2abd5e16d9d88c8, 0x0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000000 )

Account State Difference:

  Address   Before After State Difference Code
(Titan Builder)
10.340323304253216799 Eth10.340355465496855774 Eth0.000032161243638975
0x554b9dBD...16d9d88C8
0.000606493133918783 Eth
Nonce: 42
0.000227111829463333 Eth
Nonce: 43
0.00037938130445545
0x7476d8B3...Ffa552034

Execution Trace

BeaconProxy.d505accf( )
  • Beacon.STATICCALL( )
  • P00lsTokenCreator.permit( owner=0x554b9dBD1f4FB9d0F10Ffa1EC2AbD5e16d9d88C8, spender=0x0000000000000000000000000000000000000001, value=0, deadline=115792089237316195423570985008687907853269984665640564039457584007913129639935, v=27, r=B6C45749CE48D3DCBF586F8498F9041369F709AA2D5C7427BEDBC513B0173BFC, s=3D8BB76D98D33DEA7CBA41888F6CCB93D383293893E7A18171C3B0C9DFBFC87D )
    • Null: 0x000...001.1cf753bf( )
      File 1 of 3: BeaconProxy
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
      import "@openzeppelin/contracts/proxy/Proxy.sol";
      /// @custom:security-contact [email protected]
      contract BeaconProxy is Proxy {
          IBeacon private immutable _beacon;
          event BeaconUpgraded(IBeacon indexed beacon);
          constructor(IBeacon beacon)
          {
              _beacon = beacon;
              emit BeaconUpgraded(beacon);
          }
          function _implementation()
              internal
              view
              override
              returns (address)
          {
              return _beacon.implementation();
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev This is the interface that {BeaconProxy} expects of its beacon.
       */
      interface IBeacon {
          /**
           * @dev Must return an address that can be used as a delegate call target.
           *
           * {BeaconProxy} will check that this address is a contract.
           */
          function implementation() external view returns (address);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (proxy/Proxy.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
       * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
       * be specified by overriding the virtual {_implementation} function.
       *
       * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
       * different contract through the {_delegate} function.
       *
       * The success and return data of the delegated call will be returned back to the caller of the proxy.
       */
      abstract contract Proxy {
          /**
           * @dev Delegates the current call to `implementation`.
           *
           * This function does not return to its internal call site, it will return directly to the external caller.
           */
          function _delegate(address implementation) internal virtual {
              assembly {
                  // Copy msg.data. We take full control of memory in this inline assembly
                  // block because it will not return to Solidity code. We overwrite the
                  // Solidity scratch pad at memory position 0.
                  calldatacopy(0, 0, calldatasize())
                  // Call the implementation.
                  // out and outsize are 0 because we don't know the size yet.
                  let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
                  // Copy the returned data.
                  returndatacopy(0, 0, returndatasize())
                  switch result
                  // delegatecall returns 0 on error.
                  case 0 {
                      revert(0, returndatasize())
                  }
                  default {
                      return(0, returndatasize())
                  }
              }
          }
          /**
           * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function
           * and {_fallback} should delegate.
           */
          function _implementation() internal view virtual returns (address);
          /**
           * @dev Delegates the current call to the address returned by `_implementation()`.
           *
           * This function does not return to its internall call site, it will return directly to the external caller.
           */
          function _fallback() internal virtual {
              _beforeFallback();
              _delegate(_implementation());
          }
          /**
           * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
           * function in the contract matches the call data.
           */
          fallback() external payable virtual {
              _fallback();
          }
          /**
           * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
           * is empty.
           */
          receive() external payable virtual {
              _fallback();
          }
          /**
           * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
           * call, or as part of the Solidity `fallback` or `receive` functions.
           *
           * If overriden should call `super._beforeFallback()`.
           */
          function _beforeFallback() internal virtual {}
      }
      

      File 2 of 3: Beacon
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@openzeppelin/contracts/access/Ownable.sol";
      import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
      import "@openzeppelin/contracts/utils/Address.sol";
      /// @custom:security-contact [email protected]
      contract Beacon is IBeacon, Ownable {
          address private _implementation;
          event Upgraded(address indexed implementation);
          function implementation()
              public
              view
              override
              returns (address)
          {
              return _implementation;
          }
          function upgradeTo(address newImplementation)
              public
              onlyOwner
          {
              _setImplementation(newImplementation);
              emit Upgraded(newImplementation);
          }
          function _setImplementation(address newImplementation)
              private
          {
              require(Address.isContract(newImplementation), "UpgradeableBeacon: implementation is not a contract");
              _implementation = newImplementation;
          }
      }// SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
      pragma solidity ^0.8.0;
      import "../utils/Context.sol";
      /**
       * @dev Contract module which provides a basic access control mechanism, where
       * there is an account (an owner) that can be granted exclusive access to
       * specific functions.
       *
       * By default, the owner account will be the one that deploys the contract. This
       * can later be changed with {transferOwnership}.
       *
       * This module is used through inheritance. It will make available the modifier
       * `onlyOwner`, which can be applied to your functions to restrict their use to
       * the owner.
       */
      abstract contract Ownable is Context {
          address private _owner;
          event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
          /**
           * @dev Initializes the contract setting the deployer as the initial owner.
           */
          constructor() {
              _transferOwnership(_msgSender());
          }
          /**
           * @dev Returns the address of the current owner.
           */
          function owner() public view virtual returns (address) {
              return _owner;
          }
          /**
           * @dev Throws if called by any account other than the owner.
           */
          modifier onlyOwner() {
              require(owner() == _msgSender(), "Ownable: caller is not the owner");
              _;
          }
          /**
           * @dev Leaves the contract without owner. It will not be possible to call
           * `onlyOwner` functions anymore. Can only be called by the current owner.
           *
           * NOTE: Renouncing ownership will leave the contract without an owner,
           * thereby removing any functionality that is only available to the owner.
           */
          function renounceOwnership() public virtual onlyOwner {
              _transferOwnership(address(0));
          }
          /**
           * @dev Transfers ownership of the contract to a new account (`newOwner`).
           * Can only be called by the current owner.
           */
          function transferOwnership(address newOwner) public virtual onlyOwner {
              require(newOwner != address(0), "Ownable: new owner is the zero address");
              _transferOwnership(newOwner);
          }
          /**
           * @dev Transfers ownership of the contract to a new account (`newOwner`).
           * Internal function without access restriction.
           */
          function _transferOwnership(address newOwner) internal virtual {
              address oldOwner = _owner;
              _owner = newOwner;
              emit OwnershipTransferred(oldOwner, newOwner);
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev This is the interface that {BeaconProxy} expects of its beacon.
       */
      interface IBeacon {
          /**
           * @dev Must return an address that can be used as a delegate call target.
           *
           * {BeaconProxy} will check that this address is a contract.
           */
          function implementation() external view returns (address);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
      pragma solidity ^0.8.1;
      /**
       * @dev Collection of functions related to the address type
       */
      library Address {
          /**
           * @dev Returns true if `account` is a contract.
           *
           * [IMPORTANT]
           * ====
           * It is unsafe to assume that an address for which this function returns
           * false is an externally-owned account (EOA) and not a contract.
           *
           * Among others, `isContract` will return false for the following
           * types of addresses:
           *
           *  - an externally-owned account
           *  - a contract in construction
           *  - an address where a contract will be created
           *  - an address where a contract lived, but was destroyed
           * ====
           *
           * [IMPORTANT]
           * ====
           * You shouldn't rely on `isContract` to protect against flash loan attacks!
           *
           * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
           * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
           * constructor.
           * ====
           */
          function isContract(address account) internal view returns (bool) {
              // This method relies on extcodesize/address.code.length, which returns 0
              // for contracts in construction, since the code is only stored at the end
              // of the constructor execution.
              return account.code.length > 0;
          }
          /**
           * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
           * `recipient`, forwarding all available gas and reverting on errors.
           *
           * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
           * of certain opcodes, possibly making contracts go over the 2300 gas limit
           * imposed by `transfer`, making them unable to receive funds via
           * `transfer`. {sendValue} removes this limitation.
           *
           * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
           *
           * IMPORTANT: because control is transferred to `recipient`, care must be
           * taken to not create reentrancy vulnerabilities. Consider using
           * {ReentrancyGuard} or the
           * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
           */
          function sendValue(address payable recipient, uint256 amount) internal {
              require(address(this).balance >= amount, "Address: insufficient balance");
              (bool success, ) = recipient.call{value: amount}("");
              require(success, "Address: unable to send value, recipient may have reverted");
          }
          /**
           * @dev Performs a Solidity function call using a low level `call`. A
           * plain `call` is an unsafe replacement for a function call: use this
           * function instead.
           *
           * If `target` reverts with a revert reason, it is bubbled up by this
           * function (like regular Solidity function calls).
           *
           * Returns the raw returned data. To convert to the expected return value,
           * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
           *
           * Requirements:
           *
           * - `target` must be a contract.
           * - calling `target` with `data` must not revert.
           *
           * _Available since v3.1._
           */
          function functionCall(address target, bytes memory data) internal returns (bytes memory) {
              return functionCall(target, data, "Address: low-level call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
           * `errorMessage` as a fallback revert reason when `target` reverts.
           *
           * _Available since v3.1._
           */
          function functionCall(
              address target,
              bytes memory data,
              string memory errorMessage
          ) internal returns (bytes memory) {
              return functionCallWithValue(target, data, 0, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but also transferring `value` wei to `target`.
           *
           * Requirements:
           *
           * - the calling contract must have an ETH balance of at least `value`.
           * - the called Solidity function must be `payable`.
           *
           * _Available since v3.1._
           */
          function functionCallWithValue(
              address target,
              bytes memory data,
              uint256 value
          ) internal returns (bytes memory) {
              return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
          }
          /**
           * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
           * with `errorMessage` as a fallback revert reason when `target` reverts.
           *
           * _Available since v3.1._
           */
          function functionCallWithValue(
              address target,
              bytes memory data,
              uint256 value,
              string memory errorMessage
          ) internal returns (bytes memory) {
              require(address(this).balance >= value, "Address: insufficient balance for call");
              require(isContract(target), "Address: call to non-contract");
              (bool success, bytes memory returndata) = target.call{value: value}(data);
              return verifyCallResult(success, returndata, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but performing a static call.
           *
           * _Available since v3.3._
           */
          function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
              return functionStaticCall(target, data, "Address: low-level static call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
           * but performing a static call.
           *
           * _Available since v3.3._
           */
          function functionStaticCall(
              address target,
              bytes memory data,
              string memory errorMessage
          ) internal view returns (bytes memory) {
              require(isContract(target), "Address: static call to non-contract");
              (bool success, bytes memory returndata) = target.staticcall(data);
              return verifyCallResult(success, returndata, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but performing a delegate call.
           *
           * _Available since v3.4._
           */
          function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
              return functionDelegateCall(target, data, "Address: low-level delegate call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
           * but performing a delegate call.
           *
           * _Available since v3.4._
           */
          function functionDelegateCall(
              address target,
              bytes memory data,
              string memory errorMessage
          ) internal returns (bytes memory) {
              require(isContract(target), "Address: delegate call to non-contract");
              (bool success, bytes memory returndata) = target.delegatecall(data);
              return verifyCallResult(success, returndata, errorMessage);
          }
          /**
           * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
           * revert reason using the provided one.
           *
           * _Available since v4.3._
           */
          function verifyCallResult(
              bool success,
              bytes memory returndata,
              string memory errorMessage
          ) internal pure returns (bytes memory) {
              if (success) {
                  return returndata;
              } else {
                  // Look for revert reason and bubble it up if present
                  if (returndata.length > 0) {
                      // The easiest way to bubble the revert reason is using memory via assembly
                      assembly {
                          let returndata_size := mload(returndata)
                          revert(add(32, returndata), returndata_size)
                      }
                  } else {
                      revert(errorMessage);
                  }
              }
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Provides information about the current execution context, including the
       * sender of the transaction and its data. While these are generally available
       * via msg.sender and msg.data, they should not be accessed in such a direct
       * manner, since when dealing with meta-transactions the account sending and
       * paying for execution may not be the actual sender (as far as an application
       * is concerned).
       *
       * This contract is only required for intermediate, library-like contracts.
       */
      abstract contract Context {
          function _msgSender() internal view virtual returns (address) {
              return msg.sender;
          }
          function _msgData() internal view virtual returns (bytes calldata) {
              return msg.data;
          }
      }
      

      File 3 of 3: P00lsTokenCreator
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
      import "@openzeppelin/contracts/utils/structs/BitMaps.sol";
      import "../utils/RegistryOwnable.sol";
      import "./P00lsTokenBase.sol";
      import "./interfaces.sol";
      /// @custom:security-contact [email protected]
      contract P00lsTokenCreator is P00lsTokenBase, RegistryOwnable
      {
          using BitMaps for BitMaps.BitMap;
          IP00lsTokenXCreator public xCreatorToken;
          bytes32             public merkleRoot;
          BitMaps.BitMap      private __claimedBitMap;
          /// @custom:oz-upgrades-unsafe-allow constructor
          constructor(address registry)
              RegistryOwnable(registry)
              initializer()
          {}
          function initialize(string calldata name, string calldata symbol, bytes32 root, address child)
              external
              initializer()
          {
              __ERC20_init(name, symbol);
              __ERC20Permit_init(name);
              merkleRoot = root;
              xCreatorToken = IP00lsTokenXCreator(child);
          }
          function isClaimed(uint256 index)
              external
              view
              returns (bool)
          {
              return __claimedBitMap.get(index);
          }
          function claim(uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof)
              external
          {
              require(!__claimedBitMap.get(index), "P00lsTokenCreator::claim: drop already claimed");
              require(MerkleProof.verify(merkleProof, merkleRoot, keccak256(abi.encodePacked(index, account, amount))), "P00lsTokenCreator::claim: invalid merkle proof");
              __claimedBitMap.set(index);
              _mint(account, amount);
          }
          function owner()
              public
              view
              override(P00lsTokenBase, RegistryOwnable)
              returns (address)
          {
              return super.owner();
          }
          /**
           * xCreatorToken bindings
           */
          function _delegate(address delegator, address delegatee)
              internal
              override
          {
              super._delegate(delegator, delegatee);
              xCreatorToken.__delegate(delegator, delegatee);
          }
          function allowance(address holder, address spender)
              public
              view
              override
              returns (uint256)
          {
              return spender == address(xCreatorToken)
                  ? type(uint256).max
                  : super.allowance(holder, spender);
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/MerkleProof.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev These functions deal with verification of Merkle Trees proofs.
       *
       * The proofs can be generated using the JavaScript library
       * https://github.com/miguelmota/merkletreejs[merkletreejs].
       * Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
       *
       * See `test/utils/cryptography/MerkleProof.test.js` for some examples.
       */
      library MerkleProof {
          /**
           * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
           * defined by `root`. For this, a `proof` must be provided, containing
           * sibling hashes on the branch from the leaf to the root of the tree. Each
           * pair of leaves and each pair of pre-images are assumed to be sorted.
           */
          function verify(
              bytes32[] memory proof,
              bytes32 root,
              bytes32 leaf
          ) internal pure returns (bool) {
              return processProof(proof, leaf) == root;
          }
          /**
           * @dev Returns the rebuilt hash obtained by traversing a Merklee tree up
           * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
           * hash matches the root of the tree. When processing the proof, the pairs
           * of leafs & pre-images are assumed to be sorted.
           *
           * _Available since v4.4._
           */
          function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
              bytes32 computedHash = leaf;
              for (uint256 i = 0; i < proof.length; i++) {
                  bytes32 proofElement = proof[i];
                  if (computedHash <= proofElement) {
                      // Hash(current computed hash + current element of the proof)
                      computedHash = _efficientHash(computedHash, proofElement);
                  } else {
                      // Hash(current element of the proof + current computed hash)
                      computedHash = _efficientHash(proofElement, computedHash);
                  }
              }
              return computedHash;
          }
          function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
              assembly {
                  mstore(0x00, a)
                  mstore(0x20, b)
                  value := keccak256(0x00, 0x40)
              }
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/structs/BitMaps.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.
       * Largelly inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
       */
      library BitMaps {
          struct BitMap {
              mapping(uint256 => uint256) _data;
          }
          /**
           * @dev Returns whether the bit at `index` is set.
           */
          function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
              uint256 bucket = index >> 8;
              uint256 mask = 1 << (index & 0xff);
              return bitmap._data[bucket] & mask != 0;
          }
          /**
           * @dev Sets the bit at `index` to the boolean `value`.
           */
          function setTo(
              BitMap storage bitmap,
              uint256 index,
              bool value
          ) internal {
              if (value) {
                  set(bitmap, index);
              } else {
                  unset(bitmap, index);
              }
          }
          /**
           * @dev Sets the bit at `index`.
           */
          function set(BitMap storage bitmap, uint256 index) internal {
              uint256 bucket = index >> 8;
              uint256 mask = 1 << (index & 0xff);
              bitmap._data[bucket] |= mask;
          }
          /**
           * @dev Unsets the bit at `index`.
           */
          function unset(BitMap storage bitmap, uint256 index) internal {
              uint256 bucket = index >> 8;
              uint256 mask = 1 << (index & 0xff);
              bitmap._data[bucket] &= ~mask;
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
      import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
      function addressToUint256(address a) pure returns (uint256) {
          return uint256(uint160(a));
      }
      /// @custom:security-contact [email protected]
      abstract contract RegistryOwnable {
          /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
          IERC721 public immutable ownershipRegistry;
          modifier onlyOwner() {
              require(owner() == msg.sender, "RegistryOwnable: caller is not the owner");
              _;
          }
          modifier onlyAdmin() {
              require(admin() == msg.sender, "RegistryOwnable: caller is not the admin");
              _;
          }
          /// @custom:oz-upgrades-unsafe-allow constructor
          constructor(address ownershipRegistry_)
          {
              ownershipRegistry = IERC721(ownershipRegistry_);
          }
          function owner()
              public
              view
              virtual
              returns (address)
          {
              return ownershipRegistry.ownerOf(addressToUint256(address(this)));
          }
          function admin()
              public
              view
              virtual
              returns (address)
          {
              return ownershipRegistry.ownerOf(addressToUint256(address(ownershipRegistry)));
          }
          function transferOwnership(address newOwner) public virtual onlyOwner {
              ownershipRegistry.transferFrom(owner(), newOwner, addressToUint256(address(this)));
          }
      }
      /// @custom:security-contact [email protected]
      abstract contract RegistryOwnableUpgradeable is Initializable {
          IERC721 public ownershipRegistry;
          modifier onlyOwner() {
              require(owner() == msg.sender, "RegistryOwnable: caller is not the owner");
              _;
          }
          modifier onlyAdmin() {
              require(admin() == msg.sender, "RegistryOwnable: caller is not the admin");
              _;
          }
          function __RegistryOwnable_init(address ownershipRegistry_)
              public
              initializer
          {
              ownershipRegistry = IERC721(ownershipRegistry_);
          }
          function owner()
              public
              view
              virtual
              returns (address)
          {
              return ownershipRegistry.ownerOf(addressToUint256(address(this)));
          }
          function admin()
              public
              view
              virtual
              returns (address)
          {
              return ownershipRegistry.ownerOf(addressToUint256(address(ownershipRegistry)));
          }
          function transferOwnership(address newOwner)
              public
              virtual
              onlyOwner
          {
              ownershipRegistry.transferFrom(owner(), newOwner, addressToUint256(address(this)));
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@amxx/hre/contracts/ENSReverseRegistration.sol";
      import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
      import "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol";
      import "./extensions/ERC1046Upgradeable.sol";
      import "./extensions/ERC1363Upgradeable.sol";
      /// @custom:security-contact [email protected]
      abstract contract P00lsTokenBase is
          ERC20VotesUpgradeable,
          ERC1046Upgradeable,
          ERC1363Upgradeable,
          MulticallUpgradeable
      {
          function owner()
              public
              view
              virtual
              returns (address);
          /**
           * Admin
           */
          function setTokenURI(string calldata _tokenURI)
              external
          {
              require(owner() == msg.sender, "P00lsToken: restricted");
              _setTokenURI(_tokenURI);
          }
          function setName(address ensregistry, string calldata ensname)
              external
          {
              require(owner() == msg.sender, "P00lsToken: restricted");
              ENSReverseRegistration.setName(ensregistry, ensname);
          }
          /**
           * Internal override resolution
           */
          function _mint(address account, uint256 amount)
              internal
              override(ERC20Upgradeable, ERC20VotesUpgradeable)
          {
              super._mint(account, amount);
          }
          function _burn(address account, uint256 amount)
              internal
              override(ERC20Upgradeable, ERC20VotesUpgradeable)
          {
              super._burn(account, amount);
          }
          function _afterTokenTransfer(address from, address to, uint256 amount)
              internal
              override(ERC20Upgradeable, ERC20VotesUpgradeable)
          {
              super._afterTokenTransfer(from, to, amount);
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@openzeppelin/contracts/interfaces/IERC20.sol";
      import "@openzeppelin/contracts/interfaces/draft-IERC2612.sol";
      import "@openzeppelin/contracts/governance/utils/IVotes.sol";
      import "./extensions/IERC1046.sol";
      import "./extensions/IERC1363.sol";
      /// @custom:security-contact [email protected]
      interface IP00lsTokenBase is IERC20, IERC1046, IERC1363, IERC2612, IVotes
      {
          function owner() external view returns (address);
          function setTokenURI(string calldata) external;
          function setName(address, string calldata) external;
      }
      /// @custom:security-contact [email protected]
      interface IP00lsTokenCreator is IP00lsTokenBase {
          function xCreatorToken() external view returns (IP00lsTokenXCreator);
          function merkleRoot() external view returns (bytes32);
          function isClaimed(uint256) external view returns (bool);
          function claim(uint256, address, uint256, bytes32[] calldata) external;
      }
      /// @custom:security-contact [email protected]
      interface IP00lsTokenXCreator is IP00lsTokenBase {
          function creatorToken() external view returns (IP00lsTokenCreator);
          function escrow() external view returns (address);
          function deposit(uint256) external;
          function withdraw(uint256) external;
          function depositFor(uint256, address) external;
          function withdrawTo(uint256, address) external;
          function valueToShares(uint256) external view returns (uint256);
          function sharesToValue(uint256) external view returns (uint256);
          function pastSharesToValue(uint256 shares, uint256 blockNumber) external view returns (uint256);
          function __delegate(address, address) external;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
      pragma solidity ^0.8.0;
      import "../../utils/introspection/IERC165.sol";
      /**
       * @dev Required interface of an ERC721 compliant contract.
       */
      interface IERC721 is IERC165 {
          /**
           * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
           */
          event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
          /**
           * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
           */
          event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
          /**
           * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
           */
          event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
          /**
           * @dev Returns the number of tokens in ``owner``'s account.
           */
          function balanceOf(address owner) external view returns (uint256 balance);
          /**
           * @dev Returns the owner of the `tokenId` token.
           *
           * Requirements:
           *
           * - `tokenId` must exist.
           */
          function ownerOf(uint256 tokenId) external view returns (address owner);
          /**
           * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
           * are aware of the ERC721 protocol to prevent tokens from being forever locked.
           *
           * Requirements:
           *
           * - `from` cannot be the zero address.
           * - `to` cannot be the zero address.
           * - `tokenId` token must exist and be owned by `from`.
           * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
           * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
           *
           * Emits a {Transfer} event.
           */
          function safeTransferFrom(
              address from,
              address to,
              uint256 tokenId
          ) external;
          /**
           * @dev Transfers `tokenId` token from `from` to `to`.
           *
           * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
           *
           * Requirements:
           *
           * - `from` cannot be the zero address.
           * - `to` cannot be the zero address.
           * - `tokenId` token must be owned by `from`.
           * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
           *
           * Emits a {Transfer} event.
           */
          function transferFrom(
              address from,
              address to,
              uint256 tokenId
          ) external;
          /**
           * @dev Gives permission to `to` to transfer `tokenId` token to another account.
           * The approval is cleared when the token is transferred.
           *
           * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
           *
           * Requirements:
           *
           * - The caller must own the token or be an approved operator.
           * - `tokenId` must exist.
           *
           * Emits an {Approval} event.
           */
          function approve(address to, uint256 tokenId) external;
          /**
           * @dev Returns the account approved for `tokenId` token.
           *
           * Requirements:
           *
           * - `tokenId` must exist.
           */
          function getApproved(uint256 tokenId) external view returns (address operator);
          /**
           * @dev Approve or remove `operator` as an operator for the caller.
           * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
           *
           * Requirements:
           *
           * - The `operator` cannot be the caller.
           *
           * Emits an {ApprovalForAll} event.
           */
          function setApprovalForAll(address operator, bool _approved) external;
          /**
           * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
           *
           * See {setApprovalForAll}
           */
          function isApprovedForAll(address owner, address operator) external view returns (bool);
          /**
           * @dev Safely transfers `tokenId` token from `from` to `to`.
           *
           * Requirements:
           *
           * - `from` cannot be the zero address.
           * - `to` cannot be the zero address.
           * - `tokenId` token must exist and be owned by `from`.
           * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
           * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
           *
           * Emits a {Transfer} event.
           */
          function safeTransferFrom(
              address from,
              address to,
              uint256 tokenId,
              bytes calldata data
          ) external;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)
      pragma solidity ^0.8.0;
      import "../../utils/AddressUpgradeable.sol";
      /**
       * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
       * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
       * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
       * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
       *
       * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
       * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
       *
       * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
       * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
       *
       * [CAUTION]
       * ====
       * Avoid leaving a contract uninitialized.
       *
       * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
       * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
       * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
       *
       * [.hljs-theme-light.nopadding]
       * ```
       * /// @custom:oz-upgrades-unsafe-allow constructor
       * constructor() initializer {}
       * ```
       * ====
       */
      abstract contract Initializable {
          /**
           * @dev Indicates that the contract has been initialized.
           */
          bool private _initialized;
          /**
           * @dev Indicates that the contract is in the process of being initialized.
           */
          bool private _initializing;
          /**
           * @dev Modifier to protect an initializer function from being invoked twice.
           */
          modifier initializer() {
              // If the contract is initializing we ignore whether _initialized is set in order to support multiple
              // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
              // contract may have been reentered.
              require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");
              bool isTopLevelCall = !_initializing;
              if (isTopLevelCall) {
                  _initializing = true;
                  _initialized = true;
              }
              _;
              if (isTopLevelCall) {
                  _initializing = false;
              }
          }
          /**
           * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
           * {initializer} modifier, directly or indirectly.
           */
          modifier onlyInitializing() {
              require(_initializing, "Initializable: contract is not initializing");
              _;
          }
          function _isConstructor() private view returns (bool) {
              return !AddressUpgradeable.isContract(address(this));
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Interface of the ERC165 standard, as defined in the
       * https://eips.ethereum.org/EIPS/eip-165[EIP].
       *
       * Implementers can declare support of contract interfaces, which can then be
       * queried by others ({ERC165Checker}).
       *
       * For an implementation, see {ERC165}.
       */
      interface IERC165 {
          /**
           * @dev Returns true if this contract implements the interface defined by
           * `interfaceId`. See the corresponding
           * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
           * to learn more about how these ids are created.
           *
           * This function call must use less than 30 000 gas.
           */
          function supportsInterface(bytes4 interfaceId) external view returns (bool);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
      pragma solidity ^0.8.1;
      /**
       * @dev Collection of functions related to the address type
       */
      library AddressUpgradeable {
          /**
           * @dev Returns true if `account` is a contract.
           *
           * [IMPORTANT]
           * ====
           * It is unsafe to assume that an address for which this function returns
           * false is an externally-owned account (EOA) and not a contract.
           *
           * Among others, `isContract` will return false for the following
           * types of addresses:
           *
           *  - an externally-owned account
           *  - a contract in construction
           *  - an address where a contract will be created
           *  - an address where a contract lived, but was destroyed
           * ====
           *
           * [IMPORTANT]
           * ====
           * You shouldn't rely on `isContract` to protect against flash loan attacks!
           *
           * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
           * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
           * constructor.
           * ====
           */
          function isContract(address account) internal view returns (bool) {
              // This method relies on extcodesize/address.code.length, which returns 0
              // for contracts in construction, since the code is only stored at the end
              // of the constructor execution.
              return account.code.length > 0;
          }
          /**
           * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
           * `recipient`, forwarding all available gas and reverting on errors.
           *
           * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
           * of certain opcodes, possibly making contracts go over the 2300 gas limit
           * imposed by `transfer`, making them unable to receive funds via
           * `transfer`. {sendValue} removes this limitation.
           *
           * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
           *
           * IMPORTANT: because control is transferred to `recipient`, care must be
           * taken to not create reentrancy vulnerabilities. Consider using
           * {ReentrancyGuard} or the
           * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
           */
          function sendValue(address payable recipient, uint256 amount) internal {
              require(address(this).balance >= amount, "Address: insufficient balance");
              (bool success, ) = recipient.call{value: amount}("");
              require(success, "Address: unable to send value, recipient may have reverted");
          }
          /**
           * @dev Performs a Solidity function call using a low level `call`. A
           * plain `call` is an unsafe replacement for a function call: use this
           * function instead.
           *
           * If `target` reverts with a revert reason, it is bubbled up by this
           * function (like regular Solidity function calls).
           *
           * Returns the raw returned data. To convert to the expected return value,
           * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
           *
           * Requirements:
           *
           * - `target` must be a contract.
           * - calling `target` with `data` must not revert.
           *
           * _Available since v3.1._
           */
          function functionCall(address target, bytes memory data) internal returns (bytes memory) {
              return functionCall(target, data, "Address: low-level call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
           * `errorMessage` as a fallback revert reason when `target` reverts.
           *
           * _Available since v3.1._
           */
          function functionCall(
              address target,
              bytes memory data,
              string memory errorMessage
          ) internal returns (bytes memory) {
              return functionCallWithValue(target, data, 0, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but also transferring `value` wei to `target`.
           *
           * Requirements:
           *
           * - the calling contract must have an ETH balance of at least `value`.
           * - the called Solidity function must be `payable`.
           *
           * _Available since v3.1._
           */
          function functionCallWithValue(
              address target,
              bytes memory data,
              uint256 value
          ) internal returns (bytes memory) {
              return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
          }
          /**
           * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
           * with `errorMessage` as a fallback revert reason when `target` reverts.
           *
           * _Available since v3.1._
           */
          function functionCallWithValue(
              address target,
              bytes memory data,
              uint256 value,
              string memory errorMessage
          ) internal returns (bytes memory) {
              require(address(this).balance >= value, "Address: insufficient balance for call");
              require(isContract(target), "Address: call to non-contract");
              (bool success, bytes memory returndata) = target.call{value: value}(data);
              return verifyCallResult(success, returndata, errorMessage);
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
           * but performing a static call.
           *
           * _Available since v3.3._
           */
          function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
              return functionStaticCall(target, data, "Address: low-level static call failed");
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
           * but performing a static call.
           *
           * _Available since v3.3._
           */
          function functionStaticCall(
              address target,
              bytes memory data,
              string memory errorMessage
          ) internal view returns (bytes memory) {
              require(isContract(target), "Address: static call to non-contract");
              (bool success, bytes memory returndata) = target.staticcall(data);
              return verifyCallResult(success, returndata, errorMessage);
          }
          /**
           * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
           * revert reason using the provided one.
           *
           * _Available since v4.3._
           */
          function verifyCallResult(
              bool success,
              bytes memory returndata,
              string memory errorMessage
          ) internal pure returns (bytes memory) {
              if (success) {
                  return returndata;
              } else {
                  // Look for revert reason and bubble it up if present
                  if (returndata.length > 0) {
                      // The easiest way to bubble the revert reason is using memory via assembly
                      assembly {
                          let returndata_size := mload(returndata)
                          revert(add(32, returndata), returndata_size)
                      }
                  } else {
                      revert(errorMessage);
                  }
              }
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      interface IENS {
          event NewOwner(bytes32 indexed node, bytes32 indexed label, address owner);
          event Transfer(bytes32 indexed node, address owner);
          event NewResolver(bytes32 indexed node, address resolver);
          event NewTTL(bytes32 indexed node, uint64 ttl);
          event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
          function setRecord(bytes32, address, address, uint64) external;
          function setSubnodeRecord(bytes32, bytes32, address, address, uint64) external;
          function setSubnodeOwner(bytes32, bytes32, address) external returns(bytes32);
          function setResolver(bytes32, address) external;
          function setOwner(bytes32, address) external;
          function setTTL(bytes32, uint64) external;
          function setApprovalForAll(address, bool) external;
          function owner(bytes32) external view returns (address);
          function resolver(bytes32) external view returns (address);
          function ttl(bytes32) external view returns (uint64);
          function recordExists(bytes32) external view returns (bool);
          function isApprovedForAll(address, address) external view returns (bool);
      }
      interface IReverseRegistrar {
          function ADDR_REVERSE_NODE() external view returns (bytes32);
          function ens() external view returns (IENS);
          function defaultResolver() external view returns (address);
          function claim(address) external returns (bytes32);
          function claimWithResolver(address, address) external returns (bytes32);
          function setName(string calldata) external returns (bytes32);
          function node(address) external pure returns (bytes32);
      }
      library ENSReverseRegistration {
          // namehash('addr.reverse')
          bytes32 internal constant ADDR_REVERSE_NODE = 0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;
          function setName(address ensregistry, string calldata ensname) internal {
              IReverseRegistrar(IENS(ensregistry).owner(ADDR_REVERSE_NODE)).setName(ensname);
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Votes.sol)
      pragma solidity ^0.8.0;
      import "./draft-ERC20PermitUpgradeable.sol";
      import "../../../utils/math/MathUpgradeable.sol";
      import "../../../governance/utils/IVotesUpgradeable.sol";
      import "../../../utils/math/SafeCastUpgradeable.sol";
      import "../../../utils/cryptography/ECDSAUpgradeable.sol";
      import "../../../proxy/utils/Initializable.sol";
      /**
       * @dev Extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound's,
       * and supports token supply up to 2^224^ - 1, while COMP is limited to 2^96^ - 1.
       *
       * NOTE: If exact COMP compatibility is required, use the {ERC20VotesComp} variant of this module.
       *
       * This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either
       * by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting
       * power can be queried through the public accessors {getVotes} and {getPastVotes}.
       *
       * By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
       * requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.
       *
       * _Available since v4.2._
       */
      abstract contract ERC20VotesUpgradeable is Initializable, IVotesUpgradeable, ERC20PermitUpgradeable {
          function __ERC20Votes_init() internal onlyInitializing {
          }
          function __ERC20Votes_init_unchained() internal onlyInitializing {
          }
          struct Checkpoint {
              uint32 fromBlock;
              uint224 votes;
          }
          bytes32 private constant _DELEGATION_TYPEHASH =
              keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
          mapping(address => address) private _delegates;
          mapping(address => Checkpoint[]) private _checkpoints;
          Checkpoint[] private _totalSupplyCheckpoints;
          /**
           * @dev Get the `pos`-th checkpoint for `account`.
           */
          function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoint memory) {
              return _checkpoints[account][pos];
          }
          /**
           * @dev Get number of checkpoints for `account`.
           */
          function numCheckpoints(address account) public view virtual returns (uint32) {
              return SafeCastUpgradeable.toUint32(_checkpoints[account].length);
          }
          /**
           * @dev Get the address `account` is currently delegating to.
           */
          function delegates(address account) public view virtual override returns (address) {
              return _delegates[account];
          }
          /**
           * @dev Gets the current votes balance for `account`
           */
          function getVotes(address account) public view virtual override returns (uint256) {
              uint256 pos = _checkpoints[account].length;
              return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes;
          }
          /**
           * @dev Retrieve the number of votes for `account` at the end of `blockNumber`.
           *
           * Requirements:
           *
           * - `blockNumber` must have been already mined
           */
          function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) {
              require(blockNumber < block.number, "ERC20Votes: block not yet mined");
              return _checkpointsLookup(_checkpoints[account], blockNumber);
          }
          /**
           * @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances.
           * It is but NOT the sum of all the delegated votes!
           *
           * Requirements:
           *
           * - `blockNumber` must have been already mined
           */
          function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256) {
              require(blockNumber < block.number, "ERC20Votes: block not yet mined");
              return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
          }
          /**
           * @dev Lookup a value in a list of (sorted) checkpoints.
           */
          function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 blockNumber) private view returns (uint256) {
              // We run a binary search to look for the earliest checkpoint taken after `blockNumber`.
              //
              // During the loop, the index of the wanted checkpoint remains in the range [low-1, high).
              // With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the invariant.
              // - If the middle checkpoint is after `blockNumber`, we look in [low, mid)
              // - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high)
              // Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not
              // out of bounds (in which case we're looking too far in the past and the result is 0).
              // Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is
              // past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out
              // the same.
              uint256 high = ckpts.length;
              uint256 low = 0;
              while (low < high) {
                  uint256 mid = MathUpgradeable.average(low, high);
                  if (ckpts[mid].fromBlock > blockNumber) {
                      high = mid;
                  } else {
                      low = mid + 1;
                  }
              }
              return high == 0 ? 0 : ckpts[high - 1].votes;
          }
          /**
           * @dev Delegate votes from the sender to `delegatee`.
           */
          function delegate(address delegatee) public virtual override {
              _delegate(_msgSender(), delegatee);
          }
          /**
           * @dev Delegates votes from signer to `delegatee`
           */
          function delegateBySig(
              address delegatee,
              uint256 nonce,
              uint256 expiry,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) public virtual override {
              require(block.timestamp <= expiry, "ERC20Votes: signature expired");
              address signer = ECDSAUpgradeable.recover(
                  _hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
                  v,
                  r,
                  s
              );
              require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
              _delegate(signer, delegatee);
          }
          /**
           * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1).
           */
          function _maxSupply() internal view virtual returns (uint224) {
              return type(uint224).max;
          }
          /**
           * @dev Snapshots the totalSupply after it has been increased.
           */
          function _mint(address account, uint256 amount) internal virtual override {
              super._mint(account, amount);
              require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes");
              _writeCheckpoint(_totalSupplyCheckpoints, _add, amount);
          }
          /**
           * @dev Snapshots the totalSupply after it has been decreased.
           */
          function _burn(address account, uint256 amount) internal virtual override {
              super._burn(account, amount);
              _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount);
          }
          /**
           * @dev Move voting power when tokens are transferred.
           *
           * Emits a {DelegateVotesChanged} event.
           */
          function _afterTokenTransfer(
              address from,
              address to,
              uint256 amount
          ) internal virtual override {
              super._afterTokenTransfer(from, to, amount);
              _moveVotingPower(delegates(from), delegates(to), amount);
          }
          /**
           * @dev Change delegation for `delegator` to `delegatee`.
           *
           * Emits events {DelegateChanged} and {DelegateVotesChanged}.
           */
          function _delegate(address delegator, address delegatee) internal virtual {
              address currentDelegate = delegates(delegator);
              uint256 delegatorBalance = balanceOf(delegator);
              _delegates[delegator] = delegatee;
              emit DelegateChanged(delegator, currentDelegate, delegatee);
              _moveVotingPower(currentDelegate, delegatee, delegatorBalance);
          }
          function _moveVotingPower(
              address src,
              address dst,
              uint256 amount
          ) private {
              if (src != dst && amount > 0) {
                  if (src != address(0)) {
                      (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount);
                      emit DelegateVotesChanged(src, oldWeight, newWeight);
                  }
                  if (dst != address(0)) {
                      (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount);
                      emit DelegateVotesChanged(dst, oldWeight, newWeight);
                  }
              }
          }
          function _writeCheckpoint(
              Checkpoint[] storage ckpts,
              function(uint256, uint256) view returns (uint256) op,
              uint256 delta
          ) private returns (uint256 oldWeight, uint256 newWeight) {
              uint256 pos = ckpts.length;
              oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes;
              newWeight = op(oldWeight, delta);
              if (pos > 0 && ckpts[pos - 1].fromBlock == block.number) {
                  ckpts[pos - 1].votes = SafeCastUpgradeable.toUint224(newWeight);
              } else {
                  ckpts.push(Checkpoint({fromBlock: SafeCastUpgradeable.toUint32(block.number), votes: SafeCastUpgradeable.toUint224(newWeight)}));
              }
          }
          function _add(uint256 a, uint256 b) private pure returns (uint256) {
              return a + b;
          }
          function _subtract(uint256 a, uint256 b) private pure returns (uint256) {
              return a - b;
          }
          /**
           * This empty reserved space is put in place to allow future versions to add new
           * variables without shifting down storage in the inheritance chain.
           * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
           */
          uint256[47] private __gap;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (utils/Multicall.sol)
      pragma solidity ^0.8.0;
      import "./AddressUpgradeable.sol";
      import "../proxy/utils/Initializable.sol";
      /**
       * @dev Provides a function to batch together multiple calls in a single external call.
       *
       * _Available since v4.1._
       */
      abstract contract MulticallUpgradeable is Initializable {
          function __Multicall_init() internal onlyInitializing {
          }
          function __Multicall_init_unchained() internal onlyInitializing {
          }
          /**
           * @dev Receives and executes a batch of function calls on this contract.
           */
          function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
              results = new bytes[](data.length);
              for (uint256 i = 0; i < data.length; i++) {
                  results[i] = _functionDelegateCall(address(this), data[i]);
              }
              return results;
          }
          /**
           * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
           * but performing a delegate call.
           *
           * _Available since v3.4._
           */
          function _functionDelegateCall(address target, bytes memory data) private returns (bytes memory) {
              require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract");
              // solhint-disable-next-line avoid-low-level-calls
              (bool success, bytes memory returndata) = target.delegatecall(data);
              return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed");
          }
          /**
           * This empty reserved space is put in place to allow future versions to add new
           * variables without shifting down storage in the inheritance chain.
           * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
           */
          uint256[50] private __gap;
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "./IERC1046.sol";
      /// @custom:security-contact [email protected]
      abstract contract ERC1046Upgradeable is IERC1046 {
          string public override tokenURI;
          function _setTokenURI(string calldata _tokenURI) internal {
              tokenURI = _tokenURI;
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
      import "./IERC1363.sol";
      /// @custom:security-contact [email protected]
      abstract contract ERC1363Upgradeable is IERC1363, ERC20Upgradeable {
          function transferAndCall(address to, uint256 value) public override returns (bool) {
              return transferAndCall(to, value, bytes(""));
          }
          function transferAndCall(address to, uint256 value, bytes memory data) public override returns (bool) {
              require(transfer(to, value));
              try IERC1363Receiver(to).onTransferReceived(_msgSender(), _msgSender(), value, data) returns (bytes4 selector) {
                  require(selector == IERC1363Receiver(to).onTransferReceived.selector, "ERC1363: onTransferReceived invalid result");
              } catch Error(string memory reason) {
                  revert(reason);
              } catch {
                  revert("ERC1363: onTransferReceived reverted without reason");
              }
              return true;
          }
          function transferFromAndCall(address from, address to, uint256 value) public override returns (bool) {
              return transferFromAndCall(from, to, value, bytes(""));
          }
          function transferFromAndCall(address from, address to, uint256 value, bytes memory data) public override returns (bool) {
              require(transferFrom(from, to, value));
              try IERC1363Receiver(to).onTransferReceived(_msgSender(), from, value, data) returns (bytes4 selector) {
                  require(selector == IERC1363Receiver(to).onTransferReceived.selector, "ERC1363: onTransferReceived invalid result");
              } catch Error(string memory reason) {
                  revert(reason);
              } catch {
                  revert("ERC1363: onTransferReceived reverted without reason");
              }
              return true;
          }
          function approveAndCall(address spender, uint256 value) public override returns (bool) {
              return approveAndCall(spender, value, bytes(""));
          }
          function approveAndCall(address spender, uint256 value, bytes memory data) public override returns (bool) {
              require(approve(spender, value));
              try IERC1363Spender(spender).onApprovalReceived(_msgSender(), value, data) returns (bytes4 selector) {
                  require(selector == IERC1363Spender(spender).onApprovalReceived.selector, "ERC1363: onApprovalReceived invalid result");
              } catch Error(string memory reason) {
                  revert(reason);
              } catch {
                  revert("ERC1363: onApprovalReceived reverted without reason");
              }
              return true;
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-ERC20Permit.sol)
      pragma solidity ^0.8.0;
      import "./draft-IERC20PermitUpgradeable.sol";
      import "../ERC20Upgradeable.sol";
      import "../../../utils/cryptography/draft-EIP712Upgradeable.sol";
      import "../../../utils/cryptography/ECDSAUpgradeable.sol";
      import "../../../utils/CountersUpgradeable.sol";
      import "../../../proxy/utils/Initializable.sol";
      /**
       * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
       * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
       *
       * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
       * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
       * need to send a transaction, and thus is not required to hold Ether at all.
       *
       * _Available since v3.4._
       */
      abstract contract ERC20PermitUpgradeable is Initializable, ERC20Upgradeable, IERC20PermitUpgradeable, EIP712Upgradeable {
          using CountersUpgradeable for CountersUpgradeable.Counter;
          mapping(address => CountersUpgradeable.Counter) private _nonces;
          // solhint-disable-next-line var-name-mixedcase
          bytes32 private _PERMIT_TYPEHASH;
          /**
           * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
           *
           * It's a good idea to use the same `name` that is defined as the ERC20 token name.
           */
          function __ERC20Permit_init(string memory name) internal onlyInitializing {
              __EIP712_init_unchained(name, "1");
              __ERC20Permit_init_unchained(name);
          }
          function __ERC20Permit_init_unchained(string memory) internal onlyInitializing {
              _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");}
          /**
           * @dev See {IERC20Permit-permit}.
           */
          function permit(
              address owner,
              address spender,
              uint256 value,
              uint256 deadline,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) public virtual override {
              require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
              bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
              bytes32 hash = _hashTypedDataV4(structHash);
              address signer = ECDSAUpgradeable.recover(hash, v, r, s);
              require(signer == owner, "ERC20Permit: invalid signature");
              _approve(owner, spender, value);
          }
          /**
           * @dev See {IERC20Permit-nonces}.
           */
          function nonces(address owner) public view virtual override returns (uint256) {
              return _nonces[owner].current();
          }
          /**
           * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
           */
          // solhint-disable-next-line func-name-mixedcase
          function DOMAIN_SEPARATOR() external view override returns (bytes32) {
              return _domainSeparatorV4();
          }
          /**
           * @dev "Consume a nonce": return the current value and increment.
           *
           * _Available since v4.1._
           */
          function _useNonce(address owner) internal virtual returns (uint256 current) {
              CountersUpgradeable.Counter storage nonce = _nonces[owner];
              current = nonce.current();
              nonce.increment();
          }
          /**
           * This empty reserved space is put in place to allow future versions to add new
           * variables without shifting down storage in the inheritance chain.
           * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
           */
          uint256[49] private __gap;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Standard math utilities missing in the Solidity language.
       */
      library MathUpgradeable {
          /**
           * @dev Returns the largest of two numbers.
           */
          function max(uint256 a, uint256 b) internal pure returns (uint256) {
              return a >= b ? a : b;
          }
          /**
           * @dev Returns the smallest of two numbers.
           */
          function min(uint256 a, uint256 b) internal pure returns (uint256) {
              return a < b ? a : b;
          }
          /**
           * @dev Returns the average of two numbers. The result is rounded towards
           * zero.
           */
          function average(uint256 a, uint256 b) internal pure returns (uint256) {
              // (a + b) / 2 can overflow.
              return (a & b) + (a ^ b) / 2;
          }
          /**
           * @dev Returns the ceiling of the division of two numbers.
           *
           * This differs from standard division with `/` in that it rounds up instead
           * of rounding down.
           */
          function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
              // (a + b - 1) / b can overflow on addition, so we distribute.
              return a / b + (a % b == 0 ? 0 : 1);
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (governance/utils/IVotes.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
       *
       * _Available since v4.5._
       */
      interface IVotesUpgradeable {
          /**
           * @dev Emitted when an account changes their delegate.
           */
          event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
          /**
           * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
           */
          event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
          /**
           * @dev Returns the current amount of votes that `account` has.
           */
          function getVotes(address account) external view returns (uint256);
          /**
           * @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`).
           */
          function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);
          /**
           * @dev Returns the total supply of votes available at the end of a past block (`blockNumber`).
           *
           * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
           * Votes that have not been delegated are still part of total supply, even though they would not participate in a
           * vote.
           */
          function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);
          /**
           * @dev Returns the delegate that `account` has chosen.
           */
          function delegates(address account) external view returns (address);
          /**
           * @dev Delegates votes from the sender to `delegatee`.
           */
          function delegate(address delegatee) external;
          /**
           * @dev Delegates votes from signer to `delegatee`.
           */
          function delegateBySig(
              address delegatee,
              uint256 nonce,
              uint256 expiry,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) external;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
       * checks.
       *
       * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
       * easily result in undesired exploitation or bugs, since developers usually
       * assume that overflows raise errors. `SafeCast` restores this intuition by
       * reverting the transaction when such an operation overflows.
       *
       * Using this library instead of the unchecked operations eliminates an entire
       * class of bugs, so it's recommended to use it always.
       *
       * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
       * all math on `uint256` and `int256` and then downcasting.
       */
      library SafeCastUpgradeable {
          /**
           * @dev Returns the downcasted uint224 from uint256, reverting on
           * overflow (when the input is greater than largest uint224).
           *
           * Counterpart to Solidity's `uint224` operator.
           *
           * Requirements:
           *
           * - input must fit into 224 bits
           */
          function toUint224(uint256 value) internal pure returns (uint224) {
              require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
              return uint224(value);
          }
          /**
           * @dev Returns the downcasted uint128 from uint256, reverting on
           * overflow (when the input is greater than largest uint128).
           *
           * Counterpart to Solidity's `uint128` operator.
           *
           * Requirements:
           *
           * - input must fit into 128 bits
           */
          function toUint128(uint256 value) internal pure returns (uint128) {
              require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
              return uint128(value);
          }
          /**
           * @dev Returns the downcasted uint96 from uint256, reverting on
           * overflow (when the input is greater than largest uint96).
           *
           * Counterpart to Solidity's `uint96` operator.
           *
           * Requirements:
           *
           * - input must fit into 96 bits
           */
          function toUint96(uint256 value) internal pure returns (uint96) {
              require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
              return uint96(value);
          }
          /**
           * @dev Returns the downcasted uint64 from uint256, reverting on
           * overflow (when the input is greater than largest uint64).
           *
           * Counterpart to Solidity's `uint64` operator.
           *
           * Requirements:
           *
           * - input must fit into 64 bits
           */
          function toUint64(uint256 value) internal pure returns (uint64) {
              require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
              return uint64(value);
          }
          /**
           * @dev Returns the downcasted uint32 from uint256, reverting on
           * overflow (when the input is greater than largest uint32).
           *
           * Counterpart to Solidity's `uint32` operator.
           *
           * Requirements:
           *
           * - input must fit into 32 bits
           */
          function toUint32(uint256 value) internal pure returns (uint32) {
              require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
              return uint32(value);
          }
          /**
           * @dev Returns the downcasted uint16 from uint256, reverting on
           * overflow (when the input is greater than largest uint16).
           *
           * Counterpart to Solidity's `uint16` operator.
           *
           * Requirements:
           *
           * - input must fit into 16 bits
           */
          function toUint16(uint256 value) internal pure returns (uint16) {
              require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
              return uint16(value);
          }
          /**
           * @dev Returns the downcasted uint8 from uint256, reverting on
           * overflow (when the input is greater than largest uint8).
           *
           * Counterpart to Solidity's `uint8` operator.
           *
           * Requirements:
           *
           * - input must fit into 8 bits.
           */
          function toUint8(uint256 value) internal pure returns (uint8) {
              require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
              return uint8(value);
          }
          /**
           * @dev Converts a signed int256 into an unsigned uint256.
           *
           * Requirements:
           *
           * - input must be greater than or equal to 0.
           */
          function toUint256(int256 value) internal pure returns (uint256) {
              require(value >= 0, "SafeCast: value must be positive");
              return uint256(value);
          }
          /**
           * @dev Returns the downcasted int128 from int256, reverting on
           * overflow (when the input is less than smallest int128 or
           * greater than largest int128).
           *
           * Counterpart to Solidity's `int128` operator.
           *
           * Requirements:
           *
           * - input must fit into 128 bits
           *
           * _Available since v3.1._
           */
          function toInt128(int256 value) internal pure returns (int128) {
              require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
              return int128(value);
          }
          /**
           * @dev Returns the downcasted int64 from int256, reverting on
           * overflow (when the input is less than smallest int64 or
           * greater than largest int64).
           *
           * Counterpart to Solidity's `int64` operator.
           *
           * Requirements:
           *
           * - input must fit into 64 bits
           *
           * _Available since v3.1._
           */
          function toInt64(int256 value) internal pure returns (int64) {
              require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
              return int64(value);
          }
          /**
           * @dev Returns the downcasted int32 from int256, reverting on
           * overflow (when the input is less than smallest int32 or
           * greater than largest int32).
           *
           * Counterpart to Solidity's `int32` operator.
           *
           * Requirements:
           *
           * - input must fit into 32 bits
           *
           * _Available since v3.1._
           */
          function toInt32(int256 value) internal pure returns (int32) {
              require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
              return int32(value);
          }
          /**
           * @dev Returns the downcasted int16 from int256, reverting on
           * overflow (when the input is less than smallest int16 or
           * greater than largest int16).
           *
           * Counterpart to Solidity's `int16` operator.
           *
           * Requirements:
           *
           * - input must fit into 16 bits
           *
           * _Available since v3.1._
           */
          function toInt16(int256 value) internal pure returns (int16) {
              require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
              return int16(value);
          }
          /**
           * @dev Returns the downcasted int8 from int256, reverting on
           * overflow (when the input is less than smallest int8 or
           * greater than largest int8).
           *
           * Counterpart to Solidity's `int8` operator.
           *
           * Requirements:
           *
           * - input must fit into 8 bits.
           *
           * _Available since v3.1._
           */
          function toInt8(int256 value) internal pure returns (int8) {
              require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
              return int8(value);
          }
          /**
           * @dev Converts an unsigned uint256 into a signed int256.
           *
           * Requirements:
           *
           * - input must be less than or equal to maxInt256.
           */
          function toInt256(uint256 value) internal pure returns (int256) {
              // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
              require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
              return int256(value);
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)
      pragma solidity ^0.8.0;
      import "../StringsUpgradeable.sol";
      /**
       * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
       *
       * These functions can be used to verify that a message was signed by the holder
       * of the private keys of a given address.
       */
      library ECDSAUpgradeable {
          enum RecoverError {
              NoError,
              InvalidSignature,
              InvalidSignatureLength,
              InvalidSignatureS,
              InvalidSignatureV
          }
          function _throwError(RecoverError error) private pure {
              if (error == RecoverError.NoError) {
                  return; // no error: do nothing
              } else if (error == RecoverError.InvalidSignature) {
                  revert("ECDSA: invalid signature");
              } else if (error == RecoverError.InvalidSignatureLength) {
                  revert("ECDSA: invalid signature length");
              } else if (error == RecoverError.InvalidSignatureS) {
                  revert("ECDSA: invalid signature 's' value");
              } else if (error == RecoverError.InvalidSignatureV) {
                  revert("ECDSA: invalid signature 'v' value");
              }
          }
          /**
           * @dev Returns the address that signed a hashed message (`hash`) with
           * `signature` or error string. This address can then be used for verification purposes.
           *
           * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
           * this function rejects them by requiring the `s` value to be in the lower
           * half order, and the `v` value to be either 27 or 28.
           *
           * IMPORTANT: `hash` _must_ be the result of a hash operation for the
           * verification to be secure: it is possible to craft signatures that
           * recover to arbitrary addresses for non-hashed data. A safe way to ensure
           * this is by receiving a hash of the original message (which may otherwise
           * be too long), and then calling {toEthSignedMessageHash} on it.
           *
           * Documentation for signature generation:
           * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
           * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
           *
           * _Available since v4.3._
           */
          function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
              // Check the signature length
              // - case 65: r,s,v signature (standard)
              // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
              if (signature.length == 65) {
                  bytes32 r;
                  bytes32 s;
                  uint8 v;
                  // ecrecover takes the signature parameters, and the only way to get them
                  // currently is to use assembly.
                  assembly {
                      r := mload(add(signature, 0x20))
                      s := mload(add(signature, 0x40))
                      v := byte(0, mload(add(signature, 0x60)))
                  }
                  return tryRecover(hash, v, r, s);
              } else if (signature.length == 64) {
                  bytes32 r;
                  bytes32 vs;
                  // ecrecover takes the signature parameters, and the only way to get them
                  // currently is to use assembly.
                  assembly {
                      r := mload(add(signature, 0x20))
                      vs := mload(add(signature, 0x40))
                  }
                  return tryRecover(hash, r, vs);
              } else {
                  return (address(0), RecoverError.InvalidSignatureLength);
              }
          }
          /**
           * @dev Returns the address that signed a hashed message (`hash`) with
           * `signature`. This address can then be used for verification purposes.
           *
           * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
           * this function rejects them by requiring the `s` value to be in the lower
           * half order, and the `v` value to be either 27 or 28.
           *
           * IMPORTANT: `hash` _must_ be the result of a hash operation for the
           * verification to be secure: it is possible to craft signatures that
           * recover to arbitrary addresses for non-hashed data. A safe way to ensure
           * this is by receiving a hash of the original message (which may otherwise
           * be too long), and then calling {toEthSignedMessageHash} on it.
           */
          function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
              (address recovered, RecoverError error) = tryRecover(hash, signature);
              _throwError(error);
              return recovered;
          }
          /**
           * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
           *
           * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
           *
           * _Available since v4.3._
           */
          function tryRecover(
              bytes32 hash,
              bytes32 r,
              bytes32 vs
          ) internal pure returns (address, RecoverError) {
              bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
              uint8 v = uint8((uint256(vs) >> 255) + 27);
              return tryRecover(hash, v, r, s);
          }
          /**
           * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
           *
           * _Available since v4.2._
           */
          function recover(
              bytes32 hash,
              bytes32 r,
              bytes32 vs
          ) internal pure returns (address) {
              (address recovered, RecoverError error) = tryRecover(hash, r, vs);
              _throwError(error);
              return recovered;
          }
          /**
           * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
           * `r` and `s` signature fields separately.
           *
           * _Available since v4.3._
           */
          function tryRecover(
              bytes32 hash,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) internal pure returns (address, RecoverError) {
              // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
              // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
              // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
              // signatures from current libraries generate a unique signature with an s-value in the lower half order.
              //
              // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
              // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
              // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
              // these malleable signatures as well.
              if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
                  return (address(0), RecoverError.InvalidSignatureS);
              }
              if (v != 27 && v != 28) {
                  return (address(0), RecoverError.InvalidSignatureV);
              }
              // If the signature is valid (and not malleable), return the signer address
              address signer = ecrecover(hash, v, r, s);
              if (signer == address(0)) {
                  return (address(0), RecoverError.InvalidSignature);
              }
              return (signer, RecoverError.NoError);
          }
          /**
           * @dev Overload of {ECDSA-recover} that receives the `v`,
           * `r` and `s` signature fields separately.
           */
          function recover(
              bytes32 hash,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) internal pure returns (address) {
              (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
              _throwError(error);
              return recovered;
          }
          /**
           * @dev Returns an Ethereum Signed Message, created from a `hash`. This
           * produces hash corresponding to the one signed with the
           * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
           * JSON-RPC method as part of EIP-191.
           *
           * See {recover}.
           */
          function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
              // 32 is the length in bytes of hash,
              // enforced by the type signature above
              return keccak256(abi.encodePacked("\\x19Ethereum Signed Message:\
      32", hash));
          }
          /**
           * @dev Returns an Ethereum Signed Message, created from `s`. This
           * produces hash corresponding to the one signed with the
           * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
           * JSON-RPC method as part of EIP-191.
           *
           * See {recover}.
           */
          function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
              return keccak256(abi.encodePacked("\\x19Ethereum Signed Message:\
      ", StringsUpgradeable.toString(s.length), s));
          }
          /**
           * @dev Returns an Ethereum Signed Typed Data, created from a
           * `domainSeparator` and a `structHash`. This produces hash corresponding
           * to the one signed with the
           * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
           * JSON-RPC method as part of EIP-712.
           *
           * See {recover}.
           */
          function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
              return keccak256(abi.encodePacked("\\x19\\x01", domainSeparator, structHash));
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
       * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
       *
       * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
       * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
       * need to send a transaction, and thus is not required to hold Ether at all.
       */
      interface IERC20PermitUpgradeable {
          /**
           * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
           * given ``owner``'s signed approval.
           *
           * IMPORTANT: The same issues {IERC20-approve} has related to transaction
           * ordering also apply here.
           *
           * Emits an {Approval} event.
           *
           * Requirements:
           *
           * - `spender` cannot be the zero address.
           * - `deadline` must be a timestamp in the future.
           * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
           * over the EIP712-formatted function arguments.
           * - the signature must use ``owner``'s current nonce (see {nonces}).
           *
           * For more information on the signature format, see the
           * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
           * section].
           */
          function permit(
              address owner,
              address spender,
              uint256 value,
              uint256 deadline,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) external;
          /**
           * @dev Returns the current nonce for `owner`. This value must be
           * included whenever a signature is generated for {permit}.
           *
           * Every successful call to {permit} increases ``owner``'s nonce by one. This
           * prevents a signature from being used multiple times.
           */
          function nonces(address owner) external view returns (uint256);
          /**
           * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
           */
          // solhint-disable-next-line func-name-mixedcase
          function DOMAIN_SEPARATOR() external view returns (bytes32);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)
      pragma solidity ^0.8.0;
      import "./IERC20Upgradeable.sol";
      import "./extensions/IERC20MetadataUpgradeable.sol";
      import "../../utils/ContextUpgradeable.sol";
      import "../../proxy/utils/Initializable.sol";
      /**
       * @dev Implementation of the {IERC20} interface.
       *
       * This implementation is agnostic to the way tokens are created. This means
       * that a supply mechanism has to be added in a derived contract using {_mint}.
       * For a generic mechanism see {ERC20PresetMinterPauser}.
       *
       * TIP: For a detailed writeup see our guide
       * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
       * to implement supply mechanisms].
       *
       * We have followed general OpenZeppelin Contracts guidelines: functions revert
       * instead returning `false` on failure. This behavior is nonetheless
       * conventional and does not conflict with the expectations of ERC20
       * applications.
       *
       * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
       * This allows applications to reconstruct the allowance for all accounts just
       * by listening to said events. Other implementations of the EIP may not emit
       * these events, as it isn't required by the specification.
       *
       * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
       * functions have been added to mitigate the well-known issues around setting
       * allowances. See {IERC20-approve}.
       */
      contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
          mapping(address => uint256) private _balances;
          mapping(address => mapping(address => uint256)) private _allowances;
          uint256 private _totalSupply;
          string private _name;
          string private _symbol;
          /**
           * @dev Sets the values for {name} and {symbol}.
           *
           * The default value of {decimals} is 18. To select a different value for
           * {decimals} you should overload it.
           *
           * All two of these values are immutable: they can only be set once during
           * construction.
           */
          function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
              __ERC20_init_unchained(name_, symbol_);
          }
          function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
              _name = name_;
              _symbol = symbol_;
          }
          /**
           * @dev Returns the name of the token.
           */
          function name() public view virtual override returns (string memory) {
              return _name;
          }
          /**
           * @dev Returns the symbol of the token, usually a shorter version of the
           * name.
           */
          function symbol() public view virtual override returns (string memory) {
              return _symbol;
          }
          /**
           * @dev Returns the number of decimals used to get its user representation.
           * For example, if `decimals` equals `2`, a balance of `505` tokens should
           * be displayed to a user as `5.05` (`505 / 10 ** 2`).
           *
           * Tokens usually opt for a value of 18, imitating the relationship between
           * Ether and Wei. This is the value {ERC20} uses, unless this function is
           * overridden;
           *
           * NOTE: This information is only used for _display_ purposes: it in
           * no way affects any of the arithmetic of the contract, including
           * {IERC20-balanceOf} and {IERC20-transfer}.
           */
          function decimals() public view virtual override returns (uint8) {
              return 18;
          }
          /**
           * @dev See {IERC20-totalSupply}.
           */
          function totalSupply() public view virtual override returns (uint256) {
              return _totalSupply;
          }
          /**
           * @dev See {IERC20-balanceOf}.
           */
          function balanceOf(address account) public view virtual override returns (uint256) {
              return _balances[account];
          }
          /**
           * @dev See {IERC20-transfer}.
           *
           * Requirements:
           *
           * - `to` cannot be the zero address.
           * - the caller must have a balance of at least `amount`.
           */
          function transfer(address to, uint256 amount) public virtual override returns (bool) {
              address owner = _msgSender();
              _transfer(owner, to, amount);
              return true;
          }
          /**
           * @dev See {IERC20-allowance}.
           */
          function allowance(address owner, address spender) public view virtual override returns (uint256) {
              return _allowances[owner][spender];
          }
          /**
           * @dev See {IERC20-approve}.
           *
           * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
           * `transferFrom`. This is semantically equivalent to an infinite approval.
           *
           * Requirements:
           *
           * - `spender` cannot be the zero address.
           */
          function approve(address spender, uint256 amount) public virtual override returns (bool) {
              address owner = _msgSender();
              _approve(owner, spender, amount);
              return true;
          }
          /**
           * @dev See {IERC20-transferFrom}.
           *
           * Emits an {Approval} event indicating the updated allowance. This is not
           * required by the EIP. See the note at the beginning of {ERC20}.
           *
           * NOTE: Does not update the allowance if the current allowance
           * is the maximum `uint256`.
           *
           * Requirements:
           *
           * - `from` and `to` cannot be the zero address.
           * - `from` must have a balance of at least `amount`.
           * - the caller must have allowance for ``from``'s tokens of at least
           * `amount`.
           */
          function transferFrom(
              address from,
              address to,
              uint256 amount
          ) public virtual override returns (bool) {
              address spender = _msgSender();
              _spendAllowance(from, spender, amount);
              _transfer(from, to, amount);
              return true;
          }
          /**
           * @dev Atomically increases the allowance granted to `spender` by the caller.
           *
           * This is an alternative to {approve} that can be used as a mitigation for
           * problems described in {IERC20-approve}.
           *
           * Emits an {Approval} event indicating the updated allowance.
           *
           * Requirements:
           *
           * - `spender` cannot be the zero address.
           */
          function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
              address owner = _msgSender();
              _approve(owner, spender, _allowances[owner][spender] + addedValue);
              return true;
          }
          /**
           * @dev Atomically decreases the allowance granted to `spender` by the caller.
           *
           * This is an alternative to {approve} that can be used as a mitigation for
           * problems described in {IERC20-approve}.
           *
           * Emits an {Approval} event indicating the updated allowance.
           *
           * Requirements:
           *
           * - `spender` cannot be the zero address.
           * - `spender` must have allowance for the caller of at least
           * `subtractedValue`.
           */
          function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
              address owner = _msgSender();
              uint256 currentAllowance = _allowances[owner][spender];
              require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
              unchecked {
                  _approve(owner, spender, currentAllowance - subtractedValue);
              }
              return true;
          }
          /**
           * @dev Moves `amount` of tokens from `sender` to `recipient`.
           *
           * This internal function is equivalent to {transfer}, and can be used to
           * e.g. implement automatic token fees, slashing mechanisms, etc.
           *
           * Emits a {Transfer} event.
           *
           * Requirements:
           *
           * - `from` cannot be the zero address.
           * - `to` cannot be the zero address.
           * - `from` must have a balance of at least `amount`.
           */
          function _transfer(
              address from,
              address to,
              uint256 amount
          ) internal virtual {
              require(from != address(0), "ERC20: transfer from the zero address");
              require(to != address(0), "ERC20: transfer to the zero address");
              _beforeTokenTransfer(from, to, amount);
              uint256 fromBalance = _balances[from];
              require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
              unchecked {
                  _balances[from] = fromBalance - amount;
              }
              _balances[to] += amount;
              emit Transfer(from, to, amount);
              _afterTokenTransfer(from, to, amount);
          }
          /** @dev Creates `amount` tokens and assigns them to `account`, increasing
           * the total supply.
           *
           * Emits a {Transfer} event with `from` set to the zero address.
           *
           * Requirements:
           *
           * - `account` cannot be the zero address.
           */
          function _mint(address account, uint256 amount) internal virtual {
              require(account != address(0), "ERC20: mint to the zero address");
              _beforeTokenTransfer(address(0), account, amount);
              _totalSupply += amount;
              _balances[account] += amount;
              emit Transfer(address(0), account, amount);
              _afterTokenTransfer(address(0), account, amount);
          }
          /**
           * @dev Destroys `amount` tokens from `account`, reducing the
           * total supply.
           *
           * Emits a {Transfer} event with `to` set to the zero address.
           *
           * Requirements:
           *
           * - `account` cannot be the zero address.
           * - `account` must have at least `amount` tokens.
           */
          function _burn(address account, uint256 amount) internal virtual {
              require(account != address(0), "ERC20: burn from the zero address");
              _beforeTokenTransfer(account, address(0), amount);
              uint256 accountBalance = _balances[account];
              require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
              unchecked {
                  _balances[account] = accountBalance - amount;
              }
              _totalSupply -= amount;
              emit Transfer(account, address(0), amount);
              _afterTokenTransfer(account, address(0), amount);
          }
          /**
           * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
           *
           * This internal function is equivalent to `approve`, and can be used to
           * e.g. set automatic allowances for certain subsystems, etc.
           *
           * Emits an {Approval} event.
           *
           * Requirements:
           *
           * - `owner` cannot be the zero address.
           * - `spender` cannot be the zero address.
           */
          function _approve(
              address owner,
              address spender,
              uint256 amount
          ) internal virtual {
              require(owner != address(0), "ERC20: approve from the zero address");
              require(spender != address(0), "ERC20: approve to the zero address");
              _allowances[owner][spender] = amount;
              emit Approval(owner, spender, amount);
          }
          /**
           * @dev Spend `amount` form the allowance of `owner` toward `spender`.
           *
           * Does not update the allowance amount in case of infinite allowance.
           * Revert if not enough allowance is available.
           *
           * Might emit an {Approval} event.
           */
          function _spendAllowance(
              address owner,
              address spender,
              uint256 amount
          ) internal virtual {
              uint256 currentAllowance = allowance(owner, spender);
              if (currentAllowance != type(uint256).max) {
                  require(currentAllowance >= amount, "ERC20: insufficient allowance");
                  unchecked {
                      _approve(owner, spender, currentAllowance - amount);
                  }
              }
          }
          /**
           * @dev Hook that is called before any transfer of tokens. This includes
           * minting and burning.
           *
           * Calling conditions:
           *
           * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
           * will be transferred to `to`.
           * - when `from` is zero, `amount` tokens will be minted for `to`.
           * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
           * - `from` and `to` are never both zero.
           *
           * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
           */
          function _beforeTokenTransfer(
              address from,
              address to,
              uint256 amount
          ) internal virtual {}
          /**
           * @dev Hook that is called after any transfer of tokens. This includes
           * minting and burning.
           *
           * Calling conditions:
           *
           * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
           * has been transferred to `to`.
           * - when `from` is zero, `amount` tokens have been minted for `to`.
           * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
           * - `from` and `to` are never both zero.
           *
           * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
           */
          function _afterTokenTransfer(
              address from,
              address to,
              uint256 amount
          ) internal virtual {}
          /**
           * This empty reserved space is put in place to allow future versions to add new
           * variables without shifting down storage in the inheritance chain.
           * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
           */
          uint256[45] private __gap;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/cryptography/draft-EIP712.sol)
      pragma solidity ^0.8.0;
      import "./ECDSAUpgradeable.sol";
      import "../../proxy/utils/Initializable.sol";
      /**
       * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
       *
       * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
       * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
       * they need in their contracts using a combination of `abi.encode` and `keccak256`.
       *
       * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
       * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
       * ({_hashTypedDataV4}).
       *
       * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
       * the chain id to protect against replay attacks on an eventual fork of the chain.
       *
       * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
       * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
       *
       * _Available since v3.4._
       */
      abstract contract EIP712Upgradeable is Initializable {
          /* solhint-disable var-name-mixedcase */
          bytes32 private _HASHED_NAME;
          bytes32 private _HASHED_VERSION;
          bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
          /* solhint-enable var-name-mixedcase */
          /**
           * @dev Initializes the domain separator and parameter caches.
           *
           * The meaning of `name` and `version` is specified in
           * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
           *
           * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
           * - `version`: the current major version of the signing domain.
           *
           * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
           * contract upgrade].
           */
          function __EIP712_init(string memory name, string memory version) internal onlyInitializing {
              __EIP712_init_unchained(name, version);
          }
          function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing {
              bytes32 hashedName = keccak256(bytes(name));
              bytes32 hashedVersion = keccak256(bytes(version));
              _HASHED_NAME = hashedName;
              _HASHED_VERSION = hashedVersion;
          }
          /**
           * @dev Returns the domain separator for the current chain.
           */
          function _domainSeparatorV4() internal view returns (bytes32) {
              return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash());
          }
          function _buildDomainSeparator(
              bytes32 typeHash,
              bytes32 nameHash,
              bytes32 versionHash
          ) private view returns (bytes32) {
              return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
          }
          /**
           * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
           * function returns the hash of the fully encoded EIP712 message for this domain.
           *
           * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
           *
           * ```solidity
           * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
           *     keccak256("Mail(address to,string contents)"),
           *     mailTo,
           *     keccak256(bytes(mailContents))
           * )));
           * address signer = ECDSA.recover(digest, signature);
           * ```
           */
          function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
              return ECDSAUpgradeable.toTypedDataHash(_domainSeparatorV4(), structHash);
          }
          /**
           * @dev The hash of the name parameter for the EIP712 domain.
           *
           * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
           * are a concern.
           */
          function _EIP712NameHash() internal virtual view returns (bytes32) {
              return _HASHED_NAME;
          }
          /**
           * @dev The hash of the version parameter for the EIP712 domain.
           *
           * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
           * are a concern.
           */
          function _EIP712VersionHash() internal virtual view returns (bytes32) {
              return _HASHED_VERSION;
          }
          /**
           * This empty reserved space is put in place to allow future versions to add new
           * variables without shifting down storage in the inheritance chain.
           * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
           */
          uint256[50] private __gap;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
      pragma solidity ^0.8.0;
      /**
       * @title Counters
       * @author Matt Condon (@shrugs)
       * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
       * of elements in a mapping, issuing ERC721 ids, or counting request ids.
       *
       * Include with `using Counters for Counters.Counter;`
       */
      library CountersUpgradeable {
          struct Counter {
              // This variable should never be directly accessed by users of the library: interactions must be restricted to
              // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
              // this feature: see https://github.com/ethereum/solidity/issues/4637
              uint256 _value; // default: 0
          }
          function current(Counter storage counter) internal view returns (uint256) {
              return counter._value;
          }
          function increment(Counter storage counter) internal {
              unchecked {
                  counter._value += 1;
              }
          }
          function decrement(Counter storage counter) internal {
              uint256 value = counter._value;
              require(value > 0, "Counter: decrement overflow");
              unchecked {
                  counter._value = value - 1;
              }
          }
          function reset(Counter storage counter) internal {
              counter._value = 0;
          }
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Interface of the ERC20 standard as defined in the EIP.
       */
      interface IERC20Upgradeable {
          /**
           * @dev Returns the amount of tokens in existence.
           */
          function totalSupply() external view returns (uint256);
          /**
           * @dev Returns the amount of tokens owned by `account`.
           */
          function balanceOf(address account) external view returns (uint256);
          /**
           * @dev Moves `amount` tokens from the caller's account to `to`.
           *
           * Returns a boolean value indicating whether the operation succeeded.
           *
           * Emits a {Transfer} event.
           */
          function transfer(address to, uint256 amount) external returns (bool);
          /**
           * @dev Returns the remaining number of tokens that `spender` will be
           * allowed to spend on behalf of `owner` through {transferFrom}. This is
           * zero by default.
           *
           * This value changes when {approve} or {transferFrom} are called.
           */
          function allowance(address owner, address spender) external view returns (uint256);
          /**
           * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
           *
           * Returns a boolean value indicating whether the operation succeeded.
           *
           * IMPORTANT: Beware that changing an allowance with this method brings the risk
           * that someone may use both the old and the new allowance by unfortunate
           * transaction ordering. One possible solution to mitigate this race
           * condition is to first reduce the spender's allowance to 0 and set the
           * desired value afterwards:
           * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
           *
           * Emits an {Approval} event.
           */
          function approve(address spender, uint256 amount) external returns (bool);
          /**
           * @dev Moves `amount` tokens from `from` to `to` using the
           * allowance mechanism. `amount` is then deducted from the caller's
           * allowance.
           *
           * Returns a boolean value indicating whether the operation succeeded.
           *
           * Emits a {Transfer} event.
           */
          function transferFrom(
              address from,
              address to,
              uint256 amount
          ) external returns (bool);
          /**
           * @dev Emitted when `value` tokens are moved from one account (`from`) to
           * another (`to`).
           *
           * Note that `value` may be zero.
           */
          event Transfer(address indexed from, address indexed to, uint256 value);
          /**
           * @dev Emitted when the allowance of a `spender` for an `owner` is set by
           * a call to {approve}. `value` is the new allowance.
           */
          event Approval(address indexed owner, address indexed spender, uint256 value);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
      pragma solidity ^0.8.0;
      import "../IERC20Upgradeable.sol";
      /**
       * @dev Interface for the optional metadata functions from the ERC20 standard.
       *
       * _Available since v4.1._
       */
      interface IERC20MetadataUpgradeable is IERC20Upgradeable {
          /**
           * @dev Returns the name of the token.
           */
          function name() external view returns (string memory);
          /**
           * @dev Returns the symbol of the token.
           */
          function symbol() external view returns (string memory);
          /**
           * @dev Returns the decimals places of the token.
           */
          function decimals() external view returns (uint8);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
      pragma solidity ^0.8.0;
      import "../proxy/utils/Initializable.sol";
      /**
       * @dev Provides information about the current execution context, including the
       * sender of the transaction and its data. While these are generally available
       * via msg.sender and msg.data, they should not be accessed in such a direct
       * manner, since when dealing with meta-transactions the account sending and
       * paying for execution may not be the actual sender (as far as an application
       * is concerned).
       *
       * This contract is only required for intermediate, library-like contracts.
       */
      abstract contract ContextUpgradeable is Initializable {
          function __Context_init() internal onlyInitializing {
          }
          function __Context_init_unchained() internal onlyInitializing {
          }
          function _msgSender() internal view virtual returns (address) {
              return msg.sender;
          }
          function _msgData() internal view virtual returns (bytes calldata) {
              return msg.data;
          }
          /**
           * This empty reserved space is put in place to allow future versions to add new
           * variables without shifting down storage in the inheritance chain.
           * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
           */
          uint256[50] private __gap;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev String operations.
       */
      library StringsUpgradeable {
          bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
          /**
           * @dev Converts a `uint256` to its ASCII `string` decimal representation.
           */
          function toString(uint256 value) internal pure returns (string memory) {
              // Inspired by OraclizeAPI's implementation - MIT licence
              // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
              if (value == 0) {
                  return "0";
              }
              uint256 temp = value;
              uint256 digits;
              while (temp != 0) {
                  digits++;
                  temp /= 10;
              }
              bytes memory buffer = new bytes(digits);
              while (value != 0) {
                  digits -= 1;
                  buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
                  value /= 10;
              }
              return string(buffer);
          }
          /**
           * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
           */
          function toHexString(uint256 value) internal pure returns (string memory) {
              if (value == 0) {
                  return "0x00";
              }
              uint256 temp = value;
              uint256 length = 0;
              while (temp != 0) {
                  length++;
                  temp >>= 8;
              }
              return toHexString(value, length);
          }
          /**
           * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
           */
          function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
              bytes memory buffer = new bytes(2 * length + 2);
              buffer[0] = "0";
              buffer[1] = "x";
              for (uint256 i = 2 * length + 1; i > 1; --i) {
                  buffer[i] = _HEX_SYMBOLS[value & 0xf];
                  value >>= 4;
              }
              require(value == 0, "Strings: hex length insufficient");
              return string(buffer);
          }
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      interface IERC1046 {
          function tokenURI() external view returns (string memory);
      }
      // SPDX-License-Identifier: MIT
      pragma solidity ^0.8.0;
      interface IERC1363 {
          /*
          * Note: the ERC-165 identifier for this interface is 0x4bbee2df.
          * 0x4bbee2df ===
          *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
          *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
          *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
          *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)'))
          */
          /*
           * Note: the ERC-165 identifier for this interface is 0xfb9ec8ce.
           * 0xfb9ec8ce ===
           *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
           *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
           */
          /**
           * @notice Transfer tokens from `msg.sender` to another address and then call `onTransferReceived` on receiver
           * @param to address The address which you want to transfer to
           * @param value uint256 The amount of tokens to be transferred
           * @return true unless throwing
           */
          function transferAndCall(address to, uint256 value) external returns (bool);
          /**
           * @notice Transfer tokens from `msg.sender` to another address and then call `onTransferReceived` on receiver
           * @param to address The address which you want to transfer to
           * @param value uint256 The amount of tokens to be transferred
           * @param data bytes Additional data with no specified format, sent in call to `to`
           * @return true unless throwing
           */
          function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
          /**
           * @notice Transfer tokens from one address to another and then call `onTransferReceived` on receiver
           * @param from address The address which you want to send tokens from
           * @param to address The address which you want to transfer to
           * @param value uint256 The amount of tokens to be transferred
           * @return true unless throwing
           */
          function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
          /**
           * @notice Transfer tokens from one address to another and then call `onTransferReceived` on receiver
           * @param from address The address which you want to send tokens from
           * @param to address The address which you want to transfer to
           * @param value uint256 The amount of tokens to be transferred
           * @param data bytes Additional data with no specified format, sent in call to `to`
           * @return true unless throwing
           */
          function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
          /**
           * @notice Approve the passed address to spend the specified amount of tokens on behalf of msg.sender
           * and then call `onApprovalReceived` on spender.
           * @param spender address The address which will spend the funds
           * @param value uint256 The amount of tokens to be spent
           */
          function approveAndCall(address spender, uint256 value) external returns (bool);
          /**
           * @notice Approve the passed address to spend the specified amount of tokens on behalf of msg.sender
           * and then call `onApprovalReceived` on spender.
           * @param spender address The address which will spend the funds
           * @param value uint256 The amount of tokens to be spent
           * @param data bytes Additional data with no specified format, sent in call to `spender`
           */
          function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
      }
      /**
       * @title ERC1363Spender interface
       * @dev Interface for any contract that wants to support `approveAndCall`
       *  from ERC1363 token contracts.
       */
      interface IERC1363Spender {
          /*
           * Note: the ERC-165 identifier for this interface is 0x7b04a2d0.
           * 0x7b04a2d0 === bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))
           */
          /**
           * @notice Handle the approval of ERC1363 tokens
           * @dev Any ERC1363 smart contract calls this function on the recipient
           * after an `approve`. This function MAY throw to revert and reject the
           * approval. Return of other than the magic value MUST result in the
           * transaction being reverted.
           * Note: the token contract address is always the message sender.
           * @param owner address The address which called `approveAndCall` function
           * @param value uint256 The amount of tokens to be spent
           * @param data bytes Additional data with no specified format
           * @return `bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))`
           *  unless throwing
           */
          function onApprovalReceived(address owner, uint256 value, bytes calldata data) external returns (bytes4);
      }
      /**
       * @title ERC1363Receiver interface
       * @dev Interface for any contract that wants to support `transferAndCall` or `transferFromAndCall`
       *  from ERC1363 token contracts.
       */
      interface IERC1363Receiver {
          /*
           * Note: the ERC-165 identifier for this interface is 0x88a7ca5c.
           * 0x88a7ca5c === bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))
           */
          /**
           * @notice Handle the receipt of ERC1363 tokens
           * @dev Any ERC1363 smart contract calls this function on the recipient
           * after a `transfer` or a `transferFrom`. This function MAY throw to revert and reject the
           * transfer. Return of other than the magic value MUST result in the
           * transaction being reverted.
           * Note: the token contract address is always the message sender.
           * @param operator address The address which called `transferAndCall` or `transferFromAndCall` function
           * @param from address The address which are token transferred from
           * @param value uint256 The amount of tokens transferred
           * @param data bytes Additional data with no specified format
           * @return `bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))`
           *  unless throwing
           */
          function onTransferReceived(address operator, address from, uint256 value, bytes calldata data) external returns (bytes4);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)
      pragma solidity ^0.8.0;
      import "../token/ERC20/IERC20.sol";
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (interfaces/draft-IERC2612.sol)
      pragma solidity ^0.8.0;
      import "../token/ERC20/extensions/draft-IERC20Permit.sol";
      interface IERC2612 is IERC20Permit {}
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (governance/utils/IVotes.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
       *
       * _Available since v4.5._
       */
      interface IVotes {
          /**
           * @dev Emitted when an account changes their delegate.
           */
          event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
          /**
           * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
           */
          event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
          /**
           * @dev Returns the current amount of votes that `account` has.
           */
          function getVotes(address account) external view returns (uint256);
          /**
           * @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`).
           */
          function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);
          /**
           * @dev Returns the total supply of votes available at the end of a past block (`blockNumber`).
           *
           * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
           * Votes that have not been delegated are still part of total supply, even though they would not participate in a
           * vote.
           */
          function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);
          /**
           * @dev Returns the delegate that `account` has chosen.
           */
          function delegates(address account) external view returns (address);
          /**
           * @dev Delegates votes from the sender to `delegatee`.
           */
          function delegate(address delegatee) external;
          /**
           * @dev Delegates votes from signer to `delegatee`.
           */
          function delegateBySig(
              address delegatee,
              uint256 nonce,
              uint256 expiry,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) external;
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Interface of the ERC20 standard as defined in the EIP.
       */
      interface IERC20 {
          /**
           * @dev Returns the amount of tokens in existence.
           */
          function totalSupply() external view returns (uint256);
          /**
           * @dev Returns the amount of tokens owned by `account`.
           */
          function balanceOf(address account) external view returns (uint256);
          /**
           * @dev Moves `amount` tokens from the caller's account to `to`.
           *
           * Returns a boolean value indicating whether the operation succeeded.
           *
           * Emits a {Transfer} event.
           */
          function transfer(address to, uint256 amount) external returns (bool);
          /**
           * @dev Returns the remaining number of tokens that `spender` will be
           * allowed to spend on behalf of `owner` through {transferFrom}. This is
           * zero by default.
           *
           * This value changes when {approve} or {transferFrom} are called.
           */
          function allowance(address owner, address spender) external view returns (uint256);
          /**
           * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
           *
           * Returns a boolean value indicating whether the operation succeeded.
           *
           * IMPORTANT: Beware that changing an allowance with this method brings the risk
           * that someone may use both the old and the new allowance by unfortunate
           * transaction ordering. One possible solution to mitigate this race
           * condition is to first reduce the spender's allowance to 0 and set the
           * desired value afterwards:
           * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
           *
           * Emits an {Approval} event.
           */
          function approve(address spender, uint256 amount) external returns (bool);
          /**
           * @dev Moves `amount` tokens from `from` to `to` using the
           * allowance mechanism. `amount` is then deducted from the caller's
           * allowance.
           *
           * Returns a boolean value indicating whether the operation succeeded.
           *
           * Emits a {Transfer} event.
           */
          function transferFrom(
              address from,
              address to,
              uint256 amount
          ) external returns (bool);
          /**
           * @dev Emitted when `value` tokens are moved from one account (`from`) to
           * another (`to`).
           *
           * Note that `value` may be zero.
           */
          event Transfer(address indexed from, address indexed to, uint256 value);
          /**
           * @dev Emitted when the allowance of a `spender` for an `owner` is set by
           * a call to {approve}. `value` is the new allowance.
           */
          event Approval(address indexed owner, address indexed spender, uint256 value);
      }
      // SPDX-License-Identifier: MIT
      // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
      pragma solidity ^0.8.0;
      /**
       * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
       * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
       *
       * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
       * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
       * need to send a transaction, and thus is not required to hold Ether at all.
       */
      interface IERC20Permit {
          /**
           * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
           * given ``owner``'s signed approval.
           *
           * IMPORTANT: The same issues {IERC20-approve} has related to transaction
           * ordering also apply here.
           *
           * Emits an {Approval} event.
           *
           * Requirements:
           *
           * - `spender` cannot be the zero address.
           * - `deadline` must be a timestamp in the future.
           * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
           * over the EIP712-formatted function arguments.
           * - the signature must use ``owner``'s current nonce (see {nonces}).
           *
           * For more information on the signature format, see the
           * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
           * section].
           */
          function permit(
              address owner,
              address spender,
              uint256 value,
              uint256 deadline,
              uint8 v,
              bytes32 r,
              bytes32 s
          ) external;
          /**
           * @dev Returns the current nonce for `owner`. This value must be
           * included whenever a signature is generated for {permit}.
           *
           * Every successful call to {permit} increases ``owner``'s nonce by one. This
           * prevents a signature from being used multiple times.
           */
          function nonces(address owner) external view returns (uint256);
          /**
           * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
           */
          // solhint-disable-next-line func-name-mixedcase
          function DOMAIN_SEPARATOR() external view returns (bytes32);
      }