IAccessManager.sol 16 KB

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