@drift-labs/sdk
Version:
SDK for Drift Protocol
45 lines (44 loc) • 2.44 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { BulkAccountLoader } from './bulkAccountLoader';
import { Commitment, Connection, PublicKey } from '@solana/web3.js';
export declare class CustomizedCadenceBulkAccountLoader extends BulkAccountLoader {
private customIntervalId;
private currentPollingFrequency;
private accountFrequencies;
private lastPollingTimes;
private defaultPollingFrequency;
constructor(connection: Connection, commitment: Commitment, defaultPollingFrequency: number);
private getAccountsToLoad;
load(): Promise<void>;
private handleAccountLoading;
/**
* Updates the polling frequency for an account. This affects all callbacks attached to this account.
*
* @param publicKey The public key of the account to set the custom polling frequency for
* @param newFrequency The new polling frequency in ms
*/
setCustomPollingFrequency(publicKey: PublicKey, newFrequency: number): void;
private restartPollingIfNeeded;
/**
* Adds an account to be monitored by the bulk account loader
* @param publicKey The public key of the account to monitor
* @param callback Function to be called when account data is received
* @param customPollingFrequency Optional custom polling frequency in ms for this specific account.
* If not provided, will use the default polling frequency
* @returns A unique callback ID that can be used to remove this specific callback later
*
* The method will:
* 1. Create a new callback mapping for the account if it doesn't exist already
* 2. Set up polling frequency tracking for the account if it doesn't exist already. If previous polling frequency is faster than the new one,
* we will use the previous frequency.
* 3. Reset last polling time to 0 to ensure data fetch is triggered on the next poll. Note that this does not mean the account will be fetched immediately.
* 4. Automatically restart polling if this account needs a faster frequency than existing accounts
*/
addAccount(publicKey: PublicKey, callback: (buffer: Buffer, slot: number) => void, customPollingFrequency?: number): Promise<string>;
removeAccount(publicKey: PublicKey, callbackId: string): void;
getAccountCadence(publicKey: PublicKey): number | null;
startPolling(): void;
stopPolling(): void;
clearAccountFrequencies(): void;
}