Access Control Grant Facet
Grants roles to accounts within a diamond
- Exposes
grantRolefor programmatic role assignment. - Emits
RoleGrantedevent for state changes. - Utilizes diamond storage for shared state management.
- Reverts with
AccessControlUnauthorizedAccountfor unauthorized calls.
Overview
This facet exposes functions to grant roles to specific accounts within a Compose diamond. It leverages shared diamond storage and emits events for off-chain monitoring. Developers integrate this facet to manage permissions programmatically.
Storage
AccessControlStorage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol")) |
Functions
grantRole
Grants a role to an account. Emits a RoleGranted event. Reverts with AccessControlUnauthorizedAccount If the caller is not the admin of the role.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to grant. |
_account | address | The account to grant the role to. |
exportSelectors
Exports the selectors that are exposed by the facet.
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | Selectors that are exported by the facet. |
Events
Errors
Best Practices
- Initialize roles and grant administrative permissions during diamond deployment.
- Ensure the caller of
grantRolehas the necessary administrative privileges. - Monitor
RoleGrantedevents for auditing and off-chain state tracking.
Security Considerations
The grantRole function is protected by access control, reverting if the caller is not the admin of the role. Input validation on _role and _account is implicitly handled by the diamond's call routing and the facet's internal logic. No reentrancy risks are apparent as the function performs a role grant before any external calls.