/**
 * Generic account subscription manager using Solana programNotifications.
 *
 * Framework-agnostic — no React, no Sentry, no webapp-specific deps.
 * Consumers provide error/log callbacks for observability.
 *
 * Features:
 * - Ref-counted: first listener starts the WS, last unsubscribe tears it down
 * - Slot-based ordering: rejects out-of-order notifications
 * - Buffer dedup: skips unchanged data (updates slot without firing callbacks)
 * - Auto-reconnect: retries on all WS errors with configurable delay
 * - Per-subscription onReconnect hook for state refresh after WS recovery
 */
import { type Address, type Base58EncodedBytes, type Commitment, type RpcSubscriptions, type Slot, type SolanaRpcSubscriptionsApi } from '@solana/kit';
export declare const WS_RECONNECT_DELAY_MS = 500;
export type SubscriptionCallback = (address: Address, buffer: Uint8Array, slot: Slot) => void;
export type SubscriptionMode = 'ws' | 'idle';
export type SubscriptionErrorHandler = (error: unknown) => void;
export type SubscriptionLogger = (...args: unknown[]) => void;
export type ProgramFilter = Readonly<{
    dataSize: bigint;
}> | Readonly<{
    memcmp: Readonly<{
        offset: bigint;
        bytes: Base58EncodedBytes;
        encoding: 'base58';
    }>;
}>;
export interface AccountSubscriptionManagerConfig {
    wsRpc: RpcSubscriptions<SolanaRpcSubscriptionsApi>;
    onError?: SubscriptionErrorHandler;
    onLog?: SubscriptionLogger;
    reconnectDelayMs?: number;
}
export interface SubscribeProgramAccountsOptions {
    commitment?: Commitment;
    /** Called after WS reconnects (before resuming the notification loop).
     *  Use this to refresh local state that may have gone stale during downtime.
     *
     *  Note: onReconnect is per-subscription-key, not per-listener. If multiple
     *  listeners share the same key, the last one to provide onReconnect wins. */
    onReconnect?: () => void | Promise<void>;
    /** Throttle callback invocations to at most once per N milliseconds.
     *  Useful for high-frequency accounts like reserves that update every slot.
     *  When set, the latest notification is buffered and delivered after the interval.
     *  Not recommended for obligations (low-frequency, want instant delivery).
     *
     *  Note: throttleMs is set once per subscription key (first subscriber wins).
     *  Subsequent subscribers to the same key inherit the existing throttle. */
    throttleMs?: number;
}
export declare class AccountSubscriptionManager {
    private subscriptions;
    private nextListenerId;
    private wsRpc;
    private onError;
    private onLog;
    private reconnectDelayMs;
    constructor(config: AccountSubscriptionManagerConfig);
    /**
     * Subscribe to program account changes. Returns an unsubscribe function.
     *
     * The first subscriber for a given key starts the WS connection; the last
     * unsubscribe tears it down. Late subscribers immediately receive any
     * cached account data from previous notifications.
     */
    subscribeProgramAccounts(programId: Address, filters: readonly ProgramFilter[], callback: SubscriptionCallback, options?: SubscribeProgramAccountsOptions): () => void;
    /**
     * Immediately flush any throttled pending notifications for the subscription
     * matching the given programId + filters. Resets the throttle timer so the
     * next notification after flush waits the full interval again.
     *
     * No-op if the subscription doesn't exist or has no pending notifications.
     */
    /**
     * Immediately flush any throttled pending notifications.
     * When commitment is provided, flushes only that specific subscription.
     * When omitted, flushes all matching programId+filters across all commitments.
     */
    flushPending(programId: Address, filters: readonly ProgramFilter[], commitment?: Commitment): void;
    getMode(programId: Address, filters: readonly ProgramFilter[], commitment?: Commitment): SubscriptionMode;
    /** Tear down all subscriptions. Useful for shutdown and test cleanup. */
    destroy(): void;
    /** Resolves when the WS subscription for the given programId + filters is established. */
    waitForConnection(programId: Address, filters: readonly ProgramFilter[], commitment?: Commitment): Promise<void>;
    private buildKey;
    /**
     * Find a subscription by programId + filters.
     * When commitment is provided, does a direct Map lookup (O(1)).
     * When omitted, scans all commitments and returns the first match.
     */
    private findSubscription;
    private flushSub;
    private createSubscription;
    private startWs;
    private handleNotification;
    private flushPendingNotifications;
    private fireCallbacks;
    private teardown;
}
//# sourceMappingURL=accountSubscriptionManager.d.ts.map