Skip to content

Commit

Permalink
implmented delayed functionality into batchMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
GWSzeto committed Sep 4, 2024
1 parent 76655aa commit c324d4b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 396 deletions.
45 changes: 44 additions & 1 deletion src/module/token/metadata/BatchMetadataERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {
config.fallbackFunctions[0] =
FallbackFunction({selector: this.uploadMetadata.selector, permissionBits: Role._MINTER_ROLE});
config.fallbackFunctions[1] =
FallbackFunction({selector: this.setBaseURI.selector, permissionBits: Role._MANAGER_ROLE});
config.fallbackFunctions[2] =
FallbackFunction({selector: this.getAllMetadataBatches.selector, permissionBits: 0});
config.fallbackFunctions[2] = FallbackFunction({selector: this.nextTokenIdToMint.selector, permissionBits: 0});
config.fallbackFunctions[3] = FallbackFunction({selector: this.nextTokenIdToMint.selector, permissionBits: 0});
config.fallbackFunctions[4] = FallbackFunction({selector: this.getBatchId.selector, permissionBits: 0});
config.fallbackFunctions[5] = FallbackFunction({selector: this.getBatchStartId.selector, permissionBits: 0});

config.requiredInterfaces = new bytes4[](1);
config.requiredInterfaces[0] = 0x80ac58cd; // ERC721.
Expand Down Expand Up @@ -153,6 +157,45 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {
return _batchMetadataStorage().nextTokenIdRangeStart;
}

/// @dev Returns the id for the batch of tokens the given tokenId belongs to.
function getBatchId(uint256 _tokenId) public view virtual returns (uint256 batchId, uint256 index) {
uint256[] memory rangeEnds = _batchMetadataStorage().tokenIdRangeEnd;
uint256 numOfBatches = rangeEnds.length;

for (uint256 i = 0; i < numOfBatches; i += 1) {
if (_tokenId < rangeEnds[i]) {
index = i;
batchId = rangeEnds[i];

return (batchId, index);
}
}
revert BatchMetadataNoMetadataForTokenId();
}

/// @dev returns the starting tokenId of a given batchId.
function getBatchStartId(uint256 _batchID) public view returns (uint256) {
uint256[] memory rangeEnds = _batchMetadataStorage().tokenIdRangeEnd;
uint256 numOfBatches = rangeEnds.length;

for (uint256 i = 0; i < numOfBatches; i += 1) {
if (_batchID == rangeEnds[i]) {
if (i > 0) {
return rangeEnds[i - 1];
}
return 0;
}
}

revert BatchMetadataNoMetadataForTokenId();
}

/// @dev Sets the base URI for the batch of tokens with the given batchId.
function setBaseURI(uint256 _batchId, string memory _baseURI) external virtual {
_batchMetadataStorage().baseURIOfTokenIdRange[_batchId] = _baseURI;
emit BatchMetadataUpdate(getBatchStartId(_batchId), _batchId);
}

/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
Expand Down
285 changes: 0 additions & 285 deletions src/module/token/metadata/DelayedRevealBatchMetadataERC721.sol

This file was deleted.

25 changes: 0 additions & 25 deletions src/module/token/metadata/SimpleMetadataERC1155.sol

This file was deleted.

Loading

0 comments on commit c324d4b

Please sign in to comment.