Skip to main content

Governor Contract Implementation

Overview

The Governor contract is a role-based authority system that supports up to 256 roles, enhancing readability and utility without needing off-chain indexing. Built on RolesAuthority and expanding upon Solmate's role-based system, it provides detailed role and permission management for authorized functions.

Inherits: RolesAuthority

Key Data Structures

  • Role: Struct holding a role ID and role name.
  • Capability: Struct specifying a target contract, function signature, and role requirements.
  • Mappings:
    • roleNames: Maps role IDs to descriptive role names.

Events

  • RoleNameSet: Emitted when a role name is assigned.

Functions

Constructor

Initializes RolesAuthority with the given owner address.

constructor(address _owner) RolesAuthority(_owner, Authority(address(this))) {}
NameTypeDescription
_owneraddressInitial owner who gains all permissions by default.

getUsersByRole

Returns addresses assigned a specific role.

function getUsersByRole(uint8 role) external view returns (address[] memory usersWithRole);
NameTypeDescription
roleuint8Role ID for which to list users.

getRolesForUser

Returns all roles assigned to a user.

function getRolesForUser(address user) external view returns (uint8[] memory rolesForUser);
NameTypeDescription
useraddressAddress of the user.

getRolesFromByteMap

Converts a byte map into an array of role IDs.

function getRolesFromByteMap(bytes32 byteMap) public pure returns (uint8[] memory roleIds);
NameTypeDescription
byteMapbytes32Bytes32 encoding of roles.

getByteMapFromRoles

Converts an array of role IDs to a byte map.

function getByteMapFromRoles(uint8[] memory roleIds) public pure returns (bytes32);
NameTypeDescription
roleIdsuint8[]Array of role IDs.

getEnabledFunctionsInTarget

Returns function signatures enabled for a specified contract.

function getEnabledFunctionsInTarget(address _target) public view returns (bytes4[] memory _funcs);
NameTypeDescription
_targetaddressTarget contract address.

getRoleName

Returns the name associated with a specific role ID.

function getRoleName(uint8 role) external view returns (string memory roleName);
NameTypeDescription
roleuint8Role ID.

setRoleName

Sets a human-readable name for a role ID. Requires authorization.

function setRoleName(uint8 role, string memory roleName) external requiresAuth;
NameTypeDescription
roleuint8Role ID.
roleNamestringDescriptive name for the role.