Skip to content

Commit

Permalink
Merge pull request #124 from open-format/feature--add-updated-base-ur…
Browse files Browse the repository at this point in the history
…i-event-to-badge-contract

Feature: add updated base uri event to badge contract
  • Loading branch information
george-openformat authored May 16, 2024
2 parents 85c245f + dfbb7fe commit cda19c9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-lizards-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openformat/contracts": patch
---

add metadata update events to ERC721Badge contract
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
26 changes: 26 additions & 0 deletions scripts/tokens/ERC721Badge.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
7 changes: 7 additions & 0 deletions src/tokens/ERC721/ERC721Badge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -155,6 +159,9 @@ contract ERC721Badge is
_batchMintMetadata(0, MAX_INT, _baseURIForTokens);
}

emit BatchMetadataUpdate(0, MAX_INT);
emit UpdatedBaseURI(_baseURIForTokens);

_payPlatformFee(platformFeeRecipient, platformFeeAmount);
}

Expand Down
22 changes: 22 additions & 0 deletions test/tokens/ERC721/ERC721Badge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cda19c9

Please sign in to comment.