diff --git a/src/upgradeable/ERC721CommonUpgradeable.sol b/src/upgradeable/ERC721CommonUpgradeable.sol index f664fa6..3a7e70a 100644 --- a/src/upgradeable/ERC721CommonUpgradeable.sol +++ b/src/upgradeable/ERC721CommonUpgradeable.sol @@ -13,6 +13,7 @@ abstract contract ERC721CommonUpgradeable is error ErrInvalidArrayLength(); error ErrNonExistentToken(); + /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } @@ -20,22 +21,9 @@ abstract contract ERC721CommonUpgradeable is /** * @inheritdoc IERC721State */ - function stateOf(uint256 _tokenId) external view virtual override returns (bytes memory) { - if (!_exists(_tokenId)) revert ErrNonExistentToken(); - return abi.encodePacked(ownerOf(_tokenId), nonces[_tokenId], _tokenId); - } - - /** - * @dev Override `ERC721Upgradeable-_baseURI`. - */ - function _baseURI() - internal - view - virtual - override(ERC721Upgradeable, ERC721PresetMinterPauserAutoIdCustomizedUpgradeable) - returns (string memory) - { - return super._baseURI(); + function stateOf(uint256 tokenId) external view virtual override returns (bytes memory) { + if (!_exists(tokenId)) revert ErrNonExistentToken(); + return abi.encodePacked(ownerOf(tokenId), nonces(tokenId), tokenId); } /** @@ -51,17 +39,6 @@ abstract contract ERC721CommonUpgradeable is return super.supportsInterface(interfaceId); } - /** - * @dev Override `ERC721PresetMinterPauserAutoIdCustomizedUpgradeable-_beforeTokenTransfer`. - */ - function _beforeTokenTransfer(address _from, address _to, uint256 _firstTokenId, uint256 _batchSize) - internal - virtual - override(ERC721NonceUpgradeable, ERC721PresetMinterPauserAutoIdCustomizedUpgradeable) - { - super._beforeTokenTransfer(_from, _to, _firstTokenId, _batchSize); - } - /** * @dev Bulk create new tokens for `_recipients`. Tokens ID will be automatically * assigned (and available on the emitted {IERC721Upgradeable-Transfer} event), and the token @@ -73,17 +50,42 @@ abstract contract ERC721CommonUpgradeable is * * - the caller must have the `MINTER_ROLE`. */ - function bulkMint(address[] calldata _recipients) + function bulkMint(address[] calldata recipients) external virtual onlyRole(MINTER_ROLE) - returns (uint256[] memory _tokenIds) + returns (uint256[] memory tokenIds) { - if (_recipients.length == 0) revert ErrInvalidArrayLength(); - _tokenIds = new uint256[](_recipients.length); + uint256 length = recipients.length; + if (length == 0) revert ErrInvalidArrayLength(); + tokenIds = new uint256[](length); - for (uint256 _i = 0; _i < _recipients.length; _i++) { - _tokenIds[_i] = _mintFor(_recipients[_i]); + for (uint256 i; i < length; ++i) { + tokenIds[i] = _mintFor(recipients[i]); } } + + /** + * @dev Override `ERC721Upgradeable-_baseURI`. + */ + function _baseURI() + internal + view + virtual + override(ERC721Upgradeable, ERC721PresetMinterPauserAutoIdCustomizedUpgradeable) + returns (string memory) + { + return super._baseURI(); + } + + /** + * @dev Override `ERC721PresetMinterPauserAutoIdCustomizedUpgradeable-_beforeTokenTransfer`. + */ + function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) + internal + virtual + override(ERC721NonceUpgradeable, ERC721PresetMinterPauserAutoIdCustomizedUpgradeable) + { + super._beforeTokenTransfer(from, to, firstTokenId, batchSize); + } } diff --git a/src/upgradeable/ERC721PresetMinterPauserAutoIdCustomizedUpgradeable.sol b/src/upgradeable/ERC721PresetMinterPauserAutoIdCustomizedUpgradeable.sol index afe0ed3..e400034 100644 --- a/src/upgradeable/ERC721PresetMinterPauserAutoIdCustomizedUpgradeable.sol +++ b/src/upgradeable/ERC721PresetMinterPauserAutoIdCustomizedUpgradeable.sol @@ -48,9 +48,16 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is string private _baseTokenURI; + /** + * @dev This empty reserved space is put in place to allow future versions to add new + * variables without shifting down storage in the inheritance chain. + */ + uint256[50] private __gap; + function initialize(string memory name, string memory symbol, string memory baseTokenURI) public virtual initializer { __ERC721PresetMinterPauserAutoId_init(name, symbol, baseTokenURI); } + /** * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the * account that deploys the contract. @@ -58,7 +65,6 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is * Token URIs will be autogenerated based on `baseURI` and their token IDs. * See {ERC721-tokenURI}. */ - function __ERC721PresetMinterPauserAutoId_init(string memory name, string memory symbol, string memory baseTokenURI) internal onlyInitializing @@ -81,10 +87,6 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is _setupRole(PAUSER_ROLE, _msgSender()); } - function _baseURI() internal view virtual override returns (string memory) { - return _baseTokenURI; - } - /** * @dev Creates a new token for `to`. Its token ID will be automatically * assigned (and available on the emitted {IERC721Upgradeable-Transfer} event), and the token @@ -135,14 +137,6 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is _unpause(); } - function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) - internal - virtual - override(ERC721Upgradeable, ERC721EnumerableUpgradeable, ERC721PausableUpgradeable) - { - super._beforeTokenTransfer(from, to, firstTokenId, batchSize); - } - /** * @dev See {IERC165-supportsInterface}. */ @@ -156,6 +150,14 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is return super.supportsInterface(interfaceId); } + function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) + internal + virtual + override(ERC721Upgradeable, ERC721EnumerableUpgradeable, ERC721PausableUpgradeable) + { + super._beforeTokenTransfer(from, to, firstTokenId, batchSize); + } + /** * @dev Helper function to mint for address `to`. * @@ -171,9 +173,12 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is } /** - * @dev This empty reserved space is put in place to allow future versions to add new - * variables without shifting down storage in the inheritance chain. - * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps + * @dev Helper function to mint for address `to`. + * + * See {ERC721Upgradeable-_mint}. + * */ - uint256[48] private __gap; + function _baseURI() internal view virtual override returns (string memory) { + return _baseTokenURI; + } } diff --git a/src/upgradeable/refs/ERC721NonceUpgradeable.sol b/src/upgradeable/refs/ERC721NonceUpgradeable.sol index 6193a97..d075a01 100644 --- a/src/upgradeable/refs/ERC721NonceUpgradeable.sol +++ b/src/upgradeable/refs/ERC721NonceUpgradeable.sol @@ -9,10 +9,10 @@ import "../../../lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/E */ abstract contract ERC721NonceUpgradeable is ERC721Upgradeable { /// @dev Emitted when the token nonce is updated - event NonceUpdated(uint256 indexed _tokenId, uint256 indexed _nonce); + event NonceUpdated(uint256 indexed tokenId, uint256 indexed nonce); - /// @dev Mapping from token id => token nonce - mapping(uint256 => uint256) public nonces; + /// @dev Mapping from token id => token nonce. + mapping(uint256 => uint256) private _nonceOf; /** * @dev This empty reserved space is put in place to allow future versions to add new @@ -20,17 +20,21 @@ abstract contract ERC721NonceUpgradeable is ERC721Upgradeable { */ uint256[50] private ______gap; + function nonces(uint256 tokenId) public view returns (uint256) { + return _nonceOf[tokenId]; + } + /** * @dev Override `ERC721Upgradeable-_beforeTokenTransfer`. */ - function _beforeTokenTransfer(address _from, address _to, uint256 _firstTokenId, uint256 _batchSize) + function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { - for (uint256 _tokenId = _firstTokenId; _tokenId < _firstTokenId + _batchSize; _tokenId++) { - emit NonceUpdated(_tokenId, ++nonces[_tokenId]); + for (uint256 tokenId = firstTokenId; tokenId < firstTokenId + batchSize; tokenId++) { + emit NonceUpdated(tokenId, ++_nonceOf[tokenId]); } - super._beforeTokenTransfer(_from, _to, _firstTokenId, _batchSize); + super._beforeTokenTransfer(from, to, firstTokenId, batchSize); } }