When an interface has multiple levels of inheritance, should the supportsInterface
in ERC165 checks the entire entire inheritance stack of the interface or just the top-most level?
Here's an example. Let's say I have an interface IAnimal
and another interface ICat
which implements IAnimal
like this:
interface IAnimal {
function walk() external;
function run() external;
}
interface ICat is IAnimal {
function meow() external;
function jumps() external;
}
Then, I have a ERC165 contract that uses ICat
:
contract MyContract is ERC165, ICat {
// Implements interface methods of both ICat and IAnimal because ICat implements IAnimal...
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
// How should the check here be like?
}
}
My question is, how should I implement the check in supportsInterface
in this case?
Should the check in supportsInterface
match the interface ID of only the methods in ICat
excluding IAnimal
? Or should the check here match the interface ID of all methods in both ICat
and IAnimal
since ICat
extends IAnimal
?
- If the check only has to match the interface ID of the methods, I could do this:
return interfaceId == type(ICat).interfaceId || interfaceId == type(IAnimal).interfaceId;
- However, if the check has to match the interface ID of all methods in both
ICat
andIAnimal
, how should I combine the interface ID from both interfaces?- I notice that
type(ICat).interfaceId
will ignore the methods inIAnimal
when computing the interface ID. In other words, the interface ID is only computing the methodsmeow()
andjumps()
inICat
but doesn't includewalk()
andrun()
inIAnimal
! This is surprising to me becausetype().interfaceId
seems to ignore any inherited methods in the interface? So I can't usetype(ICat)
. - I tried something like this but this doesn't seem correct:
return interfaceId == type(IAnimal).interfaceId || interfaceId == (type(ICat).interfaceId ^ type(IAnimal).interfaceId);
- I notice that
I haven't found any examples on ERC165 with multiple levels of inheritance with its interface, not even in its EIP doc.