creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/interfaces/IERC5267.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.0;\n\ninterface IERC5267 {\n    /**\n     * @dev MAY be emitted to signal that the domain could have changed.\n     */\n    event EIP712DomainChanged();\n\n    /**\n     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n     * signature.\n     */\n    function eip712Domain()\n        external\n        view\n        returns (\n            bytes1 fields,\n            string memory name,\n            string memory version,\n            uint256 chainId,\n            address verifyingContract,\n            bytes32 salt,\n            uint256[] memory extensions\n        );\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/ERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n    mapping(address => uint256) private _balances;\n\n    mapping(address => mapping(address => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}.\n     *\n     * All two of these values are immutable: they can only be set once during\n     * construction.\n     */\n    constructor(string memory name_, string memory symbol_) {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual override returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual override returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the default value returned by this function, unless\n     * it's overridden.\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual override returns (uint8) {\n        return 18;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address to, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _transfer(owner, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n     * `transferFrom`. This is semantically equivalent to an infinite approval.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * NOTE: Does not update the allowance if the current allowance\n     * is the maximum `uint256`.\n     *\n     * Requirements:\n     *\n     * - `from` and `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``from``'s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {\n        address spender = _msgSender();\n        _spendAllowance(from, spender, amount);\n        _transfer(from, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, allowance(owner, spender) + addedValue);\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        uint256 currentAllowance = allowance(owner, spender);\n        require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n        unchecked {\n            _approve(owner, spender, currentAllowance - subtractedValue);\n        }\n\n        return true;\n    }\n\n    /**\n     * @dev Moves `amount` of tokens from `from` to `to`.\n     *\n     * This internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     */\n    function _transfer(address from, address to, uint256 amount) internal virtual {\n        require(from != address(0), \"ERC20: transfer from the zero address\");\n        require(to != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(from, to, amount);\n\n        uint256 fromBalance = _balances[from];\n        require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n        unchecked {\n            _balances[from] = fromBalance - amount;\n            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n            // decrementing then incrementing.\n            _balances[to] += amount;\n        }\n\n        emit Transfer(from, to, amount);\n\n        _afterTokenTransfer(from, to, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply += amount;\n        unchecked {\n            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n            _balances[account] += amount;\n        }\n        emit Transfer(address(0), account, amount);\n\n        _afterTokenTransfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        uint256 accountBalance = _balances[account];\n        require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n        unchecked {\n            _balances[account] = accountBalance - amount;\n            // Overflow not possible: amount <= accountBalance <= totalSupply.\n            _totalSupply -= amount;\n        }\n\n        emit Transfer(account, address(0), amount);\n\n        _afterTokenTransfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(address owner, address spender, uint256 amount) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n     *\n     * Does not update the allowance amount in case of infinite allowance.\n     * Revert if not enough allowance is available.\n     *\n     * Might emit an {Approval} event.\n     */\n    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {\n        uint256 currentAllowance = allowance(owner, spender);\n        if (currentAllowance != type(uint256).max) {\n            require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n            unchecked {\n                _approve(owner, spender, currentAllowance - amount);\n            }\n        }\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}\n\n    /**\n     * @dev Hook that is called after any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * has been transferred to `to`.\n     * - when `from` is zero, `amount` tokens have been minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n// EIP-2612 is Final as of 2022-11-01. This file is deprecated.\n\nimport \"./IERC20Permit.sol\";\n"
      },
      "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20Permit.sol\";\nimport \"../ERC20.sol\";\nimport \"../../../utils/cryptography/ECDSA.sol\";\nimport \"../../../utils/cryptography/EIP712.sol\";\nimport \"../../../utils/Counters.sol\";\n\n/**\n * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * _Available since v3.4._\n */\nabstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {\n    using Counters for Counters.Counter;\n\n    mapping(address => Counters.Counter) private _nonces;\n\n    // solhint-disable-next-line var-name-mixedcase\n    bytes32 private constant _PERMIT_TYPEHASH =\n        keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\n    /**\n     * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.\n     * However, to ensure consistency with the upgradeable transpiler, we will continue\n     * to reserve a slot.\n     * @custom:oz-renamed-from _PERMIT_TYPEHASH\n     */\n    // solhint-disable-next-line var-name-mixedcase\n    bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;\n\n    /**\n     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `\"1\"`.\n     *\n     * It's a good idea to use the same `name` that is defined as the ERC20 token name.\n     */\n    constructor(string memory name) EIP712(name, \"1\") {}\n\n    /**\n     * @dev See {IERC20Permit-permit}.\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) public virtual override {\n        require(block.timestamp <= deadline, \"ERC20Permit: expired deadline\");\n\n        bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));\n\n        bytes32 hash = _hashTypedDataV4(structHash);\n\n        address signer = ECDSA.recover(hash, v, r, s);\n        require(signer == owner, \"ERC20Permit: invalid signature\");\n\n        _approve(owner, spender, value);\n    }\n\n    /**\n     * @dev See {IERC20Permit-nonces}.\n     */\n    function nonces(address owner) public view virtual override returns (uint256) {\n        return _nonces[owner].current();\n    }\n\n    /**\n     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view override returns (bytes32) {\n        return _domainSeparatorV4();\n    }\n\n    /**\n     * @dev \"Consume a nonce\": return the current value and increment.\n     *\n     * _Available since v4.1._\n     */\n    function _useNonce(address owner) internal virtual returns (uint256 current) {\n        Counters.Counter storage nonce = _nonces[owner];\n        current = nonce.current();\n        nonce.increment();\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Counters.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title Counters\n * @author Matt Condon (@shrugs)\n * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number\n * of elements in a mapping, issuing ERC721 ids, or counting request ids.\n *\n * Include with `using Counters for Counters.Counter;`\n */\nlibrary Counters {\n    struct Counter {\n        // This variable should never be directly accessed by users of the library: interactions must be restricted to\n        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n        // this feature: see https://github.com/ethereum/solidity/issues/4637\n        uint256 _value; // default: 0\n    }\n\n    function current(Counter storage counter) internal view returns (uint256) {\n        return counter._value;\n    }\n\n    function increment(Counter storage counter) internal {\n        unchecked {\n            counter._value += 1;\n        }\n    }\n\n    function decrement(Counter storage counter) internal {\n        uint256 value = counter._value;\n        require(value > 0, \"Counter: decrement overflow\");\n        unchecked {\n            counter._value = value - 1;\n        }\n    }\n\n    function reset(Counter storage counter) internal {\n        counter._value = 0;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/cryptography/ECDSA.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Strings.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n    enum RecoverError {\n        NoError,\n        InvalidSignature,\n        InvalidSignatureLength,\n        InvalidSignatureS,\n        InvalidSignatureV // Deprecated in v4.8\n    }\n\n    function _throwError(RecoverError error) private pure {\n        if (error == RecoverError.NoError) {\n            return; // no error: do nothing\n        } else if (error == RecoverError.InvalidSignature) {\n            revert(\"ECDSA: invalid signature\");\n        } else if (error == RecoverError.InvalidSignatureLength) {\n            revert(\"ECDSA: invalid signature length\");\n        } else if (error == RecoverError.InvalidSignatureS) {\n            revert(\"ECDSA: invalid signature 's' value\");\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature` or error string. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     *\n     * Documentation for signature generation:\n     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n        if (signature.length == 65) {\n            bytes32 r;\n            bytes32 s;\n            uint8 v;\n            // ecrecover takes the signature parameters, and the only way to get them\n            // currently is to use assembly.\n            /// @solidity memory-safe-assembly\n            assembly {\n                r := mload(add(signature, 0x20))\n                s := mload(add(signature, 0x40))\n                v := byte(0, mload(add(signature, 0x60)))\n            }\n            return tryRecover(hash, v, r, s);\n        } else {\n            return (address(0), RecoverError.InvalidSignatureLength);\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature`. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     */\n    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, signature);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n     *\n     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {\n        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n        uint8 v = uint8((uint256(vs) >> 255) + 27);\n        return tryRecover(hash, v, r, s);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n     *\n     * _Available since v4.2._\n     */\n    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {\n        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n        // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n        //\n        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n        // these malleable signatures as well.\n        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n            return (address(0), RecoverError.InvalidSignatureS);\n        }\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        if (signer == address(0)) {\n            return (address(0), RecoverError.InvalidSignature);\n        }\n\n        return (signer, RecoverError.NoError);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     */\n    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {\n        // 32 is the length in bytes of hash,\n        // enforced by the type signature above\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\")\n            mstore(0x1c, hash)\n            message := keccak256(0x00, 0x3c)\n        }\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from `s`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Typed Data, created from a\n     * `domainSeparator` and a `structHash`. This produces hash corresponding\n     * to the one signed with the\n     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n     * JSON-RPC method as part of EIP-712.\n     *\n     * See {recover}.\n     */\n    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let ptr := mload(0x40)\n            mstore(ptr, \"\\x19\\x01\")\n            mstore(add(ptr, 0x02), domainSeparator)\n            mstore(add(ptr, 0x22), structHash)\n            data := keccak256(ptr, 0x42)\n        }\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Data with intended validator, created from a\n     * `validator` and `data` according to the version 0 of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19\\x00\", validator, data));\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/cryptography/EIP712.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.8;\n\nimport \"./ECDSA.sol\";\nimport \"../ShortStrings.sol\";\nimport \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,\n * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding\n * they need in their contracts using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * _Available since v3.4._\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment\n */\nabstract contract EIP712 is IERC5267 {\n    using ShortStrings for *;\n\n    bytes32 private constant _TYPE_HASH =\n        keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n    // invalidate the cached domain separator if the chain id changes.\n    bytes32 private immutable _cachedDomainSeparator;\n    uint256 private immutable _cachedChainId;\n    address private immutable _cachedThis;\n\n    bytes32 private immutable _hashedName;\n    bytes32 private immutable _hashedVersion;\n\n    ShortString private immutable _name;\n    ShortString private immutable _version;\n    string private _nameFallback;\n    string private _versionFallback;\n\n    /**\n     * @dev Initializes the domain separator and parameter caches.\n     *\n     * The meaning of `name` and `version` is specified in\n     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:\n     *\n     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n     * - `version`: the current major version of the signing domain.\n     *\n     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n     * contract upgrade].\n     */\n    constructor(string memory name, string memory version) {\n        _name = name.toShortStringWithFallback(_nameFallback);\n        _version = version.toShortStringWithFallback(_versionFallback);\n        _hashedName = keccak256(bytes(name));\n        _hashedVersion = keccak256(bytes(version));\n\n        _cachedChainId = block.chainid;\n        _cachedDomainSeparator = _buildDomainSeparator();\n        _cachedThis = address(this);\n    }\n\n    /**\n     * @dev Returns the domain separator for the current chain.\n     */\n    function _domainSeparatorV4() internal view returns (bytes32) {\n        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n            return _cachedDomainSeparator;\n        } else {\n            return _buildDomainSeparator();\n        }\n    }\n\n    function _buildDomainSeparator() private view returns (bytes32) {\n        return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n    }\n\n    /**\n     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n     * function returns the hash of the fully encoded EIP712 message for this domain.\n     *\n     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n     *\n     * ```solidity\n     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n     *     keccak256(\"Mail(address to,string contents)\"),\n     *     mailTo,\n     *     keccak256(bytes(mailContents))\n     * )));\n     * address signer = ECDSA.recover(digest, signature);\n     * ```\n     */\n    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);\n    }\n\n    /**\n     * @dev See {EIP-5267}.\n     *\n     * _Available since v4.9._\n     */\n    function eip712Domain()\n        public\n        view\n        virtual\n        override\n        returns (\n            bytes1 fields,\n            string memory name,\n            string memory version,\n            uint256 chainId,\n            address verifyingContract,\n            bytes32 salt,\n            uint256[] memory extensions\n        )\n    {\n        return (\n            hex\"0f\", // 01111\n            _name.toStringWithFallback(_nameFallback),\n            _version.toStringWithFallback(_versionFallback),\n            block.chainid,\n            address(this),\n            bytes32(0),\n            new uint256[](0)\n        );\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/math/Math.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n    enum Rounding {\n        Down, // Toward negative infinity\n        Up, // Toward infinity\n        Zero // Toward zero\n    }\n\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds up instead\n     * of rounding down.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a == 0 ? 0 : (a - 1) / b + 1;\n    }\n\n    /**\n     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n     * with further edits by Uniswap Labs also under MIT license.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod0 := mul(x, y)\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n                // The surrounding unchecked block does not change this fact.\n                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            require(denominator > prod1, \"Math: mulDiv overflow\");\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n            // See https://cs.stackexchange.com/q/138556/92363.\n\n            // Does not overflow because the denominator cannot be zero at this stage in the function.\n            uint256 twos = denominator & (~denominator + 1);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n            // in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10 ** 64) {\n                value /= 10 ** 64;\n                result += 64;\n            }\n            if (value >= 10 ** 32) {\n                value /= 10 ** 32;\n                result += 32;\n            }\n            if (value >= 10 ** 16) {\n                value /= 10 ** 16;\n                result += 16;\n            }\n            if (value >= 10 ** 8) {\n                value /= 10 ** 8;\n                result += 8;\n            }\n            if (value >= 10 ** 4) {\n                value /= 10 ** 4;\n                result += 4;\n            }\n            if (value >= 10 ** 2) {\n                value /= 10 ** 2;\n                result += 2;\n            }\n            if (value >= 10 ** 1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/math/SafeCast.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value <= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value <= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value <= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value <= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value <= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value <= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value <= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value <= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value <= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value <= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value <= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value <= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value <= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value <= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value <= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value <= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value <= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value <= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value <= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value <= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value <= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value <= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value <= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value <= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value <= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value <= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value <= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value <= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value <= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value <= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value <= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value >= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value <= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/math/SignedMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n    /**\n     * @dev Returns the largest of two signed numbers.\n     */\n    function max(int256 a, int256 b) internal pure returns (int256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two signed numbers.\n     */\n    function min(int256 a, int256 b) internal pure returns (int256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two signed numbers without overflow.\n     * The result is rounded towards zero.\n     */\n    function average(int256 a, int256 b) internal pure returns (int256) {\n        // Formula from the book \"Hacker's Delight\"\n        int256 x = (a & b) + ((a ^ b) >> 1);\n        return x + (int256(uint256(x) >> 255) & (a ^ b));\n    }\n\n    /**\n     * @dev Returns the absolute unsigned value of a signed value.\n     */\n    function abs(int256 n) internal pure returns (uint256) {\n        unchecked {\n            // must be unchecked in order to support `n = type(int256).min`\n            return uint256(n >= 0 ? n : -n);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/ShortStrings.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.8;\n\nimport \"./StorageSlot.sol\";\n\n// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |\n// | length  | 0x                                                              BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n *     using ShortStrings for *;\n *\n *     ShortString private immutable _name;\n *     string private _nameFallback;\n *\n *     constructor(string memory contractName) {\n *         _name = contractName.toShortStringWithFallback(_nameFallback);\n *     }\n *\n *     function name() external view returns (string memory) {\n *         return _name.toStringWithFallback(_nameFallback);\n *     }\n * }\n * ```\n */\nlibrary ShortStrings {\n    // Used as an identifier for strings longer than 31 bytes.\n    bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n    error StringTooLong(string str);\n    error InvalidShortString();\n\n    /**\n     * @dev Encode a string of at most 31 chars into a `ShortString`.\n     *\n     * This will trigger a `StringTooLong` error is the input string is too long.\n     */\n    function toShortString(string memory str) internal pure returns (ShortString) {\n        bytes memory bstr = bytes(str);\n        if (bstr.length > 31) {\n            revert StringTooLong(str);\n        }\n        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n    }\n\n    /**\n     * @dev Decode a `ShortString` back to a \"normal\" string.\n     */\n    function toString(ShortString sstr) internal pure returns (string memory) {\n        uint256 len = byteLength(sstr);\n        // using `new string(len)` would work locally but is not memory safe.\n        string memory str = new string(32);\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(str, len)\n            mstore(add(str, 0x20), sstr)\n        }\n        return str;\n    }\n\n    /**\n     * @dev Return the length of a `ShortString`.\n     */\n    function byteLength(ShortString sstr) internal pure returns (uint256) {\n        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n        if (result > 31) {\n            revert InvalidShortString();\n        }\n        return result;\n    }\n\n    /**\n     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n     */\n    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n        if (bytes(value).length < 32) {\n            return toShortString(value);\n        } else {\n            StorageSlot.getStringSlot(store).value = value;\n            return ShortString.wrap(_FALLBACK_SENTINEL);\n        }\n    }\n\n    /**\n     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.\n     */\n    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {\n            return toString(value);\n        } else {\n            return store;\n        }\n    }\n\n    /**\n     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}.\n     *\n     * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n     */\n    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {\n            return byteLength(value);\n        } else {\n            return bytes(store).length;\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/StorageSlot.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n *     function _getImplementation() internal view returns (address) {\n *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n *     }\n *\n *     function _setImplementation(address newImplementation) internal {\n *         require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n *     }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._\n * _Available since v4.9 for `string`, `bytes`._\n */\nlibrary StorageSlot {\n    struct AddressSlot {\n        address value;\n    }\n\n    struct BooleanSlot {\n        bool value;\n    }\n\n    struct Bytes32Slot {\n        bytes32 value;\n    }\n\n    struct Uint256Slot {\n        uint256 value;\n    }\n\n    struct StringSlot {\n        string value;\n    }\n\n    struct BytesSlot {\n        bytes value;\n    }\n\n    /**\n     * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n     */\n    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n     */\n    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n     */\n    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n     */\n    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `StringSlot` with member `value` located at `slot`.\n     */\n    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n     */\n    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := store.slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BytesSlot` with member `value` located at `slot`.\n     */\n    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n     */\n    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := store.slot\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Strings.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\nimport \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n    bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n    uint8 private constant _ADDRESS_LENGTH = 20;\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            uint256 length = Math.log10(value) + 1;\n            string memory buffer = new string(length);\n            uint256 ptr;\n            /// @solidity memory-safe-assembly\n            assembly {\n                ptr := add(buffer, add(32, length))\n            }\n            while (true) {\n                ptr--;\n                /// @solidity memory-safe-assembly\n                assembly {\n                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n                }\n                value /= 10;\n                if (value == 0) break;\n            }\n            return buffer;\n        }\n    }\n\n    /**\n     * @dev Converts a `int256` to its ASCII `string` decimal representation.\n     */\n    function toString(int256 value) internal pure returns (string memory) {\n        return string(abi.encodePacked(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value))));\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        unchecked {\n            return toHexString(value, Math.log256(value) + 1);\n        }\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n     */\n    function toHexString(address addr) internal pure returns (string memory) {\n        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n    }\n\n    /**\n     * @dev Returns true if the two strings are equal.\n     */\n    function equal(string memory a, string memory b) internal pure returns (bool) {\n        return keccak256(bytes(a)) == keccak256(bytes(b));\n    }\n}\n"
      },
      "contracts/core/interfaces/ISmardexFactory.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.17;\n\ninterface ISmardexFactory {\n    /**\n     * @notice emitted at each SmardexPair created\n     * @param token0 address of the token0\n     * @param token1 address of the token1\n     * @param pair address of the SmardexPair created\n     * @param totalPair number of SmardexPair created so far\n     */\n    event PairCreated(address indexed token0, address indexed token1, address pair, uint256 totalPair);\n\n    /**\n     * @notice emitted at each SmardexPair manually added\n     * @param token0 address of the token0\n     * @param token1 address of the token1\n     * @param pair address of the SmardexPair created\n     * @param totalPair number of SmardexPair created so far\n     */\n    event PairAdded(address indexed token0, address indexed token1, address pair, uint256 totalPair);\n\n    /**\n     * @notice emitted each time feesLP and feesPool are changed\n     * @param feesLP new feesLP\n     * @param feesPool new feesPool\n     */\n    event FeesChanged(uint256 indexed feesLP, uint256 indexed feesPool);\n\n    /**\n     * @notice emitted when the feeTo is updated\n     * @param previousFeeTo the previous feeTo address\n     * @param newFeeTo the new feeTo address\n     */\n    event FeeToUpdated(address indexed previousFeeTo, address indexed newFeeTo);\n\n    /**\n     * @notice return which address fees will be transferred\n     */\n    function feeTo() external view returns (address);\n\n    /**\n     * @notice return the address of the pair of 2 tokens\n     */\n    function getPair(address _tokenA, address _tokenB) external view returns (address pair_);\n\n    /**\n     * @notice return the address of the pair at index\n     * @param _index index of the pair\n     * @return pair_ address of the pair\n     */\n    function allPairs(uint256 _index) external view returns (address pair_);\n\n    /**\n     * @notice return the quantity of pairs\n     * @return quantity in uint256\n     */\n    function allPairsLength() external view returns (uint256);\n\n    /**\n     * @notice return numerators of pair fees, denominator is 1_000_000\n     * @return feesLP_ numerator of fees sent to LP at pair creation\n     * @return feesPool_ numerator of fees sent to Pool at pair creation\n     */\n    function getDefaultFees() external view returns (uint128 feesLP_, uint128 feesPool_);\n\n    /**\n     * @notice whether whitelist is open\n     * @return open_ true if the whitelist is open, false otherwise\n     */\n    function whitelistOpen() external view returns (bool open_);\n\n    /**\n     * @notice create pair with 2 address\n     * @param _tokenA address of tokenA\n     * @param _tokenB address of tokenB\n     * @return pair_ address of the pair created\n     */\n    function createPair(address _tokenA, address _tokenB) external returns (address pair_);\n\n    /**\n     * @notice set the address who will receive fees, can only be call by the owner\n     * @param _feeTo address to replace\n     */\n    function setFeeTo(address _feeTo) external;\n\n    /**\n     * @notice set feesLP and feesPool for each new pair (onlyOwner)\n     * @notice sum of new feesLp and feesPool must be <= FEES_MAX = 10% FEES_BASE\n     * @param _feesLP new numerator of fees sent to LP, must be >= 1\n     * @param _feesPool new numerator of fees sent to Pool, could be = 0\n     */\n    function setFees(uint128 _feesLP, uint128 _feesPool) external;\n\n    /**\n     * @notice disable whitelist (onlyOwner)\n     * whitelist cannot be re-opened after that.\n     */\n    function closeWhitelist() external;\n\n    /**\n     * @notice add a pair manually\n     * @param _pair pair address to add (must be an ISmardexPair)\n     */\n    function addPair(address _pair) external;\n}\n"
      },
      "contracts/core/interfaces/ISmardexMintCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.17;\n\ninterface ISmardexMintCallback {\n    /**\n     * @notice callback data for mint\n     * @param token0 address of the first token of the pair\n     * @param token1 address of the second token of the pair\n     * @param amount0 amount of token0 to provide\n     * @param amount1 amount of token1 to provide\n     * @param payer address of the payer to provide token for the mint\n     */\n    struct MintCallbackData {\n        address token0;\n        address token1;\n        uint256 amount0;\n        uint256 amount1;\n        address payer;\n    }\n\n    /**\n     * @notice callback to implement when calling SmardexPair.mint\n     * @param _data callback data for mint\n     */\n    function smardexMintCallback(MintCallbackData calldata _data) external;\n}\n"
      },
      "contracts/core/interfaces/ISmardexOwnableFactory.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.17;\n\nimport \"./ISmardexFactory.sol\";\n\n/**\n * @notice the real interface of SmardexFactory, including owner's functions.\n *         Needs to be separate due to a missing IOwner interface of OpenZeppelin\n */\ninterface ISmardexOwnableFactory is ISmardexFactory {\n    /**\n     * @notice emitted each ownership transfer\n     * @param previousOwner previous owner\n     * @param newOwner new owner\n     */\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the current owner.\n     * @return address of the owner\n     */\n    function owner() external view returns (address);\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() external;\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     * @param _newOwner : address of the new owner\n     */\n    function transferOwnership(address _newOwner) external;\n}\n"
      },
      "contracts/core/interfaces/ISmardexPair.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.17;\n\n// interfaces\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol\";\n\ninterface ISmardexPair is IERC20, IERC20Permit {\n    /**\n     * @notice swap parameters used by function swap\n     * @param amountCalculated return amount from getAmountIn/Out is always positive but to avoid too much cast, is int\n     * @param fictiveReserveIn fictive reserve of the in-token of the pair\n     * @param fictiveReserveOut fictive reserve of the out-token of the pair\n     * @param priceAverageIn in-token ratio component of the price average\n     * @param priceAverageOut out-token ratio component of the price average\n     * @param token0 address of the token0\n     * @param token1 address of the token1\n     * @param balanceIn contract balance of the in-token\n     * @param balanceOut contract balance of the out-token\n     */\n    struct SwapParams {\n        int256 amountCalculated;\n        uint256 fictiveReserveIn;\n        uint256 fictiveReserveOut;\n        uint256 priceAverageIn;\n        uint256 priceAverageOut;\n        address token0;\n        address token1;\n        uint256 balanceIn;\n        uint256 balanceOut;\n    }\n\n    /**\n     * @notice emitted at each mint\n     * @param sender address calling the mint function (usually the Router contract)\n     * @param to address that receives the LP-tokens\n     * @param amount0 amount of token0 to be added in liquidity\n     * @param amount1 amount of token1 to be added in liquidity\n     * @dev the amount of LP-token sent can be caught using the transfer event of the pair\n     */\n    event Mint(address indexed sender, address indexed to, uint256 amount0, uint256 amount1);\n\n    /**\n     * @notice emitted at each burn\n     * @param sender address calling the burn function (usually the Router contract)\n     * @param to address that receives the tokens\n     * @param amount0 amount of token0 to be withdrawn\n     * @param amount1 amount of token1 to be withdrawn\n     * @dev the amount of LP-token sent can be caught using the transfer event of the pair\n     */\n    event Burn(address indexed sender, address indexed to, uint256 amount0, uint256 amount1);\n\n    /**\n     * @notice emitted at each swap\n     * @param sender address calling the swap function (usually the Router contract)\n     * @param to address that receives the out-tokens\n     * @param amount0 amount of token0 to be swapped\n     * @param amount1 amount of token1 to be swapped\n     * @dev one of the 2 amount is always negative, the other one is always positive. The positive one is the one that\n     * the user send to the contract, the negative one is the one that the contract send to the user.\n     */\n    event Swap(address indexed sender, address indexed to, int256 amount0, int256 amount1);\n\n    /**\n     * @notice emitted each time the fictive reserves are changed (mint, burn, swap)\n     * @param reserve0 the new reserve of token0\n     * @param reserve1 the new reserve of token1\n     * @param fictiveReserve0 the new fictive reserve of token0\n     * @param fictiveReserve1 the new fictive reserve of token1\n     * @param priceAverage0 the new priceAverage of token0\n     * @param priceAverage1 the new priceAverage of token1\n     */\n    event Sync(\n        uint256 reserve0,\n        uint256 reserve1,\n        uint256 fictiveReserve0,\n        uint256 fictiveReserve1,\n        uint256 priceAverage0,\n        uint256 priceAverage1\n    );\n\n    /**\n     * @notice emitted each time feesLP and feesPool are changed\n     * @param feesLP new feesLP\n     * @param feesPool new feesPool\n     */\n    event FeesChanged(uint256 indexed feesLP, uint256 indexed feesPool);\n\n    /**\n     * @notice get the factory address\n     * @return address of the factory\n     */\n    function factory() external view returns (address);\n\n    /**\n     * @notice get the token0 address\n     * @return address of the token0\n     */\n    function token0() external view returns (address);\n\n    /**\n     * @notice get the token1 address\n     * @return address of the token1\n     */\n    function token1() external view returns (address);\n\n    /**\n     * @notice called once by the factory at time of deployment\n     * @param _token0 address of token0\n     * @param _token1 address of token1\n     * @param _feesLP uint128 feesLP numerator\n     * @param _feesPool uint128 feesPool numerator\n     */\n    function initialize(address _token0, address _token1, uint128 _feesLP, uint128 _feesPool) external;\n\n    /**\n     * @notice return current Reserves of both token in the pair,\n     *  corresponding to token balance - pending fees\n     * @return reserve0_ current reserve of token0 - pending fee0\n     * @return reserve1_ current reserve of token1 - pending fee1\n     */\n    function getReserves() external view returns (uint256 reserve0_, uint256 reserve1_);\n\n    /**\n     * @notice return current fictive reserves of both token in the pair\n     * @return fictiveReserve0_ current fictive reserve of token0\n     * @return fictiveReserve1_ current fictive reserve of token1\n     */\n    function getFictiveReserves() external view returns (uint256 fictiveReserve0_, uint256 fictiveReserve1_);\n\n    /**\n     * @notice return current pending fees of both token in the pair\n     * @return fees0_ current pending fees of token0\n     * @return fees1_ current pending fees of token1\n     */\n    function getFeeToAmounts() external view returns (uint256 fees0_, uint256 fees1_);\n\n    /**\n     * @notice return numerators of pair fees, denominator is 1_000_000\n     * @return feesLP_ numerator of fees sent to LP\n     * @return feesPool_ numerator of fees sent to Pool\n     */\n    function getPairFees() external view returns (uint128 feesLP_, uint128 feesPool_);\n\n    /**\n     * @notice return last updated price average at timestamp of both token in the pair,\n     *  read price0Average/price1Average for current price of token0/token1\n     * @return priceAverage0_ current price for token0\n     * @return priceAverage1_ current price for token1\n     * @return blockTimestampLast_ last block timestamp when price was updated\n     */\n    function getPriceAverage()\n        external\n        view\n        returns (uint256 priceAverage0_, uint256 priceAverage1_, uint256 blockTimestampLast_);\n\n    /**\n     * @notice return current price average of both token in the pair for provided currentTimeStamp\n     *  read price0Average/price1Average for current price of token0/token1\n     * @param _fictiveReserveIn,\n     * @param _fictiveReserveOut,\n     * @param _priceAverageLastTimestamp,\n     * @param _priceAverageIn current price for token0\n     * @param _priceAverageOut current price for token1\n     * @param _currentTimestamp block timestamp to get price\n     * @return priceAverageIn_ current price for token0\n     * @return priceAverageOut_ current price for token1\n     */\n    function getUpdatedPriceAverage(\n        uint256 _fictiveReserveIn,\n        uint256 _fictiveReserveOut,\n        uint256 _priceAverageLastTimestamp,\n        uint256 _priceAverageIn,\n        uint256 _priceAverageOut,\n        uint256 _currentTimestamp\n    ) external pure returns (uint256 priceAverageIn_, uint256 priceAverageOut_);\n\n    /**\n     * @notice Mint lp tokens proportionally of added tokens in balance. Should be called from a contract\n     * that makes safety checks like the SmardexRouter\n     * @param _to address who will receive minted tokens\n     * @param _amount0 amount of token0 to provide\n     * @param _amount1 amount of token1 to provide\n     * @return liquidity_ amount of lp tokens minted and sent to the address defined in parameter\n     */\n    function mint(\n        address _to,\n        uint256 _amount0,\n        uint256 _amount1,\n        address _payer\n    ) external returns (uint256 liquidity_);\n\n    /**\n     * @notice Burn lp tokens in the balance of the contract. Sends to the defined address the amount of token0 and\n     * token1 proportionally of the amount burned. Should be called from a contract that makes safety checks like the\n     * SmardexRouter\n     * @param _to address who will receive tokens\n     * @return amount0_ amount of token0 sent to the address defined in parameter\n     * @return amount1_ amount of token0 sent to the address defined in parameter\n     */\n    function burn(address _to) external returns (uint256 amount0_, uint256 amount1_);\n\n    /**\n     * @notice Swaps tokens. Sends to the defined address the amount of token0 and token1 defined in parameters.\n     * Tokens to trade should be already sent in the contract.\n     * Swap function will check if the resulted balance is correct with current reserves and reserves fictive.\n     * Should be called from a contract that makes safety checks like the SmardexRouter\n     * @param _to address who will receive tokens\n     * @param _zeroForOne token0 to token1\n     * @param _amountSpecified amount of token wanted\n     * @param _data used for flash swap, data.length must be 0 for regular swap\n     */\n    function swap(\n        address _to,\n        bool _zeroForOne,\n        int256 _amountSpecified,\n        bytes calldata _data\n    ) external returns (int256 amount0_, int256 amount1_);\n\n    /**\n     * @notice set feesLP and feesPool of the pair\n     * @notice sum of new feesLp and feesPool must be <= 100_000\n     * @param _feesLP new numerator of fees sent to LP, must be >= 1\n     * @param _feesPool new numerator of fees sent to Pool, could be = 0\n     */\n    function setFees(uint128 _feesLP, uint128 _feesPool) external;\n\n    /**\n     * @notice withdraw all reserve on the pair in case no liquidity has never been provided\n     * @param _to address who will receive tokens\n     */\n    function skim(address _to) external;\n}\n"
      },
      "contracts/core/interfaces/ISmardexSwapCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.8.17;\n\ninterface ISmardexSwapCallback {\n    /**\n     * @notice callback data for swap from SmardexRouter\n     * @param path path of the swap, array of token addresses tightly packed\n     * @param payer address of the payer for the swap\n     */\n    struct SwapCallbackData {\n        bytes path;\n        address payer;\n    }\n\n    /**\n     * @notice callback data for swap\n     * @param _amount0Delta amount of token0 for the swap (negative is incoming, positive is required to pay to pair)\n     * @param _amount1Delta amount of token1 for the swap (negative is incoming, positive is required to pay to pair)\n     * @param _data for Router path and payer for the swap (see router for details)\n     */\n    function smardexSwapCallback(int256 _amount0Delta, int256 _amount1Delta, bytes calldata _data) external;\n}\n"
      },
      "contracts/core/libraries/SmardexLibrary.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity =0.8.17;\n\n// libraries\nimport \"@openzeppelin/contracts/utils/math/Math.sol\";\n\n// interfaces\nimport \"../interfaces/ISmardexPair.sol\";\n\nlibrary SmardexLibrary {\n    /// @notice base of the FEES\n    uint256 public constant FEES_BASE = 1_000_000;\n\n    /// @notice max fees of feesLP and feesPool sum, 10% FEES_BASE\n    uint256 public constant FEES_MAX = FEES_BASE / 10;\n\n    /// @notice precision for approxEq, not in percent but in APPROX_PRECISION_BASE\n    uint256 public constant APPROX_PRECISION = 1;\n\n    /// @notice base of the APPROX_PRECISION\n    uint256 public constant APPROX_PRECISION_BASE = 1_000_000;\n\n    /// @notice number of seconds to reset priceAverage\n    uint256 private constant MAX_BLOCK_DIFF_SECONDS = 300;\n\n    /// @notice parameters of getAmountIn and getAmountOut\n    struct GetAmountParameters {\n        uint256 amount;\n        uint256 reserveIn;\n        uint256 reserveOut;\n        uint256 fictiveReserveIn;\n        uint256 fictiveReserveOut;\n        uint256 priceAverageIn;\n        uint256 priceAverageOut;\n        uint128 feesLP;\n        uint128 feesPool;\n    }\n\n    /**\n     * @notice check if 2 numbers are approximately equal, using APPROX_PRECISION\n     * @param _x number to compare\n     * @param _y number to compare\n     * @return true if numbers are approximately equal, false otherwise\n     */\n    function approxEq(uint256 _x, uint256 _y) internal pure returns (bool) {\n        if (_x == _y) {\n            return true;\n        } else if (_x > _y) {\n            return _x < (_y + (_y * APPROX_PRECISION) / APPROX_PRECISION_BASE);\n        } else {\n            return _y < (_x + (_x * APPROX_PRECISION) / APPROX_PRECISION_BASE);\n        }\n    }\n\n    /**\n     * @notice check if 2 ratio are approximately equal: _xNum _/ xDen ~= _yNum / _yDen\n     * @param _xNum numerator of the first ratio to compare\n     * @param _xDen denominator of the first ratio to compare\n     * @param _yNum numerator of the second ratio to compare\n     * @param _yDen denominator of the second ratio to compare\n     * @return true if ratio are approximately equal, false otherwise\n     */\n    function ratioApproxEq(uint256 _xNum, uint256 _xDen, uint256 _yNum, uint256 _yDen) internal pure returns (bool) {\n        return approxEq(_xNum * _yDen, _xDen * _yNum);\n    }\n\n    /**\n     * @notice update priceAverage given old timestamp, new timestamp and prices\n     * @param _fictiveReserveIn ratio component of the new price of the in-token\n     * @param _fictiveReserveOut ratio component of the new price of the out-token\n     * @param _priceAverageLastTimestamp timestamp of the last priceAverage update (0, if never updated)\n     * @param _priceAverageIn ratio component of the last priceAverage of the in-token\n     * @param _priceAverageOut ratio component of the last priceAverage of the out-token\n     * @param _currentTimestamp timestamp of the priceAverage to update\n     * @return newPriceAverageIn_ ratio component of the updated priceAverage of the in-token\n     * @return newPriceAverageOut_ ratio component of the updated priceAverage of the out-token\n     */\n    function getUpdatedPriceAverage(\n        uint256 _fictiveReserveIn,\n        uint256 _fictiveReserveOut,\n        uint256 _priceAverageLastTimestamp,\n        uint256 _priceAverageIn,\n        uint256 _priceAverageOut,\n        uint256 _currentTimestamp\n    ) internal pure returns (uint256 newPriceAverageIn_, uint256 newPriceAverageOut_) {\n        require(_currentTimestamp >= _priceAverageLastTimestamp, \"SmardexPair: INVALID_TIMESTAMP\");\n\n        // very first time\n        if (_priceAverageLastTimestamp == 0) {\n            newPriceAverageIn_ = _fictiveReserveIn;\n            newPriceAverageOut_ = _fictiveReserveOut;\n        }\n        // another tx has been done in the same timestamp\n        else if (_priceAverageLastTimestamp == _currentTimestamp) {\n            newPriceAverageIn_ = _priceAverageIn;\n            newPriceAverageOut_ = _priceAverageOut;\n        }\n        // need to compute new linear-average price\n        else {\n            // compute new price:\n            uint256 _timeDiff = Math.min(_currentTimestamp - _priceAverageLastTimestamp, MAX_BLOCK_DIFF_SECONDS);\n\n            newPriceAverageIn_ = _fictiveReserveIn;\n            newPriceAverageOut_ =\n                (((MAX_BLOCK_DIFF_SECONDS - _timeDiff) * _priceAverageOut * newPriceAverageIn_) /\n                    _priceAverageIn +\n                    _timeDiff *\n                    _fictiveReserveOut) /\n                MAX_BLOCK_DIFF_SECONDS;\n        }\n    }\n\n    /**\n     * @notice compute the firstTradeAmountIn so that the price reach the price Average\n     * @param _param contain all params required from struct GetAmountParameters\n     * @return firstAmountIn_ the first amount of in-token\n     *\n     * @dev if the trade is going in the direction that the price will never reach the priceAverage, or if _amountIn\n     * is not big enough to reach the priceAverage or if the price is already equal to the priceAverage, then\n     * firstAmountIn_ will be set to _amountIn\n     */\n    function computeFirstTradeQtyIn(GetAmountParameters memory _param) internal pure returns (uint256 firstAmountIn_) {\n        // default value\n        firstAmountIn_ = _param.amount;\n\n        // if trade is in the good direction\n        if (_param.fictiveReserveOut * _param.priceAverageIn > _param.fictiveReserveIn * _param.priceAverageOut) {\n            // pre-compute all operands\n            uint256 _toSub = _param.fictiveReserveIn * ((FEES_BASE * 2) - (_param.feesPool * 2) - _param.feesLP);\n            uint256 _toDiv = (FEES_BASE - _param.feesPool) * 2;\n            uint256 _inSqrt = (((_param.fictiveReserveIn * _param.fictiveReserveOut) * 4) / _param.priceAverageOut) *\n                _param.priceAverageIn *\n                ((FEES_BASE - _param.feesPool - _param.feesLP) * (FEES_BASE - _param.feesPool)) +\n                ((_param.fictiveReserveIn * _param.fictiveReserveIn) * (_param.feesLP * _param.feesLP));\n\n            // reverse sqrt check to only compute sqrt if really needed\n            uint256 _inSqrtCompare = _toSub + _param.amount * _toDiv;\n            if (_inSqrt < _inSqrtCompare * _inSqrtCompare) {\n                firstAmountIn_ = (Math.sqrt(_inSqrt) - _toSub) / _toDiv;\n            }\n        }\n    }\n\n    /**\n     * @notice compute the firstTradeAmountOut so that the price reach the price Average\n     * @param _param contain all params required from struct GetAmountParameters\n     * @return firstAmountOut_ the first amount of out-token\n     *\n     * @dev if the trade is going in the direction that the price will never reach the priceAverage, or if _amountOut\n     * is not big enough to reach the priceAverage or if the price is already equal to the priceAverage, then\n     * firstAmountOut_ will be set to _amountOut\n     */\n    function computeFirstTradeQtyOut(\n        GetAmountParameters memory _param\n    ) internal pure returns (uint256 firstAmountOut_) {\n        // default value\n        firstAmountOut_ = _param.amount;\n        uint256 _reverseFeesTotal = FEES_BASE - _param.feesPool - _param.feesLP;\n        // if trade is in the good direction\n        if (_param.fictiveReserveOut * _param.priceAverageIn > _param.fictiveReserveIn * _param.priceAverageOut) {\n            // pre-compute all operands\n            uint256 _fictiveReserveOutPredFees = (_param.fictiveReserveIn * _param.feesLP * _param.priceAverageOut) /\n                _param.priceAverageIn;\n            uint256 _toAdd = ((_param.fictiveReserveOut * _reverseFeesTotal) * 2) + _fictiveReserveOutPredFees;\n            uint256 _toDiv = _reverseFeesTotal * 2;\n\n            uint256 _inSqrt = (((_param.fictiveReserveOut * _fictiveReserveOutPredFees) * 4) *\n                (_reverseFeesTotal * (FEES_BASE - _param.feesPool))) /\n                _param.feesLP +\n                (_fictiveReserveOutPredFees * _fictiveReserveOutPredFees);\n\n            // reverse sqrt check to only compute sqrt if really needed\n            uint256 _inSqrtCompare = _toAdd - _param.amount * _toDiv;\n            if (_inSqrt > _inSqrtCompare * _inSqrtCompare) {\n                firstAmountOut_ = (_toAdd - Math.sqrt(_inSqrt)) / _toDiv;\n            }\n        }\n    }\n\n    /**\n     * @notice compute fictive reserves\n     * @param _reserveIn reserve of the in-token\n     * @param _reserveOut reserve of the out-token\n     * @param _fictiveReserveIn fictive reserve of the in-token\n     * @param _fictiveReserveOut fictive reserve of the out-token\n     * @return newFictiveReserveIn_ new fictive reserve of the in-token\n     * @return newFictiveReserveOut_ new fictive reserve of the out-token\n     */\n    function computeFictiveReserves(\n        uint256 _reserveIn,\n        uint256 _reserveOut,\n        uint256 _fictiveReserveIn,\n        uint256 _fictiveReserveOut\n    ) internal pure returns (uint256 newFictiveReserveIn_, uint256 newFictiveReserveOut_) {\n        if (_reserveOut * _fictiveReserveIn < _reserveIn * _fictiveReserveOut) {\n            uint256 _temp = (((_reserveOut * _reserveOut) / _fictiveReserveOut) * _fictiveReserveIn) / _reserveIn;\n            newFictiveReserveIn_ =\n                (_temp * _fictiveReserveIn) /\n                _fictiveReserveOut +\n                (_reserveOut * _fictiveReserveIn) /\n                _fictiveReserveOut;\n            newFictiveReserveOut_ = _reserveOut + _temp;\n        } else {\n            newFictiveReserveIn_ = (_fictiveReserveIn * _reserveOut) / _fictiveReserveOut + _reserveIn;\n            newFictiveReserveOut_ = (_reserveIn * _fictiveReserveOut) / _fictiveReserveIn + _reserveOut;\n        }\n\n        // div all values by 4\n        newFictiveReserveIn_ /= 4;\n        newFictiveReserveOut_ /= 4;\n    }\n\n    /**\n     * @notice apply k const rule using fictive reserve, when the amountIn is specified\n     * @param _param contain all params required from struct GetAmountParameters\n     * @return amountOut_ qty of token that leaves in the contract\n     * @return newReserveIn_ new reserve of the in-token after the transaction\n     * @return newReserveOut_ new reserve of the out-token after the transaction\n     * @return newFictiveReserveIn_ new fictive reserve of the in-token after the transaction\n     * @return newFictiveReserveOut_ new fictive reserve of the out-token after the transaction\n     */\n    function applyKConstRuleOut(\n        GetAmountParameters memory _param\n    )\n        internal\n        pure\n        returns (\n            uint256 amountOut_,\n            uint256 newReserveIn_,\n            uint256 newReserveOut_,\n            uint256 newFictiveReserveIn_,\n            uint256 newFictiveReserveOut_\n        )\n    {\n        // k const rule\n        uint256 _amountInWithFee = _param.amount * (FEES_BASE - _param.feesLP - _param.feesPool);\n        uint256 _numerator = _amountInWithFee * _param.fictiveReserveOut;\n        uint256 _denominator = _param.fictiveReserveIn * FEES_BASE + _amountInWithFee;\n        amountOut_ = _numerator / _denominator;\n\n        // update new reserves and add lp-fees to pools\n        uint256 _amountInWithFeeLp = (_amountInWithFee + (_param.amount * _param.feesLP)) / FEES_BASE;\n        newReserveIn_ = _param.reserveIn + _amountInWithFeeLp;\n        newFictiveReserveIn_ = _param.fictiveReserveIn + _amountInWithFeeLp;\n        newReserveOut_ = _param.reserveOut - amountOut_;\n        newFictiveReserveOut_ = _param.fictiveReserveOut - amountOut_;\n    }\n\n    /**\n     * @notice apply k const rule using fictive reserve, when the amountOut is specified\n     * @param _param contain all params required from struct GetAmountParameters\n     * @return amountIn_ qty of token that arrives in the contract\n     * @return newReserveIn_ new reserve of the in-token after the transaction\n     * @return newReserveOut_ new reserve of the out-token after the transaction\n     * @return newFictiveReserveIn_ new fictive reserve of the in-token after the transaction\n     * @return newFictiveReserveOut_ new fictive reserve of the out-token after the transaction\n     */\n    function applyKConstRuleIn(\n        GetAmountParameters memory _param\n    )\n        internal\n        pure\n        returns (\n            uint256 amountIn_,\n            uint256 newReserveIn_,\n            uint256 newReserveOut_,\n            uint256 newFictiveReserveIn_,\n            uint256 newFictiveReserveOut_\n        )\n    {\n        // k const rule\n        uint256 _numerator = _param.fictiveReserveIn * _param.amount * FEES_BASE;\n        uint256 _denominator = (_param.fictiveReserveOut - _param.amount) *\n            (FEES_BASE - _param.feesPool - _param.feesLP);\n        amountIn_ = _numerator / _denominator + 1;\n\n        // update new reserves\n        uint256 _amountInWithFeeLp = (amountIn_ * (FEES_BASE - _param.feesPool)) / FEES_BASE;\n        newReserveIn_ = _param.reserveIn + _amountInWithFeeLp;\n        newFictiveReserveIn_ = _param.fictiveReserveIn + _amountInWithFeeLp;\n        newReserveOut_ = _param.reserveOut - _param.amount;\n        newFictiveReserveOut_ = _param.fictiveReserveOut - _param.amount;\n    }\n\n    /**\n     * @notice return the amount of tokens the user would get by doing a swap\n     * @param _param contain all params required from struct GetAmountParameters\n     * @return amountOut_ The amount of token the user would receive\n     * @return newReserveIn_ reserves of the selling token after the swap\n     * @return newReserveOut_ reserves of the buying token after the swap\n     * @return newFictiveReserveIn_ fictive reserve of the selling token after the swap\n     * @return newFictiveReserveOut_ fictive reserve of the buying token after the swap\n     */\n    function getAmountOut(\n        GetAmountParameters memory _param\n    )\n        internal\n        pure\n        returns (\n            uint256 amountOut_,\n            uint256 newReserveIn_,\n            uint256 newReserveOut_,\n            uint256 newFictiveReserveIn_,\n            uint256 newFictiveReserveOut_\n        )\n    {\n        require(_param.amount != 0, \"SmarDexLibrary: INSUFFICIENT_INPUT_AMOUNT\");\n        require(\n            _param.reserveIn != 0 &&\n                _param.reserveOut != 0 &&\n                _param.fictiveReserveIn != 0 &&\n                _param.fictiveReserveOut != 0,\n            \"SmarDexLibrary: INSUFFICIENT_LIQUIDITY\"\n        );\n\n        uint256 _amountInWithFees = (_param.amount * (FEES_BASE - _param.feesPool - _param.feesLP)) / FEES_BASE;\n        uint256 _firstAmountIn = computeFirstTradeQtyIn(\n            SmardexLibrary.GetAmountParameters({\n                amount: _amountInWithFees,\n                reserveIn: _param.reserveIn,\n                reserveOut: _param.reserveOut,\n                fictiveReserveIn: _param.fictiveReserveIn,\n                fictiveReserveOut: _param.fictiveReserveOut,\n                priceAverageIn: _param.priceAverageIn,\n                priceAverageOut: _param.priceAverageOut,\n                feesLP: _param.feesLP,\n                feesPool: _param.feesPool\n            })\n        );\n\n        // if there is 2 trade: 1st trade mustn't re-compute fictive reserves, 2nd should\n        if (\n            _firstAmountIn == _amountInWithFees &&\n            ratioApproxEq(\n                _param.fictiveReserveIn,\n                _param.fictiveReserveOut,\n                _param.priceAverageIn,\n                _param.priceAverageOut\n            )\n        ) {\n            (_param.fictiveReserveIn, _param.fictiveReserveOut) = computeFictiveReserves(\n                _param.reserveIn,\n                _param.reserveOut,\n                _param.fictiveReserveIn,\n                _param.fictiveReserveOut\n            );\n        }\n\n        // avoid stack too deep\n        {\n            uint256 _firstAmountInNoFees = (_firstAmountIn * FEES_BASE) / (FEES_BASE - _param.feesPool - _param.feesLP);\n            (\n                amountOut_,\n                newReserveIn_,\n                newReserveOut_,\n                newFictiveReserveIn_,\n                newFictiveReserveOut_\n            ) = applyKConstRuleOut(\n                SmardexLibrary.GetAmountParameters({\n                    amount: _firstAmountInNoFees,\n                    reserveIn: _param.reserveIn,\n                    reserveOut: _param.reserveOut,\n                    fictiveReserveIn: _param.fictiveReserveIn,\n                    fictiveReserveOut: _param.fictiveReserveOut,\n                    priceAverageIn: _param.priceAverageIn,\n                    priceAverageOut: _param.priceAverageOut,\n                    feesLP: _param.feesLP,\n                    feesPool: _param.feesPool\n                })\n            );\n\n            // update amountIn in case there is a second trade\n            _param.amount -= _firstAmountInNoFees;\n        }\n\n        // if we need a second trade\n        if (_firstAmountIn < _amountInWithFees) {\n            // in the second trade ALWAYS recompute fictive reserves\n            (newFictiveReserveIn_, newFictiveReserveOut_) = computeFictiveReserves(\n                newReserveIn_,\n                newReserveOut_,\n                newFictiveReserveIn_,\n                newFictiveReserveOut_\n            );\n\n            uint256 _secondAmountOutNoFees;\n            (\n                _secondAmountOutNoFees,\n                newReserveIn_,\n                newReserveOut_,\n                newFictiveReserveIn_,\n                newFictiveReserveOut_\n            ) = applyKConstRuleOut(\n                SmardexLibrary.GetAmountParameters({\n                    amount: _param.amount,\n                    reserveIn: newReserveIn_,\n                    reserveOut: newReserveOut_,\n                    fictiveReserveIn: newFictiveReserveIn_,\n                    fictiveReserveOut: newFictiveReserveOut_,\n                    priceAverageIn: _param.priceAverageIn,\n                    priceAverageOut: _param.priceAverageOut,\n                    feesLP: _param.feesLP,\n                    feesPool: _param.feesPool\n                })\n            );\n            amountOut_ += _secondAmountOutNoFees;\n        }\n    }\n\n    /**\n     * @notice return the amount of tokens the user should spend by doing a swap\n     * @param _param contain all params required from struct GetAmountParameters\n     * @return amountIn_ The amount of token the user would spend to receive _amountOut\n     * @return newReserveIn_ reserves of the selling token after the swap\n     * @return newReserveOut_ reserves of the buying token after the swap\n     * @return newFictiveReserveIn_ fictive reserve of the selling token after the swap\n     * @return newFictiveReserveOut_ fictive reserve of the buying token after the swap\n     */\n    function getAmountIn(\n        GetAmountParameters memory _param\n    )\n        internal\n        pure\n        returns (\n            uint256 amountIn_,\n            uint256 newReserveIn_,\n            uint256 newReserveOut_,\n            uint256 newFictiveReserveIn_,\n            uint256 newFictiveReserveOut_\n        )\n    {\n        require(_param.amount != 0, \"SmarDexLibrary: INSUFFICIENT_OUTPUT_AMOUNT\");\n        require(\n            _param.amount < _param.fictiveReserveOut &&\n                _param.reserveIn != 0 &&\n                _param.reserveOut != 0 &&\n                _param.fictiveReserveIn != 0 &&\n                _param.fictiveReserveOut != 0,\n            \"SmarDexLibrary: INSUFFICIENT_LIQUIDITY\"\n        );\n\n        uint256 _firstAmountOut = computeFirstTradeQtyOut(_param);\n\n        // if there is 2 trade: 1st trade mustn't re-compute fictive reserves, 2nd should\n        if (\n            _firstAmountOut == _param.amount &&\n            ratioApproxEq(\n                _param.fictiveReserveIn,\n                _param.fictiveReserveOut,\n                _param.priceAverageIn,\n                _param.priceAverageOut\n            )\n        ) {\n            (_param.fictiveReserveIn, _param.fictiveReserveOut) = computeFictiveReserves(\n                _param.reserveIn,\n                _param.reserveOut,\n                _param.fictiveReserveIn,\n                _param.fictiveReserveOut\n            );\n        }\n\n        (amountIn_, newReserveIn_, newReserveOut_, newFictiveReserveIn_, newFictiveReserveOut_) = applyKConstRuleIn(\n            SmardexLibrary.GetAmountParameters({\n                amount: _firstAmountOut,\n                reserveIn: _param.reserveIn,\n                reserveOut: _param.reserveOut,\n                fictiveReserveIn: _param.fictiveReserveIn,\n                fictiveReserveOut: _param.fictiveReserveOut,\n                priceAverageIn: _param.priceAverageIn,\n                priceAverageOut: _param.priceAverageOut,\n                feesLP: _param.feesLP,\n                feesPool: _param.feesPool\n            })\n        );\n\n        // if we need a second trade\n        if (_firstAmountOut < _param.amount) {\n            // in the second trade ALWAYS recompute fictive reserves\n            (newFictiveReserveIn_, newFictiveReserveOut_) = computeFictiveReserves(\n                newReserveIn_,\n                newReserveOut_,\n                newFictiveReserveIn_,\n                newFictiveReserveOut_\n            );\n\n            uint256 _secondAmountIn;\n            (\n                _secondAmountIn,\n                newReserveIn_,\n                newReserveOut_,\n                newFictiveReserveIn_,\n                newFictiveReserveOut_\n            ) = applyKConstRuleIn(\n                SmardexLibrary.GetAmountParameters({\n                    amount: _param.amount - _firstAmountOut,\n                    reserveIn: newReserveIn_,\n                    reserveOut: newReserveOut_,\n                    fictiveReserveIn: newFictiveReserveIn_,\n                    fictiveReserveOut: newFictiveReserveOut_,\n                    priceAverageIn: _param.priceAverageIn,\n                    priceAverageOut: _param.priceAverageOut,\n                    feesLP: _param.feesLP,\n                    feesPool: _param.feesPool\n                })\n            );\n            amountIn_ += _secondAmountIn;\n        }\n    }\n}\n"
      },
      "contracts/core/libraries/TransferHelper.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity =0.8.17;\n\n/**\n * @title TransferHelper\n * @notice helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false\n * @custom:from Uniswap lib, adapted to version 0.8.17\n * @custom:url https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/TransferHelper.sol\n */\nlibrary TransferHelper {\n    function safeApprove(address token, address to, uint256 value) internal {\n        // bytes4(keccak256(bytes('approve(address,uint256)')));\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            \"TransferHelper::safeApprove: approve failed\"\n        );\n    }\n\n    function safeTransfer(address token, address to, uint256 value) internal {\n        // bytes4(keccak256(bytes('transfer(address,uint256)')));\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            \"TransferHelper::safeTransfer: transfer failed\"\n        );\n    }\n\n    function safeTransferFrom(address token, address from, address to, uint256 value) internal {\n        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            \"TransferHelper::transferFrom: transferFrom failed\"\n        );\n    }\n\n    function safeTransferETH(address to, uint256 value) internal {\n        (bool success, ) = to.call{ value: value }(new bytes(0));\n        require(success, \"TransferHelper::safeTransferETH: ETH transfer failed\");\n    }\n}\n"
      },
      "contracts/core/SmardexPair.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity =0.8.17;\n\n// contracts\nimport \"@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol\";\n\n// libraries\nimport \"@openzeppelin/contracts/utils/math/SafeCast.sol\";\nimport \"./libraries/SmardexLibrary.sol\";\nimport \"./libraries/TransferHelper.sol\";\n\n// interfaces\nimport \"./interfaces/ISmardexPair.sol\";\nimport \"./interfaces/ISmardexOwnableFactory.sol\";\nimport \"./interfaces/ISmardexSwapCallback.sol\";\nimport \"./interfaces/ISmardexMintCallback.sol\";\n\n/**\n * @title SmardexPair\n * @notice Pair contract that allows user to swap 2 ERC20-strict tokens in a decentralised and automated way\n */\ncontract SmardexPair is ISmardexPair, ERC20Permit {\n    using SafeCast for uint256;\n    using SafeCast for int256;\n\n    uint8 private constant CONTRACT_UNLOCKED = 1;\n    uint8 private constant CONTRACT_LOCKED = 2;\n    uint256 private constant MINIMUM_LIQUIDITY = 10 ** 3;\n    bytes4 private constant AUTOSWAP_SELECTOR = bytes4(keccak256(bytes(\"executeWork(address,address)\")));\n\n    address public immutable factory;\n    address public token0;\n    address public token1;\n\n    // smardex pair fees numerators, denominator is 1_000_000\n    uint128 internal feesLP = 1; // numerator of fees sent to lp, min 1,\n    uint128 internal feesPool; // numerator of fees sent to pool\n\n    // smardex new fictive reserves\n    uint128 internal fictiveReserve0;\n    uint128 internal fictiveReserve1; // accessible via getFictiveReserves()\n\n    // moving average on the price\n    uint128 internal priceAverage0;\n    uint128 internal priceAverage1;\n    uint40 internal priceAverageLastTimestamp; // accessible via getPriceAverage()\n\n    // fee for FEE_POOL\n    uint104 internal feeToAmount0;\n    uint104 internal feeToAmount1; // accessible via getFeeToAmounts()\n\n    // reentrancy\n    uint8 private lockStatus = CONTRACT_UNLOCKED;\n\n    modifier lock() {\n        require(lockStatus == CONTRACT_UNLOCKED, \"SmarDex: LOCKED\");\n        lockStatus = CONTRACT_LOCKED;\n        _;\n        lockStatus = CONTRACT_UNLOCKED;\n    }\n\n    modifier onlyFactoryOwner() {\n        require(msg.sender == ISmardexOwnableFactory(factory).owner(), \"SmarDex: NOT_OWNER\");\n        _;\n    }\n\n    constructor() ERC20(\"SmarDex LP-Token\", \"SDEX-LP\") ERC20Permit(\"SmarDex LP-Token\") {\n        factory = msg.sender;\n    }\n\n    ///@inheritdoc ISmardexPair\n    function initialize(address _token0, address _token1, uint128 _feesLP, uint128 _feesPool) external override {\n        require(msg.sender == factory, \"SmarDex: FORBIDDEN\"); // sufficient check\n        token0 = _token0;\n        token1 = _token1;\n        _setFees(_feesLP, _feesPool);\n    }\n\n    ///@inheritdoc ISmardexPair\n    function getReserves() external view override returns (uint256 reserve0_, uint256 reserve1_) {\n        reserve0_ = IERC20(token0).balanceOf(address(this)) - feeToAmount0;\n        reserve1_ = IERC20(token1).balanceOf(address(this)) - feeToAmount1;\n    }\n\n    ///@inheritdoc ISmardexPair\n    function getFictiveReserves() external view override returns (uint256 fictiveReserve0_, uint256 fictiveReserve1_) {\n        fictiveReserve0_ = fictiveReserve0;\n        fictiveReserve1_ = fictiveReserve1;\n    }\n\n    ///@inheritdoc ISmardexPair\n    function getFeeToAmounts() external view override returns (uint256 fees0_, uint256 fees1_) {\n        fees0_ = feeToAmount0;\n        fees1_ = feeToAmount1;\n    }\n\n    ///@inheritdoc ISmardexPair\n    function getPairFees() external view override returns (uint128 feesLP_, uint128 feesPool_) {\n        feesLP_ = feesLP;\n        feesPool_ = feesPool;\n    }\n\n    ///@inheritdoc ISmardexPair\n    function getPriceAverage()\n        external\n        view\n        returns (uint256 priceAverage0_, uint256 priceAverage1_, uint256 priceAverageLastTimestamp_)\n    {\n        priceAverage0_ = priceAverage0;\n        priceAverage1_ = priceAverage1;\n        priceAverageLastTimestamp_ = priceAverageLastTimestamp;\n    }\n\n    ///@inheritdoc ISmardexPair\n    function getUpdatedPriceAverage(\n        uint256 _fictiveReserveIn,\n        uint256 _fictiveReserveOut,\n        uint256 _priceAverageLastTimestamp,\n        uint256 _priceAverageIn,\n        uint256 _priceAverageOut,\n        uint256 _currentTimestamp\n    ) public pure returns (uint256 priceAverageIn_, uint256 priceAverageOut_) {\n        (priceAverageIn_, priceAverageOut_) = SmardexLibrary.getUpdatedPriceAverage(\n            _fictiveReserveIn,\n            _fictiveReserveOut,\n            _priceAverageLastTimestamp,\n            _priceAverageIn,\n            _priceAverageOut,\n            _currentTimestamp\n        );\n    }\n\n    ///@inheritdoc ISmardexPair\n    function mint(\n        address _to,\n        uint256 _amount0,\n        uint256 _amount1,\n        address _payer\n    ) external override returns (uint256 liquidity_) {\n        liquidity_ = _mintBeforeFee(_to, _amount0, _amount1, _payer);\n\n        // we call feeTo out of the internal locked mint (_mintExt) function to be able to swap fees in here\n        _feeToSwap();\n    }\n\n    ///@inheritdoc ISmardexPair\n    function burn(address _to) external override returns (uint256 amount0_, uint256 amount1_) {\n        (amount0_, amount1_) = _burnBeforeFee(_to);\n\n        // we call feeTo out of the internal locked burn (_burnExt) function to be able to swap fees in here\n        _feeToSwap();\n    }\n\n    ///@inheritdoc ISmardexPair\n    function swap(\n        address _to,\n        bool _zeroForOne,\n        int256 _amountSpecified,\n        bytes calldata _data\n    ) external override lock returns (int256 amount0_, int256 amount1_) {\n        require(_amountSpecified != 0, \"SmarDex: ZERO_AMOUNT\");\n\n        ISmardexPair.SwapParams memory _params = SwapParams({\n            amountCalculated: 0,\n            fictiveReserveIn: 0,\n            fictiveReserveOut: 0,\n            priceAverageIn: 0,\n            priceAverageOut: 0,\n            token0: token0,\n            token1: token1,\n            balanceIn: 0,\n            balanceOut: 0\n        });\n\n        require(_to != _params.token0 && _to != _params.token1, \"SmarDex: INVALID_TO\");\n        (\n            _params.balanceIn,\n            _params.balanceOut,\n            _params.fictiveReserveIn,\n            _params.fictiveReserveOut,\n            _params.priceAverageIn,\n            _params.priceAverageOut\n        ) = _zeroForOne\n            ? (\n                IERC20(_params.token0).balanceOf(address(this)) - feeToAmount0,\n                IERC20(_params.token1).balanceOf(address(this)) - feeToAmount1,\n                fictiveReserve0,\n                fictiveReserve1,\n                priceAverage0,\n                priceAverage1\n            )\n            : (\n                IERC20(_params.token1).balanceOf(address(this)) - feeToAmount1,\n                IERC20(_params.token0).balanceOf(address(this)) - feeToAmount0,\n                fictiveReserve1,\n                fictiveReserve0,\n                priceAverage1,\n                priceAverage0\n            );\n\n        // compute new price average\n        (_params.priceAverageIn, _params.priceAverageOut) = SmardexLibrary.getUpdatedPriceAverage(\n            _params.fictiveReserveIn,\n            _params.fictiveReserveOut,\n            priceAverageLastTimestamp,\n            _params.priceAverageIn,\n            _params.priceAverageOut,\n            block.timestamp\n        );\n\n        // SSTORE new price average\n        (priceAverage0, priceAverage1, priceAverageLastTimestamp) = _zeroForOne\n            ? (_params.priceAverageIn.toUint128(), _params.priceAverageOut.toUint128(), uint40(block.timestamp))\n            : (_params.priceAverageOut.toUint128(), _params.priceAverageIn.toUint128(), uint40(block.timestamp));\n\n        uint128 _feesPool = feesPool; // caching feesPool to save gas\n\n        if (_amountSpecified > 0) {\n            uint256 _temp;\n            (_temp, , , _params.fictiveReserveIn, _params.fictiveReserveOut) = SmardexLibrary.getAmountOut(\n                SmardexLibrary.GetAmountParameters({\n                    amount: _amountSpecified.toUint256(),\n                    reserveIn: _params.balanceIn,\n                    reserveOut: _params.balanceOut,\n                    fictiveReserveIn: _params.fictiveReserveIn,\n                    fictiveReserveOut: _params.fictiveReserveOut,\n                    priceAverageIn: _params.priceAverageIn,\n                    priceAverageOut: _params.priceAverageOut,\n                    feesLP: feesLP,\n                    feesPool: _feesPool\n                })\n            );\n            _params.amountCalculated = _temp.toInt256();\n        } else {\n            uint256 _temp;\n            (_temp, , , _params.fictiveReserveIn, _params.fictiveReserveOut) = SmardexLibrary.getAmountIn(\n                SmardexLibrary.GetAmountParameters({\n                    amount: (-_amountSpecified).toUint256(),\n                    reserveIn: _params.balanceIn,\n                    reserveOut: _params.balanceOut,\n                    fictiveReserveIn: _params.fictiveReserveIn,\n                    fictiveReserveOut: _params.fictiveReserveOut,\n                    priceAverageIn: _params.priceAverageIn,\n                    priceAverageOut: _params.priceAverageOut,\n                    feesLP: feesLP,\n                    feesPool: _feesPool\n                })\n            );\n            _params.amountCalculated = _temp.toInt256();\n        }\n\n        (amount0_, amount1_) = _zeroForOne\n            ? (\n                _amountSpecified > 0\n                    ? (_amountSpecified, -_params.amountCalculated)\n                    : (_params.amountCalculated, _amountSpecified)\n            )\n            : (\n                _amountSpecified > 0\n                    ? (-_params.amountCalculated, _amountSpecified)\n                    : (_amountSpecified, _params.amountCalculated)\n            );\n\n        if (_zeroForOne) {\n            if (amount1_ < 0) {\n                TransferHelper.safeTransfer(_params.token1, _to, uint256(-amount1_));\n            }\n            ISmardexSwapCallback(msg.sender).smardexSwapCallback(amount0_, amount1_, _data);\n            uint256 _balanceInBefore = _params.balanceIn;\n            _params.balanceIn = IERC20(token0).balanceOf(address(this));\n            require(\n                _balanceInBefore + feeToAmount0 + (amount0_).toUint256() <= _params.balanceIn,\n                \"SmarDex: INSUFFICIENT_TOKEN0_INPUT_AMOUNT\"\n            );\n            _params.balanceOut = IERC20(token1).balanceOf(address(this));\n        } else {\n            if (amount0_ < 0) {\n                TransferHelper.safeTransfer(_params.token0, _to, uint256(-amount0_));\n            }\n            ISmardexSwapCallback(msg.sender).smardexSwapCallback(amount0_, amount1_, _data);\n            uint256 _balanceInBefore = _params.balanceIn;\n            _params.balanceIn = IERC20(token1).balanceOf(address(this));\n            require(\n                _balanceInBefore + feeToAmount1 + (amount1_).toUint256() <= _params.balanceIn,\n                \"SmarDex: INSUFFICIENT_TOKEN1_INPUT_AMOUNT\"\n            );\n            _params.balanceOut = IERC20(token0).balanceOf(address(this));\n        }\n\n        // update feeTopart\n        bool _feeOn = ISmardexOwnableFactory(factory).feeTo() != address(0);\n        if (_zeroForOne) {\n            if (_feeOn) {\n                feeToAmount0 += ((uint256(amount0_) * _feesPool) / SmardexLibrary.FEES_BASE).toUint104();\n            }\n            _update(\n                _params.balanceIn,\n                _params.balanceOut,\n                _params.fictiveReserveIn,\n                _params.fictiveReserveOut,\n                _params.priceAverageIn,\n                _params.priceAverageOut\n            );\n        } else {\n            if (_feeOn) {\n                feeToAmount1 += ((uint256(amount1_) * _feesPool) / SmardexLibrary.FEES_BASE).toUint104();\n            }\n            _update(\n                _params.balanceOut,\n                _params.balanceIn,\n                _params.fictiveReserveOut,\n                _params.fictiveReserveIn,\n                _params.priceAverageOut,\n                _params.priceAverageIn\n            );\n        }\n\n        emit Swap(msg.sender, _to, amount0_, amount1_);\n    }\n\n    ///@inheritdoc ISmardexPair\n    function setFees(uint128 _feesLP, uint128 _feesPool) external onlyFactoryOwner {\n        _setFees(_feesLP, _feesPool);\n    }\n\n    /**\n     * @notice set feesLP and feesPool of the pair\n     * @notice sum of new feesLp and feesPool must be <= 100_000\n     * @param _feesLP new numerator of fees sent to LP, must be >= 1\n     * @param _feesPool new numerator of fees sent to Pool, could be = 0\n     */\n    function _setFees(uint128 _feesLP, uint128 _feesPool) internal {\n        require(_feesLP != 0, \"SmarDex: ZERO_FEES_LP\");\n        require(_feesLP + _feesPool <= SmardexLibrary.FEES_MAX, \"SmarDex: FEES_MAX\");\n        feesLP = _feesLP;\n        feesPool = _feesPool;\n\n        emit FeesChanged(_feesLP, _feesPool);\n    }\n\n    /**\n     * @notice update fictive reserves and emit the Sync event\n     * @param _balance0 the new balance of token0\n     * @param _balance1 the new balance of token1\n     * @param _fictiveReserve0 the new fictive reserves of token0\n     * @param _fictiveReserve1 the new fictive reserves of token1\n     * @param _priceAverage0 the new priceAverage of token0\n     * @param _priceAverage1 the new priceAverage of token1\n     */\n    function _update(\n        uint256 _balance0,\n        uint256 _balance1,\n        uint256 _fictiveReserve0,\n        uint256 _fictiveReserve1,\n        uint256 _priceAverage0,\n        uint256 _priceAverage1\n    ) private {\n        require(_fictiveReserve0 != 0 && _fictiveReserve1 != 0, \"SmarDex: FICTIVE_RESERVES_TOO_LOW\");\n        require(_fictiveReserve0 <= type(uint128).max && _fictiveReserve1 <= type(uint128).max, \"SmarDex: OVERFLOW\");\n        fictiveReserve0 = uint128(_fictiveReserve0);\n        fictiveReserve1 = uint128(_fictiveReserve1);\n\n        emit Sync(\n            _balance0 - feeToAmount0,\n            _balance1 - feeToAmount1,\n            _fictiveReserve0,\n            _fictiveReserve1,\n            _priceAverage0,\n            _priceAverage1\n        );\n    }\n\n    /**\n     * @notice transfers feeToAmount of tokens 0 and 1 to feeTo, and reset feeToAmounts\n     * @return feeOn_ if part of the fees goes to feeTo\n     */\n    function _sendFee() private returns (bool feeOn_) {\n        address _feeTo = ISmardexFactory(factory).feeTo();\n        feeOn_ = _feeTo != address(0);\n        if (feeOn_) {\n            // gas saving\n            uint256 _feeToAmount0 = feeToAmount0;\n            uint256 _feeToAmount1 = feeToAmount1;\n\n            if (_feeToAmount0 != 0) {\n                TransferHelper.safeTransfer(token0, _feeTo, _feeToAmount0);\n                feeToAmount0 = 0;\n            }\n            if (_feeToAmount1 != 0) {\n                TransferHelper.safeTransfer(token1, _feeTo, _feeToAmount1);\n                feeToAmount1 = 0;\n            }\n        } else {\n            feeToAmount0 = 0;\n            feeToAmount1 = 0;\n        }\n    }\n\n    /**\n     * @notice Mint lp tokens proportionally of added tokens in balance.\n     * @param _to address who will receive minted tokens\n     * @param _amount0 amount of token0 to provide\n     * @param _amount1 amount of token1 to provide\n     * @param _payer address of the payer to provide token for the mint\n     * @return liquidity_ amount of lp tokens minted and sent to the address defined in parameter\n     */\n    function _mintBeforeFee(\n        address _to,\n        uint256 _amount0,\n        uint256 _amount1,\n        address _payer\n    ) internal lock returns (uint256 liquidity_) {\n        _sendFee();\n\n        uint256 _fictiveReserve0;\n        uint256 _fictiveReserve1;\n\n        // gas saving\n        uint256 _balance0 = IERC20(token0).balanceOf(address(this));\n        uint256 _balance1 = IERC20(token1).balanceOf(address(this));\n        uint256 _totalSupply = totalSupply();\n\n        ISmardexMintCallback(msg.sender).smardexMintCallback(\n            ISmardexMintCallback.MintCallbackData({\n                token0: token0,\n                token1: token1,\n                amount0: _amount0,\n                amount1: _amount1,\n                payer: _payer\n            })\n        );\n\n        // gas savings\n        uint256 _balance0after = IERC20(token0).balanceOf(address(this));\n        uint256 _balance1after = IERC20(token1).balanceOf(address(this));\n\n        require(_balance0after >= _balance0 + _amount0, \"SmarDex: INSUFFICIENT_AMOUNT_0\");\n        require(_balance1after >= _balance1 + _amount1, \"SmarDex: INSUFFICIENT_AMOUNT_1\");\n\n        if (_totalSupply == 0) {\n            liquidity_ = Math.sqrt(_amount0 * _amount1) - MINIMUM_LIQUIDITY;\n            _mint(address(0xdead), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens\n            _fictiveReserve0 = _balance0after / 2;\n            _fictiveReserve1 = _balance1after / 2;\n        } else {\n            liquidity_ = Math.min((_amount0 * _totalSupply) / _balance0, (_amount1 * _totalSupply) / _balance1);\n\n            // update proportionally the fictiveReserves\n            _fictiveReserve0 = (fictiveReserve0 * (_totalSupply + liquidity_)) / _totalSupply;\n            _fictiveReserve1 = (fictiveReserve1 * (_totalSupply + liquidity_)) / _totalSupply;\n        }\n\n        require(liquidity_ != 0, \"SmarDex: INSUFFICIENT_LIQUIDITY_MINTED\");\n        _mint(_to, liquidity_);\n\n        _update(_balance0after, _balance1after, _fictiveReserve0, _fictiveReserve1, priceAverage0, priceAverage1);\n\n        emit Mint(msg.sender, _to, _amount0, _amount1);\n    }\n\n    /**\n     * @notice Burn lp tokens in the balance of the contract. Sends to the defined address the amount of token0 and\n     * token1 proportionally of the amount burned.\n     * @param _to address who will receive tokens\n     * @return amount0_ amount of token0 sent to the address defined in parameter\n     * @return amount1_ amount of token0 sent to the address defined in parameter\n     */\n    function _burnBeforeFee(address _to) internal lock returns (uint256 amount0_, uint256 amount1_) {\n        _sendFee();\n\n        // gas savings\n        address _token0 = token0;\n        address _token1 = token1;\n        uint256 _balance0 = IERC20(_token0).balanceOf(address(this));\n        uint256 _balance1 = IERC20(_token1).balanceOf(address(this));\n        uint256 _liquidity = balanceOf(address(this));\n        uint256 _totalSupply = totalSupply();\n\n        // pro-rata distribution\n        amount0_ = (_liquidity * _balance0) / _totalSupply;\n        amount1_ = (_liquidity * _balance1) / _totalSupply;\n        require(amount0_ != 0 && amount1_ != 0, \"SmarDex: INSUFFICIENT_LIQUIDITY_BURNED\");\n\n        // update proportionally the fictiveReserves\n        uint256 _fictiveReserve0 = fictiveReserve0;\n        uint256 _fictiveReserve1 = fictiveReserve1;\n        _fictiveReserve0 -= (_fictiveReserve0 * _liquidity) / _totalSupply;\n        _fictiveReserve1 -= (_fictiveReserve1 * _liquidity) / _totalSupply;\n\n        _burn(address(this), _liquidity);\n        TransferHelper.safeTransfer(_token0, _to, amount0_);\n        TransferHelper.safeTransfer(_token1, _to, amount1_);\n\n        _balance0 = IERC20(_token0).balanceOf(address(this));\n        _balance1 = IERC20(_token1).balanceOf(address(this));\n\n        _update(_balance0, _balance1, _fictiveReserve0, _fictiveReserve1, priceAverage0, priceAverage1);\n\n        emit Burn(msg.sender, _to, amount0_, amount1_);\n    }\n\n    /**\n     * @notice execute function \"executeWork(address,address)\" of the feeTo contract. Doesn't revert tx if it reverts\n     */\n    function _feeToSwap() internal {\n        address _feeTo = ISmardexOwnableFactory(factory).feeTo();\n\n        // call contract destination for handling fees\n        // We don't handle return values so it does not revert for LP if something went wrong in feeTo\n        // Will swap fees to SDEX and send them. We want this to not revert if the swap failed\n        // but to revert if not enough gas\n        _feeTo.call(abi.encodeWithSelector(AUTOSWAP_SELECTOR, token0, token1));\n\n        // After the _feeTo call, we check if gas is not equal to 0. Though seemingly redundant\n        // (as running out of gas would fail the transaction anyway), this require prevents the\n        // compiler from ignoring a simple gasleft() expression, which it may perceive as\n        // useless if not used elsewhere. The aim here is to consume some gas to ensure the\n        // transaction isn't out of gas at this point. This acts as a safeguard against potential\n        // exploitation where a low gasLimit prevents the _feeTo call from fully executing.\n        require(gasleft() != 0, \"\");\n    }\n\n    ///@inheritdoc ISmardexPair\n    function skim(address _to) external lock {\n        require(totalSupply() == 0, \"SmarDex: ONLY_EMPTY_PAIR\");\n\n        // gas savings\n        address _token0 = token0;\n        address _token1 = token1;\n        uint256 _balance0 = IERC20(_token0).balanceOf(address(this));\n        uint256 _balance1 = IERC20(_token1).balanceOf(address(this));\n\n        if (_balance0 != 0) {\n            TransferHelper.safeTransfer(_token0, _to, _balance0);\n        }\n        if (_balance1 != 0) {\n            TransferHelper.safeTransfer(_token1, _to, _balance1);\n        }\n    }\n}\n"
      }
    },
    "settings": {
      "metadata": {
        "bytecodeHash": "none",
        "useLiteralContent": true
      },
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}