@drift-labs/sdk 2.144.0-beta.4 → 2.144.0-beta.6

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.
Files changed (37) hide show
  1. package/VERSION +1 -1
  2. package/bun.lock +3 -0
  3. package/lib/browser/accounts/grpcMultiAccountSubscriber.js +1 -0
  4. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +25 -0
  5. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.js +196 -0
  6. package/lib/browser/driftClient.js +26 -25
  7. package/lib/browser/driftClientConfig.d.ts +2 -0
  8. package/lib/browser/index.d.ts +1 -0
  9. package/lib/browser/index.js +3 -1
  10. package/lib/browser/user.js +10 -4
  11. package/lib/browser/userConfig.d.ts +2 -0
  12. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  13. package/lib/node/accounts/grpcMultiAccountSubscriber.js +1 -0
  14. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +26 -0
  15. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -0
  16. package/lib/node/accounts/grpcMultiUserAccountSubscriber.js +196 -0
  17. package/lib/node/driftClient.d.ts.map +1 -1
  18. package/lib/node/driftClient.js +26 -25
  19. package/lib/node/driftClientConfig.d.ts +2 -0
  20. package/lib/node/driftClientConfig.d.ts.map +1 -1
  21. package/lib/node/index.d.ts +1 -0
  22. package/lib/node/index.d.ts.map +1 -1
  23. package/lib/node/index.js +3 -1
  24. package/lib/node/user.d.ts.map +1 -1
  25. package/lib/node/user.js +10 -4
  26. package/lib/node/userConfig.d.ts +2 -0
  27. package/lib/node/userConfig.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/scripts/grpc-multiuser-client-test-comparison.ts +156 -0
  30. package/scripts/single-grpc-client-test.ts +20 -10
  31. package/src/accounts/grpcMultiAccountSubscriber.ts +1 -0
  32. package/src/accounts/grpcMultiUserAccountSubscriber.ts +274 -0
  33. package/src/driftClient.ts +2 -0
  34. package/src/driftClientConfig.ts +2 -0
  35. package/src/index.ts +1 -0
  36. package/src/user.ts +16 -9
  37. package/src/userConfig.ts +2 -0
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.144.0-beta.4
1
+ 2.144.0-beta.6
package/bun.lock CHANGED
@@ -8,6 +8,7 @@
8
8
  "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1",
9
9
  "@ellipsis-labs/phoenix-sdk": "1.4.5",
10
10
  "@grpc/grpc-js": "1.14.0",
11
+ "@msgpack/msgpack": "^3.1.2",
11
12
  "@openbook-dex/openbook-v2": "0.2.10",
12
13
  "@project-serum/serum": "0.13.65",
13
14
  "@pythnetwork/client": "2.5.3",
@@ -147,6 +148,8 @@
147
148
 
148
149
  "@metaplex-foundation/solita": ["@metaplex-foundation/solita@0.12.2", "", { "dependencies": { "@metaplex-foundation/beet": "^0.4.0", "@metaplex-foundation/beet-solana": "^0.3.0", "@metaplex-foundation/rustbin": "^0.3.0", "@solana/web3.js": "^1.36.0", "camelcase": "^6.2.1", "debug": "^4.3.3", "js-sha256": "^0.9.0", "prettier": "^2.5.1", "snake-case": "^3.0.4", "spok": "^1.4.3" }, "bin": { "solita": "dist/src/cli/solita.js" } }, "sha512-oczMfE43NNHWweSqhXPTkQBUbap/aAiwjDQw8zLKNnd/J8sXr/0+rKcN5yJIEgcHeKRkp90eTqkmt2WepQc8yw=="],
149
150
 
