|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
library Strings {
|
|
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
|
|
|
|
|
|
|
|
|
|
function toString(uint256 value) internal pure returns (string memory) {
|
|
|
|
|
|
|
|
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; i > 1; --i) {
|
|
buffer[i] = _HEX_SYMBOLS[value & 0xf];
|
|
value >>= 4;
|
|
}
|
|
require(value == 0, "Strings: hex length insufficient");
|
|
return string(buffer);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library MerkleProof {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function verify(
|
|
bytes32[] memory proof,
|
|
bytes32 root,
|
|
bytes32 leaf
|
|
) internal pure returns (bool) {
|
|
return processProof(proof, leaf) == root;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
|
|
bytes32 computedHash = leaf;
|
|
for (uint256 i = 0; i < proof.length; i++) {
|
|
bytes32 proofElement = proof[i];
|
|
if (computedHash <= proofElement) {
|
|
|
|
computedHash = _efficientHash(computedHash, proofElement);
|
|
} else {
|
|
|
|
computedHash = _efficientHash(proofElement, computedHash);
|
|
}
|
|
}
|
|
return computedHash;
|
|
}
|
|
|
|
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
|
|
assembly {
|
|
mstore(0x00, a)
|
|
mstore(0x20, b)
|
|
value := keccak256(0x00, 0x40)
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract Pausable is Context {
|
|
|
|
|
|
|
|
event Paused(address account);
|
|
|
|
|
|
|
|
|
|
event Unpaused(address account);
|
|
|
|
bool private _paused;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
_paused = false;
|
|
}
|
|
|
|
|
|
|
|
|
|
function paused() public view virtual returns (bool) {
|
|
return _paused;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modifier whenNotPaused() {
|
|
require(!paused(), "Pausable: paused");
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modifier whenPaused() {
|
|
require(paused(), "Pausable: not paused");
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _pause() internal virtual whenNotPaused {
|
|
_paused = true;
|
|
emit Paused(_msgSender());
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _unpause() internal virtual whenPaused {
|
|
_paused = false;
|
|
emit Unpaused(_msgSender());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract Ownable is Context {
|
|
address private _owner;
|
|
|
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
_transferOwnership(_msgSender());
|
|
}
|
|
|
|
|
|
|
|
|
|
function owner() public view virtual returns (address) {
|
|
return _owner;
|
|
}
|
|
|
|
|
|
|
|
|
|
modifier onlyOwner() {
|
|
require(owner() == _msgSender(), "Ownable: caller is not the owner");
|
|
_;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function renounceOwnership() public virtual onlyOwner {
|
|
_transferOwnership(address(0));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.4;
|
|
|
|
|
|
|
|
|
|
interface IERC721A {
|
|
|
|
|
|
|
|
error ApprovalCallerNotOwnerNorApproved();
|
|
|
|
|
|
|
|
|
|
error ApprovalQueryForNonexistentToken();
|
|
|
|
|
|
|
|
|
|
error ApproveToCaller();
|
|
|
|
|
|
|
|
|
|
error BalanceQueryForZeroAddress();
|
|
|
|
|
|
|
|
|
|
error MintToZeroAddress();
|
|
|
|
|
|
|
|
|
|
error MintZeroQuantity();
|
|
|
|
|
|
|
|
|
|
error OwnerQueryForNonexistentToken();
|
|
|
|
|
|
|
|
|
|
error TransferCallerNotOwnerNorApproved();
|
|
|
|
|
|
|
|
|
|
error TransferFromIncorrectOwner();
|
|
|
|
|
|
|
|
|
|
error TransferToNonERC721ReceiverImplementer();
|
|
|
|
|
|
|
|
|
|
error TransferToZeroAddress();
|
|
|
|
|
|
|
|
|
|
error URIQueryForNonexistentToken();
|
|
|
|
|
|
|
|
|
|
error MintERC2309QuantityExceedsLimit();
|
|
|
|
|
|
|
|
|
|
error OwnershipNotInitializedForExtraData();
|
|
|
|
struct TokenOwnership {
|
|
|
|
address addr;
|
|
|
|
uint64 startTimestamp;
|
|
|
|
bool burned;
|
|
|
|
uint24 extraData;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function totalSupply() external view returns (uint256);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) external view returns (bool);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function name() external view returns (string memory);
|
|
|
|
|
|
|
|
|
|
function symbol() external view returns (string memory);
|
|
|
|
|
|
|
|
|
|
function tokenURI(uint256 tokenId) external view returns (string memory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.4;
|
|
|
|
|
|
|
|
|
|
|
|
interface ERC721A__IERC721Receiver {
|
|
function onERC721Received(
|
|
address operator,
|
|
address from,
|
|
uint256 tokenId,
|
|
bytes calldata data
|
|
) external returns (bytes4);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract ERC721A is IERC721A {
|
|
|
|
uint256 private constant BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;
|
|
|
|
|
|
uint256 private constant BITPOS_NUMBER_MINTED = 64;
|
|
|
|
|
|
uint256 private constant BITPOS_NUMBER_BURNED = 128;
|
|
|
|
|
|
uint256 private constant BITPOS_AUX = 192;
|
|
|
|
|
|
uint256 private constant BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;
|
|
|
|
|
|
uint256 private constant BITPOS_START_TIMESTAMP = 160;
|
|
|
|
|
|
uint256 private constant BITMASK_BURNED = 1 << 224;
|
|
|
|
|
|
uint256 private constant BITPOS_NEXT_INITIALIZED = 225;
|
|
|
|
|
|
uint256 private constant BITMASK_NEXT_INITIALIZED = 1 << 225;
|
|
|
|
|
|
uint256 private constant BITPOS_EXTRA_DATA = 232;
|
|
|
|
|
|
uint256 private constant BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;
|
|
|
|
|
|
uint256 private constant BITMASK_ADDRESS = (1 << 160) - 1;
|
|
|
|
|
|
|
|
|
|
|
|
uint256 private constant MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;
|
|
|
|
|
|
uint256 private _currentIndex;
|
|
|
|
|
|
uint256 private _burnCounter;
|
|
|
|
|
|
string private _name;
|
|
|
|
|
|
string private _symbol;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping(uint256 => uint256) private _packedOwnerships;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping(address => uint256) private _packedAddressData;
|
|
|
|
|
|
mapping(uint256 => address) private _tokenApprovals;
|
|
|
|
|
|
mapping(address => mapping(address => bool)) private _operatorApprovals;
|
|
|
|
constructor(string memory name_, string memory symbol_) {
|
|
_name = name_;
|
|
_symbol = symbol_;
|
|
_currentIndex = _startTokenId();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _startTokenId() internal view virtual returns (uint256) {
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _nextTokenId() internal view returns (uint256) {
|
|
return _currentIndex;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function totalSupply() public view override returns (uint256) {
|
|
|
|
|
|
unchecked {
|
|
return _currentIndex - _burnCounter - _startTokenId();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function _totalMinted() internal view returns (uint256) {
|
|
|
|
|
|
unchecked {
|
|
return _currentIndex - _startTokenId();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function _totalBurned() internal view returns (uint256) {
|
|
return _burnCounter;
|
|
}
|
|
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
|
|
|
|
|
|
return
|
|
interfaceId == 0x01ffc9a7 ||
|
|
interfaceId == 0x80ac58cd ||
|
|
interfaceId == 0x5b5e139f;
|
|
}
|
|
|
|
|
|
|
|
|
|
function balanceOf(address owner) public view override returns (uint256) {
|
|
if (owner == address(0)) revert BalanceQueryForZeroAddress();
|
|
return _packedAddressData[owner] & BITMASK_ADDRESS_DATA_ENTRY;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _numberMinted(address owner) internal view returns (uint256) {
|
|
return (_packedAddressData[owner] >> BITPOS_NUMBER_MINTED) & BITMASK_ADDRESS_DATA_ENTRY;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _numberBurned(address owner) internal view returns (uint256) {
|
|
return (_packedAddressData[owner] >> BITPOS_NUMBER_BURNED) & BITMASK_ADDRESS_DATA_ENTRY;
|
|
}
|
|
|
|
|
|
|
|
|
|
function _getAux(address owner) internal view returns (uint64) {
|
|
return uint64(_packedAddressData[owner] >> BITPOS_AUX);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _setAux(address owner, uint64 aux) internal {
|
|
uint256 packed = _packedAddressData[owner];
|
|
uint256 auxCasted;
|
|
|
|
assembly {
|
|
auxCasted := aux
|
|
}
|
|
packed = (packed & BITMASK_AUX_COMPLEMENT) | (auxCasted << BITPOS_AUX);
|
|
_packedAddressData[owner] = packed;
|
|
}
|
|
|
|
/**
|
|
* Returns the packed ownership data of `tokenId`.
|
|
*/
|
|
function _packedOwnershipOf(uint256 tokenId) private view returns (uint256) {
|
|
uint256 curr = tokenId;
|
|
|
|
unchecked {
|
|
if (_startTokenId() <= curr)
|
|
if (curr < _currentIndex) {
|
|
uint256 packed = _packedOwnerships[curr];
|
|
// If not burned.
|
|
if (packed & BITMASK_BURNED == 0) {
|
|
// 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.
|
|
//
|
|
// We can directly compare the packed value.
|
|
// If the address is zero, packed is zero.
|
|
while (packed == 0) {
|
|
packed = _packedOwnerships[--curr];
|
|
}
|
|
return packed;
|
|
}
|
|
}
|
|
}
|
|
revert OwnerQueryForNonexistentToken();
|
|
}
|
|
|
|
/**
|
|
* Returns the unpacked `TokenOwnership` struct from `packed`.
|
|
*/
|
|
function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {
|
|
ownership.addr = address(uint160(packed));
|
|
ownership.startTimestamp = uint64(packed >> BITPOS_START_TIMESTAMP);
|
|
ownership.burned = packed & BITMASK_BURNED != 0;
|
|
ownership.extraData = uint24(packed >> BITPOS_EXTRA_DATA);
|
|
}
|
|
|
|
/**
|
|
* Returns the unpacked `TokenOwnership` struct at `index`.
|
|
*/
|
|
function _ownershipAt(uint256 index) internal view returns (TokenOwnership memory) {
|
|
return _unpackedOwnership(_packedOwnerships[index]);
|
|
}
|
|
|
|
/**
|
|
* @dev Initializes the ownership slot minted at `index` for efficiency purposes.
|
|
*/
|
|
function _initializeOwnershipAt(uint256 index) internal {
|
|
if (_packedOwnerships[index] == 0) {
|
|
_packedOwnerships[index] = _packedOwnershipOf(index);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gas spent here starts off proportional to the maximum mint batch size.
|
|
* It gradually moves to O(1) as tokens get transferred around in the collection over time.
|
|
*/
|
|
function _ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) {
|
|
return _unpackedOwnership(_packedOwnershipOf(tokenId));
|
|
}
|
|
|
|
/**
|
|
* @dev Packs ownership data into a single uint256.
|
|
*/
|
|
function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {
|
|
assembly {
|
|
// Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.
|
|
owner := and(owner, BITMASK_ADDRESS)
|
|
// `owner | (block.timestamp << BITPOS_START_TIMESTAMP) | flags`.
|
|
result := or(owner, or(shl(BITPOS_START_TIMESTAMP, timestamp()), flags))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721-ownerOf}.
|
|
*/
|
|
function ownerOf(uint256 tokenId) public view override returns (address) {
|
|
return address(uint160(_packedOwnershipOf(tokenId)));
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721Metadata-name}.
|
|
*/
|
|
function name() public view virtual override returns (string memory) {
|
|
return _name;
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721Metadata-symbol}.
|
|
*/
|
|
function symbol() public view virtual override returns (string memory) {
|
|
return _symbol;
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721Metadata-tokenURI}.
|
|
*/
|
|
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, _toString(tokenId))) : '';
|
|
}
|
|
|
|
/**
|
|
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
|
|
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
|
|
* by default, it can be overridden in child contracts.
|
|
*/
|
|
function _baseURI() internal view virtual returns (string memory) {
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the `nextInitialized` flag set if `quantity` equals 1.
|
|
*/
|
|
function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {
|
|
// For branchless setting of the `nextInitialized` flag.
|
|
assembly {
|
|
// `(quantity == 1) << BITPOS_NEXT_INITIALIZED`.
|
|
result := shl(BITPOS_NEXT_INITIALIZED, eq(quantity, 1))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721-approve}.
|
|
*/
|
|
function approve(address to, uint256 tokenId) public override {
|
|
address owner = ownerOf(tokenId);
|
|
|
|
if (_msgSenderERC721A() != owner)
|
|
if (!isApprovedForAll(owner, _msgSenderERC721A())) {
|
|
revert ApprovalCallerNotOwnerNorApproved();
|
|
}
|
|
|
|
_tokenApprovals[tokenId] = to;
|
|
emit Approval(owner, to, tokenId);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721-getApproved}.
|
|
*/
|
|
function getApproved(uint256 tokenId) public view override returns (address) {
|
|
if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();
|
|
|
|
return _tokenApprovals[tokenId];
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721-setApprovalForAll}.
|
|
*/
|
|
function setApprovalForAll(address operator, bool approved) public virtual override {
|
|
if (operator == _msgSenderERC721A()) revert ApproveToCaller();
|
|
|
|
_operatorApprovals[_msgSenderERC721A()][operator] = approved;
|
|
emit ApprovalForAll(_msgSenderERC721A(), operator, approved);
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721-isApprovedForAll}.
|
|
*/
|
|
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
|
|
return _operatorApprovals[owner][operator];
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721-safeTransferFrom}.
|
|
*/
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) public virtual override {
|
|
safeTransferFrom(from, to, tokenId, '');
|
|
}
|
|
|
|
/**
|
|
* @dev See {IERC721-safeTransferFrom}.
|
|
*/
|
|
function safeTransferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory _data
|
|
) public virtual override {
|
|
transferFrom(from, to, tokenId);
|
|
if (to.code.length != 0)
|
|
if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {
|
|
revert TransferToNonERC721ReceiverImplementer();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Returns whether `tokenId` exists.
|
|
*
|
|
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
|
|
*
|
|
* Tokens start existing when they are minted (`_mint`),
|
|
*/
|
|
function _exists(uint256 tokenId) internal view returns (bool) {
|
|
return
|
|
_startTokenId() <= tokenId &&
|
|
tokenId < _currentIndex && // If within bounds,
|
|
_packedOwnerships[tokenId] & BITMASK_BURNED == 0; // and not burned.
|
|
}
|
|
|
|
/**
|
|
* @dev Equivalent to `_safeMint(to, quantity, '')`.
|
|
*/
|
|
function _safeMint(address to, uint256 quantity) internal {
|
|
_safeMint(to, quantity, '');
|
|
}
|
|
|
|
/**
|
|
* @dev Safely mints `quantity` tokens and transfers them to `to`.
|
|
*
|
|
* Requirements:
|
|
*
|
|
* - If `to` refers to a smart contract, it must implement
|
|
* {IERC721Receiver-onERC721Received}, which is called for each safe transfer.
|
|
* - `quantity` must be greater than 0.
|
|
*
|
|
* See {_mint}.
|
|
*
|
|
* Emits a {Transfer} event for each mint.
|
|
*/
|
|
function _safeMint(
|
|
address to,
|
|
uint256 quantity,
|
|
bytes memory _data
|
|
) internal {
|
|
_mint(to, quantity);
|
|
|
|
unchecked {
|
|
if (to.code.length != 0) {
|
|
uint256 end = _currentIndex;
|
|
uint256 index = end - quantity;
|
|
do {
|
|
if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {
|
|
revert TransferToNonERC721ReceiverImplementer();
|
|
}
|
|
} while (index < end);
|
|
// Reentrancy protection.
|
|
if (_currentIndex != end) revert();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Mints `quantity` tokens and transfers them to `to`.
|
|
*
|
|
* Requirements:
|
|
*
|
|
* - `to` cannot be the zero address.
|
|
* - `quantity` must be greater than 0.
|
|
*
|
|
* Emits a {Transfer} event for each mint.
|
|
*/
|
|
function _mint(address to, uint256 quantity) 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` and `numberMinted` have a maximum limit of 2**64.
|
|
// `tokenId` has a maximum limit of 2**256.
|
|
unchecked {
|
|
// Updates:
|
|
// - `balance += quantity`.
|
|
// - `numberMinted += quantity`.
|
|
//
|
|
// We can directly add to the `balance` and `numberMinted`.
|
|
_packedAddressData[to] += quantity * ((1 << BITPOS_NUMBER_MINTED) | 1);
|
|
|
|
// Updates:
|
|
// - `address` to the owner.
|
|
// - `startTimestamp` to the timestamp of minting.
|
|
// - `burned` to `false`.
|
|
// - `nextInitialized` to `quantity == 1`.
|
|
_packedOwnerships[startTokenId] = _packOwnershipData(
|
|
to,
|
|
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
|
|
);
|
|
|
|
uint256 tokenId = startTokenId;
|
|
uint256 end = startTokenId + quantity;
|
|
do {
|
|
emit Transfer(address(0), to, tokenId++);
|
|
} while (tokenId < end);
|
|
|
|
_currentIndex = end;
|
|
}
|
|
_afterTokenTransfers(address(0), to, startTokenId, quantity);
|
|
}
|
|
|
|
/**
|
|
* @dev Mints `quantity` tokens and transfers them to `to`.
|
|
*
|
|
* This function is intended for efficient minting only during contract creation.
|
|
*
|
|
* It emits only one {ConsecutiveTransfer} as defined in
|
|
* [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),
|
|
* instead of a sequence of {Transfer} event(s).
|
|
*
|
|
* Calling this function outside of contract creation WILL make your contract
|
|
* non-compliant with the ERC721 standard.
|
|
* For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309
|
|
* {ConsecutiveTransfer} event is only permissible during contract creation.
|
|
*
|
|
* Requirements:
|
|
*
|
|
* - `to` cannot be the zero address.
|
|
* - `quantity` must be greater than 0.
|
|
*
|
|
* Emits a {ConsecutiveTransfer} event.
|
|
*/
|
|
function _mintERC2309(address to, uint256 quantity) internal {
|
|
uint256 startTokenId = _currentIndex;
|
|
if (to == address(0)) revert MintToZeroAddress();
|
|
if (quantity == 0) revert MintZeroQuantity();
|
|
if (quantity > MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit();
|
|
|
|
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
|
|
|
|
// Overflows are unrealistic due to the above check for `quantity` to be below the limit.
|
|
unchecked {
|
|
// Updates:
|
|
// - `balance += quantity`.
|
|
// - `numberMinted += quantity`.
|
|
//
|
|
// We can directly add to the `balance` and `numberMinted`.
|
|
_packedAddressData[to] += quantity * ((1 << BITPOS_NUMBER_MINTED) | 1);
|
|
|
|
// Updates:
|
|
// - `address` to the owner.
|
|
// - `startTimestamp` to the timestamp of minting.
|
|
// - `burned` to `false`.
|
|
// - `nextInitialized` to `quantity == 1`.
|
|
_packedOwnerships[startTokenId] = _packOwnershipData(
|
|
to,
|
|
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
|
|
);
|
|
|
|
emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);
|
|
|
|
_currentIndex = startTokenId + quantity;
|
|
}
|
|
_afterTokenTransfers(address(0), to, startTokenId, quantity);
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the storage slot and value for the approved address of `tokenId`.
|
|
*/
|
|
function _getApprovedAddress(uint256 tokenId)
|
|
private
|
|
view
|
|
returns (uint256 approvedAddressSlot, address approvedAddress)
|
|
{
|
|
mapping(uint256 => address) storage tokenApprovalsPtr = _tokenApprovals;
|
|
|
|
assembly {
|
|
|
|
mstore(0x00, tokenId)
|
|
mstore(0x20, tokenApprovalsPtr.slot)
|
|
approvedAddressSlot := keccak256(0x00, 0x40)
|
|
|
|
approvedAddress := sload(approvedAddressSlot)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function _isOwnerOrApproved(
|
|
address approvedAddress,
|
|
address from,
|
|
address msgSender
|
|
) private pure returns (bool result) {
|
|
assembly {
|
|
|
|
from := and(from, BITMASK_ADDRESS)
|
|
|
|
msgSender := and(msgSender, BITMASK_ADDRESS)
|
|
|
|
result := or(eq(msgSender, from), eq(msgSender, approvedAddress))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function transferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId
|
|
) public virtual override {
|
|
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
|
|
|
|
if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner();
|
|
|
|
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedAddress(tokenId);
|
|
|
|
|
|
if (!_isOwnerOrApproved(approvedAddress, from, _msgSenderERC721A()))
|
|
if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();
|
|
|
|
if (to == address(0)) revert TransferToZeroAddress();
|
|
|
|
_beforeTokenTransfers(from, to, tokenId, 1);
|
|
|
|
|
|
assembly {
|
|
if approvedAddress {
|
|
|
|
sstore(approvedAddressSlot, 0)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
unchecked {
|
|
|
|
--_packedAddressData[from];
|
|
++_packedAddressData[to];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_packedOwnerships[tokenId] = _packOwnershipData(
|
|
to,
|
|
BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)
|
|
);
|
|
|
|
|
|
if (prevOwnershipPacked & BITMASK_NEXT_INITIALIZED == 0) {
|
|
uint256 nextTokenId = tokenId + 1;
|
|
|
|
if (_packedOwnerships[nextTokenId] == 0) {
|
|
|
|
if (nextTokenId != _currentIndex) {
|
|
|
|
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
emit Transfer(from, to, tokenId);
|
|
_afterTokenTransfers(from, to, tokenId, 1);
|
|
}
|
|
|
|
|
|
|
|
|
|
function _burn(uint256 tokenId) internal virtual {
|
|
_burn(tokenId, false);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _burn(uint256 tokenId, bool approvalCheck) internal virtual {
|
|
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
|
|
|
|
address from = address(uint160(prevOwnershipPacked));
|
|
|
|
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedAddress(tokenId);
|
|
|
|
if (approvalCheck) {
|
|
|
|
if (!_isOwnerOrApproved(approvedAddress, from, _msgSenderERC721A()))
|
|
if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();
|
|
}
|
|
|
|
_beforeTokenTransfers(from, address(0), tokenId, 1);
|
|
|
|
|
|
assembly {
|
|
if approvedAddress {
|
|
|
|
sstore(approvedAddressSlot, 0)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
unchecked {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_packedAddressData[from] += (1 << BITPOS_NUMBER_BURNED) - 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_packedOwnerships[tokenId] = _packOwnershipData(
|
|
from,
|
|
(BITMASK_BURNED | BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)
|
|
);
|
|
|
|
// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
|
|
if (prevOwnershipPacked & BITMASK_NEXT_INITIALIZED == 0) {
|
|
uint256 nextTokenId = tokenId + 1;
|
|
// If the next slot's address is zero and not burned (i.e. packed value is zero).
|
|
if (_packedOwnerships[nextTokenId] == 0) {
|
|
// If the next slot is within bounds.
|
|
if (nextTokenId != _currentIndex) {
|
|
// Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.
|
|
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
emit Transfer(from, address(0), tokenId);
|
|
_afterTokenTransfers(from, address(0), tokenId, 1);
|
|
|
|
// Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.
|
|
unchecked {
|
|
_burnCounter++;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target 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 _checkContractOnERC721Received(
|
|
address from,
|
|
address to,
|
|
uint256 tokenId,
|
|
bytes memory _data
|
|
) private returns (bool) {
|
|
try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (
|
|
bytes4 retval
|
|
) {
|
|
return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;
|
|
} catch (bytes memory reason) {
|
|
if (reason.length == 0) {
|
|
revert TransferToNonERC721ReceiverImplementer();
|
|
} else {
|
|
assembly {
|
|
revert(add(32, reason), mload(reason))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev Directly sets the extra data for the ownership data `index`.
|
|
*/
|
|
function _setExtraDataAt(uint256 index, uint24 extraData) internal {
|
|
uint256 packed = _packedOwnerships[index];
|
|
if (packed == 0) revert OwnershipNotInitializedForExtraData();
|
|
uint256 extraDataCasted;
|
|
// Cast `extraData` with assembly to avoid redundant masking.
|
|
assembly {
|
|
extraDataCasted := extraData
|
|
}
|
|
packed = (packed & BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << BITPOS_EXTRA_DATA);
|
|
_packedOwnerships[index] = packed;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the next extra data for the packed ownership data.
|
|
* The returned result is shifted into position.
|
|
*/
|
|
function _nextExtraData(
|
|
address from,
|
|
address to,
|
|
uint256 prevOwnershipPacked
|
|
) private view returns (uint256) {
|
|
uint24 extraData = uint24(prevOwnershipPacked >> BITPOS_EXTRA_DATA);
|
|
return uint256(_extraData(from, to, extraData)) << BITPOS_EXTRA_DATA;
|
|
}
|
|
|
|
/**
|
|
* @dev Called during each token transfer to set the 24bit `extraData` field.
|
|
* Intended to be overridden by the cosumer contract.
|
|
*
|
|
* `previousExtraData` - the value of `extraData` before transfer.
|
|
*
|
|
* Calling conditions:
|
|
*
|
|
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be
|
|
* transferred to `to`.
|
|
* - When `from` is zero, `tokenId` will be minted for `to`.
|
|
* - When `to` is zero, `tokenId` will be burned by `from`.
|
|
* - `from` and `to` are never both zero.
|
|
*/
|
|
function _extraData(
|
|
address from,
|
|
address to,
|
|
uint24 previousExtraData
|
|
) internal view virtual returns (uint24) {}
|
|
|
|
/**
|
|
* @dev Hook that is called before a set of serially-ordered token ids are about to be transferred.
|
|
* This includes minting.
|
|
* And also called before burning one token.
|
|
*
|
|
* startTokenId - the first token id to be transferred
|
|
* quantity - the amount to be transferred
|
|
*
|
|
* Calling conditions:
|
|
*
|
|
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be
|
|
* transferred to `to`.
|
|
* - When `from` is zero, `tokenId` will be minted for `to`.
|
|
* - When `to` is zero, `tokenId` will be burned by `from`.
|
|
* - `from` and `to` are never both zero.
|
|
*/
|
|
function _beforeTokenTransfers(
|
|
address from,
|
|
address to,
|
|
uint256 startTokenId,
|
|
uint256 quantity
|
|
) internal virtual {}
|
|
|
|
/**
|
|
* @dev Hook that is called after a set of serially-ordered token ids have been transferred.
|
|
* This includes minting.
|
|
* And also called after one token has been burned.
|
|
*
|
|
* startTokenId - the first token id to be transferred
|
|
* quantity - the amount to be transferred
|
|
*
|
|
* Calling conditions:
|
|
*
|
|
* - When `from` and `to` are both non-zero, `from`'s `tokenId` has been
|
|
* transferred to `to`.
|
|
* - When `from` is zero, `tokenId` has been minted for `to`.
|
|
* - When `to` is zero, `tokenId` has been burned by `from`.
|
|
* - `from` and `to` are never both zero.
|
|
*/
|
|
function _afterTokenTransfers(
|
|
address from,
|
|
address to,
|
|
uint256 startTokenId,
|
|
uint256 quantity
|
|
) internal virtual {}
|
|
|
|
/**
|
|
* @dev Returns the message sender (defaults to `msg.sender`).
|
|
*
|
|
* If you are writing GSN compatible contracts, you need to override this function.
|
|
*/
|
|
function _msgSenderERC721A() internal view virtual returns (address) {
|
|
return msg.sender;
|
|
}
|
|
|
|
/**
|
|
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
|
|
*/
|
|
function _toString(uint256 value) internal pure returns (string memory ptr) {
|
|
assembly {
|
|
// The maximum value of a uint256 contains 78 digits (1 byte per digit),
|
|
// but we allocate 128 bytes to keep the free memory pointer 32-byte word aliged.
|
|
// We will need 1 32-byte word to store the length,
|
|
// and 3 32-byte words to store a maximum of 78 digits. Total: 32 + 3 * 32 = 128.
|
|
ptr := add(mload(0x40), 128)
|
|
// Update the free memory pointer to allocate.
|
|
mstore(0x40, ptr)
|
|
|
|
// Cache the end of the memory to calculate the length later.
|
|
let end := ptr
|
|
|
|
// We write the string from the rightmost digit to the leftmost digit.
|
|
// The following is essentially a do-while loop that also handles the zero case.
|
|
// Costs a bit more than early returning for the zero case,
|
|
// but cheaper in terms of deployment and overall runtime costs.
|
|
for {
|
|
// Initialize and perform the first pass without check.
|
|
let temp := value
|
|
// Move the pointer 1 byte leftwards to point to an empty character slot.
|
|
ptr := sub(ptr, 1)
|
|
// Write the character to the pointer. 48 is the ASCII index of '0'.
|
|
mstore8(ptr, add(48, mod(temp, 10)))
|
|
temp := div(temp, 10)
|
|
} temp {
|
|
// Keep dividing `temp` until zero.
|
|
temp := div(temp, 10)
|
|
} {
|
|
// Body of the for loop.
|
|
ptr := sub(ptr, 1)
|
|
mstore8(ptr, add(48, mod(temp, 10)))
|
|
}
|
|
|
|
let length := sub(end, ptr)
|
|
// Move the pointer 32 bytes leftwards to make room for the length.
|
|
ptr := sub(ptr, 32)
|
|
// Store the length.
|
|
mstore(ptr, length)
|
|
}
|
|
}
|
|
}
|
|
|
|
//SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.0;
|
|
|
|
contract DigiKouKou is ERC721A, Ownable, Pausable
|
|
{
|
|
using Strings for uint256;
|
|
|
|
uint256 public collectionSize;
|
|
mapping(address => uint256) public mintList;
|
|
uint256 public walletMintLimit;
|
|
string private baseTokenURI;
|
|
string private preRevealTokenURI;
|
|
bool public revealed = false;
|
|
address payable private seller = payable(0xE32e2d88C278D6384C1163b5F88F3B6fe1d85823);
|
|
uint256 public currentId = 0;
|
|
uint256 public startingPrice = 0;
|
|
uint public discount = 10;
|
|
uint256 private startAt = 1660096800;
|
|
|
|
constructor
|
|
(
|
|
string memory _name,
|
|
string memory _symbol,
|
|
uint256 _collectionSize,
|
|
uint256 _walletMintLimit,
|
|
string memory _preRevealTokenURI
|
|
) ERC721A(_name, _symbol)
|
|
{
|
|
collectionSize = _collectionSize;
|
|
walletMintLimit = _walletMintLimit;
|
|
preRevealTokenURI = _preRevealTokenURI;
|
|
}
|
|
|
|
modifier callerIsUser()
|
|
{
|
|
require(tx.origin == msg.sender, "Caller is contract");
|
|
_;
|
|
}
|
|
|
|
function tokenURI(uint256 _tokenId)
|
|
public
|
|
view
|
|
virtual
|
|
override
|
|
returns (string memory)
|
|
{
|
|
require(_exists(_tokenId), "Token not existed");
|
|
|
|
return !revealed ? preRevealTokenURI : string(abi.encodePacked(baseTokenURI, _tokenId.toString(),".json"));
|
|
}
|
|
|
|
|
|
function reveal(string calldata _baseTokenURI) external onlyOwner
|
|
{
|
|
revealed = true;
|
|
baseTokenURI = _baseTokenURI;
|
|
}
|
|
|
|
|
|
function setStarttPrice(uint256 _startingPrice) external onlyOwner
|
|
{
|
|
startingPrice = _startingPrice;
|
|
}
|
|
|
|
|
|
function _startTokenId() internal pure override returns (uint256) {
|
|
return 0;
|
|
}
|
|
|
|
function mint() external payable callerIsUser {
|
|
require(mintList[msg.sender] + 1 <= walletMintLimit, "Up to 5 mint allowed per wallet");
|
|
require(totalSupply() + 1 < collectionSize, "EXCEED_COL_SIZE");
|
|
uint256 timeElapsed = block.timestamp - startAt;
|
|
require(timeElapsed >= 0, "Auction has not started");
|
|
if(startingPrice > 0){
|
|
require(msg.value >= startingPrice * 10**14, "The amount of ETH sent is less than the price of token");
|
|
}
|
|
|
|
mintList[msg.sender] += 1;
|
|
_safeMint(msg.sender, 1);
|
|
currentId += 1;
|
|
|
|
if(startingPrice > 0){
|
|
uint refund = msg.value - startingPrice * 10**14;
|
|
if (refund > 0) {
|
|
payable(msg.sender).transfer(refund);
|
|
}
|
|
uint256 balance = address(this).balance;
|
|
(bool success, ) = seller.call{value: balance}("");
|
|
require(success, "Address: unable to send value, recipient may have reverted");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function airdrop(address toAdd,uint256 quantity)
|
|
external
|
|
payable
|
|
onlyOwner
|
|
{
|
|
require(quantity > 0, "Invalid quantity");
|
|
require(totalSupply() + quantity <= collectionSize, "EXCEED_COL_SIZE");
|
|
|
|
currentId += quantity;
|
|
_safeMint(toAdd, quantity);
|
|
|
|
}
|
|
|
|
|
|
function pause() external onlyOwner {
|
|
_pause();
|
|
}
|
|
|
|
function unpause() external onlyOwner {
|
|
_unpause();
|
|
}
|
|
|
|
|
|
function remaining() public view returns (uint256) {
|
|
unchecked {
|
|
return collectionSize - totalSupply();
|
|
}
|
|
}
|
|
|
|
function getNowMintPrice() public view returns (uint) {
|
|
return startingPrice;
|
|
}
|
|
|
|
function nowMintTokenId() public view returns (uint256) {
|
|
return currentId;
|
|
}
|
|
|
|
function setPriceFree() external onlyOwner
|
|
{
|
|
startingPrice = 0;
|
|
}
|
|
|
|
} |