Skip to content

Commit

Permalink
Implement EIP-4906 (MetadataUpdated event)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomiOhl committed Jun 29, 2023
1 parent 7fffe9f commit 6421bfe
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 25 deletions.
2 changes: 1 addition & 1 deletion contracts/GuildPin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ contract GuildPin is IGuildPin, Initializable, OwnableUpgradeable, UUPSUpgradeab

cids[tokenId] = newCid;

emit TokenURIUpdated(tokenId);
emit MetadataUpdate(tokenId);
}

function setPinStrings(GuildAction guildAction, PinStrings memory pinStrings) public onlyOwner {
Expand Down
18 changes: 18 additions & 0 deletions contracts/interfaces/IERC4906.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { IERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import { IERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";

/// @title EIP-721 Metadata Update Extension
interface IERC4906 is IERC165Upgradeable, IERC721Upgradeable {
/// @dev This event emits when the metadata of a token is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFT.
event MetadataUpdate(uint256 _tokenId);

/// @dev This event emits when the metadata of a range of tokens is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFTs.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}
4 changes: 0 additions & 4 deletions contracts/interfaces/IGuildPin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ interface IGuildPin {
/// @param guildAction The action whose strings were set.
event PinStringsSet(GuildAction guildAction);

/// @notice Event emitted whenever a token's cid is updated.
/// @param tokenId The id of the updated token.
event TokenURIUpdated(uint256 tokenId);

/// @notice Event emitted when the validSigner is changed.
/// @param newValidSigner The new address of validSigner.
event ValidSignerChanged(address newValidSigner);
Expand Down
11 changes: 8 additions & 3 deletions contracts/token/SoulboundERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ pragma solidity 0.8.19;

/* solhint-disable max-line-length */

import { IERC4906 } from "../interfaces/IERC4906.sol";
import { ERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import { IERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import { ERC721EnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import { IERC721EnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721EnumerableUpgradeable.sol";
import { IERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";

/* solhint-enable max-line-length */

/// @title An enumerable soulbound ERC721.
/// @notice Allowance and transfer-related functions are disabled.
contract SoulboundERC721 is ERC721Upgradeable, ERC721EnumerableUpgradeable {
contract SoulboundERC721 is ERC721Upgradeable, ERC721EnumerableUpgradeable, IERC4906 {
/// @notice Empty space reserved for future updates.
uint256[50] private __gap;

Expand All @@ -28,8 +30,11 @@ contract SoulboundERC721 is ERC721Upgradeable, ERC721EnumerableUpgradeable {
/// @inheritdoc ERC721EnumerableUpgradeable
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC721EnumerableUpgradeable, ERC721Upgradeable) returns (bool) {
return interfaceId == type(IERC721EnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId);
) public view virtual override(ERC721EnumerableUpgradeable, ERC721Upgradeable, IERC165Upgradeable) returns (bool) {
return
interfaceId == 0x49064906 || // ERC4906
interfaceId == type(IERC721EnumerableUpgradeable).interfaceId ||
super.supportsInterface(interfaceId);
}

function approve(
Expand Down
43 changes: 43 additions & 0 deletions docs/contracts/interfaces/IERC4906.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# IERC4906

EIP-721 Metadata Update Extension

## Events

### MetadataUpdate

```solidity
event MetadataUpdate(
uint256 _tokenId
)
```

This event emits when the metadata of a token is changed.
So that the third-party platforms such as NFT market could
timely update the images and related attributes of the NFT.

#### Parameters

| Name | Type | Description |
| :--- | :--- | :---------- |
| `_tokenId` | uint256 | |
### BatchMetadataUpdate

```solidity
event BatchMetadataUpdate(
uint256 _fromTokenId,
uint256 _toTokenId
)
```

This event emits when the metadata of a range of tokens is changed.
So that the third-party platforms such as NFT market could
timely update the images and related attributes of the NFTs.

#### Parameters

| Name | Type | Description |
| :--- | :--- | :---------- |
| `_fromTokenId` | uint256 | |
| `_toTokenId` | uint256 | |

15 changes: 0 additions & 15 deletions docs/contracts/interfaces/IGuildPin.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,6 @@ Event emitted when pretty strings are set for a GuildAction.
| Name | Type | Description |
| :--- | :--- | :---------- |
| `guildAction` | enum IGuildPin.GuildAction | The action whose strings were set. |
### TokenURIUpdated

```solidity
event TokenURIUpdated(
uint256 tokenId
)
```

Event emitted whenever a token's cid is updated.

#### Parameters

| Name | Type | Description |
| :--- | :--- | :---------- |
| `tokenId` | uint256 | The id of the updated token. |
### ValidSignerChanged

```solidity
Expand Down
4 changes: 2 additions & 2 deletions test/GuildPin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ describe("GuildPin", () => {
expect(decodeTokenURI(newTokenURI)).to.contain(cids[1]);
});

it("should emit TokenURIUpdated event", async () => {
it("should emit MetadataUpdate event", async () => {
await expect(pin.updateImageURI(samplePinData, timestamp, cids[0], signature))
.to.emit(pin, "TokenURIUpdated")
.to.emit(pin, "MetadataUpdate")
.withArgs(1);
});
});
Expand Down

0 comments on commit 6421bfe

Please sign in to comment.