Permissions Contract Documentation
Overview
The PermissionsContract centralizes the role management system for the TRASH Protocol, using OpenZeppelin's AccessControl to manage roles such as Governance, Ecosystem Operators, and Store Owners. It allows the Governance role to manage other roles, ensuring that any changes to roles can be securely handled. The contract implements modular management by extending the EcosystemOperator and StoreOwner abstract contracts.
Inherited Contracts
- AccessControl: Provides role-based access control using
grantRoleandrevokeRole. - EcosystemOperator: Adds and removes Ecosystem Operator roles.
- StoreOwner: Adds and removes Store Owner roles.
Functions
initialize(address _initialGovernanceAddress)
- Description: Initializes the contract by setting up the governance address and assigning the role admin hierarchy. The Governance role manages the Ecosystem Operator and Store Owner roles.
- Parameters:
_initialGovernanceAddress: The initial address to be assigned the Governance role.- Emits:
GovernanceUpdated: Emitted when the governance address is updated.
updateGovernanceAddress(address newGovernanceAddress)
- Description: Updates the governance address. Only the current governance address can call this function. It revokes the Governance role from the current address and grants it to the new address.
- Parameters:
newGovernanceAddress: The new address to be assigned the Governance role.- Modifiers:
onlyRole(GOVERNANCE_ROLE): Ensures that only the current governance address can call this function.- Emits:
GovernanceUpdated: Emitted when the governance address is successfully updated.
isGovernance(address governance)
- Description: Checks if a given address has the Governance role.
- Parameters:
governance: The address to check.- Returns:
bool: Returnstrueif the address has the Governance role, otherwisefalse.
Supporting Abstract Contracts
EcosystemOperator
- Description: Manages the Ecosystem Operator role within the protocol. Only addresses with the Governance role can add or remove ecosystem operators.
Functions - EcosystemOperator
addEcosystemOperator(address operator)
- Description: Grants the Ecosystem Operator role to the specified address.
- Parameters:
operator: The address to grant the Ecosystem Operator role.- Modifiers:
onlyRole(GOVERNANCE_ROLE): Ensures only governance can call this function.
removeEcosystemOperator(address operator)
- Description: Revokes the Ecosystem Operator role from the specified address.
- Parameters:
operator: The address to revoke the Ecosystem Operator role from.- Modifiers:
onlyRole(GOVERNANCE_ROLE): Ensures only governance can call this function.
isEcosystemOperator(address operator)
- Description: Checks if a given address has the Ecosystem Operator role.
- Parameters:
operator: The address to check.- Returns:
bool: Returnstrueif the address has the Ecosystem Operator role, otherwisefalse.
StoreOwner
- Description: Manages the Store Owner role within the protocol. Only addresses with the Governance role can add or remove store owners.
Functions - StoreOwner
addStoreOwner(address storeOwner)
- Description: Grants the Store Owner role to the specified address.
- Parameters:
storeOwner: The address to grant the Store Owner role.- Modifiers:
onlyRole(GOVERNANCE_ROLE): Ensures only governance can call this function.
removeStoreOwner(address storeOwner)
- Description: Revokes the Store Owner role from the specified address.
- Parameters:
storeOwner: The address to revoke the Store Owner role from.- Modifiers:
onlyRole(GOVERNANCE_ROLE): Ensures only governance can call this function.
isStoreOwner(address storeOwner)
- Description: Checks if a given address has the Store Owner role.
- Parameters:
storeOwner: The address to check.- Returns:
bool: Returnstrueif the address has the Store Owner role, otherwisefalse.
PermissionsRoles Library
- Description: Contains constants that represent the role identifiers (hashes) used throughout the contract for role management.
Constants - PermissionsRoles
GOVERNANCE_ROLE:bytes32representing the Governance role, used for managing protocol-wide actions and overseeing other roles.-
ECOSYSTEM_OPERATOR_ROLE:bytes32representing the Ecosystem Operator role, used for interacting with core protocol features. -
STORE_OWNER_ROLE:bytes32representing the Store Owner role, used for managing store-related actions.
Events
GovernanceUpdated(address newGovernanceAddress)
- Description: Emitted when the governance address is updated.
- Parameters:
newGovernanceAddress: The new governance address that was assigned.
Conclusion
The PermissionsContract simplifies role-based access control by centralizing the management of the Governance, Ecosystem Operator, and Store Owner roles. Using AccessControl from OpenZeppelin, this contract ensures that only authorized addresses can perform critical operations within the protocol. The Governance role is granted significant control over other roles, ensuring a hierarchical and secure management structure.