IAccessManager.sol 16 KB

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