Skip to content
Lattice

ERC7579ModuleConfigLib

Git Source

Title: ERC7579ModuleConfigLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from ERC-7579 reference implementation (https://github.com/erc7579/erc7579-implementation)

Logic + ERC-7201 storage for the ERC-7579 module registry, consuming all four module types: EXECUTOR (2 — drives batches via executeFromExecutor), VALIDATOR (1 — authorizes user ops in ERC4337Validation), HOOK (4 — the single global hook wrapping execution), and FALLBACK (3 — per-selector handlers dispatched by AccountDiamond on a facet-map miss).

diamondCut remains the SOLE selector authority ("modules-as-facets"); fallback handlers are layered UNDER the facet map and may not shadow a facet selector. execute / supportsExecutionMode (completing the ERC-7579 surface) live on the ERC7821Executor facet.

Constants

_ACCOUNT_ID

ERC-7579 account identifier (vendorname.accountname.semver).

string private constant _ACCOUNT_ID = "lattice.diamond-account.0.1.0";

Functions

erc7579ModuleConfigStorage

function erc7579ModuleConfigStorage() internal pure returns (ERC7579ModuleConfigStorage storage $);

Returns

NameTypeDescription
$ERC7579ModuleConfigStorage

__ERC7579ModuleConfig_init

Registers the three ERC-7579 interface ids the Diamond supports.

function __ERC7579ModuleConfig_init() internal;

registerInterfaces

function registerInterfaces() internal;

accountId

function accountId() internal pure returns (string memory);

Returns

NameTypeDescription
<none>string

supportsModule

function supportsModule(uint256 moduleTypeId) internal pure returns (bool);

Parameters

NameTypeDescription
moduleTypeIduint256

Returns

NameTypeDescription
<none>bool

hook

The installed global hook (type 4), or address(0) if none.

function hook() internal view returns (address);

Returns

NameTypeDescription
<none>address

fallbackHandlerFor

The fallback handler (type 3) for selector, or a zero-address handler if none. Read by AccountDiamond on a facet-map miss.

function fallbackHandlerFor(bytes4 selector) internal view returns (address handler, bytes1 callType);

Parameters

NameTypeDescription
selectorbytes4

Returns

NameTypeDescription
handleraddress
callTypebytes1

isModuleInstalled

For FALLBACK (type 3), additionalContext is abi.encode(bytes4 selector); the module is "installed" iff it is the registered handler for that selector. Other types key on _installed[type][module].

function isModuleInstalled(uint256 moduleTypeId, address module, bytes calldata additionalContext)
        internal
        view
        returns (bool);

Parameters

NameTypeDescription
moduleTypeIduint256
moduleaddress
additionalContextbytes

Returns

NameTypeDescription
<none>bool

isInstalled

Whether module is installed as moduleTypeId — the context-free form for internal consumers (e.g. the validation facet's per-op validator lookup).

function isInstalled(uint256 moduleTypeId, address module) internal view returns (bool);

Parameters

NameTypeDescription
moduleTypeIduint256
moduleaddress

Returns

NameTypeDescription
<none>bool

installModule

Installs module as moduleTypeId. Caller must be the account itself or an admin; the module must report the type via isModuleType. Calls module.onInstall(initData).

function installModule(uint256 moduleTypeId, address module, bytes calldata initData) internal;

Parameters

NameTypeDescription
moduleTypeIduint256
moduleaddress
initDatabytes

uninstallModule

Uninstalls module. Caller must be the account itself or an admin. Calls onUninstall.

function uninstallModule(uint256 moduleTypeId, address module, bytes calldata deInitData) internal;

Parameters

NameTypeDescription
moduleTypeIduint256
moduleaddress
deInitDatabytes

executeFromExecutor

Runs a batch on behalf of msg.sender, which must be an installed executor module (type 2). Wrapped by the global hook (if any), like the owner/session-key execute path.

function executeFromExecutor(bytes32 mode, bytes calldata executionCalldata)
        internal
        returns (bytes[] memory results);

Parameters

NameTypeDescription
modebytes32
executionCalldatabytes

Returns

NameTypeDescription
resultsbytes[]

preExecutionHook

Runs the global hook's preCheck (if installed) before an execution, returning the hook and its opaque context for the matching postExecutionHook. A reverting hook blocks the execution.

function preExecutionHook(bytes calldata msgData) internal returns (address h, bytes memory hookData);

Parameters

NameTypeDescription
msgDatabytes

Returns

NameTypeDescription
haddress
hookDatabytes

postExecutionHook

Runs the global hook's postCheck (if h is non-zero) after an execution.

function postExecutionHook(address h, bytes memory hookData) internal;

Parameters

NameTypeDescription
haddress
hookDatabytes

_authorizeConfig

function _authorizeConfig() private view;