WithModules
Inherits: Owned
Abstract contract that provides functionality for installing and interacting with modules.
This contract is intended to be inherited by any contract that needs to install modules.
State Variables
modules
Array of the Keycodes corresponding to the currently installed modules.
Keycode[] public modules;
modulesCount
The number of modules installed.
uint256 public modulesCount;
getModuleForVeecode
Mapping of Veecode to Module address.
mapping(Veecode => Module) public getModuleForVeecode;
getModuleStatus
Mapping of Keycode to module status information.
mapping(Keycode => ModStatus) public getModuleStatus;
isExecOnModule
bool public isExecOnModule;
Functions
constructor
constructor(address owner_) Owned(owner_);
installModule
Installs a module. Can be used to install a new module or upgrade an existing one.
The version of the installed module must be one greater than the latest version. If it's a new module, then the version must be 1.
Only one version of a module is active for creation functions at a time. Older versions continue to work for existing data.
If a module is currently sunset, installing a new version will remove the sunset.
This function reverts if:
- The caller is not the owner
- The module is not a contract
- The module has an invalid Veecode
- The module (or other versions) is already installed
- The module version is not one greater than the latest version
function installModule(Module newModule_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
newModule_ | Module | The new module |
_ensureContract
function _ensureContract(address target_) internal view;
sunsetModule
Sunsets a module
Sunsetting a module prevents future deployments that use the module, but functionality remains for existing users.
Modules should implement functionality such that creation functions are disabled if sunset.
Sunset is used to disable a module type without installing a new one.
This function reverts if:
- The caller is not the owner
- The module is not installed
- The module is already sunset
function sunsetModule(Keycode keycode_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
keycode_ | Keycode | The module keycode |
_moduleIsInstalled
Checks whether any module is installed under the keycode
function _moduleIsInstalled(Keycode keycode_) internal view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
keycode_ | Keycode | The module keycode |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the module is installed, false otherwise |
_getLatestModuleIfActive
Returns the address of the latest version of a module
This function reverts if:
- The module is not installed
- The module is sunset
function _getLatestModuleIfActive(Keycode keycode_) internal view returns (address);
Parameters
Name | Type | Description |
---|---|---|
keycode_ | Keycode | The module keycode |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the latest version of the module |
_getModuleIfInstalled
Returns the address of a module
This function reverts if:
- The specific module and version is not installed
function _getModuleIfInstalled(Keycode keycode_, uint8 version_) internal view returns (address);
Parameters
Name | Type | Description |
---|---|---|
keycode_ | Keycode | The module keycode |
version_ | uint8 | The module version |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the module |
_getModuleIfInstalled
Returns the address of a module
This function reverts if:
- The specific module and version is not installed
function _getModuleIfInstalled(Veecode veecode_) internal view returns (address);
Parameters
Name | Type | Description |
---|---|---|
veecode_ | Veecode | The module Veecode |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the module |
execOnModule
Performs a call on a module
This can be used to perform administrative functions on a module, such as setting parameters or calling permissioned functions
This function reverts if:
- The caller is not the parent
- The module is not installed
- The call is made to a prohibited function
- The call reverted
function execOnModule(
Veecode veecode_,
bytes calldata callData_
) external onlyOwner returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
veecode_ | Veecode | The module Veecode |
callData_ | bytes | The call data |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | The return data from the call |
Events
ModuleInstalled
event ModuleInstalled(Keycode indexed keycode, uint8 indexed version, address indexed location);
ModuleSunset
event ModuleSunset(Keycode indexed keycode);
Errors
InvalidModuleInstall
error InvalidModuleInstall(Keycode keycode_, uint8 version_);