151
+ "@msgpack/msgpack": ["@msgpack/msgpack@3.1.2", "", {}, "sha512-JEW4DEtBzfe8HvUYecLU9e6+XJnKDlUAIve8FvPzF3Kzs6Xo/KuZkZJsDH0wJXl/qEZbeeE7edxDNY3kMs39hQ=="],
152
+
150
153
  "@noble/curves": ["@noble/curves@1.8.1", "", { "dependencies": { "@noble/hashes": "1.7.1" } }, "sha512-warwspo+UYUPep0Q+vtdVB4Ugn8GGQj8iyB3gnRWsztmUHTI3S1nhdiWNsPUGL0vud7JlRRk1XEu7Lq1KGTnMQ=="],
151
154
 
152
155
  "@noble/ed25519": ["@noble/ed25519@1.7.3", "", {}, "sha512-iR8GBkDt0Q3GyaVcIu7mSsVIqnFbkbRzGLWlvhwunacoLwt4J3swfKhfaM6rN6WY+TBGoYT1GtT1mIh2/jGbRQ=="],
@@ -277,6 +277,7 @@ class grpcMultiAccountSubscriber {
277
277
  }
278
278
  });
279
279
  });
280
+ await this.fetch();
280
281
  }
281
282
  async removeAccounts(accounts) {
282
283
  for (const pk of accounts) {
@@ -0,0 +1,25 @@
1
+ import { GrpcConfigs, ResubOpts, UserAccountSubscriber } from './types';
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import { UserAccount } from '../types';
5
+ import { grpcMultiAccountSubscriber } from './grpcMultiAccountSubscriber';
6
+ export declare class grpcMultiUserAccountSubscriber {
7
+ private program;
8
+ private multiSubscriber;
9
+ private userData;
10
+ private listeners;
11
+ private keyToPk;
12
+ private pendingAddKeys;
13
+ private debounceTimer?;
14
+ private debounceMs;
15
+ private isMultiSubscribed;
16
+ private userAccountSubscribers;
17
+ private grpcConfigs;
18
+ resubOpts?: ResubOpts;
19
+ private handleAccountChange;
20
+ constructor(program: Program, grpcConfigs: GrpcConfigs, resubOpts?: ResubOpts, multiSubscriber?: grpcMultiAccountSubscriber<UserAccount>);
21
+ subscribe(): Promise<void>;
22
+ forUser(userAccountPublicKey: PublicKey): UserAccountSubscriber;
23
+ private scheduleFlush;
24
+ private flushPending;
25
+ }
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.grpcMultiUserAccountSubscriber = void 0;
4
+ const types_1 = require("./types");
5
+ const events_1 = require("events");
6
+ const web3_js_1 = require("@solana/web3.js");
7
+ const grpcMultiAccountSubscriber_1 = require("./grpcMultiAccountSubscriber");
8
+ class grpcMultiUserAccountSubscriber {
9
+ constructor(program, grpcConfigs, resubOpts, multiSubscriber) {
10
+ this.userData = new Map();
11
+ this.listeners = new Map();
12
+ this.keyToPk = new Map();
13
+ this.pendingAddKeys = new Set();
14
+ this.debounceMs = 20;
15
+ this.isMultiSubscribed = false;
16
+ this.userAccountSubscribers = new Map();
17
+ this.handleAccountChange = (accountId, data, context, _buffer, _accountProps) => {
18
+ const k = accountId.toBase58();
19
+ this.userData.set(k, { data, slot: context.slot });
20
+ const setForKey = this.listeners.get(k);
21
+ if (setForKey) {
22
+ for (const emitter of setForKey) {
23
+ emitter.emit('userAccountUpdate', data);
24
+ emitter.emit('update');
25
+ }
26
+ }
27
+ };
28
+ this.program = program;
29
+ this.multiSubscriber = multiSubscriber;
30
+ this.grpcConfigs = grpcConfigs;
31
+ this.resubOpts = resubOpts;
32
+ }
33
+ async subscribe() {
34
+ if (!this.multiSubscriber) {
35
+ this.multiSubscriber =
36
+ await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'user', this.program, undefined, this.resubOpts);
37
+ }
38
+ // Subscribe all per-user subscribers first
39
+ await Promise.all(Array.from(this.userAccountSubscribers.values()).map((subscriber) => subscriber.subscribe()));
40
+ // Ensure we immediately register any pending keys and kick off underlying subscription/fetch
41
+ await this.flushPending();
42
+ // Proactively fetch once to populate data for all subscribed accounts
43
+ await this.multiSubscriber.fetch();
44
+ // Wait until the underlying multi-subscriber has data for every registered user key
45
+ const targetKeys = Array.from(this.listeners.keys());
46
+ if (targetKeys.length === 0)
47
+ return;
48
+ // Poll until all keys are present in dataMap
49
+ // Use debounceMs as the polling cadence to avoid introducing new magic numbers
50
+ // eslint-disable-next-line no-constant-condition
51
+ while (true) {
52
+ const map = this.multiSubscriber.getAccountDataMap();
53
+ let allPresent = true;
54
+ for (const k of targetKeys) {
55
+ if (!map.has(k)) {
56
+ allPresent = false;
57
+ break;
58
+ }
59
+ }
60
+ if (allPresent)
61
+ break;
62
+ await new Promise((resolve) => setTimeout(resolve, this.debounceMs));
63
+ }
64
+ }
65
+ forUser(userAccountPublicKey) {
66
+ if (this.userAccountSubscribers.has(userAccountPublicKey.toBase58())) {
67
+ return this.userAccountSubscribers.get(userAccountPublicKey.toBase58());
68
+ }
69
+ const key = userAccountPublicKey.toBase58();
70
+ const perUserEmitter = new events_1.EventEmitter();
71
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
72
+ const parent = this;
73
+ let isSubscribed = false;
74
+ const registerHandlerIfNeeded = async () => {
75
+ if (!this.listeners.has(key)) {
76
+ this.listeners.set(key, new Set());
77
+ this.keyToPk.set(key, userAccountPublicKey);
78
+ this.pendingAddKeys.add(key);
79
+ this.scheduleFlush();
80
+ }
81
+ };
82
+ const perUser = {
83
+ get eventEmitter() {
84
+ return perUserEmitter;
85
+ },
86
+ set eventEmitter(_v) { },
87
+ get isSubscribed() {
88
+ return isSubscribed;
89
+ },
90
+ set isSubscribed(_v) {
91
+ isSubscribed = _v;
92
+ },
93
+ async subscribe(userAccount) {
94
+ if (isSubscribed)
95
+ return true;
96
+ if (userAccount) {
97
+ this.updateData(userAccount, 0);
98
+ }
99
+ await registerHandlerIfNeeded();
100
+ const setForKey = parent.listeners.get(key);
101
+ setForKey.add(perUserEmitter);
102
+ isSubscribed = true;
103
+ return true;
104
+ },
105
+ async fetch() {
106
+ if (!isSubscribed) {
107
+ throw new types_1.NotSubscribedError('Must subscribe before fetching account updates');
108
+ }
109
+ const account = (await parent.program.account.user.fetch(userAccountPublicKey));
110
+ this.updateData(account, 0);
111
+ },
112
+ updateData(userAccount, slot) {
113
+ parent.userData.set(key, { data: userAccount, slot });
114
+ perUserEmitter.emit('userAccountUpdate', userAccount);
115
+ perUserEmitter.emit('update');
116
+ },
117
+ async unsubscribe() {
118
+ if (!isSubscribed)
119
+ return;
120
+ const setForKey = parent.listeners.get(key);
121
+ if (setForKey) {
122
+ setForKey.delete(perUserEmitter);
123
+ if (setForKey.size === 0) {
124
+ parent.listeners.delete(key);
125
+ await parent.multiSubscriber.removeAccounts([userAccountPublicKey]);
126
+ parent.userData.delete(key);
127
+ parent.keyToPk.delete(key);
128
+ parent.pendingAddKeys.delete(key);
129
+ }
130
+ }
131
+ isSubscribed = false;
132
+ },
133
+ getUserAccountAndSlot() {
134
+ const das = parent.userData.get(key);
135
+ if (!das) {
136
+ throw new types_1.NotSubscribedError('Must subscribe before getting user account data');
137
+ }
138
+ return das;
139
+ },
140
+ };
141
+ this.userAccountSubscribers.set(userAccountPublicKey.toBase58(), perUser);
142
+ return perUser;
143
+ }
144
+ scheduleFlush() {
145
+ if (this.debounceTimer)
146
+ return;
147
+ this.debounceTimer = setTimeout(() => {
148
+ void this.flushPending();
149
+ }, this.debounceMs);
150
+ }
151
+ async flushPending() {
152
+ const hasPending = this.pendingAddKeys.size > 0;
153
+ if (!hasPending) {
154
+ this.debounceTimer = undefined;
155
+ return;
156
+ }
157
+ const allPks = [];
158
+ for (const k of this.listeners.keys()) {
159
+ const pk = this.keyToPk.get(k);
160
+ if (pk)
161
+ allPks.push(pk);
162
+ }
163
+ if (allPks.length === 0) {
164
+ this.pendingAddKeys.clear();
165
+ this.debounceTimer = undefined;
166
+ return;
167
+ }
168
+ if (!this.isMultiSubscribed) {
169
+ await this.multiSubscriber.subscribe(allPks, this.handleAccountChange);
170
+ this.isMultiSubscribed = true;
171
+ await this.multiSubscriber.fetch();
172
+ for (const k of this.pendingAddKeys) {
173
+ const pk = this.keyToPk.get(k);
174
+ if (pk) {
175
+ const data = this.multiSubscriber.getAccountData(k);
176
+ if (data) {
177
+ this.handleAccountChange(pk, data.data, { slot: data.slot }, undefined, undefined);
178
+ }
179
+ }
180
+ }
181
+ }
182
+ else {
183
+ const ms = this.multiSubscriber;
184
+ for (const k of this.pendingAddKeys) {
185
+ ms.onChangeMap.set(k, (data, ctx, buffer, accountProps) => {
186
+ this.multiSubscriber.setAccountData(k, data, ctx.slot);
187
+ this.handleAccountChange(new web3_js_1.PublicKey(k), data, ctx, buffer, accountProps);
188
+ });
189
+ }
190
+ await this.multiSubscriber.addAccounts(allPks);
191
+ }
192
+ this.pendingAddKeys.clear();
193
+ this.debounceTimer = undefined;
194
+ }
195
+ }
196
+ exports.grpcMultiUserAccountSubscriber = grpcMultiUserAccountSubscriber;
@@ -88,7 +88,7 @@ class DriftClient {
88
88
  this._isSubscribed = val;
89
89
  }
90
90
  constructor(config) {
91
- 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;
91
+ 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;
92
92
  this.users = new Map();
93
93
  this._isSubscribed = false;
94
94
  this.perpMarketLastSlotCache = new Map();
@@ -164,27 +164,28 @@ class DriftClient {
164
164
  resubTimeoutMs: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.resubTimeoutMs,
165
165
  logResubMessages: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.logResubMessages,
166
166
  grpcConfigs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.grpcConfigs,
167
+ grpcMultiUserAccountSubscriber: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.grpcMultiUserAccountSubscriber,
167
168
  };
168
169
  this.userStatsAccountSubscriptionConfig = {
169
170
  type: 'grpc',
170
- grpcConfigs: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.grpcConfigs,
171
- resubTimeoutMs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.resubTimeoutMs,
172
- logResubMessages: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.logResubMessages,
171
+ grpcConfigs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.grpcConfigs,
172
+ resubTimeoutMs: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.resubTimeoutMs,
173
+ logResubMessages: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.logResubMessages,
173
174
  };
174
175
  }
175
176
  else {
176
177
  this.userAccountSubscriptionConfig = {
177
178
  type: 'websocket',
178
- resubTimeoutMs: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.resubTimeoutMs,
179
- logResubMessages: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.logResubMessages,
180
- commitment: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.commitment,
181
- programUserAccountSubscriber: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.programUserAccountSubscriber,
179
+ resubTimeoutMs: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.resubTimeoutMs,
180
+ logResubMessages: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.logResubMessages,
181
+ commitment: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.commitment,
182
+ programUserAccountSubscriber: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.programUserAccountSubscriber,
182
183
  };
183
184
  this.userStatsAccountSubscriptionConfig = {
184
185
  type: 'websocket',
185
- resubTimeoutMs: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.resubTimeoutMs,
186
- logResubMessages: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.logResubMessages,
187
- commitment: (_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.commitment,
186
+ resubTimeoutMs: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.resubTimeoutMs,
187
+ logResubMessages: (_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.logResubMessages,
188
+ commitment: (_5 = config.accountSubscription) === null || _5 === void 0 ? void 0 : _5.commitment,
188
189
  };
189
190
  }
190
191
  if (config.userStats) {
@@ -206,22 +207,22 @@ class DriftClient {
206
207
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
207
208
  config.spotMarketIndexes === undefined &&
208
209
  config.oracleInfos === undefined;
209
- if (((_5 = config.accountSubscription) === null || _5 === void 0 ? void 0 : _5.type) === 'polling') {
210
- 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);
211
- }
212
- else if (((_9 = config.accountSubscription) === null || _9 === void 0 ? void 0 : _9.type) === 'grpc') {
213
- const accountSubscriberClass = (_11 = (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.driftClientAccountSubscriber) !== null && _11 !== void 0 ? _11 : grpcDriftClientAccountSubscriber_1.grpcDriftClientAccountSubscriber;
214
- 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, {
215
- resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
216
- logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
210
+ if (((_6 = config.accountSubscription) === null || _6 === void 0 ? void 0 : _6.type) === 'polling') {
211
+ 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);
212
+ }
213
+ else if (((_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.type) === 'grpc') {
214
+ const accountSubscriberClass = (_12 = (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.driftClientAccountSubscriber) !== null && _12 !== void 0 ? _12 : grpcDriftClientAccountSubscriber_1.grpcDriftClientAccountSubscriber;
215
+ 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, {
216
+ resubTimeoutMs: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.resubTimeoutMs,
217
+ logResubMessages: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.logResubMessages,
217
218
  });
218
219
  }
219
220
  else {
220
- const accountSubscriberClass = (_18 = (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.driftClientAccountSubscriber) !== null && _18 !== void 0 ? _18 : webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber;
221
- this.accountSubscriber = new accountSubscriberClass(this.program, (_19 = config.perpMarketIndexes) !== null && _19 !== void 0 ? _19 : [], (_20 = config.spotMarketIndexes) !== null && _20 !== void 0 ? _20 : [], (_21 = config.oracleInfos) !== null && _21 !== void 0 ? _21 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
222
- resubTimeoutMs: (_22 = config.accountSubscription) === null || _22 === void 0 ? void 0 : _22.resubTimeoutMs,
223
- logResubMessages: (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.logResubMessages,
224
- }, (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.commitment);
221
+ const accountSubscriberClass = (_19 = (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.driftClientAccountSubscriber) !== null && _19 !== void 0 ? _19 : webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber;
222
+ 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, {
223
+ resubTimeoutMs: (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.resubTimeoutMs,
224
+ logResubMessages: (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.logResubMessages,
225
+ }, (_25 = config.accountSubscription) === null || _25 === void 0 ? void 0 : _25.commitment);
225
226
  }
226
227
  this.eventEmitter = this.accountSubscriber.eventEmitter;
227
228
  this.metricsEventEmitter = new events_1.EventEmitter();
@@ -229,7 +230,7 @@ class DriftClient {
229
230
  this.enableMetricsEvents = true;
230
231
  }
231
232
  this.txSender =
232
- (_25 = config.txSender) !== null && _25 !== void 0 ? _25 : new retryTxSender_1.RetryTxSender({
233
+ (_26 = config.txSender) !== null && _26 !== void 0 ? _26 : new retryTxSender_1.RetryTxSender({
233
234
  connection: this.connection,
234
235
  wallet: this.wallet,
235
236
  opts: this.opts,
@@ -16,6 +16,7 @@ import { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDri
16
16
  import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDriftClientAccountSubscriber';
17
17
  import { grpcDriftClientAccountSubscriberV2 } from './accounts/grpcDriftClientAccountSubscriberV2';
18
18
  import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
19
+ import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
19
20
  export type DriftClientConfig = {
20
21
  connection: Connection;
21
22
  wallet: IWallet;
@@ -52,6 +53,7 @@ export type DriftClientSubscriptionConfig = {
52
53
  resubTimeoutMs?: number;
53
54
  logResubMessages?: boolean;
54
55
  driftClientAccountSubscriber?: new (grpcConfigs: GrpcConfigs, program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting) => grpcDriftClientAccountSubscriberV2 | grpcDriftClientAccountSubscriber;
56
+ grpcMultiUserAccountSubscriber?: grpcMultiUserAccountSubscriber;
55
57
  } | {
56
58
  type: 'websocket';
57
59
  resubTimeoutMs?: number;
@@ -52,6 +52,7 @@ export * from './events/webSocketLogProvider';
52
52
  export * from './events/parse';
53
53
  export * from './events/pollingLogProvider';
54
54
  export * from './jupiter/jupiterClient';
55
+ export { TitanClient } from './titan/titanClient';
55
56
  export * from './math/auction';
56
57
  export * from './math/builder';
57
58
  export * from './math/spotMarket';
@@ -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.WebSocketDriftClientAccountSubscriberV2 = exports.WebSocketProgramAccountsSubscriberV2 = exports.WebSocketProgramUserAccountSubscriber = exports.WebSocketProgramAccountSubscriber = exports.WebSocketAccountSubscriberV2 = void 0;
20
+ exports.pyth = exports.PublicKey = exports.BN = exports.TitanClient = 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");
@@ -81,6 +81,8 @@ __exportStar(require("./events/webSocketLogProvider"), exports);
81
81
  __exportStar(require("./events/parse"), exports);
82
82
  __exportStar(require("./events/pollingLogProvider"), exports);
83
83
  __exportStar(require("./jupiter/jupiterClient"), exports);
84
+ var titanClient_1 = require("./titan/titanClient");
85
+ Object.defineProperty(exports, "TitanClient", { enumerable: true, get: function () { return titanClient_1.TitanClient; } });
84
86
  __exportStar(require("./math/auction"), exports);
85
87
  __exportStar(require("./math/builder"), exports);
86
88
  __exportStar(require("./math/spotMarket"), exports);
@@ -45,10 +45,16 @@ class User {
45
45
  this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
46
46
  }
47
47
  else if (((_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.type) === 'grpc') {
48
- this.accountSubscriber = new grpcUserAccountSubscriber_1.grpcUserAccountSubscriber(config.accountSubscription.grpcConfigs, config.driftClient.program, config.userAccountPublicKey, {
49
- resubTimeoutMs: (_d = config.accountSubscription) === null || _d === void 0 ? void 0 : _d.resubTimeoutMs,
50
- logResubMessages: (_e = config.accountSubscription) === null || _e === void 0 ? void 0 : _e.logResubMessages,
51
- });
48
+ if (config.accountSubscription.grpcMultiUserAccountSubscriber) {
49
+ this.accountSubscriber =
50
+ config.accountSubscription.grpcMultiUserAccountSubscriber.forUser(config.userAccountPublicKey);
51
+ }
52
+ else {
53
+ this.accountSubscriber = new grpcUserAccountSubscriber_1.grpcUserAccountSubscriber(config.accountSubscription.grpcConfigs, config.driftClient.program, config.userAccountPublicKey, {
54
+ resubTimeoutMs: (_d = config.accountSubscription) === null || _d === void 0 ? void 0 : _d.resubTimeoutMs,
55
+ logResubMessages: (_e = config.accountSubscription) === null || _e === void 0 ? void 0 : _e.logResubMessages,
56
+ });
57
+ }
52
58
  }
53
59
  else {
54
60
  if (((_f = config.accountSubscription) === null || _f === void 0 ? void 0 : _f.type) === 'websocket' &&
@@ -4,6 +4,7 @@ import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
4
  import { GrpcConfigs, UserAccountSubscriber } from './accounts/types';
5
5
  import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
6
6
  import { UserAccount } from './types';
7
+ import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
7
8
  export type UserConfig = {
8
9
  accountSubscription?: UserSubscriptionConfig;
9
10
  driftClient: DriftClient;
@@ -14,6 +15,7 @@ export type UserSubscriptionConfig = {
14
15
  resubTimeoutMs?: number;
15
16
  logResubMessages?: boolean;
16
17
  grpcConfigs: GrpcConfigs;
18
+ grpcMultiUserAccountSubscriber?: grpcMultiUserAccountSubscriber;
17
19
  } | {
18
20
  type: 'websocket';
19
21
  resubTimeoutMs?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"grpcMultiAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcMultiAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAc,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjE,OAAO,EACN,MAAM,EAMN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAiB,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAyB7E,qBAAa,0BAA0B,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS;IACvD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAwD;IACtE,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAC,CAIhB;IACP,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAC,CAAsB;IAErC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,UAAS;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAgC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AAO,CAAC,UAAU;IAelB,OAAO,CAAC,UAAU;CAIlB"}
@@ -277,6 +277,7 @@ class grpcMultiAccountSubscriber {
277
277
  }
278
278
  });
279
279
  });
280
+ await this.fetch();
280
281
  }
281
282
  async removeAccounts(accounts) {
282
283
  for (const pk of accounts) {
@@ -0,0 +1,26 @@
1
+ import { GrpcConfigs, ResubOpts, UserAccountSubscriber } from './types';
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import { UserAccount } from '../types';
5
+ import { grpcMultiAccountSubscriber } from './grpcMultiAccountSubscriber';
6
+ export declare class grpcMultiUserAccountSubscriber {
7
+ private program;
8
+ private multiSubscriber;
9
+ private userData;
10
+ private listeners;
11
+ private keyToPk;
12
+ private pendingAddKeys;
13
+ private debounceTimer?;
14
+ private debounceMs;
15
+ private isMultiSubscribed;
16
+ private userAccountSubscribers;
17
+ private grpcConfigs;
18
+ resubOpts?: ResubOpts;
19
+ private handleAccountChange;
20
+ constructor(program: Program, grpcConfigs: GrpcConfigs, resubOpts?: ResubOpts, multiSubscriber?: grpcMultiAccountSubscriber<UserAccount>);
21
+ subscribe(): Promise<void>;
22
+ forUser(userAccountPublicKey: PublicKey): UserAccountSubscriber;
23
+ private scheduleFlush;
24
+ private flushPending;
25
+ }
26
+ //# sourceMappingURL=grpcMultiUserAccountSubscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpcMultiUserAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcMultiUserAccountSubscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,WAAW,EAEX,SAAS,EAET,qBAAqB,EACrB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAW,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE1E,qBAAa,8BAA8B;IAC1C,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,eAAe,CAA0C;IAEjE,OAAO,CAAC,QAAQ,CAA+C;IAC/D,OAAO,CAAC,SAAS,CAGb;IACJ,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,aAAa,CAAC,CAAgC;IACtD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,sBAAsB,CAA4C;IAC1E,OAAO,CAAC,WAAW,CAAc;IACjC,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,OAAO,CAAC,mBAAmB,CAgBzB;gBAGD,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,SAAS,EACrB,eAAe,CAAC,EAAE,0BAA0B,CAAC,WAAW,CAAC;IAQ7C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IA0ChC,OAAO,CAAC,oBAAoB,EAAE,SAAS,GAAG,qBAAqB;IA8FtE,OAAO,CAAC,aAAa;YAOP,YAAY;CAmE1B"}