UNPKG

@pavlovcik/permit2-rpc-manager

Version:

Intelligent RPC manager with Permit2 validation and advanced fallback strategy

32 lines 1.4 kB
import { CacheManager } from "./cache-manager.ts"; import { ChainlistDataSource } from "./chainlist-data-source.ts"; import { LatencyTester } from "./latency-tester.ts"; type LoggerFn = (level: "debug" | "info" | "warn" | "error", message: string, ...optionalParams: any[]) => void; export declare class RpcSelector { private dataSource; private cacheManager; private latencyTester; private log; constructor(dataSource: ChainlistDataSource, cacheManager: CacheManager, latencyTester: LatencyTester, logger?: LoggerFn); /** * Gets a ranked list of available RPC URLs for the given chain ID. * Fetches from cache or performs latency tests if needed. * Filters out RPCs with error statuses. * Sorts the remaining RPCs by status priority (ok > wrong_bytecode > syncing) and then by latency. * Ensures only one latency test runs concurrently per chain ID. * * @param chainId - The chain ID. * @returns A promise that resolves to a sorted array of usable RPC URLs. */ getRankedRpcList(chainId: number): Promise<string[]>; /** * Helper to find the single best RPC from a latency map based on status and latency. */ private _findFastestInMap; /** * Helper to filter and rank RPC results based on status and latency. */ private _rankResults; } export {}; //# sourceMappingURL=rpc-selector.d.ts.map