creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../utils/Context.sol\";\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 () internal {\n        address msgSender = _msgSender();\n        _owner = msgSender;\n        emit OwnershipTransferred(address(0), msgSender);\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 called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n        _;\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        emit OwnershipTransferred(_owner, address(0));\n        _owner = 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        emit OwnershipTransferred(_owner, newOwner);\n        _owner = newOwner;\n    }\n}\n"
      },
      "@openzeppelin/contracts/cryptography/ECDSA.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\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    /**\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        // Check the signature length\n        if (signature.length != 65) {\n            revert(\"ECDSA: invalid signature length\");\n        }\n\n        // Divide the signature in r, s and v variables\n        bytes32 r;\n        bytes32 s;\n        uint8 v;\n\n        // ecrecover takes the signature parameters, and the only way to get them\n        // currently is to use assembly.\n        // solhint-disable-next-line no-inline-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\n        return recover(hash, v, r, s);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     */\n    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n        // 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 (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): 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        require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, \"ECDSA: invalid signature 's' value\");\n        require(v == 27 || v == 28, \"ECDSA: invalid signature 'v' value\");\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        require(signer != address(0), \"ECDSA: invalid signature\");\n\n        return signer;\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n     * replicates the behavior of the\n     * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]\n     * JSON-RPC method.\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"
      },
      "@openzeppelin/contracts/drafts/EIP712.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,\n * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding\n * they need in their contracts using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * _Available since v3.4._\n */\nabstract contract EIP712 {\n    /* solhint-disable var-name-mixedcase */\n    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n    // invalidate the cached domain separator if the chain id changes.\n    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;\n    uint256 private immutable _CACHED_CHAIN_ID;\n\n    bytes32 private immutable _HASHED_NAME;\n    bytes32 private immutable _HASHED_VERSION;\n    bytes32 private immutable _TYPE_HASH;\n    /* solhint-enable var-name-mixedcase */\n\n    /**\n     * @dev Initializes the domain separator and parameter caches.\n     *\n     * The meaning of `name` and `version` is specified in\n     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:\n     *\n     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n     * - `version`: the current major version of the signing domain.\n     *\n     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n     * contract upgrade].\n     */\n    constructor(string memory name, string memory version) internal {\n        bytes32 hashedName = keccak256(bytes(name));\n        bytes32 hashedVersion = keccak256(bytes(version));\n        bytes32 typeHash = keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n        _HASHED_NAME = hashedName;\n        _HASHED_VERSION = hashedVersion;\n        _CACHED_CHAIN_ID = _getChainId();\n        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);\n        _TYPE_HASH = typeHash;\n    }\n\n    /**\n     * @dev Returns the domain separator for the current chain.\n     */\n    function _domainSeparatorV4() internal view virtual returns (bytes32) {\n        if (_getChainId() == _CACHED_CHAIN_ID) {\n            return _CACHED_DOMAIN_SEPARATOR;\n        } else {\n            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);\n        }\n    }\n\n    function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) {\n        return keccak256(\n            abi.encode(\n                typeHash,\n                name,\n                version,\n                _getChainId(),\n                address(this)\n            )\n        );\n    }\n\n    /**\n     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n     * function returns the hash of the fully encoded EIP712 message for this domain.\n     *\n     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n     *\n     * ```solidity\n     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n     *     keccak256(\"Mail(address to,string contents)\"),\n     *     mailTo,\n     *     keccak256(bytes(mailContents))\n     * )));\n     * address signer = ECDSA.recover(digest, signature);\n     * ```\n     */\n    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19\\x01\", _domainSeparatorV4(), structHash));\n    }\n\n    function _getChainId() private view returns (uint256 chainId) {\n        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            chainId := chainid()\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/drafts/ERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.5 <0.8.0;\n\nimport \"../token/ERC20/ERC20.sol\";\nimport \"./IERC20Permit.sol\";\nimport \"../cryptography/ECDSA.sol\";\nimport \"../utils/Counters.sol\";\nimport \"./EIP712.sol\";\n\n/**\n * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * _Available since v3.4._\n */\nabstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {\n    using Counters for Counters.Counter;\n\n    mapping (address => Counters.Counter) private _nonces;\n\n    // solhint-disable-next-line var-name-mixedcase\n    bytes32 private immutable _PERMIT_TYPEHASH = keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\n\n    /**\n     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `\"1\"`.\n     *\n     * It's a good idea to use the same `name` that is defined as the ERC20 token name.\n     */\n    constructor(string memory name) internal EIP712(name, \"1\") {\n    }\n\n    /**\n     * @dev See {IERC20Permit-permit}.\n     */\n    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override {\n        // solhint-disable-next-line not-rely-on-time\n        require(block.timestamp <= deadline, \"ERC20Permit: expired deadline\");\n\n        bytes32 structHash = keccak256(\n            abi.encode(\n                _PERMIT_TYPEHASH,\n                owner,\n                spender,\n                value,\n                _nonces[owner].current(),\n                deadline\n            )\n        );\n\n        bytes32 hash = _hashTypedDataV4(structHash);\n\n        address signer = ECDSA.recover(hash, v, r, s);\n        require(signer == owner, \"ERC20Permit: invalid signature\");\n\n        _nonces[owner].increment();\n        _approve(owner, spender, value);\n    }\n\n    /**\n     * @dev See {IERC20Permit-nonces}.\n     */\n    function nonces(address owner) public view override returns (uint256) {\n        return _nonces[owner].current();\n    }\n\n    /**\n     * @dev See {IERC20Permit-DOMAIN_SEPARATOR}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view override returns (bytes32) {\n        return _domainSeparatorV4();\n    }\n}\n"
      },
      "@openzeppelin/contracts/drafts/IERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <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(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) 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/math/Math.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\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, so we distribute\n        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);\n    }\n}\n"
      },
      "@openzeppelin/contracts/math/SafeMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        uint256 c = a + b;\n        if (c < a) return (false, 0);\n        return (true, c);\n    }\n\n    /**\n     * @dev Returns the substraction of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        if (b > a) return (false, 0);\n        return (true, a - b);\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n        // benefit is lost if 'b' is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) return (true, 0);\n        uint256 c = a * b;\n        if (c / a != b) return (false, 0);\n        return (true, c);\n    }\n\n    /**\n     * @dev Returns the division of two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        if (b == 0) return (false, 0);\n        return (true, a / b);\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        if (b == 0) return (false, 0);\n        return (true, a % b);\n    }\n\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c >= a, \"SafeMath: addition overflow\");\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b <= a, \"SafeMath: subtraction overflow\");\n        return a - b;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        if (a == 0) return 0;\n        uint256 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b > 0, \"SafeMath: division by zero\");\n        return a / b;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b > 0, \"SafeMath: modulo by zero\");\n        return a % b;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {trySub}.\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b <= a, errorMessage);\n        return a - b;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryDiv}.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b > 0, errorMessage);\n        return a / b;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting with custom message when dividing by zero.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryMod}.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b > 0, errorMessage);\n        return a % b;\n    }\n}\n"
      },
      "@openzeppelin/contracts/math/SignedSafeMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @title SignedSafeMath\n * @dev Signed math operations with safety checks that revert on error.\n */\nlibrary SignedSafeMath {\n    int256 constant private _INT256_MIN = -2**255;\n\n    /**\n     * @dev Returns the multiplication of two signed integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(int256 a, int256 b) internal pure returns (int256) {\n        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n        // benefit is lost if 'b' is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        require(!(a == -1 && b == _INT256_MIN), \"SignedSafeMath: multiplication overflow\");\n\n        int256 c = a * b;\n        require(c / a == b, \"SignedSafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two signed integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(int256 a, int256 b) internal pure returns (int256) {\n        require(b != 0, \"SignedSafeMath: division by zero\");\n        require(!(b == -1 && a == _INT256_MIN), \"SignedSafeMath: division overflow\");\n\n        int256 c = a / b;\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two signed integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(int256 a, int256 b) internal pure returns (int256) {\n        int256 c = a - b;\n        require((b >= 0 && c <= a) || (b < 0 && c > a), \"SignedSafeMath: subtraction overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the addition of two signed integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(int256 a, int256 b) internal pure returns (int256) {\n        int256 c = a + b;\n        require((b >= 0 && c >= a) || (b < 0 && c < a), \"SignedSafeMath: addition overflow\");\n\n        return c;\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/ERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../../utils/Context.sol\";\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin guidelines: functions revert instead\n * of returning `false` on failure. This behavior is nonetheless conventional\n * and does not conflict with the expectations of ERC20 applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20 {\n    using SafeMath for uint256;\n\n    mapping (address => uint256) private _balances;\n\n    mapping (address => mapping (address => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n    uint8 private _decimals;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with\n     * a default value of 18.\n     *\n     * To select a different value for {decimals}, use {_setupDecimals}.\n     *\n     * All three of these values are immutable: they can only be set once during\n     * construction.\n     */\n    constructor (string memory name_, string memory symbol_) public {\n        _name = name_;\n        _symbol = symbol_;\n        _decimals = 18;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5,05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is\n     * called.\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual returns (uint8) {\n        return _decimals;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `recipient` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n        _transfer(_msgSender(), recipient, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        _approve(_msgSender(), spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * Requirements:\n     *\n     * - `sender` and `recipient` cannot be the zero address.\n     * - `sender` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``sender``'s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {\n        _transfer(sender, recipient, amount);\n        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, \"ERC20: transfer amount exceeds allowance\"));\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, \"ERC20: decreased allowance below zero\"));\n        return true;\n    }\n\n    /**\n     * @dev Moves tokens `amount` from `sender` to `recipient`.\n     *\n     * This is internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `sender` cannot be the zero address.\n     * - `recipient` cannot be the zero address.\n     * - `sender` must have a balance of at least `amount`.\n     */\n    function _transfer(address sender, address recipient, uint256 amount) internal virtual {\n        require(sender != address(0), \"ERC20: transfer from the zero address\");\n        require(recipient != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(sender, recipient, amount);\n\n        _balances[sender] = _balances[sender].sub(amount, \"ERC20: transfer amount exceeds balance\");\n        _balances[recipient] = _balances[recipient].add(amount);\n        emit Transfer(sender, recipient, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply = _totalSupply.add(amount);\n        _balances[account] = _balances[account].add(amount);\n        emit Transfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        _balances[account] = _balances[account].sub(amount, \"ERC20: burn amount exceeds balance\");\n        _totalSupply = _totalSupply.sub(amount);\n        emit Transfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(address owner, address spender, uint256 amount) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Sets {decimals} to a value other than the default one of 18.\n     *\n     * WARNING: This function should only be called from the constructor. Most\n     * applications that interact with token contracts will not expect\n     * {decimals} to ever change, and may work incorrectly if it does.\n     */\n    function _setupDecimals(uint8 decimals_) internal virtual {\n        _decimals = decimals_;\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be to transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\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 `recipient`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address recipient, 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 `sender` to `recipient` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\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"
      },
      "@openzeppelin/contracts/token/ERC20/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.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 SafeMath for uint256;\n    using Address for address;\n\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) 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(IERC20 token, address spender, uint256 value) 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        // solhint-disable-next-line max-line-length\n        require((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(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).add(value);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\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) { // Return data is optional\n            // solhint-disable-next-line max-line-length\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\npragma solidity >=0.6.2 <0.8.0;\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    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize, which returns 0 for contracts in\n        // construction, since the code is only stored at the end of the\n        // constructor execution.\n\n        uint256 size;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { size := extcodesize(account) }\n        return size > 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        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\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 functionCall(target, data, \"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(address target, bytes memory data, string memory errorMessage) 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(address target, bytes memory data, uint256 value) 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(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.call{ value: value }(data);\n        return _verifyCallResult(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(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return _verifyCallResult(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(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return _verifyCallResult(success, returndata, errorMessage);\n    }\n\n    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\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\n                // solhint-disable-next-line no-inline-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}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <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 GSN 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 payable) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes memory) {\n        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n        return msg.data;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Counters.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\nimport \"../math/SafeMath.sol\";\n\n/**\n * @title Counters\n * @author Matt Condon (@shrugs)\n * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number\n * of elements in a mapping, issuing ERC721 ids, or counting request ids.\n *\n * Include with `using Counters for Counters.Counter;`\n * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath}\n * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never\n * directly accessed.\n */\nlibrary Counters {\n    using SafeMath for uint256;\n\n    struct Counter {\n        // This variable should never be directly accessed by users of the library: interactions must be restricted to\n        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add\n        // this feature: see https://github.com/ethereum/solidity/issues/4637\n        uint256 _value; // default: 0\n    }\n\n    function current(Counter storage counter) internal view returns (uint256) {\n        return counter._value;\n    }\n\n    function increment(Counter storage counter) internal {\n        // The {SafeMath} overflow check can be skipped here, see the comment at the top\n        counter._value += 1;\n    }\n\n    function decrement(Counter storage counter) internal {\n        counter._value = counter._value.sub(1);\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.6.0 <0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    constructor () internal {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and make it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        // On the first call to nonReentrant, _notEntered will be true\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n\n        _;\n\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Callback for IUniswapV3PoolActions#mint\n/// @notice Any contract that calls IUniswapV3PoolActions#mint must implement this interface\ninterface IUniswapV3MintCallback {\n    /// @notice Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint.\n    /// @dev In the implementation you must pay the pool tokens owed for the minted liquidity.\n    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.\n    /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity\n    /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity\n    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call\n    function uniswapV3MintCallback(\n        uint256 amount0Owed,\n        uint256 amount1Owed,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Callback for IUniswapV3PoolActions#swap\n/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface\ninterface IUniswapV3SwapCallback {\n    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.\n    /// @dev In the implementation you must pay the pool tokens owed for the swap.\n    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.\n    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.\n    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.\n    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.\n    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call\n    function uniswapV3SwapCallback(\n        int256 amount0Delta,\n        int256 amount1Delta,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Minimal ERC20 interface for Uniswap\n/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3\ninterface IERC20Minimal {\n    /// @notice Returns the balance of a token\n    /// @param account The account for which to look up the number of tokens it has, i.e. its balance\n    /// @return The number of tokens held by the account\n    function balanceOf(address account) external view returns (uint256);\n\n    /// @notice Transfers the amount of token from the `msg.sender` to the recipient\n    /// @param recipient The account that will receive the amount transferred\n    /// @param amount The number of tokens to send from the sender to the recipient\n    /// @return Returns true for a successful transfer, false for an unsuccessful transfer\n    function transfer(address recipient, uint256 amount) external returns (bool);\n\n    /// @notice Returns the current allowance given to a spender by an owner\n    /// @param owner The account of the token owner\n    /// @param spender The account of the token spender\n    /// @return The current allowance granted by `owner` to `spender`\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`\n    /// @param spender The account which will be allowed to spend a given amount of the owners tokens\n    /// @param amount The amount of tokens allowed to be used by `spender`\n    /// @return Returns true for a successful approval, false for unsuccessful\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`\n    /// @param sender The account from which the transfer will be initiated\n    /// @param recipient The recipient of the transfer\n    /// @param amount The amount of the transfer\n    /// @return Returns true for a successful transfer, false for unsuccessful\n    function transferFrom(\n        address sender,\n        address recipient,\n        uint256 amount\n    ) external returns (bool);\n\n    /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.\n    /// @param from The account from which the tokens were sent, i.e. the balance decreased\n    /// @param to The account to which the tokens were sent, i.e. the balance increased\n    /// @param value The amount of tokens that were transferred\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.\n    /// @param owner The account that approved spending of its tokens\n    /// @param spender The account for which the spending allowance was modified\n    /// @param value The new allowance from the owner to the spender\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title The interface for the Uniswap V3 Factory\n/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees\ninterface IUniswapV3Factory {\n    /// @notice Emitted when the owner of the factory is changed\n    /// @param oldOwner The owner before the owner was changed\n    /// @param newOwner The owner after the owner was changed\n    event OwnerChanged(address indexed oldOwner, address indexed newOwner);\n\n    /// @notice Emitted when a pool is created\n    /// @param token0 The first token of the pool by address sort order\n    /// @param token1 The second token of the pool by address sort order\n    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n    /// @param tickSpacing The minimum number of ticks between initialized ticks\n    /// @param pool The address of the created pool\n    event PoolCreated(\n        address indexed token0,\n        address indexed token1,\n        uint24 indexed fee,\n        int24 tickSpacing,\n        address pool\n    );\n\n    /// @notice Emitted when a new fee amount is enabled for pool creation via the factory\n    /// @param fee The enabled fee, denominated in hundredths of a bip\n    /// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee\n    event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);\n\n    /// @notice Returns the current owner of the factory\n    /// @dev Can be changed by the current owner via setOwner\n    /// @return The address of the factory owner\n    function owner() external view returns (address);\n\n    /// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled\n    /// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context\n    /// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee\n    /// @return The tick spacing\n    function feeAmountTickSpacing(uint24 fee) external view returns (int24);\n\n    /// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist\n    /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order\n    /// @param tokenA The contract address of either token0 or token1\n    /// @param tokenB The contract address of the other token\n    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n    /// @return pool The pool address\n    function getPool(\n        address tokenA,\n        address tokenB,\n        uint24 fee\n    ) external view returns (address pool);\n\n    /// @notice Creates a pool for the given two tokens and fee\n    /// @param tokenA One of the two tokens in the desired pool\n    /// @param tokenB The other of the two tokens in the desired pool\n    /// @param fee The desired fee for the pool\n    /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved\n    /// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments\n    /// are invalid.\n    /// @return pool The address of the newly created pool\n    function createPool(\n        address tokenA,\n        address tokenB,\n        uint24 fee\n    ) external returns (address pool);\n\n    /// @notice Updates the owner of the factory\n    /// @dev Must be called by the current owner\n    /// @param _owner The new owner of the factory\n    function setOwner(address _owner) external;\n\n    /// @notice Enables a fee amount with the given tickSpacing\n    /// @dev Fee amounts may never be removed once enabled\n    /// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)\n    /// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount\n    function enableFeeAmount(uint24 fee, int24 tickSpacing) external;\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport './pool/IUniswapV3PoolImmutables.sol';\nimport './pool/IUniswapV3PoolState.sol';\nimport './pool/IUniswapV3PoolDerivedState.sol';\nimport './pool/IUniswapV3PoolActions.sol';\nimport './pool/IUniswapV3PoolOwnerActions.sol';\nimport './pool/IUniswapV3PoolEvents.sol';\n\n/// @title The interface for a Uniswap V3 Pool\n/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform\n/// to the ERC20 specification\n/// @dev The pool interface is broken up into many smaller pieces\ninterface IUniswapV3Pool is\n    IUniswapV3PoolImmutables,\n    IUniswapV3PoolState,\n    IUniswapV3PoolDerivedState,\n    IUniswapV3PoolActions,\n    IUniswapV3PoolOwnerActions,\n    IUniswapV3PoolEvents\n{\n\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/IUniswapV3PoolDeployer.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title An interface for a contract that is capable of deploying Uniswap V3 Pools\n/// @notice A contract that constructs a pool must implement this to pass arguments to the pool\n/// @dev This is used to avoid having constructor arguments in the pool contract, which results in the init code hash\n/// of the pool being constant allowing the CREATE2 address of the pool to be cheaply computed on-chain\ninterface IUniswapV3PoolDeployer {\n    /// @notice Get the parameters to be used in constructing the pool, set transiently during pool creation.\n    /// @dev Called by the pool constructor to fetch the parameters of the pool\n    /// Returns factory The factory address\n    /// Returns token0 The first token of the pool by address sort order\n    /// Returns token1 The second token of the pool by address sort order\n    /// Returns fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n    /// Returns tickSpacing The minimum number of ticks between initialized ticks\n    function parameters()\n        external\n        view\n        returns (\n            address factory,\n            address token0,\n            address token1,\n            uint24 fee,\n            int24 tickSpacing\n        );\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissionless pool actions\n/// @notice Contains pool methods that can be called by anyone\ninterface IUniswapV3PoolActions {\n    /// @notice Sets the initial price for the pool\n    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value\n    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96\n    function initialize(uint160 sqrtPriceX96) external;\n\n    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback\n    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends\n    /// on tickLower, tickUpper, the amount of liquidity, and the current price.\n    /// @param recipient The address for which the liquidity will be created\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount The amount of liquidity to mint\n    /// @param data Any data that should be passed through to the callback\n    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    function mint(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount,\n        bytes calldata data\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Collects tokens owed to a position\n    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.\n    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or\n    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the\n    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.\n    /// @param recipient The address which should receive the fees collected\n    /// @param tickLower The lower tick of the position for which to collect fees\n    /// @param tickUpper The upper tick of the position for which to collect fees\n    /// @param amount0Requested How much token0 should be withdrawn from the fees owed\n    /// @param amount1Requested How much token1 should be withdrawn from the fees owed\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function collect(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n\n    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position\n    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0\n    /// @dev Fees must be collected separately via a call to #collect\n    /// @param tickLower The lower tick of the position for which to burn liquidity\n    /// @param tickUpper The upper tick of the position for which to burn liquidity\n    /// @param amount How much liquidity to burn\n    /// @return amount0 The amount of token0 sent to the recipient\n    /// @return amount1 The amount of token1 sent to the recipient\n    function burn(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Swap token0 for token1, or token1 for token0\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback\n    /// @param recipient The address to receive the output of the swap\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)\n    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this\n    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap\n    /// @param data Any data to be passed through to the callback\n    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive\n    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive\n    function swap(\n        address recipient,\n        bool zeroForOne,\n        int256 amountSpecified,\n        uint160 sqrtPriceLimitX96,\n        bytes calldata data\n    ) external returns (int256 amount0, int256 amount1);\n\n    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback\n    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling\n    /// with 0 amount{0,1} and sending the donation amount(s) from the callback\n    /// @param recipient The address which will receive the token0 and token1 amounts\n    /// @param amount0 The amount of token0 to send\n    /// @param amount1 The amount of token1 to send\n    /// @param data Any data to be passed through to the callback\n    function flash(\n        address recipient,\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata data\n    ) external;\n\n    /// @notice Increase the maximum number of price and liquidity observations that this pool will store\n    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to\n    /// the input observationCardinalityNext.\n    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store\n    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that is not stored\n/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the\n/// blockchain. The functions here may have variable gas costs.\ninterface IUniswapV3PoolDerivedState {\n    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp\n    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing\n    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,\n    /// you must call it with secondsAgos = [3600, 0].\n    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in\n    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.\n    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned\n    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp\n    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block\n    /// timestamp\n    function observe(uint32[] calldata secondsAgos)\n        external\n        view\n        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);\n\n    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range\n    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.\n    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first\n    /// snapshot is taken and the second snapshot is taken.\n    /// @param tickLower The lower tick of the range\n    /// @param tickUpper The upper tick of the range\n    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range\n    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range\n    /// @return secondsInside The snapshot of seconds per liquidity for the range\n    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)\n        external\n        view\n        returns (\n            int56 tickCumulativeInside,\n            uint160 secondsPerLiquidityInsideX128,\n            uint32 secondsInside\n        );\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Events emitted by a pool\n/// @notice Contains all events emitted by the pool\ninterface IUniswapV3PoolEvents {\n    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool\n    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize\n    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96\n    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool\n    event Initialize(uint160 sqrtPriceX96, int24 tick);\n\n    /// @notice Emitted when liquidity is minted for a given position\n    /// @param sender The address that minted the liquidity\n    /// @param owner The owner of the position and recipient of any minted liquidity\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity minted to the position range\n    /// @param amount0 How much token0 was required for the minted liquidity\n    /// @param amount1 How much token1 was required for the minted liquidity\n    event Mint(\n        address sender,\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted when fees are collected by the owner of a position\n    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees\n    /// @param owner The owner of the position for which fees are collected\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount0 The amount of token0 fees collected\n    /// @param amount1 The amount of token1 fees collected\n    event Collect(\n        address indexed owner,\n        address recipient,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount0,\n        uint128 amount1\n    );\n\n    /// @notice Emitted when a position's liquidity is removed\n    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect\n    /// @param owner The owner of the position for which liquidity is removed\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity to remove\n    /// @param amount0 The amount of token0 withdrawn\n    /// @param amount1 The amount of token1 withdrawn\n    event Burn(\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted by the pool for any swaps between token0 and token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the output of the swap\n    /// @param amount0 The delta of the token0 balance of the pool\n    /// @param amount1 The delta of the token1 balance of the pool\n    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96\n    /// @param liquidity The liquidity of the pool after the swap\n    /// @param tick The log base 1.0001 of price of the pool after the swap\n    event Swap(\n        address indexed sender,\n        address indexed recipient,\n        int256 amount0,\n        int256 amount1,\n        uint160 sqrtPriceX96,\n        uint128 liquidity,\n        int24 tick\n    );\n\n    /// @notice Emitted by the pool for any flashes of token0/token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the tokens from flash\n    /// @param amount0 The amount of token0 that was flashed\n    /// @param amount1 The amount of token1 that was flashed\n    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee\n    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee\n    event Flash(\n        address indexed sender,\n        address indexed recipient,\n        uint256 amount0,\n        uint256 amount1,\n        uint256 paid0,\n        uint256 paid1\n    );\n\n    /// @notice Emitted by the pool for increases to the number of observations that can be stored\n    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index\n    /// just before a mint/swap/burn.\n    /// @param observationCardinalityNextOld The previous value of the next observation cardinality\n    /// @param observationCardinalityNextNew The updated value of the next observation cardinality\n    event IncreaseObservationCardinalityNext(\n        uint16 observationCardinalityNextOld,\n        uint16 observationCardinalityNextNew\n    );\n\n    /// @notice Emitted when the protocol fee is changed by the pool\n    /// @param feeProtocol0Old The previous value of the token0 protocol fee\n    /// @param feeProtocol1Old The previous value of the token1 protocol fee\n    /// @param feeProtocol0New The updated value of the token0 protocol fee\n    /// @param feeProtocol1New The updated value of the token1 protocol fee\n    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);\n\n    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner\n    /// @param sender The address that collects the protocol fees\n    /// @param recipient The address that receives the collected protocol fees\n    /// @param amount0 The amount of token0 protocol fees that is withdrawn\n    /// @param amount0 The amount of token1 protocol fees that is withdrawn\n    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that never changes\n/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values\ninterface IUniswapV3PoolImmutables {\n    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface\n    /// @return The contract address\n    function factory() external view returns (address);\n\n    /// @notice The first of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token0() external view returns (address);\n\n    /// @notice The second of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token1() external view returns (address);\n\n    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6\n    /// @return The fee\n    function fee() external view returns (uint24);\n\n    /// @notice The pool tick spacing\n    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive\n    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...\n    /// This value is an int24 to avoid casting even though it is always positive.\n    /// @return The tick spacing\n    function tickSpacing() external view returns (int24);\n\n    /// @notice The maximum amount of position liquidity that can use any tick in the range\n    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and\n    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool\n    /// @return The max amount of liquidity per tick\n    function maxLiquidityPerTick() external view returns (uint128);\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissioned pool actions\n/// @notice Contains pool methods that may only be called by the factory owner\ninterface IUniswapV3PoolOwnerActions {\n    /// @notice Set the denominator of the protocol's % share of the fees\n    /// @param feeProtocol0 new protocol fee for token0 of the pool\n    /// @param feeProtocol1 new protocol fee for token1 of the pool\n    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;\n\n    /// @notice Collect the protocol fee accrued to the pool\n    /// @param recipient The address to which collected protocol fees should be sent\n    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1\n    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0\n    /// @return amount0 The protocol fee collected in token0\n    /// @return amount1 The protocol fee collected in token1\n    function collectProtocol(\n        address recipient,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that can change\n/// @notice These methods compose the pool's state, and can change with any frequency including multiple times\n/// per transaction\ninterface IUniswapV3PoolState {\n    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas\n    /// when accessed externally.\n    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value\n    /// tick The current tick of the pool, i.e. according to the last tick transition that was run.\n    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick\n    /// boundary.\n    /// observationIndex The index of the last oracle observation that was written,\n    /// observationCardinality The current maximum number of observations stored in the pool,\n    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.\n    /// feeProtocol The protocol fee for both tokens of the pool.\n    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0\n    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.\n    /// unlocked Whether the pool is currently locked to reentrancy\n    function slot0()\n        external\n        view\n        returns (\n            uint160 sqrtPriceX96,\n            int24 tick,\n            uint16 observationIndex,\n            uint16 observationCardinality,\n            uint16 observationCardinalityNext,\n            uint8 feeProtocol,\n            bool unlocked\n        );\n\n    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal0X128() external view returns (uint256);\n\n    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal1X128() external view returns (uint256);\n\n    /// @notice The amounts of token0 and token1 that are owed to the protocol\n    /// @dev Protocol fees will never exceed uint128 max in either token\n    function protocolFees() external view returns (uint128 token0, uint128 token1);\n\n    /// @notice The currently in range liquidity available to the pool\n    /// @dev This value has no relationship to the total liquidity across all ticks\n    function liquidity() external view returns (uint128);\n\n    /// @notice Look up information about a specific tick in the pool\n    /// @param tick The tick to look up\n    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or\n    /// tick upper,\n    /// liquidityNet how much liquidity changes when the pool price crosses the tick,\n    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,\n    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,\n    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick\n    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,\n    /// secondsOutside the seconds spent on the other side of the tick from the current tick,\n    /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.\n    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.\n    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for\n    /// a specific position.\n    function ticks(int24 tick)\n        external\n        view\n        returns (\n            uint128 liquidityGross,\n            int128 liquidityNet,\n            uint256 feeGrowthOutside0X128,\n            uint256 feeGrowthOutside1X128,\n            int56 tickCumulativeOutside,\n            uint160 secondsPerLiquidityOutsideX128,\n            uint32 secondsOutside,\n            bool initialized\n        );\n\n    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information\n    function tickBitmap(int16 wordPosition) external view returns (uint256);\n\n    /// @notice Returns the information about a position by the position's key\n    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper\n    /// @return _liquidity The amount of liquidity in the position,\n    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,\n    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,\n    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,\n    /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke\n    function positions(bytes32 key)\n        external\n        view\n        returns (\n            uint128 _liquidity,\n            uint256 feeGrowthInside0LastX128,\n            uint256 feeGrowthInside1LastX128,\n            uint128 tokensOwed0,\n            uint128 tokensOwed1\n        );\n\n    /// @notice Returns data about a specific observation index\n    /// @param index The element of the observations array to fetch\n    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time\n    /// ago, rather than at a specific index in the array.\n    /// @return blockTimestamp The timestamp of the observation,\n    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,\n    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,\n    /// Returns initialized whether the observation has been initialized and the values are safe to use\n    function observations(uint256 index)\n        external\n        view\n        returns (\n            uint32 blockTimestamp,\n            int56 tickCumulative,\n            uint160 secondsPerLiquidityCumulativeX128,\n            bool initialized\n        );\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.4.0;\n\n/// @title FixedPoint96\n/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)\n/// @dev Used in SqrtPriceMath.sol\nlibrary FixedPoint96 {\n    uint8 internal constant RESOLUTION = 96;\n    uint256 internal constant Q96 = 0x1000000000000000000000000;\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/FullMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.4.0;\n\n/// @title Contains 512-bit math functions\n/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision\n/// @dev Handles \"phantom overflow\" i.e., allows multiplication and division where an intermediate value overflows 256 bits\nlibrary FullMath {\n    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv\n    function mulDiv(\n        uint256 a,\n        uint256 b,\n        uint256 denominator\n    ) internal pure returns (uint256 result) {\n        // 512-bit multiply [prod1 prod0] = a * b\n        // Compute the product mod 2**256 and mod 2**256 - 1\n        // then use the Chinese Remainder Theorem to reconstruct\n        // 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(a, b, not(0))\n            prod0 := mul(a, b)\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            require(denominator > 0);\n            assembly {\n                result := div(prod0, denominator)\n            }\n            return result;\n        }\n\n        // Make sure the result is less than 2**256.\n        // 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        // Compute remainder using mulmod\n        uint256 remainder;\n        assembly {\n            remainder := mulmod(a, b, denominator)\n        }\n        // Subtract 256 bit number from 512 bit number\n        assembly {\n            prod1 := sub(prod1, gt(remainder, prod0))\n            prod0 := sub(prod0, remainder)\n        }\n\n        // Factor powers of two out of denominator\n        // Compute largest power of two divisor of denominator.\n        // Always >= 1.\n        uint256 twos = -denominator & denominator;\n        // Divide denominator by power of two\n        assembly {\n            denominator := div(denominator, twos)\n        }\n\n        // Divide [prod1 prod0] by the factors of two\n        assembly {\n            prod0 := div(prod0, twos)\n        }\n        // Shift in bits from prod1 into prod0. For this we need\n        // to flip `twos` such that it is 2**256 / twos.\n        // If twos is zero, then it becomes one\n        assembly {\n            twos := add(div(sub(0, twos), twos), 1)\n        }\n        prod0 |= prod1 * twos;\n\n        // Invert denominator mod 2**256\n        // Now that denominator is an odd number, it has an inverse\n        // modulo 2**256 such that denominator * inv = 1 mod 2**256.\n        // Compute the inverse by starting with a seed that is correct\n        // correct for four bits. That is, denominator * inv = 1 mod 2**4\n        uint256 inv = (3 * denominator) ^ 2;\n        // Now use Newton-Raphson iteration to improve the precision.\n        // Thanks to Hensel's lifting lemma, this also works in modular\n        // arithmetic, doubling the correct bits in each step.\n        inv *= 2 - denominator * inv; // inverse mod 2**8\n        inv *= 2 - denominator * inv; // inverse mod 2**16\n        inv *= 2 - denominator * inv; // inverse mod 2**32\n        inv *= 2 - denominator * inv; // inverse mod 2**64\n        inv *= 2 - denominator * inv; // inverse mod 2**128\n        inv *= 2 - denominator * inv; // inverse mod 2**256\n\n        // Because the division is now exact we can divide by multiplying\n        // with the modular inverse of denominator. This will give us the\n        // correct result modulo 2**256. Since the precoditions guarantee\n        // that the outcome is less than 2**256, this is the final result.\n        // We don't need to compute the high bits of the result and prod1\n        // is no longer required.\n        result = prod0 * inv;\n        return result;\n    }\n\n    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    function mulDivRoundingUp(\n        uint256 a,\n        uint256 b,\n        uint256 denominator\n    ) internal pure returns (uint256 result) {\n        result = mulDiv(a, b, denominator);\n        if (mulmod(a, b, denominator) > 0) {\n            require(result < type(uint256).max);\n            result++;\n        }\n    }\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.7.0;\n\n/// @title Optimized overflow and underflow safe math operations\n/// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost\nlibrary LowGasSafeMath {\n    /// @notice Returns x + y, reverts if sum overflows uint256\n    /// @param x The augend\n    /// @param y The addend\n    /// @return z The sum of x and y\n    function add(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        require((z = x + y) >= x);\n    }\n\n    /// @notice Returns x - y, reverts if underflows\n    /// @param x The minuend\n    /// @param y The subtrahend\n    /// @return z The difference of x and y\n    function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        require((z = x - y) <= x);\n    }\n\n    /// @notice Returns x * y, reverts if overflows\n    /// @param x The multiplicand\n    /// @param y The multiplier\n    /// @return z The product of x and y\n    function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        require(x == 0 || (z = x * y) / x == y);\n    }\n\n    /// @notice Returns x + y, reverts if overflows or underflows\n    /// @param x The augend\n    /// @param y The addend\n    /// @return z The sum of x and y\n    function add(int256 x, int256 y) internal pure returns (int256 z) {\n        require((z = x + y) >= x == (y >= 0));\n    }\n\n    /// @notice Returns x - y, reverts if overflows or underflows\n    /// @param x The minuend\n    /// @param y The subtrahend\n    /// @return z The difference of x and y\n    function sub(int256 x, int256 y) internal pure returns (int256 z) {\n        require((z = x - y) <= x == (y >= 0));\n    }\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/TickMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Math library for computing sqrt prices from ticks and vice versa\n/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports\n/// prices between 2**-128 and 2**128\nlibrary TickMath {\n    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128\n    int24 internal constant MIN_TICK = -887272;\n    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128\n    int24 internal constant MAX_TICK = -MIN_TICK;\n\n    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)\n    uint160 internal constant MIN_SQRT_RATIO = 4295128739;\n    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)\n    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;\n\n    /// @notice Calculates sqrt(1.0001^tick) * 2^96\n    /// @dev Throws if |tick| > max tick\n    /// @param tick The input tick for the above formula\n    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)\n    /// at the given tick\n    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {\n        uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));\n        require(absTick <= uint256(MAX_TICK), 'T');\n\n        uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;\n        if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;\n        if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;\n        if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;\n        if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;\n        if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;\n        if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;\n        if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;\n        if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;\n        if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;\n        if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;\n        if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;\n        if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;\n        if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;\n        if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;\n        if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;\n        if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;\n        if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;\n        if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;\n        if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;\n\n        if (tick > 0) ratio = type(uint256).max / ratio;\n\n        // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.\n        // we then downcast because we know the result always fits within 160 bits due to our tick input constraint\n        // we round up in the division so getTickAtSqrtRatio of the output price is always consistent\n        sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));\n    }\n\n    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio\n    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may\n    /// ever return.\n    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96\n    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio\n    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {\n        // second inequality must be < because the price can never reach the price at the max tick\n        require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');\n        uint256 ratio = uint256(sqrtPriceX96) << 32;\n\n        uint256 r = ratio;\n        uint256 msb = 0;\n\n        assembly {\n            let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(5, gt(r, 0xFFFFFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(4, gt(r, 0xFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(3, gt(r, 0xFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(2, gt(r, 0xF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(1, gt(r, 0x3))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := gt(r, 0x1)\n            msb := or(msb, f)\n        }\n\n        if (msb >= 128) r = ratio >> (msb - 127);\n        else r = ratio << (127 - msb);\n\n        int256 log_2 = (int256(msb) - 128) << 64;\n\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(63, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(62, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(61, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(60, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(59, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(58, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(57, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(56, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(55, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(54, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(53, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(52, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(51, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(50, f))\n        }\n\n        int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number\n\n        int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);\n        int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);\n\n        tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;\n    }\n}\n"
      },
      "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.7.5;\npragma abicoder v2;\n\nimport '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';\n\n/// @title Router token swapping functionality\n/// @notice Functions for swapping tokens via Uniswap V3\ninterface ISwapRouter is IUniswapV3SwapCallback {\n    struct ExactInputSingleParams {\n        address tokenIn;\n        address tokenOut;\n        uint24 fee;\n        address recipient;\n        uint256 deadline;\n        uint256 amountIn;\n        uint256 amountOutMinimum;\n        uint160 sqrtPriceLimitX96;\n    }\n\n    /// @notice Swaps `amountIn` of one token for as much as possible of another token\n    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata\n    /// @return amountOut The amount of the received token\n    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);\n\n    struct ExactInputParams {\n        bytes path;\n        address recipient;\n        uint256 deadline;\n        uint256 amountIn;\n        uint256 amountOutMinimum;\n    }\n\n    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path\n    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata\n    /// @return amountOut The amount of the received token\n    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);\n\n    struct ExactOutputSingleParams {\n        address tokenIn;\n        address tokenOut;\n        uint24 fee;\n        address recipient;\n        uint256 deadline;\n        uint256 amountOut;\n        uint256 amountInMaximum;\n        uint160 sqrtPriceLimitX96;\n    }\n\n    /// @notice Swaps as little as possible of one token for `amountOut` of another token\n    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata\n    /// @return amountIn The amount of the input token\n    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);\n\n    struct ExactOutputParams {\n        bytes path;\n        address recipient;\n        uint256 deadline;\n        uint256 amountOut;\n        uint256 amountInMaximum;\n    }\n\n    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)\n    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata\n    /// @return amountIn The amount of the input token\n    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);\n}\n"
      },
      "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport '@uniswap/v3-core/contracts/libraries/FullMath.sol';\nimport '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';\n\n/// @title Liquidity amount functions\n/// @notice Provides functions for computing liquidity amounts from token amounts and prices\nlibrary LiquidityAmounts {\n    /// @notice Downcasts uint256 to uint128\n    /// @param x The uint258 to be downcasted\n    /// @return y The passed value, downcasted to uint128\n    function toUint128(uint256 x) private pure returns (uint128 y) {\n        require((y = uint128(x)) == x);\n    }\n\n    /// @notice Computes the amount of liquidity received for a given amount of token0 and price range\n    /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param amount0 The amount0 being sent in\n    /// @return liquidity The amount of returned liquidity\n    function getLiquidityForAmount0(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint256 amount0\n    ) internal pure returns (uint128 liquidity) {\n        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);\n        uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);\n        return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));\n    }\n\n    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range\n    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param amount1 The amount1 being sent in\n    /// @return liquidity The amount of returned liquidity\n    function getLiquidityForAmount1(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint256 amount1\n    ) internal pure returns (uint128 liquidity) {\n        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);\n        return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96));\n    }\n\n    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current\n    /// pool prices and the prices at the tick boundaries\n    /// @param sqrtRatioX96 A sqrt price representing the current pool prices\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param amount0 The amount of token0 being sent in\n    /// @param amount1 The amount of token1 being sent in\n    /// @return liquidity The maximum amount of liquidity received\n    function getLiquidityForAmounts(\n        uint160 sqrtRatioX96,\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint256 amount0,\n        uint256 amount1\n    ) internal pure returns (uint128 liquidity) {\n        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);\n\n        if (sqrtRatioX96 <= sqrtRatioAX96) {\n            liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);\n        } else if (sqrtRatioX96 < sqrtRatioBX96) {\n            uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);\n            uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);\n\n            liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;\n        } else {\n            liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);\n        }\n    }\n\n    /// @notice Computes the amount of token0 for a given amount of liquidity and a price range\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param liquidity The liquidity being valued\n    /// @return amount0 The amount of token0\n    function getAmount0ForLiquidity(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity\n    ) internal pure returns (uint256 amount0) {\n        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);\n\n        return\n            FullMath.mulDiv(\n                uint256(liquidity) << FixedPoint96.RESOLUTION,\n                sqrtRatioBX96 - sqrtRatioAX96,\n                sqrtRatioBX96\n            ) / sqrtRatioAX96;\n    }\n\n    /// @notice Computes the amount of token1 for a given amount of liquidity and a price range\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param liquidity The liquidity being valued\n    /// @return amount1 The amount of token1\n    function getAmount1ForLiquidity(\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity\n    ) internal pure returns (uint256 amount1) {\n        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);\n\n        return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);\n    }\n\n    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current\n    /// pool prices and the prices at the tick boundaries\n    /// @param sqrtRatioX96 A sqrt price representing the current pool prices\n    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary\n    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary\n    /// @param liquidity The liquidity being valued\n    /// @return amount0 The amount of token0\n    /// @return amount1 The amount of token1\n    function getAmountsForLiquidity(\n        uint160 sqrtRatioX96,\n        uint160 sqrtRatioAX96,\n        uint160 sqrtRatioBX96,\n        uint128 liquidity\n    ) internal pure returns (uint256 amount0, uint256 amount1) {\n        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);\n\n        if (sqrtRatioX96 <= sqrtRatioAX96) {\n            amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);\n        } else if (sqrtRatioX96 < sqrtRatioBX96) {\n            amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);\n            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);\n        } else {\n            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);\n        }\n    }\n}\n"
      },
      "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.6.0;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\n\nlibrary TransferHelper {\n    /// @notice Transfers tokens from the targeted address to the given destination\n    /// @notice Errors with 'STF' if transfer fails\n    /// @param token The contract address of the token to be transferred\n    /// @param from The originating address from which the tokens will be transferred\n    /// @param to The destination address of the transfer\n    /// @param value The amount to be transferred\n    function safeTransferFrom(\n        address token,\n        address from,\n        address to,\n        uint256 value\n    ) internal {\n        (bool success, bytes memory data) =\n            token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));\n        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');\n    }\n\n    /// @notice Transfers tokens from msg.sender to a recipient\n    /// @dev Errors with ST if transfer fails\n    /// @param token The contract address of the token which will be transferred\n    /// @param to The recipient of the transfer\n    /// @param value The value of the transfer\n    function safeTransfer(\n        address token,\n        address to,\n        uint256 value\n    ) internal {\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));\n        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');\n    }\n\n    /// @notice Approves the stipulated contract to spend the given allowance in the given token\n    /// @dev Errors with 'SA' if transfer fails\n    /// @param token The contract address of the token to be approved\n    /// @param to The target of the approval\n    /// @param value The amount of the given token the target will be allowed to spend\n    function safeApprove(\n        address token,\n        address to,\n        uint256 value\n    ) internal {\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));\n        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');\n    }\n\n    /// @notice Transfers ETH to the recipient address\n    /// @dev Fails with `STE`\n    /// @param to The destination of the transfer\n    /// @param value The value to be transferred\n    function safeTransferETH(address to, uint256 value) internal {\n        (bool success, ) = to.call{value: value}(new bytes(0));\n        require(success, 'STE');\n    }\n}\n"
      },
      "contracts/adapters/tokemak/TokeHypervisor.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity 0.7.6;\n\nimport \"@openzeppelin/contracts/math/Math.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/math/SignedSafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/drafts/ERC20Permit.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\n\nimport \"@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/TickMath.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/FullMath.sol\";\nimport \"@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol\";\n\n/// @title TokeHypervisor\n/// @notice A Uniswap V2-like interface with fungible liquidity to Uniswap V3\n/// which allows for arbitrary liquidity provision: one-sided, lop-sided, and balanced\ncontract TokeHypervisor is IUniswapV3MintCallback, ERC20Permit, ReentrancyGuard {\n    using SafeERC20 for IERC20;\n    using SafeMath for uint256;\n    using SignedSafeMath for int256;\n\n    IUniswapV3Pool public pool;\n    IERC20 public token0;\n    IERC20 public token1;\n    uint24 public fee;\n    int24 public tickSpacing;\n\n    int24 public baseLower;\n    int24 public baseUpper;\n    int24 public limitLower;\n    int24 public limitUpper;\n\n    address public owner;\n    uint256 public deposit0Max;\n    uint256 public deposit1Max;\n    uint256 public maxTotalSupply;\n    address public whitelistedAddress;\n    bool public directDeposit; /// enter uni on deposit (avoid if client uses public rpc)\n\n    uint256 public constant PRECISION = 1e36;\n\n    bool mintCalled;\n\n    event Deposit(\n        address indexed sender,\n        address indexed to,\n        uint256 shares,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    event Withdraw(\n        address indexed sender,\n        address indexed to,\n        uint256 shares,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    event Rebalance(\n        int24 tick,\n        uint256 totalAmount0,\n        uint256 totalAmount1,\n        uint256 feeAmount0,\n        uint256 feeAmount1,\n        uint256 totalSupply\n    );\n\n    /// @param _pool Uniswap V3 pool for which liquidity is managed\n    /// @param _owner Owner of the Hypervisor\n    constructor(\n        address _pool,\n        address _owner,\n        string memory name,\n        string memory symbol\n    ) ERC20Permit(name) ERC20(name, symbol) {\n        require(_pool != address(0));\n        require(_owner != address(0));\n        pool = IUniswapV3Pool(_pool);\n        token0 = IERC20(pool.token0());\n        token1 = IERC20(pool.token1());\n        require(address(token0) != address(0));\n        require(address(token1) != address(0));\n        fee = pool.fee();\n        tickSpacing = pool.tickSpacing();\n\n        owner = _owner;\n\n        maxTotalSupply = 0; /// no cap\n        deposit0Max = uint256(-1);\n        deposit1Max = uint256(-1);\n    }\n\n    /// @notice Deposit tokens\n    /// @param deposit0 Amount of token0 transfered from sender to Hypervisor\n    /// @param deposit1 Amount of token1 transfered from sender to Hypervisor\n    /// @param to Address to which liquidity tokens are minted\n    /// @param from Address from which asset tokens are transferred\n    /// @return shares Quantity of liquidity tokens minted as a result of deposit\n    function deposit(\n        uint256 deposit0,\n        uint256 deposit1,\n        address to,\n        address from,\n        uint256[4] memory inMin\n    ) nonReentrant external returns (uint256 shares) {\n        require(deposit0 > 0 || deposit1 > 0);\n        require(deposit0 <= deposit0Max && deposit1 <= deposit1Max);\n        require(to != address(0) && to != address(this), \"to\");\n        require(msg.sender == whitelistedAddress, \"WHE\");\n\n        /// update fees\n        zeroBurn();\n\n        uint160 sqrtPrice = TickMath.getSqrtRatioAtTick(currentTick());\n        uint256 price = FullMath.mulDiv(uint256(sqrtPrice).mul(uint256(sqrtPrice)), PRECISION, 2**(96 * 2));\n\n        (uint256 pool0, uint256 pool1) = getTotalAmounts();\n\n        shares = deposit1.add(deposit0.mul(price).div(PRECISION));\n\n        if (deposit0 > 0) {\n          token0.safeTransferFrom(from, address(this), deposit0);\n        }\n        if (deposit1 > 0) {\n          token1.safeTransferFrom(from, address(this), deposit1);\n        }\n\n        uint256 total = totalSupply();\n        if (total != 0) {\n          uint256 pool0PricedInToken1 = pool0.mul(price).div(PRECISION);\n          shares = shares.mul(total).div(pool0PricedInToken1.add(pool1));\n          if (directDeposit) {\n            addLiquidity(\n              baseLower,\n              baseUpper,\n              address(this),\n              token0.balanceOf(address(this)),\n              token1.balanceOf(address(this)),\n              [inMin[0], inMin[1]]\n            );\n            addLiquidity(\n              limitLower,\n              limitUpper,\n              address(this),\n              token0.balanceOf(address(this)),\n              token1.balanceOf(address(this)),\n              [inMin[2],inMin[3]]\n            );\n          }\n        }\n        _mint(to, shares);\n        emit Deposit(from, to, shares, deposit0, deposit1);\n        /// Check total supply cap not exceeded. A value of 0 means no limit.\n        require(maxTotalSupply == 0 || total <= maxTotalSupply, \"max\");\n    }\n\n    /// @notice Update fees of the positions\n    /// @return baseLiquidity Fee of base position\n    /// @return limitLiquidity Fee of limit position\n    function zeroBurn() internal returns(uint128 baseLiquidity, uint128 limitLiquidity) {\n      /// update fees for inclusion\n      (baseLiquidity, , ) = _position(baseLower, baseUpper);\n      if (baseLiquidity > 0) {\n          pool.burn(baseLower, baseUpper, 0);\n      }\n      (limitLiquidity, , ) = _position(limitLower, limitUpper);\n      if (limitLiquidity > 0) {\n          pool.burn(limitLower, limitUpper, 0);\n      }\n    }\n\n    /// @notice Pull liquidity tokens from liquidity and receive the tokens\n    /// @param shares Number of liquidity tokens to pull from liquidity\n    /// @return base0 amount of token0 received from base position\n    /// @return base1 amount of token1 received from base position\n    /// @return limit0 amount of token0 received from limit position\n    /// @return limit1 amount of token1 received from limit position\n    function pullLiquidity(\n      uint256 shares,\n      uint256[4] memory minAmounts\n    ) external onlyOwner returns(\n        uint256 base0,\n        uint256 base1,\n        uint256 limit0,\n        uint256 limit1\n      ) {\n        zeroBurn();\n        (base0, base1) = _burnLiquidity(\n            baseLower,\n            baseUpper,\n            _liquidityForShares(baseLower, baseUpper, shares),\n            address(this),\n            false,\n            minAmounts[0],\n            minAmounts[1] \n        );\n        (limit0, limit1) = _burnLiquidity(\n            limitLower,\n            limitUpper,\n            _liquidityForShares(limitLower, limitUpper, shares),\n            address(this),\n            false,\n            minAmounts[2],\n            minAmounts[3] \n        );\n    }\n\n    function _baseLiquidityForShares(uint256 shares) internal view returns (uint128) {\n        return _liquidityForShares(baseLower, baseUpper, shares);\n    }\n\n    function _limitLiquidityForShares(uint256 shares) internal view returns (uint128) {\n        return _liquidityForShares(limitLower, limitUpper, shares);\n    }\n\n    /// @param shares Number of liquidity tokens to redeem as pool assets\n    /// @param to Address to which redeemed pool assets are sent\n    /// @param from Address from which liquidity tokens are sent\n    /// @param minAmounts min amount0,1 returned for shares of liq \n    /// @return amount0 Amount of token0 redeemed by the submitted liquidity tokens\n    /// @return amount1 Amount of token1 redeemed by the submitted liquidity tokens\n    function withdraw(\n        uint256 shares,\n        address to,\n        address from,\n        uint256[4] memory minAmounts\n    ) nonReentrant external returns (uint256 amount0, uint256 amount1) {\n        require(shares > 0, \"shares\");\n        require(to != address(0), \"to\");\n        require(msg.sender == whitelistedAddress, \"WHE\");\n\n        /// update fees\n        zeroBurn();\n\n        /// Withdraw liquidity from Uniswap pool\n        (uint256 base0, uint256 base1) = _burnLiquidity(\n            baseLower,\n            baseUpper,\n            _baseLiquidityForShares(shares),\n            to,\n            false,\n            minAmounts[0],\n            minAmounts[1]\n        );\n        (uint256 limit0, uint256 limit1) = _burnLiquidity(\n            limitLower,\n            limitUpper,\n            _limitLiquidityForShares(shares),\n            to,\n            false,\n            minAmounts[2],\n            minAmounts[3]\n        );\n\n        // Push tokens proportional to unused balances\n        uint256 unusedAmount0 = token0.balanceOf(address(this)).mul(shares).div(totalSupply());\n        uint256 unusedAmount1 = token1.balanceOf(address(this)).mul(shares).div(totalSupply());\n        if (unusedAmount0 > 0) token0.safeTransfer(to, unusedAmount0);\n        if (unusedAmount1 > 0) token1.safeTransfer(to, unusedAmount1);\n\n        amount0 = base0.add(limit0).add(unusedAmount0);\n        amount1 = base1.add(limit1).add(unusedAmount1);\n\n        _burn(from, shares);\n\n        emit Withdraw(from, to, shares, amount0, amount1);\n    }\n\n    /// @param _baseLower The lower tick of the base position\n    /// @param _baseUpper The upper tick of the base position\n    /// @param _limitLower The lower tick of the limit position\n    /// @param _limitUpper The upper tick of the limit position\n    /// @param  inMin min spend \n    /// @param  outMin min amount0,1 returned for shares of liq \n    /// @param feeRecipient Address of recipient of 10% of earned fees since last rebalance\n    function rebalance(\n        int24 _baseLower,\n        int24 _baseUpper,\n        int24 _limitLower,\n        int24 _limitUpper,\n        address feeRecipient,\n        uint256[4] memory inMin, \n        uint256[4] memory outMin\n    ) nonReentrant external onlyOwner {\n        require(\n            _baseLower < _baseUpper &&\n                _baseLower % tickSpacing == 0 &&\n                _baseUpper % tickSpacing == 0\n        );\n        require(\n            _limitLower < _limitUpper &&\n                _limitLower % tickSpacing == 0 &&\n                _limitUpper % tickSpacing == 0\n        );\n        require(\n          _limitUpper != _baseUpper ||\n          _limitLower != _baseLower\n        );\n        require(feeRecipient != address(0));\n\n        /// update fees\n        (uint128 baseLiquidity, uint128 limitLiquidity) = zeroBurn();\n\n        /// Withdraw all liquidity and collect all fees from Uniswap pool\n        (, uint256 feesLimit0, uint256 feesLimit1) = _position(baseLower, baseUpper);\n        (, uint256 feesBase0, uint256 feesBase1) = _position(limitLower, limitUpper);\n\n        uint256 fees0 = feesBase0.add(feesLimit0);\n        uint256 fees1 = feesBase1.add(feesLimit1);\n        (baseLiquidity, , ) = _position(baseLower, baseUpper);\n        (limitLiquidity, , ) = _position(limitLower, limitUpper);\n\n        _burnLiquidity(baseLower, baseUpper, baseLiquidity, address(this), true, outMin[0], outMin[1]);\n        _burnLiquidity(limitLower, limitUpper, limitLiquidity, address(this), true, outMin[2], outMin[3]);\n\n        /// transfer 10% of fees for VISR buybacks\n        if (fees0 > 0) token0.safeTransfer(feeRecipient, fees0.div(10));\n        if (fees1 > 0) token1.safeTransfer(feeRecipient, fees1.div(10));\n\n        emit Rebalance(\n            currentTick(),\n            token0.balanceOf(address(this)),\n            token1.balanceOf(address(this)),\n            fees0,\n            fees1,\n            totalSupply()\n        );\n\n        uint256[2] memory addMins = [inMin[0],inMin[1]];\n        baseLower = _baseLower;\n        baseUpper = _baseUpper;\n        addLiquidity(\n          baseLower,\n          baseUpper,\n          address(this),\n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this)),\n          addMins \n        );\n\n        addMins = [inMin[2],inMin[3]];\n        limitLower = _limitLower;\n        limitUpper = _limitUpper;\n        addLiquidity(\n          limitLower,\n          limitUpper,\n          address(this),\n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this)),\n          addMins\n        );\n    }\n\n    /// @notice Compound pending fees\n    /// @param inMin min spend \n    /// @return baseToken0Owed Pending fees of base token0\n    /// @return baseToken1Owed Pending fees of base token1\n    /// @return limitToken0Owed Pending fees of limit token0\n    /// @return limitToken1Owed Pending fees of limit token1\n    function compound(uint256[4] memory inMin) external onlyOwner returns (\n        uint128 baseToken0Owed,\n        uint128 baseToken1Owed,\n        uint128 limitToken0Owed,\n        uint128 limitToken1Owed\n    ) {\n        // update fees for compounding\n        zeroBurn();\n        (, baseToken0Owed,baseToken1Owed) = _position(baseLower, baseUpper);\n        (, limitToken0Owed,limitToken1Owed) = _position(limitLower, limitUpper);\n        \n        // collect fees\n        pool.collect(address(this), baseLower, baseLower, baseToken0Owed, baseToken1Owed);\n        pool.collect(address(this), limitLower, limitUpper, limitToken0Owed, limitToken1Owed);\n        \n        addLiquidity(\n          baseLower,\n          baseUpper,\n          address(this),\n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this)),\n          [inMin[0],inMin[1]]\n        );\n        addLiquidity(\n          limitLower,\n          limitUpper,\n          address(this),\n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this)),\n          [inMin[2],inMin[3]]\n        );\n    }\n\n    /// @notice Add tokens to base liquidity\n    /// @param amount0 Amount of token0 to add\n    /// @param amount1 Amount of token1 to add\n    function addBaseLiquidity(uint256 amount0, uint256 amount1, uint256[2] memory inMin) external onlyOwner {\n        addLiquidity(\n            baseLower,\n            baseUpper,\n            address(this),\n            amount0 == 0 && amount1 == 0 ? token0.balanceOf(address(this)) : amount0,\n            amount0 == 0 && amount1 == 0 ? token1.balanceOf(address(this)) : amount1,\n            inMin\n        );\n    }\n\n    /// @notice Add tokens to limit liquidity\n    /// @param amount0 Amount of token0 to add\n    /// @param amount1 Amount of token1 to add\n    function addLimitLiquidity(uint256 amount0, uint256 amount1, uint256[2] memory inMin) external onlyOwner {\n        addLiquidity(\n            limitLower,\n            limitUpper,\n            address(this),\n            amount0 == 0 && amount1 == 0 ? token0.balanceOf(address(this)) : amount0,\n            amount0 == 0 && amount1 == 0 ? token1.balanceOf(address(this)) : amount1,\n            inMin\n        );\n    }\n\n    /// @notice Add Liquidity\n    function addLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        address payer,\n        uint256 amount0,\n        uint256 amount1,\n        uint256[2] memory inMin\n    ) internal {        \n        uint128 liquidity = _liquidityForAmounts(tickLower, tickUpper, amount0, amount1);\n        _mintLiquidity(tickLower, tickUpper, liquidity, payer, inMin[0], inMin[1]);\n    }\n\n    /// @notice Adds the liquidity for the given position\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param liquidity The amount of liquidity to mint\n    /// @param payer Payer Data\n    /// @param amount0Min Minimum amount of token0 that should be paid\n    /// @param amount1Min Minimum amount of token1 that should be paid\n    function _mintLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 liquidity,\n        address payer,\n        uint256 amount0Min,\n        uint256 amount1Min\n    ) internal {\n        if (liquidity > 0) {\n            mintCalled = true;\n            (uint256 amount0, uint256 amount1) = pool.mint(\n                address(this),\n                tickLower,\n                tickUpper,\n                liquidity,\n                abi.encode(payer)\n            );\n            require(amount0 >= amount0Min && amount1 >= amount1Min, 'PSC');\n        }\n    }\n\n    /// @notice Burn liquidity from the sender and collect tokens owed for the liquidity\n    /// @param tickLower The lower tick of the position for which to burn liquidity\n    /// @param tickUpper The upper tick of the position for which to burn liquidity\n    /// @param liquidity The amount of liquidity to burn\n    /// @param to The address which should receive the fees collected\n    /// @param collectAll If true, collect all tokens owed in the pool, else collect the owed tokens of the burn\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function _burnLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 liquidity,\n        address to,\n        bool collectAll,\n        uint256 amount0Min,\n        uint256 amount1Min\n    ) internal returns (uint256 amount0, uint256 amount1) {\n        if (liquidity > 0) {\n            /// Burn liquidity\n            (uint256 owed0, uint256 owed1) = pool.burn(tickLower, tickUpper, liquidity);\n            require(owed0 >= amount0Min && owed1 >= amount1Min, \"PSC\");\n\n            // Collect amount owed\n            uint128 collect0 = collectAll ? type(uint128).max : _uint128Safe(owed0);\n            uint128 collect1 = collectAll ? type(uint128).max : _uint128Safe(owed1);\n            if (collect0 > 0 || collect1 > 0) {\n                (amount0, amount1) = pool.collect(to, tickLower, tickUpper, collect0, collect1);\n            }\n        }\n    }\n\n    /// @notice Get the liquidity amount for given liquidity tokens\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param shares Shares of position\n    /// @return The amount of liquidity toekn for shares\n    function _liquidityForShares(\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 shares\n    ) internal view returns (uint128) {\n        (uint128 position, , ) = _position(tickLower, tickUpper);\n        return _uint128Safe(uint256(position).mul(shares).div(totalSupply()));\n    }\n\n    /// @notice Get the info of the given position\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @return liquidity The amount of liquidity of the position\n    /// @return tokensOwed0 Amount of token0 owed\n    /// @return tokensOwed1 Amount of token1 owed\n    function _position(int24 tickLower, int24 tickUpper)\n        internal\n        view\n        returns (\n            uint128 liquidity,\n            uint128 tokensOwed0,\n            uint128 tokensOwed1\n        )\n    {\n        bytes32 positionKey = keccak256(abi.encodePacked(address(this), tickLower, tickUpper));\n        (liquidity, , , tokensOwed0, tokensOwed1) = pool.positions(positionKey);\n    }\n\n    /// @notice Callback function of uniswapV3Pool mint\n    function uniswapV3MintCallback(\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata data\n    ) external override {\n        require(msg.sender == address(pool));\n        require(mintCalled == true);\n        mintCalled = false;\n\n        if (amount0 > 0) token0.safeTransfer(msg.sender, amount0);\n        if (amount1 > 0) token1.safeTransfer(msg.sender, amount1);\n    }\n\n    /// @return total0 Quantity of token0 in both positions and unused in the Hypervisor\n    /// @return total1 Quantity of token1 in both positions and unused in the Hypervisor\n    function getTotalAmounts() public view returns (uint256 total0, uint256 total1) {\n        (, uint256 base0, uint256 base1) = getBasePosition();\n        (, uint256 limit0, uint256 limit1) = getLimitPosition();\n        total0 = token0.balanceOf(address(this)).add(base0).add(limit0);\n        total1 = token1.balanceOf(address(this)).add(base1).add(limit1);\n    }\n\n    /// @return liquidity Amount of total liquidity in the base position\n    /// @return amount0 Estimated amount of token0 that could be collected by\n    /// burning the base position\n    /// @return amount1 Estimated amount of token1 that could be collected by\n    /// burning the base position\n    function getBasePosition()\n        public\n        view\n        returns (\n            uint128 liquidity,\n            uint256 amount0,\n            uint256 amount1\n        )\n    {\n        (uint128 positionLiquidity, uint128 tokensOwed0, uint128 tokensOwed1) = _position(\n            baseLower,\n            baseUpper\n        );\n        (amount0, amount1) = _amountsForLiquidity(baseLower, baseUpper, positionLiquidity);\n        amount0 = amount0.add(uint256(tokensOwed0));\n        amount1 = amount1.add(uint256(tokensOwed1));\n        liquidity = positionLiquidity;\n    }\n\n    /// @return liquidity Amount of total liquidity in the limit position\n    /// @return amount0 Estimated amount of token0 that could be collected by\n    /// burning the limit position\n    /// @return amount1 Estimated amount of token1 that could be collected by\n    /// burning the limit position\n    function getLimitPosition()\n        public\n        view\n        returns (\n            uint128 liquidity,\n            uint256 amount0,\n            uint256 amount1\n        )\n    {\n        (uint128 positionLiquidity, uint128 tokensOwed0, uint128 tokensOwed1) = _position(\n            limitLower,\n            limitUpper\n        );\n        (amount0, amount1) = _amountsForLiquidity(limitLower, limitUpper, positionLiquidity);\n        amount0 = amount0.add(uint256(tokensOwed0));\n        amount1 = amount1.add(uint256(tokensOwed1));\n        liquidity = positionLiquidity;\n    }\n\n    /// @notice Get the amounts of the given numbers of liquidity tokens\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param liquidity The amount of liquidity tokens\n    /// @return Amount of token0 and token1\n    function _amountsForLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 liquidity\n    ) internal view returns (uint256, uint256) {\n        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();\n        return\n            LiquidityAmounts.getAmountsForLiquidity(\n                sqrtRatioX96,\n                TickMath.getSqrtRatioAtTick(tickLower),\n                TickMath.getSqrtRatioAtTick(tickUpper),\n                liquidity\n            );\n    }\n\n    /// @notice Get the liquidity amount of the given numbers of token0 and token1\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount0 The amount of token0\n    /// @param amount0 The amount of token1\n    /// @return Amount of liquidity tokens\n    function _liquidityForAmounts(\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0,\n        uint256 amount1\n    ) internal view returns (uint128) {\n        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();\n        return\n            LiquidityAmounts.getLiquidityForAmounts(\n                sqrtRatioX96,\n                TickMath.getSqrtRatioAtTick(tickLower),\n                TickMath.getSqrtRatioAtTick(tickUpper),\n                amount0,\n                amount1\n            );\n    }\n\n    /// @return tick Uniswap pool's current price tick\n    function currentTick() public view returns (int24 tick) {\n        (, tick, , , , , ) = pool.slot0();\n    }\n\n    function _uint128Safe(uint256 x) internal pure returns (uint128) {\n        assert(x <= type(uint128).max);\n        return uint128(x);\n    }\n\n    /// @param _address Array of addresses to be appended\n    function setWhitelist(address _address) external onlyOwner {\n        whitelistedAddress = _address;\n    }\n\n    /// @notice Remove Whitelisted\n    function removeWhitelisted() external onlyOwner {\n        whitelistedAddress = address(0);\n    }\n\n    /// @notice Toggle Direct Deposit\n    function toggleDirectDeposit() external onlyOwner {\n        directDeposit = !directDeposit;\n    }\n\n    function transferOwnership(address newOwner) external onlyOwner {\n        require(newOwner != address(0));\n        owner = newOwner;\n    }\n\n    modifier onlyOwner {\n        require(msg.sender == owner, \"only owner\");\n        _;\n    }\n}\n"
      },
      "contracts/adapters/tokemak/TokeHypervisorFactory.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity =0.7.6;\n\nimport {IUniswapV3Factory} from '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';\n\nimport {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';\n\nimport {TokeHypervisor} from './TokeHypervisor.sol';\n\n/// @title TokeHypervisorFactory\n\ncontract TokeHypervisorFactory is Ownable {\n    IUniswapV3Factory public uniswapV3Factory;\n    mapping(address => mapping(address => mapping(uint24 => address))) public getHypervisor; // toke0, token1, fee -> hypervisor address\n    address[] public allHypervisors;\n\n    event HypervisorCreated(address token0, address token1, uint24 fee, address hypervisor, uint256);\n\n    constructor(address _uniswapV3Factory) {\n        require(_uniswapV3Factory != address(0), \"uniswapV3Factory should be non-zero\");\n        uniswapV3Factory = IUniswapV3Factory(_uniswapV3Factory);\n    }\n\n    /// @notice Get the number of hypervisors created\n    /// @return Number of hypervisors created\n    function allHypervisorsLength() external view returns (uint256) {\n        return allHypervisors.length;\n    }\n\n    /// @notice Create a Hypervisor\n    /// @param tokenA Address of token0\n    /// @param tokenB Address of toekn1\n    /// @param fee The desired fee for the hypervisor\n    /// @param name Name of the hyervisor\n    /// @param symbol Symbole of the hypervisor\n    /// @return hypervisor Address of hypervisor created\n    function createHypervisor(\n        address tokenA,\n        address tokenB,\n        uint24 fee,\n        string memory name,\n        string memory symbol\n    ) external onlyOwner returns (address hypervisor) {\n        require(tokenA != tokenB, 'SF: IDENTICAL_ADDRESSES'); // TODO: using PoolAddress library (uniswap-v3-periphery)\n        (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n        require(token0 != address(0), 'SF: ZERO_ADDRESS');\n        require(getHypervisor[token0][token1][fee] == address(0), 'SF: HYPERVISOR_EXISTS');\n        int24 tickSpacing = uniswapV3Factory.feeAmountTickSpacing(fee);\n        require(tickSpacing != 0, 'SF: INCORRECT_FEE');\n        address pool = uniswapV3Factory.getPool(token0, token1, fee);\n        if (pool == address(0)) {\n            pool = uniswapV3Factory.createPool(token0, token1, fee);\n        }\n        hypervisor = address(\n            new TokeHypervisor{salt: keccak256(abi.encodePacked(token0, token1, fee, tickSpacing))}(pool, owner(), name, symbol)\n        );\n\n        getHypervisor[token0][token1][fee] = hypervisor;\n        getHypervisor[token1][token0][fee] = hypervisor; // populate mapping in the reverse direction\n        allHypervisors.push(hypervisor);\n        emit HypervisorCreated(token0, token1, fee, hypervisor, allHypervisors.length);\n    }\n}\n"
      },
      "contracts/Clearing.sol": {
        "content": "/// SPDX-License-Identifier: BUSL-1.1\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IHypervisor.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/FullMath.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/math/SignedSafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/TickMath.sol\";\n\n/// @title Clearing v1.2.3\n/// @notice Proxy contract for hypervisor positions management\ncontract Clearing is ReentrancyGuard {\n  using SafeERC20 for IERC20;\n  using SafeMath for uint256;\n  using SignedSafeMath for int256;\n\n  string constant VERSION = '1.2.3';\n  address public owner;\n  mapping(address => Position) public positions;\n\n  bool public twapCheck = true;\n  uint32 public twapInterval = 3600;\n  uint256 public depositDelta = 1002;\n  uint256 public deltaScale = 1000; /// must be a power of 10\n  uint256 public priceThreshold = 100;\n  uint256 constant MAX_UINT = 2**256 - 1;\n  uint256 public constant PRECISION = 1e36;\n\n  struct Position {\n    bool zeroDeposit;\n    bool customRatio;\n    bool customTwap;\n    bool ratioRemoved;\n    bool depositOverride; // force custom deposit constraints\n    bool twapOverride; // force twap check for hypervisor instance\n    uint8 version; \n    uint32 twapInterval; // override global twap\n    uint256 priceThreshold; // custom price threshold\n    uint256 deposit0Max;\n    uint256 deposit1Max;\n    uint256 maxTotalSupply;\n    uint256 fauxTotal0;\n    uint256 fauxTotal1;\n    mapping(address=>bool) list; // whitelist certain accounts for freedeposit\n  }\n\n  event PositionAdded(address, uint8);\n  event CustomDeposit(address, uint256, uint256, uint256);\n  event PriceThresholdSet(uint256 _priceThreshold);\n  event DepositDeltaSet(uint256 _depositDelta);\n  event DeltaScaleSet(uint256 _deltaScale);\n  event TwapIntervalSet(uint32 _twapInterval);\n  event TwapOverrideSet(address pos, bool twapOverride, uint32 _twapInterval, uint256 _priceThreshold);\n  event PriceThresholdPosSet(address pos, uint256 _priceThreshold);\n  event DepositZeroToggled();\n  event DepositOverrideToggled(address pos);\n  event DepositZeroOverrideToggled(address pos);\n  event TwapToggled();\n  event ListAppended(address pos, address[] listed);\n  event ListRemoved(address pos, address listed);\n  event CustomRatio(address pos, uint256 fauxTotal0, uint256 fauxTotal1);\n  event RatioRemoved(address pos);\n\n  constructor() {\n    owner = msg.sender;\n  }\n\n  modifier onlyAddedPosition(address pos) {\n    Position storage p = positions[pos];\n    require(p.version != 0, \"not added\");\n    _;\n  }\n\n  /// @notice Add the hypervisor position\n  /// @param pos Address of the hypervisor\n  /// @param version Type of hypervisor\n  function addPosition(address pos, uint8 version) external onlyOwner {\n    Position storage p = positions[pos];\n    require(p.version == 0, 'already added');\n    require(version > 0, 'version < 1');\n    p.version = version;\n    IHypervisor(pos).token0().safeApprove(pos, MAX_UINT);\n    IHypervisor(pos).token1().safeApprove(pos, MAX_UINT);\n    emit PositionAdded(pos, version);\n  }\n\n  /// @notice apply configuration constraints to shares minted \n  /// @param pos Address of the hypervisor\n  /// @param shares Amount of shares minted (included for upgrades)\n  /// @return cleared whether shares are cleared \n  function clearShares(\n    address pos,\n    uint256 shares \n  ) public view onlyAddedPosition(pos) returns (bool cleared) {\n    if(positions[pos].maxTotalSupply != 0) {\n      require(IHypervisor(pos).totalSupply() <= positions[pos].maxTotalSupply, \"exceeds max supply\");\n    }\n    return true;\n  }\n\n  /// @notice apply configuration constraints to deposit \n  /// @param pos Address of the hypervisor\n  /// @param deposit0 Amount of token0 to deposit\n  /// @param deposit1 Amount of token1 to deposit\n  /// @param to Address to receive liquidity tokens\n  /// @param pos Hypervisor Address\n  /// @param minIn min assets to expect in position during a direct deposit \n  /// @return cleared whether deposit is cleared \n  function clearDeposit(\n    uint256 deposit0,\n    uint256 deposit1,\n    address from,\n    address to,\n    address pos,\n    uint256[4] memory minIn\n  ) public view onlyAddedPosition(pos) returns (bool cleared) {\n    require(to != address(0), \"to should be non-zero\");\n    Position storage p = positions[pos];\n    if(!positions[pos].list[from]) {\n      if(!p.zeroDeposit) require(deposit0 > 0 && deposit1 > 0, \"must deposit to both sides\");\n      if (deposit0 > 0 && !p.zeroDeposit) {\n        (uint256 test1Min, uint256 test1Max) = getDepositAmount(pos, address(IHypervisor(pos).token0()), deposit0);\n        require(deposit1 >= test1Min && deposit1 <= test1Max, \"Improper ratio\"); \n      }\n      if (deposit1 > 0 && !p.zeroDeposit) {\n        (uint256 test0Min, uint256 test0Max) = getDepositAmount(pos, address(IHypervisor(pos).token1()), deposit1);\n        require(deposit0 >= test0Min && deposit0 <= test0Max, \"Improper ratio\"); \n      }\n    }\n    if (twapCheck || p.twapOverride) {\n      /// check twap\n      checkPriceChange(\n        pos,\n        (p.twapOverride ? p.twapInterval : twapInterval),\n        (p.twapOverride ? p.priceThreshold : priceThreshold)\n      );\n    }\n\n    if (p.depositOverride && !positions[pos].list[from]) {\n      if (p.deposit0Max > 0) {\n        require(deposit0 <= p.deposit0Max, \"token0 exceeds\");\n      }\n      if (p.deposit1Max > 0) {\n        require(deposit1 <= p.deposit1Max, \"token1 exceeds\");\n      }\n    }\n    return true;\n  }\n\n  /// @notice Get the amount of token to deposit for the given amount of pair token\n  /// @param pos Hypervisor Address\n  /// @param token Address of token to deposit\n  /// @param _deposit Amount of token to deposit\n  /// @return amountStart Minimum amounts of the pair token to deposit\n  /// @return amountEnd Maximum amounts of the pair token to deposit\n  function getDepositAmount(\n    address pos,\n    address token,\n    uint256 _deposit\n  ) public view returns (uint256 amountStart, uint256 amountEnd) {\n    require(token == address(IHypervisor(pos).token0()) || token == address(IHypervisor(pos).token1()), \"token mistmatch\");\n    require(_deposit > 0, \"deposits can't be zero\");\n    (uint256 total0, uint256 total1) = IHypervisor(pos).getTotalAmounts();\n    if (IHypervisor(pos).totalSupply() == 0 || total0 == 0 || total1 == 0) {\n      amountStart = 0;\n      if (token == address(IHypervisor(pos).token0())) {\n        amountEnd = IHypervisor(pos).deposit1Max();\n      } else {\n        amountEnd = IHypervisor(pos).deposit0Max();\n      }\n    } else {\n      (uint256 ratioStart, uint256 ratioEnd) = positions[pos].customRatio ? \n        applyRatio(pos, token, positions[pos].fauxTotal0, positions[pos].fauxTotal1) :\n        applyRatio(pos, token, total0, total1);\n      amountStart = FullMath.mulDiv(_deposit, PRECISION, ratioStart);\n      amountEnd = FullMath.mulDiv(_deposit, PRECISION, ratioEnd);\n    }\n  }\n\n  /// @notice Get range for deposit based on provided amounts\n  /// @param pos Hypervisor Address\n  /// @param token Address of token to deposit\n  /// @param total0 Amount of token0 in hype \n  /// @param total1 Amount of token1 in hype \n  /// @return ratioStart Minimum amounts of the pair token to deposit\n  /// @return ratioEnd Maximum amounts of the pair token to deposit\n  function applyRatio(\n    address pos,\n    address token,\n    uint256 total0,\n    uint256 total1\n  ) public view returns (uint256 ratioStart, uint256 ratioEnd) {\n    require(token == address(IHypervisor(pos).token0()) || token == address(IHypervisor(pos).token1()), \"token mistmatch\");\n    if (token == address(IHypervisor(pos).token0())) {\n      ratioStart = FullMath.mulDiv(total0.mul(depositDelta), PRECISION, total1.mul(deltaScale));\n      ratioEnd = FullMath.mulDiv(total0.mul(deltaScale), PRECISION, total1.mul(depositDelta));\n    } else {\n      ratioStart = FullMath.mulDiv(total1.mul(depositDelta), PRECISION, total0.mul(deltaScale));\n      ratioEnd = FullMath.mulDiv(total1.mul(deltaScale), PRECISION, total0.mul(depositDelta));\n    }\n  }\n\n  /// @notice Check if the price change overflows or not based on given twap and threshold in the hypervisor\n  /// @param pos Hypervisor Address\n  /// @param _twapInterval Time intervals\n  /// @param _priceThreshold Price Threshold\n  /// @return price Current price\n  function checkPriceChange(\n    address pos,\n    uint32 _twapInterval,\n    uint256 _priceThreshold\n  ) public view returns (uint256 price) {\n\n    (uint160 sqrtPrice, , , , , , ) = IHypervisor(pos).pool().slot0();\n    price = FullMath.mulDiv(uint256(sqrtPrice).mul(uint256(sqrtPrice)), PRECISION, 2**(96 * 2));\n\n    uint160 sqrtPriceBefore = getSqrtTwapX96(pos, _twapInterval);\n    uint256 priceBefore = FullMath.mulDiv(uint256(sqrtPriceBefore).mul(uint256(sqrtPriceBefore)), PRECISION, 2**(96 * 2));\n    if (price.mul(100).div(priceBefore) > _priceThreshold || priceBefore.mul(100).div(price) > _priceThreshold)\n      revert(\"Price change Overflow\");\n  }\n\n  /// @notice Get the sqrt price before the given interval\n  /// @param pos Hypervisor Address\n  /// @param _twapInterval Time intervals\n  /// @return sqrtPriceX96 Sqrt price before interval\n  function getSqrtTwapX96(address pos, uint32 _twapInterval) public view returns (uint160 sqrtPriceX96) {\n    if (_twapInterval == 0) {\n      /// return the current price if _twapInterval == 0\n      (sqrtPriceX96, , , , , , ) = IHypervisor(pos).pool().slot0();\n    } \n    else {\n      uint32[] memory secondsAgos = new uint32[](2);\n      secondsAgos[0] = _twapInterval; /// from (before)\n      secondsAgos[1] = 0; /// to (now)\n\n      (int56[] memory tickCumulatives, ) = IHypervisor(pos).pool().observe(secondsAgos);\n\n      /// tick(imprecise as it's an integer) to price\n      sqrtPriceX96 = TickMath.getSqrtRatioAtTick(\n        int24((tickCumulatives[1] - tickCumulatives[0]) / _twapInterval)\n      );\n    }\n  }\n\n  /// @param _priceThreshold Price Threshold\n  function setPriceThreshold(uint256 _priceThreshold) external onlyOwner {\n    priceThreshold = _priceThreshold;\n    emit PriceThresholdSet(_priceThreshold);\n  }\n\n  /// @param _depositDelta Number to calculate deposit ratio\n  function setDepositDelta(uint256 _depositDelta) external onlyOwner {\n    depositDelta = _depositDelta;\n    emit DepositDeltaSet(_depositDelta);\n  }\n\n  /// @param _deltaScale Number to calculate deposit ratio\n  function setDeltaScale(uint256 _deltaScale) external onlyOwner {\n    deltaScale = _deltaScale;\n    emit DeltaScaleSet(_deltaScale);\n  }\n\n  /// @param pos Hypervisor address\n  /// @param deposit0Max Amount of maximum deposit amounts of token0\n  /// @param deposit1Max Amount of maximum deposit amounts of token1\n  /// @param maxTotalSupply Maximum total suppoy of hypervisor\n  function customDeposit(\n    address pos,\n    uint256 deposit0Max,\n    uint256 deposit1Max,\n    uint256 maxTotalSupply\n  ) external onlyOwner onlyAddedPosition(pos) {\n    Position storage p = positions[pos];\n    p.deposit0Max = deposit0Max;\n    p.deposit1Max = deposit1Max;\n    p.maxTotalSupply = maxTotalSupply;\n    emit CustomDeposit(pos, deposit0Max, deposit1Max, maxTotalSupply);\n  }\n\n  /// @param pos Hypervisor address\n  /// @param customRatio whether to use custom ratio \n  /// @param fauxTotal0 override total0\n  /// @param fauxTotal1 override total1 \n  function customRatio(\n    address pos,\n    bool customRatio,\n    uint256 fauxTotal0,\n    uint256 fauxTotal1\n  ) external onlyOwner onlyAddedPosition(pos) {\n    require(!positions[pos].ratioRemoved, \"custom ratio is no longer available\");\n    Position storage p = positions[pos];\n    p.customRatio = customRatio;\n    p.fauxTotal0 = fauxTotal0;\n    p.fauxTotal1 = fauxTotal1;\n    emit CustomRatio(pos, fauxTotal0, fauxTotal1);\n  }\n\n  // @note permantently remove ability to apply custom ratio to hype\n  function removeRatio(address pos) external onlyOwner onlyAddedPosition(pos) {\n    Position storage p = positions[pos];\n    p.ratioRemoved = true;\n    emit RatioRemoved(pos);\n  }\n\n  /// @notice Toggle deposit override\n  /// @param pos Hypervisor Address\n  function toggleDepositOverride(address pos) external onlyOwner onlyAddedPosition(pos) {\n    Position storage p = positions[pos];\n    p.depositOverride = !p.depositOverride;\n    emit DepositOverrideToggled(pos);\n  }\n\n  /// @notice Toggle free deposit of the given hypervisor\n  /// @param pos Hypervisor Address\n  function toggleDepositZeroOverride(address pos) external onlyOwner onlyAddedPosition(pos) {\n    Position storage p = positions[pos];\n    p.zeroDeposit = !p.zeroDeposit;\n    emit DepositZeroOverrideToggled(pos);\n  }\n\n  /// @param _twapInterval Time intervals\n  function setTwapInterval(uint32 _twapInterval) external onlyOwner {\n    twapInterval = _twapInterval;\n    emit TwapIntervalSet(_twapInterval);\n  }\n\n  /// @param pos Hypervisor Address\n  /// @param twapOverride Twap Override\n  /// @param _twapInterval Time Intervals\n  /// @param _priceThreshold Price Threshold\n  function setTwapOverride(address pos, bool twapOverride, uint32 _twapInterval, uint256 _priceThreshold) external onlyOwner onlyAddedPosition(pos) {\n    Position storage p = positions[pos];\n    p.twapOverride = twapOverride;\n    p.twapInterval = _twapInterval;\n    p.priceThreshold = _priceThreshold;\n    emit TwapOverrideSet(pos, twapOverride, _twapInterval, _priceThreshold);\n  }\n\n  /// @notice Twap Toggle\n  function toggleTwap() external onlyOwner {\n    twapCheck = !twapCheck;\n    emit TwapToggled();\n  }\n\n  // @notice check if an address is whitelisted for hype\n  function getListed(address pos, address i) public view returns(bool) {\n    Position storage p = positions[pos];\n    return p.list[i];\n  }\n\n  /// @notice Append whitelist to hypervisor\n  /// @param pos Hypervisor Address\n  /// @param listed Address array to add in whitelist\n  function appendList(address pos, address[] memory listed) external onlyOwner onlyAddedPosition(pos) {\n    Position storage p = positions[pos];\n    for (uint8 i; i < listed.length; i++) {\n      p.list[listed[i]] = true;\n    }\n    emit ListAppended(pos, listed);\n  }\n\n  /// @notice Remove address from whitelist\n  /// @param pos Hypervisor Address\n  /// @param listed Address to remove from whitelist\n  function removeListed(address pos, address listed) external onlyOwner onlyAddedPosition(pos) {\n    Position storage p = positions[pos];\n    p.list[listed] = false;\n    emit ListRemoved(pos, listed);\n  }\n\n  function transferOwnership(address newOwner) external onlyOwner {\n    require(newOwner != address(0), \"newOwner should be non-zero\");\n    owner = newOwner;\n  }\n\n  modifier onlyOwner {\n    require(msg.sender == owner, \"only owner\");\n    _;\n  }\n}"
      },
      "contracts/Hypervisor.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\n\nimport \"@openzeppelin/contracts/math/Math.sol\";\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/math/SignedSafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/drafts/ERC20Permit.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\n\nimport \"@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/TickMath.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/FullMath.sol\";\nimport \"@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol\";\n\n/// @title Hypervisor v1.3\n/// @notice A Uniswap V2-like interface with fungible liquidity to Uniswap V3\n/// which allows for arbitrary liquidity provision: one-sided, lop-sided, and balanced\ncontract Hypervisor is IUniswapV3MintCallback, ERC20Permit, ReentrancyGuard {\n    using SafeERC20 for IERC20;\n    using SafeMath for uint256;\n    using SignedSafeMath for int256;\n\n    IUniswapV3Pool public pool;\n    IERC20 public token0;\n    IERC20 public token1;\n    uint8 public fee = 4;\n    int24 public tickSpacing;\n\n    int24 public baseLower;\n    int24 public baseUpper;\n    int24 public limitLower;\n    int24 public limitUpper;\n\n    address public owner;\n    uint256 public deposit0Max;\n    uint256 public deposit1Max;\n    uint256 public maxTotalSupply;\n    address public whitelistedAddress;\n    address public feeRecipient;\n    bool public directDeposit; /// enter uni on deposit (avoid if client uses public rpc)\n\n    uint256 public constant PRECISION = 1e36;\n\n    bool mintCalled;\n\n   event Deposit(\n        address indexed sender,\n        address indexed to,\n        uint256 shares,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    event Withdraw(\n        address indexed sender,\n        address indexed to,\n        uint256 shares,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    event Rebalance(\n        int24 tick,\n        uint256 totalAmount0,\n        uint256 totalAmount1,\n        uint256 feeAmount0,\n        uint256 feeAmount1,\n        uint256 totalSupply\n    );\n\n    event ZeroBurn(uint8 fee, uint256 fees0, uint256 fees1);\n    event SetFee(uint8 newFee);\n\n\n    /// @param _pool Uniswap V3 pool for which liquidity is managed\n    /// @param _owner Owner of the Hypervisor\n    constructor(\n        address _pool,\n        address _owner,\n        string memory name,\n        string memory symbol\n    ) ERC20Permit(name) ERC20(name, symbol) {\n        require(_pool != address(0));\n        require(_owner != address(0));\n        pool = IUniswapV3Pool(_pool);\n        token0 = IERC20(pool.token0());\n        token1 = IERC20(pool.token1());\n        require(address(token0) != address(0));\n        require(address(token1) != address(0));\n        tickSpacing = pool.tickSpacing();\n\n        owner = _owner;\n\n        maxTotalSupply = 0; /// no cap\n        deposit0Max = uint256(-1);\n        deposit1Max = uint256(-1);\n    }\n\n    /// @notice Deposit tokens\n    /// @param deposit0 Amount of token0 transfered from sender to Hypervisor\n    /// @param deposit1 Amount of token1 transfered from sender to Hypervisor\n    /// @param to Address to which liquidity tokens are minted\n    /// @param from Address from which asset tokens are transferred\n    /// @param inMin min spend for directDeposit is true \n    /// @return shares Quantity of liquidity tokens minted as a result of deposit\n    function deposit(\n        uint256 deposit0,\n        uint256 deposit1,\n        address to,\n        address from,\n        uint256[4] memory inMin\n    ) nonReentrant external returns (uint256 shares) {\n        require(deposit0 > 0 || deposit1 > 0);\n        require(deposit0 <= deposit0Max && deposit1 <= deposit1Max);\n        require(to != address(0) && to != address(this), \"to\");\n        require(msg.sender == whitelistedAddress, \"WHE\");\n\n        /// update fees\n        zeroBurn();\n\n        (uint160 sqrtPrice, , , , , , ) = pool.slot0();\n        uint256 price = FullMath.mulDiv(uint256(sqrtPrice).mul(uint256(sqrtPrice)), PRECISION, 2**(96 * 2));\n\n        (uint256 pool0, uint256 pool1) = getTotalAmounts();\n\n        shares = deposit1.add(deposit0.mul(price).div(PRECISION));\n\n        if (deposit0 > 0) {\n          token0.safeTransferFrom(from, address(this), deposit0);\n        }\n        if (deposit1 > 0) {\n          token1.safeTransferFrom(from, address(this), deposit1);\n        }\n\n        uint256 total = totalSupply();\n        if (total != 0) {\n          uint256 pool0PricedInToken1 = pool0.mul(price).div(PRECISION);\n          shares = shares.mul(total).div(pool0PricedInToken1.add(pool1));\n          if (directDeposit) {\n            uint128 liquidity = _liquidityForAmounts(\n              baseLower,\n              baseUpper, \n              token0.balanceOf(address(this)),\n              token1.balanceOf(address(this))\n            );\n            _mintLiquidity(baseLower, baseUpper, liquidity, address(this), inMin[0], inMin[1]);\n            liquidity = _liquidityForAmounts(\n              limitLower,\n              limitUpper, \n              token0.balanceOf(address(this)),\n              token1.balanceOf(address(this))\n            );\n            _mintLiquidity(limitLower, limitUpper, liquidity, address(this), inMin[2], inMin[3]);\n          }\n        }\n        _mint(to, shares);\n        emit Deposit(from, to, shares, deposit0, deposit1);\n        /// Check total supply cap not exceeded. A value of 0 means no limit.\n        require(maxTotalSupply == 0 || total <= maxTotalSupply, \"max\");\n    }\n\n    function _zeroBurn(int24 tickLower, int24 tickUpper) internal returns(uint128 liquidity) {\n      /// update fees for inclusion\n      (liquidity, ,) = _position(tickLower, tickUpper);\n      if(liquidity > 0) {\n        pool.burn(tickLower, tickUpper, 0);\n        (uint256 owed0, uint256 owed1) = pool.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max);\n        emit ZeroBurn(fee, owed0, owed1);\n        if (owed0.div(fee) > 0 && token0.balanceOf(address(this)) > 0) token0.safeTransfer(feeRecipient, owed0.div(fee));\n        if (owed1.div(fee) > 0 && token1.balanceOf(address(this)) > 0) token1.safeTransfer(feeRecipient, owed1.div(fee));\n      }      \n    }\n\n    /// @notice Update fees of the positions\n    /// @return baseLiquidity Fee of base position\n    /// @return limitLiquidity Fee of limit position\n    function zeroBurn() internal returns(uint128 baseLiquidity, uint128 limitLiquidity) {\n      baseLiquidity = _zeroBurn(baseLower, baseUpper);\n      limitLiquidity = _zeroBurn(limitLower, limitUpper); \n    }\n\n    /// @notice Pull liquidity tokens from liquidity and receive the tokens\n    /// @param shares Number of liquidity tokens to pull from liquidity\n    /// @param tickLower lower tick\n    /// @param tickUpper upper tick\n    /// @param amountMin min outs \n    /// @return amount0 amount of token0 received from base position\n    /// @return amount1 amount of token1 received from base position\n    function pullLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 shares,\n        uint256[2] memory amountMin\n    ) external onlyOwner returns (uint256 amount0, uint256 amount1) {\n        _zeroBurn(tickLower, tickUpper);\n        (amount0, amount1) = _burnLiquidity(\n          tickLower,\n          tickUpper,\n          _liquidityForShares(tickLower, tickUpper, shares),\n          address(this),\n          false,\n          amountMin[0],\n          amountMin[1]\n        );\n    }\n\n    /// @param shares Number of liquidity tokens to redeem as pool assets\n    /// @param to Address to which redeemed pool assets are sent\n    /// @param from Address from which liquidity tokens are sent\n    /// @param minAmounts min amount0,1 returned for shares of liq \n    /// @return amount0 Amount of token0 redeemed by the submitted liquidity tokens\n    /// @return amount1 Amount of token1 redeemed by the submitted liquidity tokens\n    function withdraw(\n        uint256 shares,\n        address to,\n        address from,\n        uint256[4] memory minAmounts\n    ) nonReentrant external returns (uint256 amount0, uint256 amount1) {\n        require(shares > 0, \"shares\");\n        require(to != address(0), \"to\");\n\n        /// update fees\n        zeroBurn();\n\n        /// Withdraw liquidity from Uniswap pool\n        (uint256 base0, uint256 base1) = _burnLiquidity(\n            baseLower,\n            baseUpper,\n            _liquidityForShares(baseLower, baseUpper, shares),\n            to,\n            false,\n            minAmounts[0],\n            minAmounts[1]\n        );\n        (uint256 limit0, uint256 limit1) = _burnLiquidity(\n            limitLower,\n            limitUpper,\n            _liquidityForShares(limitLower, limitUpper, shares),\n            to,\n            false,\n            minAmounts[2],\n            minAmounts[3]\n        );\n\n        // Push tokens proportional to unused balances\n        uint256 unusedAmount0 = token0.balanceOf(address(this)).mul(shares).div(totalSupply());\n        uint256 unusedAmount1 = token1.balanceOf(address(this)).mul(shares).div(totalSupply());\n        if (unusedAmount0 > 0) token0.safeTransfer(to, unusedAmount0);\n        if (unusedAmount1 > 0) token1.safeTransfer(to, unusedAmount1);\n\n        amount0 = base0.add(limit0).add(unusedAmount0);\n        amount1 = base1.add(limit1).add(unusedAmount1);\n\n        require( from == msg.sender, \"own\");\n        _burn(from, shares);\n\n        emit Withdraw(from, to, shares, amount0, amount1);\n    }\n\n    /// @param _baseLower The lower tick of the base position\n    /// @param _baseUpper The upper tick of the base position\n    /// @param _limitLower The lower tick of the limit position\n    /// @param _limitUpper The upper tick of the limit position\n    /// @param  inMin min spend \n    /// @param  outMin min amount0,1 returned for shares of liq \n    /// @param _feeRecipient Address of recipient of 10% of earned fees since last rebalance\n    function rebalance(\n        int24 _baseLower,\n        int24 _baseUpper,\n        int24 _limitLower,\n        int24 _limitUpper,\n        address _feeRecipient,\n        uint256[4] memory inMin, \n        uint256[4] memory outMin\n    ) nonReentrant external onlyOwner {\n        require(\n            _baseLower < _baseUpper &&\n                _baseLower % tickSpacing == 0 &&\n                _baseUpper % tickSpacing == 0\n        );\n        require(\n            _limitLower < _limitUpper &&\n                _limitLower % tickSpacing == 0 &&\n                _limitUpper % tickSpacing == 0\n        );\n        require(\n          _limitUpper != _baseUpper ||\n          _limitLower != _baseLower\n        );\n        require(_feeRecipient != address(0));\n        feeRecipient = _feeRecipient;\n\n        /// update fees\n        zeroBurn();\n\n        /// Withdraw all liquidity and collect all fees from Uniswap pool\n        (uint128 baseLiquidity, uint256 feesLimit0, uint256 feesLimit1) = _position(baseLower, baseUpper);\n        (uint128 limitLiquidity, uint256 feesBase0, uint256 feesBase1) = _position(limitLower, limitUpper);\n\n        _burnLiquidity(baseLower, baseUpper, baseLiquidity, address(this), true, outMin[0], outMin[1]);\n        _burnLiquidity(limitLower, limitUpper, limitLiquidity, address(this), true, outMin[2], outMin[3]);\n\n        emit Rebalance(\n            currentTick(),\n            token0.balanceOf(address(this)),\n            token1.balanceOf(address(this)),\n            feesBase0.add(feesLimit0),\n            feesBase1.add(feesLimit1),\n            totalSupply()\n        );\n\n        baseLower = _baseLower;\n        baseUpper = _baseUpper;\n        baseLiquidity = _liquidityForAmounts(\n          baseLower,\n          baseUpper, \n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this))\n        );\n        _mintLiquidity(baseLower, baseUpper, baseLiquidity, address(this), inMin[0], inMin[1]);\n\n        limitLower = _limitLower;\n        limitUpper = _limitUpper;\n        limitLiquidity = _liquidityForAmounts(\n          limitLower,\n          limitUpper, \n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this))\n        );\n        _mintLiquidity(limitLower, limitUpper, limitLiquidity, address(this), inMin[2], inMin[3]);\n    }\n\n    /// @notice Compound pending fees\n    /// @param inMin min spend \n    /// @return baseToken0Owed Pending fees of base token0\n    /// @return baseToken1Owed Pending fees of base token1\n    /// @return limitToken0Owed Pending fees of limit token0\n    /// @return limitToken1Owed Pending fees of limit token1\n    function compound(uint256[4] memory inMin) external onlyOwner returns (\n        uint128 baseToken0Owed,\n        uint128 baseToken1Owed,\n        uint128 limitToken0Owed,\n        uint128 limitToken1Owed \n    ) {\n        // update fees for compounding\n        zeroBurn();\n\n        uint128 liquidity = _liquidityForAmounts(\n          baseLower,\n          baseUpper, \n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this))\n        );\n        _mintLiquidity(baseLower, baseUpper, liquidity, address(this), inMin[0], inMin[1]);\n\n        liquidity = _liquidityForAmounts(\n          limitLower,\n          limitUpper, \n          token0.balanceOf(address(this)),\n          token1.balanceOf(address(this))\n        );\n        _mintLiquidity(limitLower, limitUpper, liquidity, address(this), inMin[2], inMin[3]);\n    }\n\n    /// @notice Add Liquidity\n    function addLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0,\n        uint256 amount1,\n        uint256[2] memory inMin\n    ) public onlyOwner {        \n        _zeroBurn(tickLower, tickUpper);\n        uint128 liquidity = _liquidityForAmounts(tickLower, tickUpper, amount0, amount1);\n        _mintLiquidity(tickLower, tickUpper, liquidity, address(this), inMin[0], inMin[1]);\n    }\n\n    /// @notice Adds the liquidity for the given position\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param liquidity The amount of liquidity to mint\n    /// @param payer Payer Data\n    /// @param amount0Min Minimum amount of token0 that should be paid\n    /// @param amount1Min Minimum amount of token1 that should be paid\n    function _mintLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 liquidity,\n        address payer,\n        uint256 amount0Min,\n        uint256 amount1Min\n    ) internal {\n        if (liquidity > 0) {\n            mintCalled = true;\n            (uint256 amount0, uint256 amount1) = pool.mint(\n                address(this),\n                tickLower,\n                tickUpper,\n                liquidity,\n                abi.encode(payer)\n            );\n            require(amount0 >= amount0Min && amount1 >= amount1Min, 'PSC');\n        }\n    }\n\n    /// @notice Burn liquidity from the sender and collect tokens owed for the liquidity\n    /// @param tickLower The lower tick of the position for which to burn liquidity\n    /// @param tickUpper The upper tick of the position for which to burn liquidity\n    /// @param liquidity The amount of liquidity to burn\n    /// @param to The address which should receive the fees collected\n    /// @param collectAll If true, collect all tokens owed in the pool, else collect the owed tokens of the burn\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function _burnLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 liquidity,\n        address to,\n        bool collectAll,\n        uint256 amount0Min,\n        uint256 amount1Min\n    ) internal returns (uint256 amount0, uint256 amount1) {\n        if (liquidity > 0) {\n            /// Burn liquidity\n            (uint256 owed0, uint256 owed1) = pool.burn(tickLower, tickUpper, liquidity);\n            require(owed0 >= amount0Min && owed1 >= amount1Min, \"PSC\");\n\n            // Collect amount owed\n            uint128 collect0 = collectAll ? type(uint128).max : _uint128Safe(owed0);\n            uint128 collect1 = collectAll ? type(uint128).max : _uint128Safe(owed1);\n            if (collect0 > 0 || collect1 > 0) {\n                (amount0, amount1) = pool.collect(to, tickLower, tickUpper, collect0, collect1);\n            }\n        }\n    }\n\n    /// @notice Get the liquidity amount for given liquidity tokens\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param shares Shares of position\n    /// @return The amount of liquidity toekn for shares\n    function _liquidityForShares(\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 shares\n    ) internal view returns (uint128) {\n        (uint128 position, , ) = _position(tickLower, tickUpper);\n        return _uint128Safe(uint256(position).mul(shares).div(totalSupply()));\n    }\n\n    /// @notice Get the info of the given position\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @return liquidity The amount of liquidity of the position\n    /// @return tokensOwed0 Amount of token0 owed\n    /// @return tokensOwed1 Amount of token1 owed\n    function _position(int24 tickLower, int24 tickUpper)\n        internal\n        view\n        returns (\n            uint128 liquidity,\n            uint128 tokensOwed0,\n            uint128 tokensOwed1\n        )\n    {\n        bytes32 positionKey = keccak256(abi.encodePacked(address(this), tickLower, tickUpper));\n        (liquidity, , , tokensOwed0, tokensOwed1) = pool.positions(positionKey);\n    }\n\n    /// @notice Callback function of uniswapV3Pool mint\n    function uniswapV3MintCallback(\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata data\n    ) external override {\n        require(msg.sender == address(pool));\n        require(mintCalled == true);\n        mintCalled = false;\n\n        if (amount0 > 0) token0.safeTransfer(msg.sender, amount0);\n        if (amount1 > 0) token1.safeTransfer(msg.sender, amount1);\n    }\n\n    /// @return total0 Quantity of token0 in both positions and unused in the Hypervisor\n    /// @return total1 Quantity of token1 in both positions and unused in the Hypervisor\n    function getTotalAmounts() public view returns (uint256 total0, uint256 total1) {\n        (, uint256 base0, uint256 base1) = getBasePosition();\n        (, uint256 limit0, uint256 limit1) = getLimitPosition();\n        total0 = token0.balanceOf(address(this)).add(base0).add(limit0);\n        total1 = token1.balanceOf(address(this)).add(base1).add(limit1);\n    }\n\n    /// @return liquidity Amount of total liquidity in the base position\n    /// @return amount0 Estimated amount of token0 that could be collected by\n    /// burning the base position\n    /// @return amount1 Estimated amount of token1 that could be collected by\n    /// burning the base position\n    function getBasePosition()\n        public\n        view\n        returns (\n            uint128 liquidity,\n            uint256 amount0,\n            uint256 amount1\n        )\n    {\n        (uint128 positionLiquidity, uint128 tokensOwed0, uint128 tokensOwed1) = _position(\n            baseLower,\n            baseUpper\n        );\n        (amount0, amount1) = _amountsForLiquidity(baseLower, baseUpper, positionLiquidity);\n        amount0 = amount0.add(uint256(tokensOwed0));\n        amount1 = amount1.add(uint256(tokensOwed1));\n        liquidity = positionLiquidity;\n    }\n\n    /// @return liquidity Amount of total liquidity in the limit position\n    /// @return amount0 Estimated amount of token0 that could be collected by\n    /// burning the limit position\n    /// @return amount1 Estimated amount of token1 that could be collected by\n    /// burning the limit position\n    function getLimitPosition()\n        public\n        view\n        returns (\n            uint128 liquidity,\n            uint256 amount0,\n            uint256 amount1\n        )\n    {\n        (uint128 positionLiquidity, uint128 tokensOwed0, uint128 tokensOwed1) = _position(\n            limitLower,\n            limitUpper\n        );\n        (amount0, amount1) = _amountsForLiquidity(limitLower, limitUpper, positionLiquidity);\n        amount0 = amount0.add(uint256(tokensOwed0));\n        amount1 = amount1.add(uint256(tokensOwed1));\n        liquidity = positionLiquidity;\n    }\n\n    /// @notice Get the amounts of the given numbers of liquidity tokens\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param liquidity The amount of liquidity tokens\n    /// @return Amount of token0 and token1\n    function _amountsForLiquidity(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 liquidity\n    ) internal view returns (uint256, uint256) {\n        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();\n        return\n            LiquidityAmounts.getAmountsForLiquidity(\n                sqrtRatioX96,\n                TickMath.getSqrtRatioAtTick(tickLower),\n                TickMath.getSqrtRatioAtTick(tickUpper),\n                liquidity\n            );\n    }\n\n    /// @notice Get the liquidity amount of the given numbers of token0 and token1\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount0 The amount of token0\n    /// @param amount0 The amount of token1\n    /// @return Amount of liquidity tokens\n    function _liquidityForAmounts(\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0,\n        uint256 amount1\n    ) internal view returns (uint128) {\n        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();\n        return\n            LiquidityAmounts.getLiquidityForAmounts(\n                sqrtRatioX96,\n                TickMath.getSqrtRatioAtTick(tickLower),\n                TickMath.getSqrtRatioAtTick(tickUpper),\n                amount0,\n                amount1\n            );\n    }\n\n    /// @return tick Uniswap pool's current price tick\n    function currentTick() public view returns (int24 tick) {\n        (, tick, , , , , ) = pool.slot0();\n    }\n\n    function _uint128Safe(uint256 x) internal pure returns (uint128) {\n        assert(x <= type(uint128).max);\n        return uint128(x);\n    }\n\n    /// @param _address Array of addresses to be appended\n    function setWhitelist(address _address) external onlyOwner {\n        whitelistedAddress = _address;\n    }\n\n    /// @notice Remove Whitelisted\n    function removeWhitelisted() external onlyOwner {\n        whitelistedAddress = address(0);\n    }\n\n    /// @notice set fee \n    function setFee(uint8 newFee) external onlyOwner {\n        fee = newFee;\n        emit SetFee(fee);\n    }\n\n    /// @notice Toggle Direct Deposit\n    function toggleDirectDeposit() external onlyOwner {\n        directDeposit = !directDeposit;\n    }\n\n    function transferOwnership(address newOwner) external onlyOwner {\n        require(newOwner != address(0));\n        owner = newOwner;\n    }\n\n    modifier onlyOwner {\n        require(msg.sender == owner, \"only owner\");\n        _;\n    }\n}\n"
      },
      "contracts/HypervisorFactory.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity =0.7.6;\n\nimport {IUniswapV3Factory} from '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';\n\nimport {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';\n\nimport {Hypervisor} from './Hypervisor.sol';\n\n/// @title HypervisorFactory\n\ncontract HypervisorFactory is Ownable {\n    IUniswapV3Factory public uniswapV3Factory;\n    mapping(address => mapping(address => mapping(uint24 => address))) public getHypervisor; // toke0, token1, fee -> hypervisor address\n    address[] public allHypervisors;\n\n    event HypervisorCreated(address token0, address token1, uint24 fee, address hypervisor, uint256);\n\n    constructor(address _uniswapV3Factory) {\n        require(_uniswapV3Factory != address(0), \"uniswapV3Factory should be non-zero\");\n        uniswapV3Factory = IUniswapV3Factory(_uniswapV3Factory);\n    }\n\n    /// @notice Get the number of hypervisors created\n    /// @return Number of hypervisors created\n    function allHypervisorsLength() external view returns (uint256) {\n        return allHypervisors.length;\n    }\n\n    /// @notice Create a Hypervisor\n    /// @param tokenA Address of token0\n    /// @param tokenB Address of toekn1\n    /// @param fee The desired fee for the hypervisor\n    /// @param name Name of the hyervisor\n    /// @param symbol Symbole of the hypervisor\n    /// @return hypervisor Address of hypervisor created\n    function createHypervisor(\n        address tokenA,\n        address tokenB,\n        uint24 fee,\n        string memory name,\n        string memory symbol\n    ) external onlyOwner returns (address hypervisor) {\n        require(tokenA != tokenB, 'SF: IDENTICAL_ADDRESSES'); // TODO: using PoolAddress library (uniswap-v3-periphery)\n        (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n        require(token0 != address(0), 'SF: ZERO_ADDRESS');\n        require(getHypervisor[token0][token1][fee] == address(0), 'SF: HYPERVISOR_EXISTS');\n        int24 tickSpacing = uniswapV3Factory.feeAmountTickSpacing(fee);\n        require(tickSpacing != 0, 'SF: INCORRECT_FEE');\n        address pool = uniswapV3Factory.getPool(token0, token1, fee);\n        if (pool == address(0)) {\n            pool = uniswapV3Factory.createPool(token0, token1, fee);\n        }\n        hypervisor = address(\n            new Hypervisor{salt: keccak256(abi.encodePacked(token0, token1, fee, tickSpacing))}(pool, owner(), name, symbol)\n        );\n\n        getHypervisor[token0][token1][fee] = hypervisor;\n        getHypervisor[token1][token0][fee] = hypervisor; // populate mapping in the reverse direction\n        allHypervisors.push(hypervisor);\n        emit HypervisorCreated(token0, token1, fee, hypervisor, allHypervisors.length);\n    }\n}\n"
      },
      "contracts/interfaces/IHypervisor.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-only\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\n\ninterface IHypervisor {\n\n  function deposit(\n      uint256,\n      uint256,\n      address,\n      address,\n      uint256[4] memory minIn\n  ) external returns (uint256);\n\n  function withdraw(\n    uint256,\n    address,\n    address,\n    uint256[4] memory\n  ) external returns (uint256, uint256);\n\n  function compound() external returns (\n\n    uint128 baseToken0Owed,\n    uint128 baseToken1Owed,\n    uint128 limitToken0Owed,\n    uint128 limitToken1Owed\n  );\n\n  function compound(uint256[4] memory inMin) external returns (\n\n    uint128 baseToken0Owed,\n    uint128 baseToken1Owed,\n    uint128 limitToken0Owed,\n    uint128 limitToken1Owed\n  );\n\n\n  function rebalance(\n    int24 _baseLower,\n    int24 _baseUpper,\n    int24 _limitLower,\n    int24 _limitUpper,\n    address _feeRecipient,\n    uint256[4] memory minIn, \n    uint256[4] memory outMin\n    ) external;\n\n  function addBaseLiquidity(\n    uint256 amount0, \n    uint256 amount1,\n    uint256[2] memory minIn\n  ) external;\n\n  function addLimitLiquidity(\n    uint256 amount0, \n    uint256 amount1,\n    uint256[2] memory minIn\n  ) external;   \n\n  function pullLiquidity(\n    int24 tickLower,\n    int24 tickUpper,\n    uint128 shares,\n    uint256[2] memory amountMin\n  ) external returns (\n    uint256 base0,\n    uint256 base1\n  );\n\n  function pullLiquidity(\n    uint256 shares,\n    uint256[4] memory minAmounts \n  ) external returns(\n      uint256 base0,\n      uint256 base1,\n      uint256 limit0,\n      uint256 limit1\n  );\n\n  function addLiquidity(\n      int24 tickLower,\n      int24 tickUpper,\n      uint256 amount0,\n      uint256 amount1,\n      uint256[2] memory inMin\n  ) external;\n\n\n  function pool() external view returns (IUniswapV3Pool);\n\n  function currentTick() external view returns (int24 tick);\n  \n  function tickSpacing() external view returns (int24 spacing);\n\n  function baseLower() external view returns (int24 tick);\n\n  function baseUpper() external view returns (int24 tick);\n\n  function limitLower() external view returns (int24 tick);\n\n  function limitUpper() external view returns (int24 tick);\n\n  function token0() external view returns (IERC20);\n\n  function token1() external view returns (IERC20);\n\n  function deposit0Max() external view returns (uint256);\n\n  function deposit1Max() external view returns (uint256);\n\n  function balanceOf(address) external view returns (uint256);\n\n  function approve(address, uint256) external returns (bool);\n\n  function transferFrom(address, address, uint256) external returns (bool);\n\n  function transfer(address, uint256) external returns (bool);\n\n  function getTotalAmounts() external view returns (uint256 total0, uint256 total1);\n  \n  function getBasePosition() external view returns (uint256 liquidity, uint256 total0, uint256 total1);\n\n  function totalSupply() external view returns (uint256 );\n\n  function setWhitelist(address _address) external;\n  \n  function setFee(uint8 newFee) external;\n  \n  function removeWhitelisted() external;\n\n  function transferOwnership(address newOwner) external;\n\n  function toggleDirectDeposit() external;\n\n}\n"
      },
      "contracts/mocks/MockUniswapV3Pool.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity =0.7.6;\n\nimport {IUniswapV3Pool} from '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';\nimport {IUniswapV3Factory} from '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';\nimport {IUniswapV3MintCallback} from '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol';\nimport {IUniswapV3SwapCallback} from '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';\nimport {IERC20Minimal} from '@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol';\nimport {IUniswapV3PoolDeployer} from '@uniswap/v3-core/contracts/interfaces/IUniswapV3PoolDeployer.sol';\n\nimport {TickMath} from '@uniswap/v3-core/contracts/libraries/TickMath.sol';\nimport {LowGasSafeMath} from '@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol';\nimport {TransferHelper} from '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';\nimport {LiquidityAmounts} from '@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol';\n\ncontract MockUniswapV3Pool is IUniswapV3MintCallback, IUniswapV3SwapCallback, IERC20Minimal {\n    using LowGasSafeMath for uint256;\n\n    address public immutable token0;\n    address public immutable token1;\n\n    uint24 public fee;\n    int24 public tickSpacing;\n\n    IUniswapV3Pool public currentPool;\n    IUniswapV3Factory public immutable uniswapFactory;\n\n    int24 private constant MIN_TICK = -887220;\n    int24 private constant MAX_TICK = 887220;\n\n    mapping(address => uint256) private _balances;\n    mapping(address => mapping(address => uint256)) public override allowance;\n\n    constructor() {\n        (address _uniswapFactory, address _token0, address _token1, uint24 _fee, int24 _tickSpacing) =\n            IUniswapV3PoolDeployer(msg.sender).parameters();\n        token0 = _token0;\n        token1 = _token1;\n        uniswapFactory = IUniswapV3Factory(_uniswapFactory);\n\n        fee = _fee;\n        tickSpacing = _tickSpacing;\n\n        address uniswapPool = IUniswapV3Factory(_uniswapFactory).getPool(_token0, _token1, _fee);\n        require(uniswapPool != address(0));\n        currentPool = IUniswapV3Pool(uniswapPool);\n    }\n\n    function balanceOf(address account) external view override returns (uint256) {\n        return _balances[account];\n    }\n\n    function deposit(\n        int24 lowerTick,\n        int24 upperTick,\n        uint256 amount0,\n        uint256 amount1\n    ) external returns (uint256 rest0, uint256 rest1) {\n        (uint160 sqrtRatioX96, , , , , , ) = currentPool.slot0();\n\n        // First, deposit as much as we can\n        uint128 baseLiquidity =\n            LiquidityAmounts.getLiquidityForAmounts(\n                sqrtRatioX96,\n                TickMath.getSqrtRatioAtTick(lowerTick),\n                TickMath.getSqrtRatioAtTick(upperTick),\n                amount0,\n                amount1\n            );\n        (uint256 amountDeposited0, uint256 amountDeposited1) =\n            currentPool.mint(msg.sender, lowerTick, upperTick, baseLiquidity, abi.encode(msg.sender));\n        rest0 = amount0 - amountDeposited0;\n        rest1 = amount1 - amountDeposited1;\n    }\n\n    function swap(bool zeroForOne, int256 amountSpecified) external {\n        (uint160 sqrtRatio, , , , , , ) = currentPool.slot0();\n        currentPool.swap(\n            address(this),\n            zeroForOne,\n            amountSpecified,\n            zeroForOne ? sqrtRatio - 1 : sqrtRatio + 1,\n            abi.encode(msg.sender)\n        );\n    }\n\n    function uniswapV3MintCallback(\n        uint256 amount0Owed,\n        uint256 amount1Owed,\n        bytes calldata data\n    ) external override {\n        require(msg.sender == address(currentPool));\n\n        address sender = abi.decode(data, (address));\n\n        if (sender == address(this)) {\n            if (amount0Owed > 0) {\n                TransferHelper.safeTransfer(token0, msg.sender, amount0Owed);\n            }\n            if (amount1Owed > 0) {\n                TransferHelper.safeTransfer(token1, msg.sender, amount1Owed);\n            }\n        } else {\n            if (amount0Owed > 0) {\n                TransferHelper.safeTransferFrom(token0, sender, msg.sender, amount0Owed);\n            }\n            if (amount1Owed > 0) {\n                TransferHelper.safeTransferFrom(token1, sender, msg.sender, amount1Owed);\n            }\n        }\n    }\n\n    function uniswapV3SwapCallback(\n        int256 amount0Delta,\n        int256 amount1Delta,\n        bytes calldata data\n    ) external override {\n        require(msg.sender == address(currentPool));\n\n        address sender = abi.decode(data, (address));\n\n        if (amount0Delta > 0) {\n            TransferHelper.safeTransferFrom(token0, sender, msg.sender, uint256(amount0Delta));\n        } else if (amount1Delta > 0) {\n            TransferHelper.safeTransferFrom(token1, sender, msg.sender, uint256(amount1Delta));\n        }\n    }\n\n    function transfer(address recipient, uint256 amount) external override returns (bool) {\n        uint256 balanceBefore = _balances[msg.sender];\n        require(balanceBefore >= amount, 'insufficient balance');\n        _balances[msg.sender] = balanceBefore - amount;\n\n        uint256 balanceRecipient = _balances[recipient];\n        require(balanceRecipient + amount >= balanceRecipient, 'recipient balance overflow');\n        _balances[recipient] = balanceRecipient + amount;\n\n        emit Transfer(msg.sender, recipient, amount);\n        return true;\n    }\n\n    function approve(address spender, uint256 amount) external override returns (bool) {\n        allowance[msg.sender][spender] = amount;\n        emit Approval(msg.sender, spender, amount);\n        return true;\n    }\n\n    function transferFrom(\n        address sender,\n        address recipient,\n        uint256 amount\n    ) external override returns (bool) {\n        uint256 allowanceBefore = allowance[sender][msg.sender];\n        require(allowanceBefore >= amount, 'allowance insufficient');\n\n        allowance[sender][msg.sender] = allowanceBefore - amount;\n\n        uint256 balanceRecipient = _balances[recipient];\n        require(balanceRecipient + amount >= balanceRecipient, 'overflow balance recipient');\n        _balances[recipient] = balanceRecipient + amount;\n        uint256 balanceSender = _balances[sender];\n        require(balanceSender >= amount, 'underflow balance sender');\n        _balances[sender] = balanceSender - amount;\n\n        emit Transfer(sender, recipient, amount);\n        return true;\n    }\n\n    function _mint(address to, uint256 amount) internal {\n        uint256 balanceNext = _balances[to] + amount;\n        require(balanceNext >= amount, 'overflow balance');\n        _balances[to] = balanceNext;\n    }\n}\n"
      },
      "contracts/mocks/MockUniswapV3PoolDeployer.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity =0.7.6;\n\nimport {IUniswapV3PoolDeployer} from '@uniswap/v3-core/contracts/interfaces/IUniswapV3PoolDeployer.sol';\nimport {MockUniswapV3Pool} from './MockUniswapV3Pool.sol';\n\ncontract MockUniswapV3PoolDeployer is IUniswapV3PoolDeployer {\n    struct Parameters {\n        address factory;\n        address token0;\n        address token1;\n        uint24 fee;\n        int24 tickSpacing;\n    }\n\n    Parameters public override parameters;\n\n    event PoolDeployed(address pool);\n\n    function deploy(\n        address factory,\n        address token0,\n        address token1,\n        uint24 fee,\n        int24 tickSpacing\n    ) external returns (address pool) {\n        parameters = Parameters({factory: factory, token0: token0, token1: token1, fee: fee, tickSpacing: tickSpacing});\n        pool = address(new MockUniswapV3Pool{salt: keccak256(abi.encodePacked(token0, token1, fee, tickSpacing))}());\n        emit PoolDeployed(pool);\n        delete parameters;\n    }\n}\n"
      },
      "contracts/mocks/TestERC20.sol": {
        "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity =0.7.6;\n\nimport {IERC20Minimal} from '@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol';\n\ncontract TestERC20 is IERC20Minimal {\n    mapping(address => uint256) public override balanceOf;\n    mapping(address => mapping(address => uint256)) public override allowance;\n\n    constructor(uint256 amountToMint) {\n        mint(msg.sender, amountToMint);\n    }\n\n    function mint(address to, uint256 amount) public {\n        uint256 balanceNext = balanceOf[to] + amount;\n        require(balanceNext >= amount, 'overflow balance');\n        balanceOf[to] = balanceNext;\n    }\n\n    function transfer(address recipient, uint256 amount) external override returns (bool) {\n        uint256 balanceBefore = balanceOf[msg.sender];\n        require(balanceBefore >= amount, 'insufficient balance');\n        balanceOf[msg.sender] = balanceBefore - amount;\n\n        uint256 balanceRecipient = balanceOf[recipient];\n        require(balanceRecipient + amount >= balanceRecipient, 'recipient balance overflow');\n        balanceOf[recipient] = balanceRecipient + amount;\n\n        emit Transfer(msg.sender, recipient, amount);\n        return true;\n    }\n\n    function approve(address spender, uint256 amount) external override returns (bool) {\n        allowance[msg.sender][spender] = amount;\n        emit Approval(msg.sender, spender, amount);\n        return true;\n    }\n\n    function transferFrom(\n        address sender,\n        address recipient,\n        uint256 amount\n    ) external override returns (bool) {\n        uint256 allowanceBefore = allowance[sender][msg.sender];\n        require(allowanceBefore >= amount, 'allowance insufficient');\n\n        allowance[sender][msg.sender] = allowanceBefore - amount;\n\n        uint256 balanceRecipient = balanceOf[recipient];\n        require(balanceRecipient + amount >= balanceRecipient, 'overflow balance recipient');\n        balanceOf[recipient] = balanceRecipient + amount;\n        uint256 balanceSender = balanceOf[sender];\n        require(balanceSender >= amount, 'underflow balance sender');\n        balanceOf[sender] = balanceSender - amount;\n\n        emit Transfer(sender, recipient, amount);\n        return true;\n    }\n}\n"
      },
      "contracts/proxy/admin.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\n\nimport \"../interfaces/IHypervisor.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n/// @title Admin\n\ncontract Admin {\n\n    address public admin;\n\t\tbool public ownerFixed = false;\n    mapping(address => address) public rebalancers;\n    mapping(address => address) public advisors;\n\n    modifier onlyAdmin {\n        require(msg.sender == admin, \"only admin\");\n        _;\n    }\n\n    modifier onlyAdvisor(address hypervisor) {\n        require(msg.sender == advisors[hypervisor], \"only advisor\");\n        _;\n    }\n\n    modifier onlyRebalancer(address hypervisor) {\n        require(msg.sender == rebalancers[hypervisor], \"only rebalancer\");\n        _;\n    }\n\n    constructor(address _admin) {\n        admin = _admin;\n    }\n\n    /// @param _hypervisor Hypervisor Address\n    /// @param _baseLower The lower tick of the base position\n    /// @param _baseUpper The upper tick of the base position\n    /// @param _limitLower The lower tick of the limit position\n    /// @param _limitUpper The upper tick of the limit position\n    /// @param _feeRecipient Address of recipient of 10% of earned fees since last rebalance\n    function rebalance(\n        address _hypervisor,\n        int24 _baseLower,\n        int24 _baseUpper,\n        int24 _limitLower,\n        int24 _limitUpper,\n        address _feeRecipient,\n        uint256[4] memory inMin, \n        uint256[4] memory outMin\n    ) external onlyRebalancer(_hypervisor) {\n        IHypervisor(_hypervisor).rebalance(_baseLower, _baseUpper, _limitLower, _limitUpper, _feeRecipient, inMin, outMin);\n    }\n\n    /// @notice Pull liquidity tokens from liquidity and receive the tokens\n    /// @param _hypervisor Hypervisor Address\n    /// @param tickLower lower tick\n    /// @param tickUpper upper tick\n    /// @param shares Number of liquidity tokens to pull from liquidity\n    /// @return base0 amount of token0 received from base position\n    /// @return base1 amount of token1 received from base position\n    function pullLiquidity(\n      address _hypervisor,\n      int24 tickLower,\n      int24 tickUpper,\n      uint128 shares,\n      uint256[2] memory minAmounts\n    ) external onlyRebalancer(_hypervisor) returns(\n        uint256 base0,\n        uint256 base1\n      ) {\n      (base0, base1) = IHypervisor(_hypervisor).pullLiquidity(tickLower, tickUpper, shares, minAmounts);\n    }\n\n    function pullLiquidity(\n      address _hypervisor,\n      uint256 shares,\n      uint256[4] memory minAmounts \n    ) external onlyRebalancer(_hypervisor) returns(\n        uint256 base0,\n        uint256 base1,\n        uint256 limit0,\n        uint256 limit1\n      ) {\n      (base0, base1, limit0, limit1) = IHypervisor(_hypervisor).pullLiquidity(shares, minAmounts);\n    }\n\n    function addLiquidity(\n        address _hypervisor,\n        int24 tickLower,\n        int24 tickUpper,\n        uint256 amount0,\n        uint256 amount1,\n        uint256[2] memory inMin\n    ) external onlyRebalancer(_hypervisor) {\n        IHypervisor(_hypervisor).addLiquidity(tickLower, tickUpper, amount0, amount1, inMin);\n    }\n\n    /// @notice Add tokens to base liquidity\n    /// @param _hypervisor Hypervisor Address\n    /// @param amount0 Amount of token0 to add\n    /// @param amount1 Amount of token1 to add\n    function addBaseLiquidity(address _hypervisor, uint256 amount0, uint256 amount1, uint256[2] memory inMin) external onlyRebalancer(_hypervisor) {\n        IHypervisor(_hypervisor).addBaseLiquidity(amount0, amount1, inMin);\n    }\n\n    /// @notice Add tokens to limit liquidity\n    /// @param _hypervisor Hypervisor Address\n    /// @param amount0 Amount of token0 to add\n    /// @param amount1 Amount of token1 to add\n    function addLimitLiquidity(address _hypervisor, uint256 amount0, uint256 amount1, uint256[2] memory inMin) external onlyRebalancer(_hypervisor) {\n        IHypervisor(_hypervisor).addLimitLiquidity(amount0, amount1, inMin);\n    }\n\n    /// @notice compound pending fees \n    /// @param _hypervisor Hypervisor Address\n    function compound( address _hypervisor) external onlyAdvisor(_hypervisor) returns(\n        uint128 baseToken0Owed,\n        uint128 baseToken1Owed,\n        uint128 limitToken0Owed,\n        uint128 limitToken1Owed,\n        uint256[4] memory inMin\n    ) {\n        IHypervisor(_hypervisor).compound();\n    }\n\n    function compound( address _hypervisor, uint256[4] memory inMin)\n      external onlyAdvisor(_hypervisor) returns(\n        uint128 baseToken0Owed,\n        uint128 baseToken1Owed,\n        uint128 limitToken0Owed,\n        uint128 limitToken1Owed\n    ) {\n        IHypervisor(_hypervisor).compound(inMin);\n    }\n    /// @param _hypervisor Hypervisor Address\n    function setWhitelist(address _hypervisor, address newWhitelist) external onlyAdmin {\n        IHypervisor(_hypervisor).setWhitelist(newWhitelist);\n    }\n\n    /// @param _hypervisor Hypervisor Address\n    function removeWhitelisted(address _hypervisor) external onlyAdmin {\n        IHypervisor(_hypervisor).removeWhitelisted();\n    }\n\n    /// @param newAdmin New Admin Address\n    function transferAdmin(address newAdmin) external onlyAdmin {\n        require(newAdmin != address(0), \"newAdmin should be non-zero\");\n        admin = newAdmin;\n    }\n\n    /// @param _hypervisor Hypervisor Address\n    /// @param newOwner New Owner Address\n    function transferHypervisorOwner(address _hypervisor, address newOwner) external onlyAdmin {\n\t\t\t\trequire(!ownerFixed, \"permanent owner in place\");\n        IHypervisor(_hypervisor).transferOwnership(newOwner);\n    }\n\n\t\t// @dev permanently disable hypervisor ownership transfer \n\t\tfunction fixOwnership() external onlyAdmin {\n\t\t\townerFixed = false;\n\t\t}\n\n    /// @param newAdvisor New Advisor Address\n    function setAdvisor(address _hypervisor, address newAdvisor) external onlyAdmin {\n        require(newAdvisor != address(0), \"newAdvisor should be non-zero\");\n        advisors[_hypervisor] = newAdvisor;\n    }\n\n    /// @param newRebalancer New Rebalancer Address\n    function setRebalancer(address _hypervisor, address newRebalancer) external onlyAdmin {\n        require(newRebalancer != address(0), \"newRebalancer should be non-zero\");\n        rebalancers[_hypervisor] = newRebalancer;\n    }\n\n    /// @notice Transfer tokens to the recipient from the contract\n    /// @param token Address of token\n    /// @param recipient Recipient Address\n    function rescueERC20(IERC20 token, address recipient) external onlyAdmin {\n        require(recipient != address(0), \"recipient should be non-zero\");\n        require(token.transfer(recipient, token.balanceOf(address(this))));\n    }\n\n    /// @param _hypervisor Hypervisor Address\n    /// @param newFee fee amount \n    function setFee(address _hypervisor, uint8 newFee) external onlyAdmin {\n        IHypervisor(_hypervisor).setFee(newFee);\n    }\n    /// @notice Toggle Direct Deposit\n    function toggleDirectDeposit(address _hypervisor) external onlyAdmin {\n        IHypervisor(_hypervisor).toggleDirectDeposit();\n    }\n}\n"
      },
      "contracts/proxy/AutoRebal.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\n\nimport \"../interfaces/IHypervisor.sol\";\nimport \"@openzeppelin/contracts/math/SignedSafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/FullMath.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/TickMath.sol\";\nimport \"@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol\";\n\ncontract AutoRebal {\n    using SafeMath for uint256;\n\n    address public admin;\n    address public advisor;\n    address public feeRecipient;\n    IUniswapV3Pool public pool;\n    IHypervisor public hypervisor;\n    int24 public limitWidth = 1;\n\n    modifier onlyAdvisor {\n        require(msg.sender == advisor, \"only advisor\");\n        _;\n    }\n\n    modifier onlyAdmin {\n        require(msg.sender == admin, \"only admin\");\n        _;\n    }\n\n    constructor(address _admin, address _advisor, address _hypervisor) {\n        require(_admin != address(0), \"_admin should be non-zero\");\n        require(_advisor != address(0), \"_advisor should be non-zero\");\n        require(_hypervisor != address(0), \"_hypervisor should be non-zero\");\n        admin = _admin;\n        advisor = _advisor;\n        hypervisor = IHypervisor(_hypervisor);\n    }\n\n    function liquidityOptions() public view returns(bool, int24 currentTick) {\n\n        (uint256 total0, uint256 total1) = hypervisor.getTotalAmounts();\n\n        uint160 sqrtRatioX96;\n        (sqrtRatioX96, currentTick, , , , , ) = hypervisor.pool().slot0();\n\n        uint128 liquidity = LiquidityAmounts.getLiquidityForAmounts(\n            sqrtRatioX96,\n            TickMath.getSqrtRatioAtTick(hypervisor.baseLower()),\n            TickMath.getSqrtRatioAtTick(hypervisor.baseUpper()),\n            total0,\n            total1 \n        );\n  \n        (uint256 amount0, uint256 amount1) = LiquidityAmounts.getAmountsForLiquidity(\n            sqrtRatioX96,\n            TickMath.getSqrtRatioAtTick(hypervisor.baseLower()),\n            TickMath.getSqrtRatioAtTick(hypervisor.baseUpper()),\n            liquidity\n        );\n\n        uint256 price = FullMath.mulDiv(uint256(sqrtRatioX96), (uint256(sqrtRatioX96)), 2**(96 * 2));\n        return ((total0-amount0) * price > (total1-amount1), currentTick);\n\n    }\n\n    /// @param  outMin min amount0,1 returned for shares of liq \n    function autoRebalance(\n        uint256[4] memory outMin\n    ) external onlyAdvisor returns(int24 limitLower, int24 limitUpper) {\n      \n        (bool token0Limit, int24 currentTick) = liquidityOptions(); \n\n        if(!token0Limit) {\n            // extra token1 in limit position = limit below\n            limitUpper = (currentTick / hypervisor.tickSpacing()) * hypervisor.tickSpacing() - hypervisor.tickSpacing();\n            if(limitUpper == currentTick) limitUpper = limitUpper - hypervisor.tickSpacing();\n\n            limitLower = limitUpper - hypervisor.tickSpacing() * limitWidth; \n        }\n        else {\n            // extra token0 in limit position = limit above\n            limitLower = (currentTick / hypervisor.tickSpacing()) * hypervisor.tickSpacing() + hypervisor.tickSpacing();\n            if(limitLower == currentTick) limitLower = limitLower + hypervisor.tickSpacing();\n\n            limitUpper = limitLower + hypervisor.tickSpacing() * limitWidth; \n        } \n\n        uint256[4] memory inMin;\n        hypervisor.rebalance(\n            hypervisor.baseLower(),\n            hypervisor.baseUpper(),\n            limitLower,\n            limitUpper,\n            feeRecipient,\n            inMin,\n            outMin \n        ); \n    }\n\n    /// @notice compound pending fees \n    function compound() external onlyAdvisor returns(\n        uint128 baseToken0Owed,\n        uint128 baseToken1Owed,\n        uint128 limitToken0Owed,\n        uint128 limitToken1Owed,\n        uint256[4] memory inMin\n    ) {\n        hypervisor.compound();\n    }\n\n    /// @param newAdmin New Admin Address\n    function transferAdmin(address newAdmin) external onlyAdmin {\n        require(newAdmin != address(0), \"newAdmin should be non-zero\");\n        admin = newAdmin;\n    }\n\n    /// @notice Transfer tokens to recipient from the contract\n    /// @param token Address of token\n    /// @param recipient Recipient Address\n    function rescueERC20(IERC20 token, address recipient) external onlyAdmin {\n        require(recipient != address(0), \"recipient should be non-zero\");\n        require(token.transfer(recipient, token.balanceOf(address(this))));\n    }\n\n    /// @param _recipient fee recipient \n    function setRecipient(address _recipient) external onlyAdmin {\n        require(feeRecipient == address(0), \"fee recipient already set\");\n        feeRecipient = _recipient;\n    }\n\n}\n"
      },
      "contracts/Swap.sol": {
        "content": "// SPDX-License-Identifier: Unlicense\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\n\nimport \"@uniswap/v3-core/contracts/libraries/TickMath.sol\";\nimport \"@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol\";\n\ncontract Swap {\n    using SafeERC20 for IERC20;\n    using SafeMath for uint256;\n\n    address public owner;\n    address public recipient;\n    address public USDT = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9;\n\n    ISwapRouter public router;\n\n    event Swap(address token, address recipient, uint256 amountOut);\n\n    constructor(\n        address _owner,\n        address _router\n    ) {\n        owner = _owner;\n        recipient = _owner;\n        router = ISwapRouter(_router);\n        IERC20(USDT).safeApprove(address(router), uint256(-1)); // USDT approval\n    }\n\n    function swap(\n        address token,\n        bytes memory path,\n        bool send\n    ) external onlyOwner {\n        uint256 balance = IERC20(token).balanceOf(address(this));\n        uint256 allowance = IERC20(token).allowance(address(this), address(router));\n        if (token != USDT && allowance < balance) IERC20(token).safeIncreaseAllowance(address(router), balance.sub(allowance));\n        uint256 amountOut = router.exactInput(\n            ISwapRouter.ExactInputParams(\n                path,\n                send ? recipient : address(this),\n                block.timestamp + 10000,\n                balance,\n                0\n            )\n        );\n        emit Swap(token, send ? recipient : address(this), amountOut);\n    }\n\n    function changeRecipient(address _recipient) external onlyOwner {\n        recipient = _recipient;\n    }\n\n    function sendToken(address token, uint256 amount) external onlyOwner {\n        IERC20(token).safeTransfer(recipient, amount);\n    }\n\n    function transferOwnership(address newOwner) external onlyOwner {\n        owner = newOwner;\n    }\n\n    modifier onlyOwner {\n        require(msg.sender == owner, \"only owner\");\n        _;\n    }\n}\n"
      },
      "contracts/test/MintableToken.sol": {
        "content": "pragma solidity ^0.7.6;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\ncontract MintableToken is Ownable, ERC20 {\n    constructor() public ERC20(\"ACCT\", \"ACCT\") { }\n\n    function mint(address account, uint256 amount) public onlyOwner {\n        _mint(account, amount);\n    }\n\n    function burn(address account, uint256 amount) public onlyOwner {\n        _burn(account, amount);\n    }\n}\n"
      },
      "contracts/test/MockToken.sol": {
        "content": "// SPDX-License-Identifier: Unlicense\n\npragma solidity 0.7.6;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\ncontract MockToken is ERC20 {\n    constructor(\n        string memory name,\n        string memory symbol,\n        uint8 decimals\n    ) ERC20(name, symbol) {\n        _setupDecimals(decimals);\n    }\n\n    function mint(address account, uint256 amount) external {\n        _mint(account, amount);\n    }\n}\n"
      },
      "contracts/test/TestRouter.sol": {
        "content": "// SPDX-License-Identifier: Unlicense\n\npragma solidity 0.7.6;\n\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\n\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol\";\nimport \"@uniswap/v3-core/contracts/libraries/TickMath.sol\";\n\n/**\n * @title  TestRouter\n * @dev    DO NOT USE IN PRODUCTION. This is only intended to be used for\n *         tests and lacks slippage and callback caller checks.\n */\ncontract TestRouter is IUniswapV3MintCallback, IUniswapV3SwapCallback {\n    using SafeERC20 for IERC20;\n\n    function mint(\n        IUniswapV3Pool pool,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount\n    ) external returns (uint256, uint256) {\n        int24 tickSpacing = pool.tickSpacing();\n        require(tickLower % tickSpacing == 0, \"tickLower must be a multiple of tickSpacing\");\n        require(tickUpper % tickSpacing == 0, \"tickUpper must be a multiple of tickSpacing\");\n        return pool.mint(msg.sender, tickLower, tickUpper, amount, abi.encode(msg.sender));\n    }\n\n    function swap(\n        IUniswapV3Pool pool,\n        bool zeroForOne,\n        int256 amountSpecified\n    ) external returns (int256, int256) {\n        return\n            pool.swap(\n                msg.sender,\n                zeroForOne,\n                amountSpecified,\n                zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1,\n                abi.encode(msg.sender)\n            );\n    }\n\n    function uniswapV3MintCallback(\n        uint256 amount0Owed,\n        uint256 amount1Owed,\n        bytes calldata data\n    ) external override {\n        _callback(amount0Owed, amount1Owed, data);\n    }\n\n    function uniswapV3SwapCallback(\n        int256 amount0Delta,\n        int256 amount1Delta,\n        bytes calldata data\n    ) external override {\n        uint256 amount0 = amount0Delta > 0 ? uint256(amount0Delta) : 0;\n        uint256 amount1 = amount1Delta > 0 ? uint256(amount1Delta) : 0;\n        _callback(amount0, amount1, data);\n    }\n\n    function _callback(\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata data\n    ) internal {\n        IUniswapV3Pool pool = IUniswapV3Pool(msg.sender);\n        address payer = abi.decode(data, (address));\n\n        IERC20(pool.token0()).safeTransferFrom(payer, msg.sender, amount0);\n        IERC20(pool.token1()).safeTransferFrom(payer, msg.sender, amount1);\n    }\n}\n"
      },
      "contracts/UniProxy.sol": {
        "content": "/// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.7.6;\npragma abicoder v2;\n\nimport \"./interfaces/IHypervisor.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\n\ninterface IClearing {\n\n\tfunction clearDeposit(\n    uint256 deposit0,\n    uint256 deposit1,\n    address from,\n    address to,\n    address pos,\n    uint256[4] memory minIn\n  ) external view returns (bool cleared);\n\n\tfunction clearShares(\n    address pos,\n    uint256 shares\n  ) external view returns (bool cleared);\n\n  function getDepositAmount(\n    address pos,\n    address token,\n    uint256 _deposit\n  ) external view returns (uint256 amountStart, uint256 amountEnd);\n}\n\n/// @title UniProxy v1.2.3\n/// @notice Proxy contract for hypervisor positions management\ncontract UniProxy is ReentrancyGuard {\n\n\tIClearing public clearance;\n  address public owner;\n\n  constructor(address _clearance) {\n    owner = msg.sender;\n\t\tclearance = IClearing(_clearance);\t\n  }\n\n  /// @notice Deposit into the given position\n  /// @param deposit0 Amount of token0 to deposit\n  /// @param deposit1 Amount of token1 to deposit\n  /// @param to Address to receive liquidity tokens\n  /// @param pos Hypervisor Address\n  /// @param minIn min assets to expect in position during a direct deposit \n  /// @return shares Amount of liquidity tokens received\n  function deposit(\n    uint256 deposit0,\n    uint256 deposit1,\n    address to,\n    address pos,\n    uint256[4] memory minIn\n  ) nonReentrant external returns (uint256 shares) {\n    require(to != address(0), \"to should be non-zero\");\n\t\trequire(clearance.clearDeposit(deposit0, deposit1, msg.sender, to, pos, minIn), \"deposit not cleared\");\n\n\t\t/// transfer assets from msg.sender and mint lp tokens to provided address \n\t\tshares = IHypervisor(pos).deposit(deposit0, deposit1, to, msg.sender, minIn);\n\t\trequire(clearance.clearShares(pos, shares), \"shares not cleared\");\n  }\n\n  /// @notice Get the amount of token to deposit for the given amount of pair token\n  /// @param pos Hypervisor Address\n  /// @param token Address of token to deposit\n  /// @param _deposit Amount of token to deposit\n  /// @return amountStart Minimum amounts of the pair token to deposit\n  /// @return amountEnd Maximum amounts of the pair token to deposit\n  function getDepositAmount(\n    address pos,\n    address token,\n    uint256 _deposit\n  ) public view returns (uint256 amountStart, uint256 amountEnd) {\n\t\treturn clearance.getDepositAmount(pos, token, _deposit);\n\t}\n\n\tfunction transferClearance(address newClearance) external onlyOwner {\n    require(newClearance != address(0), \"newClearance should be non-zero\");\n\t\tclearance = IClearing(newClearance);\n\t}\n\n  function transferOwnership(address newOwner) external onlyOwner {\n    require(newOwner != address(0), \"newOwner should be non-zero\");\n    owner = newOwner;\n  }\n\n  modifier onlyOwner {\n    require(msg.sender == owner, \"only owner\");\n    _;\n  }\n}"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 800
      },
      "metadata": {
        "bytecodeHash": "none"
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "abi"
          ]
        }
      }
    }
  }}