{ "language": "Solidity", "sources": { "contracts/TheGameOfChance/SudoChance.sol": { "content": "// SPDX-License-Identifier: MIT\r\n\r\n/*\r\n _________ .___ _________ .__ \r\n / _____/__ __ __| _/____ \\_ ___ \\| |__ _____ ____ ____ ____ \r\n \\_____ \\| | \\/ __ |/ _ \\/ \\ \\/| | \\\\__ \\ / \\_/ ___\\/ __ \\ \r\n / \\ | / /_/ ( <_> ) \\___| Y \\/ __ \\| | \\ \\__\\ ___/ \r\n/_______ /____/\\____ |\\____/ \\______ /___| (____ /___| /\\___ >___ >\r\n \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/ \r\n\r\n Official Twitter: https://twitter.com/sudoswapgame\r\n Coded by: https://twitter.com/HakoCode\r\n*/\r\n\r\npragma solidity 0.8.16;\r\n\r\nimport \"./ERC721A/IERC721A.sol\";\r\nimport \"./ERC721A/ERC721A.sol\";\r\nimport \"./SudoSwap/ILSSVMPairFactory.sol\";\r\nimport \"./SudoSwap/ILSSVMPair.sol\";\r\nimport \"./SudoSwap/ICurve.sol\";\r\nimport {SafeTransferLib} from \"./Solmate/SafeTransferLib.sol\";\r\n\r\nimport \"@api3/airnode-protocol/contracts/rrp/requesters/RrpRequesterV0.sol\";\r\nimport \"@openzeppelin/contracts/utils/Strings.sol\";\r\nimport \"@openzeppelin/contracts/utils/Base64.sol\";\r\n\r\ncontract SudoChance is ERC721A, RrpRequesterV0 {\r\n using SafeTransferLib for address payable;\r\n\r\n ILSSVMPairFactory private constant SUDO_PAIR_FACTORY = ILSSVMPairFactory(0xb16c1342E617A5B6E4b631EB114483FDB289c0A4);\r\n ICurve constant private SUDO_EXP_CURVE = ICurve(0x432f962D8209781da23fB37b6B59ee15dE7d9841);\r\n\r\n address constant private API3_AIRNODE_RRP_ADDRESS = 0xa0AD79D995DdeeB18a14eAef56A549A04e3Aa1Bd;\r\n address constant private API3_AIRNODE_ADDRESS = 0x9d3C147cA16DB954873A498e0af5852AB39139f2;\r\n bytes32 constant private API3_UINT256_ENDPOINT_ID = 0xfb6d017bb87991b7495f563db3c8cf59ff87b09781947bb1e417006ad7f55a78;\r\n\r\n uint256 constant public MAX_SUPPLY = 2500;\r\n uint128 constant public STARTING_PRICE = 0.002 ether;\r\n uint128 constant public EXP_DELTA = 1001500000000000000;\r\n\r\n GameState public currentState;\r\n ILSSVMPair public gameSudoPool;\r\n uint256 public numberOfTicketSold;\r\n bytes32 private lastRandomnessRequestId;\r\n uint256 private lastRandomNumber;\r\n address private teamWallet;\r\n address private sponsorWallet;\r\n\r\n enum GameState {\r\n CREATED,\r\n ACTIVE,\r\n PRIZE,\r\n ENDED\r\n }\r\n\r\n event RequestedUint256(bytes32 indexed requestId);\r\n event ReceivedUint256(bytes32 indexed requestId, uint256 response);\r\n\r\n\r\n constructor() ERC721A(\"SudoChance Genesis\", \"SCG\") RrpRequesterV0(API3_AIRNODE_RRP_ADDRESS) {\r\n currentState = GameState.CREATED;\r\n teamWallet = _msgSenderERC721A();\r\n }\r\n\r\n receive() external payable {}\r\n fallback() external payable {}\r\n\r\n function intializeGame(address _sponsorWallet) external onlyTeam {\r\n require(currentState == GameState.CREATED, \"Game already active\");\r\n sponsorWallet = _sponsorWallet;\r\n\r\n setupSudoPool();\r\n _mintERC2309(address(gameSudoPool), MAX_SUPPLY);\r\n currentState = GameState.ACTIVE;\r\n }\r\n\r\n function setupSudoPool() internal {\r\n gameSudoPool = SUDO_PAIR_FACTORY.createPairETH(\r\n IERC721A(this),\r\n SUDO_EXP_CURVE,\r\n payable(0),\r\n ILSSVMPair.PoolType.TRADE,\r\n EXP_DELTA,\r\n 0,\r\n STARTING_PRICE,\r\n new uint256[](0)\r\n );\r\n }\r\n\r\n function getBurnCount() view public returns (uint256) {\r\n return _totalBurned();\r\n }\r\n\r\n function distributePrize() external onlyTeam {\r\n require(currentState == GameState.PRIZE, \"Game not in prize phase\");\r\n (,address winner) = getRandomGameWinner();\r\n gameSudoPool.withdrawAllETH();\r\n\r\n payable(teamWallet).safeTransferETH(address(this).balance / 10);\r\n payable(winner).safeTransferETH(address(this).balance);\r\n\r\n currentState = GameState.ENDED;\r\n }\r\n\r\n function getRandomGameWinner() public view returns (uint256, address) {\r\n require(lastRandomNumber != 0, \"Randomness not initialized\");\r\n uint256 entropy = lastRandomNumber;\r\n uint256 winningTicketId;\r\n\r\n for (uint i = 0; i < 10; i++) {\r\n (winningTicketId, entropy) = getNextRandom(MAX_SUPPLY, entropy, 25);\r\n address ticketOwner = ownerOf(winningTicketId);\r\n\r\n if (ticketOwner != address(0) && ticketOwner != address(gameSudoPool))\r\n {\r\n return (winningTicketId, ticketOwner);\r\n }\r\n }\r\n revert(\"No winner found\");\r\n }\r\n\r\n function getNextRandom(uint256 maxNumber, uint256 entropy, uint256 bits) private pure returns (uint256, uint256) {\r\n uint256 maxB = (uint256(1)<> bits);\r\n }\r\n\r\n function makeRequestUint256(bool test) external onlyTeam {\r\n bytes32 requestId = airnodeRrp.makeFullRequest(\r\n API3_AIRNODE_ADDRESS,\r\n API3_UINT256_ENDPOINT_ID,\r\n address(this),\r\n sponsorWallet,\r\n address(this),\r\n this.fulfillUint256.selector,\r\n \"\"\r\n );\r\n emit RequestedUint256(requestId);\r\n \r\n if (!test)\r\n lastRandomnessRequestId = requestId;\r\n }\r\n\r\n function fulfillUint256(bytes32 requestId, bytes calldata data) external onlyAirnodeRrp\r\n {\r\n require(lastRandomnessRequestId == requestId, \"Invalid id\");\r\n lastRandomNumber = abi.decode(data, (uint256));\r\n lastRandomnessRequestId = 0x0;\r\n\r\n emit ReceivedUint256(requestId, lastRandomNumber);\r\n }\r\n\r\n function _beforeTokenTransfers(address from, address to, uint256 startTokenId, uint256 quantity) internal virtual override {\r\n require(currentState == GameState.ACTIVE || currentState == GameState.CREATED, \"Game must be active\");\r\n \r\n if (to == address(0) && from != address(gameSudoPool))\r\n revert(\"Can't burn directly\");\r\n }\r\n\r\n function _afterTokenTransfers(address from, address to, uint256 startTokenId, uint256 quantity) internal virtual override {\r\n if (to == address(gameSudoPool) && from != address(0)) {\r\n for (uint i = 0; i < quantity; i++)\r\n _burn(startTokenId + i);\r\n }\r\n else if (from == address(gameSudoPool) && to != address(0)) {\r\n uint256 currentTicketSold = numberOfTicketSold;\r\n unchecked {\r\n currentTicketSold++;\r\n }\r\n numberOfTicketSold = currentTicketSold;\r\n\r\n if (numberOfTicketSold >= MAX_SUPPLY)\r\n currentState = GameState.PRIZE;\r\n }\r\n }\r\n\r\n function balanceOf(address owner) public view virtual override returns (uint256) {\r\n uint256 realBalance = balanceOfOriginal(owner);\r\n\r\n if (owner == address(gameSudoPool) && msg.sender != tx.origin)\r\n return realBalance + getBurnCount();\r\n else\r\n return realBalance;\r\n }\r\n\r\n function tokenOfOwnerByIndex(address owner, uint256 index) external view virtual returns (uint256) {\r\n unchecked {\r\n uint256 tokenIdsIdx;\r\n address currOwnershipAddr;\r\n uint256 tokenIdsLength = balanceOfOriginal(owner);\r\n uint256[] memory tokenIds = new uint256[](tokenIdsLength);\r\n TokenOwnership memory ownership;\r\n\r\n for (uint256 i = _startTokenId(); tokenIdsIdx != tokenIdsLength; ++i) {\r\n ownership = _ownershipAt(i);\r\n if (ownership.burned) {\r\n continue;\r\n }\r\n if (ownership.addr != address(0)) {\r\n currOwnershipAddr = ownership.addr;\r\n }\r\n if (currOwnershipAddr == owner) {\r\n tokenIds[tokenIdsIdx++] = i;\r\n }\r\n }\r\n return tokenIds[index];\r\n }\r\n }\r\n\r\n function tokenURI(uint256 tokenId) override public view returns (string memory) {\r\n string memory base = \"data:application/json;base64,\";\r\n string memory tokenID = Strings.toString(tokenId + 1);\r\n string memory json = string(abi.encodePacked(\r\n '{\\n\\t\"name\": \"SC Ticket #', tokenID,\r\n '\",\\n\\t\"description\": \"', \"SudoChance is an innovative game on SudoSwap where the winner gets all of the liquidity in the pool\",\r\n '\",\\n\\t\"image\": \"', \"ipfs://Qmczti8PU1uumZt6kV4FXSE1pL7gABVFfVpRaHsLqFxTpm\",\r\n '\"\\n}'));\r\n\r\n return string(abi.encodePacked(base, Base64.encode(bytes(json))));\r\n }\r\n\r\n modifier onlyTeam() {\r\n require(msg.sender == teamWallet, \"Not allowed\");\r\n _;\r\n }\r\n}" }, "@openzeppelin/contracts/utils/Base64.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Base64.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides a set of functions to operate with Base64 strings.\n *\n * _Available since v4.5._\n */\nlibrary Base64 {\n /**\n * @dev Base64 Encoding/Decoding Table\n */\n string internal constant _TABLE = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n /**\n * @dev Converts a `bytes` to its Bytes64 `string` representation.\n */\n function encode(bytes memory data) internal pure returns (string memory) {\n /**\n * Inspired by Brecht Devos (Brechtpd) implementation - MIT licence\n * https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol\n */\n if (data.length == 0) return \"\";\n\n // Loads the table into memory\n string memory table = _TABLE;\n\n // Encoding takes 3 bytes chunks of binary data from `bytes` data parameter\n // and split into 4 numbers of 6 bits.\n // The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up\n // - `data.length + 2` -> Round up\n // - `/ 3` -> Number of 3-bytes chunks\n // - `4 *` -> 4 characters for each chunk\n string memory result = new string(4 * ((data.length + 2) / 3));\n\n /// @solidity memory-safe-assembly\n assembly {\n // Prepare the lookup table (skip the first \"length\" byte)\n let tablePtr := add(table, 1)\n\n // Prepare result pointer, jump over length\n let resultPtr := add(result, 32)\n\n // Run over the input, 3 bytes at a time\n for {\n let dataPtr := data\n let endPtr := add(data, mload(data))\n } lt(dataPtr, endPtr) {\n\n } {\n // Advance 3 bytes\n dataPtr := add(dataPtr, 3)\n let input := mload(dataPtr)\n\n // To write each character, shift the 3 bytes (18 bits) chunk\n // 4 times in blocks of 6 bits for each character (18, 12, 6, 0)\n // and apply logical AND with 0x3F which is the number of\n // the previous character in the ASCII table prior to the Base64 Table\n // The result is then added to the table to get the character to write,\n // and finally write it in the result pointer but with a left shift\n // of 256 (1 byte) - 8 (1 ASCII char) = 248 bits\n\n mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))\n resultPtr := add(resultPtr, 1) // Advance\n\n mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))\n resultPtr := add(resultPtr, 1) // Advance\n\n mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))\n resultPtr := add(resultPtr, 1) // Advance\n\n mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))\n resultPtr := add(resultPtr, 1) // Advance\n }\n\n // When data `bytes` is not exactly 3 bytes long\n // it is padded with `=` characters at the end\n switch mod(mload(data), 3)\n case 1 {\n mstore8(sub(resultPtr, 1), 0x3d)\n mstore8(sub(resultPtr, 2), 0x3d)\n }\n case 2 {\n mstore8(sub(resultPtr, 1), 0x3d)\n }\n }\n\n return result;\n }\n}\n" }, "@openzeppelin/contracts/utils/Strings.sol": { "content": "// SPDX-License-Identifier: MIT\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" }, "@api3/airnode-protocol/contracts/rrp/requesters/RrpRequesterV0.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"../interfaces/IAirnodeRrpV0.sol\";\n\n/// @title The contract to be inherited to make Airnode RRP requests\ncontract RrpRequesterV0 {\n IAirnodeRrpV0 public immutable airnodeRrp;\n\n /// @dev Reverts if the caller is not the Airnode RRP contract.\n /// Use it as a modifier for fulfill and error callback methods, but also\n /// check `requestId`.\n modifier onlyAirnodeRrp() {\n require(msg.sender == address(airnodeRrp), \"Caller not Airnode RRP\");\n _;\n }\n\n /// @dev Airnode RRP address is set at deployment and is immutable.\n /// RrpRequester is made its own sponsor by default. RrpRequester can also\n /// be sponsored by others and use these sponsorships while making\n /// requests, i.e., using this default sponsorship is optional.\n /// @param _airnodeRrp Airnode RRP contract address\n constructor(address _airnodeRrp) {\n airnodeRrp = IAirnodeRrpV0(_airnodeRrp);\n IAirnodeRrpV0(_airnodeRrp).setSponsorshipStatus(address(this), true);\n }\n}\n" }, "contracts/TheGameOfChance/Solmate/SafeTransferLib.sol": { "content": "// SPDX-License-Identifier: AGPL-3.0-only\r\npragma solidity >=0.8.0;\r\n\r\nimport {ERC20} from \"./ERC20.sol\";\r\n\r\n/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.\r\n/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)\r\n/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.\r\n/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.\r\nlibrary SafeTransferLib {\r\n /*//////////////////////////////////////////////////////////////\r\n ETH OPERATIONS\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n function safeTransferETH(address to, uint256 amount) internal {\r\n bool success;\r\n\r\n assembly {\r\n // Transfer the ETH and store if it succeeded or not.\r\n success := call(gas(), to, amount, 0, 0, 0, 0)\r\n }\r\n\r\n require(success, \"ETH_TRANSFER_FAILED\");\r\n }\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n ERC20 OPERATIONS\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n function safeTransferFrom(\r\n ERC20 token,\r\n address from,\r\n address to,\r\n uint256 amount\r\n ) internal {\r\n bool success;\r\n\r\n assembly {\r\n // Get a pointer to some free memory.\r\n let freeMemoryPointer := mload(0x40)\r\n\r\n // Write the abi-encoded calldata into memory, beginning with the function selector.\r\n mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)\r\n mstore(add(freeMemoryPointer, 4), from) // Append the \"from\" argument.\r\n mstore(add(freeMemoryPointer, 36), to) // Append the \"to\" argument.\r\n mstore(add(freeMemoryPointer, 68), amount) // Append the \"amount\" argument.\r\n\r\n success := and(\r\n // Set success to whether the call reverted, if not we check it either\r\n // returned exactly 1 (can't just be non-zero data), or had no return data.\r\n or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),\r\n // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.\r\n // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\r\n // Counterintuitively, this call must be positioned second to the or() call in the\r\n // surrounding and() call or else returndatasize() will be zero during the computation.\r\n call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)\r\n )\r\n }\r\n\r\n require(success, \"TRANSFER_FROM_FAILED\");\r\n }\r\n\r\n function safeTransfer(\r\n ERC20 token,\r\n address to,\r\n uint256 amount\r\n ) internal {\r\n bool success;\r\n\r\n assembly {\r\n // Get a pointer to some free memory.\r\n let freeMemoryPointer := mload(0x40)\r\n\r\n // Write the abi-encoded calldata into memory, beginning with the function selector.\r\n mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)\r\n mstore(add(freeMemoryPointer, 4), to) // Append the \"to\" argument.\r\n mstore(add(freeMemoryPointer, 36), amount) // Append the \"amount\" argument.\r\n\r\n success := and(\r\n // Set success to whether the call reverted, if not we check it either\r\n // returned exactly 1 (can't just be non-zero data), or had no return data.\r\n or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),\r\n // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.\r\n // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\r\n // Counterintuitively, this call must be positioned second to the or() call in the\r\n // surrounding and() call or else returndatasize() will be zero during the computation.\r\n call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)\r\n )\r\n }\r\n\r\n require(success, \"TRANSFER_FAILED\");\r\n }\r\n\r\n function safeApprove(\r\n ERC20 token,\r\n address to,\r\n uint256 amount\r\n ) internal {\r\n bool success;\r\n\r\n assembly {\r\n // Get a pointer to some free memory.\r\n let freeMemoryPointer := mload(0x40)\r\n\r\n // Write the abi-encoded calldata into memory, beginning with the function selector.\r\n mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)\r\n mstore(add(freeMemoryPointer, 4), to) // Append the \"to\" argument.\r\n mstore(add(freeMemoryPointer, 36), amount) // Append the \"amount\" argument.\r\n\r\n success := and(\r\n // Set success to whether the call reverted, if not we check it either\r\n // returned exactly 1 (can't just be non-zero data), or had no return data.\r\n or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),\r\n // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.\r\n // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\r\n // Counterintuitively, this call must be positioned second to the or() call in the\r\n // surrounding and() call or else returndatasize() will be zero during the computation.\r\n call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)\r\n )\r\n }\r\n\r\n require(success, \"APPROVE_FAILED\");\r\n }\r\n}" }, "contracts/TheGameOfChance/SudoSwap/ICurve.sol": { "content": "// SPDX-License-Identifier: AGPL-3.0\r\npragma solidity ^0.8.0;\r\n\r\nimport {CurveErrorCodes} from \"./CurveErrorCodes.sol\";\r\n\r\ninterface ICurve {\r\n /**\r\n @notice Validates if a delta value is valid for the curve. The criteria for\r\n validity can be different for each type of curve, for instance ExponentialCurve\r\n requires delta to be greater than 1.\r\n @param delta The delta value to be validated\r\n @return valid True if delta is valid, false otherwise\r\n */\r\n function validateDelta(uint128 delta) external pure returns (bool valid);\r\n\r\n /**\r\n @notice Validates if a new spot price is valid for the curve. Spot price is generally assumed to be the immediate sell price of 1 NFT to the pool, in units of the pool's paired token.\r\n @param newSpotPrice The new spot price to be set\r\n @return valid True if the new spot price is valid, false otherwise\r\n */\r\n function validateSpotPrice(uint128 newSpotPrice)\r\n external\r\n view\r\n returns (bool valid);\r\n\r\n /**\r\n @notice Given the current state of the pair and the trade, computes how much the user\r\n should pay to purchase an NFT from the pair, the new spot price, and other values.\r\n @param spotPrice The current selling spot price of the pair, in tokens\r\n @param delta The delta parameter of the pair, what it means depends on the curve\r\n @param numItems The number of NFTs the user is buying from the pair\r\n @param feeMultiplier Determines how much fee the LP takes from this trade, 18 decimals\r\n @param protocolFeeMultiplier Determines how much fee the protocol takes from this trade, 18 decimals\r\n @return error Any math calculation errors, only Error.OK means the returned values are valid\r\n @return newSpotPrice The updated selling spot price, in tokens\r\n @return newDelta The updated delta, used to parameterize the bonding curve\r\n @return inputValue The amount that the user should pay, in tokens\r\n @return protocolFee The amount of fee to send to the protocol, in tokens\r\n */\r\n function getBuyInfo(\r\n uint128 spotPrice,\r\n uint128 delta,\r\n uint256 numItems,\r\n uint256 feeMultiplier,\r\n uint256 protocolFeeMultiplier\r\n )\r\n external\r\n view\r\n returns (\r\n CurveErrorCodes.Error error,\r\n uint128 newSpotPrice,\r\n uint128 newDelta,\r\n uint256 inputValue,\r\n uint256 protocolFee\r\n );\r\n\r\n /**\r\n @notice Given the current state of the pair and the trade, computes how much the user\r\n should receive when selling NFTs to the pair, the new spot price, and other values.\r\n @param spotPrice The current selling spot price of the pair, in tokens\r\n @param delta The delta parameter of the pair, what it means depends on the curve\r\n @param numItems The number of NFTs the user is selling to the pair\r\n @param feeMultiplier Determines how much fee the LP takes from this trade, 18 decimals\r\n @param protocolFeeMultiplier Determines how much fee the protocol takes from this trade, 18 decimals\r\n @return error Any math calculation errors, only Error.OK means the returned values are valid\r\n @return newSpotPrice The updated selling spot price, in tokens\r\n @return newDelta The updated delta, used to parameterize the bonding curve\r\n @return outputValue The amount that the user should receive, in tokens\r\n @return protocolFee The amount of fee to send to the protocol, in tokens\r\n */\r\n function getSellInfo(\r\n uint128 spotPrice,\r\n uint128 delta,\r\n uint256 numItems,\r\n uint256 feeMultiplier,\r\n uint256 protocolFeeMultiplier\r\n )\r\n external\r\n view\r\n returns (\r\n CurveErrorCodes.Error error,\r\n uint128 newSpotPrice,\r\n uint128 newDelta,\r\n uint256 outputValue,\r\n uint256 protocolFee\r\n );\r\n}" }, "contracts/TheGameOfChance/SudoSwap/ILSSVMPair.sol": { "content": "//SPDX-License-Identifier: Unlicense\r\npragma solidity 0.8.16;\r\n\r\ninterface ILSSVMPair {\r\n enum PoolType {\r\n TOKEN,\r\n NFT,\r\n TRADE\r\n }\r\n\r\n function withdrawAllETH() external;\r\n}" }, "contracts/TheGameOfChance/SudoSwap/ILSSVMPairFactory.sol": { "content": "//SPDX-License-Identifier: Unlicense\r\npragma solidity 0.8.16;\r\n\r\nimport \"../ERC721A/IERC721A.sol\";\r\nimport \"./ILSSVMPair.sol\";\r\nimport \"./ICurve.sol\";\r\n\r\ninterface ILSSVMPairFactory {\r\n /**\r\n @notice Creates a pair contract using EIP-1167.\r\n @param _nft The NFT contract of the collection the pair trades\r\n @param _bondingCurve The bonding curve for the pair to price NFTs, must be whitelisted\r\n @param _assetRecipient The address that will receive the assets traders give during trades.\r\n If set to address(0), assets will be sent to the pool address.\r\n Not available to TRADE pools. \r\n @param _poolType TOKEN, NFT, or TRADE\r\n @param _delta The delta value used by the bonding curve. The meaning of delta depends\r\n on the specific curve.\r\n @param _fee The fee taken by the LP in each trade. Can only be non-zero if _poolType is Trade.\r\n @param _spotPrice The initial selling spot price\r\n @param _initialNFTIDs The list of IDs of NFTs to transfer from the sender to the pair\r\n @return pair The new pair\r\n */\r\n function createPairETH(\r\n IERC721A _nft,\r\n ICurve _bondingCurve,\r\n address payable _assetRecipient,\r\n ILSSVMPair.PoolType _poolType,\r\n uint128 _delta,\r\n uint96 _fee,\r\n uint128 _spotPrice,\r\n uint256[] calldata _initialNFTIDs\r\n ) external payable returns (ILSSVMPair pair);\r\n}" }, "contracts/TheGameOfChance/ERC721A/ERC721A.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// ERC721A Contracts v4.2.2\r\n// Creator: Chiru Labs\r\n\r\npragma solidity ^0.8.4;\r\n\r\nimport './IERC721A.sol';\r\n\r\n/**\r\n * @dev Interface of ERC721 token receiver.\r\n */\r\ninterface ERC721A__IERC721Receiver {\r\n function onERC721Received(\r\n address operator,\r\n address from,\r\n uint256 tokenId,\r\n bytes calldata data\r\n ) external returns (bytes4);\r\n}\r\n\r\n/**\r\n * @title ERC721A\r\n *\r\n * @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)\r\n * Non-Fungible Token Standard, including the Metadata extension.\r\n * Optimized for lower gas during batch mints.\r\n *\r\n * Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)\r\n * starting from `_startTokenId()`.\r\n *\r\n * Assumptions:\r\n *\r\n * - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.\r\n * - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).\r\n */\r\ncontract ERC721A is IERC721A {\r\n // Reference type for token approval.\r\n struct TokenApprovalRef {\r\n address value;\r\n }\r\n\r\n // =============================================================\r\n // CONSTANTS\r\n // =============================================================\r\n\r\n // Mask of an entry in packed address data.\r\n uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;\r\n\r\n // The bit position of `numberMinted` in packed address data.\r\n uint256 private constant _BITPOS_NUMBER_MINTED = 64;\r\n\r\n // The bit position of `numberBurned` in packed address data.\r\n uint256 private constant _BITPOS_NUMBER_BURNED = 128;\r\n\r\n // The bit position of `aux` in packed address data.\r\n uint256 private constant _BITPOS_AUX = 192;\r\n\r\n // Mask of all 256 bits in packed address data except the 64 bits for `aux`.\r\n uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;\r\n\r\n // The bit position of `startTimestamp` in packed ownership.\r\n uint256 private constant _BITPOS_START_TIMESTAMP = 160;\r\n\r\n // The bit mask of the `burned` bit in packed ownership.\r\n uint256 private constant _BITMASK_BURNED = 1 << 224;\r\n\r\n // The bit position of the `nextInitialized` bit in packed ownership.\r\n uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;\r\n\r\n // The bit mask of the `nextInitialized` bit in packed ownership.\r\n uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;\r\n\r\n // The bit position of `extraData` in packed ownership.\r\n uint256 private constant _BITPOS_EXTRA_DATA = 232;\r\n\r\n // Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.\r\n uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;\r\n\r\n // The mask of the lower 160 bits for addresses.\r\n uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;\r\n\r\n // The maximum `quantity` that can be minted with {_mintERC2309}.\r\n // This limit is to prevent overflows on the address data entries.\r\n // For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}\r\n // is required to cause an overflow, which is unrealistic.\r\n uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;\r\n\r\n // The `Transfer` event signature is given by:\r\n // `keccak256(bytes(\"Transfer(address,address,uint256)\"))`.\r\n bytes32 private constant _TRANSFER_EVENT_SIGNATURE =\r\n 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;\r\n\r\n // =============================================================\r\n // STORAGE\r\n // =============================================================\r\n\r\n // The next token ID to be minted.\r\n uint256 private _currentIndex;\r\n\r\n // The number of tokens burned.\r\n uint256 private _burnCounter;\r\n\r\n // Token name\r\n string private _name;\r\n\r\n // Token symbol\r\n string private _symbol;\r\n\r\n // Mapping from token ID to ownership details\r\n // An empty struct value does not necessarily mean the token is unowned.\r\n // See {_packedOwnershipOf} implementation for details.\r\n //\r\n // Bits Layout:\r\n // - [0..159] `addr`\r\n // - [160..223] `startTimestamp`\r\n // - [224] `burned`\r\n // - [225] `nextInitialized`\r\n // - [232..255] `extraData`\r\n mapping(uint256 => uint256) private _packedOwnerships;\r\n\r\n // Mapping owner address to address data.\r\n //\r\n // Bits Layout:\r\n // - [0..63] `balance`\r\n // - [64..127] `numberMinted`\r\n // - [128..191] `numberBurned`\r\n // - [192..255] `aux`\r\n mapping(address => uint256) private _packedAddressData;\r\n\r\n // Mapping from token ID to approved address.\r\n mapping(uint256 => TokenApprovalRef) private _tokenApprovals;\r\n\r\n // Mapping from owner to operator approvals\r\n mapping(address => mapping(address => bool)) private _operatorApprovals;\r\n\r\n // =============================================================\r\n // CONSTRUCTOR\r\n // =============================================================\r\n\r\n constructor(string memory name_, string memory symbol_) {\r\n _name = name_;\r\n _symbol = symbol_;\r\n _currentIndex = _startTokenId();\r\n }\r\n\r\n // =============================================================\r\n // TOKEN COUNTING OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the starting token ID.\r\n * To change the starting token ID, please override this function.\r\n */\r\n function _startTokenId() internal view virtual returns (uint256) {\r\n return 0;\r\n }\r\n\r\n /**\r\n * @dev Returns the next token ID to be minted.\r\n */\r\n function _nextTokenId() internal view virtual returns (uint256) {\r\n return _currentIndex;\r\n }\r\n\r\n /**\r\n * @dev Returns the total number of tokens in existence.\r\n * Burned tokens will reduce the count.\r\n * To get the total number of tokens minted, please see {_totalMinted}.\r\n */\r\n function totalSupply() public view virtual override returns (uint256) {\r\n // Counter underflow is impossible as _burnCounter cannot be incremented\r\n // more than `_currentIndex - _startTokenId()` times.\r\n unchecked {\r\n return _currentIndex - _burnCounter - _startTokenId();\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the total amount of tokens minted in the contract.\r\n */\r\n function _totalMinted() internal view virtual returns (uint256) {\r\n // Counter underflow is impossible as `_currentIndex` does not decrement,\r\n // and it is initialized to `_startTokenId()`.\r\n unchecked {\r\n return _currentIndex - _startTokenId();\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the total number of tokens burned.\r\n */\r\n function _totalBurned() internal view virtual returns (uint256) {\r\n return _burnCounter;\r\n }\r\n\r\n // =============================================================\r\n // ADDRESS DATA OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the number of tokens in `owner`'s account.\r\n */\r\n function balanceOfOriginal(address owner) public view virtual returns (uint256) {\r\n if (owner == address(0)) revert BalanceQueryForZeroAddress();\r\n return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;\r\n }\r\n\r\n function balanceOf(address owner) public view virtual override returns (uint256) {}\r\n\r\n /**\r\n * Returns the number of tokens minted by `owner`.\r\n */\r\n function _numberMinted(address owner) internal view returns (uint256) {\r\n return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;\r\n }\r\n\r\n /**\r\n * Returns the number of tokens burned by or on behalf of `owner`.\r\n */\r\n function _numberBurned(address owner) internal view returns (uint256) {\r\n return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;\r\n }\r\n\r\n /**\r\n * Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\r\n */\r\n function _getAux(address owner) internal view returns (uint64) {\r\n return uint64(_packedAddressData[owner] >> _BITPOS_AUX);\r\n }\r\n\r\n /**\r\n * Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\r\n * If there are multiple variables, please pack them into a uint64.\r\n */\r\n function _setAux(address owner, uint64 aux) internal virtual {\r\n uint256 packed = _packedAddressData[owner];\r\n uint256 auxCasted;\r\n // Cast `aux` with assembly to avoid redundant masking.\r\n assembly {\r\n auxCasted := aux\r\n }\r\n packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);\r\n _packedAddressData[owner] = packed;\r\n }\r\n\r\n // =============================================================\r\n // IERC165\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns true if this contract implements the interface defined by\r\n * `interfaceId`. See the corresponding\r\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\r\n * to learn more about how these ids are created.\r\n *\r\n * This function call must use less than 30000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\r\n // The interface IDs are constants representing the first 4 bytes\r\n // of the XOR of all function selectors in the interface.\r\n // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)\r\n // (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)\r\n return\r\n interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.\r\n interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.\r\n interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.\r\n }\r\n\r\n // =============================================================\r\n // IERC721Metadata\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the token collection name.\r\n */\r\n function name() public view virtual override returns (string memory) {\r\n return _name;\r\n }\r\n\r\n /**\r\n * @dev Returns the token collection symbol.\r\n */\r\n function symbol() public view virtual override returns (string memory) {\r\n return _symbol;\r\n }\r\n\r\n /**\r\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r\n */\r\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\r\n if (!_exists(tokenId)) revert URIQueryForNonexistentToken();\r\n\r\n string memory baseURI = _baseURI();\r\n return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';\r\n }\r\n\r\n /**\r\n * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\r\n * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\r\n * by default, it can be overridden in child contracts.\r\n */\r\n function _baseURI() internal view virtual returns (string memory) {\r\n return '';\r\n }\r\n\r\n // =============================================================\r\n // OWNERSHIPS OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the owner of the `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\r\n return address(uint160(_packedOwnershipOf(tokenId)));\r\n }\r\n\r\n /**\r\n * @dev Gas spent here starts off proportional to the maximum mint batch size.\r\n * It gradually moves to O(1) as tokens get transferred around over time.\r\n */\r\n function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {\r\n return _unpackedOwnership(_packedOwnershipOf(tokenId));\r\n }\r\n\r\n /**\r\n * @dev Returns the unpacked `TokenOwnership` struct at `index`.\r\n */\r\n function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {\r\n return _unpackedOwnership(_packedOwnerships[index]);\r\n }\r\n\r\n /**\r\n * @dev Initializes the ownership slot minted at `index` for efficiency purposes.\r\n */\r\n function _initializeOwnershipAt(uint256 index) internal virtual {\r\n if (_packedOwnerships[index] == 0) {\r\n _packedOwnerships[index] = _packedOwnershipOf(index);\r\n }\r\n }\r\n\r\n /**\r\n * Returns the packed ownership data of `tokenId`.\r\n */\r\n function _packedOwnershipOf(uint256 tokenId) private view returns (uint256) {\r\n uint256 curr = tokenId;\r\n\r\n unchecked {\r\n if (_startTokenId() <= curr)\r\n if (curr < _currentIndex) {\r\n uint256 packed = _packedOwnerships[curr];\r\n // If not burned.\r\n if (packed & _BITMASK_BURNED == 0) {\r\n // Invariant:\r\n // There will always be an initialized ownership slot\r\n // (i.e. `ownership.addr != address(0) && ownership.burned == false`)\r\n // before an unintialized ownership slot\r\n // (i.e. `ownership.addr == address(0) && ownership.burned == false`)\r\n // Hence, `curr` will not underflow.\r\n //\r\n // We can directly compare the packed value.\r\n // If the address is zero, packed will be zero.\r\n while (packed == 0) {\r\n packed = _packedOwnerships[--curr];\r\n }\r\n return packed;\r\n }\r\n }\r\n }\r\n revert OwnerQueryForNonexistentToken();\r\n }\r\n\r\n /**\r\n * @dev Returns the unpacked `TokenOwnership` struct from `packed`.\r\n */\r\n function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {\r\n ownership.addr = address(uint160(packed));\r\n ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);\r\n ownership.burned = packed & _BITMASK_BURNED != 0;\r\n ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);\r\n }\r\n\r\n /**\r\n * @dev Packs ownership data into a single uint256.\r\n */\r\n function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {\r\n assembly {\r\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n owner := and(owner, _BITMASK_ADDRESS)\r\n // `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.\r\n result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the `nextInitialized` flag set if `quantity` equals 1.\r\n */\r\n function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {\r\n // For branchless setting of the `nextInitialized` flag.\r\n assembly {\r\n // `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.\r\n result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))\r\n }\r\n }\r\n\r\n // =============================================================\r\n // APPROVAL OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\r\n * The approval is cleared when the token is transferred.\r\n *\r\n * Only a single account can be approved at a time, so approving the\r\n * zero address clears previous approvals.\r\n *\r\n * Requirements:\r\n *\r\n * - The caller must own the token or be an approved operator.\r\n * - `tokenId` must exist.\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address to, uint256 tokenId) public virtual override {\r\n address owner = ownerOf(tokenId);\r\n\r\n if (_msgSenderERC721A() != owner)\r\n if (!isApprovedForAll(owner, _msgSenderERC721A())) {\r\n revert ApprovalCallerNotOwnerNorApproved();\r\n }\r\n\r\n _tokenApprovals[tokenId].value = to;\r\n emit Approval(owner, to, tokenId);\r\n }\r\n\r\n /**\r\n * @dev Returns the account approved for `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function getApproved(uint256 tokenId) public view virtual override returns (address) {\r\n if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();\r\n\r\n return _tokenApprovals[tokenId].value;\r\n }\r\n\r\n /**\r\n * @dev Approve or remove `operator` as an operator for the caller.\r\n * Operators can call {transferFrom} or {safeTransferFrom}\r\n * for any token owned by the caller.\r\n *\r\n * Requirements:\r\n *\r\n * - The `operator` cannot be the caller.\r\n *\r\n * Emits an {ApprovalForAll} event.\r\n */\r\n function setApprovalForAll(address operator, bool approved) public virtual override {\r\n _operatorApprovals[_msgSenderERC721A()][operator] = approved;\r\n emit ApprovalForAll(_msgSenderERC721A(), operator, approved);\r\n }\r\n\r\n /**\r\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r\n *\r\n * See {setApprovalForAll}.\r\n */\r\n function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\r\n return _operatorApprovals[owner][operator];\r\n }\r\n\r\n /**\r\n * @dev Returns whether `tokenId` exists.\r\n *\r\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\r\n *\r\n * Tokens start existing when they are minted. See {_mint}.\r\n */\r\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\r\n return\r\n _startTokenId() <= tokenId &&\r\n tokenId < _currentIndex && // If within bounds,\r\n _packedOwnerships[tokenId] & _BITMASK_BURNED == 0; // and not burned.\r\n }\r\n\r\n /**\r\n * @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.\r\n */\r\n function _isSenderApprovedOrOwner(\r\n address approvedAddress,\r\n address owner,\r\n address msgSender\r\n ) private pure returns (bool result) {\r\n assembly {\r\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n owner := and(owner, _BITMASK_ADDRESS)\r\n // Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n msgSender := and(msgSender, _BITMASK_ADDRESS)\r\n // `msgSender == owner || msgSender == approvedAddress`.\r\n result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the storage slot and value for the approved address of `tokenId`.\r\n */\r\n function _getApprovedSlotAndAddress(uint256 tokenId)\r\n private\r\n view\r\n returns (uint256 approvedAddressSlot, address approvedAddress)\r\n {\r\n TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];\r\n // The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.\r\n assembly {\r\n approvedAddressSlot := tokenApproval.slot\r\n approvedAddress := sload(approvedAddressSlot)\r\n }\r\n }\r\n\r\n // =============================================================\r\n // TRANSFER OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Transfers `tokenId` from `from` to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token\r\n * by either {approve} or {setApprovalForAll}.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) public virtual override {\r\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\r\n\r\n if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner();\r\n\r\n (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\r\n\r\n // The nested ifs save around 20+ gas over a compound boolean condition.\r\n if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\r\n if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();\r\n\r\n if (to == address(0)) revert TransferToZeroAddress();\r\n\r\n _beforeTokenTransfers(from, to, tokenId, 1);\r\n\r\n // Clear approvals from the previous owner.\r\n assembly {\r\n if approvedAddress {\r\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\r\n sstore(approvedAddressSlot, 0)\r\n }\r\n }\r\n\r\n // Underflow of the sender's balance is impossible because we check for\r\n // ownership above and the recipient's balance can't realistically overflow.\r\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\r\n unchecked {\r\n // We can directly increment and decrement the balances.\r\n --_packedAddressData[from]; // Updates: `balance -= 1`.\r\n ++_packedAddressData[to]; // Updates: `balance += 1`.\r\n\r\n // Updates:\r\n // - `address` to the next owner.\r\n // - `startTimestamp` to the timestamp of transfering.\r\n // - `burned` to `false`.\r\n // - `nextInitialized` to `true`.\r\n _packedOwnerships[tokenId] = _packOwnershipData(\r\n to,\r\n _BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)\r\n );\r\n\r\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\r\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\r\n uint256 nextTokenId = tokenId + 1;\r\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\r\n if (_packedOwnerships[nextTokenId] == 0) {\r\n // If the next slot is within bounds.\r\n if (nextTokenId != _currentIndex) {\r\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\r\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\r\n }\r\n }\r\n }\r\n }\r\n\r\n emit Transfer(from, to, tokenId);\r\n _afterTokenTransfers(from, to, tokenId, 1);\r\n }\r\n\r\n /**\r\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) public virtual override {\r\n safeTransferFrom(from, to, tokenId, '');\r\n }\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token\r\n * by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement\r\n * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId,\r\n bytes memory _data\r\n ) public virtual override {\r\n transferFrom(from, to, tokenId);\r\n if (to.code.length != 0)\r\n if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {\r\n revert TransferToNonERC721ReceiverImplementer();\r\n }\r\n }\r\n\r\n /**\r\n * @dev Hook that is called before a set of serially-ordered token IDs\r\n * are about to be transferred. This includes minting.\r\n * And also called before burning one token.\r\n *\r\n * `startTokenId` - the first token ID to be transferred.\r\n * `quantity` - the amount to be transferred.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` will be minted for `to`.\r\n * - When `to` is zero, `tokenId` will be burned by `from`.\r\n * - `from` and `to` are never both zero.\r\n */\r\n function _beforeTokenTransfers(\r\n address from,\r\n address to,\r\n uint256 startTokenId,\r\n uint256 quantity\r\n ) internal virtual {}\r\n\r\n /**\r\n * @dev Hook that is called after a set of serially-ordered token IDs\r\n * have been transferred. This includes minting.\r\n * And also called after one token has been burned.\r\n *\r\n * `startTokenId` - the first token ID to be transferred.\r\n * `quantity` - the amount to be transferred.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` has been minted for `to`.\r\n * - When `to` is zero, `tokenId` has been burned by `from`.\r\n * - `from` and `to` are never both zero.\r\n */\r\n function _afterTokenTransfers(\r\n address from,\r\n address to,\r\n uint256 startTokenId,\r\n uint256 quantity\r\n ) internal virtual {}\r\n\r\n /**\r\n * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.\r\n *\r\n * `from` - Previous owner of the given token ID.\r\n * `to` - Target address that will receive the token.\r\n * `tokenId` - Token ID to be transferred.\r\n * `_data` - Optional data to send along with the call.\r\n *\r\n * Returns whether the call correctly returned the expected magic value.\r\n */\r\n function _checkContractOnERC721Received(\r\n address from,\r\n address to,\r\n uint256 tokenId,\r\n bytes memory _data\r\n ) private returns (bool) {\r\n try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (\r\n bytes4 retval\r\n ) {\r\n return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;\r\n } catch (bytes memory reason) {\r\n if (reason.length == 0) {\r\n revert TransferToNonERC721ReceiverImplementer();\r\n } else {\r\n assembly {\r\n revert(add(32, reason), mload(reason))\r\n }\r\n }\r\n }\r\n }\r\n\r\n // =============================================================\r\n // MINT OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Mints `quantity` tokens and transfers them to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - `to` cannot be the zero address.\r\n * - `quantity` must be greater than 0.\r\n *\r\n * Emits a {Transfer} event for each mint.\r\n */\r\n function _mint(address to, uint256 quantity) internal virtual {\r\n uint256 startTokenId = _currentIndex;\r\n if (quantity == 0) revert MintZeroQuantity();\r\n\r\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\r\n\r\n // Overflows are incredibly unrealistic.\r\n // `balance` and `numberMinted` have a maximum limit of 2**64.\r\n // `tokenId` has a maximum limit of 2**256.\r\n unchecked {\r\n // Updates:\r\n // - `balance += quantity`.\r\n // - `numberMinted += quantity`.\r\n //\r\n // We can directly add to the `balance` and `numberMinted`.\r\n _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\r\n\r\n // Updates:\r\n // - `address` to the owner.\r\n // - `startTimestamp` to the timestamp of minting.\r\n // - `burned` to `false`.\r\n // - `nextInitialized` to `quantity == 1`.\r\n _packedOwnerships[startTokenId] = _packOwnershipData(\r\n to,\r\n _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\r\n );\r\n\r\n uint256 toMasked;\r\n uint256 end = startTokenId + quantity;\r\n\r\n // Use assembly to loop and emit the `Transfer` event for gas savings.\r\n // The duplicated `log4` removes an extra check and reduces stack juggling.\r\n // The assembly, together with the surrounding Solidity code, have been\r\n // delicately arranged to nudge the compiler into producing optimized opcodes.\r\n assembly {\r\n // Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.\r\n toMasked := and(to, _BITMASK_ADDRESS)\r\n // Emit the `Transfer` event.\r\n log4(\r\n 0, // Start of data (0, since no data).\r\n 0, // End of data (0, since no data).\r\n _TRANSFER_EVENT_SIGNATURE, // Signature.\r\n 0, // `address(0)`.\r\n toMasked, // `to`.\r\n startTokenId // `tokenId`.\r\n )\r\n\r\n for {\r\n let tokenId := add(startTokenId, 1)\r\n } iszero(eq(tokenId, end)) {\r\n tokenId := add(tokenId, 1)\r\n } {\r\n // Emit the `Transfer` event. Similar to above.\r\n log4(0, 0, _TRANSFER_EVENT_SIGNATURE, 0, toMasked, tokenId)\r\n }\r\n }\r\n if (toMasked == 0) revert MintToZeroAddress();\r\n\r\n _currentIndex = end;\r\n }\r\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\r\n }\r\n\r\n /**\r\n * @dev Mints `quantity` tokens and transfers them to `to`.\r\n *\r\n * This function is intended for efficient minting only during contract creation.\r\n *\r\n * It emits only one {ConsecutiveTransfer} as defined in\r\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),\r\n * instead of a sequence of {Transfer} event(s).\r\n *\r\n * Calling this function outside of contract creation WILL make your contract\r\n * non-compliant with the ERC721 standard.\r\n * For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309\r\n * {ConsecutiveTransfer} event is only permissible during contract creation.\r\n *\r\n * Requirements:\r\n *\r\n * - `to` cannot be the zero address.\r\n * - `quantity` must be greater than 0.\r\n *\r\n * Emits a {ConsecutiveTransfer} event.\r\n */\r\n function _mintERC2309(address to, uint256 quantity) internal virtual {\r\n uint256 startTokenId = _currentIndex;\r\n if (to == address(0)) revert MintToZeroAddress();\r\n if (quantity == 0) revert MintZeroQuantity();\r\n if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit();\r\n\r\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\r\n\r\n // Overflows are unrealistic due to the above check for `quantity` to be below the limit.\r\n unchecked {\r\n // Updates:\r\n // - `balance += quantity`.\r\n // - `numberMinted += quantity`.\r\n //\r\n // We can directly add to the `balance` and `numberMinted`.\r\n _packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\r\n\r\n // Updates:\r\n // - `address` to the owner.\r\n // - `startTimestamp` to the timestamp of minting.\r\n // - `burned` to `false`.\r\n // - `nextInitialized` to `quantity == 1`.\r\n _packedOwnerships[startTokenId] = _packOwnershipData(\r\n to,\r\n _nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\r\n );\r\n\r\n emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);\r\n\r\n _currentIndex = startTokenId + quantity;\r\n }\r\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\r\n }\r\n\r\n /**\r\n * @dev Safely mints `quantity` tokens and transfers them to `to`.\r\n *\r\n * Requirements:\r\n *\r\n * - If `to` refers to a smart contract, it must implement\r\n * {IERC721Receiver-onERC721Received}, which is called for each safe transfer.\r\n * - `quantity` must be greater than 0.\r\n *\r\n * See {_mint}.\r\n *\r\n * Emits a {Transfer} event for each mint.\r\n */\r\n function _safeMint(\r\n address to,\r\n uint256 quantity,\r\n bytes memory _data\r\n ) internal virtual {\r\n _mint(to, quantity);\r\n\r\n unchecked {\r\n if (to.code.length != 0) {\r\n uint256 end = _currentIndex;\r\n uint256 index = end - quantity;\r\n do {\r\n if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {\r\n revert TransferToNonERC721ReceiverImplementer();\r\n }\r\n } while (index < end);\r\n // Reentrancy protection.\r\n if (_currentIndex != end) revert();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @dev Equivalent to `_safeMint(to, quantity, '')`.\r\n */\r\n function _safeMint(address to, uint256 quantity) internal virtual {\r\n _safeMint(to, quantity, '');\r\n }\r\n\r\n // =============================================================\r\n // BURN OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Equivalent to `_burn(tokenId, false)`.\r\n */\r\n function _burn(uint256 tokenId) internal virtual {\r\n _burn(tokenId, false);\r\n }\r\n\r\n /**\r\n * @dev Destroys `tokenId`.\r\n * The approval is cleared when the token is burned.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function _burn(uint256 tokenId, bool approvalCheck) internal virtual {\r\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\r\n\r\n address from = address(uint160(prevOwnershipPacked));\r\n\r\n (uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\r\n\r\n if (approvalCheck) {\r\n // The nested ifs save around 20+ gas over a compound boolean condition.\r\n if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\r\n if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();\r\n }\r\n\r\n _beforeTokenTransfers(from, address(0), tokenId, 1);\r\n\r\n // Clear approvals from the previous owner.\r\n assembly {\r\n if approvedAddress {\r\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\r\n sstore(approvedAddressSlot, 0)\r\n }\r\n }\r\n\r\n // Underflow of the sender's balance is impossible because we check for\r\n // ownership above and the recipient's balance can't realistically overflow.\r\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\r\n unchecked {\r\n // Updates:\r\n // - `balance -= 1`.\r\n // - `numberBurned += 1`.\r\n //\r\n // We can directly decrement the balance, and increment the number burned.\r\n // This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.\r\n _packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;\r\n\r\n // Updates:\r\n // - `address` to the last owner.\r\n // - `startTimestamp` to the timestamp of burning.\r\n // - `burned` to `true`.\r\n // - `nextInitialized` to `true`.\r\n _packedOwnerships[tokenId] = _packOwnershipData(\r\n from,\r\n (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)\r\n );\r\n\r\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\r\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\r\n uint256 nextTokenId = tokenId + 1;\r\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\r\n if (_packedOwnerships[nextTokenId] == 0) {\r\n // If the next slot is within bounds.\r\n if (nextTokenId != _currentIndex) {\r\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\r\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\r\n }\r\n }\r\n }\r\n }\r\n\r\n emit Transfer(from, address(0), tokenId);\r\n _afterTokenTransfers(from, address(0), tokenId, 1);\r\n\r\n // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.\r\n unchecked {\r\n _burnCounter++;\r\n }\r\n }\r\n\r\n // =============================================================\r\n // EXTRA DATA OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Directly sets the extra data for the ownership data `index`.\r\n */\r\n function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {\r\n uint256 packed = _packedOwnerships[index];\r\n if (packed == 0) revert OwnershipNotInitializedForExtraData();\r\n uint256 extraDataCasted;\r\n // Cast `extraData` with assembly to avoid redundant masking.\r\n assembly {\r\n extraDataCasted := extraData\r\n }\r\n packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);\r\n _packedOwnerships[index] = packed;\r\n }\r\n\r\n /**\r\n * @dev Called during each token transfer to set the 24bit `extraData` field.\r\n * Intended to be overridden by the cosumer contract.\r\n *\r\n * `previousExtraData` - the value of `extraData` before transfer.\r\n *\r\n * Calling conditions:\r\n *\r\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\r\n * transferred to `to`.\r\n * - When `from` is zero, `tokenId` will be minted for `to`.\r\n * - When `to` is zero, `tokenId` will be burned by `from`.\r\n * - `from` and `to` are never both zero.\r\n */\r\n function _extraData(\r\n address from,\r\n address to,\r\n uint24 previousExtraData\r\n ) internal view virtual returns (uint24) {}\r\n\r\n /**\r\n * @dev Returns the next extra data for the packed ownership data.\r\n * The returned result is shifted into position.\r\n */\r\n function _nextExtraData(\r\n address from,\r\n address to,\r\n uint256 prevOwnershipPacked\r\n ) private view returns (uint256) {\r\n uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);\r\n return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;\r\n }\r\n\r\n // =============================================================\r\n // OTHER OPERATIONS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the message sender (defaults to `msg.sender`).\r\n *\r\n * If you are writing GSN compatible contracts, you need to override this function.\r\n */\r\n function _msgSenderERC721A() internal view virtual returns (address) {\r\n return msg.sender;\r\n }\r\n\r\n /**\r\n * @dev Converts a uint256 to its ASCII string decimal representation.\r\n */\r\n function _toString(uint256 value) internal pure virtual returns (string memory str) {\r\n assembly {\r\n // The maximum value of a uint256 contains 78 digits (1 byte per digit),\r\n // but we allocate 0x80 bytes to keep the free memory pointer 32-byte word aligned.\r\n // We will need 1 32-byte word to store the length,\r\n // and 3 32-byte words to store a maximum of 78 digits. Total: 0x20 + 3 * 0x20 = 0x80.\r\n str := add(mload(0x40), 0x80)\r\n // Update the free memory pointer to allocate.\r\n mstore(0x40, str)\r\n\r\n // Cache the end of the memory to calculate the length later.\r\n let end := str\r\n\r\n // We write the string from rightmost digit to leftmost digit.\r\n // The following is essentially a do-while loop that also handles the zero case.\r\n // prettier-ignore\r\n for { let temp := value } 1 {} {\r\n str := sub(str, 1)\r\n // Write the character to the pointer.\r\n // The ASCII index of the '0' character is 48.\r\n mstore8(str, add(48, mod(temp, 10)))\r\n // Keep dividing `temp` until zero.\r\n temp := div(temp, 10)\r\n // prettier-ignore\r\n if iszero(temp) { break }\r\n }\r\n\r\n let length := sub(end, str)\r\n // Move the pointer 32 bytes leftwards to make room for the length.\r\n str := sub(str, 0x20)\r\n // Store the length.\r\n mstore(str, length)\r\n }\r\n }\r\n}" }, "contracts/TheGameOfChance/ERC721A/IERC721A.sol": { "content": "// SPDX-License-Identifier: MIT\r\n// ERC721A Contracts v4.2.2\r\n// Creator: Chiru Labs\r\n\r\npragma solidity ^0.8.4;\r\n\r\n/**\r\n * @dev Interface of ERC721A.\r\n */\r\ninterface IERC721A {\r\n /**\r\n * The caller must own the token or be an approved operator.\r\n */\r\n error ApprovalCallerNotOwnerNorApproved();\r\n\r\n /**\r\n * The token does not exist.\r\n */\r\n error ApprovalQueryForNonexistentToken();\r\n\r\n /**\r\n * Cannot query the balance for the zero address.\r\n */\r\n error BalanceQueryForZeroAddress();\r\n\r\n /**\r\n * Cannot mint to the zero address.\r\n */\r\n error MintToZeroAddress();\r\n\r\n /**\r\n * The quantity of tokens minted must be more than zero.\r\n */\r\n error MintZeroQuantity();\r\n\r\n /**\r\n * The token does not exist.\r\n */\r\n error OwnerQueryForNonexistentToken();\r\n\r\n /**\r\n * The caller must own the token or be an approved operator.\r\n */\r\n error TransferCallerNotOwnerNorApproved();\r\n\r\n /**\r\n * The token must be owned by `from`.\r\n */\r\n error TransferFromIncorrectOwner();\r\n\r\n /**\r\n * Cannot safely transfer to a contract that does not implement the\r\n * ERC721Receiver interface.\r\n */\r\n error TransferToNonERC721ReceiverImplementer();\r\n\r\n /**\r\n * Cannot transfer to the zero address.\r\n */\r\n error TransferToZeroAddress();\r\n\r\n /**\r\n * The token does not exist.\r\n */\r\n error URIQueryForNonexistentToken();\r\n\r\n /**\r\n * The `quantity` minted with ERC2309 exceeds the safety limit.\r\n */\r\n error MintERC2309QuantityExceedsLimit();\r\n\r\n /**\r\n * The `extraData` cannot be set on an unintialized ownership slot.\r\n */\r\n error OwnershipNotInitializedForExtraData();\r\n\r\n // =============================================================\r\n // STRUCTS\r\n // =============================================================\r\n\r\n struct TokenOwnership {\r\n // The address of the owner.\r\n address addr;\r\n // Stores the start time of ownership with minimal overhead for tokenomics.\r\n uint64 startTimestamp;\r\n // Whether the token has been burned.\r\n bool burned;\r\n // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.\r\n uint24 extraData;\r\n }\r\n\r\n // =============================================================\r\n // TOKEN COUNTERS\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the total number of tokens in existence.\r\n * Burned tokens will reduce the count.\r\n * To get the total number of tokens minted, please see {_totalMinted}.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n // =============================================================\r\n // IERC165\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns true if this contract implements the interface defined by\r\n * `interfaceId`. See the corresponding\r\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\r\n * to learn more about how these ids are created.\r\n *\r\n * This function call must use less than 30000 gas.\r\n */\r\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\r\n\r\n // =============================================================\r\n // IERC721\r\n // =============================================================\r\n\r\n /**\r\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\r\n */\r\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\r\n */\r\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\r\n\r\n /**\r\n * @dev Emitted when `owner` enables or disables\r\n * (`approved`) `operator` to manage all of its assets.\r\n */\r\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\r\n\r\n /**\r\n * @dev Returns the number of tokens in `owner`'s account.\r\n */\r\n function balanceOf(address owner) external view returns (uint256 balance);\r\n\r\n /**\r\n * @dev Returns the owner of the `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function ownerOf(uint256 tokenId) external view returns (address owner);\r\n\r\n /**\r\n * @dev Safely transfers `tokenId` token from `from` to `to`,\r\n * checking first that contract recipients are aware of the ERC721 protocol\r\n * to prevent tokens from being forever locked.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must exist and be owned by `from`.\r\n * - If the caller is not `from`, it must be have been allowed to move\r\n * this token by either {approve} or {setApprovalForAll}.\r\n * - If `to` refers to a smart contract, it must implement\r\n * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId,\r\n bytes calldata data\r\n ) external;\r\n\r\n /**\r\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\r\n */\r\n function safeTransferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) external;\r\n\r\n /**\r\n * @dev Transfers `tokenId` from `from` to `to`.\r\n *\r\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom}\r\n * whenever possible.\r\n *\r\n * Requirements:\r\n *\r\n * - `from` cannot be the zero address.\r\n * - `to` cannot be the zero address.\r\n * - `tokenId` token must be owned by `from`.\r\n * - If the caller is not `from`, it must be approved to move this token\r\n * by either {approve} or {setApprovalForAll}.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 tokenId\r\n ) external;\r\n\r\n /**\r\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\r\n * The approval is cleared when the token is transferred.\r\n *\r\n * Only a single account can be approved at a time, so approving the\r\n * zero address clears previous approvals.\r\n *\r\n * Requirements:\r\n *\r\n * - The caller must own the token or be an approved operator.\r\n * - `tokenId` must exist.\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address to, uint256 tokenId) external;\r\n\r\n /**\r\n * @dev Approve or remove `operator` as an operator for the caller.\r\n * Operators can call {transferFrom} or {safeTransferFrom}\r\n * for any token owned by the caller.\r\n *\r\n * Requirements:\r\n *\r\n * - The `operator` cannot be the caller.\r\n *\r\n * Emits an {ApprovalForAll} event.\r\n */\r\n function setApprovalForAll(address operator, bool _approved) external;\r\n\r\n /**\r\n * @dev Returns the account approved for `tokenId` token.\r\n *\r\n * Requirements:\r\n *\r\n * - `tokenId` must exist.\r\n */\r\n function getApproved(uint256 tokenId) external view returns (address operator);\r\n\r\n /**\r\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r\n *\r\n * See {setApprovalForAll}.\r\n */\r\n function isApprovedForAll(address owner, address operator) external view returns (bool);\r\n\r\n // =============================================================\r\n // IERC721Metadata\r\n // =============================================================\r\n\r\n /**\r\n * @dev Returns the token collection name.\r\n */\r\n function name() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the token collection symbol.\r\n */\r\n function symbol() external view returns (string memory);\r\n\r\n /**\r\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r\n */\r\n function tokenURI(uint256 tokenId) external view returns (string memory);\r\n\r\n // =============================================================\r\n // IERC2309\r\n // =============================================================\r\n\r\n /**\r\n * @dev Emitted when tokens in `fromTokenId` to `toTokenId`\r\n * (inclusive) is transferred from `from` to `to`, as defined in the\r\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.\r\n *\r\n * See {_mintERC2309} for more details.\r\n */\r\n event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);\r\n}" }, "contracts/TheGameOfChance/SudoSwap/CurveErrorCodes.sol": { "content": "// SPDX-License-Identifier: AGPL-3.0\r\npragma solidity ^0.8.0;\r\n\r\ncontract CurveErrorCodes {\r\n enum Error {\r\n OK, // No error\r\n INVALID_NUMITEMS, // The numItem value is 0\r\n SPOT_PRICE_OVERFLOW // The updated spot price doesn't fit into 128 bits\r\n }\r\n}" }, "contracts/TheGameOfChance/Solmate/ERC20.sol": { "content": "// SPDX-License-Identifier: AGPL-3.0-only\r\npragma solidity >=0.8.0;\r\n\r\n/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.\r\n/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)\r\n/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)\r\n/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.\r\nabstract contract ERC20 {\r\n /*//////////////////////////////////////////////////////////////\r\n EVENTS\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n event Transfer(address indexed from, address indexed to, uint256 amount);\r\n\r\n event Approval(address indexed owner, address indexed spender, uint256 amount);\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n METADATA STORAGE\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n string public name;\r\n\r\n string public symbol;\r\n\r\n uint8 public immutable decimals;\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n ERC20 STORAGE\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n uint256 public totalSupply;\r\n\r\n mapping(address => uint256) public balanceOf;\r\n\r\n mapping(address => mapping(address => uint256)) public allowance;\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n EIP-2612 STORAGE\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n uint256 internal immutable INITIAL_CHAIN_ID;\r\n\r\n bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;\r\n\r\n mapping(address => uint256) public nonces;\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n CONSTRUCTOR\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n constructor(\r\n string memory _name,\r\n string memory _symbol,\r\n uint8 _decimals\r\n ) {\r\n name = _name;\r\n symbol = _symbol;\r\n decimals = _decimals;\r\n\r\n INITIAL_CHAIN_ID = block.chainid;\r\n INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();\r\n }\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n ERC20 LOGIC\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n function approve(address spender, uint256 amount) public virtual returns (bool) {\r\n allowance[msg.sender][spender] = amount;\r\n\r\n emit Approval(msg.sender, spender, amount);\r\n\r\n return true;\r\n }\r\n\r\n function transfer(address to, uint256 amount) public virtual returns (bool) {\r\n balanceOf[msg.sender] -= amount;\r\n\r\n // Cannot overflow because the sum of all user\r\n // balances can't exceed the max uint256 value.\r\n unchecked {\r\n balanceOf[to] += amount;\r\n }\r\n\r\n emit Transfer(msg.sender, to, amount);\r\n\r\n return true;\r\n }\r\n\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 amount\r\n ) public virtual returns (bool) {\r\n uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.\r\n\r\n if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;\r\n\r\n balanceOf[from] -= amount;\r\n\r\n // Cannot overflow because the sum of all user\r\n // balances can't exceed the max uint256 value.\r\n unchecked {\r\n balanceOf[to] += amount;\r\n }\r\n\r\n emit Transfer(from, to, amount);\r\n\r\n return true;\r\n }\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n EIP-2612 LOGIC\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n function permit(\r\n address owner,\r\n address spender,\r\n uint256 value,\r\n uint256 deadline,\r\n uint8 v,\r\n bytes32 r,\r\n bytes32 s\r\n ) public virtual {\r\n require(deadline >= block.timestamp, \"PERMIT_DEADLINE_EXPIRED\");\r\n\r\n // Unchecked because the only math done is incrementing\r\n // the owner's nonce which cannot realistically overflow.\r\n unchecked {\r\n address recoveredAddress = ecrecover(\r\n keccak256(\r\n abi.encodePacked(\r\n \"\\x19\\x01\",\r\n DOMAIN_SEPARATOR(),\r\n keccak256(\r\n abi.encode(\r\n keccak256(\r\n \"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\"\r\n ),\r\n owner,\r\n spender,\r\n value,\r\n nonces[owner]++,\r\n deadline\r\n )\r\n )\r\n )\r\n ),\r\n v,\r\n r,\r\n s\r\n );\r\n\r\n require(recoveredAddress != address(0) && recoveredAddress == owner, \"INVALID_SIGNER\");\r\n\r\n allowance[recoveredAddress][spender] = value;\r\n }\r\n\r\n emit Approval(owner, spender, value);\r\n }\r\n\r\n function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {\r\n return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();\r\n }\r\n\r\n function computeDomainSeparator() internal view virtual returns (bytes32) {\r\n return\r\n keccak256(\r\n abi.encode(\r\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\r\n keccak256(bytes(name)),\r\n keccak256(\"1\"),\r\n block.chainid,\r\n address(this)\r\n )\r\n );\r\n }\r\n\r\n /*//////////////////////////////////////////////////////////////\r\n INTERNAL MINT/BURN LOGIC\r\n //////////////////////////////////////////////////////////////*/\r\n\r\n function _mint(address to, uint256 amount) internal virtual {\r\n totalSupply += amount;\r\n\r\n // Cannot overflow because the sum of all user\r\n // balances can't exceed the max uint256 value.\r\n unchecked {\r\n balanceOf[to] += amount;\r\n }\r\n\r\n emit Transfer(address(0), to, amount);\r\n }\r\n\r\n function _burn(address from, uint256 amount) internal virtual {\r\n balanceOf[from] -= amount;\r\n\r\n // Cannot underflow because a user's balance\r\n // will never be larger than the total supply.\r\n unchecked {\r\n totalSupply -= amount;\r\n }\r\n\r\n emit Transfer(from, address(0), amount);\r\n }\r\n}" }, "@api3/airnode-protocol/contracts/rrp/interfaces/IAirnodeRrpV0.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"./IAuthorizationUtilsV0.sol\";\nimport \"./ITemplateUtilsV0.sol\";\nimport \"./IWithdrawalUtilsV0.sol\";\n\ninterface IAirnodeRrpV0 is\n IAuthorizationUtilsV0,\n ITemplateUtilsV0,\n IWithdrawalUtilsV0\n{\n event SetSponsorshipStatus(\n address indexed sponsor,\n address indexed requester,\n bool sponsorshipStatus\n );\n\n event MadeTemplateRequest(\n address indexed airnode,\n bytes32 indexed requestId,\n uint256 requesterRequestCount,\n uint256 chainId,\n address requester,\n bytes32 templateId,\n address sponsor,\n address sponsorWallet,\n address fulfillAddress,\n bytes4 fulfillFunctionId,\n bytes parameters\n );\n\n event MadeFullRequest(\n address indexed airnode,\n bytes32 indexed requestId,\n uint256 requesterRequestCount,\n uint256 chainId,\n address requester,\n bytes32 endpointId,\n address sponsor,\n address sponsorWallet,\n address fulfillAddress,\n bytes4 fulfillFunctionId,\n bytes parameters\n );\n\n event FulfilledRequest(\n address indexed airnode,\n bytes32 indexed requestId,\n bytes data\n );\n\n event FailedRequest(\n address indexed airnode,\n bytes32 indexed requestId,\n string errorMessage\n );\n\n function setSponsorshipStatus(address requester, bool sponsorshipStatus)\n external;\n\n function makeTemplateRequest(\n bytes32 templateId,\n address sponsor,\n address sponsorWallet,\n address fulfillAddress,\n bytes4 fulfillFunctionId,\n bytes calldata parameters\n ) external returns (bytes32 requestId);\n\n function makeFullRequest(\n address airnode,\n bytes32 endpointId,\n address sponsor,\n address sponsorWallet,\n address fulfillAddress,\n bytes4 fulfillFunctionId,\n bytes calldata parameters\n ) external returns (bytes32 requestId);\n\n function fulfill(\n bytes32 requestId,\n address airnode,\n address fulfillAddress,\n bytes4 fulfillFunctionId,\n bytes calldata data,\n bytes calldata signature\n ) external returns (bool callSuccess, bytes memory callData);\n\n function fail(\n bytes32 requestId,\n address airnode,\n address fulfillAddress,\n bytes4 fulfillFunctionId,\n string calldata errorMessage\n ) external;\n\n function sponsorToRequesterToSponsorshipStatus(\n address sponsor,\n address requester\n ) external view returns (bool sponsorshipStatus);\n\n function requesterToRequestCountPlusOne(address requester)\n external\n view\n returns (uint256 requestCountPlusOne);\n\n function requestIsAwaitingFulfillment(bytes32 requestId)\n external\n view\n returns (bool isAwaitingFulfillment);\n}\n" }, "@api3/airnode-protocol/contracts/rrp/interfaces/IWithdrawalUtilsV0.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IWithdrawalUtilsV0 {\n event RequestedWithdrawal(\n address indexed airnode,\n address indexed sponsor,\n bytes32 indexed withdrawalRequestId,\n address sponsorWallet\n );\n\n event FulfilledWithdrawal(\n address indexed airnode,\n address indexed sponsor,\n bytes32 indexed withdrawalRequestId,\n address sponsorWallet,\n uint256 amount\n );\n\n function requestWithdrawal(address airnode, address sponsorWallet) external;\n\n function fulfillWithdrawal(\n bytes32 withdrawalRequestId,\n address airnode,\n address sponsor\n ) external payable;\n\n function sponsorToWithdrawalRequestCount(address sponsor)\n external\n view\n returns (uint256 withdrawalRequestCount);\n}\n" }, "@api3/airnode-protocol/contracts/rrp/interfaces/ITemplateUtilsV0.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface ITemplateUtilsV0 {\n event CreatedTemplate(\n bytes32 indexed templateId,\n address airnode,\n bytes32 endpointId,\n bytes parameters\n );\n\n function createTemplate(\n address airnode,\n bytes32 endpointId,\n bytes calldata parameters\n ) external returns (bytes32 templateId);\n\n function getTemplates(bytes32[] calldata templateIds)\n external\n view\n returns (\n address[] memory airnodes,\n bytes32[] memory endpointIds,\n bytes[] memory parameters\n );\n\n function templates(bytes32 templateId)\n external\n view\n returns (\n address airnode,\n bytes32 endpointId,\n bytes memory parameters\n );\n}\n" }, "@api3/airnode-protocol/contracts/rrp/interfaces/IAuthorizationUtilsV0.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IAuthorizationUtilsV0 {\n function checkAuthorizationStatus(\n address[] calldata authorizers,\n address airnode,\n bytes32 requestId,\n bytes32 endpointId,\n address sponsor,\n address requester\n ) external view returns (bool status);\n\n function checkAuthorizationStatuses(\n address[] calldata authorizers,\n address airnode,\n bytes32[] calldata requestIds,\n bytes32[] calldata endpointIds,\n address[] calldata sponsors,\n address[] calldata requesters\n ) external view returns (bool[] memory statuses);\n}\n" } }, "settings": { "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } } }