Skip to main content

Modules

Make Your Wallet More Flexible with Modular Design

Traditional smart accounts can be rigid and require developer intervention for even minor changes. This is where Modular Smart Accounts (MSA) come in!

Think of an MSA like a toolbox. Instead of having everything built-in, functionalities are stored in separate compartments called modules. This allows for:

  • Faster development: Need a new feature? Just add a module! No complex upgrades required.
  • User control: Don't like a feature? Simply remove its module. No need to redeploy the entire account.

Axir Smart Wallet Module Types

Axir Smart Wallet utilizes a modular design, allowing for customization and flexibility through different types of modules. Here's a breakdown of the four main module types:

1. Validator Modules (MODULE_TYPE_VALIDATOR TYPE == 1)

  • Function: These modules act as security guards, defining who is authorized to perform actions on your account.
  • Description: They implement various signature schemes and authorization mechanisms. For example, a validator module might require multi-signature approval for critical transactions.

2. Executor Modules (MODULE_TYPE_EXECUTOR == 2)

  • Function: These modules are the workhorses, carrying out the actual functionalities you desire.
  • Description: They define custom functions to perform specific tasks within your wallet. Need to send tokens or interact with a DeFi protocol? An executor module can handle that.

3. Fallback Modules (MODULE_TYPE_FALLBACK == 3)

  • Function: These modules (optional) provide a safety net, handling situations where no other module explicitly defines the action.
  • Description: They offer a way to define default behavior for unexpected scenarios. Think of it as a "catch-all" for unrecognized transactions.

4. Hook Modules (MODULE_TYPE_HOOK == 4)

  • Function: These modules (optional) act as observers, allowing you to intercept and react to specific events within your wallet.
  • Description: They can be used for monitoring purposes, triggering additional actions based on certain events, or even integrating with external services. Think of them as customizable triggers within your wallet's workflow.

Setting the Standard for Modular Wallets

The world of smart account modules is still young, but efforts are underway to create a common language.

  • ERC 6900 (April 2023, Alchemy): This proposal outlines a detailed rulebook for how modules should be built and how accounts should interact with them.
  • ERC 7579 (December 2023, Rhinestone, Biconomy, ZeroDev, OKX): This proposal focuses on the core functionalities needed for modules and accounts to work together seamlessly, leaving more room for innovation in how they're implemented.

ERC 7579 gives developers more freedom to experiment, while ERC 6900 offers a more structured approach. The choice depends on the desired balance between flexibility and predictability.

Installing a Module in Your Axir Smart Wallet

info

When you are deploying your Axir Smart Wallet it automatically gets initialized with default modules.

This guide explains how to install a module in your Axir Smart Wallet. Modules provide additional functionalities to your wallet, allowing for customization and flexibility.

Prerequisites:

  • You have a deployed Axir Smart Wallet contract.
  • You have the module's contract address.

Steps:

  1. Prepare the Installation Transaction:

    • Identify the module type:
      • Validator Module (MODULE_TYPE_VALIDATOR): Defines who can perform actions on your wallet.
      • Executor Module (MODULE_TYPE_EXECUTOR): Carries out specific tasks within your wallet (e.g., sending tokens).
      • Fallback Module (MODULE_TYPE_FALLBACK): Provides a default behavior for unexpected scenarios.
      • Hook Module (MODULE_TYPE_HOOK): Allows monitoring events and reacting to them.
    • Use the installModule function in your wallet contract interaction.
    • Provide the following arguments:
      • moduleTypeId: The type of module you want to install (obtained from step 1a).
      • module: The contract address of the module you want to install.
      • initData (optional): Any initialization data required by the module (check the module's documentation for details).
  2. Send the Transaction:

    • Send a transaction to your wallet contract with the prepared installModule function call.
    • The transaction will be executed if successful.

Example:

// Assuming you have the following information:
uint256 moduleTypeId = 1; // This is for a Validator Module
address moduleAddress = 0x...; // Replace with the actual module contract address
bytes memory initData = abi.encode(...); // Replace with any required initialization data (if applicable)

// Send the transaction to install the module
walletContract.installModule(moduleTypeId, moduleAddress, initData);

Important Notes:

  • Only authorized modules (typically your executor module) can call the installModule function.
  • Make sure the module you are installing is compatible with your Axir wallet version.
  • Refer to the module's documentation for specific installation requirements and initialization data.

By following these steps, you can add modules to your Axir Smart Wallet and extend its capabilities to fit your needs.

In the following sections, we provide a detailed overview of key concepts including