/** * Account Activity Service for monitoring account transactions and balance changes * * This service subscribes to account activity and receives all transactions * and balance updates for those accounts via the comprehensive AccountActivityMessage format. */ import type { AccountsControllerGetSelectedAccountAction, AccountsControllerSelectedAccountChangeEvent } from "@metamask/accounts-controller"; import type { TraceCallback } from "@metamask/controller-utils"; import type { Messenger } from "@metamask/messenger"; import type { Transaction, BalanceUpdate } from "../types.mjs"; import type { AccountActivityServiceMethodActions } from "./AccountActivityService-method-action-types.mjs"; import type { BackendWebSocketServiceConnectionStateChangedEvent } from "./BackendWebSocketService.mjs"; import type { BackendWebSocketServiceMethodActions } from "./BackendWebSocketService-method-action-types.mjs"; /** * System notification data for chain status updates */ export type SystemNotificationData = { /** Array of chain IDs affected (e.g., ['eip155:137', 'eip155:1']) */ chainIds: string[]; /** Status of the chains: 'down' or 'up' */ status: 'down' | 'up'; /** Timestamp of the notification */ timestamp?: number; }; declare const SERVICE_NAME = "AccountActivityService"; /** * Account subscription options */ export type SubscriptionOptions = { address: string; }; /** * Configuration options for the account activity service */ export type AccountActivityServiceOptions = { /** Custom subscription namespace (default: 'account-activity.v1') */ subscriptionNamespace?: string; /** Optional callback to trace performance of account activity operations (default: no-op) */ traceFn?: TraceCallback; }; export type AccountActivityServiceActions = AccountActivityServiceMethodActions; export declare const ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS: readonly ["AccountsController:getSelectedAccount", "BackendWebSocketService:connect", "BackendWebSocketService:forceReconnection", "BackendWebSocketService:subscribe", "BackendWebSocketService:getConnectionInfo", "BackendWebSocketService:channelHasSubscription", "BackendWebSocketService:getSubscriptionsByChannel", "BackendWebSocketService:findSubscriptionsByChannelPrefix", "BackendWebSocketService:addChannelCallback", "BackendWebSocketService:removeChannelCallback"]; export declare const ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS: readonly ["AccountsController:selectedAccountChange", "BackendWebSocketService:connectionStateChanged"]; export type AllowedActions = AccountsControllerGetSelectedAccountAction | BackendWebSocketServiceMethodActions; export type AccountActivityServiceTransactionUpdatedEvent = { type: `AccountActivityService:transactionUpdated`; payload: [Transaction]; }; export type AccountActivityServiceBalanceUpdatedEvent = { type: `AccountActivityService:balanceUpdated`; payload: [{ address: string; chain: string; updates: BalanceUpdate[]; }]; }; export type AccountActivityServiceSubscriptionErrorEvent = { type: `AccountActivityService:subscriptionError`; payload: [{ addresses: string[]; error: string; operation: string; }]; }; export type AccountActivityServiceStatusChangedEvent = { type: `AccountActivityService:statusChanged`; payload: [ { chainIds: string[]; status: 'up' | 'down'; timestamp?: number; } ]; }; export type AccountActivityServiceEvents = AccountActivityServiceTransactionUpdatedEvent | AccountActivityServiceBalanceUpdatedEvent | AccountActivityServiceSubscriptionErrorEvent | AccountActivityServiceStatusChangedEvent; export type AllowedEvents = AccountsControllerSelectedAccountChangeEvent | BackendWebSocketServiceConnectionStateChangedEvent; export type AccountActivityServiceMessenger = Messenger; /** * High-performance service for real-time account activity monitoring using optimized * WebSocket subscriptions with direct callback routing. Automatically subscribes to * the currently selected account and switches subscriptions when the selected account changes. * Receives transactions and balance updates using the comprehensive AccountActivityMessage format. * * Performance Features: * - Direct callback routing (no EventEmitter overhead) * - Minimal subscription tracking (no duplication with BackendWebSocketService) * - Optimized cleanup for mobile environments * - Single-account subscription (only selected account) * - Comprehensive balance updates with transfer tracking * * Architecture: * - Uses messenger pattern to communicate with BackendWebSocketService * - AccountActivityService tracks channel-to-subscriptionId mappings via messenger calls * - Automatically subscribes to selected account on initialization * - Switches subscriptions when selected account changes * - No direct dependency on BackendWebSocketService (uses messenger instead) * * @example * ```typescript * const service = new AccountActivityService({ * messenger: activityMessenger, * }); * * // Service automatically subscribes to the currently selected account * // When user switches accounts, service automatically resubscribes * * // All transactions and balance updates are received via optimized * // WebSocket callbacks and processed with zero-allocation routing * // Balance updates include comprehensive transfer details and post-transaction balances * ``` */ export declare class AccountActivityService { #private; /** * The name of the service. */ readonly name = "AccountActivityService"; /** * Creates a new Account Activity service instance * * @param options - Configuration options including messenger */ constructor(options: AccountActivityServiceOptions & { messenger: AccountActivityServiceMessenger; }); /** * Subscribe to account activity (transactions and balance updates) * Address should be in CAIP-10 format (e.g., "eip155:0:0x1234..." or "solana:0:ABC123...") * * @param subscription - Account subscription configuration with address */ subscribe(subscription: SubscriptionOptions): Promise; /** * Unsubscribe from account activity for specified address * Address should be in CAIP-10 format (e.g., "eip155:0:0x1234..." or "solana:0:ABC123...") * * @param subscription - Account subscription configuration with address to unsubscribe */ unsubscribe(subscription: SubscriptionOptions): Promise; /** * Destroy the service and clean up all resources * Optimized for fast cleanup during service destruction or mobile app termination */ destroy(): void; } export {}; //# sourceMappingURL=AccountActivityService.d.mts.map