@drift-labs/sdk-browser
Version:
SDK for Drift Protocol
67 lines (66 loc) • 2.68 kB
TypeScript
import { Commitment, Connection, MemcmpFilter } from '@solana/web3.js';
import { DataAndSlot } from '../accounts/types';
import { ConstituentAccount } from '../types';
import { DriftClient } from '../driftClient';
export type ConstituentMapConfig = {
driftClient: DriftClient;
connection?: Connection;
subscriptionConfig: {
type: 'polling';
frequency: number;
commitment?: Commitment;
} | {
type: 'websocket';
resubTimeoutMs?: number;
logResubMessages?: boolean;
commitment?: Commitment;
};
lpPoolId?: number;
additionalFilters?: MemcmpFilter[];
decoder?: 'base64' | 'base64+zstd';
};
export interface ConstituentMapInterface {
subscribe(): Promise<void>;
unsubscribe(): Promise<void>;
has(key: string): boolean;
get(key: string): ConstituentAccount | undefined;
getFromSpotMarketIndex(spotMarketIndex: number): ConstituentAccount | undefined;
getFromConstituentIndex(constituentIndex: number): ConstituentAccount | undefined;
getWithSlot(key: string): DataAndSlot<ConstituentAccount> | undefined;
mustGet(key: string): Promise<ConstituentAccount>;
mustGetWithSlot(key: string): Promise<DataAndSlot<ConstituentAccount>>;
}
export declare class ConstituentMap implements ConstituentMapInterface {
private driftClient;
private constituentMap;
private constituentAccountSubscriber;
private additionalFilters?;
private commitment?;
private connection?;
private constituentIndexToKeyMap;
private spotMarketIndexToKeyMap;
private lpPoolId;
private decoder;
constructor(config: ConstituentMapConfig);
private getFilters;
private decode;
sync(): Promise<void>;
subscribe(): Promise<void>;
unsubscribe(): Promise<void>;
has(key: string): boolean;
get(key: string): ConstituentAccount | undefined;
getFromConstituentIndex(constituentIndex: number): ConstituentAccount | undefined;
getFromSpotMarketIndex(spotMarketIndex: number): ConstituentAccount | undefined;
getWithSlot(key: string): DataAndSlot<ConstituentAccount> | undefined;
mustGet(key: string): Promise<ConstituentAccount>;
mustGetWithSlot(key: string): Promise<DataAndSlot<ConstituentAccount>>;
size(): number;
values(): IterableIterator<ConstituentAccount>;
valuesWithSlot(): IterableIterator<DataAndSlot<ConstituentAccount>>;
entries(): IterableIterator<[string, ConstituentAccount]>;
entriesWithSlot(): IterableIterator<[
string,
DataAndSlot<ConstituentAccount>
]>;
updateConstituentAccount(key: string, constituentAccount: ConstituentAccount, slot: number): void;
}