Skip to content

Factories

aboudjem edited this page Jun 5, 2024 · 11 revisions

Nexus Factories Overview

Factories in the Nexus framework are responsible for creating and managing smart accounts compliant with ERC-7579 and ERC-4337 standards. They ensure deterministic deployment of accounts and handle initialization processes, guaranteeing modular and secure account creation. Below, we explain the purpose and flow of each factory within the Nexus framework.

Contents

  1. Factory Overview
  2. BiconomyMetaFactory
  3. ModuleWhitelistFactory
  4. K1ValidatorFactory
  5. NexusAccountFactory

Factory Overview

Factories in the Nexus framework are specialized contracts that manage the creation of modular smart accounts. They provide a standardized way to deploy accounts with specific configurations, ensuring compliance with ERC-7579 and ERC-4337 standards. Each factory handles different aspects of account creation, from module whitelisting to validator integration, ensuring the robustness and flexibility of the Nexus smart accounts.

Key Responsibilities of Factories:

  • Deterministic Deployment: Ensures that the deployed account addresses are predictable and consistent across different environments.
  • Module Management: Integrates and manages various modules within the smart accounts to enhance functionality and security.
  • Compliance and Security: Adheres to industry standards and implements stringent security measures to protect user accounts.

BiconomyMetaFactory

BiconomyMetaFactory manages the deployment of Nexus accounts using approved factories. It ensures only whitelisted factories can be used, preventing unauthorized deployments and enhancing security.

BiconomyMetaFactory

Purpose:

  • Factory Whitelisting: Ensures that only authorized factories can deploy accounts.
  • Secure Deployment: Verifies the success of the deployment call and returns the created account address.

Create Account Flow:

  1. Input Factory Address and Data
  2. Check if Factory is Whitelisted
  3. Call Factory with Data
  4. Check if Call was Successful
  5. Deploy Account if Call Successful
  6. Return Created Account Address

BiconomyMetaFactory Flow

Tip

Ensure the factory whitelist is regularly updated to include only trusted factories. This prevents unauthorized access and potential security breaches.

ModuleWhitelistFactory

ModuleWhitelistFactory ensures that only whitelisted modules are used during the Nexus account creation. This factory provides an additional layer of security by validating the modules before deployment.

ModuleWhitelistFactory

Purpose:

  • Module Validation: Ensures only approved modules are integrated into the accounts.
  • Secure Initialization: Initializes the account with whitelisted modules, ensuring compliance and security.

Create Account Flow:

  1. Input Init Data and Salt
  2. Extract Modules from Init Data
  3. Check if Modules are Whitelisted
  4. Compute Deterministic Salt
  5. Deploy Nexus with Salt
  6. Initialize Account with Whitelisted Modules if Not Deployed
  7. Emit Account Created Event
  8. Return Created Account Address

ModuleWhitelistFactory Flow

Warning

Always verify the integrity and security of modules before adding them to the whitelist. Regularly review and update the whitelist to ensure only secure modules are used.

K1ValidatorFactory

K1ValidatorFactory is designed for creating Nexus accounts with K1 validators, ensuring that each account is associated with a validated owner and follows secure initialization procedures.

K1ValidatorFactory

Purpose:

  • Validator Integration: Incorporates K1 validators into the account initialization process.
  • Deterministic Deployment: Uses a unique salt and validator information for predictable deployments.

Create Account Flow:

  1. Input EOA Owner and Index
  2. Compute Deterministic Salt
  3. Deploy Nexus with Salt
  4. Check if Already Deployed
  5. Initialize Account with K1 Validator if Not Deployed
  6. Emit Account Created Event
  7. Return Created Account Address

K1ValidatorFactory Flow

[!INFO] Ensure the K1 validator address is correctly set and immutable to maintain the integrity of the validation process.

NexusAccountFactory

NexusAccountFactory handles the general creation of Nexus smart accounts using a deterministic deployment pattern, ensuring consistency and predictability.

NexusAccountFactory

Purpose:

  • Deterministic Deployment: Uses a unique salt and initialization data for predictable account creation.
  • General Account Initialization: Handles the basic initialization of Nexus accounts, making it a versatile factory for various deployment needs.

Create Account Flow:

  1. Input Init Data and Salt
  2. Compute Deterministic Salt
  3. Deploy Nexus with Salt
  4. Check if Already Deployed
  5. Initialize Account if Not Deployed
  6. Emit Account Created Event
  7. Return Created Account Address

NexusAccountFactory Flow

Tip

Regularly audit the initialization data and deployment process to ensure compliance with security standards and best practices.