@drift-labs/sdk 2.75.0-beta.1 → 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/adminClient.d.ts +72 -0
- package/lib/adminClient.js +414 -184
- package/lib/driftClient.d.ts +2 -2
- package/lib/driftClient.js +11 -7
- package/lib/idl/drift.json +5 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/tx/baseTxSender.d.ts +1 -1
- package/lib/tx/baseTxSender.js +5 -4
- package/lib/tx/fastSingleTxSender.d.ts +1 -1
- package/lib/tx/fastSingleTxSender.js +2 -13
- package/lib/tx/whileValidTxSender.d.ts +35 -0
- package/lib/tx/whileValidTxSender.js +138 -0
- package/lib/userMap/userMap.js +10 -5
- package/package.json +4 -3
- package/src/adminClient.ts +1509 -826
- package/src/driftClient.ts +14 -9
- package/src/idl/drift.json +5 -1
- package/src/index.ts +1 -0
- package/src/tx/baseTxSender.ts +12 -4
- package/src/tx/fastSingleTxSender.ts +3 -17
- package/src/tx/whileValidTxSender.ts +215 -0
- package/src/userMap/userMap.ts +23 -10
package/lib/driftClient.d.ts
CHANGED
|
@@ -329,8 +329,8 @@ export declare class DriftClient {
|
|
|
329
329
|
getRevertFillIx(fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
330
330
|
placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
331
331
|
getPlaceSpotOrderIx(orderParams: OptionalOrderParams, subAccountId?: number): Promise<TransactionInstruction>;
|
|
332
|
-
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
333
|
-
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
332
|
+
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
333
|
+
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
334
334
|
addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount): void;
|
|
335
335
|
addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
|
|
336
336
|
addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
|
package/lib/driftClient.js
CHANGED
|
@@ -1934,22 +1934,27 @@ class DriftClient {
|
|
|
1934
1934
|
const marketIndex = order
|
|
1935
1935
|
? order.marketIndex
|
|
1936
1936
|
: userAccount.orders.find((order) => order.orderId === userAccount.nextOrderId - 1).marketIndex;
|
|
1937
|
+
makerInfo = Array.isArray(makerInfo)
|
|
1938
|
+
? makerInfo
|
|
1939
|
+
: makerInfo
|
|
1940
|
+
? [makerInfo]
|
|
1941
|
+
: [];
|
|
1937
1942
|
const userAccounts = [userAccount];
|
|
1938
|
-
|
|
1939
|
-
userAccounts.push(
|
|
1943
|
+
for (const maker of makerInfo) {
|
|
1944
|
+
userAccounts.push(maker.makerUserAccount);
|
|
1940
1945
|
}
|
|
1941
1946
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1942
1947
|
userAccounts,
|
|
1943
1948
|
writableSpotMarketIndexes: [marketIndex, numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
1944
1949
|
});
|
|
1945
|
-
|
|
1950
|
+
for (const maker of makerInfo) {
|
|
1946
1951
|
remainingAccounts.push({
|
|
1947
|
-
pubkey:
|
|
1952
|
+
pubkey: maker.maker,
|
|
1948
1953
|
isWritable: true,
|
|
1949
1954
|
isSigner: false,
|
|
1950
1955
|
});
|
|
1951
1956
|
remainingAccounts.push({
|
|
1952
|
-
pubkey:
|
|
1957
|
+
pubkey: maker.makerStats,
|
|
1953
1958
|
isWritable: true,
|
|
1954
1959
|
isSigner: false,
|
|
1955
1960
|
});
|
|
@@ -1967,9 +1972,8 @@ class DriftClient {
|
|
|
1967
1972
|
});
|
|
1968
1973
|
}
|
|
1969
1974
|
const orderId = order.orderId;
|
|
1970
|
-
const makerOrderId = makerInfo ? makerInfo.order.orderId : null;
|
|
1971
1975
|
this.addSpotFulfillmentAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
|
|
1972
|
-
return await this.program.instruction.fillSpotOrder(orderId, fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null,
|
|
1976
|
+
return await this.program.instruction.fillSpotOrder(orderId, fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null, null, {
|
|
1973
1977
|
accounts: {
|
|
1974
1978
|
state: await this.getStatePublicKey(),
|
|
1975
1979
|
filler,
|
package/lib/idl/drift.json
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export * from './priorityFee';
|
|
|
73
73
|
export * from './phoenix/phoenixFulfillmentConfigMap';
|
|
74
74
|
export * from './tx/fastSingleTxSender';
|
|
75
75
|
export * from './tx/retryTxSender';
|
|
76
|
+
export * from './tx/whileValidTxSender';
|
|
76
77
|
export * from './tx/priorityFeeCalculator';
|
|
77
78
|
export * from './tx/types';
|
|
78
79
|
export * from './util/computeUnits';
|
package/lib/index.js
CHANGED
|
@@ -96,6 +96,7 @@ __exportStar(require("./priorityFee"), exports);
|
|
|
96
96
|
__exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
|
|
97
97
|
__exportStar(require("./tx/fastSingleTxSender"), exports);
|
|
98
98
|
__exportStar(require("./tx/retryTxSender"), exports);
|
|
99
|
+
__exportStar(require("./tx/whileValidTxSender"), exports);
|
|
99
100
|
__exportStar(require("./tx/priorityFeeCalculator"), exports);
|
|
100
101
|
__exportStar(require("./tx/types"), exports);
|
|
101
102
|
__exportStar(require("./util/computeUnits"), exports);
|
package/lib/tx/baseTxSender.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare abstract class BaseTxSender implements TxSender {
|
|
|
21
21
|
additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
|
|
22
22
|
});
|
|
23
23
|
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
24
|
-
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
|
|
24
|
+
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
|
|
25
25
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions, blockhash?: string): Promise<VersionedTransaction>;
|
|
26
26
|
sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
27
27
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
package/lib/tx/baseTxSender.js
CHANGED
|
@@ -28,15 +28,16 @@ class BaseTxSender {
|
|
|
28
28
|
if (opts === undefined) {
|
|
29
29
|
opts = this.opts;
|
|
30
30
|
}
|
|
31
|
-
const signedTx = preSigned
|
|
32
|
-
? tx
|
|
33
|
-
: await this.prepareTx(tx, additionalSigners, opts);
|
|
31
|
+
const signedTx = await this.prepareTx(tx, additionalSigners, opts, preSigned);
|
|
34
32
|
if (extraConfirmationOptions === null || extraConfirmationOptions === void 0 ? void 0 : extraConfirmationOptions.onSignedCb) {
|
|
35
33
|
extraConfirmationOptions.onSignedCb();
|
|
36
34
|
}
|
|
37
35
|
return this.sendRawTransaction(signedTx.serialize(), opts);
|
|
38
36
|
}
|
|
39
|
-
async prepareTx(tx, additionalSigners, opts) {
|
|
37
|
+
async prepareTx(tx, additionalSigners, opts, preSigned) {
|
|
38
|
+
if (preSigned) {
|
|
39
|
+
return tx;
|
|
40
|
+
}
|
|
40
41
|
tx.feePayer = this.wallet.publicKey;
|
|
41
42
|
tx.recentBlockhash = (await this.connection.getLatestBlockhash(opts.preflightCommitment)).blockhash;
|
|
42
43
|
additionalSigners
|
|
@@ -26,7 +26,7 @@ export declare class FastSingleTxSender extends BaseTxSender {
|
|
|
26
26
|
confirmationStrategy?: ConfirmationStrategy;
|
|
27
27
|
});
|
|
28
28
|
startBlockhashRefreshLoop(): void;
|
|
29
|
-
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, _opts: ConfirmOptions): Promise<Transaction>;
|
|
29
|
+
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, _opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
|
|
30
30
|
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], additionalSigners?: Array<Signer>, opts?: ConfirmOptions, blockhash?: string): Promise<VersionedTransaction>;
|
|
31
31
|
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
32
32
|
}
|
|
@@ -38,19 +38,8 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
|
|
|
38
38
|
}
|
|
39
39
|
}, this.blockhashRefreshInterval);
|
|
40
40
|
}
|
|
41
|
-
async prepareTx(tx, additionalSigners, _opts) {
|
|
42
|
-
|
|
43
|
-
tx.feePayer = this.wallet.publicKey;
|
|
44
|
-
tx.recentBlockhash =
|
|
45
|
-
(_a = this.recentBlockhash) !== null && _a !== void 0 ? _a : (await this.connection.getLatestBlockhash(this.blockhashCommitment))
|
|
46
|
-
.blockhash;
|
|
47
|
-
additionalSigners
|
|
48
|
-
.filter((s) => s !== undefined)
|
|
49
|
-
.forEach((kp) => {
|
|
50
|
-
tx.partialSign(kp);
|
|
51
|
-
});
|
|
52
|
-
const signedTx = await this.wallet.signTransaction(tx);
|
|
53
|
-
return signedTx;
|
|
41
|
+
async prepareTx(tx, additionalSigners, _opts, preSigned) {
|
|
42
|
+
return super.prepareTx(tx, additionalSigners, _opts, preSigned);
|
|
54
43
|
}
|
|
55
44
|
async getVersionedTransaction(ixs, lookupTableAccounts, additionalSigners, opts, blockhash) {
|
|
56
45
|
var _a;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ExtraConfirmationOptions, TxSigAndSlot } from './types';
|
|
3
|
+
import { AddressLookupTableAccount, ConfirmOptions, Connection, Signer, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
import { IWallet } from '../types';
|
|
5
|
+
import { BaseTxSender } from './baseTxSender';
|
|
6
|
+
type ResolveReference = {
|
|
7
|
+
resolve?: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare class WhileValidTxSender extends BaseTxSender {
|
|
10
|
+
connection: Connection;
|
|
11
|
+
wallet: IWallet;
|
|
12
|
+
opts: ConfirmOptions;
|
|
13
|
+
timeout: number;
|
|
14
|
+
retrySleep: number;
|
|
15
|
+
additionalConnections: Connection[];
|
|
16
|
+
timoutCount: number;
|
|
17
|
+
untilValid: Map<string, {
|
|
18
|
+
blockhash: string;
|
|
19
|
+
lastValidBlockHeight: number;
|
|
20
|
+
}>;
|
|
21
|
+
constructor({ connection, wallet, opts, retrySleep, additionalConnections, additionalTxSenderCallbacks, }: {
|
|
22
|
+
connection: Connection;
|
|
23
|
+
wallet: IWallet;
|
|
24
|
+
opts?: ConfirmOptions;
|
|
25
|
+
retrySleep?: number;
|
|
26
|
+
additionalConnections?: any;
|
|
27
|
+
additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
|
|
28
|
+
});
|
|
29
|
+
sleep(reference: ResolveReference): Promise<void>;
|
|
30
|
+
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
|
|
31
|
+
getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], _additionalSigners?: Array<Signer>, _opts?: ConfirmOptions): Promise<VersionedTransaction>;
|
|
32
|
+
sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
|
|
33
|
+
sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WhileValidTxSender = void 0;
|
|
7
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
8
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
9
|
+
const baseTxSender_1 = require("./baseTxSender");
|
|
10
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
11
|
+
const DEFAULT_RETRY = 8000;
|
|
12
|
+
class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
|
|
13
|
+
constructor({ connection, wallet, opts = anchor_1.AnchorProvider.defaultOptions(), retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), additionalTxSenderCallbacks = [], }) {
|
|
14
|
+
super({
|
|
15
|
+
connection,
|
|
16
|
+
wallet,
|
|
17
|
+
opts,
|
|
18
|
+
additionalConnections,
|
|
19
|
+
additionalTxSenderCallbacks,
|
|
20
|
+
});
|
|
21
|
+
this.timoutCount = 0;
|
|
22
|
+
this.untilValid = new Map();
|
|
23
|
+
this.retrySleep = retrySleep;
|
|
24
|
+
}
|
|
25
|
+
async sleep(reference) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
reference.resolve = resolve;
|
|
28
|
+
setTimeout(resolve, this.retrySleep);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async prepareTx(tx, additionalSigners, opts, preSigned) {
|
|
32
|
+
var _a;
|
|
33
|
+
const latestBlockhash = await this.connection.getLatestBlockhash(opts.preflightCommitment);
|
|
34
|
+
// handle tx
|
|
35
|
+
let signedTx = tx;
|
|
36
|
+
if (!preSigned) {
|
|
37
|
+
tx.feePayer = this.wallet.publicKey;
|
|
38
|
+
tx.recentBlockhash = latestBlockhash.blockhash;
|
|
39
|
+
additionalSigners
|
|
40
|
+
.filter((s) => s !== undefined)
|
|
41
|
+
.forEach((kp) => {
|
|
42
|
+
tx.partialSign(kp);
|
|
43
|
+
});
|
|
44
|
+
signedTx = await this.wallet.signTransaction(tx);
|
|
45
|
+
}
|
|
46
|
+
// handle subclass-specific side effects
|
|
47
|
+
const txSig = bs58_1.default.encode(((_a = tx.signatures[0]) === null || _a === void 0 ? void 0 : _a.signature) || tx.signatures[0]);
|
|
48
|
+
this.untilValid.set(txSig, latestBlockhash);
|
|
49
|
+
return signedTx;
|
|
50
|
+
}
|
|
51
|
+
async getVersionedTransaction(ixs, lookupTableAccounts, _additionalSigners, _opts) {
|
|
52
|
+
const message = new web3_js_1.TransactionMessage({
|
|
53
|
+
payerKey: this.wallet.publicKey,
|
|
54
|
+
recentBlockhash: '',
|
|
55
|
+
instructions: ixs,
|
|
56
|
+
}).compileToV0Message(lookupTableAccounts);
|
|
57
|
+
const tx = new web3_js_1.VersionedTransaction(message);
|
|
58
|
+
return tx;
|
|
59
|
+
}
|
|
60
|
+
async sendVersionedTransaction(tx, additionalSigners, opts, preSigned, extraConfirmationOptions) {
|
|
61
|
+
const latestBlockhash = await this.connection.getLatestBlockhash();
|
|
62
|
+
tx.message.recentBlockhash = latestBlockhash.blockhash;
|
|
63
|
+
let signedTx;
|
|
64
|
+
if (preSigned) {
|
|
65
|
+
signedTx = tx;
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
}
|
|
68
|
+
else if (this.wallet.payer) {
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
tx.sign((additionalSigners !== null && additionalSigners !== void 0 ? additionalSigners : []).concat(this.wallet.payer));
|
|
71
|
+
signedTx = tx;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
additionalSigners === null || additionalSigners === void 0 ? void 0 : additionalSigners.filter((s) => s !== undefined).forEach((kp) => {
|
|
75
|
+
tx.sign([kp]);
|
|
76
|
+
});
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
signedTx = await this.wallet.signTransaction(tx);
|
|
79
|
+
}
|
|
80
|
+
if (extraConfirmationOptions === null || extraConfirmationOptions === void 0 ? void 0 : extraConfirmationOptions.onSignedCb) {
|
|
81
|
+
extraConfirmationOptions.onSignedCb();
|
|
82
|
+
}
|
|
83
|
+
if (opts === undefined) {
|
|
84
|
+
opts = this.opts;
|
|
85
|
+
}
|
|
86
|
+
const txSig = bs58_1.default.encode(signedTx.signatures[0]);
|
|
87
|
+
this.untilValid.set(txSig, latestBlockhash);
|
|
88
|
+
return this.sendRawTransaction(signedTx.serialize(), opts);
|
|
89
|
+
}
|
|
90
|
+
async sendRawTransaction(rawTransaction, opts) {
|
|
91
|
+
const startTime = this.getTimestamp();
|
|
92
|
+
const txid = await this.connection.sendRawTransaction(rawTransaction, opts);
|
|
93
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
94
|
+
let done = false;
|
|
95
|
+
const resolveReference = {
|
|
96
|
+
resolve: undefined,
|
|
97
|
+
};
|
|
98
|
+
const stopWaiting = () => {
|
|
99
|
+
done = true;
|
|
100
|
+
if (resolveReference.resolve) {
|
|
101
|
+
resolveReference.resolve();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
(async () => {
|
|
105
|
+
while (!done && this.getTimestamp() - startTime < this.timeout) {
|
|
106
|
+
await this.sleep(resolveReference);
|
|
107
|
+
if (!done) {
|
|
108
|
+
this.connection
|
|
109
|
+
.sendRawTransaction(rawTransaction, opts)
|
|
110
|
+
.catch((e) => {
|
|
111
|
+
console.error(e);
|
|
112
|
+
stopWaiting();
|
|
113
|
+
});
|
|
114
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
let slot;
|
|
119
|
+
try {
|
|
120
|
+
const { blockhash, lastValidBlockHeight } = this.untilValid.get(txid);
|
|
121
|
+
const result = await this.connection.confirmTransaction({
|
|
122
|
+
signature: txid,
|
|
123
|
+
lastValidBlockHeight,
|
|
124
|
+
blockhash,
|
|
125
|
+
}, opts.commitment);
|
|
126
|
+
slot = result.context.slot;
|
|
127
|
+
// eslint-disable-next-line no-useless-catch
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
throw e;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
stopWaiting();
|
|
134
|
+
}
|
|
135
|
+
return { txSig: txid, slot };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.WhileValidTxSender = WhileValidTxSender;
|
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"
|