|
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023. |
|
|
|
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity ^0.8.17;
|
|
|
|
contract ReentrancyGuard {
|
|
bool private rentrancy_lock = false;
|
|
|
|
modifier nonReentrant() {
|
|
require(!rentrancy_lock);
|
|
rentrancy_lock = true;
|
|
_;
|
|
rentrancy_lock = false;
|
|
}
|
|
}
|
|
|
|
library Base64 {
|
|
bytes internal constant TABLE =
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
/// @notice Encodes some bytes to the base64 representation
|
|
function encode(bytes memory data) internal pure returns (string memory) {
|
|
uint256 len = data.length;
|
|
if (len == 0) return "";
|
|
|
|
// multiply by 4/3 rounded up
|
|
uint256 encodedLen = 4 * ((len + 2) / 3);
|
|
|
|
// Add some extra buffer at the end
|
|
bytes memory result = new bytes(encodedLen + 32);
|
|
|
|
bytes memory table = TABLE;
|
|
|
|
assembly {
|
|
let tablePtr := add(table, 1)
|
|
let resultPtr := add(result, 32)
|
|
|
|
for {
|
|
let i := 0
|
|
} lt(i, len) {
|
|
|
|
} {
|
|
i := add(i, 3)
|
|
let input := and(mload(add(data, i)), 0xffffff)
|
|
|
|
let out := mload(add(tablePtr, and(shr(18, input), 0x3F)))
|
|
out := shl(8, out)
|
|
out := add(
|
|
out,
|
|
and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF)
|
|
)
|
|
out := shl(8, out)
|
|
out := add(
|
|
out,
|
|
and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF)
|
|
)
|
|
out := shl(8, out)
|
|
out := add(
|
|
out,
|
|
and(mload(add(tablePtr, and(input, 0x3F))), 0xFF)
|
|
)
|
|
out := shl(224, out)
|
|
|
|
mstore(resultPtr, out)
|
|
|
|
resultPtr := add(resultPtr, 4)
|
|
}
|
|
|
|
switch mod(len, 3)
|
|
case 1 {
|
|
mstore(sub(resultPtr, 2), shl(240, 0x3d3d))
|
|
}
|
|
case 2 {
|
|
mstore(sub(resultPtr, 1), shl(248, 0x3d))
|
|
}
|
|
|
|
mstore(result, encodedLen)
|
|
}
|
|
|
|
return string(result);
|
|
}
|
|
}
|
|
|
|
interface IERC165 {
|
|
function supportsInterface(bytes4 interfaceId) external view returns (bool);
|
|
}
|
|
|
|
interface IERC721Receiver {
|
|
function onERC721Received(
|
|
address operator,
|
|
address from,
|
|
uint256 tokenId,
|
|
bytes calldata data
|
|
) external returns (bytes4);
|
|
}
|
|
|
|
interface IERC721 is IERC165 {
|
|
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
|
|
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
|
|
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
|
|
function balanceOf(address owner) external view returns (uint256 balance);
|
|
function ownerOf(uint256 tokenId) external view returns (address owner);
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes calldata data
|
|
) external;
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) external;
|
|
|
|
function transferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) external;
|
|
|
|
function approve(address to, uint256 tokenId) external;
|
|
function setApprovalForAll(address operator, bool _approved) external;
|
|
function getApproved(uint256 tokenId) external view returns (address operator);
|
|
function isApprovedForAll(address owner, address operator) external view returns (bool);
|
|
}
|
|
|
|
abstract contract Context {
|
|
function _msgSender() internal view virtual returns (address) {
|
|
return msg.sender;
|
|
}
|
|
}
|
|
|
|
abstract contract Ownable is Context {
|
|
address private _owner;
|
|
|
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
|
|
|
constructor() {
|
|
_transferOwnership(_msgSender());
|
|
}
|
|
|
|
modifier onlyOwner() {
|
|
_checkOwner();
|
|
_;
|
|
}
|
|
|
|
function owner() public view virtual returns (address) {
|
|
return _owner;
|
|
}
|
|
|
|
function _checkOwner() internal view virtual {
|
|
require(owner() == _msgSender(), "Ownable: caller is not the owner");
|
|
}
|
|
|
|
function renounceOwnership() external virtual onlyOwner {
|
|
_transferOwnership(address(0));
|
|
}
|
|
|
|
function transferOwnership(address newOwner) external virtual onlyOwner {
|
|
require(newOwner != address(0), "Ownable: new owner is the zero address");
|
|
_transferOwnership(newOwner);
|
|
}
|
|
|
|
function _transferOwnership(address newOwner) internal virtual {
|
|
address oldOwner = _owner;
|
|
_owner = newOwner;
|
|
emit OwnershipTransferred(oldOwner, newOwner);
|
|
}
|
|
}
|
|
|
|
interface IERC721Metadata is IERC721 {
|
|
function name() external view returns (string memory);
|
|
function symbol() external view returns (string memory);
|
|
function tokenURI(uint256 tokenId) external view returns (string memory);
|
|
}
|
|
|
|
abstract contract ERC165 is IERC165 {
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
return interfaceId == type(IERC165).interfaceId;
|
|
}
|
|
}
|
|
library Address {
|
|
function isContract(address account) internal view returns (bool) {
|
|
return account.code.length > 0;
|
|
}
|
|
}
|
|
|
|
library Math {
|
|
enum Rounding {
|
|
Down, // Toward negative infinity
|
|
Up, // Toward infinity
|
|
Zero // Toward zero
|
|
}
|
|
|
|
function log10(uint256 value) internal pure returns (uint256) {
|
|
uint256 result = 0;
|
|
unchecked {
|
|
if (value >= 10**64) {
|
|
value /= 10**64;
|
|
result += 64;
|
|
}
|
|
if (value >= 10**32) {
|
|
value /= 10**32;
|
|
result += 32;
|
|
}
|
|
if (value >= 10**16) {
|
|
value /= 10**16;
|
|
result += 16;
|
|
}
|
|
if (value >= 10**8) {
|
|
value /= 10**8;
|
|
result += 8;
|
|
}
|
|
if (value >= 10**4) {
|
|
value /= 10**4;
|
|
result += 4;
|
|
}
|
|
if (value >= 10**2) {
|
|
value /= 10**2;
|
|
result += 2;
|
|
}
|
|
if (value >= 10**1) {
|
|
result += 1;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
|
|
unchecked {
|
|
uint256 result = log10(value);
|
|
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
function log256(uint256 value) internal pure returns (uint256) {
|
|
uint256 result = 0;
|
|
unchecked {
|
|
if (value >> 128 > 0) {
|
|
value >>= 128;
|
|
result += 16;
|
|
}
|
|
if (value >> 64 > 0) {
|
|
value >>= 64;
|
|
result += 8;
|
|
}
|
|
if (value >> 32 > 0) {
|
|
value >>= 32;
|
|
result += 4;
|
|
}
|
|
if (value >> 16 > 0) {
|
|
value >>= 16;
|
|
result += 2;
|
|
}
|
|
if (value >> 8 > 0) {
|
|
result += 1;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
|
|
unchecked {
|
|
uint256 result = log256(value);
|
|
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
library Strings {
|
|
bytes16 private constant _SYMBOLS = "0123456789abcdef";
|
|
uint8 private constant _ADDRESS_LENGTH = 20;
|
|
|
|
|
|
|
|
|
|
function toString(uint256 value) internal pure returns (string memory) {
|
|
unchecked {
|
|
uint256 length = Math.log10(value) + 1;
|
|
string memory buffer = new string(length);
|
|
uint256 ptr;
|
|
/// @solidity memory-safe-assembly
|
|
assembly {
|
|
ptr := add(buffer, add(32, length))
|
|
}
|
|
while (true) {
|
|
ptr
|
|
/// @solidity memory-safe-assembly
|
|
assembly {
|
|
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
|
|
}
|
|
value /= 10;
|
|
if (value == 0) break;
|
|
}
|
|
return buffer;
|
|
}
|
|
}
|
|
}
|
|
|
|
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
|
using Address for address;
|
|
using Strings for uint256;
|
|
|
|
string private _name;
|
|
string private _symbol;
|
|
|
|
// Mapping from token ID to owner address
|
|
mapping(uint256 => address) private _owners;
|
|
mapping(address => uint256) private _balances;
|
|
mapping(uint256 => address) private _tokenApprovals;
|
|
mapping(address => mapping(address => bool)) private _operatorApprovals;
|
|
|
|
constructor(string memory name_, string memory symbol_) {
|
|
_name = name_;
|
|
_symbol = symbol_;
|
|
}
|
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
|
return
|
|
interfaceId == type(IERC721).interfaceId ||
|
|
interfaceId == type(IERC721Metadata).interfaceId ||
|
|
super.supportsInterface(interfaceId);
|
|
}
|
|
|
|
function balanceOf(address owner) external view virtual override returns (uint256) {
|
|
require(owner != address(0), "ERC721: address zero is not a valid owner");
|
|
return _balances[owner];
|
|
}
|
|
|
|
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
|
|
address owner = _ownerOf(tokenId);
|
|
require(owner != address(0), "ERC721: invalid token ID");
|
|
return owner;
|
|
}
|
|
|
|
function name() external view virtual override returns (string memory) {
|
|
return _name;
|
|
}
|
|
|
|
function symbol() external view virtual override returns (string memory) {
|
|
return _symbol;
|
|
}
|
|
|
|
function tokenURI(uint256 tokenId) external view virtual override returns (string memory) {
|
|
_requireMinted(tokenId);
|
|
string memory baseURI = _baseURI();
|
|
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
|
|
}
|
|
|
|
function _baseURI() internal view virtual returns (string memory) {
|
|
return "";
|
|
}
|
|
|
|
function approve(address to, uint256 tokenId) external virtual override {
|
|
address owner = ERC721.ownerOf(tokenId);
|
|
require(to != owner, "ERC721: approval to current owner");
|
|
|
|
require(
|
|
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
|
|
"ERC721: approve caller is not token owner or approved for all"
|
|
);
|
|
|
|
_approve(to, tokenId);
|
|
}
|
|
|
|
function getApproved(uint256 tokenId) public view virtual override returns (address) {
|
|
_requireMinted(tokenId);
|
|
|
|
return _tokenApprovals[tokenId];
|
|
}
|
|
|
|
function setApprovalForAll(address operator, bool approved) external virtual override {
|
|
_setApprovalForAll(_msgSender(), operator, approved);
|
|
}
|
|
|
|
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
|
|
return _operatorApprovals[owner][operator];
|
|
}
|
|
|
|
function transferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) external virtual override {
|
|
//solhint-disable-next-line max-line-length
|
|
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
|
|
|
|
_transfer(from, to, tokenId);
|
|
}
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) external virtual override {
|
|
safeTransferFrom(from, to, tokenId, "");
|
|
}
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory data
|
|
) public virtual override {
|
|
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
|
|
_safeTransfer(from, to, tokenId, data);
|
|
}
|
|
|
|
function _safeTransfer(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory data
|
|
) internal virtual {
|
|
_transfer(from, to, tokenId);
|
|
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
|
|
}
|
|
|
|
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
|
|
return _owners[tokenId];
|
|
}
|
|
|
|
function _exists(uint256 tokenId) internal view virtual returns (bool) {
|
|
return _ownerOf(tokenId) != address(0);
|
|
}
|
|
|
|
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
|
|
address owner = ERC721.ownerOf(tokenId);
|
|
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
|
|
}
|
|
|
|
function _safeMint(address to, uint256 tokenId) internal virtual {
|
|
_safeMint(to, tokenId, "");
|
|
}
|
|
|
|
function _safeMint(
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory data
|
|
) internal virtual {
|
|
_mint(to, tokenId);
|
|
require(
|
|
_checkOnERC721Received(address(0), to, tokenId, data),
|
|
"ERC721: transfer to non ERC721Receiver implementer"
|
|
);
|
|
}
|
|
|
|
function _mint(address to, uint256 tokenId) internal virtual {
|
|
require(to != address(0), "ERC721: mint to the zero address");
|
|
require(!_exists(tokenId), "ERC721: token already minted");
|
|
|
|
// Check that tokenId was not minted by `_beforeTokenTransfer` hook
|
|
require(!_exists(tokenId), "ERC721: token already minted");
|
|
|
|
unchecked {
|
|
// Will not overflow unless all 2**256 token ids are minted to the same owner.
|
|
// Given that tokens are minted one by one, it is impossible in practice that
|
|
// this ever happens. Might change if we allow batch minting.
|
|
// The ERC fails to describe this case.
|
|
_balances[to] += 1;
|
|
}
|
|
|
|
_owners[tokenId] = to;
|
|
|
|
emit Transfer(address(0), to, tokenId);
|
|
}
|
|
|
|
function _transfer(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) internal virtual {
|
|
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
|
|
require(to != address(0), "ERC721: transfer to the zero address");
|
|
|
|
// Check that tokenId was not transferred by `_beforeTokenTransfer` hook
|
|
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
|
|
|
|
// Clear approvals from the previous owner
|
|
delete _tokenApprovals[tokenId];
|
|
|
|
unchecked {
|
|
// `_balances[from]` cannot overflow for the same reason as described in `_burn`:
|
|
// `from`'s balance is the number of token held, which is at least one before the current
|
|
// transfer.
|
|
// `_balances[to]` could overflow in the conditions described in `_mint`. That would require
|
|
// all 2**256 token ids to be minted, which in practice is impossible.
|
|
_balances[from] -= 1;
|
|
_balances[to] += 1;
|
|
}
|
|
_owners[tokenId] = to;
|
|
|
|
emit Transfer(from, to, tokenId);
|
|
}
|
|
|
|
function _approve(address to, uint256 tokenId) internal virtual {
|
|
_tokenApprovals[tokenId] = to;
|
|
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
|
|
}
|
|
|
|
function _setApprovalForAll(
|
|
address owner,
|
|
address operator,
|
|
bool approved
|
|
) internal virtual {
|
|
require(owner != operator, "ERC721: approve to caller");
|
|
_operatorApprovals[owner][operator] = approved;
|
|
emit ApprovalForAll(owner, operator, approved);
|
|
}
|
|
|
|
function _requireMinted(uint256 tokenId) internal view virtual {
|
|
require(_exists(tokenId), "ERC721: invalid token ID");
|
|
}
|
|
|
|
/**
|
|
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
|
|
* The call is not executed if the target address is not a contract.
|
|
*
|
|
* @param from address representing the previous owner of the given token ID
|
|
* @param to target address that will receive the tokens
|
|
* @param tokenId uint256 ID of the token to be transferred
|
|
* @param data bytes optional data to send along with the call
|
|
* @return bool whether the call correctly returned the expected magic value
|
|
*/
|
|
function _checkOnERC721Received(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory data
|
|
) private returns (bool) {
|
|
if (to.isContract()) {
|
|
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
|
|
return retval == IERC721Receiver.onERC721Received.selector;
|
|
} catch (bytes memory reason) {
|
|
if (reason.length == 0) {
|
|
revert("ERC721: transfer to non ERC721Receiver implementer");
|
|
} else {
|
|
/// @solidity memory-safe-assembly
|
|
assembly {
|
|
revert(add(32, reason), mload(reason))
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
contract WizScoreNFT is ERC721, Ownable, ReentrancyGuard {
|
|
event WizScoreLocked(uint indexed tokenId, uint indexed lockedInScore);
|
|
|
|
bool internal publicMintOpen = false;
|
|
uint internal constant totalPossible = 1000;
|
|
uint internal constant wizScorePrice = 10000000000000000; // 0.01 ETH
|
|
uint internal totalMinted = 0;
|
|
string internal htmlPageURI = "";
|
|
string internal loadingGifURI = "ipfs://QmSeGiTaQrhiazvhmnEv3Tdamg3fRuKK4sHPRayKfc464x";
|
|
string internal description = "To play the Cootie Catcher, select a color and number to reveal your fortune. If you want to go on the wizard adventure, go to the smart contract, connect wallet and use claimWizScore with 0.01 eth. This will lock you a WizScore. Complete this task and you will be rewarded with some wizard magic. Each Cootie Catcher can only be locked once. Safe travels my friend.";
|
|
|
|
string internal metaName = "Paper Handed Cootie Catchers";
|
|
|
|
mapping(uint => uint) internal tokenIdToWizScore;
|
|
|
|
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {
|
|
}
|
|
|
|
receive() external payable {
|
|
require(publicMintOpen, "Public is not open yet.");
|
|
unchecked {
|
|
uint newTotal = totalMinted + 1;
|
|
require(newTotal <= totalPossible, "SOLD OUT");
|
|
totalMinted = newTotal;
|
|
_mint(msg.sender, newTotal);
|
|
}
|
|
}
|
|
|
|
function airdrop(address[] calldata users) external onlyOwner {
|
|
unchecked {
|
|
uint count = users.length;
|
|
for(uint i = 0; i < count; i++) {
|
|
uint newTotal = totalMinted + 1;
|
|
require(newTotal <= totalPossible, "SOLD OUT");
|
|
totalMinted = newTotal;
|
|
_mint(users[i], newTotal);
|
|
}
|
|
}
|
|
}
|
|
|
|
function claimWizScore(uint tokenId) payable external nonReentrant {
|
|
require(msg.value >= wizScorePrice, "It costs at least 0.01 to lock in a wizscore"); // allow for tips
|
|
require(tokenIdToWizScore[tokenId] == 0, "This already has a wizscore");
|
|
uint randomHash = uint(keccak256(abi.encodePacked(block.number, block.difficulty, block.timestamp, tokenId)));
|
|
tokenIdToWizScore[tokenId] = (randomHash % totalPossible) + 1;
|
|
|
|
emit WizScoreLocked(tokenId, tokenIdToWizScore[tokenId]);
|
|
}
|
|
|
|
function zCollectETH() external onlyOwner {
|
|
(bool sent, ) = payable(owner()).call{value: address(this).balance}("");
|
|
require(sent, "Failed to send Ether");
|
|
}
|
|
|
|
function totalSupply() external view virtual returns (uint256) {
|
|
return totalMinted;
|
|
}
|
|
|
|
function setHTMLURI(string calldata _htmlPageURI) external onlyOwner {
|
|
htmlPageURI = _htmlPageURI;
|
|
}
|
|
|
|
function setGIFURI(string calldata _loadingGifURI) external onlyOwner {
|
|
loadingGifURI = _loadingGifURI;
|
|
}
|
|
|
|
function setMetaName(string calldata _name) external onlyOwner {
|
|
metaName = _name;
|
|
}
|
|
|
|
function togglePublic() external onlyOwner {
|
|
publicMintOpen = !publicMintOpen;
|
|
}
|
|
|
|
function setDesc(string calldata _description) external onlyOwner {
|
|
description = _description;
|
|
}
|
|
|
|
function _toString(uint256 value) internal pure returns (string memory) {
|
|
// Inspired by OraclizeAPI's implementation - MIT licence
|
|
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
|
|
if (value == 0) {
|
|
return "0";
|
|
}
|
|
uint256 temp = value;
|
|
uint256 digits;
|
|
while (temp != 0) {
|
|
digits++;
|
|
temp /= 10;
|
|
}
|
|
bytes memory buffer = new bytes(digits);
|
|
while (value != 0) {
|
|
digits -= 1;
|
|
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
|
|
value /= 10;
|
|
}
|
|
return string(buffer);
|
|
}
|
|
|
|
function tokenURI(uint256 tokenId) external view virtual override returns (string memory) {
|
|
_requireMinted(tokenId);
|
|
uint foundScore = tokenIdToWizScore[tokenId];
|
|
string memory json = Base64.encode(
|
|
bytes(
|
|
string(
|
|
abi.encodePacked(
|
|
'{"name": "',
|
|
metaName,
|
|
" #",
|
|
_toString(tokenId),
|
|
'", "description": "',
|
|
string(description),
|
|
'", "animation_url": "',
|
|
string(htmlPageURI),
|
|
_toString(tokenId),
|
|
'", "image": "',
|
|
string(loadingGifURI),
|
|
'", "attributes":[{ "trait_type": "WizScore", "value": ',
|
|
foundScore == 0 ? '"UNCLAIMED"' : _toString(foundScore),
|
|
" }] }"
|
|
)
|
|
)
|
|
)
|
|
);
|
|
return string(abi.encodePacked("data:application/json;base64,", json));
|
|
}
|
|
|
|
function wizScoreForID(uint tokenId) external view returns(uint) {
|
|
return tokenIdToWizScore[tokenId];
|
|
}
|
|
} |