Skip to main content

Module

Git Source

Modules are isolated components of a contract that can be upgraded independently.

Two main patterns are considered for Modules:

1. Directly calling modules from the parent contract to execute upgradable logic or having the option to add new sub-components to a contract

2. Delegate calls to modules to execute upgradable logic, similar to a proxy, but only for specific functions and being able to add new sub-components to a contract

State Variables

PARENT

The parent contract for this module.

address public immutable PARENT;

Functions

constructor

constructor(address parent_);

onlyParent

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

modifier onlyParent();

onlyInternal

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

If a function is called through execOnModule() on the parent contract, this modifier will revert.

This modifier can be used to prevent functions from being called by governance or other external actors through execOnModule().

modifier onlyInternal();

TYPE

2 byte identifier for the module type

This enables the parent contract to check that the module Keycode specified is of the correct type

function TYPE() public pure virtual returns (Type);

VEECODE

7 byte, versioned identifier for the module. 2 characters from 0-9 that signify the version and 3-5 characters from A-Z.

function VEECODE() public pure virtual returns (Veecode);

INIT

Initialization function for the module

This function is called when the module 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

Module_OnlyParent

Error when a module function is called by a non-parent contract

error Module_OnlyParent(address caller_);

Module_OnlyInternal

Error when a module function is called by a non-internal contract

error Module_OnlyInternal();

Module_InvalidParent

Error when the parent contract is invalid

error Module_InvalidParent(address parent_);

Enums

Type

Enum of module types

enum Type {
Auction,
Derivative,
Condenser,
Transformer
}