@drift-labs/sdk 2.107.0-beta.15 → 2.107.0-beta.16
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/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -0
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +12 -3
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +12 -3
- package/package.json +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +33 -8
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.107.0-beta.
|
|
1
|
+
2.107.0-beta.16
|
|
@@ -35,6 +35,7 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
35
35
|
protected subscriptionPromiseResolver: (val: boolean) => void;
|
|
36
36
|
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting, resubOpts?: ResubOpts, commitment?: Commitment);
|
|
37
37
|
subscribe(): Promise<boolean>;
|
|
38
|
+
chunks: <T>(array: readonly T[], size: number) => T[][];
|
|
38
39
|
setInitialData(): Promise<void>;
|
|
39
40
|
removeInitialData(): void;
|
|
40
41
|
subscribeToPerpMarketAccounts(): Promise<boolean>;
|
|
@@ -24,6 +24,12 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
24
24
|
this.spotOracleStringMap = new Map();
|
|
25
25
|
this.oracleSubscribers = new Map();
|
|
26
26
|
this.isSubscribing = false;
|
|
27
|
+
this.chunks = (array, size) => {
|
|
28
|
+
return new Array(Math.ceil(array.length / size))
|
|
29
|
+
.fill(null)
|
|
30
|
+
.map((_, index) => index * size)
|
|
31
|
+
.map((begin) => array.slice(begin, begin + size));
|
|
32
|
+
};
|
|
27
33
|
this.isSubscribed = false;
|
|
28
34
|
this.program = program;
|
|
29
35
|
this.eventEmitter = new events_1.EventEmitter();
|
|
@@ -86,7 +92,8 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
86
92
|
const connection = this.program.provider.connection;
|
|
87
93
|
if (!this.initialPerpMarketAccountData) {
|
|
88
94
|
const perpMarketPublicKeys = this.perpMarketIndexes.map((marketIndex) => (0, pda_1.getPerpMarketPublicKeySync)(this.program.programId, marketIndex));
|
|
89
|
-
const
|
|
95
|
+
const perpMarketPublicKeysChunks = this.chunks(perpMarketPublicKeys, 75);
|
|
96
|
+
const perpMarketAccountInfos = (await Promise.all(perpMarketPublicKeysChunks.map((perpMarketPublicKeysChunk) => connection.getMultipleAccountsInfo(perpMarketPublicKeysChunk)))).flat();
|
|
90
97
|
this.initialPerpMarketAccountData = new Map(perpMarketAccountInfos
|
|
91
98
|
.filter((accountInfo) => !!accountInfo)
|
|
92
99
|
.map((accountInfo) => {
|
|
@@ -96,7 +103,8 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
96
103
|
}
|
|
97
104
|
if (!this.initialSpotMarketAccountData) {
|
|
98
105
|
const spotMarketPublicKeys = this.spotMarketIndexes.map((marketIndex) => (0, pda_1.getSpotMarketPublicKeySync)(this.program.programId, marketIndex));
|
|
99
|
-
const
|
|
106
|
+
const spotMarketPublicKeysChunks = this.chunks(spotMarketPublicKeys, 75);
|
|
107
|
+
const spotMarketAccountInfos = (await Promise.all(spotMarketPublicKeysChunks.map((spotMarketPublicKeysChunk) => connection.getMultipleAccountsInfo(spotMarketPublicKeysChunk)))).flat();
|
|
100
108
|
this.initialSpotMarketAccountData = new Map(spotMarketAccountInfos
|
|
101
109
|
.filter((accountInfo) => !!accountInfo)
|
|
102
110
|
.map((accountInfo) => {
|
|
@@ -104,7 +112,8 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
104
112
|
return [spotMarket.marketIndex, spotMarket];
|
|
105
113
|
}));
|
|
106
114
|
}
|
|
107
|
-
const
|
|
115
|
+
const oracleAccountPubkeyChunks = this.chunks(this.oracleInfos.map((oracleInfo) => oracleInfo.publicKey), 75);
|
|
116
|
+
const oracleAccountInfos = (await Promise.all(oracleAccountPubkeyChunks.map((oracleAccountPublicKeysChunk) => connection.getMultipleAccountsInfo(oracleAccountPublicKeysChunk)))).flat();
|
|
108
117
|
this.initialOraclePriceData = new Map(this.oracleInfos.reduce((result, oracleInfo, i) => {
|
|
109
118
|
if (!oracleAccountInfos[i]) {
|
|
110
119
|
return result;
|
|
@@ -35,6 +35,7 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
35
35
|
protected subscriptionPromiseResolver: (val: boolean) => void;
|
|
36
36
|
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting, resubOpts?: ResubOpts, commitment?: Commitment);
|
|
37
37
|
subscribe(): Promise<boolean>;
|
|
38
|
+
chunks: <T>(array: readonly T[], size: number) => T[][];
|
|
38
39
|
setInitialData(): Promise<void>;
|
|
39
40
|
removeInitialData(): void;
|
|
40
41
|
subscribeToPerpMarketAccounts(): Promise<boolean>;
|
|
@@ -24,6 +24,12 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
24
24
|
this.spotOracleStringMap = new Map();
|
|
25
25
|
this.oracleSubscribers = new Map();
|
|
26
26
|
this.isSubscribing = false;
|
|
27
|
+
this.chunks = (array, size) => {
|
|
28
|
+
return new Array(Math.ceil(array.length / size))
|
|
29
|
+
.fill(null)
|
|
30
|
+
.map((_, index) => index * size)
|
|
31
|
+
.map((begin) => array.slice(begin, begin + size));
|
|
32
|
+
};
|
|
27
33
|
this.isSubscribed = false;
|
|
28
34
|
this.program = program;
|
|
29
35
|
this.eventEmitter = new events_1.EventEmitter();
|
|
@@ -86,7 +92,8 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
86
92
|
const connection = this.program.provider.connection;
|
|
87
93
|
if (!this.initialPerpMarketAccountData) {
|
|
88
94
|
const perpMarketPublicKeys = this.perpMarketIndexes.map((marketIndex) => (0, pda_1.getPerpMarketPublicKeySync)(this.program.programId, marketIndex));
|
|
89
|
-
const
|
|
95
|
+
const perpMarketPublicKeysChunks = this.chunks(perpMarketPublicKeys, 75);
|
|
96
|
+
const perpMarketAccountInfos = (await Promise.all(perpMarketPublicKeysChunks.map((perpMarketPublicKeysChunk) => connection.getMultipleAccountsInfo(perpMarketPublicKeysChunk)))).flat();
|
|
90
97
|
this.initialPerpMarketAccountData = new Map(perpMarketAccountInfos
|
|
91
98
|
.filter((accountInfo) => !!accountInfo)
|
|
92
99
|
.map((accountInfo) => {
|
|
@@ -96,7 +103,8 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
96
103
|
}
|
|
97
104
|
if (!this.initialSpotMarketAccountData) {
|
|
98
105
|
const spotMarketPublicKeys = this.spotMarketIndexes.map((marketIndex) => (0, pda_1.getSpotMarketPublicKeySync)(this.program.programId, marketIndex));
|
|
99
|
-
const
|
|
106
|
+
const spotMarketPublicKeysChunks = this.chunks(spotMarketPublicKeys, 75);
|
|
107
|
+
const spotMarketAccountInfos = (await Promise.all(spotMarketPublicKeysChunks.map((spotMarketPublicKeysChunk) => connection.getMultipleAccountsInfo(spotMarketPublicKeysChunk)))).flat();
|
|
100
108
|
this.initialSpotMarketAccountData = new Map(spotMarketAccountInfos
|
|
101
109
|
.filter((accountInfo) => !!accountInfo)
|
|
102
110
|
.map((accountInfo) => {
|
|
@@ -104,7 +112,8 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
104
112
|
return [spotMarket.marketIndex, spotMarket];
|
|
105
113
|
}));
|
|
106
114
|
}
|
|
107
|
-
const
|
|
115
|
+
const oracleAccountPubkeyChunks = this.chunks(this.oracleInfos.map((oracleInfo) => oracleInfo.publicKey), 75);
|
|
116
|
+
const oracleAccountInfos = (await Promise.all(oracleAccountPubkeyChunks.map((oracleAccountPublicKeysChunk) => connection.getMultipleAccountsInfo(oracleAccountPublicKeysChunk)))).flat();
|
|
108
117
|
this.initialOraclePriceData = new Map(this.oracleInfos.reduce((result, oracleInfo, i) => {
|
|
109
118
|
if (!oracleAccountInfos[i]) {
|
|
110
119
|
return result;
|
package/package.json
CHANGED
|
@@ -176,6 +176,13 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
176
176
|
return true;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
chunks = <T>(array: readonly T[], size: number): T[][] => {
|
|
180
|
+
return new Array(Math.ceil(array.length / size))
|
|
181
|
+
.fill(null)
|
|
182
|
+
.map((_, index) => index * size)
|
|
183
|
+
.map((begin) => array.slice(begin, begin + size));
|
|
184
|
+
};
|
|
185
|
+
|
|
179
186
|
async setInitialData(): Promise<void> {
|
|
180
187
|
const connection = this.program.provider.connection;
|
|
181
188
|
|
|
@@ -183,9 +190,14 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
183
190
|
const perpMarketPublicKeys = this.perpMarketIndexes.map((marketIndex) =>
|
|
184
191
|
getPerpMarketPublicKeySync(this.program.programId, marketIndex)
|
|
185
192
|
);
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
193
|
+
const perpMarketPublicKeysChunks = this.chunks(perpMarketPublicKeys, 75);
|
|
194
|
+
const perpMarketAccountInfos = (
|
|
195
|
+
await Promise.all(
|
|
196
|
+
perpMarketPublicKeysChunks.map((perpMarketPublicKeysChunk) =>
|
|
197
|
+
connection.getMultipleAccountsInfo(perpMarketPublicKeysChunk)
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
).flat();
|
|
189
201
|
this.initialPerpMarketAccountData = new Map(
|
|
190
202
|
perpMarketAccountInfos
|
|
191
203
|
.filter((accountInfo) => !!accountInfo)
|
|
@@ -203,9 +215,14 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
203
215
|
const spotMarketPublicKeys = this.spotMarketIndexes.map((marketIndex) =>
|
|
204
216
|
getSpotMarketPublicKeySync(this.program.programId, marketIndex)
|
|
205
217
|
);
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
218
|
+
const spotMarketPublicKeysChunks = this.chunks(spotMarketPublicKeys, 75);
|
|
219
|
+
const spotMarketAccountInfos = (
|
|
220
|
+
await Promise.all(
|
|
221
|
+
spotMarketPublicKeysChunks.map((spotMarketPublicKeysChunk) =>
|
|
222
|
+
connection.getMultipleAccountsInfo(spotMarketPublicKeysChunk)
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
).flat();
|
|
209
226
|
this.initialSpotMarketAccountData = new Map(
|
|
210
227
|
spotMarketAccountInfos
|
|
211
228
|
.filter((accountInfo) => !!accountInfo)
|
|
@@ -219,9 +236,17 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
219
236
|
);
|
|
220
237
|
}
|
|
221
238
|
|
|
222
|
-
const
|
|
223
|
-
this.oracleInfos.map((oracleInfo) => oracleInfo.publicKey)
|
|
239
|
+
const oracleAccountPubkeyChunks = this.chunks(
|
|
240
|
+
this.oracleInfos.map((oracleInfo) => oracleInfo.publicKey),
|
|
241
|
+
75
|
|
224
242
|
);
|
|
243
|
+
const oracleAccountInfos = (
|
|
244
|
+
await Promise.all(
|
|
245
|
+
oracleAccountPubkeyChunks.map((oracleAccountPublicKeysChunk) =>
|
|
246
|
+
connection.getMultipleAccountsInfo(oracleAccountPublicKeysChunk)
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
).flat();
|
|
225
250
|
this.initialOraclePriceData = new Map(
|
|
226
251
|
this.oracleInfos.reduce((result, oracleInfo, i) => {
|
|
227
252
|
if (!oracleAccountInfos[i]) {
|