ERC7579ModuleConfigLib
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
| Name | Type | Description |
|---|---|---|
| $ | 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
| Name | Type | Description |
|---|---|---|
| <none> | string |
supportsModule
function supportsModule(uint256 moduleTypeId) internal pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| moduleTypeId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
hook
The installed global hook (type 4), or address(0) if none.
function hook() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| selector | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| handler | address | |
| callType | bytes1 |
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
| Name | Type | Description |
|---|---|---|
| moduleTypeId | uint256 | |
| module | address | |
| additionalContext | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| moduleTypeId | uint256 | |
| module | address |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| moduleTypeId | uint256 | |
| module | address | |
| initData | bytes |
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
| Name | Type | Description |
|---|---|---|
| moduleTypeId | uint256 | |
| module | address | |
| deInitData | bytes |
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
| Name | Type | Description |
|---|---|---|
| mode | bytes32 | |
| executionCalldata | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| results | bytes[] |
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
| Name | Type | Description |
|---|---|---|
| msgData | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| h | address | |
| hookData | bytes |
postExecutionHook
Runs the global hook's postCheck (if h is non-zero) after an execution.
function postExecutionHook(address h, bytes memory hookData) internal;Parameters
| Name | Type | Description |
|---|---|---|
| h | address | |
| hookData | bytes |
_authorizeConfig
function _authorizeConfig() private view;