Skip to main content

ModuleWithSubmodules

Git Source

Inherits: Module

Base level extension of the kernel. Modules act as independent state components to be interacted with and mutated through policies.

Modules are installed and uninstalled via the executor.

State Variables

submodules

Array of all submodules currently installed.

SubKeycode[] public submodules

getSubmoduleForKeycode

Mapping of SubKeycode to Submodule address.

mapping(SubKeycode => Submodule) public getSubmoduleForKeycode

Functions

installSubmodule

Install a new submodule

This function will revert if:

  • The new submodule is not a contract

  • The new submodule does not have the same keycode prefix as this module

  • The new submodule has the same keycode as an existing submodule

  • The caller is not permissioned

function installSubmodule(Submodule newSubmodule_) external permissioned;

Parameters

NameTypeDescription
newSubmodule_SubmoduleThe new submodule to install

upgradeSubmodule

Upgrades an existing submodule

This function will revert if:

  • The new submodule is not a contract

  • The new submodule does not have the same keycode prefix as this module

  • The new submodule is the zero address

  • The new submodule has the same address as an existing submodule

  • The caller is not permissioned

function upgradeSubmodule(Submodule newSubmodule_) external permissioned;

Parameters

NameTypeDescription
newSubmodule_SubmoduleThe new submodule to install

execOnSubmodule

Perform an action on a submodule

There is no need to check if the subKeycode_ belongs to this module,

because installSubmodule() and upgradeSubmodule() (via _validateSubmodule())

ensure that the submodule has the same keycode as this module.

This function will revert if:

  • The submodule is not installed

  • The caller is not permissioned

  • The call to the submodule reverts

function execOnSubmodule(SubKeycode subKeycode_, bytes memory callData_)
external
permissioned
returns (bytes memory);

Parameters

NameTypeDescription
subKeycode_SubKeycodeThe SubKeycode of the submodule to call
callData_bytesThe calldata to send to the submodule

Returns

NameTypeDescription
<none>bytesreturnData_ The return data from the submodule call

getSubmodules

function getSubmodules() external view returns (SubKeycode[] memory);

_submoduleIsInstalled

function _submoduleIsInstalled(SubKeycode subKeycode_) internal view returns (bool);

_getSubmoduleIfInstalled

function _getSubmoduleIfInstalled(SubKeycode subKeycode_) internal view returns (Submodule);

_validateSubmodule

function _validateSubmodule(Submodule newSubmodule_) internal view returns (SubKeycode);

Errors

Module_InvalidSubmodule

error Module_InvalidSubmodule();

Module_InvalidSubmoduleUpgrade

error Module_InvalidSubmoduleUpgrade(SubKeycode subKeycode_);

Module_SubmoduleAlreadyInstalled

error Module_SubmoduleAlreadyInstalled(SubKeycode subKeycode_);

Module_SubmoduleNotInstalled

error Module_SubmoduleNotInstalled(SubKeycode subKeycode_);

Module_SubmoduleExecutionReverted

error Module_SubmoduleExecutionReverted(bytes error_);

Module_SubmoduleInterfaceNotImplemented

error Module_SubmoduleInterfaceNotImplemented(address submodule_);