-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathERC721EthscriptionsSequentialEnumerableUpgradeable.sol
More file actions
86 lines (74 loc) · 3.01 KB
/
Copy pathERC721EthscriptionsSequentialEnumerableUpgradeable.sol
File metadata and controls
86 lines (74 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "./ERC721EthscriptionsUpgradeable.sol";
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @dev Enumerable mixin for Ethscriptions-style collections where token IDs are
* sequential, start at zero, and tokens are never burned.
*/
abstract contract ERC721EthscriptionsSequentialEnumerableUpgradeable is ERC721EthscriptionsUpgradeable, IERC721Enumerable {
/// @dev Raised when a mint attempts to skip or reuse a token ID.
error ERC721SequentialEnumerableInvalidTokenId(uint256 expected, uint256 actual);
/// @dev Raised if a contract attempts to remove a token from supply.
error ERC721SequentialEnumerableTokenRemoval(uint256 tokenId);
/// @custom:storage-location erc7201:ethscriptions.storage.ERC721SequentialEnumerable
struct ERC721SequentialEnumerableStorage {
uint256 _mintCount;
}
function _getERC721SequentialEnumerableStorage()
private
pure
returns (ERC721SequentialEnumerableStorage storage $)
{
bytes32 slot = keccak256(abi.encode("ethscriptions.storage.ERC721SequentialEnumerable"));
assembly {
$.slot := slot
}
}
/// @inheritdoc ERC165Upgradeable
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721EthscriptionsUpgradeable, IERC165)
returns (bool)
{
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/// @inheritdoc IERC721Enumerable
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override(IERC721Enumerable, ERC721EthscriptionsUpgradeable)
returns (uint256)
{
return super.tokenOfOwnerByIndex(owner, index);
}
/// @inheritdoc IERC721Enumerable
function totalSupply() public view virtual override returns (uint256) {
ERC721SequentialEnumerableStorage storage $ = _getERC721SequentialEnumerableStorage();
return $._mintCount;
}
/// @inheritdoc IERC721Enumerable
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
if (index >= totalSupply()) {
revert ERC721OutOfBoundsIndex(address(0), index);
}
return index;
}
function _afterTokenMint(uint256 tokenId) internal virtual override {
ERC721SequentialEnumerableStorage storage $ = _getERC721SequentialEnumerableStorage();
uint256 expectedId = $._mintCount;
if (tokenId != expectedId) {
revert ERC721SequentialEnumerableInvalidTokenId(expectedId, tokenId);
}
unchecked {
$._mintCount = expectedId + 1;
}
}
function _beforeTokenRemoval(uint256 tokenId, address) internal virtual override {
revert ERC721SequentialEnumerableTokenRemoval(tokenId);
}
}