ERC165InterfacesSupportedUpgradeable.sol 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "../../utils/introspection/IERC165Upgradeable.sol";
  4. import "../../proxy/utils/Initializable.sol";
  5. /**
  6. * https://eips.ethereum.org/EIPS/eip-214#specification
  7. * From the specification:
  8. * > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead
  9. * throw an exception.
  10. * > These operations include [...], LOG0, LOG1, LOG2, [...]
  11. *
  12. * therefore, because this contract is staticcall'd we need to not emit events (which is how solidity-coverage works)
  13. * solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it
  14. */
  15. contract SupportsInterfaceWithLookupMockUpgradeable is Initializable, IERC165Upgradeable {
  16. /*
  17. * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
  18. */
  19. bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
  20. /**
  21. * @dev A mapping of interface id to whether or not it's supported.
  22. */
  23. mapping(bytes4 => bool) private _supportedInterfaces;
  24. /**
  25. * @dev A contract implementing SupportsInterfaceWithLookup
  26. * implement ERC165 itself.
  27. */
  28. function __SupportsInterfaceWithLookupMock_init() internal onlyInitializing {
  29. __SupportsInterfaceWithLookupMock_init_unchained();
  30. }
  31. function __SupportsInterfaceWithLookupMock_init_unchained() internal onlyInitializing {
  32. _registerInterface(INTERFACE_ID_ERC165);
  33. }
  34. /**
  35. * @dev Implement supportsInterface(bytes4) using a lookup table.
  36. */
  37. function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
  38. return _supportedInterfaces[interfaceId];
  39. }
  40. /**
  41. * @dev Private method for registering an interface.
  42. */
  43. function _registerInterface(bytes4 interfaceId) internal {
  44. require(interfaceId != 0xffffffff, "ERC165InterfacesSupported: invalid interface id");
  45. _supportedInterfaces[interfaceId] = true;
  46. }
  47. /**
  48. * @dev This empty reserved space is put in place to allow future versions to add new
  49. * variables without shifting down storage in the inheritance chain.
  50. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  51. */
  52. uint256[49] private __gap;
  53. }
  54. contract ERC165InterfacesSupportedUpgradeable is Initializable, SupportsInterfaceWithLookupMockUpgradeable {
  55. function __ERC165InterfacesSupported_init(bytes4[] memory interfaceIds) internal onlyInitializing {
  56. __SupportsInterfaceWithLookupMock_init_unchained();
  57. __ERC165InterfacesSupported_init_unchained(interfaceIds);
  58. }
  59. function __ERC165InterfacesSupported_init_unchained(bytes4[] memory interfaceIds) internal onlyInitializing {
  60. for (uint256 i = 0; i < interfaceIds.length; i++) {
  61. _registerInterface(interfaceIds[i]);
  62. }
  63. }
  64. /**
  65. * @dev This empty reserved space is put in place to allow future versions to add new
  66. * variables without shifting down storage in the inheritance chain.
  67. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
  68. */
  69. uint256[50] private __gap;
  70. }