-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ERC721CommonAutoIncrement to provide zero-indexed tokenId i…
…ncrementing + totalSupply(). The _safeMintN(address,uint,[bytes]) functions work identically to _safeMint() but the uint specifies a number of tokens, not the next ID.
- Loading branch information
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2022 the ethier authors (github.com/divergencetech/ethier) | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import "./ERC721Common.sol"; | ||
import "../utils/Monotonic.sol"; | ||
|
||
/** | ||
@notice An extension of the ethier ERC721Common contract that auto-increments | ||
the next tokenId and exposes a totalSupply. | ||
*/ | ||
contract ERC721CommonAutoIncrement is ERC721Common { | ||
using Monotonic for Monotonic.Increaser; | ||
|
||
constructor(string memory name, string memory symbol) | ||
ERC721Common(name, symbol) | ||
{} | ||
|
||
/** | ||
@notice Total number of tokens minted. | ||
*/ | ||
Monotonic.Increaser public totalSupply; | ||
|
||
/** | ||
@dev _safeMint() n tokens to the specified address, only incrementing | ||
totalSupply once. | ||
*/ | ||
function _safeMintN( | ||
address to, | ||
uint256 n, | ||
bytes memory data | ||
) internal { | ||
uint256 tokenId = totalSupply.current(); | ||
uint256 end = tokenId + n; | ||
for (; tokenId < end; ++tokenId) { | ||
_safeMint(to, tokenId, data); | ||
} | ||
totalSupply.add(n); | ||
} | ||
|
||
/** | ||
@dev Alias for _safeMintN(address,uint,bytes) assuming an empty byte buffer. | ||
*/ | ||
function _safeMintN(address to, uint256 n) internal { | ||
_safeMintN(to, n, ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters