Skip to content

Commit 0aff3ff

Browse files
committed
Completed docs
1 parent 68adaf5 commit 0aff3ff

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

contracts/access/AccessControl.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import "../utils/introspection/ERC165.sol";
4444
*
4545
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
4646
* grant and revoke this role. Extra precautions should be taken to secure
47-
* accounts that have been granted it.
47+
* accounts that have been granted it. See {AccessControlAdminRules}
4848
*/
4949
abstract contract AccessControl is Context, IAccessControl, ERC165 {
5050
struct RoleData {

contracts/access/AccessControlAdminRules.sol

+25-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import "../utils/math/SafeCast.sol";
99

1010
/**
1111
* @dev Extension of {AccessControl} that allows to specify special rules to manage
12-
* the `DEFAULT_ADMIN_ROLE`´s owner, which is a sensitive role with special permissions
12+
* the `DEFAULT_ADMIN_ROLE` 's owner, which is a sensitive role with special permissions
1313
* over other valid roles that may potentially have rights.
1414
*
1515
* If a specific role doesn't have an `adminRole` assigned, the holder of the
@@ -18,12 +18,26 @@ import "../utils/math/SafeCast.sol";
1818
*
1919
* This contract implements the following risk mitigations on top of the AccessControl implementation:
2020
*
21-
* - Only one account holds the `DEFAULT_ADMIN_ROLE` at every time after construction except when renounced.
22-
* - Enforce a 2-step process to transfer the `DEFAULT_ADMIN_ROLE` to another account. Even when it's been renounced.
23-
* - Enforce a configurable delay between the two steps, with the ability to cancel in between. Even after the timer has passed to avoid locking it forever.
24-
* - The `DEFAULT_ADMIN_ROLE`'s admin can be only held by itself.
21+
* * Only one account holds the `DEFAULT_ADMIN_ROLE` at every time after construction except when renounced.
22+
* * Enforce a 2-step process to transfer the `DEFAULT_ADMIN_ROLE` to another account.
23+
* - Even when it's been renounced.
24+
* * Enforce a configurable delay between the two steps, with the ability to cancel in between.
25+
* - Even after the timer has passed to avoid locking it forever.
26+
* * The `DEFAULT_ADMIN_ROLE` 's admin can be only held by itself.
2527
*
26-
* NOTE: `delay` is only configurable in the constructor to avoid issues related with handling delay management during the transfer is pending to be completed.
28+
* Once you understand what the {constructor} parameters, you can use this reference implementation:
29+
*
30+
* ```solidity
31+
* contract MyToken is AccessControlAdminRules {
32+
* constructor() AccessControlAdminRules(
33+
* 60 * 60 * 24, // 3 days
34+
* _msgSender() // Explicit initial `DEFAULT_ADMIN_ROLE` holder
35+
* ) {}
36+
*}
37+
* ```
38+
*
39+
* NOTE: The `delay` is only configurable in the constructor to avoid issues related with handling
40+
* delay management during the transfer is pending to be completed.
2741
*
2842
* _Available since v4.9._
2943
*/
@@ -36,13 +50,12 @@ abstract contract AccessControlAdminRules is IAccessControlAdminRules, AccessCon
3650
address private _pendingAdmin;
3751

3852
/**
39-
* @dev Sets the values for {name} and {symbol}.
40-
*
41-
* All two of these values are immutable: they can only be set once during
42-
* construction.
53+
* @dev Sets the initial values the internal delay and {owner}.
54+
*
55+
* The `delay` value is immutable. It can only be set at the constructor.
4356
*/
44-
constructor(uint48 initialDelay, address initialAdmin) {
45-
_delay = initialDelay;
57+
constructor(uint48 delay, address initialAdmin) {
58+
_delay = delay;
4659
_grantRole(DEFAULT_ADMIN_ROLE, initialAdmin);
4760
}
4861

contracts/access/README.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ This directory provides ways to restrict who can access the functions of a contr
2323
{{IAccessControlEnumerable}}
2424

2525
{{AccessControlEnumerable}}
26+
27+
{{IAccessControlAdminRules}}
28+
29+
{{AccessControlAdminRules}}

docs/modules/ROOT/pages/access-control.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ Every role has an associated admin role, which grants permission to call the `gr
131131

132132
This mechanism can be used to create complex permissioning structures resembling organizational charts, but it also provides an easy way to manage simpler applications. `AccessControl` includes a special role, called `DEFAULT_ADMIN_ROLE`, which acts as the **default admin role for all roles**. An account with this role will be able to manage any other role, unless `_setRoleAdmin` is used to select a new admin role.
133133

134+
NOTE: For risk mitigations related to `DEFAULT_ADMIN_ROLE` management. See xref:api:access.adoc#AccessControlAdminRules[`AccessControlAdminRules`] as an alternative with restrictions such as 2-step admin role change, single-holder enforcing and configurable minimum delay.
135+
134136
Let's take a look at the ERC20 token example, this time taking advantage of the default admin role:
135137

136138
[source,solidity]

0 commit comments

Comments
 (0)