@drift-labs/sdk 2.53.0-beta.0 → 2.53.0-beta.1
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.53.0-beta.
|
|
1
|
+
2.53.0-beta.1
|
package/lib/userMap/userMap.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class UserMap implements UserMapInterface {
|
|
|
18
18
|
private connection;
|
|
19
19
|
private commitment;
|
|
20
20
|
private includeIdle;
|
|
21
|
+
private disableSyncOnTotalAccountsChange;
|
|
21
22
|
private lastNumberOfSubAccounts;
|
|
22
23
|
private subscription;
|
|
23
24
|
private stateAccountUpdateCallback;
|
package/lib/userMap/userMap.js
CHANGED
|
@@ -13,7 +13,7 @@ class UserMap {
|
|
|
13
13
|
* Constructs a new UserMap instance.
|
|
14
14
|
*/
|
|
15
15
|
constructor(config) {
|
|
16
|
-
var _a, _b, _c;
|
|
16
|
+
var _a, _b, _c, _d;
|
|
17
17
|
this.userMap = new Map();
|
|
18
18
|
this.stateAccountUpdateCallback = async (state) => {
|
|
19
19
|
if (!state.numberOfSubAccounts.eq(this.lastNumberOfSubAccounts)) {
|
|
@@ -32,8 +32,10 @@ class UserMap {
|
|
|
32
32
|
this.commitment =
|
|
33
33
|
(_a = config.subscriptionConfig.commitment) !== null && _a !== void 0 ? _a : this.driftClient.opts.commitment;
|
|
34
34
|
this.includeIdle = (_b = config.includeIdle) !== null && _b !== void 0 ? _b : false;
|
|
35
|
+
this.disableSyncOnTotalAccountsChange =
|
|
36
|
+
(_c = config.disableSyncOnTotalAccountsChange) !== null && _c !== void 0 ? _c : false;
|
|
35
37
|
let decodeFn;
|
|
36
|
-
if ((
|
|
38
|
+
if ((_d = config.fastDecode) !== null && _d !== void 0 ? _d : true) {
|
|
37
39
|
decodeFn = (name, buffer) => (0, user_1.decodeUser)(buffer);
|
|
38
40
|
}
|
|
39
41
|
else {
|
|
@@ -65,7 +67,9 @@ class UserMap {
|
|
|
65
67
|
await this.driftClient.subscribe();
|
|
66
68
|
this.lastNumberOfSubAccounts =
|
|
67
69
|
this.driftClient.getStateAccount().numberOfSubAccounts;
|
|
68
|
-
|
|
70
|
+
if (!this.disableSyncOnTotalAccountsChange) {
|
|
71
|
+
this.driftClient.eventEmitter.on('stateAccountUpdate', this.stateAccountUpdateCallback);
|
|
72
|
+
}
|
|
69
73
|
await this.subscription.subscribe();
|
|
70
74
|
}
|
|
71
75
|
async addPubkey(userAccountPublicKey, userAccount, slot) {
|
|
@@ -260,7 +264,9 @@ class UserMap {
|
|
|
260
264
|
this.userMap.delete(key);
|
|
261
265
|
}
|
|
262
266
|
if (this.lastNumberOfSubAccounts) {
|
|
263
|
-
|
|
267
|
+
if (!this.disableSyncOnTotalAccountsChange) {
|
|
268
|
+
this.driftClient.eventEmitter.removeListener('stateAccountUpdate', this.stateAccountUpdateCallback);
|
|
269
|
+
}
|
|
264
270
|
this.lastNumberOfSubAccounts = undefined;
|
|
265
271
|
}
|
|
266
272
|
}
|
package/package.json
CHANGED
package/src/userMap/userMap.ts
CHANGED
|
@@ -51,6 +51,7 @@ export class UserMap implements UserMapInterface {
|
|
|
51
51
|
private connection: Connection;
|
|
52
52
|
private commitment: Commitment;
|
|
53
53
|
private includeIdle: boolean;
|
|
54
|
+
private disableSyncOnTotalAccountsChange: boolean;
|
|
54
55
|
private lastNumberOfSubAccounts: BN;
|
|
55
56
|
private subscription: PollingSubscription | WebsocketSubscription;
|
|
56
57
|
private stateAccountUpdateCallback = async (state: StateAccount) => {
|
|
@@ -78,6 +79,8 @@ export class UserMap implements UserMapInterface {
|
|
|
78
79
|
this.commitment =
|
|
79
80
|
config.subscriptionConfig.commitment ?? this.driftClient.opts.commitment;
|
|
80
81
|
this.includeIdle = config.includeIdle ?? false;
|
|
82
|
+
this.disableSyncOnTotalAccountsChange =
|
|
83
|
+
config.disableSyncOnTotalAccountsChange ?? false;
|
|
81
84
|
|
|
82
85
|
let decodeFn;
|
|
83
86
|
if (config.fastDecode ?? true) {
|
|
@@ -115,10 +118,12 @@ export class UserMap implements UserMapInterface {
|
|
|
115
118
|
await this.driftClient.subscribe();
|
|
116
119
|
this.lastNumberOfSubAccounts =
|
|
117
120
|
this.driftClient.getStateAccount().numberOfSubAccounts;
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
if (!this.disableSyncOnTotalAccountsChange) {
|
|
122
|
+
this.driftClient.eventEmitter.on(
|
|
123
|
+
'stateAccountUpdate',
|
|
124
|
+
this.stateAccountUpdateCallback
|
|
125
|
+
);
|
|
126
|
+
}
|
|
122
127
|
|
|
123
128
|
await this.subscription.subscribe();
|
|
124
129
|
}
|
|
@@ -363,10 +368,13 @@ export class UserMap implements UserMapInterface {
|
|
|
363
368
|
}
|
|
364
369
|
|
|
365
370
|
if (this.lastNumberOfSubAccounts) {
|
|
366
|
-
this.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
371
|
+
if (!this.disableSyncOnTotalAccountsChange) {
|
|
372
|
+
this.driftClient.eventEmitter.removeListener(
|
|
373
|
+
'stateAccountUpdate',
|
|
374
|
+
this.stateAccountUpdateCallback
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
370
378
|
this.lastNumberOfSubAccounts = undefined;
|
|
371
379
|
}
|
|
372
380
|
}
|
|
@@ -31,4 +31,8 @@ export type UserMapConfig = {
|
|
|
31
31
|
|
|
32
32
|
// Whether to skip loading available perp/spot positions and open orders
|
|
33
33
|
fastDecode?: boolean;
|
|
34
|
+
|
|
35
|
+
// If true, will not do a full sync whenever StateAccount.numberOfSubAccounts changes.
|
|
36
|
+
// default behavior is to do a full sync on changes.
|
|
37
|
+
disableSyncOnTotalAccountsChange?: boolean;
|
|
34
38
|
};
|