RoleByRoles.sol
RoleByRoles.sol is an electoral law that assigns or revokes a role based on whether an account holds any of a set of prerequisite roles. It provides a mechanism for composing "grouped" roles and automatic role management based on prerequisite role ownership.
Overview
This law provides a mechanism to:
Assign a target role to accounts holding prerequisite roles
Revoke the target role when prerequisite roles are lost
Compose hierarchical role structures
Automatically manage role assignments
Track role dependencies
Configuration
When adopting a RoleByRoles instance, two parameters must be provided:
newRoleId
(uint256): The role ID to assign/revoke based on prerequisitesroleIdsNeeded
(uint256[]): Array of prerequisite role IDs
Usage
Proposing an Action
When calling the law, one parameter must be provided:
account
(address): The account to check and potentially assign/revoke the role for
Execution Flow
Prerequisite Check
Checks if the account holds any of the prerequisite roles
Verifies current role status for the target role
Determines required action
Role Assignment Logic
If account has prerequisite roles and doesn't have target role:
Assigns the target role
If account lacks prerequisite roles but has target role:
Revokes the target role
If no change needed:
Returns empty execution data
State Management
Records role assignment/revocation
Updates role holder lists
Tracks role dependencies
Technical Specifications
State Variables
struct Data {
uint256 newRoleId; // Role ID to assign/revoke
uint256[] roleIdsNeeded; // Array of prerequisite role IDs
}
mapping(bytes32 lawHash => Data) public data;
Functions
initializeLaw
initializeLaw
function initializeLaw(
uint16 index,
string memory nameDescription,
bytes memory inputParams,
bytes memory config
) public override
Initializes law with configuration parameters
Sets up target role and prerequisite roles
Configures role dependency structure
handleRequest
handleRequest
function handleRequest(
address caller,
address powers,
uint16 lawId,
bytes memory lawCalldata,
uint256 nonce
) public view virtual override returns (
uint256 actionId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas
)
Processes the role management request
Checks prerequisite role ownership
Prepares role assignment/revocation call
Returns execution data
Error Conditions
Role Assignment Errors
"Account already has role"
"Account does not have prerequisite roles"
Role Revocation Errors
"Account does not have role"
"Account still has prerequisite roles"
Validation Errors
Invalid role ID
Invalid account address
Zero address account
Current Deployments
421614
Arbitrum Sepolia
0xa797799EE0C6FA7d9b76eF52e993288a04982267
11155420
Optimism Sepolia
0xa797799EE0C6FA7d9b76eF52e993288a04982267
11155111
Ethereum Sepolia
0xa797799EE0C6FA7d9b76eF52e993288a04982267
Last updated