UNPKG

@drift-labs/sdk

Version:
87 lines (86 loc) 4.73 kB
/// <reference types="node" /> import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js'; import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SignedMsgOrderRecord, DeleteUserRecord, FuelSweepRecord, FuelSeasonRecord, InsuranceFundSwapRecord, TransferProtocolIfSharesToRevenuePoolRecord, LPMintRedeemRecord, LPSettleRecord, LPSwapRecord } from '../types'; import { EventEmitter } from 'events'; export type EventSubscriptionOptions = { address?: PublicKey; eventTypes?: EventType[]; maxEventsPerType?: number; orderBy?: EventSubscriptionOrderBy; orderDir?: EventSubscriptionOrderDirection; commitment?: Commitment; maxTx?: number; logProviderConfig?: LogProviderConfig; untilTx?: TransactionSignature; }; export declare const DefaultEventSubscriptionOptions: EventSubscriptionOptions; export type EventSubscriptionOrderBy = 'blockchain' | 'client'; export type EventSubscriptionOrderDirection = 'asc' | 'desc'; export type Event<T> = T & { txSig: TransactionSignature; slot: number; txSigIndex: number; }; export type WrappedEvent<Type extends EventType> = EventMap[Type] & { eventType: Type; }; export type WrappedEvents = WrappedEvent<EventType>[]; export type EventMap = { DepositRecord: Event<DepositRecord>; FundingPaymentRecord: Event<FundingPaymentRecord>; LiquidationRecord: Event<LiquidationRecord>; FundingRateRecord: Event<FundingRateRecord>; OrderRecord: Event<OrderRecord>; OrderActionRecord: Event<OrderActionRecord>; SettlePnlRecord: Event<SettlePnlRecord>; NewUserRecord: Event<NewUserRecord>; LPRecord: Event<LPRecord>; InsuranceFundRecord: Event<InsuranceFundRecord>; SpotInterestRecord: Event<SpotInterestRecord>; InsuranceFundStakeRecord: Event<InsuranceFundStakeRecord>; CurveRecord: Event<CurveRecord>; SwapRecord: Event<SwapRecord>; SpotMarketVaultDepositRecord: Event<SpotMarketVaultDepositRecord>; SignedMsgOrderRecord: Event<SignedMsgOrderRecord>; DeleteUserRecord: Event<DeleteUserRecord>; FuelSweepRecord: Event<FuelSweepRecord>; FuelSeasonRecord: Event<FuelSeasonRecord>; InsuranceFundSwapRecord: Event<InsuranceFundSwapRecord>; TransferProtocolIfSharesToRevenuePoolRecord: Event<TransferProtocolIfSharesToRevenuePoolRecord>; LPMintRedeemRecord: Event<LPMintRedeemRecord>; LPSettleRecord: Event<LPSettleRecord>; LPSwapRecord: Event<LPSwapRecord>; }; export type EventType = keyof EventMap; export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SignedMsgOrderRecord> | Event<DeleteUserRecord> | Event<FuelSweepRecord> | Event<FuelSeasonRecord> | Event<InsuranceFundSwapRecord> | Event<TransferProtocolIfSharesToRevenuePoolRecord> | Event<LPSettleRecord> | Event<LPSwapRecord> | Event<LPMintRedeemRecord>; export interface EventSubscriberEvents { newEvent: (event: WrappedEvent<EventType>) => void; } export type SortFn = (currentRecord: EventMap[EventType], newRecord: EventMap[EventType]) => 'less than' | 'greater than'; export type logProviderCallback = (txSig: TransactionSignature, slot: number, logs: string[], mostRecentBlockTime: number | undefined, txSigIndex: number | undefined) => void; export interface LogProvider { isSubscribed(): boolean; subscribe(callback: logProviderCallback, skipHistory?: boolean): Promise<boolean>; unsubscribe(external?: boolean): Promise<boolean>; eventEmitter?: EventEmitter; } export type LogProviderType = 'websocket' | 'polling' | 'events-server'; export type StreamingLogProviderConfig = { maxReconnectAttempts?: number; fallbackFrequency?: number; fallbackBatchSize?: number; }; export type WebSocketLogProviderConfig = StreamingLogProviderConfig & { type: 'websocket'; resubTimeoutMs?: number; }; export type PollingLogProviderConfig = { type: 'polling'; frequency: number; batchSize?: number; }; export type EventsServerLogProviderConfig = StreamingLogProviderConfig & { type: 'events-server'; url: string; }; export type LogProviderConfig = WebSocketLogProviderConfig | PollingLogProviderConfig | EventsServerLogProviderConfig;