IAccessManager.sol 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {IAccessManaged} from "./IAccessManaged.sol";
  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 AccessManagerLockedAccount(address account);
  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 this manager itself. These are defined by the
  95. * {_canCallSelf} function instead.
  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. 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(uint64 roleId, address account) external view returns (uint48, uint32, uint32, uint48);
  159. /**
  160. * @dev Check if a given account currently has the permission level corresponding to a given role. Note that this
  161. * permission might be associated with an execution delay. {getAccess} can provide more details.
  162. */
  163. function hasRole(uint64 roleId, address account) external view returns (bool, uint32);
  164. /**
  165. * @dev Give a label to a role, for improved role discoverability by UIs.
  166. *
  167. * Requirements:
  168. *
  169. * - the caller must be a global admin
  170. *
  171. * Emits a {RoleLabel} event.
  172. */
  173. function labelRole(uint64 roleId, string calldata label) external;
  174. /**
  175. * @dev Add `account` to `roleId`, or change its execution delay.
  176. *
  177. * This gives the account the authorization to call any function that is restricted to this role. An optional
  178. * execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation
  179. * that is restricted to members of this role. The user will only be able to execute the operation after the delay has
  180. * passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).
  181. *
  182. * If the account has already been granted this role, the execution delay will be updated. This update is not
  183. * immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is
  184. * called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any
  185. * operation executed in the 3 hours that follows this update was indeed scheduled before this update.
  186. *
  187. * Requirements:
  188. *
  189. * - the caller must be an admin for the role (see {getRoleAdmin})
  190. * - granted role must not be the `PUBLIC_ROLE`
  191. *
  192. * Emits a {RoleGranted} event.
  193. */
  194. function grantRole(uint64 roleId, address account, uint32 executionDelay) external;
  195. /**
  196. * @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has
  197. * no effect.
  198. *
  199. * Requirements:
  200. *
  201. * - the caller must be an admin for the role (see {getRoleAdmin})
  202. * - revoked role must not be the `PUBLIC_ROLE`
  203. *
  204. * Emits a {RoleRevoked} event if the account had the role.
  205. */
  206. function revokeRole(uint64 roleId, address account) external;
  207. /**
  208. * @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in
  209. * the role this call has no effect.
  210. *
  211. * Requirements:
  212. *
  213. * - the caller must be `callerConfirmation`.
  214. *
  215. * Emits a {RoleRevoked} event if the account had the role.
  216. */
  217. function renounceRole(uint64 roleId, address callerConfirmation) external;
  218. /**
  219. * @dev Change admin role for a given role.
  220. *
  221. * Requirements:
  222. *
  223. * - the caller must be a global admin
  224. *
  225. * Emits a {RoleAdminChanged} event
  226. */
  227. function setRoleAdmin(uint64 roleId, uint64 admin) external;
  228. /**
  229. * @dev Change guardian role for a given role.
  230. *
  231. * Requirements:
  232. *
  233. * - the caller must be a global admin
  234. *
  235. * Emits a {RoleGuardianChanged} event
  236. */
  237. function setRoleGuardian(uint64 roleId, uint64 guardian) external;
  238. /**
  239. * @dev Update the delay for granting a `roleId`.
  240. *
  241. * Requirements:
  242. *
  243. * - the caller must be a global admin
  244. *
  245. * Emits a {RoleGrantDelayChanged} event.
  246. */
  247. function setGrantDelay(uint64 roleId, uint32 newDelay) external;
  248. /**
  249. * @dev Set the role required to call functions identified by the `selectors` in the `target` contract.
  250. *
  251. * Requirements:
  252. *
  253. * - the caller must be a global admin
  254. *
  255. * Emits a {TargetFunctionRoleUpdated} event per selector.
  256. */
  257. function setTargetFunctionRole(address target, bytes4[] calldata selectors, uint64 roleId) external;
  258. /**
  259. * @dev Set the delay for changing the configuration of a given target contract.
  260. *
  261. * Requirements:
  262. *
  263. * - the caller must be a global admin
  264. *
  265. * Emits a {TargetAdminDelayUpdated} event.
  266. */
  267. function setTargetAdminDelay(address target, uint32 newDelay) external;
  268. /**
  269. * @dev Set the closed flag for a contract.
  270. *
  271. * Requirements:
  272. *
  273. * - the caller must be a global admin
  274. *
  275. * Emits a {TargetClosed} event.
  276. */
  277. function setTargetClosed(address target, bool closed) external;
  278. /**
  279. * @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
  280. * operation is not yet scheduled, has expired, was executed, or was canceled.
  281. */
  282. function getSchedule(bytes32 id) external view returns (uint48);
  283. /**
  284. * @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never
  285. * been scheduled.
  286. */
  287. function getNonce(bytes32 id) external view returns (uint32);
  288. /**
  289. * @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to
  290. * choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays
  291. * required for the caller. The special value zero will automatically set the earliest possible time.
  292. *
  293. * Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when
  294. * the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this
  295. * scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.
  296. *
  297. * Emits a {OperationScheduled} event.
  298. *
  299. * NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If
  300. * this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target
  301. * contract if it is using standard Solidity ABI encoding.
  302. */
  303. function schedule(address target, bytes calldata data, uint48 when) external returns (bytes32, uint32);
  304. /**
  305. * @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
  306. * execution delay is 0.
  307. *
  308. * Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the
  309. * operation wasn't previously scheduled (if the caller doesn't have an execution delay).
  310. *
  311. * Emits an {OperationExecuted} event only if the call was scheduled and delayed.
  312. */
  313. function execute(address target, bytes calldata data) external payable returns (uint32);
  314. /**
  315. * @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled
  316. * operation that is cancelled.
  317. *
  318. * Requirements:
  319. *
  320. * - the caller must be the proposer, a guardian of the targeted function, or a global admin
  321. *
  322. * Emits a {OperationCanceled} event.
  323. */
  324. function cancel(address caller, address target, bytes calldata data) external returns (uint32);
  325. /**
  326. * @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed
  327. * (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.
  328. *
  329. * This is useful for contract that want to enforce that calls targeting them were scheduled on the manager,
  330. * with all the verifications that it implies.
  331. *
  332. * Emit a {OperationExecuted} event.
  333. */
  334. function consumeScheduledOp(address caller, bytes calldata data) external;
  335. /**
  336. * @dev Hashing function for delayed operations.
  337. */
  338. function hashOperation(address caller, address target, bytes calldata data) external view returns (bytes32);
  339. /**
  340. * @dev Changes the authority of a target managed by this manager instance.
  341. *
  342. * Requirements:
  343. *
  344. * - the caller must be a global admin
  345. */
  346. function updateAuthority(address target, address newAuthority) external;
  347. }