@drift-labs/sdk 2.75.0-beta.2 → 2.75.0-beta.3
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/userMap/userMap.js +10 -5
- package/package.json +4 -3
- package/src/userMap/userMap.ts +23 -10
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.75.0-beta.
|
|
1
|
+
2.75.0-beta.3
|
package/lib/userMap/userMap.js
CHANGED
|
@@ -4,10 +4,12 @@ exports.UserMap = void 0;
|
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const buffer_1 = require("buffer");
|
|
7
|
+
const zstddec_1 = require("zstddec");
|
|
7
8
|
const memcmp_1 = require("../memcmp");
|
|
8
9
|
const WebsocketSubscription_1 = require("./WebsocketSubscription");
|
|
9
10
|
const PollingSubscription_1 = require("./PollingSubscription");
|
|
10
11
|
const user_1 = require("../decode/user");
|
|
12
|
+
const MAX_USER_ACCOUNT_SIZE_BYTES = 4376;
|
|
11
13
|
class UserMap {
|
|
12
14
|
/**
|
|
13
15
|
* Constructs a new UserMap instance.
|
|
@@ -242,7 +244,7 @@ class UserMap {
|
|
|
242
244
|
{
|
|
243
245
|
commitment: this.commitment,
|
|
244
246
|
filters,
|
|
245
|
-
encoding: 'base64',
|
|
247
|
+
encoding: 'base64+zstd',
|
|
246
248
|
withContext: true,
|
|
247
249
|
},
|
|
248
250
|
];
|
|
@@ -252,11 +254,14 @@ class UserMap {
|
|
|
252
254
|
const slot = rpcResponseAndContext.context.slot;
|
|
253
255
|
this.updateLatestSlot(slot);
|
|
254
256
|
const programAccountBufferMap = new Map();
|
|
255
|
-
rpcResponseAndContext.value.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
257
|
+
const decodingPromises = rpcResponseAndContext.value.map(async (programAccount) => {
|
|
258
|
+
const compressedUserData = buffer_1.Buffer.from(programAccount.account.data[0], 'base64');
|
|
259
|
+
const decoder = new zstddec_1.ZSTDDecoder();
|
|
260
|
+
await decoder.init();
|
|
261
|
+
const userBuffer = decoder.decode(compressedUserData, MAX_USER_ACCOUNT_SIZE_BYTES);
|
|
262
|
+
programAccountBufferMap.set(programAccount.pubkey.toString(), buffer_1.Buffer.from(userBuffer));
|
|
259
263
|
});
|
|
264
|
+
await Promise.all(decodingPromises);
|
|
260
265
|
const promises = Array.from(programAccountBufferMap.entries()).map(([key, buffer]) => (async () => {
|
|
261
266
|
const currAccountWithSlot = this.getWithSlot(key);
|
|
262
267
|
if (currAccountWithSlot) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.75.0-beta.
|
|
3
|
+
"version": "2.75.0-beta.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"@solana/spl-token": "^0.3.7",
|
|
42
42
|
"@solana/web3.js": "1.73.2",
|
|
43
43
|
"strict-event-emitter-types": "^2.0.0",
|
|
44
|
-
"uuid": "^8.3.2"
|
|
44
|
+
"uuid": "^8.3.2",
|
|
45
|
+
"zstddec": "^0.1.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"object-sizeof": "^2.6.3",
|
|
48
48
|
"@types/big.js": "^6.2.0",
|
|
49
49
|
"@types/bn.js": "^5.1.3",
|
|
50
50
|
"@types/chai": "^4.3.1",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"eslint-plugin-prettier": "^3.4.0",
|
|
60
60
|
"lodash": "^4.17.21",
|
|
61
61
|
"mocha": "^10.0.0",
|
|
62
|
+
"object-sizeof": "^2.6.3",
|
|
62
63
|
"prettier": "^3.0.1",
|
|
63
64
|
"ts-node": "^10.8.0",
|
|
64
65
|
"typescript": "^4.9.5"
|
package/src/userMap/userMap.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
RpcResponseAndContext,
|
|
27
27
|
} from '@solana/web3.js';
|
|
28
28
|
import { Buffer } from 'buffer';
|
|
29
|
+
import { ZSTDDecoder } from 'zstddec';
|
|
29
30
|
import { getNonIdleUserFilter, getUserFilter } from '../memcmp';
|
|
30
31
|
import {
|
|
31
32
|
UserAccountFilterCriteria as UserFilterCriteria,
|
|
@@ -35,6 +36,8 @@ import { WebsocketSubscription } from './WebsocketSubscription';
|
|
|
35
36
|
import { PollingSubscription } from './PollingSubscription';
|
|
36
37
|
import { decodeUser } from '../decode/user';
|
|
37
38
|
|
|
39
|
+
const MAX_USER_ACCOUNT_SIZE_BYTES = 4376;
|
|
40
|
+
|
|
38
41
|
export interface UserMapInterface {
|
|
39
42
|
subscribe(): Promise<void>;
|
|
40
43
|
unsubscribe(): Promise<void>;
|
|
@@ -357,7 +360,7 @@ export class UserMap implements UserMapInterface {
|
|
|
357
360
|
{
|
|
358
361
|
commitment: this.commitment,
|
|
359
362
|
filters,
|
|
360
|
-
encoding: 'base64',
|
|
363
|
+
encoding: 'base64+zstd',
|
|
361
364
|
withContext: true,
|
|
362
365
|
},
|
|
363
366
|
];
|
|
@@ -375,16 +378,26 @@ export class UserMap implements UserMapInterface {
|
|
|
375
378
|
this.updateLatestSlot(slot);
|
|
376
379
|
|
|
377
380
|
const programAccountBufferMap = new Map<string, Buffer>();
|
|
378
|
-
rpcResponseAndContext.value.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
// @ts-ignore
|
|
382
|
-
Buffer.from(
|
|
381
|
+
const decodingPromises = rpcResponseAndContext.value.map(
|
|
382
|
+
async (programAccount) => {
|
|
383
|
+
const compressedUserData = Buffer.from(
|
|
383
384
|
programAccount.account.data[0],
|
|
384
|
-
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
|
|
385
|
+
'base64'
|
|
386
|
+
);
|
|
387
|
+
const decoder = new ZSTDDecoder();
|
|
388
|
+
await decoder.init();
|
|
389
|
+
const userBuffer = decoder.decode(
|
|
390
|
+
compressedUserData,
|
|
391
|
+
MAX_USER_ACCOUNT_SIZE_BYTES
|
|
392
|
+
);
|
|
393
|
+
programAccountBufferMap.set(
|
|
394
|
+
programAccount.pubkey.toString(),
|
|
395
|
+
Buffer.from(userBuffer)
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
await Promise.all(decodingPromises);
|
|
388
401
|
|
|
389
402
|
const promises = Array.from(programAccountBufferMap.entries()).map(
|
|
390
403
|
([key, buffer]) =>
|