@drift-labs/sdk 2.48.0-beta.4 → 2.48.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.
- package/VERSION +1 -1
- package/lib/user.js +2 -2
- package/lib/userMap/userMap.d.ts +2 -0
- package/lib/userMap/userMap.js +18 -10
- package/package.json +1 -1
- package/src/user.ts +1 -1
- package/src/userMap/userMap.ts +33 -18
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.48.0-beta.
|
|
1
|
+
2.48.0-beta.6
|
package/lib/user.js
CHANGED
|
@@ -22,7 +22,7 @@ class User {
|
|
|
22
22
|
this._isSubscribed = val;
|
|
23
23
|
}
|
|
24
24
|
constructor(config) {
|
|
25
|
-
var _a, _b
|
|
25
|
+
var _a, _b;
|
|
26
26
|
this._isSubscribed = false;
|
|
27
27
|
this.driftClient = config.driftClient;
|
|
28
28
|
this.userAccountPublicKey = config.userAccountPublicKey;
|
|
@@ -32,7 +32,7 @@ class User {
|
|
|
32
32
|
else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === 'custom') {
|
|
33
33
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|
|
34
34
|
}
|
|
35
|
-
else
|
|
35
|
+
else {
|
|
36
36
|
this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey, config.accountSubscription.resubTimeoutMs, config.accountSubscription.commitment);
|
|
37
37
|
}
|
|
38
38
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
package/lib/userMap/userMap.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare class UserMap implements UserMapInterface {
|
|
|
35
35
|
* @param {SyncCallbackCriteria} syncCallbackCriteria - The criteria for the sync callback. Defaults to having no filters
|
|
36
36
|
*/
|
|
37
37
|
constructor(driftClient: DriftClient, accountSubscription: UserSubscriptionConfig, includeIdle?: boolean, syncCallback?: (authorities: PublicKey[]) => Promise<void>, syncCallbackCriteria?: SyncCallbackCriteria);
|
|
38
|
+
addSyncCallback(syncCallback?: (authorities: PublicKey[]) => Promise<void>, syncCallbackCriteria?: SyncCallbackCriteria): void;
|
|
38
39
|
subscribe(): Promise<void>;
|
|
39
40
|
addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount): Promise<void>;
|
|
40
41
|
has(key: string): boolean;
|
|
@@ -66,6 +67,7 @@ export declare class UserMap implements UserMapInterface {
|
|
|
66
67
|
updateWithEventRecord(record: WrappedEvent<any>): Promise<void>;
|
|
67
68
|
values(): IterableIterator<User>;
|
|
68
69
|
size(): number;
|
|
70
|
+
getUniqueAuthorities(useSyncCallbackCriteria?: boolean): PublicKey[];
|
|
69
71
|
sync(): Promise<void>;
|
|
70
72
|
unsubscribe(): Promise<void>;
|
|
71
73
|
}
|
package/lib/userMap/userMap.js
CHANGED
|
@@ -29,6 +29,10 @@ class UserMap {
|
|
|
29
29
|
this.syncCallback = syncCallback;
|
|
30
30
|
this.syncCallbackCriteria = syncCallbackCriteria;
|
|
31
31
|
}
|
|
32
|
+
addSyncCallback(syncCallback, syncCallbackCriteria = { hasOpenOrders: false }) {
|
|
33
|
+
this.syncCallback = syncCallback;
|
|
34
|
+
this.syncCallbackCriteria = syncCallbackCriteria;
|
|
35
|
+
}
|
|
32
36
|
async subscribe() {
|
|
33
37
|
if (this.size() > 0) {
|
|
34
38
|
return;
|
|
@@ -144,6 +148,19 @@ class UserMap {
|
|
|
144
148
|
size() {
|
|
145
149
|
return this.userMap.size;
|
|
146
150
|
}
|
|
151
|
+
getUniqueAuthorities(useSyncCallbackCriteria = true) {
|
|
152
|
+
const usersMeetingCriteria = Array.from(this.userMap.values()).filter((user) => {
|
|
153
|
+
let pass = true;
|
|
154
|
+
if (useSyncCallbackCriteria &&
|
|
155
|
+
this.syncCallbackCriteria.hasOpenOrders) {
|
|
156
|
+
pass = pass && user.getUserAccount().hasOpenOrder;
|
|
157
|
+
}
|
|
158
|
+
return pass;
|
|
159
|
+
});
|
|
160
|
+
const userAuths = new Set(usersMeetingCriteria.map((user) => user.getUserAccount().authority.toBase58()));
|
|
161
|
+
const userAuthKeys = Array.from(userAuths).map((userAuth) => new web3_js_1.PublicKey(userAuth));
|
|
162
|
+
return userAuthKeys;
|
|
163
|
+
}
|
|
147
164
|
async sync() {
|
|
148
165
|
if (this.syncPromise) {
|
|
149
166
|
return this.syncPromise;
|
|
@@ -193,16 +210,7 @@ class UserMap {
|
|
|
193
210
|
}
|
|
194
211
|
}
|
|
195
212
|
if (this.syncCallback) {
|
|
196
|
-
|
|
197
|
-
let pass = true;
|
|
198
|
-
if (this.syncCallbackCriteria.hasOpenOrders) {
|
|
199
|
-
pass = pass && user.getUserAccount().hasOpenOrder;
|
|
200
|
-
}
|
|
201
|
-
return pass;
|
|
202
|
-
});
|
|
203
|
-
const userAuths = new Set(usersMeetingCriteria.map((user) => user.getUserAccount().authority.toBase58()));
|
|
204
|
-
const userAuthKeys = Array.from(userAuths).map((userAuth) => new web3_js_1.PublicKey(userAuth));
|
|
205
|
-
await this.syncCallback(userAuthKeys);
|
|
213
|
+
await this.syncCallback(this.getUniqueAuthorities());
|
|
206
214
|
}
|
|
207
215
|
}
|
|
208
216
|
catch (e) {
|
package/package.json
CHANGED
package/src/user.ts
CHANGED
|
@@ -109,7 +109,7 @@ export class User {
|
|
|
109
109
|
);
|
|
110
110
|
} else if (config.accountSubscription?.type === 'custom') {
|
|
111
111
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|
|
112
|
-
} else
|
|
112
|
+
} else {
|
|
113
113
|
this.accountSubscriber = new WebSocketUserAccountSubscriber(
|
|
114
114
|
config.driftClient.program,
|
|
115
115
|
config.userAccountPublicKey,
|
package/src/userMap/userMap.ts
CHANGED
|
@@ -79,6 +79,14 @@ export class UserMap implements UserMapInterface {
|
|
|
79
79
|
this.syncCallbackCriteria = syncCallbackCriteria;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
public addSyncCallback(
|
|
83
|
+
syncCallback?: (authorities: PublicKey[]) => Promise<void>,
|
|
84
|
+
syncCallbackCriteria: SyncCallbackCriteria = { hasOpenOrders: false }
|
|
85
|
+
) {
|
|
86
|
+
this.syncCallback = syncCallback;
|
|
87
|
+
this.syncCallbackCriteria = syncCallbackCriteria;
|
|
88
|
+
}
|
|
89
|
+
|
|
82
90
|
public async subscribe() {
|
|
83
91
|
if (this.size() > 0) {
|
|
84
92
|
return;
|
|
@@ -208,6 +216,30 @@ export class UserMap implements UserMapInterface {
|
|
|
208
216
|
return this.userMap.size;
|
|
209
217
|
}
|
|
210
218
|
|
|
219
|
+
public getUniqueAuthorities(useSyncCallbackCriteria = true): PublicKey[] {
|
|
220
|
+
const usersMeetingCriteria = Array.from(this.userMap.values()).filter(
|
|
221
|
+
(user) => {
|
|
222
|
+
let pass = true;
|
|
223
|
+
if (
|
|
224
|
+
useSyncCallbackCriteria &&
|
|
225
|
+
this.syncCallbackCriteria.hasOpenOrders
|
|
226
|
+
) {
|
|
227
|
+
pass = pass && user.getUserAccount().hasOpenOrder;
|
|
228
|
+
}
|
|
229
|
+
return pass;
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
const userAuths = new Set(
|
|
233
|
+
usersMeetingCriteria.map((user) =>
|
|
234
|
+
user.getUserAccount().authority.toBase58()
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
const userAuthKeys = Array.from(userAuths).map(
|
|
238
|
+
(userAuth) => new PublicKey(userAuth)
|
|
239
|
+
);
|
|
240
|
+
return userAuthKeys;
|
|
241
|
+
}
|
|
242
|
+
|
|
211
243
|
public async sync() {
|
|
212
244
|
if (this.syncPromise) {
|
|
213
245
|
return this.syncPromise;
|
|
@@ -288,24 +320,7 @@ export class UserMap implements UserMapInterface {
|
|
|
288
320
|
}
|
|
289
321
|
|
|
290
322
|
if (this.syncCallback) {
|
|
291
|
-
|
|
292
|
-
(user) => {
|
|
293
|
-
let pass = true;
|
|
294
|
-
if (this.syncCallbackCriteria.hasOpenOrders) {
|
|
295
|
-
pass = pass && user.getUserAccount().hasOpenOrder;
|
|
296
|
-
}
|
|
297
|
-
return pass;
|
|
298
|
-
}
|
|
299
|
-
);
|
|
300
|
-
const userAuths = new Set(
|
|
301
|
-
usersMeetingCriteria.map((user) =>
|
|
302
|
-
user.getUserAccount().authority.toBase58()
|
|
303
|
-
)
|
|
304
|
-
);
|
|
305
|
-
const userAuthKeys = Array.from(userAuths).map(
|
|
306
|
-
(userAuth) => new PublicKey(userAuth)
|
|
307
|
-
);
|
|
308
|
-
await this.syncCallback(userAuthKeys);
|
|
323
|
+
await this.syncCallback(this.getUniqueAuthorities());
|
|
309
324
|
}
|
|
310
325
|
} catch (e) {
|
|
311
326
|
console.error(`Error in UserMap.sync()`);
|