{ "language": "Solidity", "sources": { "contracts/EthboxMetadata.sol": { "content": "// SPDX-License-Identifier: Unlicensed\r\n\r\npragma solidity 0.8.16;\r\n\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\nimport \"@openzeppelin/contracts/utils/Address.sol\";\r\nimport \"@openzeppelin/contracts/utils/Strings.sol\";\r\nimport \"./strings.sol\";\r\nimport \"./base64.sol\";\r\nimport \"./EthboxStructs.sol\";\r\n\r\nabstract contract ReverseRegistrar {\r\n function node(address addr) public pure virtual returns (bytes32);\r\n}\r\n\r\nabstract contract ENS {\r\n function resolver(bytes32 node) public view virtual returns (address);\r\n}\r\n\r\nabstract contract Resolver {\r\n function name(bytes32 node) public view virtual returns (string memory);\r\n}\r\n\r\ncontract EthboxMetadata is Ownable {\r\n using Address for address;\r\n using Strings for uint256;\r\n using strings for *;\r\n\r\n ENS ens;\r\n ReverseRegistrar reverseRegistrar;\r\n\r\n string private desc;\r\n string private externalUrl;\r\n string private messageInsert;\r\n string private ethboxInsert;\r\n string private emptyInsert;\r\n\r\n constructor() {\r\n ens = ENS(0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e);\r\n // reverseRegistrar = ReverseRegistrar(0x6F628b68b30Dc3c17f345c9dbBb1E483c2b7aE5c); //rinkeby\r\n reverseRegistrar = ReverseRegistrar(0x084b1c3C81545d370f3634392De611CaaBFf8148);//mainnet\r\n externalUrl = \"https://ethbox.nxc.io/address/\";\r\n desc = \"Ethbox is a fully on-chain Ethereum messaging protocol that enables any wallet to bid ETH to send messages to another wallet.\";\r\n messageInsert = '
to : ${_TO}
from: ${_FROM}
${_MESSAGE}
Bid: ${_VALUE} ETH
(${_POSITION})
';\r\n emptyInsert = '
${_TO}
Empty Ethbox
';\r\n ethboxInsert = ' Click or tap to cycle messages ${_MESSAGES}';\r\n }\r\n\r\n //////////////////////////////////////\r\n //////////////////////////////////////\r\n // Display and metadata functions //\r\n //todo : embed variables\r\n\r\n function setDesc(string memory _desc) external onlyOwner {\r\n desc = _desc;\r\n }\r\n\r\n function setExternalUrl(string memory _externalUrl) external onlyOwner {\r\n externalUrl = _externalUrl;\r\n }\r\n\r\n function setMessageInsert(string memory _messageInsert) external onlyOwner {\r\n messageInsert = _messageInsert;\r\n }\r\n\r\n function setEthboxInsert(string memory _ethboxInsert) external onlyOwner {\r\n ethboxInsert = _ethboxInsert;\r\n }\r\n\r\n function setEmptyInsert(string memory _emtpyInsert) external onlyOwner {\r\n emptyInsert = _emtpyInsert;\r\n }\r\n\r\n function valueToEthString(uint256 _value)\r\n public\r\n pure\r\n returns (string memory)\r\n {\r\n if (_value == 0) return \"0\";\r\n strings.slice memory eRep = Strings.toString(_value).toSlice();\r\n strings.slice memory zero = \"0\".toSlice();\r\n uint256 len = eRep.len();\r\n if (len > 18) {\r\n // more then 1eth, add a dot and remove trailing 0's\r\n uint256 roundEth = _value / 1 ether;\r\n strings.slice memory round = Strings.toString(roundEth).toSlice();\r\n eRep.split(round);\r\n while (eRep.endsWith(zero)) {\r\n eRep.until(zero);\r\n }\r\n return\r\n string(\r\n abi.encodePacked(round.toString(), \".\", eRep.toString())\r\n );\r\n } else {\r\n uint256 diff = 18 - len;\r\n strings.slice memory padding = \"0.\".toSlice();\r\n for (diff; diff != 0; diff--) {\r\n padding = padding.concat(zero).toSlice();\r\n }\r\n while (eRep.endsWith(zero)) {\r\n eRep.until(zero);\r\n }\r\n return\r\n string(abi.encodePacked(padding.toString(), eRep.toString()));\r\n }\r\n }\r\n\r\n function addressToENS(address _address)\r\n public\r\n view\r\n returns (string memory)\r\n {\r\n bytes32 node = reverseRegistrar.node(_address);\r\n address resolverAddress = ens.resolver(node);\r\n if (resolverAddress == address(0))\r\n return Strings.toHexString(uint160(_address), 20);\r\n Resolver resolver = Resolver(resolverAddress);\r\n string memory name = resolver.name(node);\r\n return \r\n string(\r\n abi.encodePacked(\r\n \"(maybe) \",\r\n name\r\n ));\r\n }\r\n\r\n function buildEthboxImage(\r\n address owner,\r\n EthboxStructs.UnpackedMessage[] memory messages\r\n ) public view returns (string memory) {\r\n string memory svg = buildSVG(owner, messages, messages.length);\r\n return\r\n string(\r\n abi.encodePacked(\r\n \"data:image/svg+xml;base64,\",\r\n Base64.encode(bytes(svg))\r\n )\r\n );\r\n }\r\n\r\n function buildEthboxHtml(\r\n address owner,\r\n EthboxStructs.UnpackedMessage[] memory messages\r\n ) public view returns (string memory) {\r\n string memory svg = buildSVG(owner, messages, messages.length);\r\n return\r\n string(\r\n abi.encodePacked(\r\n \"data:text/html;base64,\",\r\n Base64.encode(\r\n bytes(\r\n string(\r\n abi.encodePacked(\r\n \"\",\r\n svg,\r\n \"\"\r\n )\r\n )\r\n )\r\n )\r\n )\r\n );\r\n }\r\n\r\n function buildSingleMessageSVG(EthboxStructs.MessageInfo memory _display)\r\n private\r\n view\r\n returns (string memory)\r\n {\r\n strings.slice memory sliceMessage = messageInsert.toSlice();\r\n\r\n string memory output = string(\r\n abi.encodePacked(\r\n sliceMessage.split(\"${_INDEX}\".toSlice()).toString(),\r\n Strings.toString(_display.index),\r\n sliceMessage.split(\"${_VISIBILITY}\".toSlice()).toString(),\r\n _display.visibility,\r\n sliceMessage.split(\"${_TO}\".toSlice()).toString(),\r\n addressToENS(_display.to),\r\n sliceMessage.split(\"${_FROM}\".toSlice()).toString(),\r\n addressToENS(_display.message.from),\r\n sliceMessage.split(\"${_MESSAGE}\".toSlice()).toString()\r\n )\r\n );\r\n\r\n output = string(\r\n abi.encodePacked(\r\n output,\r\n _display.message.message,\r\n sliceMessage.split(\"${_VALUE}\".toSlice()).toString(),\r\n valueToEthString(_display.message.originalValue),\r\n sliceMessage.split(\"${_POSITION}\".toSlice()).toString(),\r\n Strings.toString(_display.index + 1),\r\n \"/\",\r\n Strings.toString(_display.maxSize),\r\n sliceMessage.toString()\r\n )\r\n );\r\n\r\n return output;\r\n }\r\n\r\n function buildEmptyEthboxSVG(address _to)\r\n private\r\n view\r\n returns (string memory)\r\n {\r\n strings.slice memory sliceMessage = emptyInsert.toSlice();\r\n\r\n string memory output = string(\r\n abi.encodePacked(\r\n sliceMessage.split(\"${_TO}\".toSlice()).toString(),\r\n addressToENS(_to),\r\n sliceMessage.toString()\r\n )\r\n );\r\n\r\n return output;\r\n }\r\n\r\n function buildSVG(\r\n address _to,\r\n EthboxStructs.UnpackedMessage[] memory _messages,\r\n uint256 _maxSize\r\n ) private view returns (string memory) {\r\n strings.slice memory sliceEthbox = ethboxInsert.toSlice();\r\n string memory output = sliceEthbox\r\n .split(\"${_MESSAGES}\".toSlice())\r\n .toString();\r\n string memory visibility = \"visible\";\r\n if (_messages.length == 0) {\r\n output = string(abi.encodePacked(output, buildEmptyEthboxSVG(_to)));\r\n } else {\r\n for (uint256 i = 0; i < _messages.length; i++) {\r\n if (i == 1) {\r\n visibility = \"none\";\r\n }\r\n EthboxStructs.MessageInfo memory display = EthboxStructs\r\n .MessageInfo(_to, visibility, _messages[i], i, _maxSize);\r\n output = string(\r\n abi.encodePacked(output, buildSingleMessageSVG(display))\r\n );\r\n }\r\n }\r\n\r\n return string(abi.encodePacked(output, sliceEthbox.toString()));\r\n }\r\n\r\n function buildMetadata(\r\n address owner,\r\n EthboxStructs.UnpackedMessage[] memory messages,\r\n uint256 ethboxSize,\r\n uint256 ethboxDrip\r\n ) public view returns (string memory) {\r\n uint256 currentSize = messages.length;\r\n string memory output = string(\r\n abi.encodePacked(\r\n '{\"name\":\"',\r\n addressToENS(owner),\r\n '\", \"description\":\"',\r\n desc,\r\n '\", \"external_url\":\"',\r\n externalUrl,\r\n addressToENS(owner),\r\n '\", \"attributes\": '\r\n )\r\n );\r\n\r\n string memory attributes = string(\r\n abi.encodePacked(\r\n '[{ \"trait_type\": \"Max Capacity\", \"value\": ',\r\n Strings.toString(ethboxSize),\r\n '},{ \"trait_type\": \"Message Count\", \"value\": ',\r\n Strings.toString(currentSize),\r\n '},{ \"trait_type\": \"Drip Time\", \"value\": ',\r\n Strings.toString(ethboxDrip),\r\n \"}]\"\r\n )\r\n );\r\n\r\n output = string(abi.encodePacked(output, attributes, ', \"image\": \"'));\r\n string memory svg = buildSVG(owner, messages, currentSize);\r\n output = string(\r\n abi.encodePacked(\r\n output,\r\n \"data:image/svg+xml;base64,\",\r\n Base64.encode(bytes(svg)),\r\n '\", \"animation_url\": \"data:text/html;base64,',\r\n Base64.encode(\r\n bytes(\r\n string(\r\n abi.encodePacked(\r\n \"\",\r\n svg,\r\n \"\"\r\n )\r\n )\r\n )\r\n ),\r\n '\"}'\r\n )\r\n );\r\n return\r\n string(\r\n abi.encodePacked(\r\n \"data:application/json;base64,\",\r\n Base64.encode(bytes(output))\r\n )\r\n );\r\n }\r\n}\r\n" }, "contracts/EthboxStructs.sol": { "content": "// SPDX-License-Identifier: Unlicensed\r\n\r\npragma solidity 0.8.16;\r\n\r\nlibrary EthboxStructs {\r\n struct Message {\r\n string message;\r\n uint256 originalValue;\r\n uint256 claimedValue;\r\n uint256 data;\r\n }\r\n\r\n struct MessageData {\r\n address from;\r\n uint64 timestamp;\r\n uint8 index;\r\n uint24 feeBPS;\r\n }\r\n\r\n struct UnpackedMessage {\r\n string message;\r\n uint256 originalValue;\r\n uint256 claimedValue;\r\n address from;\r\n uint64 timestamp;\r\n uint8 index;\r\n uint24 feeBPS;\r\n }\r\n\r\n struct MessageInfo {\r\n address to;\r\n string visibility;\r\n UnpackedMessage message;\r\n uint256 index;\r\n uint256 maxSize;\r\n }\r\n\r\n struct EthboxInfo {\r\n address recipient;\r\n uint8 size;\r\n bool locked;\r\n uint64 drip;\r\n }\r\n}\r\n" }, "contracts/base64.sol": { "content": "// SPDX-License-Identifier: MIT\r\n\r\npragma solidity ^0.8.0;\r\n\r\nlibrary Base64 {\r\n string internal constant TABLE_ENCODE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\r\n bytes internal constant TABLE_DECODE = hex\"0000000000000000000000000000000000000000000000000000000000000000\"\r\n hex\"00000000000000000000003e0000003f3435363738393a3b3c3d000000000000\"\r\n hex\"00000102030405060708090a0b0c0d0e0f101112131415161718190000000000\"\r\n hex\"001a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132330000000000\";\r\n\r\n function encode(bytes memory data) internal pure returns (string memory) {\r\n if (data.length == 0) return '';\r\n\r\n // load the table into memory\r\n string memory table = TABLE_ENCODE;\r\n\r\n // multiply by 4/3 rounded up\r\n uint256 encodedLen = 4 * ((data.length + 2) / 3);\r\n\r\n // add some extra buffer at the end required for the writing\r\n string memory result = new string(encodedLen + 32);\r\n\r\n assembly {\r\n // set the actual output length\r\n mstore(result, encodedLen)\r\n\r\n // prepare the lookup table\r\n let tablePtr := add(table, 1)\r\n\r\n // input ptr\r\n let dataPtr := data\r\n let endPtr := add(dataPtr, mload(data))\r\n\r\n // result ptr, jump over length\r\n let resultPtr := add(result, 32)\r\n\r\n // run over the input, 3 bytes at a time\r\n for {} lt(dataPtr, endPtr) {}\r\n {\r\n // read 3 bytes\r\n dataPtr := add(dataPtr, 3)\r\n let input := mload(dataPtr)\r\n\r\n // write 4 characters\r\n mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))\r\n resultPtr := add(resultPtr, 1)\r\n mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))\r\n resultPtr := add(resultPtr, 1)\r\n mstore8(resultPtr, mload(add(tablePtr, and(shr( 6, input), 0x3F))))\r\n resultPtr := add(resultPtr, 1)\r\n mstore8(resultPtr, mload(add(tablePtr, and( input, 0x3F))))\r\n resultPtr := add(resultPtr, 1)\r\n }\r\n\r\n // padding with '='\r\n switch mod(mload(data), 3)\r\n case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) }\r\n case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) }\r\n }\r\n\r\n return result;\r\n }\r\n\r\n function decode(string memory _data) internal pure returns (bytes memory) {\r\n bytes memory data = bytes(_data);\r\n\r\n if (data.length == 0) return new bytes(0);\r\n require(data.length % 4 == 0, \"invalid base64 decoder input\");\r\n\r\n // load the table into memory\r\n bytes memory table = TABLE_DECODE;\r\n\r\n // every 4 characters represent 3 bytes\r\n uint256 decodedLen = (data.length / 4) * 3;\r\n\r\n // add some extra buffer at the end required for the writing\r\n bytes memory result = new bytes(decodedLen + 32);\r\n\r\n assembly {\r\n // padding with '='\r\n let lastBytes := mload(add(data, mload(data)))\r\n if eq(and(lastBytes, 0xFF), 0x3d) {\r\n decodedLen := sub(decodedLen, 1)\r\n if eq(and(lastBytes, 0xFFFF), 0x3d3d) {\r\n decodedLen := sub(decodedLen, 1)\r\n }\r\n }\r\n\r\n // set the actual output length\r\n mstore(result, decodedLen)\r\n\r\n // prepare the lookup table\r\n let tablePtr := add(table, 1)\r\n\r\n // input ptr\r\n let dataPtr := data\r\n let endPtr := add(dataPtr, mload(data))\r\n\r\n // result ptr, jump over length\r\n let resultPtr := add(result, 32)\r\n\r\n // run over the input, 4 characters at a time\r\n for {} lt(dataPtr, endPtr) {}\r\n {\r\n // read 4 characters\r\n dataPtr := add(dataPtr, 4)\r\n let input := mload(dataPtr)\r\n\r\n // write 3 bytes\r\n let output := add(\r\n add(\r\n shl(18, and(mload(add(tablePtr, and(shr(24, input), 0xFF))), 0xFF)),\r\n shl(12, and(mload(add(tablePtr, and(shr(16, input), 0xFF))), 0xFF))),\r\n add(\r\n shl( 6, and(mload(add(tablePtr, and(shr( 8, input), 0xFF))), 0xFF)),\r\n and(mload(add(tablePtr, and( input , 0xFF))), 0xFF)\r\n )\r\n )\r\n mstore(resultPtr, shl(232, output))\r\n resultPtr := add(resultPtr, 3)\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n}" }, "contracts/strings.sol": { "content": "/*\r\n * @title String & slice utility library for Solidity contracts.\r\n * @author Nick Johnson \r\n *\r\n * @dev Functionality in this library is largely implemented using an\r\n * abstraction called a 'slice'. A slice represents a part of a string -\r\n * anything from the entire string to a single character, or even no\r\n * characters at all (a 0-length slice). Since a slice only has to specify\r\n * an offset and a length, copying and manipulating slices is a lot less\r\n * expensive than copying and manipulating the strings they reference.\r\n *\r\n * To further reduce gas costs, most functions on slice that need to return\r\n * a slice modify the original one instead of allocating a new one; for\r\n * instance, `s.split(\".\")` will return the text up to the first '.',\r\n * modifying s to only contain the remainder of the string after the '.'.\r\n * In situations where you do not want to modify the original slice, you\r\n * can make a copy first with `.copy()`, for example:\r\n * `s.copy().split(\".\")`. Try and avoid using this idiom in loops; since\r\n * Solidity has no memory management, it will result in allocating many\r\n * short-lived slices that are later discarded.\r\n *\r\n * Functions that return two slices come in two versions: a non-allocating\r\n * version that takes the second slice as an argument, modifying it in\r\n * place, and an allocating version that allocates and returns the second\r\n * slice; see `nextRune` for example.\r\n *\r\n * Functions that have to copy string data will return strings rather than\r\n * slices; these can be cast back to slices for further processing if\r\n * required.\r\n *\r\n * For convenience, some functions are provided with non-modifying\r\n * variants that create a new slice and return both; for instance,\r\n * `s.splitNew('.')` leaves s unmodified, and returns two values\r\n * corresponding to the left and right parts of the string.\r\n */\r\n\r\n// SPDX-License-Identifier: MIT\r\n\r\npragma solidity ^0.8.0;\r\n\r\nlibrary strings {\r\n struct slice {\r\n uint256 _len;\r\n uint256 _ptr;\r\n }\r\n\r\n function memcpy(\r\n uint256 dest,\r\n uint256 src,\r\n uint256 length\r\n ) private pure {\r\n // Copy word-length chunks while possible\r\n for (; length >= 32; length -= 32) {\r\n assembly {\r\n mstore(dest, mload(src))\r\n }\r\n dest += 32;\r\n src += 32;\r\n }\r\n\r\n // Copy remaining bytes\r\n uint256 mask = type(uint256).max;\r\n if (length > 0) {\r\n mask = 256**(32 - length) - 1;\r\n }\r\n assembly {\r\n let srcpart := and(mload(src), not(mask))\r\n let destpart := and(mload(dest), mask)\r\n mstore(dest, or(destpart, srcpart))\r\n }\r\n }\r\n\r\n /*\r\n * @dev Returns a slice containing the entire string.\r\n * @param self The string to make a slice from.\r\n * @return A newly allocated slice containing the entire string.\r\n */\r\n function toSlice(string memory self) internal pure returns (slice memory) {\r\n uint256 ptr;\r\n assembly {\r\n ptr := add(self, 0x20)\r\n }\r\n return slice(bytes(self).length, ptr);\r\n }\r\n\r\n /*\r\n * @dev Returns the length of a null-terminated bytes32 string.\r\n * @param self The value to find the length of.\r\n * @return The length of the string, from 0 to 32.\r\n */\r\n function len(bytes32 self) internal pure returns (uint256) {\r\n uint256 ret;\r\n if (self == 0) return 0;\r\n if (uint256(self) & type(uint128).max == 0) {\r\n ret += 16;\r\n self = bytes32(uint256(self) / 0x100000000000000000000000000000000);\r\n }\r\n if (uint256(self) & type(uint64).max == 0) {\r\n ret += 8;\r\n self = bytes32(uint256(self) / 0x10000000000000000);\r\n }\r\n if (uint256(self) & type(uint32).max == 0) {\r\n ret += 4;\r\n self = bytes32(uint256(self) / 0x100000000);\r\n }\r\n if (uint256(self) & type(uint16).max == 0) {\r\n ret += 2;\r\n self = bytes32(uint256(self) / 0x10000);\r\n }\r\n if (uint256(self) & type(uint8).max == 0) {\r\n ret += 1;\r\n }\r\n return 32 - ret;\r\n }\r\n\r\n /*\r\n * @dev Returns a slice containing the entire bytes32, interpreted as a\r\n * null-terminated utf-8 string.\r\n * @param self The bytes32 value to convert to a slice.\r\n * @return A new slice containing the value of the input argument up to the\r\n * first null.\r\n */\r\n function toSliceB32(bytes32 self) internal pure returns (slice memory ret) {\r\n // Allocate space for `self` in memory, copy it there, and point ret at it\r\n assembly {\r\n let ptr := mload(0x40)\r\n mstore(0x40, add(ptr, 0x20))\r\n mstore(ptr, self)\r\n mstore(add(ret, 0x20), ptr)\r\n }\r\n ret._len = len(self);\r\n }\r\n\r\n /*\r\n * @dev Returns a new slice containing the same data as the current slice.\r\n * @param self The slice to copy.\r\n * @return A new slice containing the same data as `self`.\r\n */\r\n function copy(slice memory self) internal pure returns (slice memory) {\r\n return slice(self._len, self._ptr);\r\n }\r\n\r\n /*\r\n * @dev Copies a slice to a new string.\r\n * @param self The slice to copy.\r\n * @return A newly allocated string containing the slice's text.\r\n */\r\n function toString(slice memory self) internal pure returns (string memory) {\r\n string memory ret = new string(self._len);\r\n uint256 retptr;\r\n assembly {\r\n retptr := add(ret, 32)\r\n }\r\n\r\n memcpy(retptr, self._ptr, self._len);\r\n return ret;\r\n }\r\n\r\n /*\r\n * @dev Returns the length in runes of the slice. Note that this operation\r\n * takes time proportional to the length of the slice; avoid using it\r\n * in loops, and call `slice.empty()` if you only need to know whether\r\n * the slice is empty or not.\r\n * @param self The slice to operate on.\r\n * @return The length of the slice in runes.\r\n */\r\n function len(slice memory self) internal pure returns (uint256 l) {\r\n // Starting at ptr-31 means the LSB will be the byte we care about\r\n uint256 ptr = self._ptr - 31;\r\n uint256 end = ptr + self._len;\r\n for (l = 0; ptr < end; l++) {\r\n uint8 b;\r\n assembly {\r\n b := and(mload(ptr), 0xFF)\r\n }\r\n if (b < 0x80) {\r\n ptr += 1;\r\n } else if (b < 0xE0) {\r\n ptr += 2;\r\n } else if (b < 0xF0) {\r\n ptr += 3;\r\n } else if (b < 0xF8) {\r\n ptr += 4;\r\n } else if (b < 0xFC) {\r\n ptr += 5;\r\n } else {\r\n ptr += 6;\r\n }\r\n }\r\n }\r\n\r\n /*\r\n * @dev Returns true if the slice is empty (has a length of 0).\r\n * @param self The slice to operate on.\r\n * @return True if the slice is empty, False otherwise.\r\n */\r\n function empty(slice memory self) internal pure returns (bool) {\r\n return self._len == 0;\r\n }\r\n\r\n /*\r\n * @dev Returns a positive number if `other` comes lexicographically after\r\n * `self`, a negative number if it comes before, or zero if the\r\n * contents of the two slices are equal. Comparison is done per-rune,\r\n * on unicode codepoints.\r\n * @param self The first slice to compare.\r\n * @param other The second slice to compare.\r\n * @return The result of the comparison.\r\n */\r\n function compare(slice memory self, slice memory other)\r\n internal\r\n pure\r\n returns (int256)\r\n {\r\n uint256 shortest = self._len;\r\n if (other._len < self._len) shortest = other._len;\r\n\r\n uint256 selfptr = self._ptr;\r\n uint256 otherptr = other._ptr;\r\n for (uint256 idx = 0; idx < shortest; idx += 32) {\r\n uint256 a;\r\n uint256 b;\r\n assembly {\r\n a := mload(selfptr)\r\n b := mload(otherptr)\r\n }\r\n if (a != b) {\r\n // Mask out irrelevant bytes and check again\r\n uint256 mask = type(uint256).max; // 0xffff...\r\n if (shortest < 32) {\r\n mask = ~(2**(8 * (32 - shortest + idx)) - 1);\r\n }\r\n unchecked {\r\n uint256 diff = (a & mask) - (b & mask);\r\n if (diff != 0) return int256(diff);\r\n }\r\n }\r\n selfptr += 32;\r\n otherptr += 32;\r\n }\r\n return int256(self._len) - int256(other._len);\r\n }\r\n\r\n /*\r\n * @dev Returns true if the two slices contain the same text.\r\n * @param self The first slice to compare.\r\n * @param self The second slice to compare.\r\n * @return True if the slices are equal, false otherwise.\r\n */\r\n function equals(slice memory self, slice memory other)\r\n internal\r\n pure\r\n returns (bool)\r\n {\r\n return compare(self, other) == 0;\r\n }\r\n\r\n /*\r\n * @dev Extracts the first rune in the slice into `rune`, advancing the\r\n * slice to point to the next rune and returning `self`.\r\n * @param self The slice to operate on.\r\n * @param rune The slice that will contain the first rune.\r\n * @return `rune`.\r\n */\r\n function nextRune(slice memory self, slice memory rune)\r\n internal\r\n pure\r\n returns (slice memory)\r\n {\r\n rune._ptr = self._ptr;\r\n\r\n if (self._len == 0) {\r\n rune._len = 0;\r\n return rune;\r\n }\r\n\r\n uint256 l;\r\n uint256 b;\r\n // Load the first byte of the rune into the LSBs of b\r\n assembly {\r\n b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF)\r\n }\r\n if (b < 0x80) {\r\n l = 1;\r\n } else if (b < 0xE0) {\r\n l = 2;\r\n } else if (b < 0xF0) {\r\n l = 3;\r\n } else {\r\n l = 4;\r\n }\r\n\r\n // Check for truncated codepoints\r\n if (l > self._len) {\r\n rune._len = self._len;\r\n self._ptr += self._len;\r\n self._len = 0;\r\n return rune;\r\n }\r\n\r\n self._ptr += l;\r\n self._len -= l;\r\n rune._len = l;\r\n return rune;\r\n }\r\n\r\n /*\r\n * @dev Returns the first rune in the slice, advancing the slice to point\r\n * to the next rune.\r\n * @param self The slice to operate on.\r\n * @return A slice containing only the first rune from `self`.\r\n */\r\n function nextRune(slice memory self)\r\n internal\r\n pure\r\n returns (slice memory ret)\r\n {\r\n nextRune(self, ret);\r\n }\r\n\r\n /*\r\n * @dev Returns the number of the first codepoint in the slice.\r\n * @param self The slice to operate on.\r\n * @return The number of the first codepoint in the slice.\r\n */\r\n function ord(slice memory self) internal pure returns (uint256 ret) {\r\n if (self._len == 0) {\r\n return 0;\r\n }\r\n\r\n uint256 word;\r\n uint256 length;\r\n uint256 divisor = 2**248;\r\n\r\n // Load the rune into the MSBs of b\r\n assembly {\r\n word := mload(mload(add(self, 32)))\r\n }\r\n uint256 b = word / divisor;\r\n if (b < 0x80) {\r\n ret = b;\r\n length = 1;\r\n } else if (b < 0xE0) {\r\n ret = b & 0x1F;\r\n length = 2;\r\n } else if (b < 0xF0) {\r\n ret = b & 0x0F;\r\n length = 3;\r\n } else {\r\n ret = b & 0x07;\r\n length = 4;\r\n }\r\n\r\n // Check for truncated codepoints\r\n if (length > self._len) {\r\n return 0;\r\n }\r\n\r\n for (uint256 i = 1; i < length; i++) {\r\n divisor = divisor / 256;\r\n b = (word / divisor) & 0xFF;\r\n if (b & 0xC0 != 0x80) {\r\n // Invalid UTF-8 sequence\r\n return 0;\r\n }\r\n ret = (ret * 64) | (b & 0x3F);\r\n }\r\n\r\n return ret;\r\n }\r\n\r\n /*\r\n * @dev Returns the keccak-256 hash of the slice.\r\n * @param self The slice to hash.\r\n * @return The hash of the slice.\r\n */\r\n function keccak(slice memory self) internal pure returns (bytes32 ret) {\r\n assembly {\r\n ret := keccak256(mload(add(self, 32)), mload(self))\r\n }\r\n }\r\n\r\n /*\r\n * @dev Returns true if `self` starts with `needle`.\r\n * @param self The slice to operate on.\r\n * @param needle The slice to search for.\r\n * @return True if the slice starts with the provided text, false otherwise.\r\n */\r\n function startsWith(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (bool)\r\n {\r\n if (self._len < needle._len) {\r\n return false;\r\n }\r\n\r\n if (self._ptr == needle._ptr) {\r\n return true;\r\n }\r\n\r\n bool equal;\r\n assembly {\r\n let length := mload(needle)\r\n let selfptr := mload(add(self, 0x20))\r\n let needleptr := mload(add(needle, 0x20))\r\n equal := eq(\r\n keccak256(selfptr, length),\r\n keccak256(needleptr, length)\r\n )\r\n }\r\n return equal;\r\n }\r\n\r\n /*\r\n * @dev If `self` starts with `needle`, `needle` is removed from the\r\n * beginning of `self`. Otherwise, `self` is unmodified.\r\n * @param self The slice to operate on.\r\n * @param needle The slice to search for.\r\n * @return `self`\r\n */\r\n function beyond(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (slice memory)\r\n {\r\n if (self._len < needle._len) {\r\n return self;\r\n }\r\n\r\n bool equal = true;\r\n if (self._ptr != needle._ptr) {\r\n assembly {\r\n let length := mload(needle)\r\n let selfptr := mload(add(self, 0x20))\r\n let needleptr := mload(add(needle, 0x20))\r\n equal := eq(\r\n keccak256(selfptr, length),\r\n keccak256(needleptr, length)\r\n )\r\n }\r\n }\r\n\r\n if (equal) {\r\n self._len -= needle._len;\r\n self._ptr += needle._len;\r\n }\r\n\r\n return self;\r\n }\r\n\r\n /*\r\n * @dev Returns true if the slice ends with `needle`.\r\n * @param self The slice to operate on.\r\n * @param needle The slice to search for.\r\n * @return True if the slice starts with the provided text, false otherwise.\r\n */\r\n function endsWith(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (bool)\r\n {\r\n if (self._len < needle._len) {\r\n return false;\r\n }\r\n\r\n uint256 selfptr = self._ptr + self._len - needle._len;\r\n\r\n if (selfptr == needle._ptr) {\r\n return true;\r\n }\r\n\r\n bool equal;\r\n assembly {\r\n let length := mload(needle)\r\n let needleptr := mload(add(needle, 0x20))\r\n equal := eq(\r\n keccak256(selfptr, length),\r\n keccak256(needleptr, length)\r\n )\r\n }\r\n\r\n return equal;\r\n }\r\n\r\n /*\r\n * @dev If `self` ends with `needle`, `needle` is removed from the\r\n * end of `self`. Otherwise, `self` is unmodified.\r\n * @param self The slice to operate on.\r\n * @param needle The slice to search for.\r\n * @return `self`\r\n */\r\n function until(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (slice memory)\r\n {\r\n if (self._len < needle._len) {\r\n return self;\r\n }\r\n\r\n uint256 selfptr = self._ptr + self._len - needle._len;\r\n bool equal = true;\r\n if (selfptr != needle._ptr) {\r\n assembly {\r\n let length := mload(needle)\r\n let needleptr := mload(add(needle, 0x20))\r\n equal := eq(\r\n keccak256(selfptr, length),\r\n keccak256(needleptr, length)\r\n )\r\n }\r\n }\r\n\r\n if (equal) {\r\n self._len -= needle._len;\r\n }\r\n\r\n return self;\r\n }\r\n\r\n // Returns the memory address of the first byte of the first occurrence of\r\n // `needle` in `self`, or the first byte after `self` if not found.\r\n function findPtr(\r\n uint256 selflen,\r\n uint256 selfptr,\r\n uint256 needlelen,\r\n uint256 needleptr\r\n ) private pure returns (uint256) {\r\n uint256 ptr = selfptr;\r\n uint256 idx;\r\n\r\n if (needlelen <= selflen) {\r\n if (needlelen <= 32) {\r\n bytes32 mask;\r\n if (needlelen > 0) {\r\n mask = bytes32(~(2**(8 * (32 - needlelen)) - 1));\r\n }\r\n\r\n bytes32 needledata;\r\n assembly {\r\n needledata := and(mload(needleptr), mask)\r\n }\r\n\r\n uint256 end = selfptr + selflen - needlelen;\r\n bytes32 ptrdata;\r\n assembly {\r\n ptrdata := and(mload(ptr), mask)\r\n }\r\n\r\n while (ptrdata != needledata) {\r\n if (ptr >= end) return selfptr + selflen;\r\n ptr++;\r\n assembly {\r\n ptrdata := and(mload(ptr), mask)\r\n }\r\n }\r\n return ptr;\r\n } else {\r\n // For long needles, use hashing\r\n bytes32 hash;\r\n assembly {\r\n hash := keccak256(needleptr, needlelen)\r\n }\r\n\r\n for (idx = 0; idx <= selflen - needlelen; idx++) {\r\n bytes32 testHash;\r\n assembly {\r\n testHash := keccak256(ptr, needlelen)\r\n }\r\n if (hash == testHash) return ptr;\r\n ptr += 1;\r\n }\r\n }\r\n }\r\n return selfptr + selflen;\r\n }\r\n\r\n // Returns the memory address of the first byte after the last occurrence of\r\n // `needle` in `self`, or the address of `self` if not found.\r\n function rfindPtr(\r\n uint256 selflen,\r\n uint256 selfptr,\r\n uint256 needlelen,\r\n uint256 needleptr\r\n ) private pure returns (uint256) {\r\n uint256 ptr;\r\n\r\n if (needlelen <= selflen) {\r\n if (needlelen <= 32) {\r\n bytes32 mask;\r\n if (needlelen > 0) {\r\n mask = bytes32(~(2**(8 * (32 - needlelen)) - 1));\r\n }\r\n\r\n bytes32 needledata;\r\n assembly {\r\n needledata := and(mload(needleptr), mask)\r\n }\r\n\r\n ptr = selfptr + selflen - needlelen;\r\n bytes32 ptrdata;\r\n assembly {\r\n ptrdata := and(mload(ptr), mask)\r\n }\r\n\r\n while (ptrdata != needledata) {\r\n if (ptr <= selfptr) return selfptr;\r\n ptr--;\r\n assembly {\r\n ptrdata := and(mload(ptr), mask)\r\n }\r\n }\r\n return ptr + needlelen;\r\n } else {\r\n // For long needles, use hashing\r\n bytes32 hash;\r\n assembly {\r\n hash := keccak256(needleptr, needlelen)\r\n }\r\n ptr = selfptr + (selflen - needlelen);\r\n while (ptr >= selfptr) {\r\n bytes32 testHash;\r\n assembly {\r\n testHash := keccak256(ptr, needlelen)\r\n }\r\n if (hash == testHash) return ptr + needlelen;\r\n ptr -= 1;\r\n }\r\n }\r\n }\r\n return selfptr;\r\n }\r\n\r\n /*\r\n * @dev Modifies `self` to contain everything from the first occurrence of\r\n * `needle` to the end of the slice. `self` is set to the empty slice\r\n * if `needle` is not found.\r\n * @param self The slice to search and modify.\r\n * @param needle The text to search for.\r\n * @return `self`.\r\n */\r\n function find(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (slice memory)\r\n {\r\n uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr);\r\n self._len -= ptr - self._ptr;\r\n self._ptr = ptr;\r\n return self;\r\n }\r\n\r\n /*\r\n * @dev Modifies `self` to contain the part of the string from the start of\r\n * `self` to the end of the first occurrence of `needle`. If `needle`\r\n * is not found, `self` is set to the empty slice.\r\n * @param self The slice to search and modify.\r\n * @param needle The text to search for.\r\n * @return `self`.\r\n */\r\n function rfind(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (slice memory)\r\n {\r\n uint256 ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr);\r\n self._len = ptr - self._ptr;\r\n return self;\r\n }\r\n\r\n /*\r\n * @dev Splits the slice, setting `self` to everything after the first\r\n * occurrence of `needle`, and `token` to everything before it. If\r\n * `needle` does not occur in `self`, `self` is set to the empty slice,\r\n * and `token` is set to the entirety of `self`.\r\n * @param self The slice to split.\r\n * @param needle The text to search for in `self`.\r\n * @param token An output parameter to which the first token is written.\r\n * @return `token`.\r\n */\r\n function split(\r\n slice memory self,\r\n slice memory needle,\r\n slice memory token\r\n ) internal pure returns (slice memory) {\r\n uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr);\r\n token._ptr = self._ptr;\r\n token._len = ptr - self._ptr;\r\n if (ptr == self._ptr + self._len) {\r\n // Not found\r\n self._len = 0;\r\n } else {\r\n self._len -= token._len + needle._len;\r\n self._ptr = ptr + needle._len;\r\n }\r\n return token;\r\n }\r\n\r\n /*\r\n * @dev Splits the slice, setting `self` to everything after the first\r\n * occurrence of `needle`, and returning everything before it. If\r\n * `needle` does not occur in `self`, `self` is set to the empty slice,\r\n * and the entirety of `self` is returned.\r\n * @param self The slice to split.\r\n * @param needle The text to search for in `self`.\r\n * @return The part of `self` up to the first occurrence of `delim`.\r\n */\r\n function split(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (slice memory token)\r\n {\r\n split(self, needle, token);\r\n }\r\n\r\n /*\r\n * @dev Splits the slice, setting `self` to everything before the last\r\n * occurrence of `needle`, and `token` to everything after it. If\r\n * `needle` does not occur in `self`, `self` is set to the empty slice,\r\n * and `token` is set to the entirety of `self`.\r\n * @param self The slice to split.\r\n * @param needle The text to search for in `self`.\r\n * @param token An output parameter to which the first token is written.\r\n * @return `token`.\r\n */\r\n function rsplit(\r\n slice memory self,\r\n slice memory needle,\r\n slice memory token\r\n ) internal pure returns (slice memory) {\r\n uint256 ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr);\r\n token._ptr = ptr;\r\n token._len = self._len - (ptr - self._ptr);\r\n if (ptr == self._ptr) {\r\n // Not found\r\n self._len = 0;\r\n } else {\r\n self._len -= token._len + needle._len;\r\n }\r\n return token;\r\n }\r\n\r\n /*\r\n * @dev Splits the slice, setting `self` to everything before the last\r\n * occurrence of `needle`, and returning everything after it. If\r\n * `needle` does not occur in `self`, `self` is set to the empty slice,\r\n * and the entirety of `self` is returned.\r\n * @param self The slice to split.\r\n * @param needle The text to search for in `self`.\r\n * @return The part of `self` after the last occurrence of `delim`.\r\n */\r\n function rsplit(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (slice memory token)\r\n {\r\n rsplit(self, needle, token);\r\n }\r\n\r\n /*\r\n * @dev Counts the number of nonoverlapping occurrences of `needle` in `self`.\r\n * @param self The slice to search.\r\n * @param needle The text to search for in `self`.\r\n * @return The number of occurrences of `needle` found in `self`.\r\n */\r\n function count(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (uint256 cnt)\r\n {\r\n uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) +\r\n needle._len;\r\n while (ptr <= self._ptr + self._len) {\r\n cnt++;\r\n ptr =\r\n findPtr(\r\n self._len - (ptr - self._ptr),\r\n ptr,\r\n needle._len,\r\n needle._ptr\r\n ) +\r\n needle._len;\r\n }\r\n }\r\n\r\n /*\r\n * @dev Returns True if `self` contains `needle`.\r\n * @param self The slice to search.\r\n * @param needle The text to search for in `self`.\r\n * @return True if `needle` is found in `self`, false otherwise.\r\n */\r\n function contains(slice memory self, slice memory needle)\r\n internal\r\n pure\r\n returns (bool)\r\n {\r\n return\r\n rfindPtr(self._len, self._ptr, needle._len, needle._ptr) !=\r\n self._ptr;\r\n }\r\n\r\n /*\r\n * @dev Returns a newly allocated string containing the concatenation of\r\n * `self` and `other`.\r\n * @param self The first slice to concatenate.\r\n * @param other The second slice to concatenate.\r\n * @return The concatenation of the two strings.\r\n */\r\n function concat(slice memory self, slice memory other)\r\n internal\r\n pure\r\n returns (string memory)\r\n {\r\n string memory ret = new string(self._len + other._len);\r\n uint256 retptr;\r\n assembly {\r\n retptr := add(ret, 32)\r\n }\r\n memcpy(retptr, self._ptr, self._len);\r\n memcpy(retptr + self._len, other._ptr, other._len);\r\n return ret;\r\n }\r\n\r\n /*\r\n * @dev Joins an array of slices, using `self` as a delimiter, returning a\r\n * newly allocated string.\r\n * @param self The delimiter to use.\r\n * @param parts A list of slices to join.\r\n * @return A newly allocated string containing all the slices in `parts`,\r\n * joined with `self`.\r\n */\r\n function join(slice memory self, slice[] memory parts)\r\n internal\r\n pure\r\n returns (string memory)\r\n {\r\n if (parts.length == 0) return \"\";\r\n\r\n uint256 length = self._len * (parts.length - 1);\r\n for (uint256 i = 0; i < parts.length; i++) length += parts[i]._len;\r\n\r\n string memory ret = new string(length);\r\n uint256 retptr;\r\n assembly {\r\n retptr := add(ret, 32)\r\n }\r\n\r\n for (uint256 i = 0; i < parts.length; i++) {\r\n memcpy(retptr, parts[i]._ptr, parts[i]._len);\r\n retptr += parts[i]._len;\r\n if (i < parts.length - 1) {\r\n memcpy(retptr, self._ptr, self._len);\r\n retptr += self._len;\r\n }\r\n }\r\n\r\n return ret;\r\n }\r\n}\r\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/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/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" }, "@openzeppelin/contracts/utils/Context.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n" } }, "settings": { "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } } }