Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"the49erGoldMiners_final.sol": {
"content": "/**\r
*Submitted for verification at Etherscan.io on 2025-10-24\r
*/\r
\r
/**\r
*Submitted for verification at Etherscan.io on 2025-09-06\r
*/\r
\r
// File: erc721a/contracts/IERC721A.sol\r
\r
\r
// ERC721A Contracts v4.3.0\r
// Creator: Chiru Labs\r
// SPDX-License-Identifier: MIT\r
\r
\r
\r
pragma solidity ^0.8.4;\r
\r
/**\r
* @dev Interface of ERC721A.\r
*/\r
interface IERC721A {\r
/**\r
* The caller must own the token or be an approved operator.\r
*/\r
error ApprovalCallerNotOwnerNorApproved();\r
\r
/**\r
* The token does not exist.\r
*/\r
error ApprovalQueryForNonexistentToken();\r
\r
/**\r
* Cannot query the balance for the zero address.\r
*/\r
error BalanceQueryForZeroAddress();\r
\r
/**\r
* Cannot mint to the zero address.\r
*/\r
error MintToZeroAddress();\r
\r
/**\r
* The quantity of tokens minted must be more than zero.\r
*/\r
error MintZeroQuantity();\r
\r
/**\r
* The token does not exist.\r
*/\r
error OwnerQueryForNonexistentToken();\r
\r
/**\r
* The caller must own the token or be an approved operator.\r
*/\r
error TransferCallerNotOwnerNorApproved();\r
\r
/**\r
* The token must be owned by `from`.\r
*/\r
error TransferFromIncorrectOwner();\r
\r
/**\r
* Cannot safely transfer to a contract that does not implement the\r
* ERC721Receiver interface.\r
*/\r
error TransferToNonERC721ReceiverImplementer();\r
\r
/**\r
* Cannot transfer to the zero address.\r
*/\r
error TransferToZeroAddress();\r
\r
/**\r
* The token does not exist.\r
*/\r
error URIQueryForNonexistentToken();\r
\r
/**\r
* The `quantity` minted with ERC2309 exceeds the safety limit.\r
*/\r
error MintERC2309QuantityExceedsLimit();\r
\r
/**\r
* The `extraData` cannot be set on an unintialized ownership slot.\r
*/\r
error OwnershipNotInitializedForExtraData();\r
\r
/**\r
* `_sequentialUpTo()` must be greater than `_startTokenId()`.\r
*/\r
error SequentialUpToTooSmall();\r
\r
/**\r
* The `tokenId` of a sequential mint exceeds `_sequentialUpTo()`.\r
*/\r
error SequentialMintExceedsLimit();\r
\r
/**\r
* Spot minting requires a `tokenId` greater than `_sequentialUpTo()`.\r
*/\r
error SpotMintTokenIdTooSmall();\r
\r
/**\r
* Cannot mint over a token that already exists.\r
*/\r
error TokenAlreadyExists();\r
\r
/**\r
* The feature is not compatible with spot mints.\r
*/\r
error NotCompatibleWithSpotMints();\r
\r
// =============================================================\r
// STRUCTS\r
// =============================================================\r
\r
struct TokenOwnership {\r
// The address of the owner.\r
address addr;\r
// Stores the start time of ownership with minimal overhead for tokenomics.\r
uint64 startTimestamp;\r
// Whether the token has been burned.\r
bool burned;\r
// Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.\r
uint24 extraData;\r
}\r
\r
// =============================================================\r
// TOKEN COUNTERS\r
// =============================================================\r
\r
/**\r
* @dev Returns the total number of tokens in existence.\r
* Burned tokens will reduce the count.\r
* To get the total number of tokens minted, please see {_totalMinted}.\r
*/\r
function totalSupply() external view returns (uint256);\r
\r
// =============================================================\r
// IERC165\r
// =============================================================\r
\r
/**\r
* @dev Returns true if this contract implements the interface defined by\r
* `interfaceId`. See the corresponding\r
* [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\r
* to learn more about how these ids are created.\r
*\r
* This function call must use less than 30000 gas.\r
*/\r
function supportsInterface(bytes4 interfaceId) external view returns (bool);\r
\r
// =============================================================\r
// IERC721\r
// =============================================================\r
\r
/**\r
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.\r
*/\r
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\r
\r
/**\r
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\r
*/\r
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\r
\r
/**\r
* @dev Emitted when `owner` enables or disables\r
* (`approved`) `operator` to manage all of its assets.\r
*/\r
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\r
\r
/**\r
* @dev Returns the number of tokens in `owner`'s account.\r
*/\r
function balanceOf(address owner) external view returns (uint256 balance);\r
\r
/**\r
* @dev Returns the owner of the `tokenId` token.\r
*\r
* Requirements:\r
*\r
* - `tokenId` must exist.\r
*/\r
function ownerOf(uint256 tokenId) external view returns (address owner);\r
\r
/**\r
* @dev Safely transfers `tokenId` token from `from` to `to`,\r
* checking first that contract recipients are aware of the ERC721 protocol\r
* to prevent tokens from being forever locked.\r
*\r
* Requirements:\r
*\r
* - `from` cannot be the zero address.\r
* - `to` cannot be the zero address.\r
* - `tokenId` token must exist and be owned by `from`.\r
* - If the caller is not `from`, it must be have been allowed to move\r
* this token by either {approve} or {setApprovalForAll}.\r
* - If `to` refers to a smart contract, it must implement\r
* {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function safeTransferFrom(\r
address from,\r
address to,\r
uint256 tokenId,\r
bytes calldata data\r
) external payable;\r
\r
/**\r
* @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\r
*/\r
function safeTransferFrom(\r
address from,\r
address to,\r
uint256 tokenId\r
) external payable;\r
\r
/**\r
* @dev Transfers `tokenId` from `from` to `to`.\r
*\r
* WARNING: Usage of this method is discouraged, use {safeTransferFrom}\r
* whenever possible.\r
*\r
* Requirements:\r
*\r
* - `from` cannot be the zero address.\r
* - `to` cannot be the zero address.\r
* - `tokenId` token must be owned by `from`.\r
* - If the caller is not `from`, it must be approved to move this token\r
* by either {approve} or {setApprovalForAll}.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function transferFrom(\r
address from,\r
address to,\r
uint256 tokenId\r
) external payable;\r
\r
/**\r
* @dev Gives permission to `to` to transfer `tokenId` token to another account.\r
* The approval is cleared when the token is transferred.\r
*\r
* Only a single account can be approved at a time, so approving the\r
* zero address clears previous approvals.\r
*\r
* Requirements:\r
*\r
* - The caller must own the token or be an approved operator.\r
* - `tokenId` must exist.\r
*\r
* Emits an {Approval} event.\r
*/\r
function approve(address to, uint256 tokenId) external payable;\r
\r
/**\r
* @dev Approve or remove `operator` as an operator for the caller.\r
* Operators can call {transferFrom} or {safeTransferFrom}\r
* for any token owned by the caller.\r
*\r
* Requirements:\r
*\r
* - The `operator` cannot be the caller.\r
*\r
* Emits an {ApprovalForAll} event.\r
*/\r
function setApprovalForAll(address operator, bool _approved) external;\r
\r
/**\r
* @dev Returns the account approved for `tokenId` token.\r
*\r
* Requirements:\r
*\r
* - `tokenId` must exist.\r
*/\r
function getApproved(uint256 tokenId) external view returns (address operator);\r
\r
/**\r
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r
*\r
* See {setApprovalForAll}.\r
*/\r
function isApprovedForAll(address owner, address operator) external view returns (bool);\r
\r
// =============================================================\r
// IERC721Metadata\r
// =============================================================\r
\r
/**\r
* @dev Returns the token collection name.\r
*/\r
function name() external view returns (string memory);\r
\r
/**\r
* @dev Returns the token collection symbol.\r
*/\r
function symbol() external view returns (string memory);\r
\r
/**\r
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r
*/\r
function tokenURI(uint256 tokenId) external view returns (string memory);\r
\r
// =============================================================\r
// IERC2309\r
// =============================================================\r
\r
/**\r
* @dev Emitted when tokens in `fromTokenId` to `toTokenId`\r
* (inclusive) is transferred from `from` to `to`, as defined in the\r
* [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.\r
*\r
* See {_mintERC2309} for more details.\r
*/\r
event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);\r
}\r
\r
// File: erc721a/contracts/ERC721A.sol\r
\r
\r
// ERC721A Contracts v4.3.0\r
// Creator: Chiru Labs\r
\r
pragma solidity ^0.8.4;\r
\r
\r
/**\r
* @dev Interface of ERC721 token receiver.\r
*/\r
interface ERC721A__IERC721Receiver {\r
function onERC721Received(\r
address operator,\r
address from,\r
uint256 tokenId,\r
bytes calldata data\r
) external returns (bytes4);\r
}\r
\r
/**\r
* @title ERC721A\r
*\r
* @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)\r
* Non-Fungible Token Standard, including the Metadata extension.\r
* Optimized for lower gas during batch mints.\r
*\r
* Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)\r
* starting from `_startTokenId()`.\r
*\r
* The `_sequentialUpTo()` function can be overriden to enable spot mints\r
* (i.e. non-consecutive mints) for `tokenId`s greater than `_sequentialUpTo()`.\r
*\r
* Assumptions:\r
*\r
* - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.\r
* - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).\r
*/\r
contract ERC721A is IERC721A {\r
// Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364).\r
struct TokenApprovalRef {\r
address value;\r
}\r
\r
// =============================================================\r
// CONSTANTS\r
// =============================================================\r
\r
// Mask of an entry in packed address data.\r
uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;\r
\r
// The bit position of `numberMinted` in packed address data.\r
uint256 private constant _BITPOS_NUMBER_MINTED = 64;\r
\r
// The bit position of `numberBurned` in packed address data.\r
uint256 private constant _BITPOS_NUMBER_BURNED = 128;\r
\r
// The bit position of `aux` in packed address data.\r
uint256 private constant _BITPOS_AUX = 192;\r
\r
// Mask of all 256 bits in packed address data except the 64 bits for `aux`.\r
uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;\r
\r
// The bit position of `startTimestamp` in packed ownership.\r
uint256 private constant _BITPOS_START_TIMESTAMP = 160;\r
\r
// The bit mask of the `burned` bit in packed ownership.\r
uint256 private constant _BITMASK_BURNED = 1 << 224;\r
\r
// The bit position of the `nextInitialized` bit in packed ownership.\r
uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;\r
\r
// The bit mask of the `nextInitialized` bit in packed ownership.\r
uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;\r
\r
// The bit position of `extraData` in packed ownership.\r
uint256 private constant _BITPOS_EXTRA_DATA = 232;\r
\r
// Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.\r
uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;\r
\r
// The mask of the lower 160 bits for addresses.\r
uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;\r
\r
// The maximum `quantity` that can be minted with {_mintERC2309}.\r
// This limit is to prevent overflows on the address data entries.\r
// For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}\r
// is required to cause an overflow, which is unrealistic.\r
uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;\r
\r
// The `Transfer` event signature is given by:\r
// `keccak256(bytes("Transfer(address,address,uint256)"))`.\r
bytes32 private constant _TRANSFER_EVENT_SIGNATURE =\r
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;\r
\r
// =============================================================\r
// STORAGE\r
// =============================================================\r
\r
// The next token ID to be minted.\r
uint256 private _currentIndex;\r
\r
// The number of tokens burned.\r
uint256 private _burnCounter;\r
\r
// Token name\r
string private _name;\r
\r
// Token symbol\r
string private _symbol;\r
\r
// Mapping from token ID to ownership details\r
// An empty struct value does not necessarily mean the token is unowned.\r
// See {_packedOwnershipOf} implementation for details.\r
//\r
// Bits Layout:\r
// - [0..159] `addr`\r
// - [160..223] `startTimestamp`\r
// - [224] `burned`\r
// - [225] `nextInitialized`\r
// - [232..255] `extraData`\r
mapping(uint256 => uint256) private _packedOwnerships;\r
\r
// Mapping owner address to address data.\r
//\r
// Bits Layout:\r
// - [0..63] `balance`\r
// - [64..127] `numberMinted`\r
// - [128..191] `numberBurned`\r
// - [192..255] `aux`\r
mapping(address => uint256) private _packedAddressData;\r
\r
// Mapping from token ID to approved address.\r
mapping(uint256 => TokenApprovalRef) private _tokenApprovals;\r
\r
// Mapping from owner to operator approvals\r
mapping(address => mapping(address => bool)) private _operatorApprovals;\r
\r
// The amount of tokens minted above `_sequentialUpTo()`.\r
// We call these spot mints (i.e. non-sequential mints).\r
uint256 private _spotMinted;\r
\r
// =============================================================\r
// CONSTRUCTOR\r
// =============================================================\r
\r
constructor(string memory name_, string memory symbol_) {\r
_name = name_;\r
_symbol = symbol_;\r
_currentIndex = _startTokenId();\r
\r
if (_sequentialUpTo() < _startTokenId()) _revert(SequentialUpToTooSmall.selector);\r
}\r
\r
// =============================================================\r
// TOKEN COUNTING OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Returns the starting token ID for sequential mints.\r
*\r
* Override this function to change the starting token ID for sequential mints.\r
*\r
* Note: The value returned must never change after any tokens have been minted.\r
*/\r
function _startTokenId() internal view virtual returns (uint256) {\r
return 0;\r
}\r
\r
/**\r
* @dev Returns the maximum token ID (inclusive) for sequential mints.\r
*\r
* Override this function to return a value less than 2**256 - 1,\r
* but greater than `_startTokenId()`, to enable spot (non-sequential) mints.\r
*\r
* Note: The value returned must never change after any tokens have been minted.\r
*/\r
function _sequentialUpTo() internal view virtual returns (uint256) {\r
return type(uint256).max;\r
}\r
\r
/**\r
* @dev Returns the next token ID to be minted.\r
*/\r
function _nextTokenId() internal view virtual returns (uint256) {\r
return _currentIndex;\r
}\r
\r
/**\r
* @dev Returns the total number of tokens in existence.\r
* Burned tokens will reduce the count.\r
* To get the total number of tokens minted, please see {_totalMinted}.\r
*/\r
function totalSupply() public view virtual override returns (uint256 result) {\r
// Counter underflow is impossible as `_burnCounter` cannot be incremented\r
// more than `_currentIndex + _spotMinted - _startTokenId()` times.\r
unchecked {\r
// With spot minting, the intermediate `result` can be temporarily negative,\r
// and the computation must be unchecked.\r
result = _currentIndex - _burnCounter - _startTokenId();\r
if (_sequentialUpTo() != type(uint256).max) result += _spotMinted;\r
}\r
}\r
\r
/**\r
* @dev Returns the total amount of tokens minted in the contract.\r
*/\r
function _totalMinted() internal view virtual returns (uint256 result) {\r
// Counter underflow is impossible as `_currentIndex` does not decrement,\r
// and it is initialized to `_startTokenId()`.\r
unchecked {\r
result = _currentIndex - _startTokenId();\r
if (_sequentialUpTo() != type(uint256).max) result += _spotMinted;\r
}\r
}\r
\r
/**\r
* @dev Returns the total number of tokens burned.\r
*/\r
function _totalBurned() internal view virtual returns (uint256) {\r
return _burnCounter;\r
}\r
\r
/**\r
* @dev Returns the total number of tokens that are spot-minted.\r
*/\r
function _totalSpotMinted() internal view virtual returns (uint256) {\r
return _spotMinted;\r
}\r
\r
// =============================================================\r
// ADDRESS DATA OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Returns the number of tokens in `owner`'s account.\r
*/\r
function balanceOf(address owner) public view virtual override returns (uint256) {\r
if (owner == address(0)) _revert(BalanceQueryForZeroAddress.selector);\r
return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;\r
}\r
\r
/**\r
* Returns the number of tokens minted by `owner`.\r
*/\r
function _numberMinted(address owner) internal view returns (uint256) {\r
return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;\r
}\r
\r
/**\r
* Returns the number of tokens burned by or on behalf of `owner`.\r
*/\r
function _numberBurned(address owner) internal view returns (uint256) {\r
return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;\r
}\r
\r
/**\r
* Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\r
*/\r
function _getAux(address owner) internal view returns (uint64) {\r
return uint64(_packedAddressData[owner] >> _BITPOS_AUX);\r
}\r
\r
/**\r
* Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\r
* If there are multiple variables, please pack them into a uint64.\r
*/\r
function _setAux(address owner, uint64 aux) internal virtual {\r
uint256 packed = _packedAddressData[owner];\r
uint256 auxCasted;\r
// Cast `aux` with assembly to avoid redundant masking.\r
assembly {\r
auxCasted := aux\r
}\r
packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);\r
_packedAddressData[owner] = packed;\r
}\r
\r
// =============================================================\r
// IERC165\r
// =============================================================\r
\r
/**\r
* @dev Returns true if this contract implements the interface defined by\r
* `interfaceId`. See the corresponding\r
* [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\r
* to learn more about how these ids are created.\r
*\r
* This function call must use less than 30000 gas.\r
*/\r
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\r
// The interface IDs are constants representing the first 4 bytes\r
// of the XOR of all function selectors in the interface.\r
// See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)\r
// (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)\r
return\r
interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.\r
interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.\r
interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.\r
}\r
\r
// =============================================================\r
// IERC721Metadata\r
// =============================================================\r
\r
/**\r
* @dev Returns the token collection name.\r
*/\r
function name() public view virtual override returns (string memory) {\r
return _name;\r
}\r
\r
/**\r
* @dev Returns the token collection symbol.\r
*/\r
function symbol() public view virtual override returns (string memory) {\r
return _symbol;\r
}\r
\r
/**\r
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\r
*/\r
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\r
if (!_exists(tokenId)) _revert(URIQueryForNonexistentToken.selector);\r
\r
string memory baseURI = _baseURI();\r
return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';\r
}\r
\r
/**\r
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\r
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty\r
* by default, it can be overridden in child contracts.\r
*/\r
function _baseURI() internal view virtual returns (string memory) {\r
return '';\r
}\r
\r
// =============================================================\r
// OWNERSHIPS OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Returns the owner of the `tokenId` token.\r
*\r
* Requirements:\r
*\r
* - `tokenId` must exist.\r
*/\r
function ownerOf(uint256 tokenId) public view virtual override returns (address) {\r
return address(uint160(_packedOwnershipOf(tokenId)));\r
}\r
\r
/**\r
* @dev Gas spent here starts off proportional to the maximum mint batch size.\r
* It gradually moves to O(1) as tokens get transferred around over time.\r
*/\r
function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {\r
return _unpackedOwnership(_packedOwnershipOf(tokenId));\r
}\r
\r
/**\r
* @dev Returns the unpacked `TokenOwnership` struct at `index`.\r
*/\r
function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {\r
return _unpackedOwnership(_packedOwnerships[index]);\r
}\r
\r
/**\r
* @dev Returns whether the ownership slot at `index` is initialized.\r
* An uninitialized slot does not necessarily mean that the slot has no owner.\r
*/\r
function _ownershipIsInitialized(uint256 index) internal view virtual returns (bool) {\r
return _packedOwnerships[index] != 0;\r
}\r
\r
/**\r
* @dev Initializes the ownership slot minted at `index` for efficiency purposes.\r
*/\r
function _initializeOwnershipAt(uint256 index) internal virtual {\r
if (_packedOwnerships[index] == 0) {\r
_packedOwnerships[index] = _packedOwnershipOf(index);\r
}\r
}\r
\r
/**\r
* @dev Returns the packed ownership data of `tokenId`.\r
*/\r
function _packedOwnershipOf(uint256 tokenId) private view returns (uint256 packed) {\r
if (_startTokenId() <= tokenId) {\r
packed = _packedOwnerships[tokenId];\r
\r
if (tokenId > _sequentialUpTo()) {\r
if (_packedOwnershipExists(packed)) return packed;\r
_revert(OwnerQueryForNonexistentToken.selector);\r
}\r
\r
// If the data at the starting slot does not exist, start the scan.\r
if (packed == 0) {\r
if (tokenId >= _currentIndex) _revert(OwnerQueryForNonexistentToken.selector);\r
// Invariant:\r
// There will always be an initialized ownership slot\r
// (i.e. `ownership.addr != address(0) && ownership.burned == false`)\r
// before an unintialized ownership slot\r
// (i.e. `ownership.addr == address(0) && ownership.burned == false`)\r
// Hence, `tokenId` will not underflow.\r
//\r
// We can directly compare the packed value.\r
// If the address is zero, packed will be zero.\r
for (;;) {\r
unchecked {\r
packed = _packedOwnerships[--tokenId];\r
}\r
if (packed == 0) continue;\r
if (packed & _BITMASK_BURNED == 0) return packed;\r
// Otherwise, the token is burned, and we must revert.\r
// This handles the case of batch burned tokens, where only the burned bit\r
// of the starting slot is set, and remaining slots are left uninitialized.\r
_revert(OwnerQueryForNonexistentToken.selector);\r
}\r
}\r
// Otherwise, the data exists and we can skip the scan.\r
// This is possible because we have already achieved the target condition.\r
// This saves 2143 gas on transfers of initialized tokens.\r
// If the token is not burned, return `packed`. Otherwise, revert.\r
if (packed & _BITMASK_BURNED == 0) return packed;\r
}\r
_revert(OwnerQueryForNonexistentToken.selector);\r
}\r
\r
/**\r
* @dev Returns the unpacked `TokenOwnership` struct from `packed`.\r
*/\r
function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {\r
ownership.addr = address(uint160(packed));\r
ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);\r
ownership.burned = packed & _BITMASK_BURNED != 0;\r
ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);\r
}\r
\r
/**\r
* @dev Packs ownership data into a single uint256.\r
*/\r
function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {\r
assembly {\r
// Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\r
owner := and(owner, _BITMASK_ADDRESS)\r
// `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.\r
result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))\r
}\r
}\r
\r
/**\r
* @dev Returns the `nextInitialized` flag set if `quantity` equals 1.\r
*/\r
function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {\r
// For branchless setting of the `nextInitialized` flag.\r
assembly {\r
// `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.\r
result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))\r
}\r
}\r
\r
// =============================================================\r
// APPROVAL OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Gives permission to `to` to transfer `tokenId` token to another account. See {ERC721A-_approve}.\r
*\r
* Requirements:\r
*\r
* - The caller must own the token or be an approved operator.\r
*/\r
function approve(address to, uint256 tokenId) public payable virtual override {\r
_approve(to, tokenId, true);\r
}\r
\r
/**\r
* @dev Returns the account approved for `tokenId` token.\r
*\r
* Requirements:\r
*\r
* - `tokenId` must exist.\r
*/\r
function getApproved(uint256 tokenId) public view virtual override returns (address) {\r
if (!_exists(tokenId)) _revert(ApprovalQueryForNonexistentToken.selector);\r
\r
return _tokenApprovals[tokenId].value;\r
}\r
\r
/**\r
* @dev Approve or remove `operator` as an operator for the caller.\r
* Operators can call {transferFrom} or {safeTransferFrom}\r
* for any token owned by the caller.\r
*\r
* Requirements:\r
*\r
* - The `operator` cannot be the caller.\r
*\r
* Emits an {ApprovalForAll} event.\r
*/\r
function setApprovalForAll(address operator, bool approved) public virtual override {\r
_operatorApprovals[_msgSenderERC721A()][operator] = approved;\r
emit ApprovalForAll(_msgSenderERC721A(), operator, approved);\r
}\r
\r
/**\r
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\r
*\r
* See {setApprovalForAll}.\r
*/\r
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\r
return _operatorApprovals[owner][operator];\r
}\r
\r
/**\r
* @dev Returns whether `tokenId` exists.\r
*\r
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\r
*\r
* Tokens start existing when they are minted. See {_mint}.\r
*/\r
function _exists(uint256 tokenId) internal view virtual returns (bool result) {\r
if (_startTokenId() <= tokenId) {\r
if (tokenId > _sequentialUpTo()) return _packedOwnershipExists(_packedOwnerships[tokenId]);\r
\r
if (tokenId < _currentIndex) {\r
uint256 packed;\r
while ((packed = _packedOwnerships[tokenId]) == 0) --tokenId;\r
result = packed & _BITMASK_BURNED == 0;\r
}\r
}\r
}\r
\r
/**\r
* @dev Returns whether `packed` represents a token that exists.\r
*/\r
function _packedOwnershipExists(uint256 packed) private pure returns (bool result) {\r
assembly {\r
// The following is equivalent to `owner != address(0) && burned == false`.\r
// Symbolically tested.\r
result := gt(and(packed, _BITMASK_ADDRESS), and(packed, _BITMASK_BURNED))\r
}\r
}\r
\r
/**\r
* @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.\r
*/\r
function _isSenderApprovedOrOwner(\r
address approvedAddress,\r
address owner,\r
address msgSender\r
) private pure returns (bool result) {\r
assembly {\r
// Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\r
owner := and(owner, _BITMASK_ADDRESS)\r
// Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.\r
msgSender := and(msgSender, _BITMASK_ADDRESS)\r
// `msgSender == owner || msgSender == approvedAddress`.\r
result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))\r
}\r
}\r
\r
/**\r
* @dev Returns the storage slot and value for the approved address of `tokenId`.\r
*/\r
function _getApprovedSlotAndAddress(uint256 tokenId)\r
private\r
view\r
returns (uint256 approvedAddressSlot, address approvedAddress)\r
{\r
TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];\r
// The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.\r
assembly {\r
approvedAddressSlot := tokenApproval.slot\r
approvedAddress := sload(approvedAddressSlot)\r
}\r
}\r
\r
// =============================================================\r
// TRANSFER OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Transfers `tokenId` from `from` to `to`.\r
*\r
* Requirements:\r
*\r
* - `from` cannot be the zero address.\r
* - `to` cannot be the zero address.\r
* - `tokenId` token must be owned by `from`.\r
* - If the caller is not `from`, it must be approved to move this token\r
* by either {approve} or {setApprovalForAll}.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function transferFrom(\r
address from,\r
address to,\r
uint256 tokenId\r
) public payable virtual override {\r
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\r
\r
// Mask `from` to the lower 160 bits, in case the upper bits somehow aren't clean.\r
from = address(uint160(uint256(uint160(from)) & _BITMASK_ADDRESS));\r
\r
if (address(uint160(prevOwnershipPacked)) != from) _revert(TransferFromIncorrectOwner.selector);\r
\r
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\r
\r
// The nested ifs save around 20+ gas over a compound boolean condition.\r
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\r
if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);\r
\r
_beforeTokenTransfers(from, to, tokenId, 1);\r
\r
// Clear approvals from the previous owner.\r
assembly {\r
if approvedAddress {\r
// This is equivalent to `delete _tokenApprovals[tokenId]`.\r
sstore(approvedAddressSlot, 0)\r
}\r
}\r
\r
// Underflow of the sender's balance is impossible because we check for\r
// ownership above and the recipient's balance can't realistically overflow.\r
// Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\r
unchecked {\r
// We can directly increment and decrement the balances.\r
--_packedAddressData[from]; // Updates: `balance -= 1`.\r
++_packedAddressData[to]; // Updates: `balance += 1`.\r
\r
// Updates:\r
// - `address` to the next owner.\r
// - `startTimestamp` to the timestamp of transfering.\r
// - `burned` to `false`.\r
// - `nextInitialized` to `true`.\r
_packedOwnerships[tokenId] = _packOwnershipData(\r
to,\r
_BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)\r
);\r
\r
// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\r
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\r
uint256 nextTokenId = tokenId + 1;\r
// If the next slot's address is zero and not burned (i.e. packed value is zero).\r
if (_packedOwnerships[nextTokenId] == 0) {\r
// If the next slot is within bounds.\r
if (nextTokenId != _currentIndex) {\r
// Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\r
_packedOwnerships[nextTokenId] = prevOwnershipPacked;\r
}\r
}\r
}\r
}\r
\r
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.\r
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;\r
assembly {\r
// Emit the `Transfer` event.\r
log4(\r
0, // Start of data (0, since no data).\r
0, // End of data (0, since no data).\r
_TRANSFER_EVENT_SIGNATURE, // Signature.\r
from, // `from`.\r
toMasked, // `to`.\r
tokenId // `tokenId`.\r
)\r
}\r
if (toMasked == 0) _revert(TransferToZeroAddress.selector);\r
\r
_afterTokenTransfers(from, to, tokenId, 1);\r
}\r
\r
/**\r
* @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\r
*/\r
function safeTransferFrom(\r
address from,\r
address to,\r
uint256 tokenId\r
) public payable virtual override {\r
safeTransferFrom(from, to, tokenId, '');\r
}\r
\r
/**\r
* @dev Safely transfers `tokenId` token from `from` to `to`.\r
*\r
* Requirements:\r
*\r
* - `from` cannot be the zero address.\r
* - `to` cannot be the zero address.\r
* - `tokenId` token must exist and be owned by `from`.\r
* - If the caller is not `from`, it must be approved to move this token\r
* by either {approve} or {setApprovalForAll}.\r
* - If `to` refers to a smart contract, it must implement\r
* {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function safeTransferFrom(\r
address from,\r
address to,\r
uint256 tokenId,\r
bytes memory _data\r
) public payable virtual override {\r
transferFrom(from, to, tokenId);\r
if (to.code.length != 0)\r
if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {\r
_revert(TransferToNonERC721ReceiverImplementer.selector);\r
}\r
}\r
\r
/**\r
* @dev Hook that is called before a set of serially-ordered token IDs\r
* are about to be transferred. This includes minting.\r
* And also called before burning one token.\r
*\r
* `startTokenId` - the first token ID to be transferred.\r
* `quantity` - the amount to be transferred.\r
*\r
* Calling conditions:\r
*\r
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\r
* transferred to `to`.\r
* - When `from` is zero, `tokenId` will be minted for `to`.\r
* - When `to` is zero, `tokenId` will be burned by `from`.\r
* - `from` and `to` are never both zero.\r
*/\r
function _beforeTokenTransfers(\r
address from,\r
address to,\r
uint256 startTokenId,\r
uint256 quantity\r
) internal virtual {}\r
\r
/**\r
* @dev Hook that is called after a set of serially-ordered token IDs\r
* have been transferred. This includes minting.\r
* And also called after one token has been burned.\r
*\r
* `startTokenId` - the first token ID to be transferred.\r
* `quantity` - the amount to be transferred.\r
*\r
* Calling conditions:\r
*\r
* - When `from` and `to` are both non-zero, `from`'s `tokenId` has been\r
* transferred to `to`.\r
* - When `from` is zero, `tokenId` has been minted for `to`.\r
* - When `to` is zero, `tokenId` has been burned by `from`.\r
* - `from` and `to` are never both zero.\r
*/\r
function _afterTokenTransfers(\r
address from,\r
address to,\r
uint256 startTokenId,\r
uint256 quantity\r
) internal virtual {}\r
\r
/**\r
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.\r
*\r
* `from` - Previous owner of the given token ID.\r
* `to` - Target address that will receive the token.\r
* `tokenId` - Token ID to be transferred.\r
* `_data` - Optional data to send along with the call.\r
*\r
* Returns whether the call correctly returned the expected magic value.\r
*/\r
function _checkContractOnERC721Received(\r
address from,\r
address to,\r
uint256 tokenId,\r
bytes memory _data\r
) private returns (bool) {\r
try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (\r
bytes4 retval\r
) {\r
return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;\r
} catch (bytes memory reason) {\r
if (reason.length == 0) {\r
_revert(TransferToNonERC721ReceiverImplementer.selector);\r
}\r
assembly {\r
revert(add(32, reason), mload(reason))\r
}\r
}\r
}\r
\r
// =============================================================\r
// MINT OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Mints `quantity` tokens and transfers them to `to`.\r
*\r
* Requirements:\r
*\r
* - `to` cannot be the zero address.\r
* - `quantity` must be greater than 0.\r
*\r
* Emits a {Transfer} event for each mint.\r
*/\r
function _mint(address to, uint256 quantity) internal virtual {\r
uint256 startTokenId = _currentIndex;\r
if (quantity == 0) _revert(MintZeroQuantity.selector);\r
\r
_beforeTokenTransfers(address(0), to, startTokenId, quantity);\r
\r
// Overflows are incredibly unrealistic.\r
// `balance` and `numberMinted` have a maximum limit of 2**64.\r
// `tokenId` has a maximum limit of 2**256.\r
unchecked {\r
// Updates:\r
// - `address` to the owner.\r
// - `startTimestamp` to the timestamp of minting.\r
// - `burned` to `false`.\r
// - `nextInitialized` to `quantity == 1`.\r
_packedOwnerships[startTokenId] = _packOwnershipData(\r
to,\r
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\r
);\r
\r
// Updates:\r
// - `balance += quantity`.\r
// - `numberMinted += quantity`.\r
//\r
// We can directly add to the `balance` and `numberMinted`.\r
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\r
\r
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.\r
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;\r
\r
if (toMasked == 0) _revert(MintToZeroAddress.selector);\r
\r
uint256 end = startTokenId + quantity;\r
uint256 tokenId = startTokenId;\r
\r
if (end - 1 > _sequentialUpTo()) _revert(SequentialMintExceedsLimit.selector);\r
\r
do {\r
assembly {\r
// Emit the `Transfer` event.\r
log4(\r
0, // Start of data (0, since no data).\r
0, // End of data (0, since no data).\r
_TRANSFER_EVENT_SIGNATURE, // Signature.\r
0, // `address(0)`.\r
toMasked, // `to`.\r
tokenId // `tokenId`.\r
)\r
}\r
// The `!=` check ensures that large values of `quantity`\r
// that overflows uint256 will make the loop run out of gas.\r
} while (++tokenId != end);\r
\r
_currentIndex = end;\r
}\r
_afterTokenTransfers(address(0), to, startTokenId, quantity);\r
}\r
\r
/**\r
* @dev Mints `quantity` tokens and transfers them to `to`.\r
*\r
* This function is intended for efficient minting only during contract creation.\r
*\r
* It emits only one {ConsecutiveTransfer} as defined in\r
* [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),\r
* instead of a sequence of {Transfer} event(s).\r
*\r
* Calling this function outside of contract creation WILL make your contract\r
* non-compliant with the ERC721 standard.\r
* For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309\r
* {ConsecutiveTransfer} event is only permissible during contract creation.\r
*\r
* Requirements:\r
*\r
* - `to` cannot be the zero address.\r
* - `quantity` must be greater than 0.\r
*\r
* Emits a {ConsecutiveTransfer} event.\r
*/\r
function _mintERC2309(address to, uint256 quantity) internal virtual {\r
uint256 startTokenId = _currentIndex;\r
if (to == address(0)) _revert(MintToZeroAddress.selector);\r
if (quantity == 0) _revert(MintZeroQuantity.selector);\r
if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) _revert(MintERC2309QuantityExceedsLimit.selector);\r
\r
_beforeTokenTransfers(address(0), to, startTokenId, quantity);\r
\r
// Overflows are unrealistic due to the above check for `quantity` to be below the limit.\r
unchecked {\r
// Updates:\r
// - `balance += quantity`.\r
// - `numberMinted += quantity`.\r
//\r
// We can directly add to the `balance` and `numberMinted`.\r
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);\r
\r
// Updates:\r
// - `address` to the owner.\r
// - `startTimestamp` to the timestamp of minting.\r
// - `burned` to `false`.\r
// - `nextInitialized` to `quantity == 1`.\r
_packedOwnerships[startTokenId] = _packOwnershipData(\r
to,\r
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)\r
);\r
\r
if (startTokenId + quantity - 1 > _sequentialUpTo()) _revert(SequentialMintExceedsLimit.selector);\r
\r
emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);\r
\r
_currentIndex = startTokenId + quantity;\r
}\r
_afterTokenTransfers(address(0), to, startTokenId, quantity);\r
}\r
\r
/**\r
* @dev Safely mints `quantity` tokens and transfers them to `to`.\r
*\r
* Requirements:\r
*\r
* - If `to` refers to a smart contract, it must implement\r
* {IERC721Receiver-onERC721Received}, which is called for each safe transfer.\r
* - `quantity` must be greater than 0.\r
*\r
* See {_mint}.\r
*\r
* Emits a {Transfer} event for each mint.\r
*/\r
function _safeMint(\r
address to,\r
uint256 quantity,\r
bytes memory _data\r
) internal virtual {\r
_mint(to, quantity);\r
\r
unchecked {\r
if (to.code.length != 0) {\r
uint256 end = _currentIndex;\r
uint256 index = end - quantity;\r
do {\r
if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {\r
_revert(TransferToNonERC721ReceiverImplementer.selector);\r
}\r
} while (index < end);\r
// This prevents reentrancy to `_safeMint`.\r
// It does not prevent reentrancy to `_safeMintSpot`.\r
if (_currentIndex != end) revert();\r
}\r
}\r
}\r
\r
/**\r
* @dev Equivalent to `_safeMint(to, quantity, '')`.\r
*/\r
function _safeMint(address to, uint256 quantity) internal virtual {\r
_safeMint(to, quantity, '');\r
}\r
\r
/**\r
* @dev Mints a single token at `tokenId`.\r
*\r
* Note: A spot-minted `tokenId` that has been burned can be re-minted again.\r
*\r
* Requirements:\r
*\r
* - `to` cannot be the zero address.\r
* - `tokenId` must be greater than `_sequentialUpTo()`.\r
* - `tokenId` must not exist.\r
*\r
* Emits a {Transfer} event for each mint.\r
*/\r
function _mintSpot(address to, uint256 tokenId) internal virtual {\r
if (tokenId <= _sequentialUpTo()) _revert(SpotMintTokenIdTooSmall.selector);\r
uint256 prevOwnershipPacked = _packedOwnerships[tokenId];\r
if (_packedOwnershipExists(prevOwnershipPacked)) _revert(TokenAlreadyExists.selector);\r
\r
_beforeTokenTransfers(address(0), to, tokenId, 1);\r
\r
// Overflows are incredibly unrealistic.\r
// The `numberMinted` for `to` is incremented by 1, and has a max limit of 2**64 - 1.\r
// `_spotMinted` is incremented by 1, and has a max limit of 2**256 - 1.\r
unchecked {\r
// Updates:\r
// - `address` to the owner.\r
// - `startTimestamp` to the timestamp of minting.\r
// - `burned` to `false`.\r
// - `nextInitialized` to `true` (as `quantity == 1`).\r
_packedOwnerships[tokenId] = _packOwnershipData(\r
to,\r
_nextInitializedFlag(1) | _nextExtraData(address(0), to, prevOwnershipPacked)\r
);\r
\r
// Updates:\r
// - `balance += 1`.\r
// - `numberMinted += 1`.\r
//\r
// We can directly add to the `balance` and `numberMinted`.\r
_packedAddressData[to] += (1 << _BITPOS_NUMBER_MINTED) | 1;\r
\r
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.\r
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;\r
\r
if (toMasked == 0) _revert(MintToZeroAddress.selector);\r
\r
assembly {\r
// Emit the `Transfer` event.\r
log4(\r
0, // Start of data (0, since no data).\r
0, // End of data (0, since no data).\r
_TRANSFER_EVENT_SIGNATURE, // Signature.\r
0, // `address(0)`.\r
toMasked, // `to`.\r
tokenId // `tokenId`.\r
)\r
}\r
\r
++_spotMinted;\r
}\r
\r
_afterTokenTransfers(address(0), to, tokenId, 1);\r
}\r
\r
/**\r
* @dev Safely mints a single token at `tokenId`.\r
*\r
* Note: A spot-minted `tokenId` that has been burned can be re-minted again.\r
*\r
* Requirements:\r
*\r
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}.\r
* - `tokenId` must be greater than `_sequentialUpTo()`.\r
* - `tokenId` must not exist.\r
*\r
* See {_mintSpot}.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function _safeMintSpot(\r
address to,\r
uint256 tokenId,\r
bytes memory _data\r
) internal virtual {\r
_mintSpot(to, tokenId);\r
\r
unchecked {\r
if (to.code.length != 0) {\r
uint256 currentSpotMinted = _spotMinted;\r
if (!_checkContractOnERC721Received(address(0), to, tokenId, _data)) {\r
_revert(TransferToNonERC721ReceiverImplementer.selector);\r
}\r
// This prevents reentrancy to `_safeMintSpot`.\r
// It does not prevent reentrancy to `_safeMint`.\r
if (_spotMinted != currentSpotMinted) revert();\r
}\r
}\r
}\r
\r
/**\r
* @dev Equivalent to `_safeMintSpot(to, tokenId, '')`.\r
*/\r
function _safeMintSpot(address to, uint256 tokenId) internal virtual {\r
_safeMintSpot(to, tokenId, '');\r
}\r
\r
// =============================================================\r
// APPROVAL OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Equivalent to `_approve(to, tokenId, false)`.\r
*/\r
function _approve(address to, uint256 tokenId) internal virtual {\r
_approve(to, tokenId, false);\r
}\r
\r
/**\r
* @dev Gives permission to `to` to transfer `tokenId` token to another account.\r
* The approval is cleared when the token is transferred.\r
*\r
* Only a single account can be approved at a time, so approving the\r
* zero address clears previous approvals.\r
*\r
* Requirements:\r
*\r
* - `tokenId` must exist.\r
*\r
* Emits an {Approval} event.\r
*/\r
function _approve(\r
address to,\r
uint256 tokenId,\r
bool approvalCheck\r
) internal virtual {\r
address owner = ownerOf(tokenId);\r
\r
if (approvalCheck && _msgSenderERC721A() != owner)\r
if (!isApprovedForAll(owner, _msgSenderERC721A())) {\r
_revert(ApprovalCallerNotOwnerNorApproved.selector);\r
}\r
\r
_tokenApprovals[tokenId].value = to;\r
emit Approval(owner, to, tokenId);\r
}\r
\r
// =============================================================\r
// BURN OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Equivalent to `_burn(tokenId, false)`.\r
*/\r
function _burn(uint256 tokenId) internal virtual {\r
_burn(tokenId, false);\r
}\r
\r
/**\r
* @dev Destroys `tokenId`.\r
* The approval is cleared when the token is burned.\r
*\r
* Requirements:\r
*\r
* - `tokenId` must exist.\r
*\r
* Emits a {Transfer} event.\r
*/\r
function _burn(uint256 tokenId, bool approvalCheck) internal virtual {\r
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\r
\r
address from = address(uint160(prevOwnershipPacked));\r
\r
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);\r
\r
if (approvalCheck) {\r
// The nested ifs save around 20+ gas over a compound boolean condition.\r
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))\r
if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);\r
}\r
\r
_beforeTokenTransfers(from, address(0), tokenId, 1);\r
\r
// Clear approvals from the previous owner.\r
assembly {\r
if approvedAddress {\r
// This is equivalent to `delete _tokenApprovals[tokenId]`.\r
sstore(approvedAddressSlot, 0)\r
}\r
}\r
\r
// Underflow of the sender's balance is impossible because we check for\r
// ownership above and the recipient's balance can't realistically overflow.\r
// Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\r
unchecked {\r
// Updates:\r
// - `balance -= 1`.\r
// - `numberBurned += 1`.\r
//\r
// We can directly decrement the balance, and increment the number burned.\r
// This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.\r
_packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;\r
\r
// Updates:\r
// - `address` to the last owner.\r
// - `startTimestamp` to the timestamp of burning.\r
// - `burned` to `true`.\r
// - `nextInitialized` to `true`.\r
_packedOwnerships[tokenId] = _packOwnershipData(\r
from,\r
(_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)\r
);\r
\r
// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\r
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\r
uint256 nextTokenId = tokenId + 1;\r
// If the next slot's address is zero and not burned (i.e. packed value is zero).\r
if (_packedOwnerships[nextTokenId] == 0) {\r
// If the next slot is within bounds.\r
if (nextTokenId != _currentIndex) {\r
// Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\r
_packedOwnerships[nextTokenId] = prevOwnershipPacked;\r
}\r
}\r
}\r
}\r
\r
emit Transfer(from, address(0), tokenId);\r
_afterTokenTransfers(from, address(0), tokenId, 1);\r
\r
// Overflow not possible, as `_burnCounter` cannot be exceed `_currentIndex + _spotMinted` times.\r
unchecked {\r
_burnCounter++;\r
}\r
}\r
\r
// =============================================================\r
// EXTRA DATA OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Directly sets the extra data for the ownership data `index`.\r
*/\r
function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {\r
uint256 packed = _packedOwnerships[index];\r
if (packed == 0) _revert(OwnershipNotInitializedForExtraData.selector);\r
uint256 extraDataCasted;\r
// Cast `extraData` with assembly to avoid redundant masking.\r
assembly {\r
extraDataCasted := extraData\r
}\r
packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);\r
_packedOwnerships[index] = packed;\r
}\r
\r
/**\r
* @dev Called during each token transfer to set the 24bit `extraData` field.\r
* Intended to be overridden by the cosumer contract.\r
*\r
* `previousExtraData` - the value of `extraData` before transfer.\r
*\r
* Calling conditions:\r
*\r
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\r
* transferred to `to`.\r
* - When `from` is zero, `tokenId` will be minted for `to`.\r
* - When `to` is zero, `tokenId` will be burned by `from`.\r
* - `from` and `to` are never both zero.\r
*/\r
function _extraData(\r
address from,\r
address to,\r
uint24 previousExtraData\r
) internal view virtual returns (uint24) {}\r
\r
/**\r
* @dev Returns the next extra data for the packed ownership data.\r
* The returned result is shifted into position.\r
*/\r
function _nextExtraData(\r
address from,\r
address to,\r
uint256 prevOwnershipPacked\r
) private view returns (uint256) {\r
uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);\r
return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;\r
}\r
\r
// =============================================================\r
// OTHER OPERATIONS\r
// =============================================================\r
\r
/**\r
* @dev Returns the message sender (defaults to `msg.sender`).\r
*\r
* If you are writing GSN compatible contracts, you need to override this function.\r
*/\r
function _msgSenderERC721A() internal view virtual returns (address) {\r
return msg.sender;\r
}\r
\r
/**\r
* @dev Converts a uint256 to its ASCII string decimal representation.\r
*/\r
function _toString(uint256 value) internal pure virtual returns (string memory str) {\r
assembly {\r
// The maximum value of a uint256 contains 78 digits (1 byte per digit), but\r
// we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.\r
// We will need 1 word for the trailing zeros padding, 1 word for the length,\r
// and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0.\r
let m := add(mload(0x40), 0xa0)\r
// Update the free memory pointer to allocate.\r
mstore(0x40, m)\r
// Assign the `str` to the end.\r
str := sub(m, 0x20)\r
// Zeroize the slot after the string.\r
mstore(str, 0)\r
\r
// Cache the end of the memory to calculate the length later.\r
let end := str\r
\r
// We write the string from rightmost digit to leftmost digit.\r
// The following is essentially a do-while loop that also handles the zero case.\r
// prettier-ignore\r
for { let temp := value } 1 {} {\r
str := sub(str, 1)\r
// Write the character to the pointer.\r
// The ASCII index of the '0' character is 48.\r
mstore8(str, add(48, mod(temp, 10)))\r
// Keep dividing `temp` until zero.\r
temp := div(temp, 10)\r
// prettier-ignore\r
if iszero(temp) { break }\r
}\r
\r
let length := sub(end, str)\r
// Move the pointer 32 bytes leftwards to make room for the length.\r
str := sub(str, 0x20)\r
// Store the length.\r
mstore(str, length)\r
}\r
}\r
\r
/**\r
* @dev For more efficient reverts.\r
*/\r
function _revert(bytes4 errorSelector) internal pure {\r
assembly {\r
mstore(0x00, errorSelector)\r
revert(0x00, 0x04)\r
}\r
}\r
}\r
\r
// File: @openzeppelin/contracts/utils/Context.sol\r
\r
\r
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\r
\r
pragma solidity ^0.8.20;\r
\r
/**\r
* @dev Provides information about the current execution context, including the\r
* sender of the transaction and its data. While these are generally available\r
* via msg.sender and msg.data, they should not be accessed in such a direct\r
* manner, since when dealing with meta-transactions the account sending and\r
* paying for execution may not be the actual sender (as far as an application\r
* is concerned).\r
*\r
* This contract is only required for intermediate, library-like contracts.\r
*/\r
abstract contract Context {\r
function _msgSender() internal view virtual returns (address) {\r
return msg.sender;\r
}\r
\r
function _msgData() internal view virtual returns (bytes calldata) {\r
return msg.data;\r
}\r
\r
function _contextSuffixLength() internal view virtual returns (uint256) {\r
return 0;\r
}\r
}\r
\r
// File: @openzeppelin/contracts/access/Ownable.sol\r
\r
\r
// OpenZeppelin Contracts (last updated v5.0.
Submitted on: 2025-11-04 12:46:36
Comments
Log in to comment.
No comments yet.