IERC1820Registry.sol 4.6 KB

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