Skip to content

Commit 644babf

Browse files
nkrishangKrishang NadgaudaKrishang Nadgauda
authored
Contracts SDK Update: BatchMintMetadata (#200)
* return the index of the batchId in getBatchId * run prettier * pkg release * make tokenURI virtual in ERC721Drop * pkg release * make critical fns public virtual for ERC721Drop * pkg release * make all overrides virtual overrides * pkg release * use PermissionsEnumerable for SoulboundERC721A * pkg release Co-authored-by: Krishang Nadgauda <[email protected]> Co-authored-by: Krishang Nadgauda <[email protected]>
1 parent 8922037 commit 644babf

File tree

8 files changed

+112
-18
lines changed

8 files changed

+112
-18
lines changed

contracts/base/ERC721DelayedReveal.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ contract ERC721DelayedReveal is ERC721LazyMint, DelayedReveal {
4848
* @param _tokenId The tokenId of an NFT.
4949
*/
5050
function tokenURI(uint256 _tokenId) public view override returns (string memory) {
51-
uint256 batchId = getBatchId(_tokenId);
51+
(uint256 batchId, ) = getBatchId(_tokenId);
5252
string memory batchUri = getBaseURI(_tokenId);
5353

5454
if (isEncryptedBatch(batchId)) {

contracts/base/ERC721Drop.sol

+12-11
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ contract ERC721Drop is ERC721SignatureMint, LazyMint, DelayedReveal, DropSingleP
5151
*
5252
* @param _tokenId The tokenId of an NFT.
5353
*/
54-
function tokenURI(uint256 _tokenId) public view override returns (string memory) {
55-
uint256 batchId = getBatchId(_tokenId);
54+
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
55+
(uint256 batchId, ) = getBatchId(_tokenId);
5656
string memory batchUri = getBaseURI(_tokenId);
5757

5858
if (isEncryptedBatch(batchId)) {
@@ -73,7 +73,7 @@ contract ERC721Drop is ERC721SignatureMint, LazyMint, DelayedReveal, DropSingleP
7373
* @param _signature The signature produced by an account signing the mint request.
7474
*/
7575
function mintWithSignature(MintRequest calldata _req, bytes calldata _signature)
76-
external
76+
public
7777
payable
7878
virtual
7979
override
@@ -145,7 +145,7 @@ contract ERC721Drop is ERC721SignatureMint, LazyMint, DelayedReveal, DropSingleP
145145
* @param _index The ID for the batch of delayed-reveal NFTs to reveal.
146146
* @param _key The key with which the base URI for the relevant batch of NFTs was encrypted.
147147
*/
148-
function reveal(uint256 _index, bytes calldata _key) external override returns (string memory revealedURI) {
148+
function reveal(uint256 _index, bytes calldata _key) public virtual override returns (string memory revealedURI) {
149149
require(_canReveal(), "Not authorized");
150150

151151
uint256 batchId = getBatchIdAtIndex(_index);
@@ -169,7 +169,7 @@ contract ERC721Drop is ERC721SignatureMint, LazyMint, DelayedReveal, DropSingleP
169169
uint256,
170170
AllowlistProof calldata,
171171
bytes memory
172-
) internal view override {
172+
) internal view virtual override {
173173
require(msg.sender == tx.origin, "BOT");
174174
if (_currentIndex + _quantity > nextTokenIdToLazyMint) {
175175
revert("Not enough minted tokens");
@@ -181,7 +181,7 @@ contract ERC721Drop is ERC721SignatureMint, LazyMint, DelayedReveal, DropSingleP
181181
uint256 _quantityToClaim,
182182
address _currency,
183183
uint256 _pricePerToken
184-
) internal override(DropSinglePhase, ERC721SignatureMint) {
184+
) internal virtual override(DropSinglePhase, ERC721SignatureMint) {
185185
if (_pricePerToken == 0) {
186186
return;
187187
}
@@ -200,6 +200,7 @@ contract ERC721Drop is ERC721SignatureMint, LazyMint, DelayedReveal, DropSingleP
200200
/// @dev Transfers the NFTs being claimed.
201201
function transferTokensOnClaim(address _to, uint256 _quantityBeingClaimed)
202202
internal
203+
virtual
203204
override
204205
returns (uint256 startTokenId)
205206
{
@@ -208,27 +209,27 @@ contract ERC721Drop is ERC721SignatureMint, LazyMint, DelayedReveal, DropSingleP
208209
}
209210

210211
/// @dev Checks whether primary sale recipient can be set in the given execution context.
211-
function _canSetPrimarySaleRecipient() internal view override returns (bool) {
212+
function _canSetPrimarySaleRecipient() internal view virtual override returns (bool) {
212213
return msg.sender == owner();
213214
}
214215

215216
/// @dev Checks whether owner can be set in the given execution context.
216-
function _canSetOwner() internal view override returns (bool) {
217+
function _canSetOwner() internal view virtual override returns (bool) {
217218
return msg.sender == owner();
218219
}
219220

220221
/// @dev Checks whether royalty info can be set in the given execution context.
221-
function _canSetRoyaltyInfo() internal view override returns (bool) {
222+
function _canSetRoyaltyInfo() internal view virtual override returns (bool) {
222223
return msg.sender == owner();
223224
}
224225

225226
/// @dev Checks whether contract metadata can be set in the given execution context.
226-
function _canSetContractURI() internal view override returns (bool) {
227+
function _canSetContractURI() internal view virtual override returns (bool) {
227228
return msg.sender == owner();
228229
}
229230

230231
/// @dev Checks whether platform fee info can be set in the given execution context.
231-
function _canSetClaimConditions() internal view override returns (bool) {
232+
function _canSetClaimConditions() internal view virtual override returns (bool) {
232233
return msg.sender == owner();
233234
}
234235

contracts/extension/BatchMintMetadata.sol

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ contract BatchMintMetadata {
2828
}
2929

3030
/// @dev Returns the id for the batch of tokens the given tokenId belongs to.
31-
function getBatchId(uint256 _tokenId) internal view returns (uint256) {
31+
function getBatchId(uint256 _tokenId) internal view returns (uint256 batchId, uint256 index) {
3232
uint256 numOfTokenBatches = getBaseURICount();
3333
uint256[] memory indices = batchIds;
3434

3535
for (uint256 i = 0; i < numOfTokenBatches; i += 1) {
3636
if (_tokenId < indices[i]) {
37-
return indices[i];
37+
index = i;
38+
batchId = indices[i];
39+
40+
return (batchId, index);
3841
}
3942
}
4043

contracts/extension/SoulboundERC721A.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.0;
33

4-
import "./Permissions.sol";
4+
import "./PermissionsEnumerable.sol";
55

66
/**
77
* The `SoulboundERC721A` extension smart contract is meant to be used with ERC721A contracts as its base. It
@@ -13,7 +13,7 @@ import "./Permissions.sol";
1313
* - Else, a transfer goes through only if either the sender or recipient holds the transfe role.
1414
*/
1515

16-
abstract contract SoulboundERC721A is Permissions {
16+
abstract contract SoulboundERC721A is PermissionsEnumerable {
1717
/// @dev Only transfers to or from TRANSFER_ROLE holders are valid, when transfers are restricted.
1818
bytes32 public constant TRANSFER_ROLE = keccak256("TRANSFER_ROLE");
1919

contracts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thirdweb-dev/contracts",
33
"description": "Collection of smart contracts deployable via the thirdweb SDK, dashboard and CLI",
4-
"version": "3.0.2",
4+
"version": "3.0.3-4",
55
"license": "Apache-2.0",
66
"repository": {
77
"type": "git",

contracts/signature-drop/SignatureDrop.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ contract SignatureDrop is
101101

102102
/// @dev Returns the URI for a given tokenId.
103103
function tokenURI(uint256 _tokenId) public view override returns (string memory) {
104-
uint256 batchId = getBatchId(_tokenId);
104+
(uint256 batchId, ) = getBatchId(_tokenId);
105105
string memory batchUri = getBaseURI(_tokenId);
106106

107107
if (isEncryptedBatch(batchId)) {

docs/ERC721Multiwrap.md

+45
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,51 @@ function getRoleAdmin(bytes32 role) external view returns (bytes32)
253253
|---|---|---|
254254
| _0 | bytes32 | undefined
255255

256+
### getRoleMember
257+
258+
```solidity
259+
function getRoleMember(bytes32 role, uint256 index) external view returns (address member)
260+
```
261+
262+
263+
264+
*Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information.*
265+
266+
#### Parameters
267+
268+
| Name | Type | Description |
269+
|---|---|---|
270+
| role | bytes32 | undefined
271+
| index | uint256 | undefined
272+
273+
#### Returns
274+
275+
| Name | Type | Description |
276+
|---|---|---|
277+
| member | address | undefined
278+
279+
### getRoleMemberCount
280+
281+
```solidity
282+
function getRoleMemberCount(bytes32 role) external view returns (uint256 count)
283+
```
284+
285+
286+
287+
*Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role.*
288+
289+
#### Parameters
290+
291+
| Name | Type | Description |
292+
|---|---|---|
293+
| role | bytes32 | undefined
294+
295+
#### Returns
296+
297+
| Name | Type | Description |
298+
|---|---|---|
299+
| count | uint256 | undefined
300+
256301
### getRoyaltyInfoForToken
257302

258303
```solidity

docs/SoulboundERC721A.md

+45
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,51 @@ function getRoleAdmin(bytes32 role) external view returns (bytes32)
6666
|---|---|---|
6767
| _0 | bytes32 | undefined
6868

69+
### getRoleMember
70+
71+
```solidity
72+
function getRoleMember(bytes32 role, uint256 index) external view returns (address member)
73+
```
74+
75+
76+
77+
*Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information.*
78+
79+
#### Parameters
80+
81+
| Name | Type | Description |
82+
|---|---|---|
83+
| role | bytes32 | undefined
84+
| index | uint256 | undefined
85+
86+
#### Returns
87+
88+
| Name | Type | Description |
89+
|---|---|---|
90+
| member | address | undefined
91+
92+
### getRoleMemberCount
93+
94+
```solidity
95+
function getRoleMemberCount(bytes32 role) external view returns (uint256 count)
96+
```
97+
98+
99+
100+
*Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role.*
101+
102+
#### Parameters
103+
104+
| Name | Type | Description |
105+
|---|---|---|
106+
| role | bytes32 | undefined
107+
108+
#### Returns
109+
110+
| Name | Type | Description |
111+
|---|---|---|
112+
| count | uint256 | undefined
113+
69114
### grantRole
70115

71116
```solidity

0 commit comments

Comments
 (0)