AccessControlStakingFacet
This facet is a core component of a staking platform, allowing 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._
RoleGranted
RoleGrantedForId
RoleMultipleGranted
RoleMultipleGrantedForId
RoleRevoked
RoleRevokedForId
RoleMultipleRevoked
RoleMultipleRevokedForId
RoleHandlerAdded
RoleHandlerRemoved
AdminChanged
AccessControlInitialized
initAccessControlFacet
Initializes the AccessControlStakingFacetStorage
by setting the Admin of the staking platform.
admin
cannot be address(0).
Emmits a {AccessControlInitialized}
event.
Parameters
Name | Type | Description |
---|---|---|
admin | 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 |
---|---|---|
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 |
---|---|---|
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
.
Emmits a {RoleGranted}
event.
Parameters
Name | Type | Description |
---|---|---|
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
.
Emits a {RoleGrantedForId}
event.
Parameters
Name | Type | Description |
---|---|---|
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
.
Emits a {RoleMultipleGranted}
event.
Parameters
Name | Type | Description |
---|---|---|
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
.
Emits a {RoleMultipleGrantedForId}
event.
Parameters
Name | Type | Description |
---|---|---|
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
.
Emits a {RoleRevoked}
event.
Parameters
Name | Type | Description |
---|---|---|
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
.
Emits a {RoleRevokedForId}
event.
Parameters
Name | Type | Description |
---|---|---|
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
.
Emits a {RoleMultipleRevoked}
event.
Parameters
Name | Type | Description |
---|---|---|
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
.
Emits a {RoleMultipleRevokedForId}
event.
Parameters
Name | Type | Description |
---|---|---|
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.
Emits a {RoleHandlerAdded}
event._
Parameters
Name | Type | Description |
---|---|---|
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.
Emits a {RoleHandlerRemoved}
event.
Parameters
Name | Type | Description |
---|---|---|
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.
Emits an {AdminChanged}
event.
Parameters
Name | Type | Description |
---|---|---|
newAdmin | address | The address of the new Admin. |