Skip to main content

IERC7579Module

IModule Interface​

The IModule interface defines the standard functions and errors for modules developed for the wallet. This interface ensures that all modules interact seamlessly with the wallet's core functionality.

Code Snippet​

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

import {PackedUserOperation} from "./PackedUserOperation.sol";

uint256 constant VALIDATION_SUCCESS = 0;
uint256 constant VALIDATION_FAILED = 1;

uint256 constant MODULE_TYPE_VALIDATOR = 1;
uint256 constant MODULE_TYPE_EXECUTOR = 2;
uint256 constant MODULE_TYPE_FALLBACK = 3;
uint256 constant MODULE_TYPE_HOOK = 4;

interface IModule {
error AlreadyInitialized(address smartAccount);
error NotInitialized(address smartAccount);

/**
* @dev This function is called by the smart account during installation of the module
* @param data arbitrary data that may be required on the module during `onInstall`
* initialization
*
* MUST revert on error (i.e. if module is already enabled)
*/
function onInstall(bytes calldata data) external;

/**
* @dev This function is called by the smart account during uninstallation of the module
* @param data arbitrary data that may be required on the module during `onUninstall`
* de-initialization
*
* MUST revert on error
*/
function onUninstall(bytes calldata data) external;

/**
* @dev Returns boolean value if module is a certain type
* @param moduleTypeId the module type ID according the ERC-7579 spec
*
* MUST return true if the module is of the given type and false otherwise
*/
function isModuleType(uint256 moduleTypeId) external view returns (bool);

/**
* @dev Returns if the module was already initialized for a provided smartaccount
*/
function isInitialized(address smartAccount) external view returns (bool);
}

interface IValidator is IModule {
error InvalidTargetAddress(address target);

/**
* @dev Validates a transaction on behalf of the account.
* This function is intended to be called by the MSA during the ERC-4337 validaton phase
* Note: solely relying on bytes32 hash and signature is not suffcient for some
* validation implementations (i.e. SessionKeys often need access to userOp.calldata)
* @param userOp The user operation to be validated. The userOp MUST NOT contain any metadata.
* The MSA MUST clean up the userOp before sending it to the validator.
* @param userOpHash The hash of the user operation to be validated
* @return return value according to ERC-4337
*/
function validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) external returns (uint256);

/**
* Validator can be used for ERC-1271 validation
*/
function isValidSignatureWithSender(
address sender,
bytes32 hash,
bytes calldata data
) external view returns (bytes4);
}

interface IExecutor is IModule {}

interface IHook is IModule {
function preCheck(
address msgSender,
uint256 msgValue,
bytes calldata msgData
) external returns (bytes memory hookData);

function postCheck(bytes calldata hookData) external;
}

interface IFallback is IModule {}

Errors​

AlreadyInitialized​

error AlreadyInitialized(address smartAccount);

This error is thrown when an attempt is made to initialize an already initialized module.

  • smartAccount: The address of the smart account.

NotInitialized​

error NotInitialized(address smartAccount);

This error is thrown when an operation is performed on a module that has not been initialized.

  • smartAccount: The address of the smart account.

Functions​

onInstall​

function onInstall(bytes calldata data) external;

This function is called by the smart account during the installation of the module.

  • data: Arbitrary data that may be required during the module's onInstall initialization.
  • MUST revert on error (e.g., if the module is already enabled).

onUninstall​

function onUninstall(bytes calldata data) external;

This function is called by the smart account during the uninstallation of the module.

  • data: Arbitrary data that may be required during the module's onUninstall de-initialization.
  • MUST revert on error.

isModuleType​

function isModuleType(uint256 moduleTypeId) external view returns (bool);

Returns a boolean value indicating if the module is of a certain type.

  • moduleTypeId: The type ID of the module according to the ERC-7579 spec.
  • MUST return true if the module is of the given type and false otherwise.

isInitialized​

function isInitialized(address smartAccount) external view returns (bool);

Returns whether the module has been initialized for a provided smart account.

  • smartAccount: The address of the smart account.

IValidator Interface​

The IValidator interface extends the IModule interface and adds functions specific to validating transactions.

Errors​

InvalidTargetAddress​

error InvalidTargetAddress(address target);

This error is thrown when an invalid target address is provided.

  • target: The invalid target address.

Functions​

validateUserOp​

function validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) external returns (uint256);

Validates a transaction on behalf of the account. This function is intended to be called by the MSA during the ERC-4337 validation phase.

  • userOp: The user operation to be validated. The userOp MUST NOT contain any metadata. The MSA MUST clean up the userOp before sending it to the validator.
  • userOpHash: The hash of the user operation to be validated.
  • Returns: A return value according to ERC-4337.

isValidSignatureWithSender​

function isValidSignatureWithSender(
address sender,
bytes32 hash,
bytes calldata data
) external view returns (bytes4);

Validates a smart account signature, which may involve forwarding the call to a validator module.

  • sender: The address of the sender.
  • hash: The hash of the data that is signed.
  • data: The data that is signed.
  • Returns: A bytes4 value indicating whether the signature is valid.

IExecutor Interface​

The IExecutor interface extends the IModule interface. It is intended for modules that execute transactions on behalf of the smart account.

IHook Interface​

The IHook interface extends the IModule interface and adds functions specific to hooks that run before and after transactions.

Functions​

preCheck​

function preCheck(
address msgSender,
uint256 msgValue,
bytes calldata msgData
) external returns (bytes memory hookData);

Runs checks before a transaction is executed.

  • msgSender: The address of the message sender.
  • msgValue: The value of the message.
  • msgData: The data of the message.
  • Returns: Hook data that may be needed for post-transaction checks.

postCheck​

function postCheck(bytes calldata hookData) external;

Runs checks after a transaction is executed.

  • hookData: The hook data returned from the preCheck function.

IFallback Interface​

The IFallback interface extends the IModule interface. It is intended for modules that act as a fallback mechanism for the smart account.


Constants​

uint256 constant VALIDATION_SUCCESS = 0;
uint256 constant VALIDATION_FAILED = 1;

uint256 constant MODULE_TYPE_VALIDATOR = 1;
uint256 constant MODULE_TYPE_EXECUTOR = 2;
uint256 constant MODULE_TYPE_FALLBACK = 3;
uint256 constant MODULE_TYPE_HOOK = 4;

These constants define standard module types and validation statuses.

By implementing these interfaces, third-party developers can create modules that integrate seamlessly with the wallet, ensuring compatibility and enhancing the wallet's functionality.