ModuleManagerBase_v1.sol

Git Source

Inherits: IModuleManagerBase_v1, Initializable, ERC2771ContextUpgradeable, ERC165Upgradeable

Author: Inverter Network Adapted from Gnosis Safe

A contract to manage Inverter Network modules. It allows for adding and removing modules in a local registry for reference. Additional functionality includes the execution of calls from this contract. The transaction execution and module management is copied from Gnosis Safe's ModuleManager.

State Variables

MAX_MODULE_AMOUNT

Marks the maximum amount of Modules a {Orchestrator_v1} can have to avoid out-of-gas risk.

uint private constant MAX_MODULE_AMOUNT = 128;

MODULE_UPDATE_TIMELOCK

Timelock used between initiating adding or removing a module and executing it.

uint public constant MODULE_UPDATE_TIMELOCK = 72 hours;

moduleFactory

{ModuleFactory_v1}.

address public moduleFactory;

_modules

List of modules.

address[] private _modules;

_isModule

Mapping to keep track of whether a module is used in the {Orchestrator_v1} address => isModule.

mapping(address => bool) private _isModule;

moduleAddressToTimelock

Mapping to keep track of active timelocks for updating modules module => timelock.

mapping(address module => ModuleUpdateTimelock timelock) public
    moduleAddressToTimelock;

__gap

Storage gap for future upgrades.

uint[50] private __gap;

Functions

supportsInterface

See {IERC165-supportsInterface}.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable)
    returns (bool);

__ModuleManager_onlyAuthorized

Modifier to guarantee function is only callable by authorized address.

modifier __ModuleManager_onlyAuthorized();

onlyModule

Modifier to guarantee that the caller is a module.

modifier onlyModule();

validModule

Modifier to guarantee that the given module is a valid module.

modifier validModule(address module);

isModule_

Modifier to guarantee that the given module is a registered module.

modifier isModule_(address module);

isNotModule

Modifier to guarantee that the given module is not a registered module.

modifier isNotModule(address module);

moduleLimitNotExceeded

Modifier to guarantee that the number of modules is not exceeded.

modifier moduleLimitNotExceeded();

updatingModuleAlreadyStarted

Modifier to guarantee that the given module is not already being updated.

modifier updatingModuleAlreadyStarted(address _module);

timelockExpired

Modifier to guarantee that the timelock for the given module is expired.

modifier timelockExpired(address _module);

constructor

constructor(address _trustedForwarder)
    ERC2771ContextUpgradeable(_trustedForwarder);

__ModuleManager_init

Initialization function.

Only callable during initialization.

function __ModuleManager_init(
    address _moduleFactory,
    address[] calldata modules
) internal onlyInitializing;

Parameters

NameTypeDescription

_moduleFactory

address

The address of the module factory.

modules

address[]

The addresses of the modules used in the orchestrator.

__ModuleManager_addModule

Adds address module as module.

function __ModuleManager_addModule(address module)
    internal
    isNotModule(module)
    validModule(module)
    moduleLimitNotExceeded;

Parameters

NameTypeDescription

module

address

The module address to add.

__ModuleManager_isAuthorized

Returns whether address who is authorized to mutate module manager's state.

MUST be overridden in downstream contract.

function __ModuleManager_isAuthorized(address who)
    internal
    view
    virtual
    returns (bool);

Parameters

NameTypeDescription

who

address

The address to check.

Returns

NameTypeDescription

<none>

bool

True if the address is authorized, false otherwise.

isModule

Returns whether the address module is added as module.

function isModule(address module)
    public
    view
    override(IModuleManagerBase_v1)
    returns (bool);

Parameters

NameTypeDescription

module

address

The module to check.

Returns

NameTypeDescription

<none>

bool

True if module added, false otherwise.

listModules

Returns the list of all modules.

function listModules() public view returns (address[] memory);

Returns

NameTypeDescription

<none>

address[]

List of all modules.

modulesSize

Returns the number of modules.

