Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/curly-pandas-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'openzeppelin-solidity': patch
---

`ERC6909ContentURI`: Add ERC-165 detection for the `IERC6909ContentURI` interface.
Add ERC-165 detection for the `IERC6909ContentURI`, `IERC6909TokenSupply` and `IERC6909Metadata` interfaces in the `ERC6909ContentURI`, `ERC6909TokenSupply` and `ERC6909Metadata` contracts respectively.
6 changes: 6 additions & 0 deletions contracts/token/ERC6909/extensions/ERC6909Metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.20;

import {ERC6909} from "../ERC6909.sol";
import {IERC6909Metadata} from "../../../interfaces/IERC6909.sol";
import {IERC165} from "../../../utils/introspection/IERC165.sol";

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

/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC6909, IERC165) returns (bool) {
return interfaceId == type(IERC6909Metadata).interfaceId || super.supportsInterface(interfaceId);
}

/**
* @dev Sets the `name` for a given token of type `id`.
*
Expand Down
6 changes: 6 additions & 0 deletions contracts/token/ERC6909/extensions/ERC6909TokenSupply.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.20;

import {ERC6909} from "../ERC6909.sol";
import {IERC6909TokenSupply} from "../../../interfaces/IERC6909.sol";
import {IERC165} from "../../../utils/introspection/IERC165.sol";

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

/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC6909, IERC165) returns (bool) {
return interfaceId == type(IERC6909TokenSupply).interfaceId || super.supportsInterface(interfaceId);
}

/// @dev Override the `_update` function to update the total supply of each token id as necessary.
function _update(address from, address to, uint256 id, uint256 amount) internal virtual override {
super._update(from, to, id, amount);
Expand Down
4 changes: 4 additions & 0 deletions test/token/ERC6909/extensions/ERC6909Metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { ethers } = require('hardhat');
const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

const { shouldSupportInterfaces } = require('../../../utils/introspection/SupportsInterface.behavior');

async function fixture() {
const token = await ethers.deployContract('$ERC6909Metadata');
return { token };
Expand Down Expand Up @@ -55,4 +57,6 @@ describe('ERC6909Metadata', function () {
await expect(this.token.decimals(2n)).to.eventually.equal(0);
});
});

shouldSupportInterfaces(['ERC6909', 'ERC6909Metadata']);
});
3 changes: 3 additions & 0 deletions test/token/ERC6909/extensions/ERC6909TokenSupply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

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

async function fixture() {
const [holder, operator, recipient, other] = await ethers.getSigners();
Expand Down Expand Up @@ -50,4 +51,6 @@ describe('ERC6909TokenSupply', function () {
});
});
});

shouldSupportInterfaces(['ERC6909', 'ERC6909TokenSupply']);
});
2 changes: 2 additions & 0 deletions test/utils/introspection/SupportsInterface.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ const SIGNATURES = {
'approve(address,uint256,uint256)',
'setOperator(address,bool)',
],
ERC6909TokenSupply: ['totalSupply(uint256)'],
ERC6909Metadata: ['name(uint256)', 'symbol(uint256)', 'decimals(uint256)'],
ERC6909ContentURI: ['contractURI()', 'tokenURI(uint256)'],
};

Expand Down