{ "language": "Solidity", "sources": { "contracts/CCCStore.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.4;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@chainlink/contracts/src/v0.8/VRFConsumerBase.sol\";\n\ninterface CCCFactory {\n function mint(address) external;\n}\n\ninterface CCCPass {\n function claimedCount(address) external view returns (uint256);\n function claimPass(\n address sender,\n uint256 _passAmount,\n uint256 _amountToMint,\n uint8 vSig,\n bytes32 rSig,\n bytes32 sSig\n ) external;\n}\n\ncontract CCCStore is Ownable, VRFConsumerBase {\n CCCPass public cccPass;\n CCCFactory public cccFactory;\n\n /**\n Max supply\n */\n uint256 public constant maxCCC = 5000;\n\n /**\n Verification and VRF\n */\n bytes32 internal keyHash;\n uint256 internal fee;\n uint256 public shuffleNumber;\n string public constant verificationHash = \"cac4549537bc6847f748479b916677fc29948e8240f94fd73020dd7dd0ffab49\"; // hash to verify initial order. it will be the keccak256 hash of the ipfs hash\n\n /**\n Team allocated CCC\n */\n uint256 public constant maxCCCForTeam = 345; // 6.9% of 5000\n\n /**\n Mint stats\n */\n uint256 public totalCCCMinted = 0;\n uint256 public totalCCCMintedByTeam = 0;\n uint256 public totalCCCMintedByVIP = 0;\n mapping(address => uint256) public CCCMinted;\n uint256 public totalETHDonated = 0;\n uint256 public totalETHDonatedByVIP = 0;\n\n /**\n Scheduling\n */\n uint256 public openingHours = 1665411010; // 2022-10-10 22:10:10 GMT+8\n\n /**\n Prices\n */\n uint256 public mintPrice = 0.2 ether;\n uint256 public constant VIPDiscount = 0.05 ether;\n\n /**\n Security\n */\n uint256 public constant maxMintPerTx = 100;\n\n event SetCCCPass(address cccPass);\n event SetCCCFactory(address cccFactory);\n event SetMintPrice(uint256 price);\n event SetOpeningHours(uint256 openingHours);\n event MintCCC(address account, uint256 amount);\n event Withdraw(address to);\n\n // mainnet\n // constructor()\n // VRFConsumerBase(\n // 0xf0d54349aDdcf704F77AE15b96510dEA15cb7952, // VRF Coordinator\n // 0x514910771AF9Ca656af840dff83E8264EcF986CA // LINK Token\n // ) {\n // keyHash = 0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445;\n // fee = 2 * 10 ** 18;\n // }\n\n // goerli\n constructor()\n VRFConsumerBase(\n 0x2bce784e69d2Ff36c71edcB9F88358dB0DfB55b4, // VRF Coordinator\n 0x326C977E6efc84E512bB9C30f76E30c160eD06FB // LINK Token\n ) {\n keyHash = 0x0476f9a745b61ea5c0ab224d3a6e4c99f0b02fce4da01143a4f70aa80ae76e8a;\n fee = 0.1 * 10 ** 18;\n }\n\n modifier whenOpened() {\n require(\n block.timestamp >= openingHours,\n \"Store is not opened\"\n );\n _;\n }\n\n function setCCCPass(CCCPass _cccPass) external onlyOwner {\n cccPass = _cccPass;\n emit SetCCCPass(address(_cccPass));\n }\n\n function setCCCFactory(CCCFactory _cccFactory) external onlyOwner {\n cccFactory = _cccFactory;\n emit SetCCCFactory(address(_cccFactory));\n }\n\n // price in terms of 0.01 ether\n function setMintPrice(uint256 _price) external onlyOwner {\n mintPrice = _price * 0.01 ether;\n require(mintPrice >= VIPDiscount, \"mintPrice lower than VIPDiscount\");\n emit SetMintPrice(_price);\n }\n\n function setOpeningHours(uint256 _openingHours) external onlyOwner {\n openingHours = _openingHours;\n emit SetOpeningHours(_openingHours);\n }\n\n function preMintCCC() external onlyOwner {\n require(totalCCCMintedByTeam == 0, \"preMint was done\");\n for (uint256 i = 0; i < maxCCCForTeam; i++) {\n cccFactory.mint(msg.sender);\n }\n totalCCCMintedByTeam += maxCCCForTeam;\n totalCCCMinted += maxCCCForTeam;\n CCCMinted[msg.sender] += maxCCCForTeam;\n }\n\n function mintCCC(\n uint256 _passAmount,\n uint256 _amountToMint,\n uint8 vSig,\n bytes32 rSig,\n bytes32 sSig)\n external \n payable \n whenOpened {\n require(_amountToMint <= maxMintPerTx, \"mint amount exceeds maximum\");\n require(_amountToMint > 0, \"Need to mint more than 0\");\n\n uint256 toClaim = 0;\n if (_passAmount > 0) {\n uint256 senderClaimedCount = cccPass.claimedCount(msg.sender);\n if (_passAmount > senderClaimedCount) {\n uint256 senderUnclaimedCount = _passAmount - senderClaimedCount;\n toClaim = _amountToMint > senderUnclaimedCount ? senderUnclaimedCount : _amountToMint;\n // claimPass will revert if fail\n cccPass.claimPass(msg.sender, _passAmount, toClaim, vSig, rSig, sSig);\n }\n }\n\n uint256 totalPrice = mintPrice * _amountToMint - VIPDiscount * toClaim;\n require(totalPrice <= msg.value, \"Not enough money\");\n\n for (uint256 i = 0; i < _amountToMint; i += 1) {\n cccFactory.mint(msg.sender);\n }\n\n totalCCCMinted += _amountToMint;\n CCCMinted[msg.sender] += _amountToMint;\n totalETHDonated += totalPrice;\n if (_passAmount > 0) {\n totalCCCMintedByVIP += _amountToMint;\n totalETHDonatedByVIP += totalPrice;\n }\n\n emit MintCCC(msg.sender, _amountToMint);\n }\n\n function getRandomNumber() external onlyOwner returns (bytes32 requestId) {\n require(LINK.balanceOf(address(this)) >= fee, \"Not enough LINK\");\n return requestRandomness(keyHash, fee);\n }\n\n /**\n * Callback from requestRandomness()\n */\n function fulfillRandomness(bytes32, uint256 randomness) internal override {\n require(shuffleNumber == 0, \"shuffleNumber is already set\");\n shuffleNumber = randomness;\n }\n\n // Fisher-Yates shuffle to obtained shuffled array of 0 to maxCCC. token id #n will be picture shuffledArray[n]\n function shuffle() external view returns (uint256[] memory shuffledArray) {\n require(shuffleNumber > 0, \"shuffleNumber is not set\");\n // initialize array\n shuffledArray = new uint256[](maxCCC);\n for (uint256 i = 0; i < maxCCC; i++) {\n shuffledArray[i] = i;\n }\n uint256 entropy = shuffleNumber;\n\n for (uint256 i = maxCCC-1; i > 0; i--) {\n // select random number from 0 to i inclusive\n entropy = uint256(keccak256(abi.encode(entropy)));\n uint256 j = (entropy) % (i+1);\n\n // swap item i and j\n uint256 temp = shuffledArray[i];\n shuffledArray[i] = shuffledArray[j];\n shuffledArray[j] = temp;\n }\n }\n\n // withdraw eth for sold CCC\n function withdraw(address payable _to, uint256 amount) external onlyOwner {\n require(_to != address(0), \"receiver cant be empty address\");\n\n // Send eth to designated receiver\n emit Withdraw(_to);\n\n _to.transfer(amount);\n }\n}" }, "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"./interfaces/LinkTokenInterface.sol\";\n\nimport \"./VRFRequestIDBase.sol\";\n\n/** ****************************************************************************\n * @notice Interface for contracts using VRF randomness\n * *****************************************************************************\n * @dev PURPOSE\n *\n * @dev Reggie the Random Oracle (not his real job) wants to provide randomness\n * @dev to Vera the verifier in such a way that Vera can be sure he's not\n * @dev making his output up to suit himself. Reggie provides Vera a public key\n * @dev to which he knows the secret key. Each time Vera provides a seed to\n * @dev Reggie, he gives back a value which is computed completely\n * @dev deterministically from the seed and the secret key.\n *\n * @dev Reggie provides a proof by which Vera can verify that the output was\n * @dev correctly computed once Reggie tells it to her, but without that proof,\n * @dev the output is indistinguishable to her from a uniform random sample\n * @dev from the output space.\n *\n * @dev The purpose of this contract is to make it easy for unrelated contracts\n * @dev to talk to Vera the verifier about the work Reggie is doing, to provide\n * @dev simple access to a verifiable source of randomness.\n * *****************************************************************************\n * @dev USAGE\n *\n * @dev Calling contracts must inherit from VRFConsumerBase, and can\n * @dev initialize VRFConsumerBase's attributes in their constructor as\n * @dev shown:\n *\n * @dev contract VRFConsumer {\n * @dev constuctor(, address _vrfCoordinator, address _link)\n * @dev VRFConsumerBase(_vrfCoordinator, _link) public {\n * @dev \n * @dev }\n * @dev }\n *\n * @dev The oracle will have given you an ID for the VRF keypair they have\n * @dev committed to (let's call it keyHash), and have told you the minimum LINK\n * @dev price for VRF service. Make sure your contract has sufficient LINK, and\n * @dev call requestRandomness(keyHash, fee, seed), where seed is the input you\n * @dev want to generate randomness from.\n *\n * @dev Once the VRFCoordinator has received and validated the oracle's response\n * @dev to your request, it will call your contract's fulfillRandomness method.\n *\n * @dev The randomness argument to fulfillRandomness is the actual random value\n * @dev generated from your seed.\n *\n * @dev The requestId argument is generated from the keyHash and the seed by\n * @dev makeRequestId(keyHash, seed). If your contract could have concurrent\n * @dev requests open, you can use the requestId to track which seed is\n * @dev associated with which randomness. See VRFRequestIDBase.sol for more\n * @dev details. (See \"SECURITY CONSIDERATIONS\" for principles to keep in mind,\n * @dev if your contract could have multiple requests in flight simultaneously.)\n *\n * @dev Colliding `requestId`s are cryptographically impossible as long as seeds\n * @dev differ. (Which is critical to making unpredictable randomness! See the\n * @dev next section.)\n *\n * *****************************************************************************\n * @dev SECURITY CONSIDERATIONS\n *\n * @dev A method with the ability to call your fulfillRandomness method directly\n * @dev could spoof a VRF response with any random value, so it's critical that\n * @dev it cannot be directly called by anything other than this base contract\n * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).\n *\n * @dev For your users to trust that your contract's random behavior is free\n * @dev from malicious interference, it's best if you can write it so that all\n * @dev behaviors implied by a VRF response are executed *during* your\n * @dev fulfillRandomness method. If your contract must store the response (or\n * @dev anything derived from it) and use it later, you must ensure that any\n * @dev user-significant behavior which depends on that stored value cannot be\n * @dev manipulated by a subsequent VRF request.\n *\n * @dev Similarly, both miners and the VRF oracle itself have some influence\n * @dev over the order in which VRF responses appear on the blockchain, so if\n * @dev your contract could have multiple VRF requests in flight simultaneously,\n * @dev you must ensure that the order in which the VRF responses arrive cannot\n * @dev be used to manipulate your contract's user-significant behavior.\n *\n * @dev Since the ultimate input to the VRF is mixed with the block hash of the\n * @dev block in which the request is made, user-provided seeds have no impact\n * @dev on its economic security properties. They are only included for API\n * @dev compatability with previous versions of this contract.\n *\n * @dev Since the block hash of the block which contains the requestRandomness\n * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful\n * @dev miner could, in principle, fork the blockchain to evict the block\n * @dev containing the request, forcing the request to be included in a\n * @dev different block with a different hash, and therefore a different input\n * @dev to the VRF. However, such an attack would incur a substantial economic\n * @dev cost. This cost scales with the number of blocks the VRF oracle waits\n * @dev until it calls responds to a request.\n */\nabstract contract VRFConsumerBase is VRFRequestIDBase {\n /**\n * @notice fulfillRandomness handles the VRF response. Your contract must\n * @notice implement it. See \"SECURITY CONSIDERATIONS\" above for important\n * @notice principles to keep in mind when implementing your fulfillRandomness\n * @notice method.\n *\n * @dev VRFConsumerBase expects its subcontracts to have a method with this\n * @dev signature, and will call it once it has verified the proof\n * @dev associated with the randomness. (It is triggered via a call to\n * @dev rawFulfillRandomness, below.)\n *\n * @param requestId The Id initially returned by requestRandomness\n * @param randomness the VRF output\n */\n function fulfillRandomness(bytes32 requestId, uint256 randomness) internal virtual;\n\n /**\n * @dev In order to keep backwards compatibility we have kept the user\n * seed field around. We remove the use of it because given that the blockhash\n * enters later, it overrides whatever randomness the used seed provides.\n * Given that it adds no security, and can easily lead to misunderstandings,\n * we have removed it from usage and can now provide a simpler API.\n */\n uint256 private constant USER_SEED_PLACEHOLDER = 0;\n\n /**\n * @notice requestRandomness initiates a request for VRF output given _seed\n *\n * @dev The fulfillRandomness method receives the output, once it's provided\n * @dev by the Oracle, and verified by the vrfCoordinator.\n *\n * @dev The _keyHash must already be registered with the VRFCoordinator, and\n * @dev the _fee must exceed the fee specified during registration of the\n * @dev _keyHash.\n *\n * @dev The _seed parameter is vestigial, and is kept only for API\n * @dev compatibility with older versions. It can't *hurt* to mix in some of\n * @dev your own randomness, here, but it's not necessary because the VRF\n * @dev oracle will mix the hash of the block containing your request into the\n * @dev VRF seed it ultimately uses.\n *\n * @param _keyHash ID of public key against which randomness is generated\n * @param _fee The amount of LINK to send with the request\n *\n * @return requestId unique ID for this request\n *\n * @dev The returned requestId can be used to distinguish responses to\n * @dev concurrent requests. It is passed as the first argument to\n * @dev fulfillRandomness.\n */\n function requestRandomness(bytes32 _keyHash, uint256 _fee) internal returns (bytes32 requestId) {\n LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, USER_SEED_PLACEHOLDER));\n // This is the seed passed to VRFCoordinator. The oracle will mix this with\n // the hash of the block containing this request to obtain the seed/input\n // which is finally passed to the VRF cryptographic machinery.\n uint256 vRFSeed = makeVRFInputSeed(_keyHash, USER_SEED_PLACEHOLDER, address(this), nonces[_keyHash]);\n // nonces[_keyHash] must stay in sync with\n // VRFCoordinator.nonces[_keyHash][this], which was incremented by the above\n // successful LINK.transferAndCall (in VRFCoordinator.randomnessRequest).\n // This provides protection against the user repeating their input seed,\n // which would result in a predictable/duplicate output, if multiple such\n // requests appeared in the same block.\n nonces[_keyHash] = nonces[_keyHash] + 1;\n return makeRequestId(_keyHash, vRFSeed);\n }\n\n LinkTokenInterface internal immutable LINK;\n address private immutable vrfCoordinator;\n\n // Nonces for each VRF key from which randomness has been requested.\n //\n // Must stay in sync with VRFCoordinator[_keyHash][this]\n mapping(bytes32 => uint256) /* keyHash */ /* nonce */\n private nonces;\n\n /**\n * @param _vrfCoordinator address of VRFCoordinator contract\n * @param _link address of LINK token contract\n *\n * @dev https://docs.chain.link/docs/link-token-contracts\n */\n constructor(address _vrfCoordinator, address _link) {\n vrfCoordinator = _vrfCoordinator;\n LINK = LinkTokenInterface(_link);\n }\n\n // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF\n // proof. rawFulfillRandomness then calls fulfillRandomness, after validating\n // the origin of the call\n function rawFulfillRandomness(bytes32 requestId, uint256 randomness) external {\n require(msg.sender == vrfCoordinator, \"Only VRFCoordinator can fulfill\");\n fulfillRandomness(requestId, randomness);\n }\n}\n" }, "@openzeppelin/contracts/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (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 Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\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 the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\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" }, "@chainlink/contracts/src/v0.8/VRFRequestIDBase.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ncontract VRFRequestIDBase {\n /**\n * @notice returns the seed which is actually input to the VRF coordinator\n *\n * @dev To prevent repetition of VRF output due to repetition of the\n * @dev user-supplied seed, that seed is combined in a hash with the\n * @dev user-specific nonce, and the address of the consuming contract. The\n * @dev risk of repetition is mostly mitigated by inclusion of a blockhash in\n * @dev the final seed, but the nonce does protect against repetition in\n * @dev requests which are included in a single block.\n *\n * @param _userSeed VRF seed input provided by user\n * @param _requester Address of the requesting contract\n * @param _nonce User-specific nonce at the time of the request\n */\n function makeVRFInputSeed(\n bytes32 _keyHash,\n uint256 _userSeed,\n address _requester,\n uint256 _nonce\n ) internal pure returns (uint256) {\n return uint256(keccak256(abi.encode(_keyHash, _userSeed, _requester, _nonce)));\n }\n\n /**\n * @notice Returns the id for this request\n * @param _keyHash The serviceAgreement ID to be used for this request\n * @param _vRFInputSeed The seed to be passed directly to the VRF\n * @return The id for this request\n *\n * @dev Note that _vRFInputSeed is not the seed passed by the consuming\n * @dev contract, but the one generated by makeVRFInputSeed\n */\n function makeRequestId(bytes32 _keyHash, uint256 _vRFInputSeed) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(_keyHash, _vRFInputSeed));\n }\n}\n" }, "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface LinkTokenInterface {\n function allowance(address owner, address spender) external view returns (uint256 remaining);\n\n function approve(address spender, uint256 value) external returns (bool success);\n\n function balanceOf(address owner) external view returns (uint256 balance);\n\n function decimals() external view returns (uint8 decimalPlaces);\n\n function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);\n\n function increaseApproval(address spender, uint256 subtractedValue) external;\n\n function name() external view returns (string memory tokenName);\n\n function symbol() external view returns (string memory tokenSymbol);\n\n function totalSupply() external view returns (uint256 totalTokensIssued);\n\n function transfer(address to, uint256 value) external returns (bool success);\n\n function transferAndCall(\n address to,\n uint256 value,\n bytes calldata data\n ) external returns (bool success);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool success);\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" ] } }, "libraries": {} } }