Skip to main content

Submodule

Git Source

Inherits: IVersioned, ISubmodule

Submodules are isolated components of a module that can be upgraded independently.

Submodules are installed and uninstalled directly on the module.

If a module is going to hold state that should be persisted across upgrades, then a submodule pattern may be a good fit.

State Variables

parent

The parent module for this submodule.

Module public parent

Functions

constructor

constructor(Module parent_) ;

_onlyParent

function _onlyParent() internal view;

onlyParent

Modifier to restrict functions to be called only by parent module.

modifier onlyParent() ;

PARENT

5 byte identifier for the parent module.

function PARENT() public pure virtual returns (Keycode);

SUBKEYCODE

20 byte identifier for the submodule. First 5 bytes must match PARENT().

function SUBKEYCODE() public pure virtual returns (SubKeycode);

VERSION

Returns the version of the contract

function VERSION() external pure virtual override returns (uint8 major, uint8 minor);

Returns

NameTypeDescription
majoruint8- Major version upgrade indicates breaking change to the interface.
minoruint8- Minor version change retains backward-compatible interface.

supportsInterface

Query if a contract implements an interface

function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4The interface identifier, as specified in ERC-165

Returns

NameTypeDescription
<none>boolbool True if the contract supports interfaceId_

INIT

Initialization function for the submodule

This function is called when the submodule is installed or upgraded by the module.

MUST BE GATED BY onlyParent. Used to encompass any initialization or upgrade logic.

function INIT() external virtual onlyParent;

Errors

Submodule_OnlyParent

error Submodule_OnlyParent(address caller_);

Submodule_ModuleDoesNotExist

error Submodule_ModuleDoesNotExist(Keycode keycode_);

Submodule_InvalidParent

error Submodule_InvalidParent();