PolicyEnabler
Inherits: PolicyAdmin
This contract is designed to be inherited by contracts that need to be enabled or disabled. It replaces the inconsistent usage of active
and locallyActive
state variables across the codebase.
*A contract that inherits from this contract should use the onlyEnabled
and onlyDisabled
modifiers to gate access to certain functions.
Inheriting contracts must do the following:
- In
configureDependencies()
, assign the module address to theROLES
state variable, e.g.ROLES = ROLESv1(getModuleAddress(toKeycode("ROLES")));
The following are optional: - Override the
_enable()
and_disable()
functions if custom logic and/or parameters are needed for the enable/disable functions. - For example,
enable()
could be called with initialisation data that is decoded, validated and assigned in_enable()
.*
State Variables
isEnabled
Whether the policy functionality is enabled
bool public isEnabled;
Functions
onlyEnabled
Modifier that reverts if the policy is not enabled
modifier onlyEnabled();
onlyDisabled
Modifier that reverts if the policy is enabled
modifier onlyDisabled();
enable
Enable the contract
*This function performs the following steps:
- Validates that the caller has the admin role
- Validates that the contract is disabled
- Calls the implementation-specific
_enable()
function - Changes the state of the contract to enabled
- Emits the
Enabled
event*
function enable(bytes calldata enableData_) public onlyAdminRole onlyDisabled;
Parameters
Name | Type | Description |
---|---|---|
enableData_ | bytes | The data to pass to the implementation-specific _enable() function |
_enable
Implementation-specific enable function
*This function is called by the enable()
function
The implementing contract can override this function and perform the following:
- Validate any parameters (if needed) or revert
- Validate state (if needed) or revert
- Perform any necessary actions, apart from modifying the
isEnabled
state variable*
function _enable(bytes calldata enableData_) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
enableData_ | bytes | Custom data that can be used by the implementation. The format of this data is left to the discretion of the implementation. |
disable
Disable the contract
*This function performs the following steps:
- Validates that the caller has the admin or emergency role
- Validates that the contract is enabled
- Calls the implementation-specific
_disable()
function - Changes the state of the contract to disabled
- Emits the
Disabled
event*
function disable(bytes calldata disableData_) public onlyEmergencyOrAdminRole onlyEnabled;
Parameters
Name | Type | Description |
---|---|---|
disableData_ | bytes | The data to pass to the implementation-specific _disable() function |
_disable
Implementation-specific disable function
*This function is called by the disable()
function.
The implementing contract can override this function and perform the following:
- Validate any parameters (if needed) or revert
- Validate state (if needed) or revert
- Perform any necessary actions, apart from modifying the
isEnabled
state variable*
function _disable(bytes calldata disableData_) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
disableData_ | bytes | Custom data that can be used by the implementation. The format of this data is left to the discretion of the implementation. |
Events
Disabled
event Disabled();
Enabled
event Enabled();
Errors
NotDisabled
error NotDisabled();
NotEnabled
error NotEnabled();