File size: 62,768 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  "language": "Solidity",
  "settings": {
    "evmVersion": "london",
    "libraries": {},
    "metadata": {
      "bytecodeHash": "ipfs",
      "useLiteralContent": true
    },
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "remappings": [],
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  },
  "sources": {
    "@openzeppelin/contracts/utils/Strings.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n    bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        // Inspired by OraclizeAPI's implementation - MIT licence\n        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n        if (value == 0) {\n            return \"0\";\n        }\n        uint256 temp = value;\n        uint256 digits;\n        while (temp != 0) {\n            digits++;\n            temp /= 10;\n        }\n        bytes memory buffer = new bytes(digits);\n        while (value != 0) {\n            digits -= 1;\n            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n            value /= 10;\n        }\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        if (value == 0) {\n            return \"0x00\";\n        }\n        uint256 temp = value;\n        uint256 length = 0;\n        while (temp != 0) {\n            length++;\n            temp >>= 8;\n        }\n        return toHexString(value, length);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _HEX_SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/cryptography/ECDSA.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Strings.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n    enum RecoverError {\n        NoError,\n        InvalidSignature,\n        InvalidSignatureLength,\n        InvalidSignatureS,\n        InvalidSignatureV\n    }\n\n    function _throwError(RecoverError error) private pure {\n        if (error == RecoverError.NoError) {\n            return; // no error: do nothing\n        } else if (error == RecoverError.InvalidSignature) {\n            revert(\"ECDSA: invalid signature\");\n        } else if (error == RecoverError.InvalidSignatureLength) {\n            revert(\"ECDSA: invalid signature length\");\n        } else if (error == RecoverError.InvalidSignatureS) {\n            revert(\"ECDSA: invalid signature 's' value\");\n        } else if (error == RecoverError.InvalidSignatureV) {\n            revert(\"ECDSA: invalid signature 'v' value\");\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature` or error string. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     *\n     * Documentation for signature generation:\n     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n        // Check the signature length\n        // - case 65: r,s,v signature (standard)\n        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._\n        if (signature.length == 65) {\n            bytes32 r;\n            bytes32 s;\n            uint8 v;\n            // ecrecover takes the signature parameters, and the only way to get them\n            // currently is to use assembly.\n            assembly {\n                r := mload(add(signature, 0x20))\n                s := mload(add(signature, 0x40))\n                v := byte(0, mload(add(signature, 0x60)))\n            }\n            return tryRecover(hash, v, r, s);\n        } else if (signature.length == 64) {\n            bytes32 r;\n            bytes32 vs;\n            // ecrecover takes the signature parameters, and the only way to get them\n            // currently is to use assembly.\n            assembly {\n                r := mload(add(signature, 0x20))\n                vs := mload(add(signature, 0x40))\n            }\n            return tryRecover(hash, r, vs);\n        } else {\n            return (address(0), RecoverError.InvalidSignatureLength);\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature`. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     */\n    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, signature);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n     *\n     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address, RecoverError) {\n        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n        uint8 v = uint8((uint256(vs) >> 255) + 27);\n        return tryRecover(hash, v, r, s);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n     *\n     * _Available since v4.2._\n     */\n    function recover(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address, RecoverError) {\n        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n        // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n        //\n        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n        // these malleable signatures as well.\n        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n            return (address(0), RecoverError.InvalidSignatureS);\n        }\n        if (v != 27 && v != 28) {\n            return (address(0), RecoverError.InvalidSignatureV);\n        }\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        if (signer == address(0)) {\n            return (address(0), RecoverError.InvalidSignature);\n        }\n\n        return (signer, RecoverError.NoError);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     */\n    function recover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n        // 32 is the length in bytes of hash,\n        // enforced by the type signature above\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from `s`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Typed Data, created from a\n     * `domainSeparator` and a `structHash`. This produces hash corresponding\n     * to the one signed with the\n     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n     * JSON-RPC method as part of EIP-712.\n     *\n     * See {recover}.\n     */\n    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/math/Math.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a >= b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds up instead\n     * of rounding down.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a / b + (a % b == 0 ? 0 : 1);\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/structs/EnumerableMap.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/EnumerableMap.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./EnumerableSet.sol\";\n\n/**\n * @dev Library for managing an enumerable variant of Solidity's\n * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]\n * type.\n *\n * Maps have the following properties:\n *\n * - Entries are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Entries are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n *     // Add the library methods\n *     using EnumerableMap for EnumerableMap.UintToAddressMap;\n *\n *     // Declare a set state variable\n *     EnumerableMap.UintToAddressMap private myMap;\n * }\n * ```\n *\n * The following map types are supported:\n *\n * - `uint256 -> address` (`UintToAddressMap`) since v3.0.0\n * - `address -> uint256` (`AddressToUintMap`) since v4.6.0\n * - `bytes32 -> bytes32` (`Bytes32ToBytes32`) since v4.6.0\n */\nlibrary EnumerableMap {\n    using EnumerableSet for EnumerableSet.Bytes32Set;\n\n    // To implement this library for multiple types with as little code\n    // repetition as possible, we write it in terms of a generic Map type with\n    // bytes32 keys and values.\n    // The Map implementation uses private functions, and user-facing\n    // implementations (such as Uint256ToAddressMap) are just wrappers around\n    // the underlying Map.\n    // This means that we can only create new EnumerableMaps for types that fit\n    // in bytes32.\n\n    struct Bytes32ToBytes32Map {\n        // Storage of keys\n        EnumerableSet.Bytes32Set _keys;\n        mapping(bytes32 => bytes32) _values;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        Bytes32ToBytes32Map storage map,\n        bytes32 key,\n        bytes32 value\n    ) internal returns (bool) {\n        map._values[key] = value;\n        return map._keys.add(key);\n    }\n\n    /**\n     * @dev Removes a key-value pair from a map. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {\n        delete map._values[key];\n        return map._keys.remove(key);\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {\n        return map._keys.contains(key);\n    }\n\n    /**\n     * @dev Returns the number of key-value pairs in the map. O(1).\n     */\n    function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {\n        return map._keys.length();\n    }\n\n    /**\n     * @dev Returns the key-value pair stored at position `index` in the map. O(1).\n     *\n     * Note that there are no guarantees on the ordering of entries inside the\n     * array, and it may change when more entries are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32, bytes32) {\n        bytes32 key = map._keys.at(index);\n        return (key, map._values[key]);\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`.  O(1).\n     * Does not revert if `key` is not in the map.\n     */\n    function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {\n        bytes32 value = map._values[key];\n        if (value == bytes32(0)) {\n            return (contains(map, key), bytes32(0));\n        } else {\n            return (true, value);\n        }\n    }\n\n    /**\n     * @dev Returns the value associated with `key`.  O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {\n        bytes32 value = map._values[key];\n        require(value != 0 || contains(map, key), \"EnumerableMap: nonexistent key\");\n        return value;\n    }\n\n    /**\n     * @dev Same as {_get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {_tryGet}.\n     */\n    function get(\n        Bytes32ToBytes32Map storage map,\n        bytes32 key,\n        string memory errorMessage\n    ) internal view returns (bytes32) {\n        bytes32 value = map._values[key];\n        require(value != 0 || contains(map, key), errorMessage);\n        return value;\n    }\n\n    // UintToAddressMap\n\n    struct UintToAddressMap {\n        Bytes32ToBytes32Map _inner;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        UintToAddressMap storage map,\n        uint256 key,\n        address value\n    ) internal returns (bool) {\n        return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {\n        return remove(map._inner, bytes32(key));\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {\n        return contains(map._inner, bytes32(key));\n    }\n\n    /**\n     * @dev Returns the number of elements in the map. O(1).\n     */\n    function length(UintToAddressMap storage map) internal view returns (uint256) {\n        return length(map._inner);\n    }\n\n    /**\n     * @dev Returns the element stored at position `index` in the set. O(1).\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {\n        (bytes32 key, bytes32 value) = at(map._inner, index);\n        return (uint256(key), address(uint160(uint256(value))));\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`.  O(1).\n     * Does not revert if `key` is not in the map.\n     *\n     * _Available since v3.4._\n     */\n    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {\n        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));\n        return (success, address(uint160(uint256(value))));\n    }\n\n    /**\n     * @dev Returns the value associated with `key`.  O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {\n        return address(uint160(uint256(get(map._inner, bytes32(key)))));\n    }\n\n    /**\n     * @dev Same as {get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryGet}.\n     */\n    function get(\n        UintToAddressMap storage map,\n        uint256 key,\n        string memory errorMessage\n    ) internal view returns (address) {\n        return address(uint160(uint256(get(map._inner, bytes32(key), errorMessage))));\n    }\n\n    // AddressToUintMap\n\n    struct AddressToUintMap {\n        Bytes32ToBytes32Map _inner;\n    }\n\n    /**\n     * @dev Adds a key-value pair to a map, or updates the value for an existing\n     * key. O(1).\n     *\n     * Returns true if the key was added to the map, that is if it was not\n     * already present.\n     */\n    function set(\n        AddressToUintMap storage map,\n        address key,\n        uint256 value\n    ) internal returns (bool) {\n        return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the key was removed from the map, that is if it was present.\n     */\n    function remove(AddressToUintMap storage map, address key) internal returns (bool) {\n        return remove(map._inner, bytes32(uint256(uint160(key))));\n    }\n\n    /**\n     * @dev Returns true if the key is in the map. O(1).\n     */\n    function contains(AddressToUintMap storage map, address key) internal view returns (bool) {\n        return contains(map._inner, bytes32(uint256(uint160(key))));\n    }\n\n    /**\n     * @dev Returns the number of elements in the map. O(1).\n     */\n    function length(AddressToUintMap storage map) internal view returns (uint256) {\n        return length(map._inner);\n    }\n\n    /**\n     * @dev Returns the element stored at position `index` in the set. O(1).\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(AddressToUintMap storage map, uint256 index) internal view returns (address, uint256) {\n        (bytes32 key, bytes32 value) = at(map._inner, index);\n        return (address(uint160(uint256(key))), uint256(value));\n    }\n\n    /**\n     * @dev Tries to returns the value associated with `key`.  O(1).\n     * Does not revert if `key` is not in the map.\n     *\n     * _Available since v3.4._\n     */\n    function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {\n        (bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));\n        return (success, uint256(value));\n    }\n\n    /**\n     * @dev Returns the value associated with `key`.  O(1).\n     *\n     * Requirements:\n     *\n     * - `key` must be in the map.\n     */\n    function get(AddressToUintMap storage map, address key) internal view returns (uint256) {\n        return uint256(get(map._inner, bytes32(uint256(uint160(key)))));\n    }\n\n    /**\n     * @dev Same as {get}, with a custom error message when `key` is not in the map.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryGet}.\n     */\n    function get(\n        AddressToUintMap storage map,\n        address key,\n        string memory errorMessage\n    ) internal view returns (uint256) {\n        return uint256(get(map._inner, bytes32(uint256(uint160(key))), errorMessage));\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/structs/EnumerableSet.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/EnumerableSet.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n *     // Add the library methods\n *     using EnumerableSet for EnumerableSet.AddressSet;\n *\n *     // Declare a set state variable\n *     EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n */\nlibrary EnumerableSet {\n    // To implement this library for multiple types with as little code\n    // repetition as possible, we write it in terms of a generic Set type with\n    // bytes32 values.\n    // The Set implementation uses private functions, and user-facing\n    // implementations (such as AddressSet) are just wrappers around the\n    // underlying Set.\n    // This means that we can only create new EnumerableSets for types that fit\n    // in bytes32.\n\n    struct Set {\n        // Storage of set values\n        bytes32[] _values;\n        // Position of the value in the `values` array, plus 1 because index 0\n        // means a value is not in the set.\n        mapping(bytes32 => uint256) _indexes;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function _add(Set storage set, bytes32 value) private returns (bool) {\n        if (!_contains(set, value)) {\n            set._values.push(value);\n            // The value is stored at length-1, but we add 1 to all indexes\n            // and use 0 as a sentinel value\n            set._indexes[value] = set._values.length;\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function _remove(Set storage set, bytes32 value) private returns (bool) {\n        // We read and store the value's index to prevent multiple reads from the same storage slot\n        uint256 valueIndex = set._indexes[value];\n\n        if (valueIndex != 0) {\n            // Equivalent to contains(set, value)\n            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n            // the array, and then remove the last element (sometimes called as 'swap and pop').\n            // This modifies the order of the array, as noted in {at}.\n\n            uint256 toDeleteIndex = valueIndex - 1;\n            uint256 lastIndex = set._values.length - 1;\n\n            if (lastIndex != toDeleteIndex) {\n                bytes32 lastValue = set._values[lastIndex];\n\n                // Move the last value to the index where the value to delete is\n                set._values[toDeleteIndex] = lastValue;\n                // Update the index for the moved value\n                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n            }\n\n            // Delete the slot where the moved value was stored\n            set._values.pop();\n\n            // Delete the index for the deleted slot\n            delete set._indexes[value];\n\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function _contains(Set storage set, bytes32 value) private view returns (bool) {\n        return set._indexes[value] != 0;\n    }\n\n    /**\n     * @dev Returns the number of values on the set. O(1).\n     */\n    function _length(Set storage set) private view returns (uint256) {\n        return set._values.length;\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function _at(Set storage set, uint256 index) private view returns (bytes32) {\n        return set._values[index];\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function _values(Set storage set) private view returns (bytes32[] memory) {\n        return set._values;\n    }\n\n    // Bytes32Set\n\n    struct Bytes32Set {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _add(set._inner, value);\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n        return _remove(set._inner, value);\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n        return _contains(set._inner, value);\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(Bytes32Set storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n        return _at(set._inner, index);\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n        return _values(set._inner);\n    }\n\n    // AddressSet\n\n    struct AddressSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(AddressSet storage set, address value) internal returns (bool) {\n        return _add(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(AddressSet storage set, address value) internal returns (bool) {\n        return _remove(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(AddressSet storage set, address value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(uint256(uint160(value))));\n    }\n\n    /**\n     * @dev Returns the number of values in the set. O(1).\n     */\n    function length(AddressSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(AddressSet storage set, uint256 index) internal view returns (address) {\n        return address(uint160(uint256(_at(set._inner, index))));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(AddressSet storage set) internal view returns (address[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        address[] memory result;\n\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n\n    // UintSet\n\n    struct UintSet {\n        Set _inner;\n    }\n\n    /**\n     * @dev Add a value to a set. O(1).\n     *\n     * Returns true if the value was added to the set, that is if it was not\n     * already present.\n     */\n    function add(UintSet storage set, uint256 value) internal returns (bool) {\n        return _add(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Removes a value from a set. O(1).\n     *\n     * Returns true if the value was removed from the set, that is if it was\n     * present.\n     */\n    function remove(UintSet storage set, uint256 value) internal returns (bool) {\n        return _remove(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns true if the value is in the set. O(1).\n     */\n    function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n        return _contains(set._inner, bytes32(value));\n    }\n\n    /**\n     * @dev Returns the number of values on the set. O(1).\n     */\n    function length(UintSet storage set) internal view returns (uint256) {\n        return _length(set._inner);\n    }\n\n    /**\n     * @dev Returns the value stored at position `index` in the set. O(1).\n     *\n     * Note that there are no guarantees on the ordering of values inside the\n     * array, and it may change when more values are added or removed.\n     *\n     * Requirements:\n     *\n     * - `index` must be strictly less than {length}.\n     */\n    function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n        return uint256(_at(set._inner, index));\n    }\n\n    /**\n     * @dev Return the entire set in an array\n     *\n     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n     * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n     */\n    function values(UintSet storage set) internal view returns (uint256[] memory) {\n        bytes32[] memory store = _values(set._inner);\n        uint256[] memory result;\n\n        assembly {\n            result := store\n        }\n\n        return result;\n    }\n}\n"
    },
    "contracts/facets/wallet/WalletHashFacet.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {IWalletHash} from \"../../interfaces/IWalletHash.sol\";\nimport {LibWalletHash} from \"../../libraries/LibWalletHash.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IWalletHash` for docs.\ncontract WalletHashFacet is IWalletHash {\n    function isHashApproved(bytes32 hash)\n        external\n        view\n        override\n        returns (bool)\n    {\n        return LibWalletHash._isHashApproved(hash);\n    }\n\n    function hashDeadline(bytes32 hash)\n        external\n        view\n        override\n        returns (uint256)\n    {\n        return LibWalletHash._hashDeadline(hash);\n    }\n\n    function approveHash(bytes32 hash, bytes[] memory signatures)\n        external\n        override\n    {\n        LibWalletHash._approveHash(hash, signatures);\n    }\n\n    function revokeHash(bytes32 hash, bytes[] memory signatures)\n        external\n        override\n    {\n        LibWalletHash._revokeHash(hash, signatures);\n    }\n}\n"
    },
    "contracts/interfaces/IWalletHash.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @title Wallet hash interface\n/// @author Amit Molek\ninterface IWalletHash {\n    /// @dev Emitted on approved hash\n    /// @param hash the approved hash\n    event ApprovedHash(bytes32 hash);\n\n    /// @dev Emitted on revoked hash\n    /// @param hash the revoked hash\n    event RevokedHash(bytes32 hash);\n\n    /// @return true, if the hash is approved\n    function isHashApproved(bytes32 hash) external view returns (bool);\n\n    /// @return `hash`'s deadline\n    function hashDeadline(bytes32 hash) external view returns (uint256);\n\n    /// @notice Approves hash\n    /// @param hash to be approved\n    /// @param signatures a set of member's EIP191 signatures on `hash`\n    /// @dev Emits `ApprovedHash`\n    function approveHash(bytes32 hash, bytes[] memory signatures) external;\n\n    /// @notice Revoke approved hash\n    /// @param hash to be revoked\n    /// @param signatures a set of member's EIP191 signatures on `hash`\n    /// @dev Emits `RevokedHash`\n    function revokeHash(bytes32 hash, bytes[] memory signatures) external;\n}\n"
    },
    "contracts/libraries/LibOwnership.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {StorageOwnershipUnits} from \"../storage/StorageOwnershipUnits.sol\";\nimport {LibState} from \"../libraries/LibState.sol\";\nimport {StateEnum} from \"../structs/StateEnum.sol\";\nimport \"@openzeppelin/contracts/utils/structs/EnumerableMap.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IOwnership` for docs\nlibrary LibOwnership {\n    using EnumerableMap for EnumerableMap.AddressToUintMap;\n\n    /// @notice Adds `account` as an onwer\n    /// @dev For internal use only\n    /// You must call this function with join's deposit value attached\n    function _addOwner(address account, uint256 ownershipUnits) internal {\n        // Verify that the group is still open\n        LibState._stateGuard(StateEnum.OPEN);\n\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        // Update the member's ownership units\n        require(\n            ds.ownershipUnits.set(account, ownershipUnits),\n            \"Ownership: existing member\"\n        );\n\n        // Verify ownership deposit is valid\n        _depositGuard(ownershipUnits);\n\n        // Update the total ownership units owned\n        ds.totalOwnedOwnershipUnits += ownershipUnits;\n    }\n\n    /// @notice `account` acquires more ownership units\n    /// @dev You must call this with value attached\n    function _acquireMoreOwnershipUnits(address account, uint256 ownershipUnits)\n        internal\n    {\n        // Verify that the group is still open\n        LibState._stateGuard(StateEnum.OPEN);\n\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        // Only existing member can obtain more units\n        require(ds.ownershipUnits.contains(account), \"Ownership: not a member\");\n\n        // Verify ownership deposit is valid\n        _depositGuard(ownershipUnits);\n\n        uint256 currentOwnerUnits = ds.ownershipUnits.get(account);\n        ds.ownershipUnits.set(account, currentOwnerUnits + ownershipUnits);\n        ds.totalOwnedOwnershipUnits += ownershipUnits;\n    }\n\n    /// @dev Guard that verifies that the ownership deposit is valid\n    /// Can revert:\n    ///     - \"Ownership: deposit not divisible by smallest unit\"\n    ///     - \"Ownership: deposit exceeds total ownership units\"\n    ///     - \"Ownership: deposit must be bigger than 0\"\n    function _depositGuard(uint256 ownershipUnits) internal {\n        uint256 value = msg.value;\n        uint256 smallestUnit = _smallestUnit();\n\n        require(\n            value >= ownershipUnits,\n            \"Ownership: mismatch between units and deposit amount\"\n        );\n\n        require(ownershipUnits > 0, \"Ownership: deposit must be bigger than 0\");\n\n        require(\n            ownershipUnits % smallestUnit == 0,\n            \"Ownership: deposit not divisible by smallest unit\"\n        );\n\n        require(\n            ownershipUnits + _totalOwnedOwnershipUnits() <=\n                _totalOwnershipUnits(),\n            \"Ownership: deposit exceeds total ownership units\"\n        );\n    }\n\n    /// @notice Renounce ownership\n    /// @dev The caller renounce his ownership\n    /// @return refund the amount to refund to the caller\n    function _renounceOwnership() internal returns (uint256 refund) {\n        // Verify that the group is still open\n        require(\n            LibState._state() == StateEnum.OPEN,\n            \"Ownership: group formed or uninitialized\"\n        );\n\n        // Verify that the caller is a member\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        require(\n            ds.ownershipUnits.contains(msg.sender),\n            \"Ownership: not an owner\"\n        );\n\n        // Update the member ownership units and the total units owned\n        refund = ds.ownershipUnits.get(msg.sender);\n        ds.totalOwnedOwnershipUnits -= refund;\n        ds.ownershipUnits.remove(msg.sender);\n    }\n\n    function _ownershipUnits(address member) internal view returns (uint256) {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        return ds.ownershipUnits.get(member);\n    }\n\n    function _totalOwnershipUnits() internal view returns (uint256) {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        return ds.totalOwnershipUnits;\n    }\n\n    function _smallestUnit() internal view returns (uint256) {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        return ds.smallestOwnershipUnit;\n    }\n\n    function _totalOwnedOwnershipUnits() internal view returns (uint256) {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        return ds.totalOwnedOwnershipUnits;\n    }\n\n    function _isCompletelyOwned() internal view returns (bool) {\n        return _totalOwnedOwnershipUnits() == _totalOwnershipUnits();\n    }\n\n    function _isMember(address account) internal view returns (bool) {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        return ds.ownershipUnits.contains(account);\n    }\n\n    function _memberAt(uint256 index)\n        internal\n        view\n        returns (address member, uint256 units)\n    {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        (member, units) = ds.ownershipUnits.at(index);\n    }\n\n    function _memberCount() internal view returns (uint256) {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        return ds.ownershipUnits.length();\n    }\n\n    function _members() internal view returns (address[] memory members) {\n        StorageOwnershipUnits.DiamondStorage storage ds = StorageOwnershipUnits\n            .diamondStorage();\n\n        uint256 length = ds.ownershipUnits.length();\n        members = new address[](length);\n\n        for (uint256 i = 0; i < length; i++) {\n            (members[i], ) = ds.ownershipUnits.at(i);\n        }\n    }\n}\n"
    },
    "contracts/libraries/LibPercentage.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {Math} from \"@openzeppelin/contracts/utils/math/Math.sol\";\n\n/// @author Amit Molek\n/// @dev Percentages helper\nlibrary LibPercentage {\n    uint256 public constant PERCENTAGE_DIVIDER = 100; // 1 percent precision\n\n    /// @dev Returns the ceil value of `percentage` out of `value`.\n    function _calculateCeil(uint256 value, uint256 percentage)\n        internal\n        pure\n        returns (uint256)\n    {\n        return Math.ceilDiv(value * percentage, PERCENTAGE_DIVIDER);\n    }\n}\n"
    },
    "contracts/libraries/LibQuorumGovernance.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {LibSignature} from \"./LibSignature.sol\";\nimport {LibPercentage} from \"./LibPercentage.sol\";\nimport {LibOwnership} from \"./LibOwnership.sol\";\nimport {StorageQuorumGovernance} from \"../storage/StorageQuorumGovernance.sol\";\nimport {Strings} from \"@openzeppelin/contracts/utils/Strings.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `QuorumGovernanceFacet` for docs\nlibrary LibQuorumGovernance {\n    /// @param hash the hash to verify\n    /// @param signatures array of the members signatures on `hash`\n    /// @return true, if enough members signed the `hash` with enough voting powers\n    function _verifyHash(bytes32 hash, bytes[] memory signatures)\n        internal\n        view\n        returns (bool)\n    {\n        address[] memory signedMembers = _extractMembers(hash, signatures);\n\n        return _verifyQuorum(signedMembers) && _verifyPassRate(signedMembers);\n    }\n\n    /// @param hash the hash to verify\n    /// @param signatures array of the members signatures on `hash`\n    /// @return members a list of the members that signed `hash`\n    function _extractMembers(bytes32 hash, bytes[] memory signatures)\n        internal\n        view\n        returns (address[] memory members)\n    {\n        members = new address[](signatures.length);\n\n        address lastSigner = address(0);\n        for (uint256 i = 0; i < signatures.length; i++) {\n            address signer = LibSignature._recoverSigner(hash, signatures[i]);\n            // Check for duplication (same signer)\n            require(signer > lastSigner, \"Governance: Invalid signatures\");\n            lastSigner = signer;\n\n            require(\n                LibOwnership._isMember(signer),\n                string(\n                    abi.encodePacked(\n                        \"Governance: Signer \",\n                        Strings.toHexString(uint256(uint160(signer)), 20),\n                        \" is not a member\"\n                    )\n                )\n            );\n\n            members[i] = signer;\n        }\n    }\n\n    /// @dev Explain to a developer any extra details\n    /// @param members the members to check the quorum of\n    /// @return true, if enough members signed the hash\n    function _verifyQuorum(address[] memory members)\n        internal\n        view\n        returns (bool)\n    {\n        return members.length >= _quorumThreshold();\n    }\n\n    /// @dev The calculation always rounds up (ceil) the threshold\n    /// e.g. if the group size is 3 and the quorum percentage is 50% the threshold is 2\n    /// ceil((3 * 50) / 100) = ceil(1.5) -> 2\n    /// @return the quorum threshold amount of members that must sign for the hash to be verified\n    function _quorumThreshold() internal view returns (uint256) {\n        uint256 groupSize = LibOwnership._members().length;\n        uint256 quorumPercentage = StorageQuorumGovernance\n            .diamondStorage()\n            .quorumPercentage;\n\n        return LibPercentage._calculateCeil(groupSize, quorumPercentage);\n    }\n\n    /// @dev Verifies that the pass rate of `members` passes the minimum pass rate\n    /// @param members the members to check the pass rate of\n    /// @return true, if the `members` pass rate has passed the minimum pass rate\n    function _verifyPassRate(address[] memory members)\n        internal\n        view\n        returns (bool)\n    {\n        uint256 passRate = _calculatePassRate(members);\n        uint256 passRatePercentage = StorageQuorumGovernance\n            .diamondStorage()\n            .passRatePercentage;\n\n        return passRate >= passRatePercentage;\n    }\n\n    /// @notice Calculate the weighted pass rate\n    /// @dev The weight is based upon the ownership units of each member\n    /// e.g. if Alice and Bob are the group members,\n    /// they have 60 and 40 units respectively. So the group total is 100 units.\n    /// so their weights are 60% (60/100*100) for Alice and 40% (40/100*100) for Bob.\n    /// @param members the members to check the pass rate of\n    /// @return the pass rate percentage of `members` (e.g. 46%)\n    function _calculatePassRate(address[] memory members)\n        internal\n        view\n        returns (uint256)\n    {\n        uint256 totalSignersUnits;\n        for (uint256 i = 0; i < members.length; i++) {\n            totalSignersUnits += LibOwnership._ownershipUnits(members[i]);\n        }\n\n        uint256 totalUnits = LibOwnership._totalOwnershipUnits();\n        require(totalUnits > 0, \"Governance: units can't be 0\");\n\n        return\n            (totalSignersUnits * LibPercentage.PERCENTAGE_DIVIDER) / totalUnits;\n    }\n}\n"
    },
    "contracts/libraries/LibSignature.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {ECDSA} from \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `ISignature` for docs\nlibrary LibSignature {\n    function _verifySigner(\n        address signer,\n        bytes32 hashToVerify,\n        bytes memory signature\n    ) internal pure returns (bool) {\n        return (signer == _recoverSigner(hashToVerify, signature));\n    }\n\n    function _recoverSigner(bytes32 hash, bytes memory signature)\n        internal\n        pure\n        returns (address)\n    {\n        return ECDSA.recover(hash, signature);\n    }\n}\n"
    },
    "contracts/libraries/LibState.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {StorageState} from \"../storage/StorageState.sol\";\nimport {StateEnum} from \"../structs/StateEnum.sol\";\n\n/// @author Amit Molek\n/// @dev Contract/Group state\nlibrary LibState {\n    string public constant INVALID_STATE_ERR = \"State: Invalid state\";\n\n    event StateChanged(StateEnum from, StateEnum to);\n\n    /// @dev Changes the state of the contract/group\n    /// Can revert:\n    ///     - \"State: same state\": When changing the state to the same one\n    /// Emits `StateChanged` event\n    /// @param state the new state\n    function _changeState(StateEnum state) internal {\n        StorageState.DiamondStorage storage ds = StorageState.diamondStorage();\n        require(ds.state != state, \"State: same state\");\n\n        emit StateChanged(ds.state, state);\n\n        ds.state = state;\n    }\n\n    function _state() internal view returns (StateEnum) {\n        StorageState.DiamondStorage storage ds = StorageState.diamondStorage();\n\n        return ds.state;\n    }\n\n    /// @dev reverts if `state` is not the current contract state\n    function _stateGuard(StateEnum state) internal view {\n        require(_state() == state, INVALID_STATE_ERR);\n    }\n}\n"
    },
    "contracts/libraries/LibWalletHash.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {LibQuorumGovernance} from \"../libraries/LibQuorumGovernance.sol\";\nimport {StorageApprovedHashes} from \"../storage/StorageApprovedHashes.sol\";\nimport {ECDSA} from \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\n\nlibrary LibWalletHash {\n    event ApprovedHash(bytes32 hash);\n    event RevokedHash(bytes32 hash);\n\n    /// @dev The hash time-to-live\n    uint256 internal constant HASH_TTL = 4 weeks;\n\n    /// @dev Adds `hash` to the approved hashes list\n    /// Emits `ApprovedHash`\n    function _internalApproveHash(bytes32 hash) internal {\n        StorageApprovedHashes.DiamondStorage storage ds = StorageApprovedHashes\n            .diamondStorage();\n\n        // solhint-disable-next-line not-rely-on-time\n        ds.deadlines[hash] = block.timestamp + HASH_TTL;\n        emit ApprovedHash(hash);\n    }\n\n    /// @dev Removes `hash` from the approved hashes list\n    /// Emits `RevokedHash`\n    function _internalRevokeHash(bytes32 hash) internal {\n        StorageApprovedHashes.DiamondStorage storage ds = StorageApprovedHashes\n            .diamondStorage();\n\n        delete ds.deadlines[hash];\n        emit RevokedHash(hash);\n    }\n\n    function _hashDeadline(bytes32 hash) internal view returns (uint256) {\n        StorageApprovedHashes.DiamondStorage storage ds = StorageApprovedHashes\n            .diamondStorage();\n\n        return ds.deadlines[hash];\n    }\n\n    function _isHashApproved(bytes32 hash) internal view returns (bool) {\n        StorageApprovedHashes.DiamondStorage storage ds = StorageApprovedHashes\n            .diamondStorage();\n\n        uint256 deadline = ds.deadlines[hash];\n\n        // solhint-disable-next-line not-rely-on-time\n        return deadline > block.timestamp;\n    }\n\n    function _approveHash(bytes32 hash, bytes[] memory signatures) internal {\n        // Can only approve an unapproved hash\n        require(hash != bytes32(0), \"Wallet: Invalid hash\");\n        require(!_isHashApproved(hash), \"Wallet: Approved hash\");\n\n        // Verify that the group agrees to approve the hash\n        _verifyHashGuard(hash, signatures);\n\n        _internalApproveHash(hash);\n    }\n\n    function _revokeHash(bytes32 hash, bytes[] memory signatures) internal {\n        // Can only revoke an already approved hash\n        require(hash != bytes32(0), \"Wallet: Invalid hash\");\n        require(_isHashApproved(hash), \"Wallet: Unapproved hash\");\n\n        // Verify that the group agrees to revoke the hash\n        _verifyHashGuard(hash, signatures);\n\n        _internalRevokeHash(hash);\n    }\n\n    /// @dev Reverts with \"Wallet: Unapproved request\", if `signatures` don't verify `hash`\n    function _verifyHashGuard(bytes32 hash, bytes[] memory signatures)\n        internal\n        view\n    {\n        bytes32 ethSignedHash = ECDSA.toEthSignedMessageHash(hash);\n        bool isAgreed = LibQuorumGovernance._verifyHash(\n            ethSignedHash,\n            signatures\n        );\n        require(isAgreed, \"Wallet: Unapproved request\");\n    }\n}\n"
    },
    "contracts/storage/StorageApprovedHashes.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for approved hashes\nlibrary StorageApprovedHashes {\n    struct DiamondStorage {\n        /// @dev Maps between hash and its deadline\n        mapping(bytes32 => uint256) deadlines;\n    }\n\n    bytes32 public constant DIAMOND_STORAGE_POSITION =\n        keccak256(\"antic.storage.ApprovedHashes\");\n\n    function diamondStorage()\n        internal\n        pure\n        returns (DiamondStorage storage ds)\n    {\n        bytes32 storagePosition = DIAMOND_STORAGE_POSITION;\n        assembly {\n            ds.slot := storagePosition\n        }\n    }\n}\n"
    },
    "contracts/storage/StorageOwnershipUnits.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport \"@openzeppelin/contracts/utils/structs/EnumerableMap.sol\";\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for ownership units of members\nlibrary StorageOwnershipUnits {\n    using EnumerableMap for EnumerableMap.AddressToUintMap;\n\n    struct DiamondStorage {\n        /// @dev Smallest ownership unit\n        uint256 smallestOwnershipUnit;\n        /// @dev Total ownership units\n        uint256 totalOwnershipUnits;\n        /// @dev Amount of ownership units that are owned by members.\n        /// join -> adding | leave -> subtracting\n        /// This is used in the join process to know when the group is fully funded\n        uint256 totalOwnedOwnershipUnits;\n        /// @dev Maps between member and their ownership units\n        EnumerableMap.AddressToUintMap ownershipUnits;\n    }\n\n    bytes32 public constant DIAMOND_STORAGE_POSITION =\n        keccak256(\"antic.storage.OwnershipUnits\");\n\n    function diamondStorage()\n        internal\n        pure\n        returns (DiamondStorage storage ds)\n    {\n        bytes32 storagePosition = DIAMOND_STORAGE_POSITION;\n        assembly {\n            ds.slot := storagePosition\n        }\n    }\n\n    function _initStorage(\n        uint256 smallestOwnershipUnit,\n        uint256 totalOwnershipUnits\n    ) internal {\n        require(\n            smallestOwnershipUnit > 0,\n            \"Storage: smallest ownership unit must be bigger than 0\"\n        );\n        require(\n            totalOwnershipUnits % smallestOwnershipUnit == 0,\n            \"Storage: total units not divisible by smallest unit\"\n        );\n\n        DiamondStorage storage ds = diamondStorage();\n\n        ds.smallestOwnershipUnit = smallestOwnershipUnit;\n        ds.totalOwnershipUnits = totalOwnershipUnits;\n    }\n}\n"
    },
    "contracts/storage/StorageQuorumGovernance.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for quorum governance\nlibrary StorageQuorumGovernance {\n    struct DiamondStorage {\n        /// @dev The minimum level of participation required for a vote to be valid.\n        /// in percentages out of 100 (e.g. 40)\n        uint8 quorumPercentage;\n        /// @dev What percentage of the votes cast need to be in favor in order\n        /// for the proposal to be accepted.\n        /// in percentages out of 100 (e.g. 40)\n        uint8 passRatePercentage;\n    }\n\n    bytes32 public constant DIAMOND_STORAGE_POSITION =\n        keccak256(\"antic.storage.QuorumGovernance\");\n\n    function diamondStorage()\n        internal\n        pure\n        returns (DiamondStorage storage ds)\n    {\n        bytes32 storagePosition = DIAMOND_STORAGE_POSITION;\n        assembly {\n            ds.slot := storagePosition\n        }\n    }\n\n    function _initStorage(uint8 quorumPercentage, uint8 passRatePercentage)\n        internal\n    {\n        require(\n            quorumPercentage > 0 && quorumPercentage <= 100,\n            \"Storage: quorum percentage must be in range (0,100]\"\n        );\n        require(\n            passRatePercentage > 0 && passRatePercentage <= 100,\n            \"Storage: pass rate percentage must be in range (0,100]\"\n        );\n\n        DiamondStorage storage ds = diamondStorage();\n\n        ds.quorumPercentage = quorumPercentage;\n        ds.passRatePercentage = passRatePercentage;\n    }\n}\n"
    },
    "contracts/storage/StorageState.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {StateEnum} from \"../structs/StateEnum.sol\";\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for group state\nlibrary StorageState {\n    struct DiamondStorage {\n        /// @dev State of the group\n        StateEnum state;\n    }\n\n    bytes32 public constant DIAMOND_STORAGE_POSITION =\n        keccak256(\"antic.storage.State\");\n\n    function diamondStorage()\n        internal\n        pure\n        returns (DiamondStorage storage ds)\n    {\n        bytes32 storagePosition = DIAMOND_STORAGE_POSITION;\n        assembly {\n            ds.slot := storagePosition\n        }\n    }\n}\n"
    },
    "contracts/structs/StateEnum.sol": {
      "content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n\n/// @dev State of the contract/group\nenum StateEnum {\n    UNINITIALIZED,\n    OPEN,\n    FORMED\n}\n"
    }
  }
}