Specs
Source
See the github repo here.
Overview
Law.sol is the base implementation for Powers Protocol Laws. It provides core functionality for creating role-restricted governance actions in the Powers protocol. Laws serve five key functions:
Role restriction of community actions
Transformation of input data into executable calls
State management for the community
Validation of proposal and execution conditions
Returning of data to the Powers protocol
Laws can be customized through:
Configuring checks in the constructor
Inheriting and implementing bespoke logic in the
handleRequest,_replyPowers, and_changeStatefunctions
State Variables
laws
An internal mapping of LawData structs that tracks all law data.
Functions
Law Execution
initializeLaw
Initializes a law with its configuration and conditions.
executeLaw
Executes the law's logic after validation. Called by the Powers protocol during action execution.
handleRequest
Handles requests from the Powers protocol and returns data for execution.
_changeState
Applies state changes from law execution.
_replyPowers
Sends execution data back to Powers protocol.
Validation
checksAtPropose
Validates conditions required to propose an action.
checksAtExecute
Validates conditions required to execute an action.
Helper Functions
getConditions
Gets the conditions for a law.
getExecutions
Gets the execution data for a law.
getInputParams
Gets the input parameters for a law.
getNameDescription
Gets the name and description of a law.
Structs
LawData
Tracks a law's configuration and state.
Conditions
Defines the conditions for a law's execution.
Executions
Tracks a law's execution history.
Events
Law Events
Law__Deployed: Emitted when a law is deployedLaw__Initialized: Emitted when a law is initialized
Errors
Law Errors
Law__OnlyPowers: Emitted when a law is called by a non-powers accountLaw__NoZeroAddress: Emitted when a zero address is usedLaw__ProposalNotSucceeded: Emitted when a proposal is not succeededLaw__ParentLawNotSet: Emitted when a parent law is not setLaw__NoDeadlineSet: Emitted when a deadline is not setLaw__InvalidPowersContractAddress: Emitted when a powers contract address is invalidLaw__ParentNotCompleted: Emitted when a parent law is not completedLaw__ParentBlocksCompletion: Emitted when a parent law blocks completionLaw__ExecutionGapTooSmall: Emitted when an execution gap is too smallLaw__DeadlineNotPassed: Emitted when a deadline is not passed
Important Considerations
1. Law Implementation Requirements
Must implement the
ILawinterfaceMust provide validation logic
Must handle state changes
Must return execution data
Must implement proper access controls
2. Gas Optimization
Law data is stored efficiently
Conditions are packed into a single struct
Execution history is stored as arrays
State changes are applied only when needed
3. Security Considerations
Laws should be thoroughly tested
Validation should be comprehensive
State changes should be properly validated
Execution data should be properly formatted
Access controls should be properly implemented
4. Best Practices
Use clear and descriptive law names
Implement proper validation
Document law conditions and requirements
Test laws thoroughly
Consider gas implications
Implement proper error handling
Use events for important state changes
Consider upgrade paths
Last updated