Skip to content

Commit a83d9aa

Browse files
arr00ernestognw
andauthored
Add ERC-165 detection for ERC6909TokenSupply and ERC6909Metadata (#6247)
Co-authored-by: ernestognw <ernestognw@gmail.com>
1 parent 0d9fcb7 commit a83d9aa

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

.changeset/curly-pandas-flow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'openzeppelin-solidity': patch
33
---
44

5-
`ERC6909ContentURI`: Add ERC-165 detection for the `IERC6909ContentURI` interface.
5+
Add ERC-165 detection for the `IERC6909ContentURI`, `IERC6909TokenSupply` and `IERC6909Metadata` interfaces in the `ERC6909ContentURI`, `ERC6909TokenSupply` and `ERC6909Metadata` contracts respectively.

contracts/token/ERC6909/extensions/ERC6909Metadata.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.20;
55

66
import {ERC6909} from "../ERC6909.sol";
77
import {IERC6909Metadata} from "../../../interfaces/IERC6909.sol";
8+
import {IERC165} from "../../../utils/introspection/IERC165.sol";
89

910
/**
1011
* @dev Implementation of the Metadata extension defined in ERC6909. Exposes the name, symbol, and decimals of each token id.
@@ -42,6 +43,11 @@ contract ERC6909Metadata is ERC6909, IERC6909Metadata {
4243
return _tokenMetadata[id].decimals;
4344
}
4445

46+
/// @inheritdoc IERC165
47+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC6909, IERC165) returns (bool) {
48+
return interfaceId == type(IERC6909Metadata).interfaceId || super.supportsInterface(interfaceId);
49+
}
50+
4551
/**
4652
* @dev Sets the `name` for a given token of type `id`.
4753
*

contracts/token/ERC6909/extensions/ERC6909TokenSupply.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.20;
55

66
import {ERC6909} from "../ERC6909.sol";
77
import {IERC6909TokenSupply} from "../../../interfaces/IERC6909.sol";
8+
import {IERC165} from "../../../utils/introspection/IERC165.sol";
89

910
/**
1011
* @dev Implementation of the Token Supply extension defined in ERC6909.
@@ -18,6 +19,11 @@ contract ERC6909TokenSupply is ERC6909, IERC6909TokenSupply {
1819
return _totalSupplies[id];
1920
}
2021

22+
/// @inheritdoc IERC165
23+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC6909, IERC165) returns (bool) {
24+
return interfaceId == type(IERC6909TokenSupply).interfaceId || super.supportsInterface(interfaceId);
25+
}
26+
2127
/// @dev Override the `_update` function to update the total supply of each token id as necessary.
2228
function _update(address from, address to, uint256 id, uint256 amount) internal virtual override {
2329
super._update(from, to, id, amount);

test/token/ERC6909/extensions/ERC6909Metadata.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const { ethers } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

5+
const { shouldSupportInterfaces } = require('../../../utils/introspection/SupportsInterface.behavior');
6+
57
async function fixture() {
68
const token = await ethers.deployContract('$ERC6909Metadata');
79
return { token };
@@ -55,4 +57,6 @@ describe('ERC6909Metadata', function () {
5557
await expect(this.token.decimals(2n)).to.eventually.equal(0);
5658
});
5759
});
60+
61+
shouldSupportInterfaces(['ERC6909', 'ERC6909Metadata']);
5862
});

test/token/ERC6909/extensions/ERC6909TokenSupply.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

55
const { shouldBehaveLikeERC6909 } = require('../ERC6909.behavior');
6+
const { shouldSupportInterfaces } = require('../../../utils/introspection/SupportsInterface.behavior');
67

78
async function fixture() {
89
const [holder, operator, recipient, other] = await ethers.getSigners();
@@ -50,4 +51,6 @@ describe('ERC6909TokenSupply', function () {
5051
});
5152
});
5253
});
54+
55+
shouldSupportInterfaces(['ERC6909', 'ERC6909TokenSupply']);
5356
});

test/utils/introspection/SupportsInterface.behavior.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const SIGNATURES = {
9999
'approve(address,uint256,uint256)',
100100
'setOperator(address,bool)',
101101
],
102+
ERC6909TokenSupply: ['totalSupply(uint256)'],
103+
ERC6909Metadata: ['name(uint256)', 'symbol(uint256)', 'decimals(uint256)'],
102104
ERC6909ContentURI: ['contractURI()', 'tokenURI(uint256)'],
103105
};
104106

0 commit comments

Comments
 (0)