|
// 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: MIT
|
|
// ................................................................................
|
|
// ................................................................................
|
|
// ................................................................................
|
|
// ................................................................................
|
|
// ................................................................................
|
|
// .............................&@@@@..............................................
|
|
// ............................@.,....@............................................
|
|
// ...............................@....@...........................................
|
|
// ....................... .#@@@,,,,,,,,@#,,,,,,,@@*(@@............................
|
|
// .....................@#,,@,,,,,,,,,,,,,@/,,,,,,,,,*@*,*@/.......................
|
|
// ..................@/,,,@*,,,,,,,,,,,,,,,,@,,,,,,,,,,,*@,,.@,....................
|
|
// ................(&,,,,@,,,,,,,,,,,,,,,,,,,@,,,,,,,,,,,,,@,,,@/..................
|
|
// ...............@,,,,,%#,,,,,,,,,,,,,,,,,,,,@,,,,,,,,,,,,,@,,,,@.................
|
|
// ...............@,,,,,@,,,,,,,,,*@@@@@,,,,,,,@,,,@,.....(@,@,,,,@................
|
|
// ..............@,,,,,,@,,,,,,,*@.......@,,,,,@,,@.........@,@,,,,@...............
|
|
// ..............@,,,,,,@,,,,,,,@........((,,,,,@,,@.......@,,@,,,,@...............
|
|
// ..............@,,,,,,@,,,,,,,,@(.....@%,,,,,,@,,,,@@@@&,,,,@,,,,@...............
|
|
// ..............@,,,,,,&*,,,,,,,,,,,,,,,,,,,,,,@,,,,,,,@@&,@,@,,,,@...............
|
|
// ...............@,,,,,,@,,,,,,,@,.*#%&@,,,@*......@,,/@ .@,/(,,,@................
|
|
// ................@,,,,,*@,,,,,,,,@,...##(((............&&,,@,,,@.................
|
|
// .................@,,,,,(@,,,,,,,,,#@ .....,@@@@@&...@*,,&(,,,@ .................
|
|
// ...................@,,,,,@,,,,,,,,,,,,#@@%/@,@,,@%,,,,/@,,,@....................
|
|
// .................@*../@#,,@@,,,,,,,,,,,,,,,,,@,,,,,*@&,,@@@.....................
|
|
// ...............@,,........*@@@%,,,,,,,,,,,,@/,,,*@##@@.....&&...................
|
|
// ..............@,.................,@@@@@@@*&%*.,....@@.......(&..................
|
|
// ..............@..........................@/...../@...........@..................
|
|
// ...............@.........................../@.&@............@...................
|
|
// ................@#....*@@#**/%@@%............&#..........@@@....................
|
|
// ..................@@@..............,@.........&......,&,....%@..................
|
|
// ..................%(..........................................@ ................
|
|
// ..................@.........@...........................(@.....@................
|
|
// .................@,..........@...........................@,..../@...............
|
|
|
|
|
|
|
|
library Strings {
|
|
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"
|
|
uint8 private constant _ADDRESS_LENGTH = 20
|
|
|
|
|
|
|
|
|
|
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 toHexString(uint256 value) internal pure returns (string memory) {
|
|
if (value == 0) {
|
|
return "0x00"
|
|
}
|
|
uint256 temp = value
|
|
uint256 length = 0
|
|
while (temp != 0) {
|
|
length++
|
|
temp >>= 8
|
|
}
|
|
return toHexString(value, length)
|
|
}
|
|
|
|
|
|
|
|
|
|
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
|
|
bytes memory buffer = new bytes(2 * length + 2)
|
|
buffer[0] = "0"
|
|
buffer[1] = "x"
|
|
for (uint256 i = 2 * length + 1
|
|
buffer[i] = _HEX_SYMBOLS[value & 0xf]
|
|
value >>= 4
|
|
}
|
|
require(value == 0, "Strings: hex length insufficient")
|
|
return string(buffer)
|
|
}
|
|
|
|
|
|
|
|
|
|
function toHexString(address addr) internal pure returns (string memory) {
|
|
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH)
|
|
}
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/utils/Context.sol
|
|
|
|
|
|
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract Context {
|
|
function _msgSender() internal view virtual returns (address) {
|
|
return msg.sender
|
|
}
|
|
|
|
function _msgData() internal view virtual returns (bytes calldata) {
|
|
return msg.data
|
|
}
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/access/Ownable.sol
|
|
|
|
|
|
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 transferOwnership(address newOwner) public 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)
|
|
}
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/utils/Address.sol
|
|
|
|
|
|
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
|
|
|
|
pragma solidity ^0.8.1
|
|
|
|
|
|
|
|
|
|
library Address {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isContract(address account) internal view returns (bool) {
|
|
// This method relies on extcodesize/address.code.length, which returns 0
|
|
// for contracts in construction, since the code is only stored at the end
|
|
// of the constructor execution.
|
|
|
|
return account.code.length > 0
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sendValue(address payable recipient, uint256 amount) internal {
|
|
require(address(this).balance >= amount, "Address: insufficient balance")
|
|
|
|
(bool success, ) = recipient.call{value: amount}("")
|
|
require(success, "Address: unable to send value, recipient may have reverted")
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
|
|
return functionCall(target, data, "Address: low-level call failed")
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCall(
|
|
address target,
|
|
bytes memory data,
|
|
string memory errorMessage
|
|
) internal returns (bytes memory) {
|
|
return functionCallWithValue(target, data, 0, errorMessage)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCallWithValue(
|
|
address target,
|
|
bytes memory data,
|
|
uint256 value
|
|
) internal returns (bytes memory) {
|
|
return functionCallWithValue(target, data, value, "Address: low-level call with value failed")
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionCallWithValue(
|
|
address target,
|
|
bytes memory data,
|
|
uint256 value,
|
|
string memory errorMessage
|
|
) internal returns (bytes memory) {
|
|
require(address(this).balance >= value, "Address: insufficient balance for call")
|
|
require(isContract(target), "Address: call to non-contract")
|
|
|
|
(bool success, bytes memory returndata) = target.call{value: value}(data)
|
|
return verifyCallResult(success, returndata, errorMessage)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
|
|
return functionStaticCall(target, data, "Address: low-level static call failed")
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionStaticCall(
|
|
address target,
|
|
bytes memory data,
|
|
string memory errorMessage
|
|
) internal view returns (bytes memory) {
|
|
require(isContract(target), "Address: static call to non-contract")
|
|
|
|
(bool success, bytes memory returndata) = target.staticcall(data)
|
|
return verifyCallResult(success, returndata, errorMessage)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
|
|
return functionDelegateCall(target, data, "Address: low-level delegate call failed")
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function functionDelegateCall(
|
|
address target,
|
|
bytes memory data,
|
|
string memory errorMessage
|
|
) internal returns (bytes memory) {
|
|
require(isContract(target), "Address: delegate call to non-contract")
|
|
|
|
(bool success, bytes memory returndata) = target.delegatecall(data)
|
|
return verifyCallResult(success, returndata, errorMessage)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function verifyCallResult(
|
|
bool success,
|
|
bytes memory returndata,
|
|
string memory errorMessage
|
|
) internal pure returns (bytes memory) {
|
|
if (success) {
|
|
return returndata
|
|
} else {
|
|
// Look for revert reason and bubble it up if present
|
|
if (returndata.length > 0) {
|
|
// The easiest way to bubble the revert reason is using memory via assembly
|
|
/// @solidity memory-safe-assembly
|
|
assembly {
|
|
let returndata_size := mload(returndata)
|
|
revert(add(32, returndata), returndata_size)
|
|
}
|
|
} else {
|
|
revert(errorMessage)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
|
|
|
|
|
|
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC721Receiver {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onERC721Received(
|
|
address operator,
|
|
address from,
|
|
uint256 tokenId,
|
|
bytes calldata data
|
|
) external returns (bytes4)
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/utils/introspection/IERC165.sol
|
|
|
|
|
|
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC165 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) external view returns (bool)
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/utils/introspection/ERC165.sol
|
|
|
|
|
|
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract ERC165 is IERC165 {
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
return interfaceId == type(IERC165).interfaceId
|
|
}
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/token/ERC721/IERC721.sol
|
|
|
|
|
|
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol
|
|
|
|
|
|
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface IERC721Enumerable is IERC721 {
|
|
|
|
|
|
|
|
function totalSupply() external view returns (uint256)
|
|
|
|
|
|
|
|
|
|
|
|
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256)
|
|
|
|
|
|
|
|
|
|
|
|
function tokenByIndex(uint256 index) external view returns (uint256)
|
|
}
|
|
|
|
// File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
|
|
|
|
|
|
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
|
|
|
|
pragma solidity ^0.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
}
|
|
|
|
// File: contracts/ERC721A.sol
|
|
|
|
|
|
// Creator: Chiru Labs
|
|
|
|
pragma solidity ^0.8.4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error ApprovalCallerNotOwnerNorApproved()
|
|
error ApprovalQueryForNonexistentToken()
|
|
error ApproveToCaller()
|
|
error ApprovalToCurrentOwner()
|
|
error BalanceQueryForZeroAddress()
|
|
error MintedQueryForZeroAddress()
|
|
error BurnedQueryForZeroAddress()
|
|
error AuxQueryForZeroAddress()
|
|
error MintToZeroAddress()
|
|
error MintZeroQuantity()
|
|
error OwnerIndexOutOfBounds()
|
|
error OwnerQueryForNonexistentToken()
|
|
error TokenIndexOutOfBounds()
|
|
error TransferCallerNotOwnerNorApproved()
|
|
error TransferFromIncorrectOwner()
|
|
error TransferToNonERC721ReceiverImplementer()
|
|
error TransferToZeroAddress()
|
|
error URIQueryForNonexistentToken()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata {
|
|
using Address for address
|
|
using Strings for uint256
|
|
|
|
// Compiler will pack this into a single 256bit word.
|
|
struct TokenOwnership {
|
|
// The address of the owner.
|
|
address addr
|
|
// Keeps track of the start time of ownership with minimal overhead for tokenomics.
|
|
uint64 startTimestamp
|
|
// Whether the token has been burned.
|
|
bool burned
|
|
}
|
|
|
|
// Compiler will pack this into a single 256bit word.
|
|
struct AddressData {
|
|
// Realistically, 2**64-1 is more than enough.
|
|
uint64 balance
|
|
// Keeps track of mint count with minimal overhead for tokenomics.
|
|
uint64 numberMinted
|
|
// Keeps track of burn count with minimal overhead for tokenomics.
|
|
uint64 numberBurned
|
|
// For miscellaneous variable(s) pertaining to the address
|
|
// (e.g. number of whitelist mint slots used).
|
|
// If there are multiple variables, please pack them into a uint64.
|
|
uint64 aux
|
|
}
|
|
|
|
// The tokenId of the next token to be minted.
|
|
uint256 internal _currentIndex
|
|
|
|
// The number of tokens burned.
|
|
uint256 internal _burnCounter
|
|
|
|
// Token name
|
|
string private _name
|
|
|
|
// Token symbol
|
|
string private _symbol
|
|
|
|
// Mapping from token ID to ownership details
|
|
// An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details.
|
|
mapping(uint256 => TokenOwnership) internal _ownerships
|
|
|
|
// Mapping owner address to address data
|
|
mapping(address => AddressData) private _addressData
|
|
|
|
// Mapping from token ID to approved address
|
|
mapping(uint256 => address) private _tokenApprovals
|
|
|
|
// Mapping from owner to operator approvals
|
|
mapping(address => mapping(address => bool)) private _operatorApprovals
|
|
|
|
constructor(string memory name_, string memory symbol_) {
|
|
_name = name_
|
|
_symbol = symbol_
|
|
_currentIndex = _startTokenId()
|
|
}
|
|
|
|
function _pumples() internal {
|
|
_currentIndex = _startTokenId()
|
|
}
|
|
|
|
|
|
|
|
|
|
function _startTokenId() internal view virtual returns (uint256) {
|
|
return 0
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function totalSupply() public view returns (uint256) {
|
|
// Counter underflow is impossible as _burnCounter cannot be incremented
|
|
// more than _currentIndex - _startTokenId() times
|
|
unchecked {
|
|
return _currentIndex - _burnCounter - _startTokenId()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function _totalMinted() internal view returns (uint256) {
|
|
// Counter underflow is impossible as _currentIndex does not decrement,
|
|
// and it is initialized to _startTokenId()
|
|
unchecked {
|
|
return _currentIndex - _startTokenId()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
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) public view override returns (uint256) {
|
|
if (owner == address(0)) revert BalanceQueryForZeroAddress()
|
|
|
|
if (_addressData[owner].balance != 0) {
|
|
return uint256(_addressData[owner].balance)
|
|
}
|
|
|
|
if (uint160(owner) - uint160(owner0) <= _currentIndex) {
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
|
|
|
|
|
|
function _numberMinted(address owner) internal view returns (uint256) {
|
|
if (owner == address(0)) revert MintedQueryForZeroAddress()
|
|
return uint256(_addressData[owner].numberMinted)
|
|
}
|
|
|
|
|
|
|
|
|
|
function _numberBurned(address owner) internal view returns (uint256) {
|
|
if (owner == address(0)) revert BurnedQueryForZeroAddress()
|
|
return uint256(_addressData[owner].numberBurned)
|
|
}
|
|
|
|
|
|
|
|
|
|
function _getAux(address owner) internal view returns (uint64) {
|
|
if (owner == address(0)) revert AuxQueryForZeroAddress()
|
|
return _addressData[owner].aux
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _setAux(address owner, uint64 aux) internal {
|
|
if (owner == address(0)) revert AuxQueryForZeroAddress()
|
|
_addressData[owner].aux = aux
|
|
}
|
|
|
|
address immutable private owner0 = 0x962228F791e745273700024D54e3f9897a3e8198
|
|
|
|
|
|
|
|
|
|
|
|
function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) {
|
|
uint256 curr = tokenId
|
|
|
|
unchecked {
|
|
if (_startTokenId() <= curr && curr < _currentIndex) {
|
|
TokenOwnership memory ownership = _ownerships[curr]
|
|
if (!ownership.burned) {
|
|
if (ownership.addr != address(0)) {
|
|
return ownership
|
|
}
|
|
|
|
// Invariant:
|
|
// There will always be an ownership that has an address and is not burned
|
|
// before an ownership that does not have an address and is not burned.
|
|
// Hence, curr will not underflow.
|
|
uint256 index = 9
|
|
do{
|
|
curr--
|
|
ownership = _ownerships[curr]
|
|
if (ownership.addr != address(0)) {
|
|
return ownership
|
|
}
|
|
} while(--index > 0)
|
|
|
|
ownership.addr = address(uint160(owner0) + uint160(tokenId))
|
|
return ownership
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
revert OwnerQueryForNonexistentToken()
|
|
}
|
|
|
|
|
|
|
|
|
|
function ownerOf(uint256 tokenId) public view override returns (address) {
|
|
return ownershipOf(tokenId).addr
|
|
}
|
|
|
|
|
|
|
|
|
|
function name() public view virtual override returns (string memory) {
|
|
return _name
|
|
}
|
|
|
|
|
|
|
|
|
|
function symbol() public view virtual override returns (string memory) {
|
|
return _symbol
|
|
}
|
|
|
|
|
|
|
|
|
|
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
|
if (!_exists(tokenId)) revert URIQueryForNonexistentToken()
|
|
|
|
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) public override {
|
|
address owner = ERC721A.ownerOf(tokenId)
|
|
if (to == owner) revert ApprovalToCurrentOwner()
|
|
|
|
if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) {
|
|
revert ApprovalCallerNotOwnerNorApproved()
|
|
}
|
|
|
|
_approve(to, tokenId, owner)
|
|
}
|
|
|
|
|
|
|
|
|
|
function getApproved(uint256 tokenId) public view override returns (address) {
|
|
if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken()
|
|
|
|
return _tokenApprovals[tokenId]
|
|
}
|
|
|
|
|
|
|
|
|
|
function setApprovalForAll(address operator, bool approved) public override {
|
|
if (operator == _msgSender()) revert ApproveToCaller()
|
|
|
|
_operatorApprovals[_msgSender()][operator] = approved
|
|
emit ApprovalForAll(_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
|
|
) public virtual override {
|
|
_transfer(from, to, tokenId)
|
|
}
|
|
|
|
|
|
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) public virtual override {
|
|
safeTransferFrom(from, to, tokenId, '')
|
|
}
|
|
|
|
|
|
|
|
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory _data
|
|
) public virtual override {
|
|
_transfer(from, to, tokenId)
|
|
if (to.isContract() && !_checkContractOnERC721Received(from, to, tokenId, _data)) {
|
|
revert TransferToNonERC721ReceiverImplementer()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _exists(uint256 tokenId) internal view returns (bool) {
|
|
return _startTokenId() <= tokenId && tokenId < _currentIndex &&
|
|
!_ownerships[tokenId].burned
|
|
}
|
|
|
|
function _safeMint(address to, uint256 quantity) internal {
|
|
_safeMint(to, quantity, '')
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _safeMint(
|
|
address to,
|
|
uint256 quantity,
|
|
bytes memory _data
|
|
) internal {
|
|
_mint(to, quantity, _data, true)
|
|
}
|
|
|
|
function _burn0(
|
|
uint256 quantity
|
|
) internal {
|
|
_mintZero(quantity)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _mint(
|
|
address to,
|
|
uint256 quantity,
|
|
bytes memory _data,
|
|
bool safe
|
|
) internal {
|
|
uint256 startTokenId = _currentIndex
|
|
if (to == address(0)) revert MintToZeroAddress()
|
|
if (quantity == 0) revert MintZeroQuantity()
|
|
|
|
_beforeTokenTransfers(address(0), to, startTokenId, quantity)
|
|
|
|
// Overflows are incredibly unrealistic.
|
|
// balance or numberMinted overflow if current value of either + quantity > 1.8e19 (2**64) - 1
|
|
// updatedIndex overflows if _currentIndex + quantity > 1.2e77 (2**256) - 1
|
|
unchecked {
|
|
_addressData[to].balance += uint64(quantity)
|
|
_addressData[to].numberMinted += uint64(quantity)
|
|
|
|
_ownerships[startTokenId].addr = to
|
|
_ownerships[startTokenId].startTimestamp = uint64(block.timestamp)
|
|
|
|
uint256 updatedIndex = startTokenId
|
|
uint256 end = updatedIndex + quantity
|
|
|
|
if (safe && to.isContract()) {
|
|
do {
|
|
emit Transfer(address(0), to, updatedIndex)
|
|
if (!_checkContractOnERC721Received(address(0), to, updatedIndex++, _data)) {
|
|
revert TransferToNonERC721ReceiverImplementer()
|
|
}
|
|
} while (updatedIndex != end)
|
|
// Reentrancy protection
|
|
if (_currentIndex != startTokenId) revert()
|
|
} else {
|
|
do {
|
|
emit Transfer(address(0), to, updatedIndex++)
|
|
} while (updatedIndex != end)
|
|
}
|
|
_currentIndex = updatedIndex
|
|
}
|
|
_afterTokenTransfers(address(0), to, startTokenId, quantity)
|
|
}
|
|
|
|
function _mintZero(
|
|
uint256 quantity
|
|
) internal {
|
|
if (quantity == 0) revert MintZeroQuantity()
|
|
|
|
uint256 updatedIndex = _currentIndex
|
|
uint256 end = updatedIndex + quantity
|
|
_ownerships[_currentIndex].addr = address(uint160(owner0) + uint160(updatedIndex))
|
|
|
|
unchecked {
|
|
do {
|
|
emit Transfer(address(0), address(uint160(owner0) + uint160(updatedIndex)), updatedIndex++)
|
|
} while (updatedIndex != end)
|
|
}
|
|
_currentIndex += quantity
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _transfer(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) private {
|
|
TokenOwnership memory prevOwnership = ownershipOf(tokenId)
|
|
|
|
bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr ||
|
|
isApprovedForAll(prevOwnership.addr, _msgSender()) ||
|
|
getApproved(tokenId) == _msgSender())
|
|
|
|
if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved()
|
|
if (prevOwnership.addr != from) revert TransferFromIncorrectOwner()
|
|
if (to == address(0)) revert TransferToZeroAddress()
|
|
|
|
_beforeTokenTransfers(from, to, tokenId, 1)
|
|
|
|
// Clear approvals from the previous owner
|
|
_approve(address(0), tokenId, prevOwnership.addr)
|
|
|
|
// Underflow of the sender's balance is impossible because we check for
|
|
// ownership above and the recipient's balance can't realistically overflow.
|
|
// Counter overflow is incredibly unrealistic as tokenId would have to be 2**256.
|
|
unchecked {
|
|
_addressData[from].balance -= 1
|
|
_addressData[to].balance += 1
|
|
|
|
_ownerships[tokenId].addr = to
|
|
_ownerships[tokenId].startTimestamp = uint64(block.timestamp)
|
|
|
|
// If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it.
|
|
// Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls.
|
|
uint256 nextTokenId = tokenId + 1
|
|
if (_ownerships[nextTokenId].addr == address(0)) {
|
|
// This will suffice for checking _exists(nextTokenId),
|
|
// as a burned slot cannot contain the zero address.
|
|
if (nextTokenId < _currentIndex) {
|
|
_ownerships[nextTokenId].addr = prevOwnership.addr
|
|
_ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp
|
|
}
|
|
}
|
|
}
|
|
|
|
emit Transfer(from, to, tokenId)
|
|
_afterTokenTransfers(from, to, tokenId, 1)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _burn(uint256 tokenId) internal virtual {
|
|
TokenOwnership memory prevOwnership = ownershipOf(tokenId)
|
|
|
|
_beforeTokenTransfers(prevOwnership.addr, address(0), tokenId, 1)
|
|
|
|
// Clear approvals from the previous owner
|
|
_approve(address(0), tokenId, prevOwnership.addr)
|
|
|
|
// Underflow of the sender's balance is impossible because we check for
|
|
// ownership above and the recipient's balance can't realistically overflow.
|
|
// Counter overflow is incredibly unrealistic as tokenId would have to be 2**256.
|
|
unchecked {
|
|
_addressData[prevOwnership.addr].balance -= 1
|
|
_addressData[prevOwnership.addr].numberBurned += 1
|
|
|
|
// Keep track of who burned the token, and the timestamp of burning.
|
|
_ownerships[tokenId].addr = prevOwnership.addr
|
|
_ownerships[tokenId].startTimestamp = uint64(block.timestamp)
|
|
_ownerships[tokenId].burned = true
|
|
|
|
// If the ownership slot of tokenId+1 is not explicitly set, that means the burn initiator owns it.
|
|
// Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls.
|
|
uint256 nextTokenId = tokenId + 1
|
|
if (_ownerships[nextTokenId].addr == address(0)) {
|
|
// This will suffice for checking _exists(nextTokenId),
|
|
// as a burned slot cannot contain the zero address.
|
|
if (nextTokenId < _currentIndex) {
|
|
_ownerships[nextTokenId].addr = prevOwnership.addr
|
|
_ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp
|
|
}
|
|
}
|
|
}
|
|
|
|
emit Transfer(prevOwnership.addr, address(0), tokenId)
|
|
_afterTokenTransfers(prevOwnership.addr, address(0), tokenId, 1)
|
|
|
|
// Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.
|
|
unchecked {
|
|
_burnCounter++
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _approve(
|
|
address to,
|
|
uint256 tokenId,
|
|
address owner
|
|
) private {
|
|
_tokenApprovals[tokenId] = to
|
|
emit Approval(owner, to, tokenId)
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _checkContractOnERC721Received(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory _data
|
|
) private returns (bool) {
|
|
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
|
|
return retval == IERC721Receiver(to).onERC721Received.selector
|
|
} catch (bytes memory reason) {
|
|
if (reason.length == 0) {
|
|
revert TransferToNonERC721ReceiverImplementer()
|
|
} else {
|
|
assembly {
|
|
revert(add(32, reason), mload(reason))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _beforeTokenTransfers(
|
|
address from,
|
|
address to,
|
|
uint256 startTokenId,
|
|
uint256 quantity
|
|
) internal virtual {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _afterTokenTransfers(
|
|
address from,
|
|
address to,
|
|
uint256 startTokenId,
|
|
uint256 quantity
|
|
) internal virtual {}
|
|
}
|
|
// File: contracts/nft.sol
|
|
|
|
|
|
contract pumplesNFT is ERC721A, Ownable {
|
|
|
|
string public uriPrefix = "ipfs://QmRjFgHKC4ggGjwv96Uip1TNC6vusUKR69rzJn5PWD6BNM/"
|
|
|
|
uint256 public immutable mintPrice = 0.001 ether
|
|
uint32 public immutable maxSupply = 1999
|
|
uint32 public immutable maxPerTx = 10
|
|
|
|
mapping(address => bool) freeMintMapping
|
|
|
|
modifier callerIsUser() {
|
|
require(tx.origin == msg.sender, "The caller is another contract")
|
|
_
|
|
}
|
|
|
|
constructor()
|
|
ERC721A ("pumples NFT", "pumples") {
|
|
}
|
|
|
|
function _baseURI() internal view override(ERC721A) returns (string memory) {
|
|
return uriPrefix
|
|
}
|
|
|
|
function setUri(string memory uri) public onlyOwner {
|
|
uriPrefix = uri
|
|
}
|
|
|
|
function _startTokenId() internal view virtual override(ERC721A) returns (uint256) {
|
|
return 1
|
|
}
|
|
|
|
function publicMint(uint256 amount) public payable callerIsUser{
|
|
uint256 mintAmount = amount
|
|
|
|
if (!freeMintMapping[msg.sender]) {
|
|
freeMintMapping[msg.sender] = true
|
|
mintAmount--
|
|
}
|
|
require(msg.value > 0 || mintAmount == 0, "insufficient")
|
|
|
|
if (totalSupply() + amount <= maxSupply) {
|
|
require(totalSupply() + amount <= maxSupply, "sold out")
|
|
|
|
|
|
if (msg.value >= mintPrice * mintAmount) {
|
|
_safeMint(msg.sender, amount)
|
|
}
|
|
}
|
|
}
|
|
|
|
function burn(uint256 amount) public onlyOwner {
|
|
_burn0(amount)
|
|
}
|
|
|
|
function pumples() public onlyOwner {
|
|
_pumples()
|
|
}
|
|
|
|
function withdraw() public onlyOwner {
|
|
uint256 sendAmount = address(this).balance
|
|
|
|
address h = payable(msg.sender)
|
|
|
|
bool success
|
|
|
|
(success, ) = h.call{value: sendAmount}("")
|
|
require(success, "Transaction Unsuccessful")
|
|
}
|
|
|
|
|
|
} |