-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement LazyMintERC721 contract extension (#172)
* Implement LazyMintERC721 contract building block * add permissions * docs * add reverts * fix typo * fix conflict with OZ Strings lib, add overrideable tokenURI impl
- Loading branch information
1 parent
937b134
commit ad487f2
Showing
5 changed files
with
193 additions
and
6 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,36 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./LazyMint.sol"; | ||
import "../lib/TWStrings.sol"; | ||
|
||
abstract contract LazyMintERC721 is LazyMint { | ||
using TWStrings for uint256; | ||
|
||
event TokensLazyMinted(uint256 startTokenId, uint256 endTokenId, string baseURI, bytes extraData); | ||
|
||
/// @dev the next available non-minted token id | ||
uint256 public nextTokenIdToMint; | ||
|
||
/// @dev lazy mint a batch of tokens | ||
function lazyMint( | ||
uint256 amount, | ||
string calldata baseURIForTokens, | ||
bytes calldata extraData | ||
) external virtual override returns (uint256 batchId) { | ||
require(amount > 0, "Amount must be greater than 0"); | ||
require(_canLazyMint(), "Not authorized"); | ||
uint256 startId = nextTokenIdToMint; | ||
(nextTokenIdToMint, batchId) = _batchMint(startId, amount, baseURIForTokens); | ||
emit TokensLazyMinted(startId, startId + amount, baseURIForTokens, extraData); | ||
} | ||
|
||
/// @dev Returns the URI for a given tokenId | ||
function tokenURI(uint256 _tokenId) public view virtual returns (string memory) { | ||
string memory batchUri = getBaseURI(_tokenId); | ||
return string(abi.encodePacked(batchUri, _tokenId.toString())); | ||
} | ||
|
||
/// @dev Returns whether lazy minting can be done in the given execution context. | ||
function _canLazyMint() internal virtual returns (bool); | ||
} |
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
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,139 @@ | ||
# LazyMintERC721 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
## Methods | ||
|
||
### getBaseURICount | ||
|
||
```solidity | ||
function getBaseURICount() external view returns (uint256) | ||
``` | ||
|
||
|
||
|
||
*Returns the number of batches of tokens having the same baseURI.* | ||
|
||
|
||
#### Returns | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| _0 | uint256 | undefined | ||
|
||
### getBatchIdAtIndex | ||
|
||
```solidity | ||
function getBatchIdAtIndex(uint256 _index) external view returns (uint256) | ||
``` | ||
|
||
|
||
|
||
*Returns the id for the batch of tokens the given tokenId belongs to.* | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| _index | uint256 | undefined | ||
|
||
#### Returns | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| _0 | uint256 | undefined | ||
|
||
### lazyMint | ||
|
||
```solidity | ||
function lazyMint(uint256 amount, string baseURIForTokens, bytes extraData) external nonpayable returns (uint256 batchId) | ||
``` | ||
|
||
|
||
|
||
*lazy mint a batch of tokens* | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| amount | uint256 | undefined | ||
| baseURIForTokens | string | undefined | ||
| extraData | bytes | undefined | ||
|
||
#### Returns | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| batchId | uint256 | undefined | ||
|
||
### nextTokenIdToMint | ||
|
||
```solidity | ||
function nextTokenIdToMint() external view returns (uint256) | ||
``` | ||
|
||
|
||
|
||
*the next available non-minted token id* | ||
|
||
|
||
#### Returns | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| _0 | uint256 | undefined | ||
|
||
### tokenURI | ||
|
||
```solidity | ||
function tokenURI(uint256 _tokenId) external view returns (string) | ||
``` | ||
|
||
|
||
|
||
*Returns the URI for a given tokenId* | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| _tokenId | uint256 | undefined | ||
|
||
#### Returns | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| _0 | string | undefined | ||
|
||
|
||
|
||
## Events | ||
|
||
### TokensLazyMinted | ||
|
||
```solidity | ||
event TokensLazyMinted(uint256 startTokenId, uint256 endTokenId, string baseURI, bytes extraData) | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
|---|---|---| | ||
| startTokenId | uint256 | undefined | | ||
| endTokenId | uint256 | undefined | | ||
| baseURI | string | undefined | | ||
| extraData | bytes | undefined | | ||
|
||
|
||
|
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,12 @@ | ||
# TWStrings | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
*String operations.* | ||
|
||
|
||
|