@drift-labs/sdk 2.48.0-beta.19 → 2.48.0-beta.20
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/accounts/webSocketDriftClientAccountSubscriber.d.ts +3 -2
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +6 -5
- package/lib/driftClient.js +3 -3
- package/package.json +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +13 -6
- package/src/driftClient.ts +2 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.48.0-beta.
|
|
1
|
+
2.48.0-beta.20
|
|
@@ -5,12 +5,13 @@ import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
|
5
5
|
import { Program } from '@coral-xyz/anchor';
|
|
6
6
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
|
-
import { PublicKey } from '@solana/web3.js';
|
|
8
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
10
|
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
11
11
|
export declare class WebSocketDriftClientAccountSubscriber implements DriftClientAccountSubscriber {
|
|
12
12
|
isSubscribed: boolean;
|
|
13
13
|
program: Program;
|
|
14
|
+
commitment?: Commitment;
|
|
14
15
|
perpMarketIndexes: number[];
|
|
15
16
|
spotMarketIndexes: number[];
|
|
16
17
|
oracleInfos: OracleInfo[];
|
|
@@ -25,7 +26,7 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
25
26
|
private isSubscribing;
|
|
26
27
|
private subscriptionPromise;
|
|
27
28
|
private subscriptionPromiseResolver;
|
|
28
|
-
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, resubTimeoutMs?: number);
|
|
29
|
+
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, resubTimeoutMs?: number, commitment?: Commitment);
|
|
29
30
|
subscribe(): Promise<boolean>;
|
|
30
31
|
subscribeToPerpMarketAccounts(): Promise<boolean>;
|
|
31
32
|
subscribeToPerpMarketAccount(marketIndex: number): Promise<boolean>;
|
|
@@ -10,7 +10,7 @@ const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
|
10
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
11
11
|
const config_1 = require("../config");
|
|
12
12
|
class WebSocketDriftClientAccountSubscriber {
|
|
13
|
-
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, resubTimeoutMs) {
|
|
13
|
+
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, resubTimeoutMs, commitment) {
|
|
14
14
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
15
15
|
this.perpMarketAccountSubscribers = new Map();
|
|
16
16
|
this.spotMarketAccountSubscribers = new Map();
|
|
@@ -24,6 +24,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
24
24
|
this.oracleInfos = oracleInfos;
|
|
25
25
|
this.shouldFindAllMarketsAndOracles = shouldFindAllMarketsAndOracles;
|
|
26
26
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
27
|
+
this.commitment = commitment;
|
|
27
28
|
}
|
|
28
29
|
async subscribe() {
|
|
29
30
|
if (this.isSubscribed) {
|
|
@@ -44,7 +45,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
44
45
|
}
|
|
45
46
|
const statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
|
|
46
47
|
// create and activate main state account subscription
|
|
47
|
-
this.stateAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('state', this.program, statePublicKey, undefined, this.resubTimeoutMs);
|
|
48
|
+
this.stateAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('state', this.program, statePublicKey, undefined, this.resubTimeoutMs, this.commitment);
|
|
48
49
|
await this.stateAccountSubscriber.subscribe((data) => {
|
|
49
50
|
this.eventEmitter.emit('stateAccountUpdate', data);
|
|
50
51
|
this.eventEmitter.emit('update');
|
|
@@ -69,7 +70,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
69
70
|
}
|
|
70
71
|
async subscribeToPerpMarketAccount(marketIndex) {
|
|
71
72
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
72
|
-
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, perpMarketPublicKey, undefined, this.resubTimeoutMs);
|
|
73
|
+
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, perpMarketPublicKey, undefined, this.resubTimeoutMs, this.commitment);
|
|
73
74
|
await accountSubscriber.subscribe((data) => {
|
|
74
75
|
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
75
76
|
this.eventEmitter.emit('update');
|
|
@@ -85,7 +86,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
85
86
|
}
|
|
86
87
|
async subscribeToSpotMarketAccount(marketIndex) {
|
|
87
88
|
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
88
|
-
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('spotMarket', this.program, marketPublicKey, undefined, this.resubTimeoutMs);
|
|
89
|
+
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('spotMarket', this.program, marketPublicKey, undefined, this.resubTimeoutMs, this.commitment);
|
|
89
90
|
await accountSubscriber.subscribe((data) => {
|
|
90
91
|
this.eventEmitter.emit('spotMarketAccountUpdate', data);
|
|
91
92
|
this.eventEmitter.emit('update');
|
|
@@ -105,7 +106,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
105
106
|
const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection);
|
|
106
107
|
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('oracle', this.program, oracleInfo.publicKey, (buffer) => {
|
|
107
108
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
108
|
-
}, this.resubTimeoutMs);
|
|
109
|
+
}, this.resubTimeoutMs, this.commitment);
|
|
109
110
|
await accountSubscriber.subscribe((data) => {
|
|
110
111
|
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey, data);
|
|
111
112
|
this.eventEmitter.emit('update');
|
package/lib/driftClient.js
CHANGED
|
@@ -66,7 +66,7 @@ class DriftClient {
|
|
|
66
66
|
this._isSubscribed = val;
|
|
67
67
|
}
|
|
68
68
|
constructor(config) {
|
|
69
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
69
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
70
70
|
this.users = new Map();
|
|
71
71
|
this._isSubscribed = false;
|
|
72
72
|
this.perpMarketLastSlotCache = new Map();
|
|
@@ -143,11 +143,11 @@ class DriftClient {
|
|
|
143
143
|
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_s = config.perpMarketIndexes) !== null && _s !== void 0 ? _s : [], (_t = config.spotMarketIndexes) !== null && _t !== void 0 ? _t : [], (_u = config.oracleInfos) !== null && _u !== void 0 ? _u : [], noMarketsAndOraclesSpecified);
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
|
-
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_v = config.perpMarketIndexes) !== null && _v !== void 0 ? _v : [], (_w = config.spotMarketIndexes) !== null && _w !== void 0 ? _w : [], (_x = config.oracleInfos) !== null && _x !== void 0 ? _x : [], noMarketsAndOraclesSpecified, (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.resubTimeoutMs);
|
|
146
|
+
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_v = config.perpMarketIndexes) !== null && _v !== void 0 ? _v : [], (_w = config.spotMarketIndexes) !== null && _w !== void 0 ? _w : [], (_x = config.oracleInfos) !== null && _x !== void 0 ? _x : [], noMarketsAndOraclesSpecified, (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.resubTimeoutMs, (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.commitment);
|
|
147
147
|
}
|
|
148
148
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
149
149
|
this.txSender =
|
|
150
|
-
(
|
|
150
|
+
(_0 = config.txSender) !== null && _0 !== void 0 ? _0 : new retryTxSender_1.RetryTxSender({
|
|
151
151
|
connection: this.connection,
|
|
152
152
|
wallet: this.wallet,
|
|
153
153
|
opts: this.opts,
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
getPerpMarketPublicKey,
|
|
15
15
|
} from '../addresses/pda';
|
|
16
16
|
import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
|
|
17
|
-
import { PublicKey } from '@solana/web3.js';
|
|
17
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
18
18
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
19
19
|
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
20
20
|
import * as Buffer from 'buffer';
|
|
@@ -26,6 +26,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
26
26
|
{
|
|
27
27
|
isSubscribed: boolean;
|
|
28
28
|
program: Program;
|
|
29
|
+
commitment?: Commitment;
|
|
29
30
|
perpMarketIndexes: number[];
|
|
30
31
|
spotMarketIndexes: number[];
|
|
31
32
|
oracleInfos: OracleInfo[];
|
|
@@ -56,7 +57,8 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
56
57
|
spotMarketIndexes: number[],
|
|
57
58
|
oracleInfos: OracleInfo[],
|
|
58
59
|
shouldFindAllMarketsAndOracles: boolean,
|
|
59
|
-
resubTimeoutMs?: number
|
|
60
|
+
resubTimeoutMs?: number,
|
|
61
|
+
commitment?: Commitment
|
|
60
62
|
) {
|
|
61
63
|
this.isSubscribed = false;
|
|
62
64
|
this.program = program;
|
|
@@ -66,6 +68,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
66
68
|
this.oracleInfos = oracleInfos;
|
|
67
69
|
this.shouldFindAllMarketsAndOracles = shouldFindAllMarketsAndOracles;
|
|
68
70
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
71
|
+
this.commitment = commitment;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
public async subscribe(): Promise<boolean> {
|
|
@@ -101,7 +104,8 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
101
104
|
this.program,
|
|
102
105
|
statePublicKey,
|
|
103
106
|
undefined,
|
|
104
|
-
this.resubTimeoutMs
|
|
107
|
+
this.resubTimeoutMs,
|
|
108
|
+
this.commitment
|
|
105
109
|
);
|
|
106
110
|
await this.stateAccountSubscriber.subscribe((data: StateAccount) => {
|
|
107
111
|
this.eventEmitter.emit('stateAccountUpdate', data);
|
|
@@ -143,7 +147,8 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
143
147
|
this.program,
|
|
144
148
|
perpMarketPublicKey,
|
|
145
149
|
undefined,
|
|
146
|
-
this.resubTimeoutMs
|
|
150
|
+
this.resubTimeoutMs,
|
|
151
|
+
this.commitment
|
|
147
152
|
);
|
|
148
153
|
await accountSubscriber.subscribe((data: PerpMarketAccount) => {
|
|
149
154
|
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
@@ -170,7 +175,8 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
170
175
|
this.program,
|
|
171
176
|
marketPublicKey,
|
|
172
177
|
undefined,
|
|
173
|
-
this.resubTimeoutMs
|
|
178
|
+
this.resubTimeoutMs,
|
|
179
|
+
this.commitment
|
|
174
180
|
);
|
|
175
181
|
await accountSubscriber.subscribe((data: SpotMarketAccount) => {
|
|
176
182
|
this.eventEmitter.emit('spotMarketAccountUpdate', data);
|
|
@@ -202,7 +208,8 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
202
208
|
(buffer: Buffer) => {
|
|
203
209
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
204
210
|
},
|
|
205
|
-
this.resubTimeoutMs
|
|
211
|
+
this.resubTimeoutMs,
|
|
212
|
+
this.commitment
|
|
206
213
|
);
|
|
207
214
|
|
|
208
215
|
await accountSubscriber.subscribe((data: OraclePriceData) => {
|
package/src/driftClient.ts
CHANGED
|
@@ -283,7 +283,8 @@ export class DriftClient {
|
|
|
283
283
|
config.spotMarketIndexes ?? [],
|
|
284
284
|
config.oracleInfos ?? [],
|
|
285
285
|
noMarketsAndOraclesSpecified,
|
|
286
|
-
config.accountSubscription?.resubTimeoutMs
|
|
286
|
+
config.accountSubscription?.resubTimeoutMs,
|
|
287
|
+
config.accountSubscription?.commitment
|
|
287
288
|
);
|
|
288
289
|
}
|
|
289
290
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|