/** * Smart Wallet Types * * Type definitions for EVM smart wallet functionality using Account Abstraction (EIP-4337) * and EIP-7702 delegation features. */ import { Chain, Hex, SignAuthorizationReturnType } from "viem"; import { PrivateKeyAccount } from "viem/accounts"; import { ModularSigner } from "@zerodev/permissions"; import { EntryPointVersion as ViemEntryPointVersion } from "viem/account-abstraction"; import { BundlerManager } from "../services/bundler"; import { ModuleType } from "./kernel-modules"; import { SessionKeyPermissionRule } from "./session-keys"; // ============================================ // Types // ============================================ export type KernelVersion = '0.3.3'; export type EntryPointVersion = '0.6' | '0.7'; /** * Single call/operation in a transaction */ export interface Call { /** Target contract address */ to: Hex; /** ETH value to send (optional, defaults to 0) */ value?: bigint; /** Calldata (optional, defaults to '0x') */ data?: Hex; } /** * Batch transaction configuration */ export interface BatchTransactionConfig { kernelAccount: KernelAccountInstance; bundlerManager: BundlerManager; authorization?: SignAuthorizationReturnType; calls: Call[]; } /** * Single transaction configuration (convenience) */ export interface SingleTransactionConfig { kernelAccount: KernelAccountInstance; bundlerManager: BundlerManager; authorization?: SignAuthorizationReturnType; to: Hex; value?: bigint; data?: Hex; } export interface KernelAccountConfig { chain: Chain; owner: PrivateKeyAccount; entryPointVersion?: EntryPointVersion; kernelVersion?: KernelVersion; aaConfig?: AA_SupportConfig; } export interface KernelAccountInstance { account: any; // The kernel account from ZeroDev address: string; owner: PrivateKeyAccount; chain: Chain; entryPoint: { address: Hex; version: EntryPointVersion; }; } // ============================================ // Configuration Types // ============================================ export interface AA_SupportConfig { enabled: boolean; entryPoints: { address: string; version: EntryPointVersion; }[] bundlerUrl: string; paymasterUrl: string; kernelImplementations: { address: string; version: number; }[]; } export interface SmartWalletOptions { /** Full AA support configuration from chain config */ aaConfig?: AA_SupportConfig; /** Bundler URL for submitting UserOperations */ bundlerUrl?: string; /** Paymaster URL for gas sponsorship (optional) */ paymasterUrl?: string; /** EntryPoint version to use (default: '0.7') */ entryPointVersion?: EntryPointVersion; /** Auto-initialize on extend (default: true) */ autoInitialize?: boolean; } // ============================================ // Transaction Types // ============================================ export interface SmartWalletTransactionResult { /** Whether the transaction succeeded */ success: boolean; /** UserOperation hash */ userOpHash: Hex; /** Transaction hash (after bundler execution) */ transactionHash?: string; /** Error message if failed */ error?: string; } export interface GasEstimate { /** Estimated gas for UserOperation */ callGasLimit: bigint; /** Estimated verification gas */ verificationGasLimit: bigint; /** Estimated pre-verification gas */ preVerificationGas: bigint; /** Total estimated gas */ total: bigint; } export interface SessionKeyApprovalOptions { /** Session key address to approve */ sessionKeyAddress: Hex; /** Session key private key (needed for serialization) */ sessionKeyPrivateKey: Hex; /** Permission rules for the session key */ permissions?: SessionKeyPermissionRule[]; /** Use unrestricted sudo policy (not recommended for production) */ useSudoPolicy?: boolean; } export interface SessionKeyUsageOptions { /** Serialized approval from owner */ approval: string; /** Session key signer */ sessionKeySigner: ModularSigner; } // ============================================ // Module Types // ============================================ export interface ModuleInstallOptions { /** Type of module to install */ moduleType: ModuleType; /** Module contract address */ moduleAddress: Hex; /** Initialization data for the module */ initData?: Hex; } export interface ModuleUninstallOptions { /** Type of module to uninstall */ moduleType: ModuleType; /** Module contract address */ moduleAddress: Hex; /** De-initialization data for the module */ deInitData?: Hex; } // ============================================ // Advanced Feature Types // ============================================ export interface MultiSigConfig { /** List of owner addresses */ owners: Hex[]; /** Number of signatures required (threshold) */ threshold: number; } export interface RecoveryConfig { /** Guardian addresses for account recovery */ guardians: Hex[]; /** Recovery delay in seconds */ recoveryDelay?: number; } export interface PaymasterConfig { /** Paymaster URL for sponsored transactions */ paymasterUrl: string; /** Paymaster context (optional, provider-specific) */ context?: any; } export interface SmartAccountInfo { /** Smart account address */ address: Hex; /** Owner EOA address */ ownerAddress: Hex; /** Chain information */ chain: Chain; /** EntryPoint version */ entryPointVersion: EntryPointVersion; /** Whether account is delegated (EIP-7702) */ isDelegated: boolean; /** Current balance in wei */ balance: bigint; } // ============================================ // Error Types // ============================================ export class SmartWalletError extends Error { code: string; constructor(message: string, code: string = 'SMART_WALLET_ERROR') { super(message); this.name = 'SmartWalletError'; this.code = code; } } export class SessionKeyError extends SmartWalletError { constructor(message: string) { super(message, 'SESSION_KEY_ERROR'); this.name = 'SessionKeyError'; } } export class ModuleError extends SmartWalletError { constructor(message: string) { super(message, 'MODULE_ERROR'); this.name = 'ModuleError'; } } export class TransactionError extends SmartWalletError { constructor(message: string) { super(message, 'TRANSACTION_ERROR'); this.name = 'TransactionError'; } }