|
|
|
|
|
|
|
|
|
|
|
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; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() 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.0; |
|
|
|
|
|
|
|
|
|
library Strings { |
|
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; |
|
uint8 private constant _ADDRESS_LENGTH = 20; |
|
|
|
|
|
|
|
|
|
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); |
|
} |
|
|
|
|
|
|
|
|
|
function toHexString(address addr) internal pure returns (string memory) { |
|
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); |
|
} |
|
} |
|
|
|
|
|
|
|
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 verifyCalldata( |
|
bytes32[] calldata proof, |
|
bytes32 root, |
|
bytes32 leaf |
|
) internal pure returns (bool) { |
|
return processProofCalldata(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++) { |
|
computedHash = _hashPair(computedHash, proof[i]); |
|
} |
|
return computedHash; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) { |
|
bytes32 computedHash = leaf; |
|
for (uint256 i = 0; i < proof.length; i++) { |
|
computedHash = _hashPair(computedHash, proof[i]); |
|
} |
|
return computedHash; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function multiProofVerify( |
|
bytes32[] memory proof, |
|
bool[] memory proofFlags, |
|
bytes32 root, |
|
bytes32[] memory leaves |
|
) internal pure returns (bool) { |
|
return processMultiProof(proof, proofFlags, leaves) == root; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function multiProofVerifyCalldata( |
|
bytes32[] calldata proof, |
|
bool[] calldata proofFlags, |
|
bytes32 root, |
|
bytes32[] memory leaves |
|
) internal pure returns (bool) { |
|
return processMultiProofCalldata(proof, proofFlags, leaves) == root; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function processMultiProof( |
|
bytes32[] memory proof, |
|
bool[] memory proofFlags, |
|
bytes32[] memory leaves |
|
) internal pure returns (bytes32 merkleRoot) { |
|
|
|
|
|
|
|
|
|
uint256 leavesLen = leaves.length; |
|
uint256 totalHashes = proofFlags.length; |
|
|
|
|
|
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof"); |
|
|
|
|
|
|
|
bytes32[] memory hashes = new bytes32[](totalHashes); |
|
uint256 leafPos = 0; |
|
uint256 hashPos = 0; |
|
uint256 proofPos = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < totalHashes; i++) { |
|
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; |
|
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; |
|
hashes[i] = _hashPair(a, b); |
|
} |
|
|
|
if (totalHashes > 0) { |
|
return hashes[totalHashes - 1]; |
|
} else if (leavesLen > 0) { |
|
return leaves[0]; |
|
} else { |
|
return proof[0]; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function processMultiProofCalldata( |
|
bytes32[] calldata proof, |
|
bool[] calldata proofFlags, |
|
bytes32[] memory leaves |
|
) internal pure returns (bytes32 merkleRoot) { |
|
|
|
|
|
|
|
|
|
uint256 leavesLen = leaves.length; |
|
uint256 totalHashes = proofFlags.length; |
|
|
|
|
|
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof"); |
|
|
|
|
|
|
|
bytes32[] memory hashes = new bytes32[](totalHashes); |
|
uint256 leafPos = 0; |
|
uint256 hashPos = 0; |
|
uint256 proofPos = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < totalHashes; i++) { |
|
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; |
|
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; |
|
hashes[i] = _hashPair(a, b); |
|
} |
|
|
|
if (totalHashes > 0) { |
|
return hashes[totalHashes - 1]; |
|
} else if (leavesLen > 0) { |
|
return leaves[0]; |
|
} else { |
|
return proof[0]; |
|
} |
|
} |
|
|
|
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) { |
|
return a < b ? _efficientHash(a, b) : _efficientHash(b, a); |
|
} |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library ECDSA { |
|
enum RecoverError { |
|
NoError, |
|
InvalidSignature, |
|
InvalidSignatureLength, |
|
InvalidSignatureS, |
|
InvalidSignatureV |
|
} |
|
|
|
function _throwError(RecoverError error) private pure { |
|
if (error == RecoverError.NoError) { |
|
return; |
|
} else if (error == RecoverError.InvalidSignature) { |
|
revert("ECDSA: invalid signature"); |
|
} else if (error == RecoverError.InvalidSignatureLength) { |
|
revert("ECDSA: invalid signature length"); |
|
} else if (error == RecoverError.InvalidSignatureS) { |
|
revert("ECDSA: invalid signature 's' value"); |
|
} else if (error == RecoverError.InvalidSignatureV) { |
|
revert("ECDSA: invalid signature 'v' value"); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { |
|
|
|
|
|
|
|
if (signature.length == 65) { |
|
bytes32 r; |
|
bytes32 s; |
|
uint8 v; |
|
|
|
|
|
|
|
assembly { |
|
r := mload(add(signature, 0x20)) |
|
s := mload(add(signature, 0x40)) |
|
v := byte(0, mload(add(signature, 0x60))) |
|
} |
|
return tryRecover(hash, v, r, s); |
|
} else if (signature.length == 64) { |
|
bytes32 r; |
|
bytes32 vs; |
|
|
|
|
|
|
|
assembly { |
|
r := mload(add(signature, 0x20)) |
|
vs := mload(add(signature, 0x40)) |
|
} |
|
return tryRecover(hash, r, vs); |
|
} else { |
|
return (address(0), RecoverError.InvalidSignatureLength); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { |
|
(address recovered, RecoverError error) = tryRecover(hash, signature); |
|
_throwError(error); |
|
return recovered; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tryRecover( |
|
bytes32 hash, |
|
bytes32 r, |
|
bytes32 vs |
|
) internal pure returns (address, RecoverError) { |
|
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); |
|
uint8 v = uint8((uint256(vs) >> 255) + 27); |
|
return tryRecover(hash, v, r, s); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function recover( |
|
bytes32 hash, |
|
bytes32 r, |
|
bytes32 vs |
|
) internal pure returns (address) { |
|
(address recovered, RecoverError error) = tryRecover(hash, r, vs); |
|
_throwError(error); |
|
return recovered; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tryRecover( |
|
bytes32 hash, |
|
uint8 v, |
|
bytes32 r, |
|
bytes32 s |
|
) internal pure returns (address, RecoverError) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { |
|
return (address(0), RecoverError.InvalidSignatureS); |
|
} |
|
if (v != 27 && v != 28) { |
|
return (address(0), RecoverError.InvalidSignatureV); |
|
} |
|
|
|
|
|
address signer = ecrecover(hash, v, r, s); |
|
if (signer == address(0)) { |
|
return (address(0), RecoverError.InvalidSignature); |
|
} |
|
|
|
return (signer, RecoverError.NoError); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function recover( |
|
bytes32 hash, |
|
uint8 v, |
|
bytes32 r, |
|
bytes32 s |
|
) internal pure returns (address) { |
|
(address recovered, RecoverError error) = tryRecover(hash, v, r, s); |
|
_throwError(error); |
|
return recovered; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { |
|
|
|
|
|
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { |
|
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { |
|
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); |
|
} |
|
} |
|
|
|
|
|
|
|
pragma solidity ^0.8.0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract contract ReentrancyGuard { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint256 private constant _NOT_ENTERED = 1; |
|
uint256 private constant _ENTERED = 2; |
|
|
|
uint256 private _status; |
|
|
|
constructor() { |
|
_status = _NOT_ENTERED; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modifier nonReentrant() { |
|
|
|
require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); |
|
|
|
|
|
_status = _ENTERED; |
|
|
|
_; |
|
|
|
|
|
|
|
_status = _NOT_ENTERED; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.4; |
|
|
|
|
|
|
|
|
|
interface IERC721A { |
|
|
|
|
|
|
|
error ApprovalCallerNotOwnerNorApproved(); |
|
|
|
|
|
|
|
|
|
error ApprovalQueryForNonexistentToken(); |
|
|
|
|
|
|
|
|
|
error ApproveToCaller(); |
|
|
|
|
|
|
|
|
|
error ApprovalToCurrentOwner(); |
|
|
|
|
|
|
|
|
|
error BalanceQueryForZeroAddress(); |
|
|
|
|
|
|
|
|
|
error MintToZeroAddress(); |
|
|
|
|
|
|
|
|
|
error MintZeroQuantity(); |
|
|
|
|
|
|
|
|
|
error OwnerQueryForNonexistentToken(); |
|
|
|
|
|
|
|
|
|
error TransferCallerNotOwnerNorApproved(); |
|
|
|
|
|
|
|
|
|
error TransferFromIncorrectOwner(); |
|
|
|
|
|
|
|
|
|
error TransferToNonERC721ReceiverImplementer(); |
|
|
|
|
|
|
|
|
|
error TransferToZeroAddress(); |
|
|
|
|
|
|
|
|
|
error URIQueryForNonexistentToken(); |
|
|
|
struct TokenOwnership { |
|
|
|
address addr; |
|
|
|
uint64 startTimestamp; |
|
|
|
bool burned; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 _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 (_addressToUint256(owner) == 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; |
|
} |
|
|
|
/** |
|
* 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 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, can be overriden in child contracts. |
|
*/ |
|
function _baseURI() internal view virtual returns (string memory) { |
|
return ''; |
|
} |
|
|
|
/** |
|
* @dev Casts the address to uint256 without masking. |
|
*/ |
|
function _addressToUint256(address value) private pure returns (uint256 result) { |
|
assembly { |
|
result := value |
|
} |
|
} |
|
|
|
/** |
|
* @dev Casts the boolean to uint256 without branching. |
|
*/ |
|
function _boolToUint256(bool value) private pure returns (uint256 result) { |
|
assembly { |
|
result := value |
|
} |
|
} |
|
|
|
/** |
|
* @dev See {IERC721-approve}. |
|
*/ |
|
function approve(address to, uint256 tokenId) public virtual override { |
|
address owner = address(uint160(_packedOwnershipOf(tokenId))); |
|
if (to == owner) revert ApprovalToCurrentOwner(); |
|
|
|
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-transferFrom}. |
|
*/ |
|
function transferFrom( |
|
address from, |
|
address to, |
|
uint256 tokenId |
|
) public virtual override { |
|
_transfer(from, to, tokenId); |
|
} |
|
|
|
/** |
|
* @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 { |
|
_transfer(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. |
|
* |
|
* Emits a {Transfer} event. |
|
*/ |
|
function _safeMint( |
|
address to, |
|
uint256 quantity, |
|
bytes memory _data |
|
) internal { |
|
uint256 startTokenId = _currentIndex; |
|
if (_addressToUint256(to) == 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 { |
|
// Updates: |
|
// - `balance += quantity`. |
|
// - `numberMinted += quantity`. |
|
// |
|
// We can directly add to the balance and number minted. |
|
_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] = |
|
_addressToUint256(to) | |
|
(block.timestamp << BITPOS_START_TIMESTAMP) | |
|
(_boolToUint256(quantity == 1) << BITPOS_NEXT_INITIALIZED); |
|
|
|
uint256 updatedIndex = startTokenId; |
|
uint256 end = updatedIndex + quantity; |
|
|
|
if (to.code.length != 0) { |
|
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); |
|
} |
|
|
|
/** |
|
* @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. |
|
*/ |
|
function _mint(address to, uint256 quantity) internal { |
|
uint256 startTokenId = _currentIndex; |
|
if (_addressToUint256(to) == 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 { |
|
// Updates: |
|
// - `balance += quantity`. |
|
// - `numberMinted += quantity`. |
|
// |
|
// We can directly add to the balance and number minted. |
|
_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] = |
|
_addressToUint256(to) | |
|
(block.timestamp << BITPOS_START_TIMESTAMP) | |
|
(_boolToUint256(quantity == 1) << BITPOS_NEXT_INITIALIZED); |
|
|
|
uint256 updatedIndex = startTokenId; |
|
uint256 end = updatedIndex + quantity; |
|
|
|
do { |
|
emit Transfer(address(0), to, updatedIndex++); |
|
} while (updatedIndex < end); |
|
|
|
_currentIndex = updatedIndex; |
|
} |
|
_afterTokenTransfers(address(0), to, startTokenId, quantity); |
|
} |
|
|
|
/** |
|
* @dev Transfers `tokenId` from `from` to `to`. |
|
* |
|
* Requirements: |
|
* |
|
* - `to` cannot be the zero address. |
|
* - `tokenId` token must be owned by `from`. |
|
* |
|
* Emits a {Transfer} event. |
|
*/ |
|
function _transfer( |
|
address from, |
|
address to, |
|
uint256 tokenId |
|
) private { |
|
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId); |
|
|
|
if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner(); |
|
|
|
address approvedAddress = _tokenApprovals[tokenId]; |
|
|
|
bool isApprovedOrOwner = (_msgSenderERC721A() == from || |
|
isApprovedForAll(from, _msgSenderERC721A()) || |
|
approvedAddress == _msgSenderERC721A()); |
|
|
|
if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved(); |
|
if (_addressToUint256(to) == 0) revert TransferToZeroAddress(); |
|
|
|
_beforeTokenTransfers(from, to, tokenId, 1); |
|
|
|
// Clear approvals from the previous owner. |
|
if (_addressToUint256(approvedAddress) != 0) { |
|
delete _tokenApprovals[tokenId]; |
|
} |
|
|
|
// 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 { |
|
// We can directly increment and decrement the balances. |
|
--_packedAddressData[from]; // Updates: `balance -= 1`. |
|
++_packedAddressData[to]; // Updates: `balance += 1`. |
|
|
|
// Updates: |
|
// - `address` to the next owner. |
|
// - `startTimestamp` to the timestamp of transfering. |
|
// - `burned` to `false`. |
|
// - `nextInitialized` to `true`. |
|
_packedOwnerships[tokenId] = |
|
_addressToUint256(to) | |
|
(block.timestamp << BITPOS_START_TIMESTAMP) | |
|
BITMASK_NEXT_INITIALIZED; |
|
|
|
// 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, to, tokenId); |
|
_afterTokenTransfers(from, to, tokenId, 1); |
|
} |
|
|
|
/** |
|
* @dev Equivalent to `_burn(tokenId, false)`. |
|
*/ |
|
function _burn(uint256 tokenId) internal virtual { |
|
_burn(tokenId, false); |
|
} |
|
|
|
/** |
|
* @dev Destroys `tokenId`. |
|
* The approval is cleared when the token is burned. |
|
* |
|
* Requirements: |
|
* |
|
* - `tokenId` must exist. |
|
* |
|
* Emits a {Transfer} event. |
|
*/ |
|
function _burn(uint256 tokenId, bool approvalCheck) internal virtual { |
|
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId); |
|
|
|
address from = address(uint160(prevOwnershipPacked)); |
|
address approvedAddress = _tokenApprovals[tokenId]; |
|
|
|
if (approvalCheck) { |
|
bool isApprovedOrOwner = (_msgSenderERC721A() == from || |
|
isApprovedForAll(from, _msgSenderERC721A()) || |
|
approvedAddress == _msgSenderERC721A()); |
|
|
|
if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved(); |
|
} |
|
|
|
_beforeTokenTransfers(from, address(0), tokenId, 1); |
|
|
|
// Clear approvals from the previous owner. |
|
if (_addressToUint256(approvedAddress) != 0) { |
|
delete _tokenApprovals[tokenId]; |
|
} |
|
|
|
// 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 { |
|
// Updates: |
|
// - `balance -= 1`. |
|
// - `numberBurned += 1`. |
|
// |
|
// We can directly decrement the balance, and increment the number burned. |
|
// This is equivalent to `packed -= 1; packed += 1 << BITPOS_NUMBER_BURNED;`. |
|
_packedAddressData[from] += (1 << BITPOS_NUMBER_BURNED) - 1; |
|
|
|
// Updates: |
|
// - `address` to the last owner. |
|
// - `startTimestamp` to the timestamp of burning. |
|
// - `burned` to `true`. |
|
// - `nextInitialized` to `true`. |
|
_packedOwnerships[tokenId] = |
|
_addressToUint256(from) | |
|
(block.timestamp << BITPOS_START_TIMESTAMP) | |
|
BITMASK_BURNED | |
|
BITMASK_NEXT_INITIALIZED; |
|
|
|
// 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 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) |
|
} |
|
} |
|
} |
|
|
|
pragma solidity ^0.8.13; |
|
|
|
interface IOperatorFilterRegistry { |
|
function isOperatorAllowed(address registrant, address operator) external view returns (bool); |
|
function register(address registrant) external; |
|
function registerAndSubscribe(address registrant, address subscription) external; |
|
function registerAndCopyEntries(address registrant, address registrantToCopy) external; |
|
function unregister(address addr) external; |
|
function updateOperator(address registrant, address operator, bool filtered) external; |
|
function updateOperators(address registrant, address[] calldata operators, bool filtered) external; |
|
function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external; |
|
function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external; |
|
function subscribe(address registrant, address registrantToSubscribe) external; |
|
function unsubscribe(address registrant, bool copyExistingEntries) external; |
|
function subscriptionOf(address addr) external returns (address registrant); |
|
function subscribers(address registrant) external returns (address[] memory); |
|
function subscriberAt(address registrant, uint256 index) external returns (address); |
|
function copyEntriesOf(address registrant, address registrantToCopy) external; |
|
function isOperatorFiltered(address registrant, address operator) external returns (bool); |
|
function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool); |
|
function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool); |
|
function filteredOperators(address addr) external returns (address[] memory); |
|
function filteredCodeHashes(address addr) external returns (bytes32[] memory); |
|
function filteredOperatorAt(address registrant, uint256 index) external returns (address); |
|
function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32); |
|
function isRegistered(address addr) external returns (bool); |
|
function codeHashOf(address addr) external returns (bytes32); |
|
} |
|
|
|
pragma solidity ^0.8.13; |
|
|
|
|
|
/** |
|
* @title OperatorFilterer |
|
* @notice Abstract contract whose constructor automatically registers and optionally subscribes to or copies another |
|
* registrant's entries in the OperatorFilterRegistry. |
|
*/ |
|
abstract contract OperatorFilterer { |
|
error OperatorNotAllowed(address operator); |
|
|
|
IOperatorFilterRegistry constant OPERATOR_FILTER_REGISTRY = |
|
IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E); |
|
|
|
constructor(address subscriptionOrRegistrantToCopy, bool subscribe) { |
|
// If an inheriting token contract is deployed to a network without the registry deployed, the modifier |
|
// will not revert, but the contract will need to be registered with the registry once it is deployed in |
|
// order for the modifier to filter addresses. |
|
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) { |
|
if (subscribe) { |
|
OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy); |
|
} else { |
|
if (subscriptionOrRegistrantToCopy != address(0)) { |
|
OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy); |
|
} else { |
|
OPERATOR_FILTER_REGISTRY.register(address(this)); |
|
} |
|
} |
|
} |
|
} |
|
|
|
modifier onlyAllowedOperator(address from) virtual { |
|
// Check registry code length to facilitate testing in environments without a deployed registry. |
|
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) { |
|
// Allow spending tokens from addresses with balance |
|
// Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred |
|
// from an EOA. |
|
if (from == msg.sender) { |
|
_; |
|
return; |
|
} |
|
if (!OPERATOR_FILTER_REGISTRY.isOperatorAllowed(address(this), msg.sender)) { |
|
revert OperatorNotAllowed(msg.sender); |
|
} |
|
} |
|
_; |
|
} |
|
|
|
modifier onlyAllowedOperatorApproval(address operator) virtual { |
|
// Check registry code length to facilitate testing in environments without a deployed registry. |
|
if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) { |
|
if (!OPERATOR_FILTER_REGISTRY.isOperatorAllowed(address(this), operator)) { |
|
revert OperatorNotAllowed(operator); |
|
} |
|
} |
|
_; |
|
} |
|
} |
|
|
|
pragma solidity ^0.8.13; |
|
|
|
/** |
|
* @title DefaultOperatorFilterer |
|
* @notice Inherits from OperatorFilterer and automatically subscribes to the default OpenSea subscription. |
|
*/ |
|
abstract contract DefaultOperatorFilterer is OperatorFilterer { |
|
address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6); |
|
|
|
constructor() OperatorFilterer(DEFAULT_SUBSCRIPTION, true) {} |
|
} |
|
|
|
contract CaptainBlackbeard is ERC721A, DefaultOperatorFilterer, Ownable, ReentrancyGuard { |
|
uint256 public MAX_SUPPLY = 999; |
|
|
|
|
|
uint256 public FREEMINT_SUPPLY = 99; |
|
uint256 public PUBLICMINT_SUPPLY = 900; |
|
|
|
bool public IS_FREEMINT_ACTIVE = false; |
|
bool public IS_PUBLICMINT_ACTIVE = false; |
|
|
|
|
|
uint256 public FREEMINT_TX_LIMIT = 1; |
|
uint256 public PUBLICMINT_TX_LIMIT = 10; |
|
|
|
|
|
uint256 public FREEMINT_WALLET_LIMIT = 1; |
|
uint256 public PUBLICMINT_WALLET_LIMIT = 50; |
|
|
|
|
|
uint256 public FREEMINT_PRICE = 0 ether; |
|
uint256 public PUBLICMINT_PRICE = 0.0059 ether; |
|
|
|
|
|
uint256 public FREEMINT_COUNT = 0; |
|
uint256 public PUBLICMINT_COUNT = 0; |
|
|
|
|
|
|
|
|
|
mapping(address => uint) public FREEMINT_Minted; |
|
mapping(address => uint) public PUBLICMINT_Minted; |
|
|
|
bool public _revealed = false; |
|
|
|
string private baseURI = ""; |
|
string private preRevealURI = "https://ipfs.w3bmint.xyz/ipfs/QmNg2eug8GeAqxXrMsMSkgM3jeSV5jPzMTC95mL2TUJm2T"; |
|
|
|
mapping(address => uint256) addressBlockBought; |
|
|
|
address public constant RL_ADDRESS = 0xc9b5553910bA47719e0202fF9F617B8BE06b3A09; |
|
|
|
constructor() ERC721A("CaptainBlackbeard", "BLACKBEARD") { |
|
|
|
|
|
_safeMint(0x9D78E267393d882C453bD2D72CbCD08289E27EF0, 1); |
|
} |
|
|
|
modifier isSecured(uint256 currentValue) { |
|
require(addressBlockBought[msg.sender] < block.timestamp, "CANNOT_MINT_ON_THE_SAME_BLOCK"); |
|
require(tx.origin == msg.sender,"CONTRACTS_NOT_ALLOWED_TO_MINT"); |
|
require(msg.value == currentValue, "WRONG_ETH_VALUE"); |
|
_; |
|
} |
|
|
|
function validateMint(bool isActive, uint256 count, uint256 supply, uint256 mintedOfUser, uint256 walletLimit, uint256 txLimit, uint256 numberOfTokens, bool isProofValid) private view { |
|
require(isActive, "MINT_IS_NOT_YET_ACTIVE"); |
|
require(isProofValid, "PROOF_INVALID"); |
|
require(numberOfTokens + totalSupply() <= MAX_SUPPLY, "NOT_ENOUGH_SUPPLY"); |
|
require(numberOfTokens + count <= supply, "NOT_ENOUGH_SUPPLY"); |
|
require(mintedOfUser + numberOfTokens <= walletLimit || walletLimit == 0, "EXCEED__MINT_LIMIT"); |
|
require(numberOfTokens <= txLimit || txLimit == 0, "EXCEED_MINT_LIMIT"); |
|
} |
|
|
|
|
|
function FREEMINTMint(uint256 numberOfTokens) external isSecured(FREEMINT_PRICE * numberOfTokens) payable { |
|
validateMint(IS_FREEMINT_ACTIVE, FREEMINT_COUNT, FREEMINT_SUPPLY, FREEMINT_Minted[msg.sender], FREEMINT_WALLET_LIMIT, FREEMINT_TX_LIMIT, numberOfTokens, true); |
|
addressBlockBought[msg.sender] = block.timestamp; |
|
FREEMINT_Minted[msg.sender] += numberOfTokens; |
|
FREEMINT_COUNT += numberOfTokens; |
|
_safeMint(msg.sender, numberOfTokens); |
|
} |
|
|
|
function PUBLICMINTMint(uint256 numberOfTokens) external isSecured(PUBLICMINT_PRICE * numberOfTokens) payable { |
|
validateMint(IS_PUBLICMINT_ACTIVE, PUBLICMINT_COUNT, PUBLICMINT_SUPPLY, PUBLICMINT_Minted[msg.sender], PUBLICMINT_WALLET_LIMIT, PUBLICMINT_TX_LIMIT, numberOfTokens, true); |
|
addressBlockBought[msg.sender] = block.timestamp; |
|
PUBLICMINT_Minted[msg.sender] += numberOfTokens; |
|
PUBLICMINT_COUNT += numberOfTokens; |
|
_safeMint(msg.sender, numberOfTokens); |
|
} |
|
|
|
|
|
|
|
function setBaseURI(string calldata URI) external onlyOwner { |
|
baseURI = URI; |
|
} |
|
|
|
function reveal(bool revealed, string calldata _baseURI) external onlyOwner { |
|
_revealed = revealed; |
|
baseURI = _baseURI; |
|
} |
|
|
|
|
|
|
|
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { |
|
if (_revealed) { |
|
return string(abi.encodePacked(baseURI, Strings.toString(tokenId))); |
|
} else { |
|
return string(abi.encodePacked(preRevealURI)); |
|
} |
|
} |
|
|
|
function numberMinted(address owner) public view returns (uint256) { |
|
return _numberMinted(owner); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function toggleFREEMINTMintStatus() external onlyOwner { |
|
IS_FREEMINT_ACTIVE = !IS_FREEMINT_ACTIVE; |
|
} |
|
function togglePUBLICMINTMintStatus() external onlyOwner { |
|
IS_PUBLICMINT_ACTIVE = !IS_PUBLICMINT_ACTIVE; |
|
} |
|
|
|
|
|
|
|
function setFREEMINTSupply(uint256 _supply) external onlyOwner { |
|
FREEMINT_SUPPLY = _supply; |
|
} |
|
|
|
function setPUBLICMINTSupply(uint256 _supply) external onlyOwner { |
|
PUBLICMINT_SUPPLY = _supply; |
|
} |
|
|
|
|
|
|
|
|
|
function setFREEMINTPrice(uint256 _price) external onlyOwner { |
|
FREEMINT_PRICE = _price; |
|
} |
|
|
|
function setPUBLICMINTPrice(uint256 _price) external onlyOwner { |
|
PUBLICMINT_PRICE = _price; |
|
} |
|
|
|
|
|
|
|
function updateMaxSupply(uint256 _maxSupply) external onlyOwner { |
|
MAX_SUPPLY = _maxSupply; |
|
} |
|
|
|
|
|
function withdraw() external onlyOwner { |
|
uint256 RLFee = (address(this).balance * 600) / 10000; |
|
(bool successRLTransfer, ) = payable(RL_ADDRESS).call{ value: RLFee }(""); |
|
require(successRLTransfer, "Transfer Failed!"); |
|
|
|
|
|
(bool successFinal, ) = payable(0x9D78E267393d882C453bD2D72CbCD08289E27EF0).call{ value: address(this).balance }(""); |
|
require(successFinal, "Transfer Failed!"); |
|
|
|
} |
|
|
|
|
|
function setApprovalForAll(address operator, bool approved) public override onlyAllowedOperatorApproval(operator) { |
|
super.setApprovalForAll(operator, approved); |
|
} |
|
|
|
function approve(address operator, uint256 tokenId) public override onlyAllowedOperatorApproval(operator) { |
|
super.approve(operator, tokenId); |
|
} |
|
|
|
function transferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) { |
|
super.transferFrom(from, to, tokenId); |
|
} |
|
|
|
function safeTransferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) { |
|
super.safeTransferFrom(from, to, tokenId); |
|
} |
|
|
|
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public override onlyAllowedOperator(from) { |
|
super.safeTransferFrom(from, to, tokenId, data); |
|
} |
|
} |
|
|