@drift-labs/sdk-browser 2.107.0-beta.14 → 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/browser/driftClient.js +4 -2
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -0
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +12 -3
- package/lib/node/driftClient.js +4 -2
- package/package.json +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +33 -8
- package/src/driftClient.ts +3 -2
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;
|
|
@@ -3188,16 +3188,18 @@ class DriftClient {
|
|
|
3188
3188
|
encodeSwiftOrderParamsMessage(orderParamsMessage) {
|
|
3189
3189
|
const anchorIxName = 'global' + ':' + 'swiftOrderMessageParams';
|
|
3190
3190
|
const prefix = Buffer.from((0, sha256_1.hash)(anchorIxName).slice(0, 8));
|
|
3191
|
-
|
|
3191
|
+
const buf = Buffer.concat([
|
|
3192
3192
|
prefix,
|
|
3193
3193
|
this.program.coder.types.encode('SwiftOrderParamsMessage', orderParamsMessage),
|
|
3194
3194
|
]);
|
|
3195
|
+
return buf;
|
|
3195
3196
|
}
|
|
3196
3197
|
/*
|
|
3197
3198
|
* Decode swift taker order params from borsh buffer
|
|
3198
3199
|
*/
|
|
3199
3200
|
decodeSwiftOrderParamsMessage(encodedMessage) {
|
|
3200
|
-
return this.program.coder.types.decode('SwiftOrderParamsMessage', encodedMessage)
|
|
3201
|
+
return this.program.coder.types.decode('SwiftOrderParamsMessage', encodedMessage.slice(8) // assumes discriminator
|
|
3202
|
+
);
|
|
3201
3203
|
}
|
|
3202
3204
|
signMessage(message, keypair = this.wallet.payer) {
|
|
3203
3205
|
return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
|
|
@@ -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/lib/node/driftClient.js
CHANGED
|
@@ -3188,16 +3188,18 @@ class DriftClient {
|
|
|
3188
3188
|
encodeSwiftOrderParamsMessage(orderParamsMessage) {
|
|
3189
3189
|
const anchorIxName = 'global' + ':' + 'swiftOrderMessageParams';
|
|
3190
3190
|
const prefix = Buffer.from((0, sha256_1.hash)(anchorIxName).slice(0, 8));
|
|
3191
|
-
|
|
3191
|
+
const buf = Buffer.concat([
|
|
3192
3192
|
prefix,
|
|
3193
3193
|
this.program.coder.types.encode('SwiftOrderParamsMessage', orderParamsMessage),
|
|
3194
3194
|
]);
|
|
3195
|
+
return buf;
|
|
3195
3196
|
}
|
|
3196
3197
|
/*
|
|
3197
3198
|
* Decode swift taker order params from borsh buffer
|
|
3198
3199
|
*/
|
|
3199
3200
|
decodeSwiftOrderParamsMessage(encodedMessage) {
|
|
3200
|
-
return this.program.coder.types.decode('SwiftOrderParamsMessage', encodedMessage)
|
|
3201
|
+
return this.program.coder.types.decode('SwiftOrderParamsMessage', encodedMessage.slice(8) // assumes discriminator
|
|
3202
|
+
);
|
|
3201
3203
|
}
|
|
3202
3204
|
signMessage(message, keypair = this.wallet.payer) {
|
|
3203
3205
|
return Buffer.from(tweetnacl_1.default.sign.detached(message, keypair.secretKey));
|
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]) {
|
package/src/driftClient.ts
CHANGED
|
@@ -5885,13 +5885,14 @@ export class DriftClient {
|
|
|
5885
5885
|
): Buffer {
|
|
5886
5886
|
const anchorIxName = 'global' + ':' + 'swiftOrderMessageParams';
|
|
5887
5887
|
const prefix = Buffer.from(hash(anchorIxName).slice(0, 8));
|
|
5888
|
-
|
|
5888
|
+
const buf = Buffer.concat([
|
|
5889
5889
|
prefix,
|
|
5890
5890
|
this.program.coder.types.encode(
|
|
5891
5891
|
'SwiftOrderParamsMessage',
|
|
5892
5892
|
orderParamsMessage
|
|
5893
5893
|
),
|
|
5894
5894
|
]);
|
|
5895
|
+
return buf;
|
|
5895
5896
|
}
|
|
5896
5897
|
|
|
5897
5898
|
/*
|
|
@@ -5902,7 +5903,7 @@ export class DriftClient {
|
|
|
5902
5903
|
): SwiftOrderParamsMessage {
|
|
5903
5904
|
return this.program.coder.types.decode(
|
|
5904
5905
|
'SwiftOrderParamsMessage',
|
|
5905
|
-
encodedMessage
|
|
5906
|
+
encodedMessage.slice(8) // assumes discriminator
|
|
5906
5907
|
);
|
|
5907
5908
|
}
|
|
5908
5909
|
|