@drift-labs/sdk 2.146.0-beta.0 → 2.146.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,6 +71,8 @@ function decodeUser(buffer) {
71
71
  const quoteAssetAmount = readSignedBigInt64LE(buffer, offset + 16);
72
72
  const lpShares = readUnsignedBigInt64LE(buffer, offset + 64);
73
73
  const openOrders = buffer.readUInt8(offset + 94);
74
+ const positionFlag = buffer.readUInt8(offset + 95);
75
+ const isolatedPositionScaledBalance = readUnsignedBigInt64LE(buffer, offset + 96);
74
76
  if (baseAssetAmount.eq(numericConstants_1.ZERO) &&
75
77
  openOrders === 0 &&
76
78
  quoteAssetAmount.eq(numericConstants_1.ZERO) &&
@@ -117,6 +119,8 @@ function decodeUser(buffer) {
117
119
  openOrders,
118
120
  perLpBase,
119
121
  maxMarginRatio,
122
+ isolatedPositionScaledBalance,
123
+ positionFlag,
120
124
  });
121
125
  }
122
126
  const orders = [];
@@ -89,7 +89,7 @@ class DriftClient {
89
89
  this._isSubscribed = val;
90
90
  }
91
91
  constructor(config) {
92
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
92
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26;
93
93
  this.users = new Map();
94
94
  this._isSubscribed = false;
95
95
  this.perpMarketLastSlotCache = new Map();
@@ -180,12 +180,13 @@ class DriftClient {
180
180
  resubTimeoutMs: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.resubTimeoutMs,
181
181
  logResubMessages: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.logResubMessages,
182
182
  commitment: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.commitment,
183
+ programUserAccountSubscriber: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.programUserAccountSubscriber,
183
184
  };
184
185
  this.userStatsAccountSubscriptionConfig = {
185
186
  type: 'websocket',
186
- resubTimeoutMs: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.resubTimeoutMs,
187
- logResubMessages: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.logResubMessages,
188
- commitment: (_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.commitment,
187
+ resubTimeoutMs: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.resubTimeoutMs,
188
+ logResubMessages: (_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.logResubMessages,
189
+ commitment: (_5 = config.accountSubscription) === null || _5 === void 0 ? void 0 : _5.commitment,
189
190
  };
190
191
  }
191
192
  if (config.userStats) {
@@ -207,21 +208,22 @@ class DriftClient {
207
208
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
208
209
  config.spotMarketIndexes === undefined &&
209
210
  config.oracleInfos === undefined;
210
- if (((_5 = config.accountSubscription) === null || _5 === void 0 ? void 0 : _5.type) === 'polling') {
211
- this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_6 = config.perpMarketIndexes) !== null && _6 !== void 0 ? _6 : [], (_7 = config.spotMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.oracleInfos) !== null && _8 !== void 0 ? _8 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
212
- }
213
- else if (((_9 = config.accountSubscription) === null || _9 === void 0 ? void 0 : _9.type) === 'grpc') {
214
- const accountSubscriberClass = (_11 = (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.driftClientAccountSubscriber) !== null && _11 !== void 0 ? _11 : grpcDriftClientAccountSubscriber_1.grpcDriftClientAccountSubscriber;
215
- this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (_12 = config.perpMarketIndexes) !== null && _12 !== void 0 ? _12 : [], (_13 = config.spotMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.oracleInfos) !== null && _14 !== void 0 ? _14 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
216
- resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
217
- logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
211
+ if (((_6 = config.accountSubscription) === null || _6 === void 0 ? void 0 : _6.type) === 'polling') {
212
+ this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_7 = config.perpMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.spotMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.oracleInfos) !== null && _9 !== void 0 ? _9 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
213
+ }
214
+ else if (((_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.type) === 'grpc') {
215
+ const accountSubscriberClass = (_12 = (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.driftClientAccountSubscriber) !== null && _12 !== void 0 ? _12 : grpcDriftClientAccountSubscriber_1.grpcDriftClientAccountSubscriber;
216
+ this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (_13 = config.perpMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.spotMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.oracleInfos) !== null && _15 !== void 0 ? _15 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
217
+ resubTimeoutMs: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.resubTimeoutMs,
218
+ logResubMessages: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.logResubMessages,
218
219
  });
219
220
  }
220
221
  else {
221
- this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_17 = config.perpMarketIndexes) !== null && _17 !== void 0 ? _17 : [], (_18 = config.spotMarketIndexes) !== null && _18 !== void 0 ? _18 : [], (_19 = config.oracleInfos) !== null && _19 !== void 0 ? _19 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
222
- resubTimeoutMs: (_20 = config.accountSubscription) === null || _20 === void 0 ? void 0 : _20.resubTimeoutMs,
223
- logResubMessages: (_21 = config.accountSubscription) === null || _21 === void 0 ? void 0 : _21.logResubMessages,
224
- }, (_22 = config.accountSubscription) === null || _22 === void 0 ? void 0 : _22.commitment, (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.perpMarketAccountSubscriber, (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.oracleAccountSubscriber);
222
+ const accountSubscriberClass = (_19 = (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.driftClientAccountSubscriber) !== null && _19 !== void 0 ? _19 : webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber;
223
+ this.accountSubscriber = new accountSubscriberClass(this.program, (_20 = config.perpMarketIndexes) !== null && _20 !== void 0 ? _20 : [], (_21 = config.spotMarketIndexes) !== null && _21 !== void 0 ? _21 : [], (_22 = config.oracleInfos) !== null && _22 !== void 0 ? _22 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
224
+ resubTimeoutMs: (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.resubTimeoutMs,
225
+ logResubMessages: (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.logResubMessages,
226
+ }, (_25 = config.accountSubscription) === null || _25 === void 0 ? void 0 : _25.commitment);
225
227
  }
226
228
  this.eventEmitter = this.accountSubscriber.eventEmitter;
227
229
  this.metricsEventEmitter = new events_1.EventEmitter();
@@ -229,7 +231,7 @@ class DriftClient {
229
231
  this.enableMetricsEvents = true;
230
232
  }
231
233
  this.txSender =
232
- (_25 = config.txSender) !== null && _25 !== void 0 ? _25 : new retryTxSender_1.RetryTxSender({
234
+ (_26 = config.txSender) !== null && _26 !== void 0 ? _26 : new retryTxSender_1.RetryTxSender({
233
235
  connection: this.connection,
234
236
  wallet: this.wallet,
235
237
  opts: this.opts,
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { Commitment, ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
4
- import { IWallet, TxParams } from './types';
4
+ import { IWallet, TxParams, UserAccount } from './types';
5
5
  import { OracleInfo } from './oracles/types';
6
6
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
7
7
  import { DriftEnv } from './config';
@@ -14,6 +14,9 @@ import { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscri
14
14
  import { grpcDriftClientAccountSubscriberV2 } from './accounts/grpcDriftClientAccountSubscriberV2';
15
15
  import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
16
16
  import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
17
+ import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
18
+ import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDriftClientAccountSubscriber';
19
+ import { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
17
20
  export type DriftClientConfig = {
18
21
  connection: Connection;
19
22
  wallet: IWallet;
@@ -56,8 +59,10 @@ export type DriftClientSubscriptionConfig = {
56
59
  resubTimeoutMs?: number;
57
60
  logResubMessages?: boolean;
58
61
  commitment?: Commitment;
62
+ programUserAccountSubscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
59
63
  perpMarketAccountSubscriber?: new (accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, commitment?: Commitment) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
60
- oracleAccountSubscriber?: new (accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, commitment?: Commitment) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
64
+ /** If you use V2 here, whatever you pass for perpMarketAccountSubscriber will be ignored and it will use v2 under the hood regardless */
65
+ driftClientAccountSubscriber?: new (program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting) => WebSocketDriftClientAccountSubscriber | WebSocketDriftClientAccountSubscriberV2;
61
66
  } | {
62
67
  type: 'polling';
63
68
  accountLoader: BulkAccountLoader;
@@ -11,6 +11,10 @@ export * from './accounts/webSocketDriftClientAccountSubscriber';
11
11
  export * from './accounts/webSocketInsuranceFundStakeAccountSubscriber';
12
12
  export * from './accounts/webSocketHighLeverageModeConfigAccountSubscriber';
13
13
  export { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscriberV2';
14
+ export { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
15
+ export { WebSocketProgramUserAccountSubscriber } from './accounts/websocketProgramUserAccountSubscriber';
16
+ export { WebSocketProgramAccountsSubscriberV2 } from './accounts/webSocketProgramAccountsSubscriberV2';
17
+ export { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
14
18
  export * from './accounts/bulkAccountLoader';
15
19
  export * from './accounts/bulkUserSubscription';
16
20
  export * from './accounts/bulkUserStatsSubscription';
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.pyth = exports.PublicKey = exports.BN = exports.CustomizedCadenceBulkAccountLoader = exports.WebSocketAccountSubscriberV2 = void 0;
20
+ exports.pyth = exports.PublicKey = exports.BN = exports.CustomizedCadenceBulkAccountLoader = exports.WebSocketDriftClientAccountSubscriberV2 = exports.WebSocketProgramAccountsSubscriberV2 = exports.WebSocketProgramUserAccountSubscriber = exports.WebSocketProgramAccountSubscriber = exports.WebSocketAccountSubscriberV2 = void 0;
21
21
  const anchor_1 = require("@coral-xyz/anchor");
22
22
  Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return anchor_1.BN; } });
23
23
  const web3_js_1 = require("@solana/web3.js");
@@ -35,6 +35,14 @@ __exportStar(require("./accounts/webSocketInsuranceFundStakeAccountSubscriber"),
35
35
  __exportStar(require("./accounts/webSocketHighLeverageModeConfigAccountSubscriber"), exports);
36
36
  var webSocketAccountSubscriberV2_1 = require("./accounts/webSocketAccountSubscriberV2");
37
37
  Object.defineProperty(exports, "WebSocketAccountSubscriberV2", { enumerable: true, get: function () { return webSocketAccountSubscriberV2_1.WebSocketAccountSubscriberV2; } });
38
+ var webSocketProgramAccountSubscriber_1 = require("./accounts/webSocketProgramAccountSubscriber");
39
+ Object.defineProperty(exports, "WebSocketProgramAccountSubscriber", { enumerable: true, get: function () { return webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber; } });
40
+ var websocketProgramUserAccountSubscriber_1 = require("./accounts/websocketProgramUserAccountSubscriber");
41
+ Object.defineProperty(exports, "WebSocketProgramUserAccountSubscriber", { enumerable: true, get: function () { return websocketProgramUserAccountSubscriber_1.WebSocketProgramUserAccountSubscriber; } });
42
+ var webSocketProgramAccountsSubscriberV2_1 = require("./accounts/webSocketProgramAccountsSubscriberV2");
43
+ Object.defineProperty(exports, "WebSocketProgramAccountsSubscriberV2", { enumerable: true, get: function () { return webSocketProgramAccountsSubscriberV2_1.WebSocketProgramAccountsSubscriberV2; } });
44
+ var webSocketDriftClientAccountSubscriberV2_1 = require("./accounts/webSocketDriftClientAccountSubscriberV2");
45
+ Object.defineProperty(exports, "WebSocketDriftClientAccountSubscriberV2", { enumerable: true, get: function () { return webSocketDriftClientAccountSubscriberV2_1.WebSocketDriftClientAccountSubscriberV2; } });
38
46
  __exportStar(require("./accounts/bulkAccountLoader"), exports);
39
47
  __exportStar(require("./accounts/bulkUserSubscription"), exports);
40
48
  __exportStar(require("./accounts/bulkUserStatsSubscription"), exports);
@@ -1191,6 +1191,8 @@ export type PerpPosition = {
1191
1191
  lastBaseAssetAmountPerLp: BN;
1192
1192
  lastQuoteAssetAmountPerLp: BN;
1193
1193
  perLpBase: number;
1194
+ isolatedPositionScaledBalance: BN;
1195
+ positionFlag: number;
1194
1196
  };
1195
1197
  export type UserStatsAccount = {
1196
1198
  numberOfSubAccounts: number;
@@ -186,6 +186,8 @@ class User {
186
186
  lastQuoteAssetAmountPerLp: numericConstants_1.ZERO,
187
187
  perLpBase: 0,
188
188
  maxMarginRatio: 0,
189
+ isolatedPositionScaledBalance: numericConstants_1.ZERO,
190
+ positionFlag: 0,
189
191
  };
190
192
  }
191
193
  getClonedPosition(position) {
@@ -3,17 +3,75 @@
3
3
  import { BufferAndSlot, ProgramAccountSubscriber, ResubOpts } from './types';
4
4
  import { Program } from '@coral-xyz/anchor';
5
5
  import { Commitment, Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
6
- import { AccountInfoBase, AccountInfoWithBase58EncodedData, AccountInfoWithBase64EncodedData } from 'gill';
7
- export declare class WebSocketProgramAccountSubscriberV2<T> implements ProgramAccountSubscriber<T> {
6
+ import { AccountInfoBase, AccountInfoWithBase58EncodedData, AccountInfoWithBase64EncodedData, Address } from 'gill';
7
+ /**
8
+ * WebSocketProgramAccountsSubscriberV2
9
+ *
10
+ * High-level overview
11
+ * - WebSocket-first subscriber for Solana program accounts that also layers in
12
+ * targeted polling to detect missed updates reliably.
13
+ * - Emits decoded account updates via the provided `onChange` callback.
14
+ * - Designed to focus extra work on the specific accounts the consumer cares
15
+ * about ("monitored accounts") while keeping baseline WS behavior for the
16
+ * full program subscription.
17
+ *
18
+ * Why polling if this is a WebSocket subscriber?
19
+ * - WS infra can stall, drop, or reorder notifications under network stress or
20
+ * provider hiccups. When that happens, critical account changes can be missed.
21
+ * - To mitigate this, the class accepts a set of accounts (provided via constructor) to monitor
22
+ * and uses light polling to verify whether a WS change was missed.
23
+ * - If polling detects a newer slot with different data than the last seen
24
+ * buffer, a centralized resubscription is triggered to restore a clean stream.
25
+ *
26
+ * Initial fetch (on subscribe)
27
+ * - On `subscribe()`, we first perform a single batched fetch of all monitored
28
+ * accounts ("initial monitor fetch").
29
+ * - Purpose: seed the internal `bufferAndSlotMap` and emit the latest state so
30
+ * consumers have up-to-date data immediately, even before WS events arrive.
31
+ * - This step does not decide resubscription; it only establishes ground truth.
32
+ *
33
+ * Continuous polling (only for monitored accounts)
34
+ * - After seeding, each monitored account is put into a monitoring cycle:
35
+ * 1) If no WS notification for an account is observed for `pollingIntervalMs`,
36
+ * we enqueue it for a batched fetch (buffered for a short window).
37
+ * 2) Once an account enters the "currently polling" set, a shared batch poll
38
+ * runs every `pollingIntervalMs` across all such accounts.
39
+ * 3) If WS notifications resume for an account, that account is removed from
40
+ * the polling set and returns to passive monitoring.
41
+ * - Polling compares the newly fetched buffer with the last stored buffer at a
42
+ * later slot. A difference indicates a missed update; we schedule a single
43
+ * resubscription (coalesced across accounts) to re-sync.
44
+ *
45
+ * Accounts the consumer cares about
46
+ * - Provide accounts up-front via the constructor `accountsToMonitor`, or add
47
+ * them dynamically with `addAccountToMonitor()` and remove with
48
+ * `removeAccountFromMonitor()`.
49
+ * - Only these accounts incur additional polling safeguards; other accounts are
50
+ * still processed from the WS stream normally.
51
+ *
52
+ * Resubscription strategy
53
+ * - Missed updates from any monitored account are coalesced and trigger a single
54
+ * resubscription after a short delay. This avoids rapid churn.
55
+ * - If `resubOpts.resubTimeoutMs` is set, an inactivity timer also performs a
56
+ * batch check of monitored accounts. If a missed update is found, the same
57
+ * centralized resubscription flow is used.
58
+ *
59
+ * Tuning knobs
60
+ * - `setPollingInterval(ms)`: adjust how often monitoring/polling runs
61
+ * (default 30s). Shorter = faster detection, higher RPC load.
62
+ * - Debounced immediate poll (~100ms): batches accounts added to polling right after inactivity.
63
+ * - Batch size for `getMultipleAccounts` is limited to 100, requests are chunked
64
+ * and processed concurrently.
65
+ */
66
+ export declare class WebSocketProgramAccountsSubscriberV2<T> implements ProgramAccountSubscriber<T> {
8
67
  subscriptionName: string;
9
68
  accountDiscriminator: string;
10
- bufferAndSlot?: BufferAndSlot;
11
69
  bufferAndSlotMap: Map<string, BufferAndSlot>;
12
70
  program: Program;
13
71
  decodeBuffer: (accountName: string, ix: Buffer) => T;
14
72
  onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void;
15
73
  listenerId?: number;
16
- resubOpts?: ResubOpts;
74
+ resubOpts: ResubOpts;
17
75
  isUnsubscribing: boolean;
18
76
  timeoutId?: ReturnType<typeof setTimeout>;
19
77
  options: {
@@ -30,25 +88,59 @@ export declare class WebSocketProgramAccountSubscriberV2<T> implements ProgramAc
30
88
  private lastWsNotificationTime;
31
89
  private accountsCurrentlyPolling;
32
90
  private batchPollingTimeout?;
91
+ private debouncedImmediatePollTimeout?;
92
+ private debouncedImmediatePollMs;
93
+ private missedChangeDetected;
94
+ private resubscriptionTimeout?;
95
+ private accountsWithMissedUpdates;
33
96
  constructor(subscriptionName: string, accountDiscriminator: string, program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => T, options?: {
34
97
  filters: MemcmpFilter[];
35
98
  commitment?: Commitment;
36
99
  }, resubOpts?: ResubOpts, accountsToMonitor?: PublicKey[]);
100
+ private handleNotificationLoop;
37
101
  subscribe(onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
38
102
  protected setTimeout(): void;
39
103
  handleRpcResponse(context: {
40
104
  slot: bigint;
41
- }, accountInfo?: AccountInfoBase & (AccountInfoWithBase58EncodedData | AccountInfoWithBase64EncodedData)): void;
105
+ }, accountId: Address, accountInfo?: AccountInfoBase & (AccountInfoWithBase58EncodedData | AccountInfoWithBase64EncodedData)['data']): void;
42
106
  private startMonitoringForAccounts;
43
107
  private startMonitoringForAccount;
44
- private startPollingForAccount;
108
+ private scheduleDebouncedImmediatePoll;
45
109
  private startBatchPolling;
46
110
  private pollAllAccounts;
47
- private pollAccount;
111
+ /**
112
+ * Fetches and populates all monitored accounts data without checking for missed changes
113
+ * This is used during initial subscription to populate data
114
+ */
115
+ private fetchAndPopulateAllMonitoredAccounts;
116
+ /**
117
+ * Fetches all monitored accounts and checks for missed changes
118
+ * Returns true if a missed change was detected and resubscription is needed
119
+ */
120
+ private fetchAllMonitoredAccounts;
121
+ private fetchAccountsBatch;
48
122
  private clearPollingTimeouts;
123
+ /**
124
+ * Centralized resubscription handler that only resubscribes once after checking all accounts
125
+ */
126
+ private handleResubscription;
127
+ /**
128
+ * Signal that a missed change was detected and schedule resubscription
129
+ */
130
+ private signalMissedChange;
49
131
  unsubscribe(onResub?: boolean): Promise<void>;
132
+ /**
133
+ * Add an account to the monitored set.
134
+ * - Monitored accounts are subject to initial fetch and periodic batch polls
135
+ * if WS notifications are not observed within `pollingIntervalMs`.
136
+ */
50
137
  addAccountToMonitor(accountId: PublicKey): void;
51
138
  removeAccountFromMonitor(accountId: PublicKey): void;
139
+ /**
140
+ * Set the monitoring/polling interval for monitored accounts.
141
+ * Shorter intervals detect missed updates sooner but increase RPC load.
142
+ */
52
143
  setPollingInterval(intervalMs: number): void;
144
+ private updateBufferAndHandleChange;
53
145
  }
54
146
  //# sourceMappingURL=webSocketProgramAccountSubscriberV2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webSocketProgramAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/webSocketProgramAccountSubscriberV2.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa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