Skip to content

ModuleManager

aboudjem edited this page Jun 7, 2024 · 1 revision

Table of Contents

ModuleManager

Git Source

Inherits: Storage, Receiver, IModuleManagerEventsAndErrors

Manages Validator, Executor, Hook, and Fallback modules within the Nexus suite, supporting

Implements SentinelList for managing modules via a linked list structure, adhering to ERC-7579.

Functions

onlyExecutorModule

Ensures the message sender is a registered executor module.

modifier onlyExecutorModule() virtual;

withHook

Does pre-checks and post-checks using an installed hook on the account.

sender, msg.data and msg.value is passed to the hook to implement custom flows.

modifier withHook();

fallback

Fallback function to manage incoming calls using designated handlers based on the call type.

fallback() external payable override(Receiver) receiverFallback;

getValidatorsPaginated

Retrieves a paginated list of validator addresses from the linked list. This utility function is not defined by the ERC-7579 standard and is implemented to facilitate easier management and retrieval of large sets of validator modules.

function getValidatorsPaginated(address cursor, uint256 size) external view returns (address[] memory array, address next);

Parameters

Name Type Description
cursor address The address to start pagination from, or zero to start from the first entry.
size uint256 The number of validator addresses to return.

Returns

Name Type Description
array address[] An array of validator addresses.
next address The address to use as a cursor for the next page of results.

getExecutorsPaginated

Retrieves a paginated list of executor addresses from the linked list. This utility function is not defined by the ERC-7579 standard and is implemented to facilitate easier management and retrieval of large sets of executor modules.

function getExecutorsPaginated(address cursor, uint256 size) external view returns (address[] memory array, address next);

Parameters

Name Type Description
cursor address The address to start pagination from, or zero to start from the first entry.
size uint256 The number of executor addresses to return.

Returns

Name Type Description
array address[] An array of executor addresses.
next address The address to use as a cursor for the next page of results.

getActiveHook

Retrieves the currently active hook address.

function getActiveHook() external view returns (address hook);

Returns

Name Type Description
hook address The address of the active hook module.

getFallbackHandlerBySelector

Fetches the fallback handler for a specific selector.

function getFallbackHandlerBySelector(bytes4 selector) external view returns (CallType, address);

Parameters

Name Type Description
selector bytes4 The function selector to query.

Returns

Name Type Description
<none> CallType calltype The type of call that the handler manages.
<none> address handler The address of the fallback handler.

_initModuleManager

Initializes the module manager by setting up default states for validators and executors.

function _initModuleManager() internal virtual;

_installValidator

Installs a new validator module after checking if it matches the required module type.

function _installValidator(address validator, bytes calldata data) internal virtual;

Parameters

Name Type Description
validator address The address of the validator module to be installed.
data bytes Initialization data to configure the validator upon installation.

Important

_installValidator: Ensure the validator module to be installed matches the required module type. Incorrect modules could lead to unexpected behavior or security vulnerabilities.

_uninstallValidator

Uninstalls a validator module /!\ ensuring the account retains at least one validator.

function _uninstallValidator(address validator, bytes calldata data) internal virtual;

Parameters

Name Type Description
validator address The address of the validator to be uninstalled.
data bytes De-initialization data to configure the validator upon uninstallation.

Caution

_uninstallValidator: Uninstalling the last validator could leave the account without necessary validation. Ensure the account retains at least one validator.

_installExecutor

Installs a new executor module after checking if it matches the required module type.

function _installExecutor(address executor, bytes calldata data) internal virtual;

Parameters

Name Type Description
executor address The address of the executor module to be installed.
data bytes Initialization data to configure the executor upon installation.

_uninstallExecutor

Uninstalls an executor module by removing it from the executors list.

function _uninstallExecutor(address executor, bytes calldata data) internal virtual;

Parameters

Name Type Description
executor address The address of the executor to be uninstalled.
data bytes De-initialization data to configure the executor upon uninstallation.

_installHook

Installs a hook module, ensuring no other hooks are installed before proceeding.

function _installHook(address hook, bytes calldata data) internal virtual;

Parameters

Name Type Description
hook address The address of the hook to be installed.
data bytes Initialization data to configure the hook upon installation.

_uninstallHook

Uninstalls a hook module, ensuring the current hook matches the one intended for uninstallation.

function _uninstallHook(address hook, bytes calldata data) internal virtual;

Parameters

Name Type Description
hook address The address of the hook to be uninstalled.
data bytes De-initialization data to configure the hook upon uninstallation.

_setHook

Sets the current hook in the storage to the specified address.

function _setHook(address hook) internal virtual;

Parameters

Name Type Description
hook address The new hook address.

_installFallbackHandler

Installs a fallback handler for a given selector with initialization data.

function _installFallbackHandler(address handler, bytes calldata params) internal virtual;

Parameters

Name Type Description
handler address The address of the fallback handler to install.
params bytes The initialization parameters including the selector and call type.

_uninstallFallbackHandler

Uninstalls a fallback handler for a given selector.

function _uninstallFallbackHandler(address fallbackHandler, bytes calldata data) internal virtual;

Parameters

Name Type Description
fallbackHandler address The address of the fallback handler to uninstall.
data bytes The de-initialization data containing the selector.

_isFallbackHandlerInstalled

Checks if a fallback handler is set for a given selector.

function _isFallbackHandlerInstalled(bytes4 selector) internal view virtual returns (bool);

Parameters

Name Type Description
selector bytes4 The function selector to check.

Returns

Name Type Description
<none> bool True if a fallback handler is set, otherwise false.

_isFallbackHandlerInstalled

Checks if the expected fallback handler is installed for a given selector.

function _isFallbackHandlerInstalled(bytes4 selector, address expectedHandler) internal view returns (bool);

Parameters

Name Type Description
selector bytes4 The function selector to check.
expectedHandler address The address of the handler expected to be installed.

Returns

Name Type Description
<none> bool True if the installed handler matches the expected handler, otherwise false.

_isValidatorInstalled

Checks if a validator is currently installed.

function _isValidatorInstalled(address validator) internal view virtual returns (bool);

Parameters

Name Type Description
validator address The address of the validator to check.

Returns

Name Type Description
<none> bool True if the validator is installed, otherwise false.

_isExecutorInstalled

Checks if an executor is currently installed.

function _isExecutorInstalled(address executor) internal view virtual returns (bool);

Parameters

Name Type Description
executor address The address of the executor to check.

Returns

Name Type Description
<none> bool True if the executor is installed, otherwise false.

_isHookInstalled

Checks if a hook is currently installed.

function _isHookInstalled(address hook) internal view returns (bool);

Parameters

Name Type Description
hook address The address of the hook to check.

Returns

Name Type Description
<none> bool True if the hook is installed, otherwise false.

_getHook

Retrieves the current hook from the storage.

function _getHook() internal view returns (address hook);

Returns

Name Type Description
hook address The address of the current hook.

_paginate

Helper function to paginate entries in a SentinelList.

function _paginate(
    SentinelListLib.SentinelList storage list,
    address cursor,
    uint256 size
)
    private
    view
    returns (address[] memory array, address nextCursor);

Parameters

Name Type Description
list SentinelListLib.SentinelList The SentinelList to paginate.
cursor address The cursor to start paginating from.
size uint256 The number of entries to return.

Returns

Name Type Description
array address[] The array of addresses in the list.
nextCursor address The cursor for the next page of entries.
Clone this wiki locally