Staking ProtocolgenericFacetsaccessControlFacet

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 and OPEN_ROLE to/from users, and designate or dismiss users as role handlers (see addRoleHandler() & 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 and OPEN_ROLE.
  • This version supports only one Admin per staking platform._

RoleGranted

event RoleGranted(bytes32 role, address account)

RoleGrantedForId

event RoleGrantedForId(uint256 id, bytes32 role, address account)

RoleMultipleGranted

event RoleMultipleGranted(bytes32 role, address[] accounts)

RoleMultipleGrantedForId

event RoleMultipleGrantedForId(uint256 id, bytes32 role, address[] accounts)

RoleRevoked

event RoleRevoked(bytes32 role, address account)

RoleRevokedForId

event RoleRevokedForId(uint256 id, bytes32 role, address account)

RoleMultipleRevoked

event RoleMultipleRevoked(bytes32 role, address[] accounts)

RoleMultipleRevokedForId

event RoleMultipleRevokedForId(uint256 id, bytes32 role, address[] accounts)

RoleHandlerAdded

event RoleHandlerAdded(bytes32 role, address account)

RoleHandlerRemoved

event RoleHandlerRemoved(bytes32 role, address account)

AdminChanged

event AdminChanged(address previousAdmin, address newAdmin)

AccessControlInitialized

event AccessControlInitialized(address admin)

initAccessControlFacet

function initAccessControlFacet(address admin) external

Initializes the AccessControlStakingFacetStorage by setting the Admin of the staking platform.

admin cannot be address(0). Emmits a {AccessControlInitialized} event.

Parameters

NameTypeDescription
adminaddressThe address to be the designated Admin of the staking platform, responsible for managing permissions.

hasRole

function hasRole(bytes32 role, address account) external view returns (bool)

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

NameTypeDescription
rolebytes32The role identifier to check for.
accountaddressThe address being checked for the specified role.

Return Values

NameTypeDescription
[0]booltrue if account possesses role; false otherwise.

hasRoleForId

function hasRoleForId(uint256 campaignId, bytes32 role, address account) external view returns (bool)

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

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
rolebytes32The role identifier to check for.
accountaddressThe address being checked for the specified role in the campaign.

Return Values

NameTypeDescription
[0]booltrue if account possesses role within the specified campaignId; false otherwise.

grantRole

function grantRole(bytes32 role, address account) external

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

NameTypeDescription
rolebytes32The identifier of the role to grant.
accountaddressThe address to grant role to.

grantRoleForId

function grantRoleForId(uint256 campaignId, bytes32 role, address account) external

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

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
rolebytes32The identifier of the role to grant.
accountaddressThe address to grant role to.

grantRoleMultiple

function grantRoleMultiple(bytes32 role, address[] accounts) external

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

NameTypeDescription
rolebytes32The identifier of the role to grant.
accountsaddress[]An array of addresses to grant role to.

grantRoleMultipleForId

function grantRoleMultipleForId(uint256 campaignId, bytes32 role, address[] accounts) external

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

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
rolebytes32The identifier of the role to grant.
accountsaddress[]An array of addresses to grant role to.

revokeRole

function revokeRole(bytes32 role, address account) external

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

NameTypeDescription
rolebytes32The identifier of the role to revoke.
accountaddressThe address to revoke role from.

revokeRoleForId

function revokeRoleForId(uint256 campaignId, bytes32 role, address account) external

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

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
rolebytes32The identifier of the role to revoke.
accountaddressThe address to revoke role from.

revokeRoleMultiple

function revokeRoleMultiple(bytes32 role, address[] accounts) external

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

NameTypeDescription
rolebytes32The identifier of the role to revoke.
accountsaddress[]An array of addresses to revoke role from.

revokeRoleMultipleForId

function revokeRoleMultipleForId(uint256 campaignId, bytes32 role, address[] accounts) external

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

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
rolebytes32The identifier of the role to revoke.
accountsaddress[]An array of addresses to revoke role from.

addRoleHandler

function addRoleHandler(bytes32 role, address account) external

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

NameTypeDescription
rolebytes32The identifier of the role to delegate the handling of.
accountaddressThe address to be the designated role handler of role.

removeRoleHandler

function removeRoleHandler(bytes32 role, address account) external

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

NameTypeDescription
rolebytes32The identifier of the role to dismiss handling for.
accountaddressThe address to be removed as a role handler for role.

changeAdmin

function changeAdmin(address newAdmin) external

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

NameTypeDescription
newAdminaddressThe address of the new Admin.