IAccessManager.sol 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 AccessManagerLockedAccount(address account);
  71. error AccessManagerLockedRole(uint64 roleId);
  72. error AccessManagerBadConfirmation();
  73. error AccessManagerUnauthorizedAccount(address msgsender, uint64 roleId);
  74. error AccessManagerUnauthorizedCall(address caller, address target, bytes4 selector);
  75. error AccessManagerUnauthorizedConsume(address target);
  76. error AccessManagerUnauthorizedCancel(address msgsender, address caller, address target, bytes4 selector);
  77. error AccessManagerInvalidInitialAdmin(address initialAdmin);
  78. /**
  79. * @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with
  80. * no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}
  81. * & {execute} workflow.
  82. *
  83. * This function is usually called by the targeted contract to control immediate execution of restricted functions.
  84. * Therefore we only return true if the call can be performed without any delay. If the call is subject to a
  85. * previously set delay (not zero), then the function should return false and the caller should schedule the operation
  86. * for future execution.
  87. *
  88. * If `immediate` is true, the delay can be disregarded and the operation can be immediately executed, otherwise
  89. * the operation can be executed if and only if delay is greater than 0.
  90. *
  91. * NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that
  92. * is backward compatible. Some contracts may thus ignore the second return argument. In that case they will fail
  93. * to identify the indirect workflow, and will consider calls that require a delay to be forbidden.
  94. *
  95. * NOTE: This function does not report the permissions of this manager itself. These are defined by the
  96. * {_canCallSelf} function instead.
  97. */
  98. function canCall(
  99. address caller,
  100. address target,
  101. bytes4 selector
  102. ) external view returns (bool allowed, uint32 delay);
  103. /**
  104. * @dev Expiration delay for scheduled proposals. Defaults to 1 week.
  105. *
  106. * IMPORTANT: Avoid overriding the expiration with 0. Otherwise every contract proposal will be expired immediately,
  107. * disabling any scheduling usage.
  108. */
  109. function expiration() external view returns (uint32);
  110. /**
  111. * @dev Minimum setback for all delay updates, with the exception of execution delays. It
  112. * can be increased without setback (and reset via {revokeRole} in the case event of an
  113. * accidental increase). Defaults to 5 days.
  114. */
  115. function minSetback() external view returns (uint32);
  116. /**
  117. * @dev Get whether the contract is closed disabling any access. Otherwise role permissions are applied.
  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(uint64 roleId, address account) external view returns (uint48, uint32, uint32, uint48);
  160. /**
  161. * @dev Check if a given account currently has the permission level corresponding to a given role. Note that this
  162. * permission might be associated with an execution delay. {getAccess} can provide more details.
  163. */
  164. function hasRole(uint64 roleId, address account) external view returns (bool, uint32);
  165. /**
  166. * @dev Give a label to a role, for improved role discoverability by UIs.
  167. *
  168. * Requirements:
  169. *
  170. * - the caller must be a global admin
  171. *
  172. * Emits a {RoleLabel} event.
  173. */
  174. function labelRole(uint64 roleId, string calldata label) external;
  175. /**
  176. * @dev Add `account` to `roleId`, or change its execution delay.
  177. *
  178. * This gives the account the authorization to call any function that is restricted to this role. An optional
  179. * execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation
  180. * that is restricted to members of this role. The user will only be able to execute the operation after the delay has
  181. * passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).
  182. *
  183. * If the account has already been granted this role, the execution delay will be updated. This update is not
  184. * immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is
  185. * called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any
  186. * operation executed in the 3 hours that follows this update was indeed scheduled before this update.
  187. *
  188. * Requirements:
  189. *
  190. * - the caller must be an admin for the role (see {getRoleAdmin})
  191. * - granted role must not be the `PUBLIC_ROLE`
  192. *
  193. * Emits a {RoleGranted} event.
  194. */
  195. function grantRole(uint64 roleId, address account, uint32 executionDelay) external;
  196. /**
  197. * @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has
  198. * no effect.
  199. *
  200. * Requirements:
  201. *
  202. * - the caller must be an admin for the role (see {getRoleAdmin})
  203. * - revoked role must not be the `PUBLIC_ROLE`
  204. *
  205. * Emits a {RoleRevoked} event if the account had the role.
  206. */
  207. function revokeRole(uint64 roleId, address account) external;
  208. /**
  209. * @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in
  210. * the role this call has no effect.
  211. *
  212. * Requirements:
  213. *
  214. * - the caller must be `callerConfirmation`.
  215. *
  216. * Emits a {RoleRevoked} event if the account had the role.
  217. */
  218. function renounceRole(uint64 roleId, address callerConfirmation) external;
  219. /**
  220. * @dev Change admin role for a given role.
  221. *
  222. * Requirements:
  223. *
  224. * - the caller must be a global admin
  225. *
  226. * Emits a {RoleAdminChanged} event
  227. */
  228. function setRoleAdmin(uint64 roleId, uint64 admin) external;
  229. /**
  230. * @dev Change guardian role for a given role.
  231. *
  232. * Requirements:
  233. *
  234. * - the caller must be a global admin
  235. *
  236. * Emits a {RoleGuardianChanged} event
  237. */
  238. function setRoleGuardian(uint64 roleId, uint64 guardian) external;
  239. /**
  240. * @dev Update the delay for granting a `roleId`.
  241. *
  242. * Requirements:
  243. *
  244. * - the caller must be a global admin
  245. *
  246. * Emits a {RoleGrantDelayChanged} event.
  247. */
  248. function setGrantDelay(uint64 roleId, uint32 newDelay) external;
  249. /**
  250. * @dev Set the role required to call functions identified by the `selectors` in the `target` contract.
  251. *
  252. * Requirements:
  253. *
  254. * - the caller must be a global admin
  255. *
  256. * Emits a {TargetFunctionRoleUpdated} event per selector.
  257. */
  258. function setTargetFunctionRole(address target, bytes4[] calldata selectors, uint64 roleId) external;
  259. /**
  260. * @dev Set the delay for changing the configuration of a given target contract.
  261. *
  262. * Requirements:
  263. *
  264. * - the caller must be a global admin
  265. *
  266. * Emits a {TargetAdminDelayUpdated} event.
  267. */
  268. function setTargetAdminDelay(address target, uint32 newDelay) external;
  269. /**
  270. * @dev Set the closed flag for a contract.
  271. *
  272. * Requirements:
  273. *
  274. * - the caller must be a global admin
  275. *
  276. * Emits a {TargetClosed} event.
  277. */
  278. function setTargetClosed(address target, bool closed) external;
  279. /**
  280. * @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
  281. * operation is not yet scheduled, has expired, was executed, or was canceled.
  282. */
  283. function getSchedule(bytes32 id) external view returns (uint48);
  284. /**
  285. * @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never
  286. * been scheduled.
  287. */
  288. function getNonce(bytes32 id) external view returns (uint32);
  289. /**
  290. * @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to
  291. * choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays
  292. * required for the caller. The special value zero will automatically set the earliest possible time.
  293. *
  294. * Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when
  295. * the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this
  296. * scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.
  297. *
  298. * Emits a {OperationScheduled} event.
  299. *
  300. * NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If
  301. * this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target
  302. * contract if it is using standard Solidity ABI encoding.
  303. */
  304. function schedule(address target, bytes calldata data, uint48 when) external returns (bytes32, uint32);
  305. /**
  306. * @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
  307. * execution delay is 0.
  308. *
  309. * Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the
  310. * operation wasn't previously scheduled (if the caller doesn't have an execution delay).
  311. *
  312. * Emits an {OperationExecuted} event only if the call was scheduled and delayed.
  313. */
  314. function execute(address target, bytes calldata data) external payable returns (uint32);
  315. /**
  316. * @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled
  317. * operation that is cancelled.
  318. *
  319. * Requirements:
  320. *
  321. * - the caller must be the proposer, a guardian of the targeted function, or a global admin
  322. *
  323. * Emits a {OperationCanceled} event.
  324. */
  325. function cancel(address caller, address target, bytes calldata data) external returns (uint32);
  326. /**
  327. * @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed
  328. * (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.
  329. *
  330. * This is useful for contract that want to enforce that calls targeting them were scheduled on the manager,
  331. * with all the verifications that it implies.
  332. *
  333. * Emit a {OperationExecuted} event.
  334. */
  335. function consumeScheduledOp(address caller, bytes calldata data) external;
  336. /**
  337. * @dev Hashing function for delayed operations.
  338. */
  339. function hashOperation(address caller, address target, bytes calldata data) external view returns (bytes32);
  340. /**
  341. * @dev Changes the authority of a target managed by this manager instance.
  342. *
  343. * Requirements:
  344. *
  345. * - the caller must be a global admin
  346. */
  347. function updateAuthority(address target, address newAuthority) external;
  348. }