UNPKG

@drift-labs/sdk-browser

Version:
29 lines (28 loc) 1.13 kB
import { BlockhashWithExpiryBlockHeight, Commitment, Connection } from '@solana/web3.js'; import { BlockhashFetcher } from './types'; /** * Fetches the latest blockhash and caches it for a configurable amount of time. * * - Prevents RPC spam by reusing cached values * - Retries on failure with exponential backoff * - Prevents concurrent requests for the same blockhash */ export declare class CachedBlockhashFetcher implements BlockhashFetcher { private connection; private blockhashCommitment; private retryCount; private retrySleepTimeMs; private staleCacheTimeMs; private recentBlockhashCache; private blockhashFetchingPromise; constructor(connection: Connection, blockhashCommitment: Commitment, retryCount: number, retrySleepTimeMs: number, staleCacheTimeMs: number); private fetchBlockhashWithRetry; private sleep; private updateBlockhashCache; getLatestBlockhash(): Promise<BlockhashWithExpiryBlockHeight | undefined>; private isCacheStale; /** * Refresh the blockhash cache, await a pending refresh if it exists */ private refreshBlockhash; }