@drift-labs/sdk 2.96.0-beta.2 → 2.96.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/accounts/types.d.ts +0 -8
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +3 -3
- package/lib/accounts/webSocketProgramAccountSubscriber.d.ts +1 -1
- package/lib/driftClient.js +14 -35
- package/lib/driftClientConfig.d.ts +0 -6
- package/lib/orderSubscriber/OrderSubscriber.d.ts +1 -2
- package/lib/orderSubscriber/OrderSubscriber.js +4 -19
- package/lib/orderSubscriber/types.d.ts +0 -9
- package/lib/user.js +4 -11
- package/lib/userConfig.d.ts +1 -6
- package/lib/userMap/userMap.js +0 -14
- package/lib/userMap/userMapConfig.d.ts +0 -7
- package/lib/userStatsConfig.d.ts +0 -6
- package/package.json +1 -3
- package/src/accounts/types.ts +0 -9
- package/src/accounts/webSocketAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +3 -3
- package/src/accounts/webSocketProgramAccountSubscriber.ts +1 -1
- package/src/driftClient.ts +0 -28
- package/src/driftClientConfig.ts +0 -7
- package/src/orderSubscriber/OrderSubscriber.ts +1 -15
- package/src/orderSubscriber/types.ts +0 -10
- package/src/user.ts +0 -11
- package/src/userConfig.ts +1 -7
- package/src/userMap/userMap.ts +1 -17
- package/src/userMap/userMapConfig.ts +0 -8
- package/src/userStatsConfig.ts +0 -7
- package/lib/accounts/grpcAccountSubscriber.d.ts +0 -16
- package/lib/accounts/grpcAccountSubscriber.js +0 -155
- package/lib/accounts/grpcDriftClientAccountSubscriber.d.ts +0 -13
- package/lib/accounts/grpcDriftClientAccountSubscriber.js +0 -96
- package/lib/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +0 -10
- package/lib/accounts/grpcInsuranceFundStakeAccountSubscriber.js +0 -30
- package/lib/accounts/grpcProgramAccountSubscriber.d.ts +0 -19
- package/lib/accounts/grpcProgramAccountSubscriber.js +0 -161
- package/lib/accounts/grpcUserAccountSubscriber.d.ts +0 -10
- package/lib/accounts/grpcUserAccountSubscriber.js +0 -28
- package/lib/accounts/grpcUserStatsAccountSubscriber.d.ts +0 -10
- package/lib/accounts/grpcUserStatsAccountSubscriber.js +0 -28
- package/lib/orderSubscriber/grpcSubscription.d.ts +0 -25
- package/lib/orderSubscriber/grpcSubscription.js +0 -68
- package/lib/userMap/grpcSubscription.d.ts +0 -26
- package/lib/userMap/grpcSubscription.js +0 -42
- package/src/accounts/grpcAccountSubscriber.ts +0 -158
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +0 -196
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +0 -62
- package/src/accounts/grpcProgramAccountSubscriber.ts +0 -181
- package/src/accounts/grpcUserAccountSubscriber.ts +0 -48
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +0 -51
- package/src/orderSubscriber/grpcSubscription.ts +0 -126
- package/src/userMap/grpcSubscription.ts +0 -83
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.96.0-beta.
|
|
1
|
+
2.96.0-beta.3
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -6,8 +6,6 @@ import { EventEmitter } from 'events';
|
|
|
6
6
|
import { Context, PublicKey } from '@solana/web3.js';
|
|
7
7
|
import { Account } from '@solana/spl-token';
|
|
8
8
|
import { OracleInfo, OraclePriceData } from '..';
|
|
9
|
-
import { CommitmentLevel } from '@triton-one/yellowstone-grpc';
|
|
10
|
-
import { ChannelOptions } from '@grpc/grpc-js';
|
|
11
9
|
export interface AccountSubscriber<T> {
|
|
12
10
|
dataAndSlot?: DataAndSlot<T>;
|
|
13
11
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
@@ -142,9 +140,3 @@ export interface UserStatsAccountSubscriber {
|
|
|
142
140
|
unsubscribe(): Promise<void>;
|
|
143
141
|
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
144
142
|
}
|
|
145
|
-
export type GrpcConfigs = {
|
|
146
|
-
endpoint: string;
|
|
147
|
-
token: string;
|
|
148
|
-
commitmentLevel?: CommitmentLevel;
|
|
149
|
-
channelOptions?: ChannelOptions;
|
|
150
|
-
};
|
|
@@ -20,7 +20,7 @@ export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<
|
|
|
20
20
|
constructor(accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubOpts?: ResubOpts, commitment?: Commitment);
|
|
21
21
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
22
22
|
setData(data: T, slot?: number): void;
|
|
23
|
-
|
|
23
|
+
private setTimeout;
|
|
24
24
|
fetch(): Promise<void>;
|
|
25
25
|
handleRpcResponse(context: Context, accountInfo?: AccountInfo<Buffer>): void;
|
|
26
26
|
decodeBuffer(buffer: Buffer): T;
|
|
@@ -30,9 +30,9 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
30
30
|
initialPerpMarketAccountData: Map<number, PerpMarketAccount>;
|
|
31
31
|
initialSpotMarketAccountData: Map<number, SpotMarketAccount>;
|
|
32
32
|
initialOraclePriceData: Map<string, OraclePriceData>;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
private isSubscribing;
|
|
34
|
+
private subscriptionPromise;
|
|
35
|
+
private subscriptionPromiseResolver;
|
|
36
36
|
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, resubOpts?: ResubOpts, commitment?: Commitment);
|
|
37
37
|
subscribe(): Promise<boolean>;
|
|
38
38
|
setInitialData(): Promise<void>;
|
|
@@ -27,7 +27,7 @@ export declare class WebSocketProgramAccountSubscriber<T> implements ProgramAcco
|
|
|
27
27
|
commitment?: Commitment;
|
|
28
28
|
}, resubOpts?: ResubOpts);
|
|
29
29
|
subscribe(onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
|
|
30
|
-
|
|
30
|
+
private setTimeout;
|
|
31
31
|
handleRpcResponse(context: Context, keyedAccountInfo: KeyedAccountInfo): void;
|
|
32
32
|
unsubscribe(onResub?: boolean): Promise<void>;
|
|
33
33
|
}
|
package/lib/driftClient.js
CHANGED
|
@@ -68,7 +68,6 @@ const utils_2 = require("./tx/utils");
|
|
|
68
68
|
const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
|
|
69
69
|
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
|
70
70
|
const switchboard_on_demand_30_json_1 = __importDefault(require("./idl/switchboard_on_demand_30.json"));
|
|
71
|
-
const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
|
|
72
71
|
/**
|
|
73
72
|
* # DriftClient
|
|
74
73
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
@@ -81,7 +80,7 @@ class DriftClient {
|
|
|
81
80
|
this._isSubscribed = val;
|
|
82
81
|
}
|
|
83
82
|
constructor(config) {
|
|
84
|
-
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, _1, _2, _3, _4, _5, _6
|
|
83
|
+
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, _1, _2, _3, _4, _5, _6;
|
|
85
84
|
this.users = new Map();
|
|
86
85
|
this._isSubscribed = false;
|
|
87
86
|
this.perpMarketLastSlotCache = new Map();
|
|
@@ -144,32 +143,18 @@ class DriftClient {
|
|
|
144
143
|
accountLoader: config.accountSubscription.accountLoader,
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
|
-
else if (((_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.type) === 'grpc') {
|
|
148
|
-
this.userAccountSubscriptionConfig = {
|
|
149
|
-
type: 'grpc',
|
|
150
|
-
resubTimeoutMs: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.resubTimeoutMs,
|
|
151
|
-
logResubMessages: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.logResubMessages,
|
|
152
|
-
configs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.configs,
|
|
153
|
-
};
|
|
154
|
-
this.userStatsAccountSubscriptionConfig = {
|
|
155
|
-
type: 'grpc',
|
|
156
|
-
resubTimeoutMs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.resubTimeoutMs,
|
|
157
|
-
logResubMessages: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.logResubMessages,
|
|
158
|
-
configs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.configs,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
146
|
else {
|
|
162
147
|
this.userAccountSubscriptionConfig = {
|
|
163
148
|
type: 'websocket',
|
|
164
|
-
resubTimeoutMs: (
|
|
165
|
-
logResubMessages: (
|
|
166
|
-
commitment: (
|
|
149
|
+
resubTimeoutMs: (_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.resubTimeoutMs,
|
|
150
|
+
logResubMessages: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.logResubMessages,
|
|
151
|
+
commitment: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.commitment,
|
|
167
152
|
};
|
|
168
153
|
this.userStatsAccountSubscriptionConfig = {
|
|
169
154
|
type: 'websocket',
|
|
170
|
-
resubTimeoutMs: (
|
|
171
|
-
logResubMessages: (
|
|
172
|
-
commitment: (
|
|
155
|
+
resubTimeoutMs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.resubTimeoutMs,
|
|
156
|
+
logResubMessages: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.logResubMessages,
|
|
157
|
+
commitment: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.commitment,
|
|
173
158
|
};
|
|
174
159
|
}
|
|
175
160
|
if (config.userStats) {
|
|
@@ -186,20 +171,14 @@ class DriftClient {
|
|
|
186
171
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
187
172
|
config.spotMarketIndexes === undefined &&
|
|
188
173
|
config.oracleInfos === undefined;
|
|
189
|
-
if (((
|
|
190
|
-
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (
|
|
191
|
-
}
|
|
192
|
-
else if (((_7 = config.accountSubscription) === null || _7 === void 0 ? void 0 : _7.type) === 'grpc') {
|
|
193
|
-
this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.configs, this.program, (_8 = config.perpMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.spotMarketIndexes) !== null && _9 !== void 0 ? _9 : [], (_10 = config.oracleInfos) !== null && _10 !== void 0 ? _10 : [], noMarketsAndOraclesSpecified, {
|
|
194
|
-
resubTimeoutMs: (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.resubTimeoutMs,
|
|
195
|
-
logResubMessages: (_12 = config.accountSubscription) === null || _12 === void 0 ? void 0 : _12.logResubMessages,
|
|
196
|
-
});
|
|
174
|
+
if (((_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.type) === 'polling') {
|
|
175
|
+
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_x = config.perpMarketIndexes) !== null && _x !== void 0 ? _x : [], (_y = config.spotMarketIndexes) !== null && _y !== void 0 ? _y : [], (_z = config.oracleInfos) !== null && _z !== void 0 ? _z : [], noMarketsAndOraclesSpecified);
|
|
197
176
|
}
|
|
198
177
|
else {
|
|
199
|
-
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (
|
|
200
|
-
resubTimeoutMs: (
|
|
201
|
-
logResubMessages: (
|
|
202
|
-
}, (
|
|
178
|
+
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_0 = config.perpMarketIndexes) !== null && _0 !== void 0 ? _0 : [], (_1 = config.spotMarketIndexes) !== null && _1 !== void 0 ? _1 : [], (_2 = config.oracleInfos) !== null && _2 !== void 0 ? _2 : [], noMarketsAndOraclesSpecified, {
|
|
179
|
+
resubTimeoutMs: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.resubTimeoutMs,
|
|
180
|
+
logResubMessages: (_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.logResubMessages,
|
|
181
|
+
}, (_5 = config.accountSubscription) === null || _5 === void 0 ? void 0 : _5.commitment);
|
|
203
182
|
}
|
|
204
183
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
205
184
|
this.metricsEventEmitter = new events_1.EventEmitter();
|
|
@@ -207,7 +186,7 @@ class DriftClient {
|
|
|
207
186
|
this.enableMetricsEvents = true;
|
|
208
187
|
}
|
|
209
188
|
this.txSender =
|
|
210
|
-
(
|
|
189
|
+
(_6 = config.txSender) !== null && _6 !== void 0 ? _6 : new retryTxSender_1.RetryTxSender({
|
|
211
190
|
connection: this.connection,
|
|
212
191
|
wallet: this.wallet,
|
|
213
192
|
opts: this.opts,
|
|
@@ -5,7 +5,6 @@ import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
|
5
5
|
import { DriftEnv } from './config';
|
|
6
6
|
import { TxSender } from './tx/types';
|
|
7
7
|
import { TxHandler, TxHandlerConfig } from './tx/txHandler';
|
|
8
|
-
import { GrpcConfigs } from './accounts/types';
|
|
9
8
|
export type DriftClientConfig = {
|
|
10
9
|
connection: Connection;
|
|
11
10
|
wallet: IWallet;
|
|
@@ -39,9 +38,4 @@ export type DriftClientSubscriptionConfig = {
|
|
|
39
38
|
} | {
|
|
40
39
|
type: 'polling';
|
|
41
40
|
accountLoader: BulkAccountLoader;
|
|
42
|
-
} | {
|
|
43
|
-
type: 'grpc';
|
|
44
|
-
configs: GrpcConfigs;
|
|
45
|
-
resubTimeoutMs?: number;
|
|
46
|
-
logResubMessages?: boolean;
|
|
47
41
|
};
|
|
@@ -10,14 +10,13 @@ import { PollingSubscription } from './PollingSubscription';
|
|
|
10
10
|
import { WebsocketSubscription } from './WebsocketSubscription';
|
|
11
11
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
12
12
|
import { EventEmitter } from 'events';
|
|
13
|
-
import { grpcSubscription } from './grpcSubscription';
|
|
14
13
|
export declare class OrderSubscriber {
|
|
15
14
|
driftClient: DriftClient;
|
|
16
15
|
usersAccounts: Map<string, {
|
|
17
16
|
slot: number;
|
|
18
17
|
userAccount: UserAccount;
|
|
19
18
|
}>;
|
|
20
|
-
subscription: PollingSubscription | WebsocketSubscription
|
|
19
|
+
subscription: PollingSubscription | WebsocketSubscription;
|
|
21
20
|
commitment: Commitment;
|
|
22
21
|
eventEmitter: StrictEventEmitter<EventEmitter, OrderSubscriberEvents>;
|
|
23
22
|
fetchPromise?: Promise<void>;
|
|
@@ -10,10 +10,9 @@ const WebsocketSubscription_1 = require("./WebsocketSubscription");
|
|
|
10
10
|
const events_1 = require("events");
|
|
11
11
|
const index_1 = require("../index");
|
|
12
12
|
const user_1 = require("../decode/user");
|
|
13
|
-
const grpcSubscription_1 = require("./grpcSubscription");
|
|
14
13
|
class OrderSubscriber {
|
|
15
14
|
constructor(config) {
|
|
16
|
-
var _a, _b, _c
|
|
15
|
+
var _a, _b, _c;
|
|
17
16
|
this.usersAccounts = new Map();
|
|
18
17
|
this.driftClient = config.driftClient;
|
|
19
18
|
this.commitment = config.subscriptionConfig.commitment || 'processed';
|
|
@@ -23,34 +22,20 @@ class OrderSubscriber {
|
|
|
23
22
|
frequency: config.subscriptionConfig.frequency,
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
|
-
else if (config.subscriptionConfig.type === 'grpc') {
|
|
27
|
-
this.subscription = new grpcSubscription_1.grpcSubscription({
|
|
28
|
-
grpcConfigs: config.subscriptionConfig.configs,
|
|
29
|
-
orderSubscriber: this,
|
|
30
|
-
commitment: this.commitment,
|
|
31
|
-
skipInitialLoad: config.subscriptionConfig.skipInitialLoad,
|
|
32
|
-
resubOpts: {
|
|
33
|
-
resubTimeoutMs: (_a = config.subscriptionConfig) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs,
|
|
34
|
-
logResubMessages: (_b = config.subscriptionConfig) === null || _b === void 0 ? void 0 : _b.logResubMessages,
|
|
35
|
-
},
|
|
36
|
-
resyncIntervalMs: config.subscriptionConfig.resyncIntervalMs,
|
|
37
|
-
decoded: config.decodeData,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
25
|
else {
|
|
41
26
|
this.subscription = new WebsocketSubscription_1.WebsocketSubscription({
|
|
42
27
|
orderSubscriber: this,
|
|
43
28
|
commitment: this.commitment,
|
|
44
29
|
skipInitialLoad: config.subscriptionConfig.skipInitialLoad,
|
|
45
30
|
resubOpts: {
|
|
46
|
-
resubTimeoutMs: (
|
|
47
|
-
logResubMessages: (
|
|
31
|
+
resubTimeoutMs: (_a = config.subscriptionConfig) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs,
|
|
32
|
+
logResubMessages: (_b = config.subscriptionConfig) === null || _b === void 0 ? void 0 : _b.logResubMessages,
|
|
48
33
|
},
|
|
49
34
|
resyncIntervalMs: config.subscriptionConfig.resyncIntervalMs,
|
|
50
35
|
decoded: config.decodeData,
|
|
51
36
|
});
|
|
52
37
|
}
|
|
53
|
-
if ((
|
|
38
|
+
if ((_c = config.fastDecode) !== null && _c !== void 0 ? _c : true) {
|
|
54
39
|
this.decodeFn = (name, data) => (0, user_1.decodeUser)(data);
|
|
55
40
|
}
|
|
56
41
|
else {
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { Order, UserAccount } from '../types';
|
|
3
3
|
import { DriftClient } from '../driftClient';
|
|
4
|
-
import { GrpcConfigs } from '../accounts/types';
|
|
5
4
|
export type OrderSubscriberConfig = {
|
|
6
5
|
driftClient: DriftClient;
|
|
7
6
|
subscriptionConfig: {
|
|
8
7
|
type: 'polling';
|
|
9
8
|
frequency: number;
|
|
10
9
|
commitment?: Commitment;
|
|
11
|
-
} | {
|
|
12
|
-
type: 'grpc';
|
|
13
|
-
skipInitialLoad?: boolean;
|
|
14
|
-
resubTimeoutMs?: number;
|
|
15
|
-
logResubMessages?: boolean;
|
|
16
|
-
resyncIntervalMs?: number;
|
|
17
|
-
configs: GrpcConfigs;
|
|
18
|
-
commitment?: Commitment;
|
|
19
10
|
} | {
|
|
20
11
|
type: 'websocket';
|
|
21
12
|
skipInitialLoad?: boolean;
|
package/lib/user.js
CHANGED
|
@@ -15,7 +15,6 @@ const oracles_1 = require("./math/oracles");
|
|
|
15
15
|
const tiers_1 = require("./math/tiers");
|
|
16
16
|
const strictOraclePrice_1 = require("./oracles/strictOraclePrice");
|
|
17
17
|
const fuel_1 = require("./math/fuel");
|
|
18
|
-
const grpcUserAccountSubscriber_1 = require("./accounts/grpcUserAccountSubscriber");
|
|
19
18
|
class User {
|
|
20
19
|
get isSubscribed() {
|
|
21
20
|
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
@@ -24,7 +23,7 @@ class User {
|
|
|
24
23
|
this._isSubscribed = val;
|
|
25
24
|
}
|
|
26
25
|
constructor(config) {
|
|
27
|
-
var _a, _b, _c, _d, _e
|
|
26
|
+
var _a, _b, _c, _d, _e;
|
|
28
27
|
this._isSubscribed = false;
|
|
29
28
|
this.driftClient = config.driftClient;
|
|
30
29
|
this.userAccountPublicKey = config.userAccountPublicKey;
|
|
@@ -34,17 +33,11 @@ class User {
|
|
|
34
33
|
else if (((_b = config.accountSubscription) === null || _b === void 0 ? void 0 : _b.type) === 'custom') {
|
|
35
34
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|
|
36
35
|
}
|
|
37
|
-
else if (((_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.type) === 'grpc') {
|
|
38
|
-
this.accountSubscriber = new grpcUserAccountSubscriber_1.grpcUserAccountSubscriber(config.accountSubscription.configs, config.driftClient.program, config.userAccountPublicKey, {
|
|
39
|
-
resubTimeoutMs: (_d = config.accountSubscription) === null || _d === void 0 ? void 0 : _d.resubTimeoutMs,
|
|
40
|
-
logResubMessages: (_e = config.accountSubscription) === null || _e === void 0 ? void 0 : _e.logResubMessages,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
36
|
else {
|
|
44
37
|
this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey, {
|
|
45
|
-
resubTimeoutMs: (
|
|
46
|
-
logResubMessages: (
|
|
47
|
-
}, (
|
|
38
|
+
resubTimeoutMs: (_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.resubTimeoutMs,
|
|
39
|
+
logResubMessages: (_d = config.accountSubscription) === null || _d === void 0 ? void 0 : _d.logResubMessages,
|
|
40
|
+
}, (_e = config.accountSubscription) === null || _e === void 0 ? void 0 : _e.commitment);
|
|
48
41
|
}
|
|
49
42
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
50
43
|
}
|
package/lib/userConfig.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
2
|
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
|
-
import {
|
|
4
|
+
import { UserAccountSubscriber } from './accounts/types';
|
|
5
5
|
export type UserConfig = {
|
|
6
6
|
accountSubscription?: UserSubscriptionConfig;
|
|
7
7
|
driftClient: DriftClient;
|
|
@@ -18,9 +18,4 @@ export type UserSubscriptionConfig = {
|
|
|
18
18
|
} | {
|
|
19
19
|
type: 'custom';
|
|
20
20
|
userAccountSubscriber: UserAccountSubscriber;
|
|
21
|
-
} | {
|
|
22
|
-
type: 'grpc';
|
|
23
|
-
resubTimeoutMs?: number;
|
|
24
|
-
logResubMessages?: boolean;
|
|
25
|
-
configs: GrpcConfigs;
|
|
26
21
|
};
|
package/lib/userMap/userMap.js
CHANGED
|
@@ -9,7 +9,6 @@ const memcmp_1 = require("../memcmp");
|
|
|
9
9
|
const WebsocketSubscription_1 = require("./WebsocketSubscription");
|
|
10
10
|
const PollingSubscription_1 = require("./PollingSubscription");
|
|
11
11
|
const user_1 = require("../decode/user");
|
|
12
|
-
const grpcSubscription_1 = require("./grpcSubscription");
|
|
13
12
|
const MAX_USER_ACCOUNT_SIZE_BYTES = 4376;
|
|
14
13
|
class UserMap {
|
|
15
14
|
/**
|
|
@@ -53,19 +52,6 @@ class UserMap {
|
|
|
53
52
|
skipInitialLoad: config.skipInitialLoad,
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
|
-
else if (config.subscriptionConfig.type === 'grpc') {
|
|
57
|
-
this.subscription = new grpcSubscription_1.grpcSubscription({
|
|
58
|
-
configs: config.subscriptionConfig.configs,
|
|
59
|
-
userMap: this,
|
|
60
|
-
commitment: this.commitment,
|
|
61
|
-
resubOpts: {
|
|
62
|
-
resubTimeoutMs: config.subscriptionConfig.resubTimeoutMs,
|
|
63
|
-
logResubMessages: config.subscriptionConfig.logResubMessages,
|
|
64
|
-
},
|
|
65
|
-
skipInitialLoad: config.skipInitialLoad,
|
|
66
|
-
decodeFn,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
55
|
else {
|
|
70
56
|
this.subscription = new WebsocketSubscription_1.WebsocketSubscription({
|
|
71
57
|
userMap: this,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Commitment, Connection } from '@solana/web3.js';
|
|
2
2
|
import { DriftClient } from '../driftClient';
|
|
3
|
-
import { GrpcConfigs } from '../accounts/types';
|
|
4
3
|
export type UserAccountFilterCriteria = {
|
|
5
4
|
hasOpenOrders: boolean;
|
|
6
5
|
};
|
|
@@ -18,12 +17,6 @@ export type UserMapConfig = {
|
|
|
18
17
|
type: 'polling';
|
|
19
18
|
frequency: number;
|
|
20
19
|
commitment?: Commitment;
|
|
21
|
-
} | {
|
|
22
|
-
type: 'grpc';
|
|
23
|
-
configs: GrpcConfigs;
|
|
24
|
-
resubTimeoutMs?: number;
|
|
25
|
-
logResubMessages?: boolean;
|
|
26
|
-
commitment?: Commitment;
|
|
27
20
|
} | {
|
|
28
21
|
type: 'websocket';
|
|
29
22
|
resubTimeoutMs?: number;
|
package/lib/userStatsConfig.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
2
|
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
|
-
import { GrpcConfigs } from './accounts/types';
|
|
5
4
|
export type UserStatsConfig = {
|
|
6
5
|
accountSubscription?: UserStatsSubscriptionConfig;
|
|
7
6
|
driftClient: DriftClient;
|
|
@@ -17,9 +16,4 @@ export type UserStatsSubscriptionConfig = {
|
|
|
17
16
|
accountLoader: BulkAccountLoader;
|
|
18
17
|
} | {
|
|
19
18
|
type: 'custom';
|
|
20
|
-
} | {
|
|
21
|
-
type: 'grpc';
|
|
22
|
-
resubTimeoutMs?: number;
|
|
23
|
-
logResubMessages?: boolean;
|
|
24
|
-
configs: GrpcConfigs;
|
|
25
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.96.0-beta.
|
|
3
|
+
"version": "2.96.0-beta.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"@coral-xyz/anchor": "0.28.0",
|
|
38
38
|
"@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1",
|
|
39
39
|
"@ellipsis-labs/phoenix-sdk": "^1.4.2",
|
|
40
|
-
"@grpc/grpc-js": "^1.11.2",
|
|
41
40
|
"@openbook-dex/openbook-v2": "^0.2.10",
|
|
42
41
|
"@project-serum/serum": "^0.13.38",
|
|
43
42
|
"@pythnetwork/client": "2.5.3",
|
|
@@ -46,7 +45,6 @@
|
|
|
46
45
|
"@solana/spl-token": "0.3.7",
|
|
47
46
|
"@solana/web3.js": "1.92.3",
|
|
48
47
|
"@switchboard-xyz/on-demand": "1.2.32",
|
|
49
|
-
"@triton-one/yellowstone-grpc": "^0.6.0",
|
|
50
48
|
"anchor-bankrun": "^0.3.0",
|
|
51
49
|
"node-cache": "^5.1.2",
|
|
52
50
|
"rpc-websockets": "7.5.1",
|
package/src/accounts/types.ts
CHANGED
|
@@ -12,8 +12,6 @@ import { EventEmitter } from 'events';
|
|
|
12
12
|
import { Context, PublicKey } from '@solana/web3.js';
|
|
13
13
|
import { Account } from '@solana/spl-token';
|
|
14
14
|
import { OracleInfo, OraclePriceData } from '..';
|
|
15
|
-
import { CommitmentLevel } from '@triton-one/yellowstone-grpc';
|
|
16
|
-
import { ChannelOptions } from '@grpc/grpc-js';
|
|
17
15
|
|
|
18
16
|
export interface AccountSubscriber<T> {
|
|
19
17
|
dataAndSlot?: DataAndSlot<T>;
|
|
@@ -203,10 +201,3 @@ export interface UserStatsAccountSubscriber {
|
|
|
203
201
|
|
|
204
202
|
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
205
203
|
}
|
|
206
|
-
|
|
207
|
-
export type GrpcConfigs = {
|
|
208
|
-
endpoint: string;
|
|
209
|
-
token: string;
|
|
210
|
-
commitmentLevel?: CommitmentLevel;
|
|
211
|
-
channelOptions?: ChannelOptions;
|
|
212
|
-
};
|
|
@@ -60,9 +60,9 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
60
60
|
initialSpotMarketAccountData: Map<number, SpotMarketAccount>;
|
|
61
61
|
initialOraclePriceData: Map<string, OraclePriceData>;
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
private isSubscribing = false;
|
|
64
|
+
private subscriptionPromise: Promise<boolean>;
|
|
65
|
+
private subscriptionPromiseResolver: (val: boolean) => void;
|
|
66
66
|
|
|
67
67
|
public constructor(
|
|
68
68
|
program: Program,
|
package/src/driftClient.ts
CHANGED
|
@@ -152,7 +152,6 @@ import { isVersionedTransaction } from './tx/utils';
|
|
|
152
152
|
import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
|
|
153
153
|
import { asV0Tx, PullFeed } from '@switchboard-xyz/on-demand';
|
|
154
154
|
import switchboardOnDemandIdl from './idl/switchboard_on_demand_30.json';
|
|
155
|
-
import { gprcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
|
|
156
155
|
|
|
157
156
|
type RemainingAccountParams = {
|
|
158
157
|
userAccounts: UserAccount[];
|
|
@@ -293,19 +292,6 @@ export class DriftClient {
|
|
|
293
292
|
type: 'polling',
|
|
294
293
|
accountLoader: config.accountSubscription.accountLoader,
|
|
295
294
|
};
|
|
296
|
-
} else if (config.accountSubscription?.type === 'grpc') {
|
|
297
|
-
this.userAccountSubscriptionConfig = {
|
|
298
|
-
type: 'grpc',
|
|
299
|
-
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
300
|
-
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
301
|
-
configs: config.accountSubscription?.configs,
|
|
302
|
-
};
|
|
303
|
-
this.userStatsAccountSubscriptionConfig = {
|
|
304
|
-
type: 'grpc',
|
|
305
|
-
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
306
|
-
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
307
|
-
configs: config.accountSubscription?.configs,
|
|
308
|
-
};
|
|
309
295
|
} else {
|
|
310
296
|
this.userAccountSubscriptionConfig = {
|
|
311
297
|
type: 'websocket',
|
|
@@ -352,19 +338,6 @@ export class DriftClient {
|
|
|
352
338
|
config.oracleInfos ?? [],
|
|
353
339
|
noMarketsAndOraclesSpecified
|
|
354
340
|
);
|
|
355
|
-
} else if (config.accountSubscription?.type === 'grpc') {
|
|
356
|
-
this.accountSubscriber = new gprcDriftClientAccountSubscriber(
|
|
357
|
-
config.accountSubscription.configs,
|
|
358
|
-
this.program,
|
|
359
|
-
config.perpMarketIndexes ?? [],
|
|
360
|
-
config.spotMarketIndexes ?? [],
|
|
361
|
-
config.oracleInfos ?? [],
|
|
362
|
-
noMarketsAndOraclesSpecified,
|
|
363
|
-
{
|
|
364
|
-
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
365
|
-
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
366
|
-
}
|
|
367
|
-
);
|
|
368
341
|
} else {
|
|
369
342
|
this.accountSubscriber = new WebSocketDriftClientAccountSubscriber(
|
|
370
343
|
this.program,
|
|
@@ -379,7 +352,6 @@ export class DriftClient {
|
|
|
379
352
|
config.accountSubscription?.commitment
|
|
380
353
|
);
|
|
381
354
|
}
|
|
382
|
-
|
|
383
355
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
384
356
|
|
|
385
357
|
this.metricsEventEmitter = new EventEmitter();
|
package/src/driftClientConfig.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
|
11
11
|
import { DriftEnv } from './config';
|
|
12
12
|
import { TxSender } from './tx/types';
|
|
13
13
|
import { TxHandler, TxHandlerConfig } from './tx/txHandler';
|
|
14
|
-
import { GrpcConfigs } from './accounts/types';
|
|
15
14
|
|
|
16
15
|
export type DriftClientConfig = {
|
|
17
16
|
connection: Connection;
|
|
@@ -49,10 +48,4 @@ export type DriftClientSubscriptionConfig =
|
|
|
49
48
|
| {
|
|
50
49
|
type: 'polling';
|
|
51
50
|
accountLoader: BulkAccountLoader;
|
|
52
|
-
}
|
|
53
|
-
| {
|
|
54
|
-
type: 'grpc';
|
|
55
|
-
configs: GrpcConfigs;
|
|
56
|
-
resubTimeoutMs?: number;
|
|
57
|
-
logResubMessages?: boolean;
|
|
58
51
|
};
|
|
@@ -11,12 +11,11 @@ import StrictEventEmitter from 'strict-event-emitter-types';
|
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
12
12
|
import { BN } from '../index';
|
|
13
13
|
import { decodeUser } from '../decode/user';
|
|
14
|
-
import { grpcSubscription } from './grpcSubscription';
|
|
15
14
|
|
|
16
15
|
export class OrderSubscriber {
|
|
17
16
|
driftClient: DriftClient;
|
|
18
17
|
usersAccounts = new Map<string, { slot: number; userAccount: UserAccount }>();
|
|
19
|
-
subscription: PollingSubscription | WebsocketSubscription
|
|
18
|
+
subscription: PollingSubscription | WebsocketSubscription;
|
|
20
19
|
commitment: Commitment;
|
|
21
20
|
eventEmitter: StrictEventEmitter<EventEmitter, OrderSubscriberEvents>;
|
|
22
21
|
|
|
@@ -35,19 +34,6 @@ export class OrderSubscriber {
|
|
|
35
34
|
orderSubscriber: this,
|
|
36
35
|
frequency: config.subscriptionConfig.frequency,
|
|
37
36
|
});
|
|
38
|
-
} else if (config.subscriptionConfig.type === 'grpc') {
|
|
39
|
-
this.subscription = new grpcSubscription({
|
|
40
|
-
grpcConfigs: config.subscriptionConfig.configs,
|
|
41
|
-
orderSubscriber: this,
|
|
42
|
-
commitment: this.commitment,
|
|
43
|
-
skipInitialLoad: config.subscriptionConfig.skipInitialLoad,
|
|
44
|
-
resubOpts: {
|
|
45
|
-
resubTimeoutMs: config.subscriptionConfig?.resubTimeoutMs,
|
|
46
|
-
logResubMessages: config.subscriptionConfig?.logResubMessages,
|
|
47
|
-
},
|
|
48
|
-
resyncIntervalMs: config.subscriptionConfig.resyncIntervalMs,
|
|
49
|
-
decoded: config.decodeData,
|
|
50
|
-
});
|
|
51
37
|
} else {
|
|
52
38
|
this.subscription = new WebsocketSubscription({
|
|
53
39
|
orderSubscriber: this,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { Order, UserAccount } from '../types';
|
|
3
3
|
import { DriftClient } from '../driftClient';
|
|
4
|
-
import { GrpcConfigs } from '../accounts/types';
|
|
5
4
|
|
|
6
5
|
export type OrderSubscriberConfig = {
|
|
7
6
|
driftClient: DriftClient;
|
|
@@ -11,15 +10,6 @@ export type OrderSubscriberConfig = {
|
|
|
11
10
|
frequency: number;
|
|
12
11
|
commitment?: Commitment;
|
|
13
12
|
}
|
|
14
|
-
| {
|
|
15
|
-
type: 'grpc';
|
|
16
|
-
skipInitialLoad?: boolean;
|
|
17
|
-
resubTimeoutMs?: number;
|
|
18
|
-
logResubMessages?: boolean;
|
|
19
|
-
resyncIntervalMs?: number;
|
|
20
|
-
configs: GrpcConfigs;
|
|
21
|
-
commitment?: Commitment;
|
|
22
|
-
}
|
|
23
13
|
| {
|
|
24
14
|
type: 'websocket';
|
|
25
15
|
skipInitialLoad?: boolean;
|
package/src/user.ts
CHANGED
|
@@ -98,7 +98,6 @@ import {
|
|
|
98
98
|
calculatePerpFuelBonus,
|
|
99
99
|
calculateInsuranceFuelBonus,
|
|
100
100
|
} from './math/fuel';
|
|
101
|
-
import { grpcUserAccountSubscriber } from './accounts/grpcUserAccountSubscriber';
|
|
102
101
|
|
|
103
102
|
export class User {
|
|
104
103
|
driftClient: DriftClient;
|
|
@@ -129,16 +128,6 @@ export class User {
|
|
|
129
128
|
);
|
|
130
129
|
} else if (config.accountSubscription?.type === 'custom') {
|
|
131
130
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|
|
132
|
-
} else if (config.accountSubscription?.type === 'grpc') {
|
|
133
|
-
this.accountSubscriber = new grpcUserAccountSubscriber(
|
|
134
|
-
config.accountSubscription.configs,
|
|
135
|
-
config.driftClient.program,
|
|
136
|
-
config.userAccountPublicKey,
|
|
137
|
-
{
|
|
138
|
-
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
139
|
-
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
131
|
} else {
|
|
143
132
|
this.accountSubscriber = new WebSocketUserAccountSubscriber(
|
|
144
133
|
config.driftClient.program,
|
package/src/userConfig.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DriftClient } from './driftClient';
|
|
2
2
|
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
|
-
import {
|
|
4
|
+
import { UserAccountSubscriber } from './accounts/types';
|
|
5
5
|
|
|
6
6
|
export type UserConfig = {
|
|
7
7
|
accountSubscription?: UserSubscriptionConfig;
|
|
@@ -23,10 +23,4 @@ export type UserSubscriptionConfig =
|
|
|
23
23
|
| {
|
|
24
24
|
type: 'custom';
|
|
25
25
|
userAccountSubscriber: UserAccountSubscriber;
|
|
26
|
-
}
|
|
27
|
-
| {
|
|
28
|
-
type: 'grpc';
|
|
29
|
-
resubTimeoutMs?: number;
|
|
30
|
-
logResubMessages?: boolean;
|
|
31
|
-
configs: GrpcConfigs;
|
|
32
26
|
};
|