File size: 111,240 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
  "language": "Solidity",
  "sources": {
    "@openzeppelin/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
    },
    "@openzeppelin/contracts/proxy/Clones.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (proxy/Clones.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for\n * deploying minimal proxy contracts, also known as \"clones\".\n *\n * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies\n * > a minimal bytecode implementation that delegates all calls to a known, fixed address.\n *\n * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`\n * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the\n * deterministic method.\n *\n * _Available since v3.4._\n */\nlibrary Clones {\n    /**\n     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\n     *\n     * This function uses the create opcode, which should never revert.\n     */\n    function clone(address implementation) internal returns (address instance) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes\n            // of the `implementation` address with the bytecode before the address.\n            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))\n            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.\n            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))\n            instance := create(0, 0x09, 0x37)\n        }\n        require(instance != address(0), \"ERC1167: create failed\");\n    }\n\n    /**\n     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\n     *\n     * This function uses the create2 opcode and a `salt` to deterministically deploy\n     * the clone. Using the same `implementation` and `salt` multiple time will revert, since\n     * the clones cannot be deployed twice at the same address.\n     */\n    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes\n            // of the `implementation` address with the bytecode before the address.\n            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))\n            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.\n            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))\n            instance := create2(0, 0x09, 0x37, salt)\n        }\n        require(instance != address(0), \"ERC1167: create2 failed\");\n    }\n\n    /**\n     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\n     */\n    function predictDeterministicAddress(\n        address implementation,\n        bytes32 salt,\n        address deployer\n    ) internal pure returns (address predicted) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let ptr := mload(0x40)\n            mstore(add(ptr, 0x38), deployer)\n            mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)\n            mstore(add(ptr, 0x14), implementation)\n            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)\n            mstore(add(ptr, 0x58), salt)\n            mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))\n            predicted := keccak256(add(ptr, 0x43), 0x55)\n        }\n    }\n\n    /**\n     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\n     */\n    function predictDeterministicAddress(address implementation, bytes32 salt)\n        internal\n        view\n        returns (address predicted)\n    {\n        return predictDeterministicAddress(implementation, salt, address(this));\n    }\n}\n"
    },
    "@openzeppelin/contracts/security/Pausable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n    /**\n     * @dev Emitted when the pause is triggered by `account`.\n     */\n    event Paused(address account);\n\n    /**\n     * @dev Emitted when the pause is lifted by `account`.\n     */\n    event Unpaused(address account);\n\n    bool private _paused;\n\n    /**\n     * @dev Initializes the contract in unpaused state.\n     */\n    constructor() {\n        _paused = false;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is not paused.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    modifier whenNotPaused() {\n        _requireNotPaused();\n        _;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is paused.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    modifier whenPaused() {\n        _requirePaused();\n        _;\n    }\n\n    /**\n     * @dev Returns true if the contract is paused, and false otherwise.\n     */\n    function paused() public view virtual returns (bool) {\n        return _paused;\n    }\n\n    /**\n     * @dev Throws if the contract is paused.\n     */\n    function _requireNotPaused() internal view virtual {\n        require(!paused(), \"Pausable: paused\");\n    }\n\n    /**\n     * @dev Throws if the contract is not paused.\n     */\n    function _requirePaused() internal view virtual {\n        require(paused(), \"Pausable: not paused\");\n    }\n\n    /**\n     * @dev Triggers stopped state.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    function _pause() internal virtual whenNotPaused {\n        _paused = true;\n        emit Paused(_msgSender());\n    }\n\n    /**\n     * @dev Returns to normal state.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    function _unpause() internal virtual whenPaused {\n        _paused = false;\n        emit Unpaused(_msgSender());\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface 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.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface 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(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/draft-IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using Address for address;\n\n    function safeTransfer(\n        IERC20 token,\n        address to,\n        uint256 value\n    ) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(\n        IERC20 token,\n        address from,\n        address to,\n        uint256 value\n    ) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        require(\n            (value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    function safeIncreaseAllowance(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        uint256 newAllowance = token.allowance(address(this), spender) + value;\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        unchecked {\n            uint256 oldAllowance = token.allowance(address(this), spender);\n            require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n            uint256 newAllowance = oldAllowance - value;\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n        }\n    }\n\n    function safePermit(\n        IERC20Permit token,\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        uint256 nonceBefore = token.nonces(owner);\n        token.permit(owner, spender, value, deadline, v, r, s);\n        uint256 nonceAfter = token.nonces(owner);\n        require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        if (returndata.length > 0) {\n            // Return data is optional\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Address.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/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/cryptography/ECDSA.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../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(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address, RecoverError) {\n        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n        uint8 v = uint8((uint256(vs) >> 255) + 27);\n        return tryRecover(hash, v, r, s);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n     *\n     * _Available since v4.2._\n     */\n    function recover(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address, RecoverError) {\n        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n        // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n        //\n        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n        // these malleable signatures as well.\n        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n            return (address(0), RecoverError.InvalidSignatureS);\n        }\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        if (signer == address(0)) {\n            return (address(0), RecoverError.InvalidSignature);\n        }\n\n        return (signer, RecoverError.NoError);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     */\n    function recover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n        // 32 is the length in bytes of hash,\n        // enforced by the type signature above\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from `s`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", 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) {\n        return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/math/Math.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary 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(\n        uint256 x,\n        uint256 y,\n        uint256 denominator\n    ) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod0 := mul(x, y)\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            require(denominator > prod1);\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n            // See https://cs.stackexchange.com/q/138556/92363.\n\n            // Does not overflow because the denominator cannot be zero at this stage in the function.\n            uint256 twos = denominator & (~denominator + 1);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n            // in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(\n        uint256 x,\n        uint256 y,\n        uint256 denominator,\n        Rounding rounding\n    ) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10**64) {\n                value /= 10**64;\n                result += 64;\n            }\n            if (value >= 10**32) {\n                value /= 10**32;\n                result += 32;\n            }\n            if (value >= 10**16) {\n                value /= 10**16;\n                result += 16;\n            }\n            if (value >= 10**8) {\n                value /= 10**8;\n                result += 8;\n            }\n            if (value >= 10**4) {\n                value /= 10**4;\n                result += 4;\n            }\n            if (value >= 10**2) {\n                value /= 10**2;\n                result += 2;\n            }\n            if (value >= 10**1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/StorageSlot.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```\n * contract ERC1967 {\n *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n *     function _getImplementation() internal view returns (address) {\n *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n *     }\n *\n *     function _setImplementation(address newImplementation) internal {\n *         require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n *     }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\n */\nlibrary 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    /**\n     * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n     */\n    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n     */\n    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n     */\n    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n     */\n    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r.slot := slot\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Strings.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.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 `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"
    },
    "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)\n// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n *     // Add the library methods\n *     using EnumerableSet for EnumerableSet.AddressSet;\n *\n *     // Declare a set state variable\n *     EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n *\n * [WARNING]\n * ====\n * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure\n * unusable.\n * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.\n *\n * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an\n * array of EnumerableSet.\n * ====\n */\nlibrary EnumerableSet {\n    // To implement this library for multiple types with as little code\n    // repetition as possible, we write it in terms of a generic Set type with\n    // bytes32 values.\n    // The Set implementation uses private functions, and user-facing\n    // implementations (such as AddressSet) are just wrappers around the\n    // underlying Set.\n    // This means that we can only create new EnumerableSets for types that fit\n    // in bytes32.\n\n    struct Set {\n        // Storage of set values\n        bytes32[] _values;\n        // Position of the value in the `values` array, plus 1 because index 0\n        // means a value is not in the set.\n        mapping(bytes32 => uint256) _indexes;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function _add(Set storage set, bytes32 value) private returns (bool) {\n        if (!_contains(set, value)) {\n            set._values.push(value);\n            // The value is stored at length-1, but we add 1 to all indexes\n            // and use 0 as a sentinel value\n            set._indexes[value] = set._values.length;\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function _remove(Set storage set, bytes32 value) private returns (bool) {\n        // We read and store the value's index to prevent multiple reads from the same storage slot\n        uint256 valueIndex = set._indexes[value];\n\n        if (valueIndex != 0) {\n            // Equivalent to contains(set, value)\n            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n            // the array, and then remove the last element (sometimes called as 'swap and pop').\n            // This modifies the order of the array, as noted in {at}.\n\n            uint256 toDeleteIndex = valueIndex - 1;\n            uint256 lastIndex = set._values.length - 1;\n\n            if (lastIndex != toDeleteIndex) {\n                bytes32 lastValue = set._values[lastIndex];\n\n                // Move the last value to the index where the value to delete is\n                set._values[toDeleteIndex] = lastValue;\n                // Update the index for the moved value\n                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n            }\n\n            // Delete the slot where the moved value was stored\n            set._values.pop();\n\n            // Delete the index for the deleted slot\n            delete set._indexes[value];\n\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function _contains(Set storage set, bytes32 value) private view returns (bool) {\n        return set._indexes[value] != 0;\n    }\n\n    /**\n     * @dev Returns the number of values on the set. O(1).\n     */\n    function _length(Set storage set) private view returns (uint256) {\n        return set._values.length;\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function _at(Set storage set, uint256 index) private view returns (bytes32) {\n        return set._values[index];\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function _values(Set storage set) private view returns (bytes32[] memory) {\n        return set._values;\n    }\n\n    // Bytes32Set\n\n    struct Bytes32Set {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _add(set._inner, value);\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _remove(set._inner, value);\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n        return _contains(set._inner, value);\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(Bytes32Set storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n        return _at(set._inner, index);\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        bytes32[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n\n    // AddressSet\n\n    struct AddressSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(AddressSet storage set, address value) internal returns (bool) {\n        return _add(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(AddressSet storage set, address value) internal returns (bool) {\n        return _remove(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(AddressSet storage set, address value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(AddressSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(AddressSet storage set, uint256 index) internal view returns (address) {\n        return address(uint160(uint256(_at(set._inner, index))));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(AddressSet storage set) internal view returns (address[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        address[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n\n    // UintSet\n\n    struct UintSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(UintSet storage set, uint256 value) internal returns (bool) {\n        return _add(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(UintSet storage set, uint256 value) internal returns (bool) {\n        return _remove(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(UintSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n        return uint256(_at(set._inner, index));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(UintSet storage set) internal view returns (uint256[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        uint256[] memory result;\n\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n}\n"
    },
    "contracts/core/asset/NativeClaimer.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nlibrary NativeClaimer {\n    struct State {\n        uint256 _valueClaimed;\n    }\n\n    function claimed(NativeClaimer.State memory claimer_) internal pure returns (uint256) {\n        return claimer_._valueClaimed;\n    }\n\n    function unclaimed(NativeClaimer.State memory claimer_) internal view returns (uint256) {\n        return msg.value - claimer_._valueClaimed;\n    }\n\n    function claim(NativeClaimer.State memory claimer_, uint256 value_) internal view {\n        require(unclaimed(claimer_) >= value_, \"NC: insufficient msg value\");\n        claimer_._valueClaimed += value_;\n    }\n}\n"
    },
    "contracts/core/asset/NativeReceiver.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nabstract contract NativeReceiver {\n    receive() external payable {}\n}\n"
    },
    "contracts/core/asset/NativeReturnMods.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {NativeClaimer} from \"./NativeClaimer.sol\";\nimport {TokenHelper} from \"./TokenHelper.sol\";\n\nabstract contract NativeReturnMods {\n    using NativeClaimer for NativeClaimer.State;\n\n    modifier returnUnclaimedNative(NativeClaimer.State memory claimer_) {\n        require(claimer_.claimed() == 0, \"NR: claimer already in use\");\n        _;\n        TokenHelper.transferFromThis(TokenHelper.NATIVE_TOKEN, msg.sender, claimer_.unclaimed());\n    }\n}\n"
    },
    "contracts/core/asset/TokenChecker.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {TokenCheck} from \"../swap/Swap.sol\";\n\nlibrary TokenChecker {\n    function checkMin(TokenCheck calldata check_, uint256 amount_) internal pure returns (uint256) {\n        order(check_); min(check_, amount_);\n        return capMax(check_, amount_);\n    }\n\n    function checkMinMax(TokenCheck calldata check_, uint256 amount_) internal pure {\n        order(check_); min(check_, amount_); max(check_, amount_);\n    }\n\n    function checkMinMaxToken(TokenCheck calldata check_, uint256 amount_, address token_) internal pure {\n        order(check_); min(check_, amount_); max(check_, amount_); token(check_, token_);\n    }\n\n    function order(TokenCheck calldata check_) private pure {\n        require(check_.minAmount <= check_.maxAmount, \"TC: unordered min/max amounts\");\n    }\n\n    function min(TokenCheck calldata check_, uint256 amount_) private pure {\n        require(amount_ >= check_.minAmount, \"TC: insufficient token amount\");\n    }\n\n    function max(TokenCheck calldata check_, uint256 amount_) private pure {\n        require(amount_ <= check_.maxAmount, \"TC: excessive token amount\");\n    }\n\n    function token(TokenCheck calldata check_, address token_) private pure {\n        require(token_ == check_.token, \"TC: wrong token address\");\n    }\n\n    function capMax(TokenCheck calldata check_, uint256 amount_) private pure returns (uint256) {\n        return amount_ < check_.maxAmount ? amount_ : check_.maxAmount;\n    }\n}\n"
    },
    "contracts/core/asset/TokenHelper.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport {SafeERC20} from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport {Address} from \"@openzeppelin/contracts/utils/Address.sol\";\nimport {NativeClaimer} from \"./NativeClaimer.sol\";\n\nlibrary TokenHelper {\n    using NativeClaimer for NativeClaimer.State;\n\n    address public constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n    modifier whenNonZero(uint256 amount_) {\n        if (amount_ == 0) return;\n        _;\n    }\n\n    function isNative(address token_) internal pure returns (bool) {\n        return token_ == NATIVE_TOKEN;\n    }\n\n    function balanceOf(address token_, address owner_, NativeClaimer.State memory claimer_) internal view returns (uint256) {\n        return isNative(token_) ? _nativeBalanceOf(owner_, claimer_) : IERC20(token_).balanceOf(owner_);\n    }\n\n    function balanceOfThis(address token_, NativeClaimer.State memory claimer_) internal view returns (uint256) {\n        return balanceOf(token_, address(this), claimer_);\n    }\n\n    function transferToThis(address token_, address from_, uint256 amount_, NativeClaimer.State memory claimer_) internal whenNonZero(amount_) {\n        if (isNative(token_)) {\n            require(from_ == msg.sender, \"TH: native allows sender only\");\n            claimer_.claim(amount_);\n        } else SafeERC20.safeTransferFrom(IERC20(token_), from_, address(this), amount_);\n    }\n\n    function transferFromThis(address token_, address to_, uint256 amount_) internal whenNonZero(amount_) {\n        isNative(token_) ? Address.sendValue(payable(to_), amount_) : SafeERC20.safeTransfer(IERC20(token_), to_, amount_);\n    }\n\n    function approveOfThis(address token_, address spender_, uint256 amount_) internal whenNonZero(amount_) returns (uint256 sendValue) {\n        if (isNative(token_)) sendValue = amount_;\n        else SafeERC20.safeApprove(IERC20(token_), spender_, amount_);\n    }\n\n    function revokeOfThis(address token_, address spender_) internal {\n        if (!isNative(token_)) SafeERC20.safeApprove(IERC20(token_), spender_, 0);\n    }\n\n    function _nativeBalanceOf(address owner_, NativeClaimer.State memory claimer_) private view returns (uint256 balance) {\n        if (owner_ == msg.sender) balance = claimer_.unclaimed();\n        else {\n            balance = owner_.balance;\n            if (owner_ == address(this)) balance -= claimer_.unclaimed();\n        }\n    }\n}\n"
    },
    "contracts/core/delegate/Delegate.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {NativeReceiver} from \"../asset/NativeReceiver.sol\";\nimport {SimpleInitializable} from \"../misc/SimpleInitializable.sol\";\nimport {Withdrawable} from \"../withdraw/Withdrawable.sol\";\n\ncontract Delegate is SimpleInitializable, Ownable, Withdrawable, NativeReceiver {\n    constructor() {\n        _initializeWithSender();\n    }\n\n    function _initialize() internal override {\n        _transferOwnership(initializer());\n    }\n\n    function setOwner(address newOwner_) external whenInitialized onlyInitializer {\n        _transferOwnership(newOwner_);\n    }\n\n    function _checkWithdraw() internal view override {\n        _ensureInitialized();\n        _checkOwner();\n    }\n}\n"
    },
    "contracts/core/delegate/DelegateManager.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {Clones} from \"@openzeppelin/contracts/proxy/Clones.sol\";\nimport {Address} from \"@openzeppelin/contracts/utils/Address.sol\";\nimport {AccountWhitelist} from \"../whitelist/AccountWhitelist.sol\";\nimport {Withdraw} from \"../withdraw/Withdrawable.sol\";\nimport {Delegate} from \"./Delegate.sol\";\n\ncontract DelegateManager {\n    address private immutable _delegatePrototype;\n    address private immutable _withdrawWhitelist;\n\n    constructor(address delegatePrototype_, address withdrawWhitelist_) {\n        _delegatePrototype = delegatePrototype_;\n        _withdrawWhitelist = withdrawWhitelist_;\n    }\n\n    modifier onlyWhitelistedWithdrawer() {\n        require(AccountWhitelist(_withdrawWhitelist).isAccountWhitelisted(msg.sender), \"DM: withdrawer not whitelisted\");\n        _;\n    }\n\n    function predictDelegateDeploy(address account_) public view returns (address) {\n        return Clones.predictDeterministicAddress(_delegatePrototype, _calcSalt(account_));\n    }\n\n    function deployDelegate(address account_) public returns (address) {\n        Delegate delegate = Delegate(payable(Clones.cloneDeterministic(_delegatePrototype, _calcSalt(account_))));\n        delegate.initialize();\n        delegate.transferOwnership(account_);\n        return address(delegate);\n    }\n\n    function isDelegateDeployed(address account_) public view returns (bool) {\n        return Address.isContract(predictDelegateDeploy(account_));\n    }\n\n    function withdraw(address account_, Withdraw[] calldata withdraws_) external onlyWhitelistedWithdrawer {\n        Delegate delegate = Delegate(payable(predictDelegateDeploy(account_)));\n        address savedOwner = delegate.owner();\n        delegate.setOwner(address(this));\n        delegate.withdraw(withdraws_);\n        delegate.setOwner(savedOwner);\n    }\n\n    function _calcSalt(address account_) private pure returns (bytes32) {\n        return bytes20(account_);\n    }\n}\n"
    },
    "contracts/core/misc/AccountCounter.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nlibrary AccountCounter {\n    uint256 private constant _ACCOUNT_MIXIN = 0xacc0acc0acc0acc0acc0acc0acc0acc0acc0acc0acc0acc0acc0acc0acc0acc0;\n    uint256 private constant _NULL_INDEX = type(uint256).max;\n\n    struct State {\n        uint256[] _accounts;\n        uint256[] _counts;\n        uint256 _size;\n    }\n\n    using AccountCounter for State;\n\n    function create(uint256 maxSize_) internal pure returns (AccountCounter.State memory accountCounter) {\n        accountCounter._accounts = new uint256[](maxSize_);\n        accountCounter._counts = new uint256[](maxSize_);\n    }\n\n    function size(AccountCounter.State memory accountCounter_) internal pure returns (uint256) {\n        return accountCounter_._size;\n    }\n\n    function indexOf(AccountCounter.State memory accountCounter_, address account_, bool insert_) internal pure returns (uint256) {\n        uint256 targetAccount = uint160(account_) ^ _ACCOUNT_MIXIN;\n        for (uint256 i = 0; i < accountCounter_._accounts.length; i++) {\n            uint256 iAccount = accountCounter_._accounts[i];\n            if (iAccount == targetAccount) return i;\n            if (iAccount == 0) {\n                if (!insert_) return _NULL_INDEX;\n                accountCounter_._accounts[i] = targetAccount;\n                accountCounter_._size = i + 1;\n                return i;\n            }\n        }\n        if (!insert_) return _NULL_INDEX;\n        revert(\"AC: insufficient size\");\n    }\n\n    function indexOf(AccountCounter.State memory accountCounter_, address account_) internal pure returns (uint256) {\n        return indexOf(accountCounter_, account_, true);\n    }\n\n    function isNullIndex(uint256 index_) internal pure returns (bool) {\n        return index_ == _NULL_INDEX;\n    }\n\n    function accountAt(AccountCounter.State memory accountCounter_, uint256 index_) internal pure returns (address) {\n        return address(uint160(accountCounter_._accounts[index_] ^ _ACCOUNT_MIXIN));\n    }\n\n    function get(AccountCounter.State memory accountCounter_, address account_) internal pure returns (uint256) {\n        return getAt(accountCounter_, indexOf(accountCounter_, account_));\n    }\n\n    function getAt(AccountCounter.State memory accountCounter_, uint256 index_) internal pure returns (uint256) {\n        return accountCounter_._counts[index_];\n    }\n\n    function set(AccountCounter.State memory accountCounter_, address account_, uint256 count_) internal pure {\n        setAt(accountCounter_, indexOf(accountCounter_, account_), count_);\n    }\n\n    function setAt(AccountCounter.State memory accountCounter_, uint256 index_, uint256 count_) internal pure {\n        accountCounter_._counts[index_] = count_;\n    }\n\n    function add(AccountCounter.State memory accountCounter_, address account_, uint256 count_) internal pure returns (uint256 newCount) {\n        return addAt(accountCounter_, indexOf(accountCounter_, account_), count_);\n    }\n\n    function addAt(AccountCounter.State memory accountCounter_, uint256 index_, uint256 count_) internal pure returns (uint256 newCount) {\n        newCount = getAt(accountCounter_, index_) + count_;\n        setAt(accountCounter_, index_, newCount);\n    }\n\n    function sub(AccountCounter.State memory accountCounter_, address account_, uint256 count_) internal pure returns (uint256 newCount) {\n        return subAt(accountCounter_, indexOf(accountCounter_, account_), count_);\n    }\n\n    function subAt(AccountCounter.State memory accountCounter_, uint256 index_, uint256 count_) internal pure returns (uint256 newCount) {\n        newCount = getAt(accountCounter_, index_) - count_;\n        setAt(accountCounter_, index_, newCount);\n    }\n}\n"
    },
    "contracts/core/misc/LifeControl.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {Pausable} from \"@openzeppelin/contracts/security/Pausable.sol\";\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract LifeControl is Ownable, Pausable {\n    event Terminated(address account);\n\n    bool public terminated;\n\n    function pause() public onlyOwner {\n        _pause();\n    }\n\n    function unpause() public onlyOwner {\n        _requireNotTerminated();\n        _unpause();\n    }\n\n    function terminate() public onlyOwner whenPaused {\n        _requireNotTerminated();\n        terminated = true;\n        emit Terminated(_msgSender());\n    }\n\n    function _requireNotTerminated() private view {\n        require(!terminated, \"LC: terminated\");\n    }\n}\n"
    },
    "contracts/core/misc/SimpleInitializable.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {StorageSlot} from \"@openzeppelin/contracts/utils/StorageSlot.sol\";\n\nabstract contract SimpleInitializable {\n    function _initializerStorage() private pure returns (StorageSlot.AddressSlot storage) {\n        return StorageSlot.getAddressSlot(0x4c943a984a6327bfee4b36cd148236ae13d07c9a3fe7f9857f4809df3e826db1);\n    }\n\n    modifier init() {\n        _ensureNotInitialized();\n        _initializeWithSender();\n        _;\n    }\n\n    modifier whenInitialized() {\n        _ensureInitialized();\n        _;\n    }\n\n    modifier onlyInitializer() {\n        require(msg.sender == initializer(), \"SI: sender not initializer\");\n        _;\n    }\n\n    function initializer() public view returns (address) {\n        return _initializerStorage().value;\n    }\n\n    function initialized() public view returns (bool) {\n        return initializer() != address(0);\n    }\n\n    function initialize() external init {\n        _initialize();\n    }\n\n    function _initialize() internal virtual;\n\n    function _initializeWithSender() internal {\n        _initializerStorage().value = msg.sender;\n    }\n\n    function _ensureInitialized() internal view {\n        require(initialized(), \"SI: not initialized\");\n    }\n\n    function _ensureNotInitialized() internal view {\n        require(!initialized(), \"SI: already initialized\");\n    }\n}\n"
    },
    "contracts/core/permit/PermitResolver.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {SafeERC20, IERC20Permit} from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport {SignatureDecomposer} from \"./SignatureDecomposer.sol\";\n\ncontract PermitResolver is SignatureDecomposer {\n    function resolvePermit(address token_, address from_, uint256 amount_, uint256 deadline_, bytes calldata signature_) external {\n        SafeERC20.safePermit(IERC20Permit(token_), from_, msg.sender, amount_, deadline_, v(signature_), r(signature_), s(signature_));\n    }\n}\n"
    },
    "contracts/core/permit/SignatureDecomposer.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nabstract contract SignatureDecomposer {\n    function r(bytes calldata sig_) internal pure returns (bytes32) { return bytes32(sig_[0:32]); }\n    function s(bytes calldata sig_) internal pure returns (bytes32) { return bytes32(sig_[32:64]); }\n    function v(bytes calldata sig_) internal pure returns (uint8) { return uint8(bytes1(sig_[64:65])); }\n}\n"
    },
    "contracts/core/swap/Swap.sol": {
      "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity ^0.8.16;\n\nstruct TokenCheck {\n    address token;\n    uint256 minAmount;\n    uint256 maxAmount;\n}\n\nstruct TokenUse {\n    address protocol;\n    uint256 chain;\n    address account;\n    uint256[] inIndices;\n    TokenCheck[] outs;\n    bytes args; // Example of reserved value: 0x44796E616D6963 (\"Dynamic\")\n}\n\nstruct SwapStep {\n    uint256 chain;\n    address swapper;\n    address sponsor;\n    uint256 nonce;\n    uint256 deadline;\n    TokenCheck[] ins;\n    TokenCheck[] outs;\n    TokenUse[] uses;\n}\n\nstruct Swap {\n    address account;\n    SwapStep[] steps;\n}\n\nstruct StealthSwap {\n    uint256 chain;\n    address swapper;\n    address account;\n    bytes32[] stepHashes;\n}\n\nstruct UseParams {\n    uint256 chain;\n    address account;\n    TokenCheck[] ins;\n    uint256[] inAmounts;\n    TokenCheck[] outs;\n    bytes args;\n    address msgSender;\n    bytes msgData;\n}\n\ninterface IUseProtocol {\n    function use(UseParams calldata params) external payable;\n}\n"
    },
    "contracts/core/swap/Swapper.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {Address} from \"@openzeppelin/contracts/utils/Address.sol\";\nimport {NativeClaimer} from \"../asset/NativeClaimer.sol\";\nimport {NativeReceiver} from \"../asset/NativeReceiver.sol\";\nimport {NativeReturnMods} from \"../asset/NativeReturnMods.sol\";\nimport {TokenChecker} from \"../asset/TokenChecker.sol\";\nimport {TokenHelper} from \"../asset/TokenHelper.sol\";\nimport {DelegateManager} from \"../delegate/DelegateManager.sol\";\nimport {AccountCounter} from \"../misc/AccountCounter.sol\";\nimport {PermitResolver} from \"../permit/PermitResolver.sol\";\nimport {AccountWhitelist} from \"../whitelist/AccountWhitelist.sol\";\nimport {Withdraw} from \"../withdraw/Withdrawable.sol\";\nimport {Swap, SwapStep, TokenUse, StealthSwap, TokenCheck, IUseProtocol, UseParams} from \"./Swap.sol\";\nimport {SwapSignatureValidator} from \"./SwapSignatureValidator.sol\";\n\nstruct Permit {\n    address resolver;\n    address token;\n    uint256 amount;\n    uint256 deadline;\n    bytes signature;\n}\n\nstruct Call {\n    address target;\n    bytes data;\n}\n\nstruct SwapParams {\n    Swap swap;\n    bytes swapSignature;\n    uint256 stepIndex;\n    Permit[] permits;\n    uint256[] inAmounts;\n    Call call;\n    bytes[] useArgs;\n}\n\nstruct StealthSwapParams {\n    StealthSwap swap;\n    bytes swapSignature;\n    SwapStep step;\n    Permit[] permits;\n    uint256[] inAmounts;\n    Call call;\n    bytes[] useArgs;\n}\n\ncontract Swapper is NativeReceiver, NativeReturnMods {\n    using AccountCounter for AccountCounter.State;\n\n    address private immutable _swapSignatureValidator;\n    address private immutable _permitResolverWhitelist;\n    address private immutable _useProtocolWhitelist;\n    address private immutable _delegateManager;\n    mapping(address => mapping(uint256 => bool)) private _usedNonces;\n\n    constructor(address swapSignatureValidator_, address permitResolverWhitelist_, address useProtocolWhitelist_, address delegateManager_) {\n        _swapSignatureValidator = swapSignatureValidator_;\n        _permitResolverWhitelist = permitResolverWhitelist_;\n        _useProtocolWhitelist = useProtocolWhitelist_;\n        _delegateManager = delegateManager_;\n    }\n\n    function swap(SwapParams calldata params_) external payable {\n        _checkSwapEnabled();\n        require(params_.stepIndex < params_.swap.steps.length, \"SW: no step with provided index\");\n        SwapStep calldata step = params_.swap.steps[params_.stepIndex];\n        _validateSwapSignature(params_.swap, params_.swapSignature);\n        _performSwapStep(params_.swap.account, step, params_.permits, params_.inAmounts, params_.call, params_.useArgs);\n    }\n\n    function swapStealth(StealthSwapParams calldata params_) external payable {\n        _checkSwapEnabled();\n        _validateStealthSwapSignature(params_.swap, params_.swapSignature, params_.step);\n        _performSwapStep(params_.swap.account, params_.step, params_.permits, params_.inAmounts, params_.call, params_.useArgs);\n    }\n\n    function _checkSwapEnabled() internal view virtual {} // Nothing is hindering by default\n\n    function _validateSwapSignature(Swap calldata swap_, bytes calldata swapSignature_) private view {\n        if (_isSignaturePresented(swapSignature_))\n            SwapSignatureValidator(_swapSignatureValidator).validateSwapSignature(swap_, swapSignature_);\n        else _validateSwapManualCaller(swap_.account);\n    }\n\n    function _validateStealthSwapSignature(StealthSwap calldata stealthSwap_, bytes calldata stealthSwapSignature_, SwapStep calldata step_) private view {\n        if (_isSignaturePresented(stealthSwapSignature_))\n            SwapSignatureValidator(_swapSignatureValidator).validateStealthSwapStepSignature(step_, stealthSwap_, stealthSwapSignature_);\n        else {\n            _validateSwapManualCaller(stealthSwap_.account);\n            SwapSignatureValidator(_swapSignatureValidator).findStealthSwapStepIndex(step_, stealthSwap_); // Ensure presented\n        }\n    }\n\n    function _isSignaturePresented(bytes calldata signature_) private pure returns (bool) {\n        return signature_.length > 0;\n    }\n\n    function _validateSwapManualCaller(address account_) private view {\n        require(msg.sender == account_, \"SW: caller must be swap account\");\n    }\n\n    function _performSwapStep(address account_, SwapStep calldata step_, Permit[] calldata permits_, uint256[] calldata inAmounts_, Call calldata call_, bytes[] calldata useArgs_) private {\n        require(step_.deadline > block.timestamp, \"SW: swap step expired\");\n        require(step_.chain == block.chainid, \"SW: wrong swap step chain\");\n        require(step_.swapper == address(this), \"SW: wrong swap step swapper\");\n        require(step_.ins.length == inAmounts_.length, \"SW: in amounts length mismatch\");\n\n        _useNonce(account_, step_.nonce);\n        _usePermits(account_, permits_);\n\n        uint256[] memory outAmounts = _performCall(account_, step_.sponsor, step_.ins, inAmounts_, step_.outs, call_);\n        _performUses(step_.uses, useArgs_, step_.outs, outAmounts);\n    }\n\n    function _useNonce(address account_, uint256 nonce_) private {\n        require(!_usedNonces[account_][nonce_], \"SW: invalid nonce\");\n        _usedNonces[account_][nonce_] = true;\n    }\n\n    function _usePermits(address account_, Permit[] calldata permits_) private {\n        for (uint256 i = 0; i < permits_.length; i++)\n            _usePermit(account_, permits_[i]);\n    }\n\n    function _usePermit(address account_, Permit calldata permit_) private {\n        require(_isWhitelistedResolver(permit_.resolver), \"SW: permitter not whitelisted\");\n        PermitResolver(permit_.resolver).resolvePermit(permit_.token, account_, permit_.amount, permit_.deadline, permit_.signature);\n    }\n\n    function _isWhitelistedResolver(address resolver_) private view returns (bool) {\n        return AccountWhitelist(_permitResolverWhitelist).isAccountWhitelisted(resolver_);\n    }\n\n    function _performCall(address account_, address sponsor_, TokenCheck[] calldata ins_, uint256[] calldata inAmounts_, TokenCheck[] calldata outs_, Call calldata call_) private returns (uint256[] memory outAmounts) {\n        NativeClaimer.State memory nativeClaimer;\n        return _performCallWithReturn(account_, sponsor_, ins_, inAmounts_, outs_, call_, nativeClaimer);\n    }\n\n    function _performCallWithReturn(address account_, address sponsor_, TokenCheck[] calldata ins_, uint256[] calldata inAmounts_, TokenCheck[] calldata outs_, Call calldata call_, NativeClaimer.State memory nativeClaimer_) private returnUnclaimedNative(nativeClaimer_) returns (uint256[] memory outAmounts) {\n        for (uint256 i = 0; i < ins_.length; i++)\n            TokenChecker.checkMinMax(ins_[i], inAmounts_[i]);\n\n        AccountCounter.State memory inAmountsByToken = AccountCounter.create(ins_.length);\n        for (uint256 i = 0; i < ins_.length; i++)\n            inAmountsByToken.add(ins_[i].token, inAmounts_[i]);\n\n        address delegate = DelegateManager(_delegateManager).predictDelegateDeploy(account_);\n        require(sponsor_ == account_ || sponsor_ == delegate || _isWhitelistedResolver(sponsor_), \"SW: sponsor not allowed\");\n        if (sponsor_ == delegate) _claimDelegateCallIns(account_, inAmountsByToken);\n        else _claimSponsorCallIns(sponsor_, inAmountsByToken, nativeClaimer_);\n\n        AccountCounter.State memory outBalances = AccountCounter.create(outs_.length);\n        for (uint256 i = 0; i < outs_.length; i++) {\n            address token = outs_[i].token;\n            uint256 sizeBefore = outBalances.size();\n            uint256 tokenIndex = outBalances.indexOf(token);\n            if (sizeBefore != outBalances.size())\n                outBalances.setAt(tokenIndex, TokenHelper.balanceOfThis(token, nativeClaimer_));\n        }\n        uint256 totalOutTokens = outBalances.size();\n\n        uint256 sendValue = _approveAssets(inAmountsByToken, call_.target);\n        bytes memory result = Address.functionCallWithValue(call_.target, call_.data, sendValue);\n        _revokeAssets(inAmountsByToken, call_.target);\n\n        for (uint256 i = 0; i < totalOutTokens; i++) {\n            uint256 tokenInIndex = inAmountsByToken.indexOf(outBalances.accountAt(i), false);\n            if (!AccountCounter.isNullIndex(tokenInIndex))\n                outBalances.subAt(i, inAmountsByToken.getAt(tokenInIndex));\n        }\n\n        for (uint256 i = 0; i < totalOutTokens; i++)\n            outBalances.setAt(i, TokenHelper.balanceOfThis(outBalances.accountAt(i), nativeClaimer_) - outBalances.getAt(i));\n\n        outAmounts = abi.decode(result, (uint256[]));\n        require(outAmounts.length == outs_.length, \"SW: out amounts length mismatch\");\n\n        for (uint256 i = 0; i < outs_.length; i++) {\n            uint256 amount = TokenChecker.checkMin(outs_[i], outAmounts[i]);\n            outAmounts[i] = amount;\n            uint256 tokenIndex = outBalances.indexOf(outs_[i].token, false);\n            require(outBalances.getAt(tokenIndex) >= amount, \"SW: insufficient out amount\");\n            outBalances.subAt(tokenIndex, amount);\n        }\n    }\n\n    function _claimDelegateCallIns(address account_, AccountCounter.State memory inAmountsByToken_) private {\n        Withdraw[] memory withdraws = new Withdraw[](inAmountsByToken_.size());\n        for (uint256 i = 0; i < inAmountsByToken_.size(); i++)\n            withdraws[i] = Withdraw({token: inAmountsByToken_.accountAt(i), amount: inAmountsByToken_.getAt(i), to: address(this)});\n\n        if (!DelegateManager(_delegateManager).isDelegateDeployed(account_))\n            DelegateManager(_delegateManager).deployDelegate(account_);\n        DelegateManager(_delegateManager).withdraw(account_, withdraws);\n    }\n\n    function _claimSponsorCallIns(address sponsor_, AccountCounter.State memory inAmountsByToken_, NativeClaimer.State memory nativeClaimer_) private {\n        for (uint256 i = 0; i < inAmountsByToken_.size(); i++)\n            TokenHelper.transferToThis(inAmountsByToken_.accountAt(i), sponsor_, inAmountsByToken_.getAt(i), nativeClaimer_);\n    }\n\n    function _approveAssets(AccountCounter.State memory amountsByToken_, address spender_) private returns (uint256 sendValue) {\n        for (uint256 i = 0; i < amountsByToken_.size(); i++)\n            sendValue += TokenHelper.approveOfThis(amountsByToken_.accountAt(i), spender_, amountsByToken_.getAt(i));\n    }\n\n    function _revokeAssets(AccountCounter.State memory amountsByToken_, address spender_) private {\n        for (uint256 i = 0; i < amountsByToken_.size(); i++)\n            TokenHelper.revokeOfThis(amountsByToken_.accountAt(i), spender_);\n    }\n\n    function _performUses(TokenUse[] calldata uses_, bytes[] calldata useArgs_, TokenCheck[] calldata useIns_, uint256[] memory useInAmounts_) private {\n        uint256 dynamicArgsCursor = 0;\n        for (uint256 i = 0; i < uses_.length; i++) {\n            bytes calldata args = uses_[i].args;\n            if (_shouldUseDynamicArgs(args)) {\n                require(dynamicArgsCursor < useArgs_.length, \"SW: not enough dynamic use args\");\n                args = useArgs_[dynamicArgsCursor];\n                dynamicArgsCursor++;\n            }\n            _performUse(uses_[i], args, useIns_, useInAmounts_);\n        }\n        require(dynamicArgsCursor == useArgs_.length, \"SW: too many dynamic use args\");\n    }\n\n    function _shouldUseDynamicArgs(bytes calldata args_) private pure returns (bool) {\n        if (args_.length != 7) return false;\n        return bytes7(args_) == 0x44796E616D6963; // \"Dynamic\" in ASCII\n    }\n\n    function _performUse(TokenUse calldata use_, bytes calldata args_, TokenCheck[] calldata useIns_, uint256[] memory useInAmounts_) private {\n        require(AccountWhitelist(_useProtocolWhitelist).isAccountWhitelisted(use_.protocol), \"SW: use protocol not whitelisted\");\n\n        TokenCheck[] memory ins = new TokenCheck[](use_.inIndices.length);\n        uint256[] memory inAmounts = new uint256[](use_.inIndices.length);\n        for (uint256 i = 0; i < use_.inIndices.length; i++) {\n            uint256 inIndex = use_.inIndices[i];\n            require(useInAmounts_[inIndex] != type(uint256).max, \"SW: input already spent\");\n            ins[i] = useIns_[inIndex];\n            inAmounts[i] = useInAmounts_[inIndex];\n            useInAmounts_[inIndex] = type(uint256).max; // Mark as spent\n        }\n\n        AccountCounter.State memory useInAmounts = AccountCounter.create(use_.inIndices.length);\n        for (uint256 i = 0; i < use_.inIndices.length; i++)\n            useInAmounts.add(ins[i].token, inAmounts[i]);\n\n        uint256 sendValue = _approveAssets(useInAmounts, use_.protocol);\n        IUseProtocol(use_.protocol).use{value: sendValue}(UseParams({chain: use_.chain, account: use_.account, ins: ins, inAmounts: inAmounts, outs: use_.outs, args: args_, msgSender: msg.sender, msgData: msg.data}));\n        _revokeAssets(useInAmounts, use_.protocol);\n    }\n}\n"
    },
    "contracts/core/swap/SwapSignatureValidator.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {ECDSA} from \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\nimport {TokenCheck, TokenUse, SwapStep, Swap, StealthSwap} from \"./Swap.sol\";\n\ncontract SwapSignatureValidator {\n    function validateSwapSignature(Swap calldata swap_, bytes calldata swapSignature_) public pure {\n        require(swap_.steps.length > 0, \"SV: swap has no steps\");\n        address signer = ECDSA.recover(_hashTypedDataV4(_hashSwap(swap_), swap_.steps[0].chain, swap_.steps[0].swapper), swapSignature_);\n        require(signer == swap_.account, \"SV: invalid swap signature\");\n    }\n\n    function validateStealthSwapStepSignature(SwapStep calldata swapStep_, StealthSwap calldata stealthSwap_, bytes calldata stealthSwapSignature_) public pure returns (uint256 stepIndex) {\n        address signer = ECDSA.recover(_hashTypedDataV4(_hashStealthSwap(stealthSwap_), stealthSwap_.chain, stealthSwap_.swapper), stealthSwapSignature_);\n        require(signer == stealthSwap_.account, \"SV: invalid s-swap signature\");\n        return findStealthSwapStepIndex(swapStep_, stealthSwap_);\n    }\n\n    function findStealthSwapStepIndex(SwapStep calldata swapStep_, StealthSwap calldata stealthSwap_) public pure returns (uint256 stepIndex) {\n        bytes32 stepHash = _hashSwapStep(swapStep_);\n        for (uint256 i = 0; i < stealthSwap_.stepHashes.length; i++)\n            if (stealthSwap_.stepHashes[i] == stepHash) return i;\n        revert(\"SV: no step hash match in s-swap\");\n    }\n\n    function _hashTypedDataV4(bytes32 structHash_, uint256 chainId_, address verifyingContract_) private pure returns (bytes32) {\n        bytes32 domainSeparator = keccak256(abi.encode(0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f, 0x759f8d0a6b014b7601ff701e703719d70a717971c25deb97628336c51d9e7d86, 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6, chainId_, verifyingContract_));\n        return ECDSA.toTypedDataHash(domainSeparator, structHash_);\n    }\n\n    function _hashSwap(Swap calldata swap_) private pure returns (bytes32) {\n        return keccak256(abi.encode(0x09b148e744e0e1801943dd449b1fa4d29b7172ff190d22f95b1bb7e5df52e37d, swap_.account, _hashSwapSteps(swap_.steps)));\n    }\n\n    function _hashSwapSteps(SwapStep[] calldata swapSteps_) private pure returns (bytes32) {\n        bytes memory bytesToHash = new bytes(swapSteps_.length << 5); // * 0x20\n        uint256 offset; assembly { offset := add(bytesToHash, 0x20) }\n        for (uint256 i = 0; i < swapSteps_.length; i++) {\n            bytes32 hash = _hashSwapStep(swapSteps_[i]);\n            assembly { mstore(offset, hash) offset := add(offset, 0x20) }\n        }\n        return keccak256(bytesToHash);\n    }\n\n    function _hashSwapStep(SwapStep calldata swapStep_) private pure returns (bytes32) {\n        return keccak256(abi.encode(0x5302e49a52f1122ff531999c0f7afcb4d2bfefa7562dfefbdb7ed114d495ea6a, swapStep_.chain, swapStep_.swapper, swapStep_.sponsor, swapStep_.nonce, swapStep_.deadline, _hashTokenChecks(swapStep_.ins), _hashTokenChecks(swapStep_.outs), _hashTokenUses(swapStep_.uses)));\n    }\n\n    function _hashTokenChecks(TokenCheck[] calldata tokenChecks_) private pure returns (bytes32) {\n        bytes memory bytesToHash = new bytes(tokenChecks_.length << 5); // * 0x20\n        uint256 offset; assembly { offset := add(bytesToHash, 0x20) }\n        for (uint256 i = 0; i < tokenChecks_.length; i++) {\n            bytes32 hash = _hashTokenCheck(tokenChecks_[i]);\n            assembly { mstore(offset, hash) offset := add(offset, 0x20) }\n        }\n        return keccak256(bytesToHash);\n    }\n\n    function _hashTokenCheck(TokenCheck calldata tokenCheck_) private pure returns (bytes32) {\n        return keccak256(abi.encode(0x382391664c9ae06333b02668b6d763ab547bd70c71636e236fdafaacf1e55bdd, tokenCheck_.token, tokenCheck_.minAmount, tokenCheck_.maxAmount));\n    }\n\n    function _hashTokenUses(TokenUse[] calldata tokenUses_) private pure returns (bytes32) {\n        bytes memory bytesToHash = new bytes(tokenUses_.length << 5); // * 0x20\n        uint256 offset; assembly { offset := add(bytesToHash, 0x20) }\n        for (uint256 i = 0; i < tokenUses_.length; i++) {\n            bytes32 hash = _hashTokenUse(tokenUses_[i]);\n            assembly { mstore(offset, hash) offset := add(offset, 0x20) }\n        }\n        return keccak256(bytesToHash);\n    }\n\n    function _hashTokenUse(TokenUse calldata tokenUse_) private pure returns (bytes32) {\n        return keccak256(abi.encode(0x192f17c5e66907915b200bca0d866184770ff7faf25a0b4ccd2ef26ebd21725a, tokenUse_.protocol, tokenUse_.chain, tokenUse_.account, keccak256(abi.encodePacked(tokenUse_.inIndices)), _hashTokenChecks(tokenUse_.outs), keccak256(tokenUse_.args)));\n    }\n\n    function _hashStealthSwap(StealthSwap calldata stealthSwap_) private pure returns (bytes32) {\n        return keccak256(abi.encode(0x0f2b1c8dae54aa1b96d626d678ec60a7c6d113b80ccaf635737a6f003d1cbaf5, stealthSwap_.chain, stealthSwap_.swapper, stealthSwap_.account, keccak256(abi.encodePacked(stealthSwap_.stepHashes))));\n    }\n}\n"
    },
    "contracts/core/whitelist/AccountWhitelist.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {EnumerableSet} from \"@openzeppelin/contracts/utils/structs/EnumerableSet.sol\";\nimport {SimpleInitializable} from \"../misc/SimpleInitializable.sol\";\n\ncontract AccountWhitelist is Ownable, SimpleInitializable {\n    using EnumerableSet for EnumerableSet.AddressSet;\n\n    event AccountAdded(address account);\n    event AccountRemoved(address account);\n\n    EnumerableSet.AddressSet private _accounts;\n\n    constructor() {\n        _initializeWithSender();\n    }\n\n    function getWhitelistedAccounts() external view returns (address[] memory) {\n        return _accounts.values();\n    }\n\n    function isAccountWhitelisted(address account_) external view returns (bool) {\n        return _accounts.contains(account_);\n    }\n\n    function addAccountToWhitelist(address account_) external whenInitialized onlyOwner {\n        require(_accounts.add(account_), \"AW: account already included\");\n        emit AccountAdded(account_);\n    }\n\n    function removeAccountFromWhitelist(address account_) external whenInitialized onlyOwner {\n        require(_accounts.remove(account_), \"AW: account already excluded\");\n        emit AccountRemoved(account_);\n    }\n\n    function _initialize() internal override {\n        _transferOwnership(initializer());\n    }\n}\n"
    },
    "contracts/core/withdraw/WhitelistWithdrawable.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {Withdrawable} from \"./Withdrawable.sol\";\nimport {AccountWhitelist} from \"../whitelist/AccountWhitelist.sol\";\n\nabstract contract WhitelistWithdrawable is Withdrawable {\n    address private immutable _withdrawWhitelist;\n\n    constructor(address withdrawWhitelist_) {\n        _withdrawWhitelist = withdrawWhitelist_;\n    }\n\n    function _checkWithdraw() internal view override {\n        require(AccountWhitelist(_withdrawWhitelist).isAccountWhitelisted(msg.sender), \"WW: withdrawer not whitelisted\");\n    }\n}\n"
    },
    "contracts/core/withdraw/Withdrawable.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {TokenHelper} from \"../asset/TokenHelper.sol\";\n\nstruct Withdraw {\n    address token;\n    uint256 amount;\n    address to;\n}\n\nabstract contract Withdrawable {\n    event Withdrawn(address token, uint256 amount, address to);\n\n    function withdraw(Withdraw[] calldata withdraws_) external virtual {\n        _checkWithdraw();\n        for (uint256 i = 0; i < withdraws_.length; i++) {\n            Withdraw calldata w = withdraws_[i];\n            TokenHelper.transferFromThis(w.token, w.to, w.amount);\n            emit Withdrawn(w.token, w.amount, w.to);\n        }\n    }\n\n    function _checkWithdraw() internal view virtual;\n}\n"
    },
    "contracts/XSwap.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.16;\n\nimport {Swapper} from \"./core/swap/Swapper.sol\";\nimport {WhitelistWithdrawable} from \"./core/withdraw/WhitelistWithdrawable.sol\";\nimport {LifeControl} from \"./core/misc/LifeControl.sol\";\n\nstruct XSwapConstructorParams {\n    address swapSignatureValidator;\n    address permitResolverWhitelist;\n    address useProtocolWhitelist;\n    address delegateManager;\n    address withdrawWhitelist;\n    address lifeControl;\n}\n\ncontract XSwap is Swapper, WhitelistWithdrawable {\n    address private immutable _lifeControl;\n\n    constructor(XSwapConstructorParams memory params_)\n        WhitelistWithdrawable(params_.withdrawWhitelist)\n        Swapper(params_.swapSignatureValidator, params_.permitResolverWhitelist, params_.useProtocolWhitelist, params_.delegateManager) {\n        _lifeControl = params_.lifeControl;\n    }\n\n    function _checkSwapEnabled() internal view override {\n        require(!LifeControl(_lifeControl).paused(), \"XS: swapping paused\");\n    }\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 1000
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "libraries": {}
  }
}