function modulesSize() external view returns (uint8);

Returns

NameTypeDescription

<none>

uint8

The number of modules.

_cancelModuleUpdate

Cancels an initiated update for a module.

Only callable by authorized address.

Fails if module update has not been initiated.

function _cancelModuleUpdate(address module)
    internal
    __ModuleManager_onlyAuthorized
    updatingModuleAlreadyStarted(module);

Parameters

NameTypeDescription

module

address

The module address to remove.

_initiateAddModuleWithTimelock

Initiates adding of a module to the {Orchestrator_v1} on a timelock.

Only callable by authorized address.

Fails of adding module exeeds max modules limit.

Fails if address invalid or address already added as module.

function _initiateAddModuleWithTimelock(address module)
    internal
    __ModuleManager_onlyAuthorized
    isNotModule(module)
    validModule(module);

Parameters

NameTypeDescription

module

address

The module address to add.

_initiateRemoveModuleWithTimelock

Initiates removing of a module from the {Orchestrator_v1} on a timelock.

Only callable by authorized address.

Fails if address not added as module.

function _initiateRemoveModuleWithTimelock(address module)
    internal
    __ModuleManager_onlyAuthorized
    isModule_(module);

Parameters

NameTypeDescription

module

address

The module address to remove.

_executeAddModule

Executes adding of a module to the {Orchestrator_v1}.

Only callable by authorized address.

Fails if adding of module has not been initiated.

Fails if timelock has not been expired yet.

function _executeAddModule(address module)
    internal
    __ModuleManager_onlyAuthorized
    updatingModuleAlreadyStarted(module)
    timelockExpired(module);

Parameters

NameTypeDescription

module

address

The module address to add.

_executeRemoveModule

Executes removing of a module from the {Orchestrator_v1}.

Only callable by authorized address.

Fails if removing of module has not been initiated.

Fails if timelock has not been expired yet.

function _executeRemoveModule(address module)
    internal
    __ModuleManager_onlyAuthorized
    updatingModuleAlreadyStarted(module)
    timelockExpired(module);

Parameters

NameTypeDescription

module

address

The module address to remove.

_commitAddModule

Expects module to be valid module address.

Expects module to not be enabled module.

function _commitAddModule(address module) internal;

Parameters

NameTypeDescription

module

address

The module address to add.

_commitRemoveModule

Expects address arguments to be consecutive in the modules list.

Expects address module to be enabled module.

function _commitRemoveModule(address module) private;

Parameters

NameTypeDescription

module

address

The module address to remove.

_ensureValidModule

Ensures that the given module is a valid module.

Reverts if the module is invalid.

function _ensureValidModule(address module) private view;

Parameters

NameTypeDescription

module

address

The module address to check.

_ensureNotModule

Ensures that the given module is not a registered module.

Reverts if the module is registered.

function _ensureNotModule(address module) private view;

Parameters

NameTypeDescription

module

address

The module address to check.

_startModuleUpdateTimelock

Starts the timelock for the given module.

function _startModuleUpdateTimelock(address _module) internal;

Parameters

NameTypeDescription

_module

address

The module address to start the timelock for.

isTrustedForwarder

Returns wether the given address is the trusted forwarder or not.

Exposes the ERC2771 isTrusted Forwarder.

function isTrustedForwarder(address forwarder)
    public
    view
    virtual
    override(IModuleManagerBase_v1, ERC2771ContextUpgradeable)
    returns (bool);

Parameters

NameTypeDescription

forwarder

address

The address to check.

Returns

NameTypeDescription

<none>

bool

True if the address is the trusted forwarder, false otherwise.

trustedForwarder

Returns the trusted forwarder for metatransactions.

Exposes the ERC2771 isTrusted Forwarder.

function trustedForwarder()
    public
    view
    virtual
    override(IModuleManagerBase_v1, ERC2771ContextUpgradeable)
    returns (address);

Returns

NameTypeDescription

<none>

address

The trusted forwarder address.

Last updated