Access Control Grant Batch Facet
Grants roles to multiple accounts in batch
- Grants roles to multiple accounts in a single atomic operation.
- Emits
RoleGrantedevents for each account granted a role. - Uses diamond storage for role management, ensuring state consistency across facets.
- Provides
exportSelectorsfor easy integration into diamond upgrade processes.
Overview
This facet exposes an external function to grant a specific role to multiple accounts efficiently within a single transaction. It enhances the diamond's access control capabilities by reducing gas costs and complexity for bulk role assignments. Calls are routed through the diamond proxy, interacting with shared diamond storage.
Storage
AccessControlStorage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol")) |
Functions
grantRoleBatch
Grants a role to multiple accounts in a single transaction. Emits a RoleGranted event for each newly granted account. Reverts with AccessControlUnauthorizedAccount If the caller is not the admin of the role.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to grant. |
_accounts | address[] | The accounts 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
- Ensure the caller has the necessary administrative privileges to grant the specified role before invoking
grantRoleBatch. - Verify that the
AccessControlGrantBatchFacetis correctly added to the diamond with the appropriate selectors. - Consider the gas implications for very large
_accountsarrays; for extremely large lists, multiple calls might be more gas-efficient.
Security Considerations
The grantRoleBatch function is protected by access control, reverting with AccessControlUnauthorizedAccount if the caller does not possess the required administrative role for the target role. Input validation is performed by the underlying access control mechanism. Follow standard Solidity security practices for managing roles and account permissions.