diff --git a/EIPS/eip-5008.md b/EIPS/eip-5008.md index 56252e39f1022..5dde543fc75c2 100755 --- a/EIPS/eip-5008.md +++ b/EIPS/eip-5008.md @@ -4,7 +4,8 @@ title: ERC-721 Nonce Extension description: Add a `nonce` function to ERC-721. author: Anders (@0xanders), Lance (@LanceSnow), Shrug discussions-to: https://ethereum-magicians.org/t/eip5008-eip-721-nonce-and-metadata-update-extension/8925 -status: Final +status: Last Call +last-call-deadline: 2023-08-15 type: Standards Track category: ERC created: 2022-04-10 @@ -26,7 +27,12 @@ This EIP proposes adding a `nonce` property to ERC-721 tokens, and the `nonce` w The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY" and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. ```solidity + +/// @dev the ERC-165 identifier for this interface is 0xce03fdab. interface IERC5008 /* is IERC165 */ { + /// @notice Emitted when the `nonce` of an NFT is changed + event NonceChanged(uint256 tokenId, uint256 nonce); + /// @notice Get the nonce of an NFT /// Throws if `tokenId` is not a valid NFT /// @param tokenId The id of the NFT @@ -56,7 +62,7 @@ Run: ```sh cd ../assets/eip-5008 npm install -npx hardhat test ./test/test.ts +npm run test ``` ## Reference Implementation diff --git a/assets/eip-5008/contracts/ERC5008.sol b/assets/eip-5008/contracts/ERC5008.sol index ccf251c178a00..99fa042b157d5 100644 --- a/assets/eip-5008/contracts/ERC5008.sol +++ b/assets/eip-5008/contracts/ERC5008.sol @@ -27,6 +27,7 @@ contract ERC5008 is ERC721, IERC5008 { ) internal virtual override{ super._beforeTokenTransfer(from, to, tokenId); _tokenNonce[tokenId]++; + emit NonceChanged(tokenId, _tokenNonce[tokenId]); } /// @dev See {IERC165-supportsInterface}. diff --git a/assets/eip-5008/contracts/ERC5008Demo.sol b/assets/eip-5008/contracts/ERC5008Demo.sol index 0e1c6fbffa8a6..89a80de8c51a2 100644 --- a/assets/eip-5008/contracts/ERC5008Demo.sol +++ b/assets/eip-5008/contracts/ERC5008Demo.sol @@ -15,4 +15,8 @@ contract ERC5008Demo is ERC5008{ function mint(address to, uint256 tokenId) public { _mint(to, tokenId); } + + function getInterfaceId() public pure returns (bytes4) { + return type(IERC5008).interfaceId; + } } diff --git a/assets/eip-5008/contracts/IERC5008.sol b/assets/eip-5008/contracts/IERC5008.sol index 2dff84c860266..a7b3741ed3e97 100644 --- a/assets/eip-5008/contracts/IERC5008.sol +++ b/assets/eip-5008/contracts/IERC5008.sol @@ -2,6 +2,9 @@ pragma solidity ^0.8.0; interface IERC5008 /* is IERC165 */ { + /// @notice Emitted when the `nonce` of an NFT is changed + event NonceChanged(uint256 tokenId, uint256 nonce); + /// @notice Get the nonce of an NFT /// Throws if `tokenId` is not a valid NFT /// @param tokenId The id of the NFT diff --git a/assets/eip-5008/package.json b/assets/eip-5008/package.json index 4bdee48c1bc95..8d51880b185c1 100644 --- a/assets/eip-5008/package.json +++ b/assets/eip-5008/package.json @@ -1,5 +1,8 @@ { "name": "EIP-5008", + "scripts": { + "test": "npx hardhat test" + }, "dependencies": { "@openzeppelin/contracts": "^4.7.3", "@nomiclabs/hardhat-ethers": "^2.0.5", diff --git a/assets/eip-5008/test/test.ts b/assets/eip-5008/test/test.ts index 22f272c0d6639..5d85e2becf934 100644 --- a/assets/eip-5008/test/test.ts +++ b/assets/eip-5008/test/test.ts @@ -11,12 +11,19 @@ describe("Test ERC5008 ", function () { let contract = await ERC5008Demo.deploy("ERC5008Demo","ERC5008Demo"); let tokenId = 1; - await contract.mint(alice.address, tokenId); + await expect(contract.mint(alice.address, tokenId)).to.emit(contract, "NonceChanged").withArgs(tokenId, 1); expect(await contract.nonce(tokenId)).equals(1); - await contract.transferFrom(alice.address, bob.address, tokenId); + + await expect(contract.transferFrom(alice.address, bob.address, tokenId)).to.emit(contract, "NonceChanged").withArgs(tokenId, 2); + expect(await contract.nonce(tokenId)).equals(2); + + console.log("IERC5008 InterfaceId:", await contract.getInterfaceId()) + let isSupport = await contract.supportsInterface('0xce03fdab'); + expect(isSupport).equals(true , "supportsInterface error"); + }); });