IAccessManager.sol 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.4.0-rc.0) (access/manager/IAccessManager.sol)
  3. pragma solidity >=0.8.4;
  4. interface IAccessManager {
  5. /**
  6. * @dev A delayed operation was scheduled.
  7. */
  8. event OperationScheduled(
  9. bytes32 indexed operationId,
  10. uint32 indexed nonce,
  11. uint48 schedule,
  12. address caller,
  13. address target,
  14. bytes data
  15. );
  16. /**
  17. * @dev A scheduled operation was executed.
  18. */
  19. event OperationExecuted(bytes32 indexed operationId, uint32 indexed nonce);
  20. /**
  21. * @dev A scheduled operation was canceled.
  22. */
  23. event OperationCanceled(bytes32 indexed operationId, uint32 indexed nonce);
  24. /**
  25. * @dev Informational labelling for a roleId.
  26. */
  27. event RoleLabel(uint64 indexed roleId, string label);
  28. /**
  29. * @dev Emitted when `account` is granted `roleId`.
  30. *
  31. * NOTE: The meaning of the `since` argument depends on the `newMember` argument.
  32. * If the role is granted to a new member, the `since` argument indicates when the account becomes a member of the role,
  33. * otherwise it indicates the execution delay for this account and roleId is updated.
  34. */
  35. event RoleGranted(uint64 indexed roleId, address indexed account, uint32 delay, uint48 since, bool newMember);
  36. /**
  37. * @dev Emitted when `account` membership or `roleId` is revoked. Unlike granting, revoking is instantaneous.
  38. */
  39. event RoleRevoked(uint64 indexed roleId, address indexed account);
  40. /**
  41. * @dev Role acting as admin over a given `roleId` is updated.
  42. */
  43. event RoleAdminChanged(uint64 indexed roleId, uint64 indexed admin);
  44. /**
  45. * @dev Role acting as guardian over a given `roleId` is updated.
  46. */
  47. event RoleGuardianChanged(uint64 indexed roleId, uint64 indexed guardian);
  48. /**
  49. * @dev Grant delay for a given `roleId` will be updated to `delay` when `since` is reached.
  50. */
  51. event RoleGrantDelayChanged(uint64 indexed roleId, uint32 delay, uint48 since);
  52. /**
  53. * @dev Target mode is updated (true = closed, false = open).
  54. */
  55. event TargetClosed(address indexed target, bool closed);
  56. /**
  57. * @dev Role required to invoke `selector` on `target` is updated to `roleId`.
  58. */
  59. event TargetFunctionRoleUpdated(address indexed target, bytes4 selector, uint64 indexed roleId);
  60. /**
  61. * @dev Admin delay for a given `target` will be updated to `delay` when `since` is reached.
  62. */
  63. event TargetAdminDelayUpdated(address indexed target, uint32 delay, uint48 since);
  64. error AccessManagerAlreadyScheduled(bytes32 operationId);
  65. error AccessManagerNotScheduled(bytes32 operationId);
  66. error AccessManagerNotReady(bytes32 operationId);
  67. error AccessManagerExpired(bytes32 operationId);
  68. error AccessManagerLockedRole(uint64 roleId);
  69. error AccessManagerBadConfirmation();
  70. error AccessManagerUnauthorizedAccount(address msgsender, uint64 roleId);
  71. error AccessManagerUnauthorizedCall(address caller, address target, bytes4 selector);
  72. error AccessManagerUnauthorizedConsume(address target);
  73. error AccessManagerUnauthorizedCancel(address msgsender, address caller, address target, bytes4 selector);
  74. error AccessManagerInvalidInitialAdmin(address initialAdmin);
  75. /**
  76. * @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with
  77. * no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}
  78. * & {execute} workflow.
  79. *
  80. * This function is usually called by the targeted contract to control immediate execution of restricted functions.
  81. * Therefore we only return true if the call can be performed without any delay. If the call is subject to a
  82. * previously set delay (not zero), then the function should return false and the caller should schedule the operation
  83. * for future execution.
  84. *
  85. * If `immediate` is true, the delay can be disregarded and the operation can be immediately executed, otherwise
  86. * the operation can be executed if and only if delay is greater than 0.
  87. *
  88. * NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that
  89. * is backward compatible. Some contracts may thus ignore the second return argument. In that case they will fail
  90. * to identify the indirect workflow, and will consider calls that require a delay to be forbidden.
  91. *
  92. * NOTE: This function does not report the permissions of the admin functions in the manager itself. These are defined by the
  93. * {AccessManager} documentation.
  94. */
  95. function canCall(
  96. address caller,
  97. address target,
  98. bytes4 selector
  99. ) external view returns (bool allowed, uint32 delay);
  100. /**
  101. * @dev Expiration delay for scheduled proposals. Defaults to 1 week.
  102. *
  103. * IMPORTANT: Avoid overriding the expiration with 0. Otherwise every contract proposal will be expired immediately,
  104. * disabling any scheduling usage.
  105. */
  106. function expiration() external view returns (uint32);
  107. /**
  108. * @dev Minimum setback for all delay updates, with the exception of execution delays. It
  109. * can be increased without setback (and reset via {revokeRole} in the case event of an
  110. * accidental increase). Defaults to 5 days.
  111. */
  112. function minSetback() external view returns (uint32);
  113. /**
  114. * @dev Get whether the contract is closed disabling any access. Otherwise role permissions are applied.
  115. *
  116. * NOTE: When the manager itself is closed, admin functions are still accessible to avoid locking the contract.
  117. */
  118. function isTargetClosed(address target) external view returns (bool);
  119. /**
  120. * @dev Get the role required to call a function.
  121. */
  122. function getTargetFunctionRole(address target, bytes4 selector) external view returns (uint64);
  123. /**
  124. * @dev Get the admin delay for a target contract. Changes to contract configuration are subject to this delay.
  125. */
  126. function getTargetAdminDelay(address target) external view returns (uint32);
  127. /**
  128. * @dev Get the id of the role that acts as an admin for the given role.
  129. *
  130. * The admin permission is required to grant the role, revoke the role and update the execution delay to execute
  131. * an operation that is restricted to this role.
  132. */
  133. function getRoleAdmin(uint64 roleId) external view returns (uint64);
  134. /**
  135. * @dev Get the role that acts as a guardian for a given role.
  136. *
  137. * The guardian permission allows canceling operations that have been scheduled under the role.
  138. */
  139. function getRoleGuardian(uint64 roleId) external view returns (uint64);
  140. /**
  141. * @dev Get the role current grant delay.
  142. *
  143. * Its value may change at any point without an event emitted following a call to {setGrantDelay}.
  144. * Changes to this value, including effect timepoint are notified in advance by the {RoleGrantDelayChanged} event.
  145. */
  146. function getRoleGrantDelay(uint64 roleId) external view returns (uint32);
  147. /**
  148. * @dev Get the access details for a given account for a given role. These details include the timepoint at which
  149. * membership becomes active, and the delay applied to all operation by this user that requires this permission
  150. * level.
  151. *
  152. * Returns:
  153. * [0] Timestamp at which the account membership becomes valid. 0 means role is not granted.
  154. * [1] Current execution delay for the account.
  155. * [2] Pending execution delay for the account.
  156. * [3] Timestamp at which the pending execution delay will become active. 0 means no delay update is scheduled.
  157. */
  158. function getAccess(
  159. uint64 roleId,
  160. address account
  161. ) external view returns (uint48 since, uint32 currentDelay, uint32 pendingDelay, uint48 effect);
  162. /**
  163. * @dev Check if a given account currently has the permission level corresponding to a given role. Note that this
  164. * permission might be associated with an execution delay. {getAccess} can provide more details.
  165. */
  166. function hasRole(uint64 roleId, address account) external view returns (bool isMember, uint32 executionDelay);
  167. /**
  168. * @dev Give a label to a role, for improved role discoverability by UIs.
  169. *
  170. * Requirements:
  171. *
  172. * - the caller must be a global admin
  173. *
  174. * Emits a {RoleLabel} event.
  175. */
  176. function labelRole(uint64 roleId, string calldata label) external;
  177. /**
  178. * @dev Add `account` to `roleId`, or change its execution delay.
  179. *
  180. * This gives the account the authorization to call any function that is restricted to this role. An optional
  181. * execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation
  182. * that is restricted to members of this role. The user will only be able to execute the operation after the delay has
  183. * passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).
  184. *
  185. * If the account has already been granted this role, the execution delay will be updated. This update is not
  186. * immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is
  187. * called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any
  188. * operation executed in the 3 hours that follows this update was indeed scheduled before this update.
  189. *
  190. * Requirements:
  191. *
  192. * - the caller must be an admin for the role (see {getRoleAdmin})
  193. * - granted role must not be the `PUBLIC_ROLE`
  194. *
  195. * Emits a {RoleGranted} event.
  196. */
  197. function grantRole(uint64 roleId, address account, uint32 executionDelay) external;
  198. /**
  199. * @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has
  200. * no effect.
  201. *
  202. * Requirements:
  203. *
  204. * - the caller must be an admin for the role (see {getRoleAdmin})
  205. * - revoked role must not be the `PUBLIC_ROLE`
  206. *
  207. * Emits a {RoleRevoked} event if the account had the role.
  208. */
  209. function revokeRole(uint64 roleId, address account) external;
  210. /**
  211. * @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in
  212. * the role this call has no effect.
  213. *
  214. * Requirements:
  215. *
  216. * - the caller must be `callerConfirmation`.
  217. *
  218. * Emits a {RoleRevoked} event if the account had the role.
  219. */
  220. function renounceRole(uint64 roleId, address callerConfirmation) external;
  221. /**
  222. * @dev Change admin role for a given role.
  223. *
  224. * Requirements:
  225. *
  226. * - the caller must be a global admin
  227. *
  228. * Emits a {RoleAdminChanged} event
  229. */
  230. function setRoleAdmin(uint64 roleId, uint64 admin) external;
  231. /**
  232. * @dev Change guardian role for a given role.
  233. *
  234. * Requirements:
  235. *
  236. * - the caller must be a global admin
  237. *
  238. * Emits a {RoleGuardianChanged} event
  239. */
  240. function setRoleGuardian(uint64 roleId, uint64 guardian) external;
  241. /**
  242. * @dev Update the delay for granting a `roleId`.
  243. *
  244. * Requirements:
  245. *
  246. * - the caller must be a global admin
  247. *
  248. * Emits a {RoleGrantDelayChanged} event.
  249. */
  250. function setGrantDelay(uint64 roleId, uint32 newDelay) external;
  251. /**
  252. * @dev Set the role required to call functions identified by the `selectors` in the `target` contract.
  253. *
  254. * Requirements:
  255. *
  256. * - the caller must be a global admin
  257. *
  258. * Emits a {TargetFunctionRoleUpdated} event per selector.
  259. */
  260. function setTargetFunctionRole(address target, bytes4[] calldata selectors, uint64 roleId) external;
  261. /**
  262. * @dev Set the delay for changing the configuration of a given target contract.
  263. *
  264. * Requirements:
  265. *
  266. * - the caller must be a global admin
  267. *
  268. * Emits a {TargetAdminDelayUpdated} event.
  269. */
  270. function setTargetAdminDelay(address target, uint32 newDelay) external;
  271. /**
  272. * @dev Set the closed flag for a contract.
  273. *
  274. * Closing the manager itself won't disable access to admin methods to avoid locking the contract.
  275. *
  276. * Requirements:
  277. *
  278. * - the caller must be a global admin
  279. *
  280. * Emits a {TargetClosed} event.
  281. */
  282. function setTargetClosed(address target, bool closed) external;
  283. /**
  284. * @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
  285. * operation is not yet scheduled, has expired, was executed, or was canceled.
  286. */
  287. function getSchedule(bytes32 id) external view returns (uint48);
  288. /**
  289. * @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never
  290. * been scheduled.
  291. */
  292. function getNonce(bytes32 id) external view returns (uint32);
  293. /**
  294. * @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to
  295. * choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays
  296. * required for the caller. The special value zero will automatically set the earliest possible time.
  297. *
  298. * Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when
  299. * the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this
  300. * scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.
  301. *
  302. * Emits a {OperationScheduled} event.
  303. *
  304. * NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If
  305. * this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target
  306. * contract if it is using standard Solidity ABI encoding.
  307. */
  308. function schedule(
  309. address target,
  310. bytes calldata data,
  311. uint48 when
  312. ) external returns (bytes32 operationId, uint32 nonce);
  313. /**
  314. * @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
  315. * execution delay is 0.
  316. *
  317. * Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the
  318. * operation wasn't previously scheduled (if the caller doesn't have an execution delay).
  319. *
  320. * Emits an {OperationExecuted} event only if the call was scheduled and delayed.
  321. */
  322. function execute(address target, bytes calldata data) external payable returns (uint32);
  323. /**
  324. * @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled
  325. * operation that is cancelled.
  326. *
  327. * Requirements:
  328. *
  329. * - the caller must be the proposer, a guardian of the targeted function, or a global admin
  330. *
  331. * Emits a {OperationCanceled} event.
  332. */
  333. function cancel(address caller, address target, bytes calldata data) external returns (uint32);
  334. /**
  335. * @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed
  336. * (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.
  337. *
  338. * This is useful for contract that want to enforce that calls targeting them were scheduled on the manager,
  339. * with all the verifications that it implies.
  340. *
  341. * Emit a {OperationExecuted} event.
  342. */
  343. function consumeScheduledOp(address caller, bytes calldata data) external;
  344. /**
  345. * @dev Hashing function for delayed operations.
  346. */
  347. function hashOperation(address caller, address target, bytes calldata data) external view returns (bytes32);
  348. /**
  349. * @dev Changes the authority of a target managed by this manager instance.
  350. *
  351. * Requirements:
  352. *
  353. * - the caller must be a global admin
  354. */
  355. function updateAuthority(address target, address newAuthority) external;
  356. }