AccessControlStakingFacetStorage
Inspired by the OpenZeppelin implementation https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol
_This library manages and allows for role-based access control mechanisms for both the staking platform and its individual staking campaigns.
Roles are referred to by their bytes32
identifier.
IMPORTANT:
The Admin of the staking platform is not the owner
of the StakingDiamond.sol
and does not possess
the same privileges.
NOTE:
- Only the Admin can grant and revoke all roles except for
ADMIN_ROLE
andOPEN_ROLE
to/from users, and designate or dismiss users as role handlers (seeaddRoleHandler()
&removeRoleHandler()
). - Designated role handlers can only grant and revoke roles they are assigned to manage from/to users.
OPEN_ROLE
is the default role; all accounts inherently have this role.- By default, the Admin is a handler of all roles except for
ADMIN_ROLE
andOPEN_ROLE
. - This version supports only one Admin per staking platform._
AlreadyInitialized
Thrown when attempting to re-initialize.
RestrictedDefaultRole
Thrown when attempting to handle (grant or revoke) a default role (either OPEN_ROLE
or ADMIN_ROLE
).
UnauthorizedRoleHandling
Thrown when an account attempts to handle (grant or revoke) a role it is not permitted to manage.
AccountMissingRole
Thrown when an account attempts an action without the required role.
InvalidZeroAddressForAdmin
Thrown when attempting to assign the zero address as the admin.
InvalidCampaignIdZero
Thrown when a campaignId of 0 is provided, which is invalid for role checks.
ZeroAccountsToGrant
Thrown when no accounts provided for role granting.
ZeroAccountsToRevoke
Thrown when no accounts provided for role revocation.
CannotHandleAdminRole
Thrown when an attempt is made to handle ADMIN_ROLE
.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
ADMIN_ROLE
The unique identifier of the admin role.
OPEN_ROLE
The unique identifier of the open role (all users inherently possess this role).
Layout
Struct for managing access control related data.
onlyRoleHandler
Restricts function execution to designated role handlers for a specified role.
Checks that the specified role is not OPEN_ROLE
or ADMIN_ROLE
, and verifies whether
the caller (msg.sender) is authorized to handle the specified role.
If the caller (msg.sender) is neither a designated role handler nor the Admin, the function reverts.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | The identifier of the role for which the caller must be a designated handler |
onlyRole
Rrestricts function execution to accounts with the specified role.
Checks whether the caller (msg.sender) has the specified role, else it reverts.
If the specified role is the OPEN_ROLE
then function proceeds with the execution.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | The identifier of the role that the caller must possess to proceed. |
layout
Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT
unique identifier.
initAccessControlFacet
Initializes the AccessControlStakingFacetStorage
by setting the Admin of the staking platform.
account
cannot be address(0).
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
account | address | The address to be the designated Admin of the staking platform, responsible for managing permissions. |
hasRole
Checks whether a specific account possesses a specified role within the staking platform.
This function verifies role-based permissions within the context of the staking platform.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
role | bytes32 | The role identifier to check for. |
account | address | The address being checked for the specified role. |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | true if account possesses role ; false otherwise. |
hasRoleForId
Checks whether a specific account possesses a specified role within a given staking campaign.
This function verifies role-based permissions within the context of a specific campaign.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
role | bytes32 | The role identifier to check for. |
account | address | The address being checked for the specified role in the campaign. |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | true if account possesses role within the specified campaignId ; false otherwise. |
grantRole
Grants role
to account
within the context of the staking platform.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
role | bytes32 | The identifier of the role to grant. |
account | address | The address to grant role to. |
grantRoleForId
Grants role
to account
within the context of a specified staking campaign.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
role | bytes32 | The identifier of the role to grant. |
account | address | The address to grant role to. |
grantRoleMultiple
Grants role
to multiple accounts
within the context of the staking platform.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
role | bytes32 | The identifier of the role to grant. |
accounts | address[] | An array of addresses to grant role to. |
grantRoleMultipleForId
Grants role
to multiple accounts
within the context of a specified staking campaign.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
role | bytes32 | The identifier of the role to grant. |
accounts | address[] | An array of addresses to grant role to. |
revokeRole
Revokes role
from account
within the context of the staking platform.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
role | bytes32 | The identifier of the role to revoke. |
account | address | The address to revoke role from. |
revokeRoleForId
Revokes role
from account
within the context of a specified staking campaign.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
role | bytes32 | The identifier of the role to revoke. |
account | address | The address to revoke role from. |
revokeRoleMultiple
Revokes role
from multiple accounts
within the context of the staking platform.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
role | bytes32 | The identifier of the role to revoke. |
accounts | address[] | An array of addresses to revoke role from. |
revokeRoleMultipleForId
Revoke role
from multiple accounts
within the context of a specified staking campaign.
Only callable by the Admin or a handler of role
.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
role | bytes32 | The identifier of the role to revoke. |
accounts | address[] | An array of addresses to revoke role from. |
addRoleHandler
Delegates the handling of role
to the specified account, allowing account
to manage
the granting and revocation of this role.
Only callable by the Admin. Designated role handlers can manage the associated roles both at the platform level and within individual campaigns.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
role | bytes32 | The identifier of the role to delegate the handling of. |
account | address | The address to be the designated role handler of role . |
removeRoleHandler
Dismisses the handling of role
from the specified account, preventing account
from managing
the granting and revocation of this role.
Only callable by the Admin.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
role | bytes32 | The identifier of the role to dismiss handling for. |
account | address | The address to be removed as a role handler for role . |
changeAdmin
Replaces the current Admin with a new Admin.
Only callable by the (current) Admin. In this version, only one Admin is supported per staking platform.
Parameters
Name | Type | Description |
---|---|---|
l | struct AccessControlStakingFacetStorage.Layout | A reference to the Layout struct in storage. |
account | address | The address of the new Admin. |