|
{
|
|
"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/Address.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return 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(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\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(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\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(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // 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 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/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/access/DiamondReentrancyGuard.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {ReentrancyGuardStatus} from \"../structs/ReentrancyGuardStatus.sol\";\nimport {StorageReentrancyGuard} from \"../storage/StorageReentrancyGuard.sol\";\n\n/// @author Amit Molek\n/// @dev Diamond compatible reentrancy guard\ncontract DiamondReentrancyGuard {\n modifier nonReentrant() {\n StorageReentrancyGuard.DiamondStorage\n storage ds = StorageReentrancyGuard.diamondStorage();\n\n // On first call, status MUST be NOT_ENTERED\n require(\n ds.status != ReentrancyGuardStatus.ENTERED,\n \"LibReentrancyGuard: reentrant call\"\n );\n\n // About to enter the function, set guard.\n ds.status = ReentrancyGuardStatus.ENTERED;\n _;\n\n // Existed function, reset guard\n ds.status = ReentrancyGuardStatus.NOT_ENTERED;\n }\n}\n"
|
|
},
|
|
"contracts/facets/group/GroupFacet.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {LibGroup} from \"../../libraries/LibGroup.sol\";\nimport {IGroup} from \"../../interfaces/IGroup.sol\";\nimport {IWallet} from \"../../interfaces/IWallet.sol\";\nimport {DiamondReentrancyGuard} from \"../../access/DiamondReentrancyGuard.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IGroup` for docs\ncontract GroupFacet is IGroup, DiamondReentrancyGuard {\n function join(bytes memory data) external payable override {\n LibGroup._untrustedJoinDecode(data);\n }\n\n function acquireMore(bytes memory data) external payable override {\n LibGroup._untrustedAcquireMoreDecode(data);\n }\n\n function leave() external override nonReentrant {\n LibGroup._leave();\n }\n\n /// @dev Returns the value needed to send when a members wants to `join` the group, if the\n /// member wants to acquire `ownershipUnits` ownership units.\n /// You can use this function to know the value to pass to `join`/`acquireMore`.\n /// @return total The total value you need to pass on `join` (`ownershipUnits` + `anticFee` + `deploymentRefund`)\n /// @return anticFee The antic fee that will be collected\n /// @return deploymentRefund The deployment refund that will be passed to the group deployer\n function calculateValueToPass(uint256 ownershipUnits)\n public\n view\n returns (\n uint256 total,\n uint256 anticFee,\n uint256 deploymentRefund\n )\n {\n (anticFee, deploymentRefund) = LibGroup._calculateExpectedValue(\n ownershipUnits\n );\n total = anticFee + deploymentRefund + ownershipUnits;\n }\n\n /// @return true, if `proposition` is the forming proposition\n function isValidFormingProposition(IWallet.Proposition memory proposition)\n external\n view\n returns (bool)\n {\n return LibGroup._isValidFormingProposition(proposition);\n }\n}\n"
|
|
},
|
|
"contracts/interfaces/IGroup.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @title Group managment interface\n/// @author Amit Molek\ninterface IGroup {\n /// @dev Emitted when a member joins the group\n /// @param account the member that joined the group\n /// @param ownershipUnits number of ownership units bought\n event Joined(address account, uint256 ownershipUnits);\n\n /// @dev Emitted when a member acquires more ownership units\n /// @param account the member that acquired more\n /// @param ownershipUnits number of ownership units bought\n event AcquiredMore(address account, uint256 ownershipUnits);\n\n /// @dev Emitted when a member leaves the group\n /// @param account the member that leaved the group\n event Left(address account);\n\n /// @notice Join the group\n /// @dev The caller must pass contribution to the group\n /// which also represent the ownership units.\n /// The value passed to this function MUST include:\n /// the ownership units cost, Antic fee and deployment cost refund\n /// (ownership units + Antic fee + deployment refund)\n /// Emits `Joined` event\n function join(bytes memory data) external payable;\n\n /// @notice Acquire more ownership units\n /// @dev The caller must pass contribution to the group\n /// which also represent the ownership units.\n /// The value passed to this function MUST include:\n /// the ownership units cost, Antic fee and deployment cost refund\n /// (ownership units + Antic fee + deployment refund)\n /// Emits `AcquiredMore` event\n function acquireMore(bytes memory data) external payable;\n\n /// @notice Leave the group\n /// @dev The member will be refunded with his join contribution and Antic fee\n /// Emits `Leaved` event\n function leave() external;\n}\n"
|
|
},
|
|
"contracts/interfaces/IWallet.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @title Multisig wallet interface\n/// @author Amit Molek\ninterface IWallet {\n struct Transaction {\n address to;\n uint256 value;\n bytes data;\n }\n\n struct Proposition {\n /// @dev Proposition's deadline\n uint256 endsAt;\n /// @dev Proposed transaction to execute\n Transaction tx;\n /// @dev can be useful if your `transaction` needs an accompanying hash.\n /// For example in EIP1271 `isValidSignature` function.\n /// Note: Pass zero hash (0x0) if you don't need this.\n bytes32 relevantHash;\n }\n\n /// @dev Emitted on proposition execution\n /// @param hash the transaction's hash\n /// @param value the value passed with `transaction`\n /// @param successful is the transaction were successfully executed\n event ExecutedTransaction(\n bytes32 indexed hash,\n uint256 value,\n bool successful\n );\n\n /// @notice Execute proposition\n /// @param proposition the proposition to enact\n /// @param signatures a set of members EIP712 signatures on `proposition`\n /// @dev Emits `ExecutedTransaction` and `ApprovedHash` (only if `relevantHash` is passed) events\n /// @return successful true if the `proposition`'s transaction executed successfully\n /// @return returnData the data returned from the transaction\n function enactProposition(\n Proposition memory proposition,\n bytes[] memory signatures\n ) external returns (bool successful, bytes memory returnData);\n\n /// @return true, if the proposition has been enacted\n function isPropositionEnacted(bytes32 propositionHash)\n external\n view\n returns (bool);\n\n /// @return the maximum amount of value allowed to be transferred out of the contract\n function maxAllowedTransfer() external view returns (uint256);\n}\n"
|
|
},
|
|
"contracts/libraries/LibAnticFee.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {LibTransfer} from \"./LibTransfer.sol\";\nimport {StorageAnticFee} from \"../storage/StorageAnticFee.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IAnticFee` for docs\nlibrary LibAnticFee {\n event TransferredToAntic(uint256 amount);\n\n function _antic() internal view returns (address) {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n return ds.antic;\n }\n\n /// @return The amount of fee collected so far from `join`\n function _totalJoinFeeDeposits() internal view returns (uint256) {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n return ds.totalJoinFeeDeposits;\n }\n\n function _calculateAnticJoinFee(uint256 value)\n internal\n view\n returns (uint256)\n {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n return\n (value * ds.joinFeePercentage) / StorageAnticFee.PERCENTAGE_DIVIDER;\n }\n\n function _calculateAnticSellFee(uint256 value)\n internal\n view\n returns (uint256)\n {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n return\n (value * ds.sellFeePercentage) / StorageAnticFee.PERCENTAGE_DIVIDER;\n }\n\n /// @dev Store `member`'s join fee\n function _depositJoinFeePayment(address member, uint256 value) internal {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n ds.memberFeeDeposits[member] += value;\n ds.totalJoinFeeDeposits += value;\n }\n\n /// @dev Removes `member` from fee collection\n /// @return amount The amount that needs to be refunded to `member`\n function _refundFeePayment(address member)\n internal\n returns (uint256 amount)\n {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n amount = ds.memberFeeDeposits[member];\n ds.totalJoinFeeDeposits -= amount;\n delete ds.memberFeeDeposits[member];\n }\n\n /// @dev Transfer `value` to Antic\n function _untrustedTransferToAntic(uint256 value) internal {\n emit TransferredToAntic(value);\n\n LibTransfer._untrustedSendValue(payable(_antic()), value);\n }\n\n /// @dev Transfer all the `join` fees collected to Antic\n function _untrustedTransferJoinAnticFee() internal {\n _untrustedTransferToAntic(_totalJoinFeeDeposits());\n }\n\n function _anticFeePercentages()\n internal\n view\n returns (uint16 joinFeePercentage, uint16 sellFeePercentage)\n {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n joinFeePercentage = ds.joinFeePercentage;\n sellFeePercentage = ds.sellFeePercentage;\n }\n\n function _memberFeeDeposits(address member)\n internal\n view\n returns (uint256)\n {\n StorageAnticFee.DiamondStorage storage ds = StorageAnticFee\n .diamondStorage();\n\n return ds.memberFeeDeposits[member];\n }\n}\n"
|
|
},
|
|
"contracts/libraries/LibDeploymentRefund.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {StorageDeploymentCost} from \"../storage/StorageDeploymentCost.sol\";\nimport {LibOwnership} from \"./LibOwnership.sol\";\nimport {LibTransfer} from \"./LibTransfer.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IDeploymentRefund` for docs\nlibrary LibDeploymentRefund {\n event WithdrawnDeploymentRefund(address account, uint256 amount);\n event InitializedDeploymentCost(\n uint256 gasUsed,\n uint256 gasPrice,\n address deployer\n );\n event DeployerJoined(uint256 ownershipUnits);\n\n /// @dev The total refund amount can't exceed the deployment cost, so\n /// if the deployment cost refund based on `ownershipUnits` exceeds the\n /// deployment cost, the refund will be equal to only the delta left (deploymentCost - paidSoFar)\n /// @return The deployment cost refund amount that needs to be paid,\n /// if the member acquires `ownershipUnits` ownership units\n function _calculateDeploymentCostRefund(uint256 ownershipUnits)\n internal\n view\n returns (uint256)\n {\n uint256 totalOwnershipUnits = LibOwnership._totalOwnershipUnits();\n\n require(\n ownershipUnits <= totalOwnershipUnits,\n \"DeploymentRefund: Invalid units\"\n );\n\n uint256 deploymentCost = _deploymentCostToRefund();\n uint256 refundPayment = (deploymentCost * ownershipUnits) /\n totalOwnershipUnits;\n uint256 paidSoFar = _deploymentCostPaid();\n\n // Can't refund more than the deployment cost\n return\n refundPayment + paidSoFar > deploymentCost\n ? deploymentCost - paidSoFar\n : refundPayment;\n }\n\n function _payDeploymentCost(uint256 refundAmount) internal {\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n ds.paid += refundAmount;\n }\n\n function _initDeploymentCost(uint256 deploymentGasUsed, address deployer)\n internal\n {\n require(\n deploymentGasUsed > 0,\n \"DeploymentRefund: Deployment gas can't be 0\"\n );\n require(\n deployer != address(0),\n \"DeploymentRefund: Invalid deployer address\"\n );\n\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n require(\n ds.deploymentCostToRefund == 0,\n \"DeploymentRefund: Deployment cost already initialized\"\n );\n\n uint256 gasPrice = tx.gasprice;\n ds.deploymentCostToRefund = deploymentGasUsed * gasPrice;\n ds.deployer = deployer;\n\n emit InitializedDeploymentCost(deploymentGasUsed, gasPrice, deployer);\n }\n\n function _deployerJoin(address member, uint256 deployerOwnershipUnits)\n internal\n {\n require(\n !_isDeployerJoined(),\n \"DeploymentRefund: Deployer already joined\"\n );\n\n require(\n _isDeploymentCostSet(),\n \"DeploymentRefund: Must initialized deployment cost first\"\n );\n\n require(member == _deployer(), \"DeploymentRefund: Not the deployer\");\n\n require(\n deployerOwnershipUnits > 0,\n \"DeploymentRefund: Invalid ownership units\"\n );\n\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n uint256 deployerDeploymentCost = _calculateDeploymentCostRefund(\n deployerOwnershipUnits\n );\n\n // The deployer already paid\n ds.paid += deployerDeploymentCost;\n // The deployer can't withdraw his payment\n ds.withdrawn += deployerDeploymentCost;\n ds.isDeployerJoined = true;\n\n emit DeployerJoined(deployerOwnershipUnits);\n }\n\n function _isDeploymentCostSet() internal view returns (bool) {\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n return ds.deploymentCostToRefund > 0;\n }\n\n function _deploymentCostToRefund() internal view returns (uint256) {\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n return ds.deploymentCostToRefund;\n }\n\n function _deploymentCostPaid() internal view returns (uint256) {\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n return ds.paid;\n }\n\n function _withdrawn() internal view returns (uint256) {\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n return ds.withdrawn;\n }\n\n function _deployer() internal view returns (address) {\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n return ds.deployer;\n }\n\n function _refundable() internal view returns (uint256) {\n return _deploymentCostPaid() - _withdrawn();\n }\n\n function _isDeployerJoined() internal view returns (bool) {\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n\n return ds.isDeployerJoined;\n }\n\n function _withdrawDeploymentRefund() internal {\n address deployer = _deployer();\n\n // Only the deployer can withdraw the deployment cost refund\n require(\n msg.sender == deployer,\n \"DeploymentRefund: caller not the deployer\"\n );\n\n uint256 refundAmount = _refundable();\n require(refundAmount > 0, \"DeploymentRefund: nothing to withdraw\");\n\n StorageDeploymentCost.DiamondStorage storage ds = StorageDeploymentCost\n .diamondStorage();\n ds.withdrawn += refundAmount;\n\n emit WithdrawnDeploymentRefund(deployer, refundAmount);\n\n LibTransfer._untrustedSendValue(payable(deployer), refundAmount);\n }\n}\n"
|
|
},
|
|
"contracts/libraries/LibEIP712.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {StorageAnticDomain} from \"../storage/StorageAnticDomain.sol\";\nimport {ECDSA} from \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IEIP712` for docs\n/// Also please make sure you are familiar with EIP712 before editing anything\nlibrary LibEIP712 {\n bytes32 internal constant _DOMAIN_NAME = keccak256(\"Antic\");\n bytes32 internal constant _DOMAIN_VERSION = keccak256(\"1\");\n bytes32 internal constant _SALT = keccak256(\"Magrathea\");\n\n bytes32 internal constant _EIP712_DOMAIN_TYPEHASH =\n keccak256(\n \"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)\"\n );\n\n /// @dev Initializes the EIP712's domain separator\n /// note Must be called at least once, because it saves the\n /// domain separator in storage\n function _initDomainSeparator() internal {\n StorageAnticDomain.DiamondStorage storage ds = StorageAnticDomain\n .diamondStorage();\n\n ds.domainSeparator = keccak256(\n abi.encode(\n _EIP712_DOMAIN_TYPEHASH,\n _DOMAIN_NAME,\n _DOMAIN_VERSION,\n _chainId(),\n _verifyingContract(),\n _salt()\n )\n );\n }\n\n function _toTypedDataHash(bytes32 messageHash)\n internal\n view\n returns (bytes32)\n {\n return ECDSA.toTypedDataHash(_domainSeparator(), messageHash);\n }\n\n function _domainSeparator() internal view returns (bytes32) {\n StorageAnticDomain.DiamondStorage storage ds = StorageAnticDomain\n .diamondStorage();\n\n return ds.domainSeparator;\n }\n\n function _chainId() internal view returns (uint256 id) {\n assembly {\n id := chainid()\n }\n }\n\n function _verifyingContract() internal view returns (address) {\n return address(this);\n }\n\n function _salt() internal pure returns (bytes32) {\n return _SALT;\n }\n}\n"
|
|
},
|
|
"contracts/libraries/LibEIP712Proposition.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {IWallet} from \"../interfaces/IWallet.sol\";\nimport {LibEIP712} from \"./LibEIP712.sol\";\nimport {LibSignature} from \"./LibSignature.sol\";\nimport {LibEIP712Transaction} from \"./LibEIP712Transaction.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IEIP712Proposition` for docs\n/// Also please make sure you are familiar with EIP712 before editing anything\nlibrary LibEIP712Proposition {\n bytes32 internal constant _PROPOSITION_TYPEHASH =\n keccak256(\n \"Proposition(uint256 endsAt,Transaction tx,bytes32 relevantHash)Transaction(address to,uint256 value,bytes data)\"\n );\n\n function _verifyPropositionSigner(\n address signer,\n IWallet.Proposition memory proposition,\n bytes memory signature\n ) internal view returns (bool) {\n return\n LibSignature._verifySigner(\n signer,\n LibEIP712._toTypedDataHash(_hashProposition(proposition)),\n signature\n );\n }\n\n function _recoverPropositionSigner(\n IWallet.Proposition memory proposition,\n bytes memory signature\n ) internal view returns (address) {\n return\n LibSignature._recoverSigner(\n LibEIP712._toTypedDataHash(_hashProposition(proposition)),\n signature\n );\n }\n\n function _hashProposition(IWallet.Proposition memory proposition)\n internal\n pure\n returns (bytes32)\n {\n return\n keccak256(\n abi.encode(\n _PROPOSITION_TYPEHASH,\n proposition.endsAt,\n LibEIP712Transaction._hashTransaction(proposition.tx),\n proposition.relevantHash\n )\n );\n }\n\n function _toTypedDataHash(IWallet.Proposition memory proposition)\n internal\n view\n returns (bytes32)\n {\n return LibEIP712._toTypedDataHash(_hashProposition(proposition));\n }\n}\n"
|
|
},
|
|
"contracts/libraries/LibEIP712Transaction.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {IWallet} from \"../interfaces/IWallet.sol\";\nimport {LibEIP712} from \"./LibEIP712.sol\";\nimport {LibSignature} from \"./LibSignature.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IEIP712Transaction` for docs\n/// Also please make sure you are familiar with EIP712 before editing anything\nlibrary LibEIP712Transaction {\n bytes32 internal constant _TRANSACTION_TYPEHASH =\n keccak256(\"Transaction(address to,uint256 value,bytes data)\");\n\n function _verifyTransactionSigner(\n address signer,\n IWallet.Transaction memory transaction,\n bytes memory signature\n ) internal view returns (bool) {\n return\n LibSignature._verifySigner(\n signer,\n LibEIP712._toTypedDataHash(_hashTransaction(transaction)),\n signature\n );\n }\n\n function _recoverTransactionSigner(\n IWallet.Transaction memory transaction,\n bytes memory signature\n ) internal view returns (address) {\n return\n LibSignature._recoverSigner(\n LibEIP712._toTypedDataHash(_hashTransaction(transaction)),\n signature\n );\n }\n\n function _hashTransaction(IWallet.Transaction memory transaction)\n internal\n pure\n returns (bytes32)\n {\n return\n keccak256(\n abi.encode(\n _TRANSACTION_TYPEHASH,\n transaction.to,\n transaction.value,\n keccak256(transaction.data)\n )\n );\n }\n\n function _toTypedDataHash(IWallet.Transaction memory transaction)\n internal\n view\n returns (bytes32)\n {\n return LibEIP712._toTypedDataHash(_hashTransaction(transaction));\n }\n}\n"
|
|
},
|
|
"contracts/libraries/LibGroup.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {StateEnum} from \"../structs/StateEnum.sol\";\nimport {LibState} from \"../libraries/LibState.sol\";\nimport {LibOwnership} from \"../libraries/LibOwnership.sol\";\nimport {LibTransfer} from \"../libraries/LibTransfer.sol\";\nimport {LibWallet} from \"../libraries/LibWallet.sol\";\nimport {IWallet} from \"../interfaces/IWallet.sol\";\nimport {JoinData} from \"../structs/JoinData.sol\";\nimport {LibAnticFee} from \"../libraries/LibAnticFee.sol\";\nimport {LibDeploymentRefund} from \"../libraries/LibDeploymentRefund.sol\";\nimport {Strings} from \"@openzeppelin/contracts/utils/Strings.sol\";\nimport {StorageFormingProposition} from \"../storage/StorageFormingProposition.sol\";\nimport {LibEIP712Proposition} from \"./LibEIP712Proposition.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IGroup` for docs\nlibrary LibGroup {\n event Joined(address account, uint256 ownershipUnits);\n event AcquiredMore(address account, uint256 ownershipUnits);\n event Left(address account);\n\n function _calculateExpectedValue(uint256 ownershipUnits)\n internal\n view\n returns (uint256 anticFee, uint256 deploymentRefund)\n {\n require(\n LibDeploymentRefund._isDeploymentCostSet(),\n \"Group: Deployment cost must be initialized\"\n );\n\n anticFee = LibAnticFee._calculateAnticJoinFee(ownershipUnits);\n\n // If the deployer has not joined yet, he/she MUST be the next one to join,\n // and he/she doesn't need to pay the deployment cost refund.\n // Otherwise the next one to join, MUST pay the deployment refund\n deploymentRefund = !LibDeploymentRefund._isDeployerJoined()\n ? deploymentRefund = 0\n : LibDeploymentRefund._calculateDeploymentCostRefund(\n ownershipUnits\n );\n }\n\n function _internalJoin(\n address member,\n uint256 ownershipUnits,\n uint256 anticFee,\n uint256 deploymentRefund,\n bool newOwner\n ) internal {\n uint256 expectedTotal = anticFee + deploymentRefund + ownershipUnits;\n uint256 value = msg.value;\n\n // Verify that the caller passed enough value\n require(\n value == expectedTotal,\n string(\n abi.encodePacked(\n \"Group: Expected \",\n Strings.toString(expectedTotal),\n \" but received \",\n Strings.toString(value)\n )\n )\n );\n\n // Transfer fee to antic\n LibAnticFee._depositJoinFeePayment(member, anticFee);\n\n // Pay deployment cost\n LibDeploymentRefund._payDeploymentCost(deploymentRefund);\n\n if (newOwner) {\n // Add the member as a owner\n LibOwnership._addOwner(member, ownershipUnits);\n } else {\n // Update member's ownership\n LibOwnership._acquireMoreOwnershipUnits(member, ownershipUnits);\n }\n }\n\n /// @dev Decodes `data` and passes it to `_join`\n /// `data` must be encoded `JoinData` struct\n function _untrustedJoinDecode(bytes memory data) internal {\n JoinData memory joinData = abi.decode(data, (JoinData));\n\n _untrustedJoin(\n joinData.member,\n joinData.proposition,\n joinData.signatures,\n joinData.ownershipUnits\n );\n }\n\n /// @notice Internal join\n /// @dev Adds `member` to the group\n /// If the `member` fulfills the targeted ownership units -> enacts `proposition`\n /// Emits `Joined` event\n function _untrustedJoin(\n address member,\n IWallet.Proposition memory proposition,\n bytes[] memory signatures,\n uint256 ownershipUnits\n ) internal {\n // Members can join only when the group is forming (open)\n LibState._stateGuard(StateEnum.OPEN);\n\n (uint256 anticFee, uint256 deploymentRefund) = _calculateExpectedValue(\n ownershipUnits\n );\n\n if (!LibDeploymentRefund._isDeployerJoined()) {\n LibDeploymentRefund._deployerJoin(member, ownershipUnits);\n }\n\n _internalJoin(member, ownershipUnits, anticFee, deploymentRefund, true);\n\n emit Joined(member, ownershipUnits);\n\n _untrustedTryEnactFormingProposition(proposition, signatures);\n }\n\n /// @dev Decodes `data` and passes it to `_acquireMore`\n /// `data` must be encoded `JoinData` struct\n function _untrustedAcquireMoreDecode(bytes memory data) internal {\n JoinData memory joinData = abi.decode(data, (JoinData));\n\n _untrustedAcquireMore(\n joinData.member,\n joinData.proposition,\n joinData.signatures,\n joinData.ownershipUnits\n );\n }\n\n /// @notice Internal acquire more\n /// @dev `member` obtains more ownership units\n /// `member` must be an actual group member\n /// if the `member` fulfills the targeted ownership units -> enacts `proposition`\n /// Emits `AcquiredMore` event\n function _untrustedAcquireMore(\n address member,\n IWallet.Proposition memory proposition,\n bytes[] memory signatures,\n uint256 ownershipUnits\n ) internal {\n // Members can acquire more ownership units only when the group is forming (open)\n LibState._stateGuard(StateEnum.OPEN);\n\n (uint256 anticFee, uint256 deploymentRefund) = _calculateExpectedValue(\n ownershipUnits\n );\n\n _internalJoin(\n member,\n ownershipUnits,\n anticFee,\n deploymentRefund,\n false\n );\n\n emit AcquiredMore(member, ownershipUnits);\n\n _untrustedTryEnactFormingProposition(proposition, signatures);\n }\n\n /// @notice Enacts the group forming proposition\n /// @dev Enacts the given `proposition` if the group completely owns all the ownership units\n function _untrustedTryEnactFormingProposition(\n IWallet.Proposition memory proposition,\n bytes[] memory signatures\n ) internal {\n // Enacting the forming proposition is only available while the group is open\n // because this is the last step to form the group\n LibState._stateGuard(StateEnum.OPEN);\n\n // Last member to acquire the remaining ownership units, enacts the proposition\n // and forms the group\n if (LibOwnership._isCompletelyOwned()) {\n // Verify that we are going to enact the expected forming proposition\n require(\n _isValidFormingProposition(proposition),\n \"Group: Unexpected proposition\"\n );\n\n // The group is now formed\n LibState._changeState(StateEnum.FORMED);\n\n // Transfer Antic fee\n LibAnticFee._untrustedTransferJoinAnticFee();\n\n (bool successful, bytes memory returnData) = LibWallet\n ._untrustedEnactProposition(proposition, signatures);\n\n if (!successful) {\n LibTransfer._revertWithReason(returnData);\n }\n }\n }\n\n /// @notice Internal member leaves\n /// @dev `member` will be refunded with his join deposit and Antic fee\n /// Emits `Left` event\n function _leave() internal {\n // Members can leave only while the group is forming (open)\n LibState._stateGuard(StateEnum.OPEN);\n\n address member = msg.sender;\n\n // Caller renounce his ownership\n uint256 ownershipRefundAmount = LibOwnership._renounceOwnership();\n uint256 anticFeeRefundAmount = LibAnticFee._refundFeePayment(member);\n uint256 refundAmount = ownershipRefundAmount + anticFeeRefundAmount;\n\n emit Left(member);\n\n // Refund the caller with his join deposit\n LibTransfer._untrustedSendValue(payable(member), refundAmount);\n }\n\n function _isValidFormingProposition(IWallet.Proposition memory proposition)\n internal\n view\n returns (bool)\n {\n StorageFormingProposition.DiamondStorage\n storage ds = StorageFormingProposition.diamondStorage();\n\n bytes32 propositionHash = LibEIP712Proposition._toTypedDataHash(\n proposition\n );\n return propositionHash == ds.formingPropositionHash;\n }\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/LibReceive.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {LibAnticFee} from \"./LibAnticFee.sol\";\nimport {LibOwnership} from \"./LibOwnership.sol\";\nimport {StorageReceive} from \"../storage/StorageReceive.sol\";\nimport {LibTransfer} from \"./LibTransfer.sol\";\nimport {LibDeploymentRefund} from \"./LibDeploymentRefund.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IReceive` for docs\nlibrary LibReceive {\n event ValueWithdrawn(address member, uint256 value);\n event ValueReceived(address from, uint256 value);\n\n function _receive() internal {\n uint256 value = msg.value;\n\n emit ValueReceived(msg.sender, value);\n\n uint256 anticFee = LibAnticFee._calculateAnticSellFee(value);\n uint256 remainingValue = value - anticFee;\n\n _splitValueToMembers(remainingValue);\n LibAnticFee._untrustedTransferToAntic(anticFee);\n }\n\n /// @dev Splits `value` to the group members, based on their ownership units\n function _splitValueToMembers(uint256 value) internal {\n uint256 memberCount = LibOwnership._memberCount();\n uint256 totalOwnershipUnits = LibOwnership._totalOwnershipUnits();\n\n StorageReceive.DiamondStorage storage ds = StorageReceive\n .diamondStorage();\n\n // Iterate over all the group members and split the incoming funds to them.\n // *Based on their ownership units\n uint256 total = 0;\n for (uint256 i = 0; i < memberCount; i++) {\n (address member, uint256 units) = LibOwnership._memberAt(i);\n\n uint256 withdrawablePortion = (value * units) / totalOwnershipUnits;\n ds.withdrawable[member] += withdrawablePortion;\n total += withdrawablePortion;\n }\n\n // The loss of precision in the split calculation\n // can lead to trace funds unavailable to claim. So we tip\n // the deployer with the remainder\n if (value > total) {\n uint256 deployerTip = value - total;\n address deployer = LibDeploymentRefund._deployer();\n\n ds.withdrawable[deployer] += deployerTip;\n }\n\n // Update the total withdrawable amount by members.\n ds.totalWithdrawable += value;\n }\n\n /// @dev Transfer collected funds to the calling member\n /// Emits `ValueWithdrawn`\n function _withdraw() internal {\n address account = msg.sender;\n\n require(LibOwnership._isMember(account), \"Receive: not a member\");\n\n StorageReceive.DiamondStorage storage ds = StorageReceive\n .diamondStorage();\n\n uint256 withdrawable = ds.withdrawable[account];\n require(withdrawable > 0, \"Receive: nothing to withdraw\");\n\n ds.withdrawable[account] = 0;\n ds.totalWithdrawable -= withdrawable;\n\n emit ValueWithdrawn(account, withdrawable);\n\n LibTransfer._untrustedSendValue(payable(account), withdrawable);\n }\n\n function _withdrawable(address member) internal view returns (uint256) {\n StorageReceive.DiamondStorage storage ds = StorageReceive\n .diamondStorage();\n\n return ds.withdrawable[member];\n }\n\n function _totalWithdrawable() internal view returns (uint256) {\n StorageReceive.DiamondStorage storage ds = StorageReceive\n .diamondStorage();\n\n return ds.totalWithdrawable;\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/LibTransfer.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\n/// @author Amit Molek\n/// @dev Transfer helpers\nlibrary LibTransfer {\n /// @dev Sends `value` in wei to `recipient`\n /// Reverts on failure\n function _untrustedSendValue(address payable recipient, uint256 value)\n internal\n {\n Address.sendValue(recipient, value);\n }\n\n /// @dev Performs a function call\n function _untrustedCall(\n address to,\n uint256 value,\n bytes memory data\n ) internal returns (bool successful, bytes memory returnData) {\n require(\n address(this).balance >= value,\n \"Transfer: insufficient balance\"\n );\n\n (successful, returnData) = to.call{value: value}(data);\n }\n\n /// @dev Extracts and bubbles the revert reason if exist, otherwise reverts with a hard-coded reason.\n function _revertWithReason(bytes memory returnData) internal pure {\n if (returnData.length == 0) {\n revert(\"Transfer: call reverted without a reason\");\n }\n\n // Bubble the revert reason\n assembly {\n let returnDataSize := mload(returnData)\n revert(add(32, returnData), returnDataSize)\n }\n }\n}\n"
|
|
},
|
|
"contracts/libraries/LibWallet.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {IWallet} from \"../interfaces/IWallet.sol\";\nimport {LibQuorumGovernance} from \"../libraries/LibQuorumGovernance.sol\";\nimport {LibEIP712Transaction} from \"../libraries/LibEIP712Transaction.sol\";\nimport {LibEIP712} from \"../libraries/LibEIP712.sol\";\nimport {StorageEnactedPropositions} from \"../storage/StorageEnactedPropositions.sol\";\nimport {LibEIP712Proposition} from \"../libraries/LibEIP712Proposition.sol\";\nimport {LibState} from \"../libraries/LibState.sol\";\nimport {StateEnum} from \"../structs/StateEnum.sol\";\nimport {LibTransfer} from \"../libraries/LibTransfer.sol\";\nimport {LibWalletHash} from \"./LibWalletHash.sol\";\nimport {LibDeploymentRefund} from \"./LibDeploymentRefund.sol\";\nimport {LibReceive} from \"./LibReceive.sol\";\nimport {Strings} from \"@openzeppelin/contracts/utils/Strings.sol\";\n\n/// @author Amit Molek\n/// @dev Please see `IWallet` for docs\nlibrary LibWallet {\n event ExecutedTransaction(\n bytes32 indexed hash,\n uint256 value,\n bool successful\n );\n\n function _maxAllowedTransfer() internal view returns (uint256) {\n return\n address(this).balance -\n LibDeploymentRefund._refundable() -\n LibReceive._totalWithdrawable();\n }\n\n /// @dev Reverts if the transaction's value exceeds the maximum allowed value\n /// max allowed = (balance - deployer's refund - total withdrawable value by members)\n /// revert message example: \"Wallet: 42 exceeds maximum value of 6\"\n function _maxAllowedTransferGuard(uint256 value) internal view {\n uint256 maxValueAllowed = _maxAllowedTransfer();\n require(\n value <= maxValueAllowed,\n string(\n abi.encodePacked(\n \"Wallet: \",\n Strings.toString(value),\n \" exceeds maximum value of \",\n Strings.toString(maxValueAllowed)\n )\n )\n );\n }\n\n /// @dev Emits `ExecutedTransaction` event\n /// @param transaction the transaction to execute\n function _untrustedExecuteTransaction(\n IWallet.Transaction memory transaction\n ) internal returns (bool successful, bytes memory returnData) {\n // Verify that the transaction's value doesn't exceeds\n // the maximum allowed value.\n // The deployer's refund and each member's withdrawable value\n _maxAllowedTransferGuard(transaction.value);\n\n (successful, returnData) = LibTransfer._untrustedCall(\n transaction.to,\n transaction.value,\n transaction.data\n );\n\n emit ExecutedTransaction(\n LibEIP712Transaction._hashTransaction(transaction),\n transaction.value,\n successful\n );\n }\n\n /// @dev Can revert:\n /// - \"Wallet: Enacted proposition given\": If the proposition was already enacted\n /// - \"Wallet: Proposition ended\": If the proposition's time-to-live ended\n /// - \"Wallet: Unapproved proposition\": If group members did not reach on agreement on `proposition`\n /// - \"Wallet: Group not formed\": If the group state is not valid\n /// Emits `ApprovedHash` and `ExecutedTransaction` events\n function _untrustedEnactProposition(\n IWallet.Proposition memory proposition,\n bytes[] memory signatures\n ) internal returns (bool successful, bytes memory returnData) {\n LibState._stateGuard(StateEnum.FORMED);\n\n bytes32 propositionHash = LibEIP712Proposition._toTypedDataHash(\n proposition\n );\n\n StorageEnactedPropositions.DiamondStorage\n storage enactedPropositionsStorage = StorageEnactedPropositions\n .diamondStorage();\n\n // A proposition can only be executed once\n require(\n !enactedPropositionsStorage.enactedPropositions[propositionHash],\n \"Wallet: Enacted proposition given\"\n );\n\n require(\n // solhint-disable-next-line not-rely-on-time\n proposition.endsAt >= block.timestamp,\n \"Wallet: Proposition ended\"\n );\n\n // Verify that the proposition is agreed upon\n bool isPropositionVerified = LibQuorumGovernance._verifyHash(\n propositionHash,\n signatures\n );\n require(isPropositionVerified, \"Wallet: Unapproved proposition\");\n\n // Tag the proposition as enacted\n enactedPropositionsStorage.enactedPropositions[propositionHash] = true;\n\n if (proposition.relevantHash != bytes32(0)) {\n // Store the approved hash for later (probably for EIP1271)\n LibWalletHash._internalApproveHash(proposition.relevantHash);\n }\n\n return _untrustedExecuteTransaction(proposition.tx);\n }\n\n function _isPropositionEnacted(bytes32 propositionHash)\n internal\n view\n returns (bool)\n {\n StorageEnactedPropositions.DiamondStorage\n storage ds = StorageEnactedPropositions.diamondStorage();\n\n return ds.enactedPropositions[propositionHash];\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/StorageAnticDomain.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for EIP712's domain separator\nlibrary StorageAnticDomain {\n struct DiamondStorage {\n bytes32 domainSeparator;\n }\n\n bytes32 public constant DIAMOND_STORAGE_POSITION =\n keccak256(\"antic.storage.AnticDomain\");\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/StorageAnticFee.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for Antic fee\nlibrary StorageAnticFee {\n uint16 public constant PERCENTAGE_DIVIDER = 1000; // .1 precision\n uint16 public constant MAX_ANTIC_FEE_PERCENTAGE = 500; // 50%\n\n struct DiamondStorage {\n address antic;\n /// @dev Maps between member and it's Antic fee deposit\n /// Used only in `leave`\n mapping(address => uint256) memberFeeDeposits;\n /// @dev Total Antic join deposits mades\n uint256 totalJoinFeeDeposits;\n /// @dev Antic join fee percentage out of 1000\n /// e.g. 25 -> 25/1000 = 2.5%\n uint16 joinFeePercentage;\n /// @dev Antic sell/receive fee percentage out of 1000\n /// e.g. 25 -> 25/1000 = 2.5%\n uint16 sellFeePercentage;\n }\n\n bytes32 public constant DIAMOND_STORAGE_POSITION =\n keccak256(\"antic.storage.AnticFee\");\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 address antic,\n uint16 joinFeePercentage,\n uint16 sellFeePercentage\n ) internal {\n DiamondStorage storage ds = diamondStorage();\n\n require(antic != address(0), \"Storage: Invalid Antic address\");\n\n require(\n joinFeePercentage <= MAX_ANTIC_FEE_PERCENTAGE,\n \"Storage: Invalid Antic join fee percentage\"\n );\n\n require(\n sellFeePercentage <= MAX_ANTIC_FEE_PERCENTAGE,\n \"Storage: Invalid Antic sell/receive fee percentage\"\n );\n\n ds.antic = antic;\n ds.joinFeePercentage = joinFeePercentage;\n ds.sellFeePercentage = sellFeePercentage;\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/StorageDeploymentCost.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for deployment cost split mechanism\nlibrary StorageDeploymentCost {\n struct DiamondStorage {\n /// @dev The account that deployed the contract\n address deployer;\n /// @dev Use to indicate that the deployer has joined the group\n /// (for deployment cost refund calculation)\n bool isDeployerJoined;\n /// @dev Contract deployment cost to refund (minus what the deployer already paid)\n uint256 deploymentCostToRefund;\n /// @dev Deployment cost refund paid so far\n uint256 paid;\n /// @dev Refund amount withdrawn by the deployer\n uint256 withdrawn;\n }\n\n bytes32 public constant DIAMOND_STORAGE_POSITION =\n keccak256(\"antic.storage.DeploymentCost\");\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/StorageEnactedPropositions.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for enacted propositions (propositions that already got executed)\nlibrary StorageEnactedPropositions {\n struct DiamondStorage {\n /// @dev Mapping of proposition's EIP712 hash to enacted flag\n mapping(bytes32 => bool) enactedPropositions;\n }\n\n bytes32 public constant DIAMOND_STORAGE_POSITION =\n keccak256(\"antic.storage.EnactedPropositions\");\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/StorageFormingProposition.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for the forming proposition\nlibrary StorageFormingProposition {\n struct DiamondStorage {\n /// @dev The hash of the forming proposition to be enacted\n bytes32 formingPropositionHash;\n }\n\n bytes32 public constant DIAMOND_STORAGE_POSITION =\n keccak256(\"antic.storage.FormingProposition\");\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(bytes32 formingPropositionHash) internal {\n DiamondStorage storage ds = diamondStorage();\n\n require(\n formingPropositionHash != bytes32(0),\n \"Storage: Invalid forming proposition hash\"\n );\n\n ds.formingPropositionHash = formingPropositionHash;\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/StorageReceive.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for receive funds\nlibrary StorageReceive {\n struct DiamondStorage {\n /// Map between a member and amount of funds it can withdraw\n mapping(address => uint256) withdrawable;\n /// Total withdrawable amount\n uint256 totalWithdrawable;\n }\n\n bytes32 public constant DIAMOND_STORAGE_POSITION =\n keccak256(\"antic.storage.Receive\");\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/StorageReentrancyGuard.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {ReentrancyGuardStatus} from \"../structs/ReentrancyGuardStatus.sol\";\n\n/// @author Amit Molek\n/// @dev Diamond compatible storage for reentrancy guard\nlibrary StorageReentrancyGuard {\n struct DiamondStorage {\n /// @dev\n ReentrancyGuardStatus status;\n }\n\n bytes32 public constant DIAMOND_STORAGE_POSITION =\n keccak256(\"antic.storage.ReentrancyGuard\");\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/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/JoinData.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\nimport {IWallet} from \"../interfaces/IWallet.sol\";\n\n/// @author Amit Molek\n\n/// @dev The data needed for `join`\n/// This needs to be encoded (you can use `JoinDataCodec`) and be passed to `join`\nstruct JoinData {\n address member;\n IWallet.Proposition proposition;\n bytes[] signatures;\n /// @dev How much ownership units `member` want to acquire\n uint256 ownershipUnits;\n}\n\n/// @dev Codec for `JoinData`\ncontract JoinDataCodec {\n function encode(JoinData memory joinData)\n external\n pure\n returns (bytes memory)\n {\n return abi.encode(joinData);\n }\n\n function decode(bytes memory data) external pure returns (JoinData memory) {\n return abi.decode(data, (JoinData));\n }\n}\n"
|
|
},
|
|
"contracts/structs/ReentrancyGuardStatus.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.16;\n\n/// @author Amit Molek\n\n/// @dev Status enum for DiamondReentrancyGuard\nenum ReentrancyGuardStatus {\n NOT_ENTERED,\n ENTERED\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"
|
|
}
|
|
}
|
|
} |