@drift-labs/sdk 2.46.0-beta.1 → 2.47.0-beta.1
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/webSocketAccountSubscriber.d.ts +3 -2
- package/lib/accounts/webSocketAccountSubscriber.js +4 -2
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +3 -2
- package/lib/accounts/webSocketUserAccountSubscriber.js +3 -2
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +3 -2
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +3 -2
- package/lib/driftClient.js +9 -5
- package/lib/driftClientConfig.d.ts +2 -1
- package/lib/idl/drift.json +1 -1
- package/lib/user.js +3 -3
- package/lib/userConfig.d.ts +3 -1
- package/lib/userStats.js +4 -4
- package/lib/userStatsConfig.d.ts +3 -1
- package/package.json +1 -1
- package/src/accounts/webSocketAccountSubscriber.ts +7 -3
- package/src/accounts/webSocketUserAccountSubscriber.ts +7 -3
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +7 -3
- package/src/driftClient.ts +4 -0
- package/src/driftClientConfig.ts +2 -0
- package/src/idl/drift.json +1 -1
- package/src/user.ts +4 -2
- package/src/userConfig.ts +3 -1
- package/src/userStats.ts +8 -6
- package/src/userStatsConfig.ts +3 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.47.0-beta.1
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { DataAndSlot, BufferAndSlot, AccountSubscriber } from './types';
|
|
4
4
|
import { Program } from '@coral-xyz/anchor';
|
|
5
|
-
import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
|
|
5
|
+
import { AccountInfo, Commitment, Context, PublicKey } from '@solana/web3.js';
|
|
6
6
|
export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
7
7
|
dataAndSlot?: DataAndSlot<T>;
|
|
8
8
|
bufferAndSlot?: BufferAndSlot;
|
|
@@ -13,10 +13,11 @@ export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<
|
|
|
13
13
|
onChange: (data: T) => void;
|
|
14
14
|
listenerId?: number;
|
|
15
15
|
resubTimeoutMs?: number;
|
|
16
|
+
commitment?: Commitment;
|
|
16
17
|
isUnsubscribing: boolean;
|
|
17
18
|
timeoutId?: NodeJS.Timeout;
|
|
18
19
|
receivingData: boolean;
|
|
19
|
-
constructor(accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubTimeoutMs?: number);
|
|
20
|
+
constructor(accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubTimeoutMs?: number, commitment?: Commitment);
|
|
20
21
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
21
22
|
setData(data: T, slot?: number): void;
|
|
22
23
|
private setTimeout;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebSocketAccountSubscriber = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
class WebSocketAccountSubscriber {
|
|
6
|
-
constructor(accountName, program, accountPublicKey, decodeBuffer, resubTimeoutMs) {
|
|
6
|
+
constructor(accountName, program, accountPublicKey, decodeBuffer, resubTimeoutMs, commitment) {
|
|
7
7
|
this.isUnsubscribing = false;
|
|
8
8
|
this.accountName = accountName;
|
|
9
9
|
this.program = program;
|
|
@@ -11,6 +11,8 @@ class WebSocketAccountSubscriber {
|
|
|
11
11
|
this.decodeBufferFn = decodeBuffer;
|
|
12
12
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
13
13
|
this.receivingData = false;
|
|
14
|
+
this.commitment =
|
|
15
|
+
commitment !== null && commitment !== void 0 ? commitment : this.program.provider.opts.commitment;
|
|
14
16
|
}
|
|
15
17
|
async subscribe(onChange) {
|
|
16
18
|
if (this.listenerId || this.isUnsubscribing) {
|
|
@@ -30,7 +32,7 @@ class WebSocketAccountSubscriber {
|
|
|
30
32
|
else {
|
|
31
33
|
this.handleRpcResponse(context, accountInfo);
|
|
32
34
|
}
|
|
33
|
-
}, this.
|
|
35
|
+
}, this.commitment);
|
|
34
36
|
if (this.resubTimeoutMs) {
|
|
35
37
|
this.setTimeout();
|
|
36
38
|
}
|
|
@@ -3,16 +3,17 @@ import { DataAndSlot, AccountSubscriber, UserAccountEvents, UserAccountSubscribe
|
|
|
3
3
|
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
|
-
import { PublicKey } from '@solana/web3.js';
|
|
6
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
7
7
|
import { UserAccount } from '../types';
|
|
8
8
|
export declare class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
9
9
|
isSubscribed: boolean;
|
|
10
10
|
reconnectTimeoutMs?: number;
|
|
11
|
+
commitment?: Commitment;
|
|
11
12
|
program: Program;
|
|
12
13
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
13
14
|
userAccountPublicKey: PublicKey;
|
|
14
15
|
userDataAccountSubscriber: AccountSubscriber<UserAccount>;
|
|
15
|
-
constructor(program: Program, userAccountPublicKey: PublicKey, reconnectTimeoutMs?: number);
|
|
16
|
+
constructor(program: Program, userAccountPublicKey: PublicKey, reconnectTimeoutMs?: number, commitment?: Commitment);
|
|
16
17
|
subscribe(userAccount?: UserAccount): Promise<boolean>;
|
|
17
18
|
fetch(): Promise<void>;
|
|
18
19
|
unsubscribe(): Promise<void>;
|
|
@@ -5,18 +5,19 @@ const types_1 = require("./types");
|
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
7
7
|
class WebSocketUserAccountSubscriber {
|
|
8
|
-
constructor(program, userAccountPublicKey, reconnectTimeoutMs) {
|
|
8
|
+
constructor(program, userAccountPublicKey, reconnectTimeoutMs, commitment) {
|
|
9
9
|
this.isSubscribed = false;
|
|
10
10
|
this.program = program;
|
|
11
11
|
this.userAccountPublicKey = userAccountPublicKey;
|
|
12
12
|
this.eventEmitter = new events_1.EventEmitter();
|
|
13
13
|
this.reconnectTimeoutMs = reconnectTimeoutMs;
|
|
14
|
+
this.commitment = commitment;
|
|
14
15
|
}
|
|
15
16
|
async subscribe(userAccount) {
|
|
16
17
|
if (this.isSubscribed) {
|
|
17
18
|
return true;
|
|
18
19
|
}
|
|
19
|
-
this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, this.userAccountPublicKey, undefined, this.reconnectTimeoutMs);
|
|
20
|
+
this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, this.userAccountPublicKey, undefined, this.reconnectTimeoutMs, this.commitment);
|
|
20
21
|
if (userAccount) {
|
|
21
22
|
this.userDataAccountSubscriber.setData(userAccount);
|
|
22
23
|
}
|
|
@@ -3,16 +3,17 @@ import { DataAndSlot, AccountSubscriber, UserStatsAccountSubscriber, UserStatsAc
|
|
|
3
3
|
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
|
-
import { PublicKey } from '@solana/web3.js';
|
|
6
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
7
7
|
import { UserStatsAccount } from '../types';
|
|
8
8
|
export declare class WebSocketUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
|
|
9
9
|
isSubscribed: boolean;
|
|
10
10
|
reconnectTimeoutMs?: number;
|
|
11
|
+
commitment?: Commitment;
|
|
11
12
|
program: Program;
|
|
12
13
|
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
13
14
|
userStatsAccountPublicKey: PublicKey;
|
|
14
15
|
userStatsAccountSubscriber: AccountSubscriber<UserStatsAccount>;
|
|
15
|
-
constructor(program: Program, userStatsAccountPublicKey: PublicKey, reconnectTimeoutMs?: number);
|
|
16
|
+
constructor(program: Program, userStatsAccountPublicKey: PublicKey, reconnectTimeoutMs?: number, commitment?: Commitment);
|
|
16
17
|
subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
|
|
17
18
|
fetch(): Promise<void>;
|
|
18
19
|
unsubscribe(): Promise<void>;
|
|
@@ -5,18 +5,19 @@ const types_1 = require("./types");
|
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
7
7
|
class WebSocketUserStatsAccountSubscriber {
|
|
8
|
-
constructor(program, userStatsAccountPublicKey, reconnectTimeoutMs) {
|
|
8
|
+
constructor(program, userStatsAccountPublicKey, reconnectTimeoutMs, commitment) {
|
|
9
9
|
this.isSubscribed = false;
|
|
10
10
|
this.program = program;
|
|
11
11
|
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
12
12
|
this.eventEmitter = new events_1.EventEmitter();
|
|
13
13
|
this.reconnectTimeoutMs = reconnectTimeoutMs;
|
|
14
|
+
this.commitment = commitment;
|
|
14
15
|
}
|
|
15
16
|
async subscribe(userStatsAccount) {
|
|
16
17
|
if (this.isSubscribed) {
|
|
17
18
|
return true;
|
|
18
19
|
}
|
|
19
|
-
this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey, undefined, this.reconnectTimeoutMs);
|
|
20
|
+
this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey, undefined, this.reconnectTimeoutMs, this.commitment);
|
|
20
21
|
if (userStatsAccount) {
|
|
21
22
|
this.userStatsAccountSubscriber.setData(userStatsAccount);
|
|
22
23
|
}
|
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;
|
|
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;
|
|
70
70
|
this.users = new Map();
|
|
71
71
|
this._isSubscribed = false;
|
|
72
72
|
this.perpMarketLastSlotCache = new Map();
|
|
@@ -116,9 +116,13 @@ class DriftClient {
|
|
|
116
116
|
else {
|
|
117
117
|
this.userAccountSubscriptionConfig = {
|
|
118
118
|
type: 'websocket',
|
|
119
|
+
resubTimeoutMs: (_m = config.accountSubscription) === null || _m === void 0 ? void 0 : _m.resubTimeoutMs,
|
|
120
|
+
commitment: (_o = config.accountSubscription) === null || _o === void 0 ? void 0 : _o.commitment,
|
|
119
121
|
};
|
|
120
122
|
this.userStatsAccountSubscriptionConfig = {
|
|
121
123
|
type: 'websocket',
|
|
124
|
+
resubTimeoutMs: (_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.resubTimeoutMs,
|
|
125
|
+
commitment: (_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.commitment,
|
|
122
126
|
};
|
|
123
127
|
}
|
|
124
128
|
if (config.userStats) {
|
|
@@ -135,15 +139,15 @@ class DriftClient {
|
|
|
135
139
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
136
140
|
config.spotMarketIndexes === undefined &&
|
|
137
141
|
config.oracleInfos === undefined;
|
|
138
|
-
if (((
|
|
139
|
-
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (
|
|
142
|
+
if (((_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.type) === 'polling') {
|
|
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);
|
|
140
144
|
}
|
|
141
145
|
else {
|
|
142
|
-
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (
|
|
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);
|
|
143
147
|
}
|
|
144
148
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
145
149
|
this.txSender =
|
|
146
|
-
(
|
|
150
|
+
(_z = config.txSender) !== null && _z !== void 0 ? _z : new retryTxSender_1.RetryTxSender({
|
|
147
151
|
connection: this.connection,
|
|
148
152
|
wallet: this.wallet,
|
|
149
153
|
opts: this.opts,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
|
|
1
|
+
import { Commitment, ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
|
|
2
2
|
import { IWallet, TxParams } from './types';
|
|
3
3
|
import { OracleInfo } from './oracles/types';
|
|
4
4
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
@@ -29,6 +29,7 @@ export type DriftClientConfig = {
|
|
|
29
29
|
export type DriftClientSubscriptionConfig = {
|
|
30
30
|
type: 'websocket';
|
|
31
31
|
resubTimeoutMs?: number;
|
|
32
|
+
commitment?: Commitment;
|
|
32
33
|
} | {
|
|
33
34
|
type: 'polling';
|
|
34
35
|
accountLoader: BulkAccountLoader;
|
package/lib/idl/drift.json
CHANGED
package/lib/user.js
CHANGED
|
@@ -22,7 +22,7 @@ class User {
|
|
|
22
22
|
this._isSubscribed = val;
|
|
23
23
|
}
|
|
24
24
|
constructor(config) {
|
|
25
|
-
var _a, _b;
|
|
25
|
+
var _a, _b, _c;
|
|
26
26
|
this._isSubscribed = false;
|
|
27
27
|
this.driftClient = config.driftClient;
|
|
28
28
|
this.userAccountPublicKey = config.userAccountPublicKey;
|
|
@@ -32,8 +32,8 @@ class User {
|
|
|
32
32
|
else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === 'custom') {
|
|
33
33
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|
|
34
34
|
}
|
|
35
|
-
else {
|
|
36
|
-
this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey);
|
|
35
|
+
else if (((_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.type) === 'websocket') {
|
|
36
|
+
this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey, config.accountSubscription.resubTimeoutMs, config.accountSubscription.commitment);
|
|
37
37
|
}
|
|
38
38
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
39
39
|
}
|
package/lib/userConfig.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
4
|
import { UserAccountSubscriber } from './accounts/types';
|
|
5
5
|
export type UserConfig = {
|
|
@@ -9,6 +9,8 @@ export type UserConfig = {
|
|
|
9
9
|
};
|
|
10
10
|
export type UserSubscriptionConfig = {
|
|
11
11
|
type: 'websocket';
|
|
12
|
+
resubTimeoutMs?: number;
|
|
13
|
+
commitment?: Commitment;
|
|
12
14
|
} | {
|
|
13
15
|
type: 'polling';
|
|
14
16
|
accountLoader: BulkAccountLoader;
|
package/lib/userStats.js
CHANGED
|
@@ -7,17 +7,17 @@ const webSocketUserStatsAccountSubsriber_1 = require("./accounts/webSocketUserSt
|
|
|
7
7
|
const pda_1 = require("./addresses/pda");
|
|
8
8
|
class UserStats {
|
|
9
9
|
constructor(config) {
|
|
10
|
-
var _a, _b;
|
|
10
|
+
var _a, _b, _c;
|
|
11
11
|
this.driftClient = config.driftClient;
|
|
12
12
|
this.userStatsAccountPublicKey = config.userStatsAccountPublicKey;
|
|
13
13
|
if (((_a = config.accountSubscription) === null || _a === void 0 ? void 0 : _a.type) === 'polling') {
|
|
14
14
|
this.accountSubscriber = new pollingUserStatsAccountSubscriber_1.PollingUserStatsAccountSubscriber(config.driftClient.program, config.userStatsAccountPublicKey, config.accountSubscription.accountLoader);
|
|
15
15
|
}
|
|
16
|
-
else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === '
|
|
17
|
-
|
|
16
|
+
else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === 'websocket') {
|
|
17
|
+
this.accountSubscriber = new webSocketUserStatsAccountSubsriber_1.WebSocketUserStatsAccountSubscriber(config.driftClient.program, config.userStatsAccountPublicKey, config.accountSubscription.resubTimeoutMs, config.accountSubscription.commitment);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
|
|
20
|
+
throw new Error(`Unknown user stats account subscription type: ${(_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.type}`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
async subscribe(userStatsAccount) {
|
package/lib/userStatsConfig.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
4
|
export type UserStatsConfig = {
|
|
5
5
|
accountSubscription?: UserStatsSubscriptionConfig;
|
|
@@ -8,6 +8,8 @@ export type UserStatsConfig = {
|
|
|
8
8
|
};
|
|
9
9
|
export type UserStatsSubscriptionConfig = {
|
|
10
10
|
type: 'websocket';
|
|
11
|
+
resubTimeoutMs?: number;
|
|
12
|
+
commitment?: Commitment;
|
|
11
13
|
} | {
|
|
12
14
|
type: 'polling';
|
|
13
15
|
accountLoader: BulkAccountLoader;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataAndSlot, BufferAndSlot, AccountSubscriber } from './types';
|
|
2
2
|
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
3
|
-
import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { AccountInfo, Commitment, Context, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { capitalize } from './utils';
|
|
5
5
|
import * as Buffer from 'buffer';
|
|
6
6
|
|
|
@@ -14,6 +14,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
14
14
|
onChange: (data: T) => void;
|
|
15
15
|
listenerId?: number;
|
|
16
16
|
resubTimeoutMs?: number;
|
|
17
|
+
commitment?: Commitment;
|
|
17
18
|
isUnsubscribing = false;
|
|
18
19
|
|
|
19
20
|
timeoutId?: NodeJS.Timeout;
|
|
@@ -25,7 +26,8 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
25
26
|
program: Program,
|
|
26
27
|
accountPublicKey: PublicKey,
|
|
27
28
|
decodeBuffer?: (buffer: Buffer) => T,
|
|
28
|
-
resubTimeoutMs?: number
|
|
29
|
+
resubTimeoutMs?: number,
|
|
30
|
+
commitment?: Commitment
|
|
29
31
|
) {
|
|
30
32
|
this.accountName = accountName;
|
|
31
33
|
this.program = program;
|
|
@@ -33,6 +35,8 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
33
35
|
this.decodeBufferFn = decodeBuffer;
|
|
34
36
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
35
37
|
this.receivingData = false;
|
|
38
|
+
this.commitment =
|
|
39
|
+
commitment ?? (this.program.provider as AnchorProvider).opts.commitment;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
async subscribe(onChange: (data: T) => void): Promise<void> {
|
|
@@ -57,7 +61,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
57
61
|
this.handleRpcResponse(context, accountInfo);
|
|
58
62
|
}
|
|
59
63
|
},
|
|
60
|
-
|
|
64
|
+
this.commitment
|
|
61
65
|
);
|
|
62
66
|
|
|
63
67
|
if (this.resubTimeoutMs) {
|
|
@@ -8,13 +8,14 @@ import {
|
|
|
8
8
|
import { Program } from '@coral-xyz/anchor';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
|
-
import { PublicKey } from '@solana/web3.js';
|
|
11
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
12
12
|
import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
|
|
13
13
|
import { UserAccount } from '../types';
|
|
14
14
|
|
|
15
15
|
export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
16
16
|
isSubscribed: boolean;
|
|
17
17
|
reconnectTimeoutMs?: number;
|
|
18
|
+
commitment?: Commitment;
|
|
18
19
|
program: Program;
|
|
19
20
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
20
21
|
userAccountPublicKey: PublicKey;
|
|
@@ -24,13 +25,15 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
24
25
|
public constructor(
|
|
25
26
|
program: Program,
|
|
26
27
|
userAccountPublicKey: PublicKey,
|
|
27
|
-
reconnectTimeoutMs?: number
|
|
28
|
+
reconnectTimeoutMs?: number,
|
|
29
|
+
commitment?: Commitment
|
|
28
30
|
) {
|
|
29
31
|
this.isSubscribed = false;
|
|
30
32
|
this.program = program;
|
|
31
33
|
this.userAccountPublicKey = userAccountPublicKey;
|
|
32
34
|
this.eventEmitter = new EventEmitter();
|
|
33
35
|
this.reconnectTimeoutMs = reconnectTimeoutMs;
|
|
36
|
+
this.commitment = commitment;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
async subscribe(userAccount?: UserAccount): Promise<boolean> {
|
|
@@ -43,7 +46,8 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
43
46
|
this.program,
|
|
44
47
|
this.userAccountPublicKey,
|
|
45
48
|
undefined,
|
|
46
|
-
this.reconnectTimeoutMs
|
|
49
|
+
this.reconnectTimeoutMs,
|
|
50
|
+
this.commitment
|
|
47
51
|
);
|
|
48
52
|
|
|
49
53
|
if (userAccount) {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { Program } from '@coral-xyz/anchor';
|
|
9
9
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
|
-
import { PublicKey } from '@solana/web3.js';
|
|
11
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
12
12
|
import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
|
|
13
13
|
import { UserStatsAccount } from '../types';
|
|
14
14
|
|
|
@@ -17,6 +17,7 @@ export class WebSocketUserStatsAccountSubscriber
|
|
|
17
17
|
{
|
|
18
18
|
isSubscribed: boolean;
|
|
19
19
|
reconnectTimeoutMs?: number;
|
|
20
|
+
commitment?: Commitment;
|
|
20
21
|
program: Program;
|
|
21
22
|
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
22
23
|
userStatsAccountPublicKey: PublicKey;
|
|
@@ -26,13 +27,15 @@ export class WebSocketUserStatsAccountSubscriber
|
|
|
26
27
|
public constructor(
|
|
27
28
|
program: Program,
|
|
28
29
|
userStatsAccountPublicKey: PublicKey,
|
|
29
|
-
reconnectTimeoutMs?: number
|
|
30
|
+
reconnectTimeoutMs?: number,
|
|
31
|
+
commitment?: Commitment
|
|
30
32
|
) {
|
|
31
33
|
this.isSubscribed = false;
|
|
32
34
|
this.program = program;
|
|
33
35
|
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
34
36
|
this.eventEmitter = new EventEmitter();
|
|
35
37
|
this.reconnectTimeoutMs = reconnectTimeoutMs;
|
|
38
|
+
this.commitment = commitment;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
async subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean> {
|
|
@@ -45,7 +48,8 @@ export class WebSocketUserStatsAccountSubscriber
|
|
|
45
48
|
this.program,
|
|
46
49
|
this.userStatsAccountPublicKey,
|
|
47
50
|
undefined,
|
|
48
|
-
this.reconnectTimeoutMs
|
|
51
|
+
this.reconnectTimeoutMs,
|
|
52
|
+
this.commitment
|
|
49
53
|
);
|
|
50
54
|
|
|
51
55
|
if (userStatsAccount) {
|
package/src/driftClient.ts
CHANGED
|
@@ -235,9 +235,13 @@ export class DriftClient {
|
|
|
235
235
|
} else {
|
|
236
236
|
this.userAccountSubscriptionConfig = {
|
|
237
237
|
type: 'websocket',
|
|
238
|
+
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
239
|
+
commitment: config.accountSubscription?.commitment,
|
|
238
240
|
};
|
|
239
241
|
this.userStatsAccountSubscriptionConfig = {
|
|
240
242
|
type: 'websocket',
|
|
243
|
+
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
244
|
+
commitment: config.accountSubscription?.commitment,
|
|
241
245
|
};
|
|
242
246
|
}
|
|
243
247
|
|
package/src/driftClientConfig.ts
CHANGED
package/src/idl/drift.json
CHANGED
package/src/user.ts
CHANGED
|
@@ -109,10 +109,12 @@ export class User {
|
|
|
109
109
|
);
|
|
110
110
|
} else if (config.accountSubscription?.type === 'custom') {
|
|
111
111
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|
|
112
|
-
} else {
|
|
112
|
+
} else if (config.accountSubscription?.type === 'websocket') {
|
|
113
113
|
this.accountSubscriber = new WebSocketUserAccountSubscriber(
|
|
114
114
|
config.driftClient.program,
|
|
115
|
-
config.userAccountPublicKey
|
|
115
|
+
config.userAccountPublicKey,
|
|
116
|
+
config.accountSubscription.resubTimeoutMs,
|
|
117
|
+
config.accountSubscription.commitment
|
|
116
118
|
);
|
|
117
119
|
}
|
|
118
120
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
package/src/userConfig.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
4
|
import { UserAccountSubscriber } from './accounts/types';
|
|
5
5
|
|
|
@@ -12,6 +12,8 @@ export type UserConfig = {
|
|
|
12
12
|
export type UserSubscriptionConfig =
|
|
13
13
|
| {
|
|
14
14
|
type: 'websocket';
|
|
15
|
+
resubTimeoutMs?: number;
|
|
16
|
+
commitment?: Commitment;
|
|
15
17
|
}
|
|
16
18
|
| {
|
|
17
19
|
type: 'polling';
|
package/src/userStats.ts
CHANGED
|
@@ -25,14 +25,16 @@ export class UserStats {
|
|
|
25
25
|
config.userStatsAccountPublicKey,
|
|
26
26
|
config.accountSubscription.accountLoader
|
|
27
27
|
);
|
|
28
|
-
} else if (config.accountSubscription?.type === '
|
|
29
|
-
throw new Error(
|
|
30
|
-
'Custom account subscription not yet implemented for user stats'
|
|
31
|
-
);
|
|
32
|
-
} else {
|
|
28
|
+
} else if (config.accountSubscription?.type === 'websocket') {
|
|
33
29
|
this.accountSubscriber = new WebSocketUserStatsAccountSubscriber(
|
|
34
30
|
config.driftClient.program,
|
|
35
|
-
config.userStatsAccountPublicKey
|
|
31
|
+
config.userStatsAccountPublicKey,
|
|
32
|
+
config.accountSubscription.resubTimeoutMs,
|
|
33
|
+
config.accountSubscription.commitment
|
|
34
|
+
);
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Unknown user stats account subscription type: ${config.accountSubscription?.type}`
|
|
36
38
|
);
|
|
37
39
|
}
|
|
38
40
|
}
|
package/src/userStatsConfig.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
4
|
|
|
5
5
|
export type UserStatsConfig = {
|
|
@@ -11,6 +11,8 @@ export type UserStatsConfig = {
|
|
|
11
11
|
export type UserStatsSubscriptionConfig =
|
|
12
12
|
| {
|
|
13
13
|
type: 'websocket';
|
|
14
|
+
resubTimeoutMs?: number;
|
|
15
|
+
commitment?: Commitment;
|
|
14
16
|
}
|
|
15
17
|
| {
|
|
16
18
|
type: 'polling';
|