Skip to main content

WithModules

Git Source

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

NameTypeDescription
newModule_ModuleThe 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

NameTypeDescription
keycode_KeycodeThe module keycode

_moduleIsInstalled

Checks whether any module is installed under the keycode

function _moduleIsInstalled(Keycode keycode_) internal view returns (bool);

Parameters

NameTypeDescription
keycode_KeycodeThe module keycode

Returns

NameTypeDescription
<none>boolTrue 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

NameTypeDescription
keycode_KeycodeThe module keycode

Returns

NameTypeDescription
<none>addressThe 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

NameTypeDescription
keycode_KeycodeThe module keycode
version_uint8The module version

Returns

NameTypeDescription
<none>addressThe 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

NameTypeDescription
veecode_VeecodeThe module Veecode

Returns

NameTypeDescription
<none>addressThe 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

NameTypeDescription
veecode_VeecodeThe module Veecode
callData_bytesThe call data

Returns

NameTypeDescription
<none>bytesThe 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_);

ModuleNotInstalled

error ModuleNotInstalled(Keycode keycode_, uint8 version_);

ModuleExecutionReverted

error ModuleExecutionReverted(bytes error_);

ModuleAlreadySunset

error ModuleAlreadySunset(Keycode keycode_);

ModuleIsSunset

error ModuleIsSunset(Keycode keycode_);

TargetNotAContract

error TargetNotAContract(address target_);

Structs

ModStatus

struct ModStatus {
uint8 latestVersion;
bool sunset;
}