diff --git a/.changeset/late-lizards-sleep.md b/.changeset/late-lizards-sleep.md new file mode 100644 index 0000000..ad57b2c --- /dev/null +++ b/.changeset/late-lizards-sleep.md @@ -0,0 +1,5 @@ +--- +"@openformat/contracts": patch +--- + +add metadata update events to ERC721Badge contract diff --git a/Makefile b/Makefile index fc412c6..9052409 100644 --- a/Makefile +++ b/Makefile @@ -94,6 +94,19 @@ createERC721Base:; forge script scripts/facet/ERC721FactoryFacet.s.sol:CreateBas # Note: make sure app is setup with correct permissions and APP_ID env is set. createERC721Badge:; forge script scripts/facet/ERC721FactoryFacet.s.sol:CreateBadge --rpc-url $(rpc) --broadcast $(verbose) $(legacy) $(slow) +# example: make ERC721Badge.mintTo args="0xaf4c80136581212185f37c5e8809120d8fbf6224" +ERC721Badge.mintTo:; forge script \ + scripts/tokens/ERC721Badge.s.sol:MintTo \ + --sig "run(address)" \ + --rpc-url $(rpc) --broadcast $(verbose) $(legacy) $(slow) $(args) + +# example: make ERC721Badge.setBaseURI args="0xaf4c80136581212185f37c5e8809120d8fbf6224 someotherurl" +ERC721Badge.setBaseURI:; forge script \ + scripts/tokens/ERC721Badge.s.sol:SetBaseURI \ + --sig "run(address,string)" \ + --rpc-url $(rpc) --broadcast $(verbose) $(legacy) $(slow) \ + $(word 1, $(args)) $(word 2, $(args)) + # Run all update scripts update:; make \ update-ERC721FactoryFacet \ diff --git a/scripts/tokens/ERC721Badge.s.sol b/scripts/tokens/ERC721Badge.s.sol index becd01d..26f7883 100644 --- a/scripts/tokens/ERC721Badge.s.sol +++ b/scripts/tokens/ERC721Badge.s.sol @@ -25,3 +25,29 @@ contract Deploy is Script, Utils { exportContractDeployment(CONTRACT_NAME, address(erc721Badge), block.number); } } + +contract SetBaseURI is Script, Utils { + function run(address _contractAddress, string memory _baseURIForTokens) external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + address deployerAddress = vm.addr(deployerPrivateKey); + vm.startBroadcast(deployerPrivateKey); + + ERC721Badge erc721Badge = ERC721Badge(_contractAddress); + erc721Badge.setBaseURI(_baseURIForTokens); + + vm.stopBroadcast(); + } +} + +contract MintTo is Script, Utils { + function run(address _contractAddress) external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + address deployerAddress = vm.addr(deployerPrivateKey); + vm.startBroadcast(deployerPrivateKey); + + ERC721Badge erc721Badge = ERC721Badge(_contractAddress); + erc721Badge.mintTo(deployerAddress); + + vm.stopBroadcast(); + } +} diff --git a/src/tokens/ERC721/ERC721Badge.sol b/src/tokens/ERC721/ERC721Badge.sol index 8ec8bd2..d0dde57 100644 --- a/src/tokens/ERC721/ERC721Badge.sol +++ b/src/tokens/ERC721/ERC721Badge.sol @@ -46,6 +46,8 @@ contract ERC721Badge is event Minted(address to, string tokenURI); event BatchMinted(address to, uint256 quantity, string baseURI); + event UpdatedBaseURI(string baseURIForTokens); + event BatchMetadataUpdate(uint256 fromTokenId, uint256 toTokenId); /** * @dev this contract is meant to be an implementation for a factory contract @@ -103,6 +105,8 @@ contract ERC721Badge is if (bytes(baseURIForTokens).length > 0) { _batchMintMetadata(0, MAX_INT, baseURIForTokens); + emit BatchMetadataUpdate(0, MAX_INT); + emit UpdatedBaseURI(baseURIForTokens); } } @@ -155,6 +159,9 @@ contract ERC721Badge is _batchMintMetadata(0, MAX_INT, _baseURIForTokens); } + emit BatchMetadataUpdate(0, MAX_INT); + emit UpdatedBaseURI(_baseURIForTokens); + _payPlatformFee(platformFeeRecipient, platformFeeAmount); } diff --git a/test/tokens/ERC721/ERC721Badge.t.sol b/test/tokens/ERC721/ERC721Badge.t.sol index e8cde39..30fd71c 100644 --- a/test/tokens/ERC721/ERC721Badge.t.sol +++ b/test/tokens/ERC721/ERC721Badge.t.sol @@ -11,6 +11,9 @@ import {IBatchMintMetadata} from "src/extensions/batchMintMetadata/IBatchMintMet uint256 constant MAX_INT = 2 ** 256 - 1; contract Setup is Test { + event UpdatedBaseURI(string baseURIForTokens); + event BatchMetadataUpdate(uint256 fromTokenId, uint256 toTokenId); + address creator = address(0x10); address other = address(0x11); address globals = address(0x12); @@ -62,6 +65,17 @@ contract ERC721Badge_initialise is Setup { emptyString.mintTo(creator); } + function test_emits_updated_base_uri_event() public { + // global and minter address but baseTokenURI is an empty string + bytes memory data = abi.encode(address(0), address(0), baseURI); + + vm.expectEmit(true, true, true, true); + emit UpdatedBaseURI(baseURI); + + vm.prank(creator); + new ERC721BadgeMock("Name", "Symbol", creator, uint16(tenPercentBPS), data); + } + function test_should_revert_when_initialised_without_base_token_URI() public { vm.prank(creator); // global and minter address but no baseTokenURI in data @@ -95,6 +109,14 @@ contract ERC721Badge__setBaseURI is Setup { assertEq(baseURI, erc721Badge.tokenURI(MAX_INT - 1)); } + function test_emits_updated_base_uri_event() public { + vm.expectEmit(true, true, true, true); + emit UpdatedBaseURI(differentBaseURI); + + vm.prank(creator); + erc721Badge.setBaseURI(differentBaseURI); + } + function test_reverts_when_access_is_invalid() public { vm.expectRevert(ERC721Badge.ERC721Badge_notAuthorized.selector); vm.prank(other);