/** * Savings Pocket Types * * Type definitions for the savings pocket feature that allows users to create * multiple savings accounts derived from their seed phrase using BIP-44 account indices. */ import { Hex } from "viem"; import { EVMSmartWallet } from "../evm/smartWallet"; /** * Savings account derived from BIP-44 account index */ export interface SavingsAccount { /** Account index used for derivation (m/44'/60'/accountIndex'/0/0) */ accountIndex: number; /** Derived private key for this savings account */ privateKey: Hex; /** Derived address for this savings account */ address: Hex; /** Full BIP-44 derivation path */ derivationPath: string; } /** * Savings account upgraded to EIP-7702 smart account */ export interface SmartSavingsAccount extends SavingsAccount { /** Smart wallet instance for advanced features */ smartWallet: EVMSmartWallet; /** Whether the account has been initialized on-chain */ isInitialized: boolean; } /** * Options for transferring to savings */ export interface TransferToSavingsOptions { /** Expected address for verification (prevents tampering) */ expectedAddress?: Hex; /** Transaction priority for gas estimation */ priority?: 'low' | 'medium' | 'high'; /** Whether to use smart account features (requires 7702 upgrade) */ useSmartAccount?: boolean; } /** * Options for withdrawing from savings */ export interface WithdrawFromSavingsOptions { /** Expected source address for verification */ expectedAddress?: Hex; /** Transaction priority */ priority?: 'low' | 'medium' | 'high'; /** Whether to use smart account features */ useSmartAccount?: boolean; } /** * Result of address verification */ export interface AddressVerificationResult { /** Account index that was verified */ accountIndex: number; /** Stored address that was checked */ storedAddress: Hex; /** Derived address from account index */ derivedAddress: Hex; /** Whether addresses match */ isValid: boolean; /** Error message if invalid */ error?: string; } /** * Result of batch address audit */ export interface SavingsAuditResult { /** Total number of addresses audited */ total: number; /** Number of valid addresses */ valid: number; /** Number of invalid addresses */ invalid: number; /** Whether all addresses are valid */ allValid: boolean; /** Detailed results per address */ results: AddressVerificationResult[]; /** Timestamp of audit */ timestamp: Date; } /** * Lock module configuration for locked savings */ export interface LockModuleConfig { /** Lock duration in seconds */ lockDuration: number; /** Lock end timestamp (computed) */ lockedUntil: number; /** Whether early withdrawal is allowed with penalty */ allowEarlyWithdrawal?: boolean; /** Penalty percentage for early withdrawal (0-100) */ earlyWithdrawalPenalty?: number; } /** * Periodic savings session configuration */ export interface PeriodicSavingsConfig { /** Amount to save each period */ amount: number; /** Savings frequency */ frequency: 'daily' | 'weekly' | 'monthly'; /** Destination account index */ savingsAccountIndex: number; /** Optional end date for recurring savings */ endDate?: Date; /** Maximum number of executions */ maxExecutions?: number; } /** * Spend and save hook configuration */ export interface SpendAndSaveConfig { /** Percentage of spending to save (0-100) */ savePercentage: number; /** Destination savings account index */ savingsAccountIndex: number; /** Minimum transaction amount to trigger saving */ minTransactionAmount?: number; /** Maximum amount to save per transaction */ maxSaveAmount?: number; }