Law.sol
Checking under the hood of law implementations.
Law.sol is the base implementation for Powers Protocol Laws. It provides core functionality for creating role-restricted governance actions in the Powers protocol.
Overview
Laws are modular, role-restricted governance actions that serve as building blocks of the Powers protocol. Each law is a singleton contract that can be used by multiple Powers protocols, and multiple times by a single protocol. The use of a law is linked to a unique adoption ID of a Powers.sol deployment.
Key Functions
Laws serve five key functions in the Powers protocol:
Role Restriction: Laws enforce role-based access control for community actions
Data Transformation: Laws transform input data into executable calls
State Management: Laws manage state changes for the community
Validation: Laws validate proposal and execution conditions
Data Return: Laws return execution data to the Powers protocol
Law Characteristics
Singleton Contracts: One law instance can be used by multiple Powers protocols
Role Restricted: Each law is restricted by a single role
Optional Checks: Laws can implement multiple validation checks
State Management: Laws can save and manage state
Function Return: Laws return function calls to be executed
Protected Execution: The
executeLawfunction can only be called by the associatedPowers.soldeployment
Core Functionality
1. Initialization
Setting up law parameters and conditions
Configuring role restrictions
Defining validation rules
2. Execution Flow
Validation: Running checks for proposal and execution
Request Handling: Processing and transforming input data
State Management: Applying state changes if needed
Reply: Returning execution data to Powers protocol
3. State Management
Tracking law executions
Managing law conditions
Storing law configuration
Recording action IDs
Implementation Guide
To implement a new law:
Inherit from the Law contract
Implement required functions:
handleRequest: Process incoming requests_changeState: Manage state changes
Configure validation logic
Set up proper access controls
Implement error handling
Related Documentation
Governance Space
The Powers protocol ensures that each community can only interact with their adopted instance of a law. For example, the Yellow community cannot interfere with assigning roles in the Red community. This protects governance against outside interference.

🚧 Everythign from here on is still completely work in progress and incomplete. 🚧
Law functionalities
The core functionality of a Law is to receive an input of Powers and to return an output back to the same contract. This is done through the executeLaw function. When this function is called, the following happens:
Checks are run.
The calldata is decoded and transformed on the function
handleRequest.If
handleRequestreturns target contracts to be called by Powers, these are returned by the_replyPowersfunction.If
handleRequestreturns state data, these are saved by the_changeStatefunction.
Last updated