IERC1820Registry.sol 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.6.0;
  3. /**
  4. * @dev Interface of the global ERC1820 Registry, as defined in the
  5. * https://eips.ethereum.org/EIPS/eip-1820[EIP]. Accounts may register
  6. * implementers for interfaces in this registry, as well as query support.
  7. *
  8. * Implementers may be shared by multiple accounts, and can also implement more
  9. * than a single interface for each account. Contracts can implement interfaces
  10. * for themselves, but externally-owned accounts (EOA) must delegate this to a
  11. * contract.
  12. *
  13. * {IERC165} interfaces can also be queried via the registry.
  14. *
  15. * For an in-depth explanation and source code analysis, see the EIP text.
  16. */
  17. interface IERC1820Registry {
  18. /**
  19. * @dev Sets `newManager` as the manager for `account`. A manager of an
  20. * account is able to set interface implementers for it.
  21. *
  22. * By default, each account is its own manager. Passing a value of `0x0` in
  23. * `newManager` will reset the manager to this initial state.
  24. *
  25. * Emits a {ManagerChanged} event.
  26. *
  27. * Requirements:
  28. *
  29. * - the caller must be the current manager for `account`.
  30. */
  31. function setManager(address account, address newManager) external;
  32. /**
  33. * @dev Returns the manager for `account`.
  34. *
  35. * See {setManager}.
  36. */
  37. function getManager(address account) external view returns (address);
  38. /**
  39. * @dev Sets the `implementer` contract as ``account``'s implementer for
  40. * `interfaceHash`.
  41. *
  42. * `account` being the zero address is an alias for the caller's address.
  43. * The zero address can also be used in `implementer` to remove an old one.
  44. *
  45. * See {interfaceHash} to learn how these are created.
  46. *
  47. * Emits an {InterfaceImplementerSet} event.
  48. *
  49. * Requirements:
  50. *
  51. * - the caller must be the current manager for `account`.
  52. * - `interfaceHash` must not be an {IERC165} interface id (i.e. it must not
  53. * end in 28 zeroes).
  54. * - `implementer` must implement {IERC1820Implementer} and return true when
  55. * queried for support, unless `implementer` is the caller. See
  56. * {IERC1820Implementer-canImplementInterfaceForAddress}.
  57. */
  58. function setInterfaceImplementer(address account, bytes32 interfaceHash, address implementer) external;
  59. /**
  60. * @dev Returns the implementer of `interfaceHash` for `account`. If no such
  61. * implementer is registered, returns the zero address.
  62. *
  63. * If `interfaceHash` is an {IERC165} interface id (i.e. it ends with 28
  64. * zeroes), `account` will be queried for support of it.
  65. *
  66. * `account` being the zero address is an alias for the caller's address.
  67. */
  68. function getInterfaceImplementer(address account, bytes32 interfaceHash) external view returns (address);
  69. /**
  70. * @dev Returns the interface hash for an `interfaceName`, as defined in the
  71. * corresponding
  72. * https://eips.ethereum.org/EIPS/eip-1820#interface-name[section of the EIP].
  73. */
  74. function interfaceHash(string calldata interfaceName) external pure returns (bytes32);
  75. /**
  76. * @notice Updates the cache with whether the contract implements an ERC165 interface or not.
  77. * @param account Address of the contract for which to update the cache.
  78. * @param interfaceId ERC165 interface for which to update the cache.
  79. */
  80. function updateERC165Cache(address account, bytes4 interfaceId) external;
  81. /**
  82. * @notice Checks whether a contract implements an ERC165 interface or not.
  83. * If the result is not cached a direct lookup on the contract address is performed.
  84. * If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling
  85. * {updateERC165Cache} with the contract address.
  86. * @param account Address of the contract to check.
  87. * @param interfaceId ERC165 interface to check.
  88. * @return True if `account` implements `interfaceId`, false otherwise.
  89. */
  90. function implementsERC165Interface(address account, bytes4 interfaceId) external view returns (bool);
  91. /**
  92. * @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache.
  93. * @param account Address of the contract to check.
  94. * @param interfaceId ERC165 interface to check.
  95. * @return True if `account` implements `interfaceId`, false otherwise.
  96. */
  97. function implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) external view returns (bool);
  98. event InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer);
  99. event ManagerChanged(address indexed account, address indexed newManager);
  100. }