import BN from "bn.js" import { EVMVM } from "./evm"; import { SVMVM } from "./svm"; import type { EntryPointVersion } from "./evm/aa-service/lib/type"; export interface ChainWalletConfig { chainId: number; name: string; rpcUrl: string; explorerUrl: string; nativeToken: { name: string; symbol: string; decimals: number; }; logoUrl: string confirmationNo?: number testnet?: boolean; vmType: vmTypes savings?: ChainSavingConfig // Smart wallet configuration (optional) only for EVM chains and 7702 aaSupport?: AA_SupportConfig } export interface ChainSavingConfig { supported: boolean; // Whether savings tracking is supported on this chain tokens: TokenInfo[]; // List of token addresses to track for savings } export interface AA_SupportConfig { enabled: boolean; entryPoints: { address: string; version: EntryPointVersion; }[] bundlerUrl: string; paymasterUrl: string; kernelImplementations: { address: string; version: number; }[]; } export interface TokenInfo { address: string; name: string; symbol: string; decimals: number; logoUrl?: string; description?: string; website?: string; social?: { twitter?: string; discord?: string; telegram?: string; [key: string]: string | undefined; }; } export interface UserTokenBalance extends TokenInfo { balance: number; owner: AddressType; } export interface NFTInfo { tokenId: string; contractAddress: string; name?: string; description?: string; image?: string; } // Unified NFT interface for both EVM and SVM chains export interface NFT { // Unique identifier id: string; // For Solana: mint address, For EVM: contractAddress:tokenId // Basic metadata name: string; symbol?: string; description: string; image?: string; uri: string; // Metadata URI // Collection/Contract info collection: { address: string; name: string; verified?: boolean; }; // Chain-specific data chainType: 'SVM' | 'EVM'; // Ownership balance?: string; // Quantity owned (useful for ERC1155) // Optional metadata attributes?: Array<{ trait_type: string; value: string | number; display_type?: string; }>; // Creators/Royalties (mainly for Solana) creators?: Array<{ address: string; verified: boolean; share: number; }>; // Additional metadata sellerFeeBasisPoints?: number; // Royalty percentage tokenStandard?: string; // e.g., "ERC721", "ERC1155", "NonFungible", etc. // Spam detection (mainly for EVM) isSpam?: boolean; // Raw chain-specific data for advanced use cases raw?: { svm?: SolanaNFT; evm?: EVMNFT; }; } // NFT Collection interface for both EVM and SVM chains export interface NFTCollection { // Collection identifier address: string; // Collection metadata name: string; symbol?: string; description?: string; image?: string; // Verification status verified?: boolean; // Chain-specific data chainType: 'SVM' | 'EVM'; // NFTs owned by the user in this collection nfts: NFT[]; // Collection statistics totalOwned: number; // Number of NFTs owned by user in this collection // Collection-level metadata (for EVM) contractMetadata?: { tokenType?: string; // ERC721, ERC1155, etc. totalSupply?: string; contractDeployer?: string; deployedBlockNumber?: number; }; // Collection-level metadata (for SVM) collectionMetadata?: { updateAuthority?: string; sellerFeeBasisPoints?: number; creators?: Array<{ address: string; verified: boolean; share: number; }>; }; // OpenSea metadata (for EVM) openSeaMetadata?: { collectionSlug?: string; floorPrice?: number; safelistRequestStatus?: string; }; } export interface SolanaNFT { mint: string; name: string; symbol: string; uri: string; updateAuthority: string; sellerFeeBasisPoints: number; creators?: Array<{ address: string; verified: boolean; share: number; }>; } export interface EVMNFTContract { address: string; name: string; symbol: string; totalSupply: string; tokenType: string; contractDeployer: string; deployedBlockNumber: number; isSpam: boolean; spamClassifications?: string[]; } export interface EVMNFTOpenSeaMetadata { collectionName: string; collectionSlug: string; floorPrice?: number; safelistRequestStatus: string; imageUrl?: string; lastIngestedAt: string; } export interface EVMNFTImage { cachedUrl?: string; thumbnailUrl?: string; pngUrl?: string; contentType?: string; size?: number; originalUrl?: string; } export interface EVMNFTAttribute { trait_type: string; value: string | number; display_type?: string; } export interface EVMNFTRawMetadata { tokenUri?: string; metadata?: { name?: string; description?: string; image?: string; attributes?: EVMNFTAttribute[]; [key: string]: any; }; } export interface EVMNFTMint { mintAddress?: string; blockNumber?: number; timestamp?: string; transactionHash?: string; } export interface EVMNFT { contract: EVMNFTContract; openSeaMetadata?: EVMNFTOpenSeaMetadata; tokenId: string; tokenType: string; name: string; description: string; balance: string; image?: EVMNFTImage; raw?: EVMNFTRawMetadata; mint?: EVMNFTMint; timeLastUpdated: string; acquiredAt?: string; } export interface EVMNFTResponse { data: EVMNFT[]; } export interface TransactionResult { hash: string; success: boolean; error?: string; } export interface Balance { balance: BN; formatted: number; decimal: number } // ============================================ // Wallet Discovery Types // ============================================ /** * A discovered wallet with balance information */ export interface DiscoveredWallet { /** BIP-44 account index */ index: number; /** Wallet address */ address: string; /** Full BIP-44 derivation path */ derivationPath: string; /** Native token balance */ nativeBalance: { amount: bigint; // Raw amount (wei, lamports) formatted: number; // Human-readable (ETH, SOL) symbol: string; // 'ETH', 'SOL', etc. }; /** Optional: Include private key (security consideration) */ privateKey?: string; } /** * Discovery options */ export interface WalletDiscoveryOptions { /** Starting index (default: 0) */ startIndex?: number; /** Maximum index to check (default: 100) */ maxIndex?: number; /** Gap limit - stop after N empty wallets (default: 20) */ gapLimit?: number; /** Minimum balance to consider (default: 0) */ minBalance?: bigint; /** Include wallets with zero balance (default: false) */ includeZeroBalance?: boolean; /** Include private keys in results (default: false) */ includePrivateKeys?: boolean; /** Check wallets in parallel (default: true for speed) */ checkInParallel?: boolean; /** If parallel, batch size (default: 10) */ batchSize?: number; /** Delay between checks in milliseconds (default: 200ms for parallel, 50ms for sequential) */ checkDelay?: number; /** Progress callback */ onProgress?: (current: number, total: number, found: number) => void; /** Callback when a wallet is discovered */ onDiscovered?: (wallet: DiscoveredWallet) => void; } /** * Pocket discovery options */ export interface PocketDiscoveryOptions extends Omit { /** Wallet index for pocket derivation (default: 0) */ walletIndex?: number; /** Callback when a pocket is discovered */ onDiscovered?: (pocket: DiscoveredWallet) => void; } /** * Discovery result */ export interface WalletDiscoveryResult { /** Discovered wallets with balances */ discovered: DiscoveredWallet[]; /** Number of indices scanned */ scannedIndices: number; /** Highest index checked */ highestIndex: number; /** Total balance across all discovered wallets */ totalBalance: bigint; /** Whether scan was stopped by gap limit */ stoppedByGapLimit: boolean; /** Scan duration in milliseconds */ duration: number; } export const SUPPORTED_VM = { 'EVM': EVMVM, 'SVM': SVMVM } as const; export type vmTypes = keyof typeof SUPPORTED_VM;