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 _changeState functions
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 deployed
Law__Initialized: Emitted when a law is initialized
Errors
Law Errors
Law__OnlyPowers: Emitted when a law is called by a non-powers account
Law__NoZeroAddress: Emitted when a zero address is used
Law__ProposalNotSucceeded: Emitted when a proposal is not succeeded
Law__ParentLawNotSet: Emitted when a parent law is not set
Law__NoDeadlineSet: Emitted when a deadline is not set
Law__InvalidPowersContractAddress: Emitted when a powers contract address is invalid
Law__ParentNotCompleted: Emitted when a parent law is not completed
Law__ParentBlocksCompletion: Emitted when a parent law blocks completion
Law__ExecutionGapTooSmall: Emitted when an execution gap is too small
Law__DeadlineNotPassed: Emitted when a deadline is not passed