@drift-labs/sdk 2.105.0-beta.0 → 2.105.0-beta.2
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/browser/accounts/pollingDriftClientAccountSubscriber.js +0 -1
- package/lib/browser/driftClient.d.ts +1 -0
- package/lib/browser/driftClient.js +40 -40
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +0 -1
- package/lib/node/driftClient.d.ts +1 -0
- package/lib/node/driftClient.js +40 -40
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +0 -1
- package/src/driftClient.ts +5 -4
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.105.0-beta.
|
|
1
|
+
2.105.0-beta.2
|
|
@@ -244,7 +244,6 @@ class PollingDriftClientAccountSubscriber {
|
|
|
244
244
|
this.accountsToPoll.clear();
|
|
245
245
|
this.oraclesToPoll.clear();
|
|
246
246
|
this.isSubscribed = false;
|
|
247
|
-
this.accountLoader.accountsToLoad = new Map();
|
|
248
247
|
}
|
|
249
248
|
async addSpotMarket(marketIndex) {
|
|
250
249
|
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
@@ -92,11 +92,12 @@ class DriftClient {
|
|
|
92
92
|
this.mustIncludeSpotMarketIndexes = new Set();
|
|
93
93
|
this.connection = config.connection;
|
|
94
94
|
this.wallet = config.wallet;
|
|
95
|
+
this.env = (_a = config.env) !== null && _a !== void 0 ? _a : 'mainnet-beta';
|
|
95
96
|
this.opts = config.opts || {
|
|
96
97
|
...config_1.DEFAULT_CONFIRMATION_OPTS,
|
|
97
98
|
};
|
|
98
|
-
this.useHotWalletAdmin = (
|
|
99
|
-
if ((
|
|
99
|
+
this.useHotWalletAdmin = (_b = config.useHotWalletAdmin) !== null && _b !== void 0 ? _b : false;
|
|
100
|
+
if ((_c = config === null || config === void 0 ? void 0 : config.connection) === null || _c === void 0 ? void 0 : _c.commitment) {
|
|
100
101
|
// At the moment this ensures that our transaction simulations (which use Connection object) will use the same commitment level as our Transaction blockhashes (which use these opts)
|
|
101
102
|
this.opts.commitment = config.connection.commitment;
|
|
102
103
|
this.opts.preflightCommitment = config.connection.commitment;
|
|
@@ -104,17 +105,17 @@ class DriftClient {
|
|
|
104
105
|
this.provider = new anchor_1.AnchorProvider(config.connection,
|
|
105
106
|
// @ts-ignore
|
|
106
107
|
config.wallet, this.opts);
|
|
107
|
-
this.program = new anchor_1.Program(drift_json_1.default, (
|
|
108
|
-
this.authority = (
|
|
109
|
-
this.activeSubAccountId = (
|
|
110
|
-
this.skipLoadUsers = (
|
|
111
|
-
this.txVersion = (
|
|
108
|
+
this.program = new anchor_1.Program(drift_json_1.default, (_d = config.programID) !== null && _d !== void 0 ? _d : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
|
|
109
|
+
this.authority = (_e = config.authority) !== null && _e !== void 0 ? _e : this.wallet.publicKey;
|
|
110
|
+
this.activeSubAccountId = (_f = config.activeSubAccountId) !== null && _f !== void 0 ? _f : 0;
|
|
111
|
+
this.skipLoadUsers = (_g = config.skipLoadUsers) !== null && _g !== void 0 ? _g : false;
|
|
112
|
+
this.txVersion = (_h = config.txVersion) !== null && _h !== void 0 ? _h : 0;
|
|
112
113
|
this.txParams = {
|
|
113
|
-
computeUnits: (
|
|
114
|
-
computeUnitsPrice: (
|
|
114
|
+
computeUnits: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnits) !== null && _k !== void 0 ? _k : 600000,
|
|
115
|
+
computeUnitsPrice: (_m = (_l = config.txParams) === null || _l === void 0 ? void 0 : _l.computeUnitsPrice) !== null && _m !== void 0 ? _m : 0,
|
|
115
116
|
};
|
|
116
117
|
this.txHandler =
|
|
117
|
-
(
|
|
118
|
+
(_o = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _o !== void 0 ? _o : new txHandler_1.TxHandler({
|
|
118
119
|
connection: this.connection,
|
|
119
120
|
// @ts-ignore
|
|
120
121
|
wallet: this.provider.wallet,
|
|
@@ -140,8 +141,8 @@ class DriftClient {
|
|
|
140
141
|
: config.subAccountIds
|
|
141
142
|
? new Map([[this.authority.toString(), config.subAccountIds]])
|
|
142
143
|
: new Map();
|
|
143
|
-
this.includeDelegates = (
|
|
144
|
-
if (((
|
|
144
|
+
this.includeDelegates = (_p = config.includeDelegates) !== null && _p !== void 0 ? _p : false;
|
|
145
|
+
if (((_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.type) === 'polling') {
|
|
145
146
|
this.userAccountSubscriptionConfig = {
|
|
146
147
|
type: 'polling',
|
|
147
148
|
accountLoader: config.accountSubscription.accountLoader,
|
|
@@ -151,32 +152,32 @@ class DriftClient {
|
|
|
151
152
|
accountLoader: config.accountSubscription.accountLoader,
|
|
152
153
|
};
|
|
153
154
|
}
|
|
154
|
-
else if (((
|
|
155
|
+
else if (((_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.type) === 'grpc') {
|
|
155
156
|
this.userAccountSubscriptionConfig = {
|
|
156
157
|
type: 'grpc',
|
|
157
|
-
resubTimeoutMs: (
|
|
158
|
-
logResubMessages: (
|
|
159
|
-
grpcConfigs: (
|
|
158
|
+
resubTimeoutMs: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.resubTimeoutMs,
|
|
159
|
+
logResubMessages: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.logResubMessages,
|
|
160
|
+
grpcConfigs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.grpcConfigs,
|
|
160
161
|
};
|
|
161
162
|
this.userStatsAccountSubscriptionConfig = {
|
|
162
163
|
type: 'grpc',
|
|
163
|
-
grpcConfigs: (
|
|
164
|
-
resubTimeoutMs: (
|
|
165
|
-
logResubMessages: (
|
|
164
|
+
grpcConfigs: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.grpcConfigs,
|
|
165
|
+
resubTimeoutMs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.resubTimeoutMs,
|
|
166
|
+
logResubMessages: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.logResubMessages,
|
|
166
167
|
};
|
|
167
168
|
}
|
|
168
169
|
else {
|
|
169
170
|
this.userAccountSubscriptionConfig = {
|
|
170
171
|
type: 'websocket',
|
|
171
|
-
resubTimeoutMs: (
|
|
172
|
-
logResubMessages: (
|
|
173
|
-
commitment: (
|
|
172
|
+
resubTimeoutMs: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.resubTimeoutMs,
|
|
173
|
+
logResubMessages: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.logResubMessages,
|
|
174
|
+
commitment: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.commitment,
|
|
174
175
|
};
|
|
175
176
|
this.userStatsAccountSubscriptionConfig = {
|
|
176
177
|
type: 'websocket',
|
|
177
|
-
resubTimeoutMs: (
|
|
178
|
-
logResubMessages: (
|
|
179
|
-
commitment: (
|
|
178
|
+
resubTimeoutMs: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.resubTimeoutMs,
|
|
179
|
+
logResubMessages: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.logResubMessages,
|
|
180
|
+
commitment: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.commitment,
|
|
180
181
|
};
|
|
181
182
|
}
|
|
182
183
|
if (config.userStats) {
|
|
@@ -187,27 +188,27 @@ class DriftClient {
|
|
|
187
188
|
});
|
|
188
189
|
}
|
|
189
190
|
this.marketLookupTable = config.marketLookupTable;
|
|
190
|
-
if (
|
|
191
|
-
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[
|
|
191
|
+
if (!this.marketLookupTable) {
|
|
192
|
+
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[this.env].MARKET_LOOKUP_TABLE);
|
|
192
193
|
}
|
|
193
194
|
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
|
|
194
195
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
195
196
|
config.spotMarketIndexes === undefined &&
|
|
196
197
|
config.oracleInfos === undefined;
|
|
197
|
-
if (((
|
|
198
|
-
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (
|
|
198
|
+
if (((_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.type) === 'polling') {
|
|
199
|
+
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_5 = config.perpMarketIndexes) !== null && _5 !== void 0 ? _5 : [], (_6 = config.spotMarketIndexes) !== null && _6 !== void 0 ? _6 : [], (_7 = config.oracleInfos) !== null && _7 !== void 0 ? _7 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
|
|
199
200
|
}
|
|
200
|
-
else if (((
|
|
201
|
-
this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (
|
|
202
|
-
resubTimeoutMs: (
|
|
203
|
-
logResubMessages: (
|
|
201
|
+
else if (((_8 = config.accountSubscription) === null || _8 === void 0 ? void 0 : _8.type) === 'grpc') {
|
|
202
|
+
this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_9 = config.perpMarketIndexes) !== null && _9 !== void 0 ? _9 : [], (_10 = config.spotMarketIndexes) !== null && _10 !== void 0 ? _10 : [], (_11 = config.oracleInfos) !== null && _11 !== void 0 ? _11 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
203
|
+
resubTimeoutMs: (_12 = config.accountSubscription) === null || _12 === void 0 ? void 0 : _12.resubTimeoutMs,
|
|
204
|
+
logResubMessages: (_13 = config.accountSubscription) === null || _13 === void 0 ? void 0 : _13.logResubMessages,
|
|
204
205
|
});
|
|
205
206
|
}
|
|
206
207
|
else {
|
|
207
|
-
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (
|
|
208
|
-
resubTimeoutMs: (
|
|
209
|
-
logResubMessages: (
|
|
210
|
-
}, (
|
|
208
|
+
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_14 = config.perpMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.spotMarketIndexes) !== null && _15 !== void 0 ? _15 : [], (_16 = config.oracleInfos) !== null && _16 !== void 0 ? _16 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
209
|
+
resubTimeoutMs: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.resubTimeoutMs,
|
|
210
|
+
logResubMessages: (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.logResubMessages,
|
|
211
|
+
}, (_19 = config.accountSubscription) === null || _19 === void 0 ? void 0 : _19.commitment);
|
|
211
212
|
}
|
|
212
213
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
213
214
|
this.metricsEventEmitter = new events_1.EventEmitter();
|
|
@@ -215,14 +216,13 @@ class DriftClient {
|
|
|
215
216
|
this.enableMetricsEvents = true;
|
|
216
217
|
}
|
|
217
218
|
this.txSender =
|
|
218
|
-
(
|
|
219
|
+
(_20 = config.txSender) !== null && _20 !== void 0 ? _20 : new retryTxSender_1.RetryTxSender({
|
|
219
220
|
connection: this.connection,
|
|
220
221
|
wallet: this.wallet,
|
|
221
222
|
opts: this.opts,
|
|
222
223
|
txHandler: this.txHandler,
|
|
223
224
|
});
|
|
224
|
-
this.sbOnDemandProgramdId =
|
|
225
|
-
config_1.configs[(_20 = config.env) !== null && _20 !== void 0 ? _20 : 'mainnet-beta'].SB_ON_DEMAND_PID;
|
|
225
|
+
this.sbOnDemandProgramdId = config_1.configs[this.env].SB_ON_DEMAND_PID;
|
|
226
226
|
}
|
|
227
227
|
getUserMapKey(subAccountId, authority) {
|
|
228
228
|
return `${subAccountId}_${authority.toString()}`;
|
|
@@ -244,7 +244,6 @@ class PollingDriftClientAccountSubscriber {
|
|
|
244
244
|
this.accountsToPoll.clear();
|
|
245
245
|
this.oraclesToPoll.clear();
|
|
246
246
|
this.isSubscribed = false;
|
|
247
|
-
this.accountLoader.accountsToLoad = new Map();
|
|
248
247
|
}
|
|
249
248
|
async addSpotMarket(marketIndex) {
|
|
250
249
|
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
package/lib/node/driftClient.js
CHANGED
|
@@ -92,11 +92,12 @@ class DriftClient {
|
|
|
92
92
|
this.mustIncludeSpotMarketIndexes = new Set();
|
|
93
93
|
this.connection = config.connection;
|
|
94
94
|
this.wallet = config.wallet;
|
|
95
|
+
this.env = (_a = config.env) !== null && _a !== void 0 ? _a : 'mainnet-beta';
|
|
95
96
|
this.opts = config.opts || {
|
|
96
97
|
...config_1.DEFAULT_CONFIRMATION_OPTS,
|
|
97
98
|
};
|
|
98
|
-
this.useHotWalletAdmin = (
|
|
99
|
-
if ((
|
|
99
|
+
this.useHotWalletAdmin = (_b = config.useHotWalletAdmin) !== null && _b !== void 0 ? _b : false;
|
|
100
|
+
if ((_c = config === null || config === void 0 ? void 0 : config.connection) === null || _c === void 0 ? void 0 : _c.commitment) {
|
|
100
101
|
// At the moment this ensures that our transaction simulations (which use Connection object) will use the same commitment level as our Transaction blockhashes (which use these opts)
|
|
101
102
|
this.opts.commitment = config.connection.commitment;
|
|
102
103
|
this.opts.preflightCommitment = config.connection.commitment;
|
|
@@ -104,17 +105,17 @@ class DriftClient {
|
|
|
104
105
|
this.provider = new anchor_1.AnchorProvider(config.connection,
|
|
105
106
|
// @ts-ignore
|
|
106
107
|
config.wallet, this.opts);
|
|
107
|
-
this.program = new anchor_1.Program(drift_json_1.default, (
|
|
108
|
-
this.authority = (
|
|
109
|
-
this.activeSubAccountId = (
|
|
110
|
-
this.skipLoadUsers = (
|
|
111
|
-
this.txVersion = (
|
|
108
|
+
this.program = new anchor_1.Program(drift_json_1.default, (_d = config.programID) !== null && _d !== void 0 ? _d : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
|
|
109
|
+
this.authority = (_e = config.authority) !== null && _e !== void 0 ? _e : this.wallet.publicKey;
|
|
110
|
+
this.activeSubAccountId = (_f = config.activeSubAccountId) !== null && _f !== void 0 ? _f : 0;
|
|
111
|
+
this.skipLoadUsers = (_g = config.skipLoadUsers) !== null && _g !== void 0 ? _g : false;
|
|
112
|
+
this.txVersion = (_h = config.txVersion) !== null && _h !== void 0 ? _h : 0;
|
|
112
113
|
this.txParams = {
|
|
113
|
-
computeUnits: (
|
|
114
|
-
computeUnitsPrice: (
|
|
114
|
+
computeUnits: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnits) !== null && _k !== void 0 ? _k : 600000,
|
|
115
|
+
computeUnitsPrice: (_m = (_l = config.txParams) === null || _l === void 0 ? void 0 : _l.computeUnitsPrice) !== null && _m !== void 0 ? _m : 0,
|
|
115
116
|
};
|
|
116
117
|
this.txHandler =
|
|
117
|
-
(
|
|
118
|
+
(_o = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _o !== void 0 ? _o : new txHandler_1.TxHandler({
|
|
118
119
|
connection: this.connection,
|
|
119
120
|
// @ts-ignore
|
|
120
121
|
wallet: this.provider.wallet,
|
|
@@ -140,8 +141,8 @@ class DriftClient {
|
|
|
140
141
|
: config.subAccountIds
|
|
141
142
|
? new Map([[this.authority.toString(), config.subAccountIds]])
|
|
142
143
|
: new Map();
|
|
143
|
-
this.includeDelegates = (
|
|
144
|
-
if (((
|
|
144
|
+
this.includeDelegates = (_p = config.includeDelegates) !== null && _p !== void 0 ? _p : false;
|
|
145
|
+
if (((_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.type) === 'polling') {
|
|
145
146
|
this.userAccountSubscriptionConfig = {
|
|
146
147
|
type: 'polling',
|
|
147
148
|
accountLoader: config.accountSubscription.accountLoader,
|
|
@@ -151,32 +152,32 @@ class DriftClient {
|
|
|
151
152
|
accountLoader: config.accountSubscription.accountLoader,
|
|
152
153
|
};
|
|
153
154
|
}
|
|
154
|
-
else if (((
|
|
155
|
+
else if (((_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.type) === 'grpc') {
|
|
155
156
|
this.userAccountSubscriptionConfig = {
|
|
156
157
|
type: 'grpc',
|
|
157
|
-
resubTimeoutMs: (
|
|
158
|
-
logResubMessages: (
|
|
159
|
-
grpcConfigs: (
|
|
158
|
+
resubTimeoutMs: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.resubTimeoutMs,
|
|
159
|
+
logResubMessages: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.logResubMessages,
|
|
160
|
+
grpcConfigs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.grpcConfigs,
|
|
160
161
|
};
|
|
161
162
|
this.userStatsAccountSubscriptionConfig = {
|
|
162
163
|
type: 'grpc',
|
|
163
|
-
grpcConfigs: (
|
|
164
|
-
resubTimeoutMs: (
|
|
165
|
-
logResubMessages: (
|
|
164
|
+
grpcConfigs: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.grpcConfigs,
|
|
165
|
+
resubTimeoutMs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.resubTimeoutMs,
|
|
166
|
+
logResubMessages: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.logResubMessages,
|
|
166
167
|
};
|
|
167
168
|
}
|
|
168
169
|
else {
|
|
169
170
|
this.userAccountSubscriptionConfig = {
|
|
170
171
|
type: 'websocket',
|
|
171
|
-
resubTimeoutMs: (
|
|
172
|
-
logResubMessages: (
|
|
173
|
-
commitment: (
|
|
172
|
+
resubTimeoutMs: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.resubTimeoutMs,
|
|
173
|
+
logResubMessages: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.logResubMessages,
|
|
174
|
+
commitment: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.commitment,
|
|
174
175
|
};
|
|
175
176
|
this.userStatsAccountSubscriptionConfig = {
|
|
176
177
|
type: 'websocket',
|
|
177
|
-
resubTimeoutMs: (
|
|
178
|
-
logResubMessages: (
|
|
179
|
-
commitment: (
|
|
178
|
+
resubTimeoutMs: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.resubTimeoutMs,
|
|
179
|
+
logResubMessages: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.logResubMessages,
|
|
180
|
+
commitment: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.commitment,
|
|
180
181
|
};
|
|
181
182
|
}
|
|
182
183
|
if (config.userStats) {
|
|
@@ -187,27 +188,27 @@ class DriftClient {
|
|
|
187
188
|
});
|
|
188
189
|
}
|
|
189
190
|
this.marketLookupTable = config.marketLookupTable;
|
|
190
|
-
if (
|
|
191
|
-
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[
|
|
191
|
+
if (!this.marketLookupTable) {
|
|
192
|
+
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[this.env].MARKET_LOOKUP_TABLE);
|
|
192
193
|
}
|
|
193
194
|
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Unsubscribe;
|
|
194
195
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
195
196
|
config.spotMarketIndexes === undefined &&
|
|
196
197
|
config.oracleInfos === undefined;
|
|
197
|
-
if (((
|
|
198
|
-
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (
|
|
198
|
+
if (((_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.type) === 'polling') {
|
|
199
|
+
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_5 = config.perpMarketIndexes) !== null && _5 !== void 0 ? _5 : [], (_6 = config.spotMarketIndexes) !== null && _6 !== void 0 ? _6 : [], (_7 = config.oracleInfos) !== null && _7 !== void 0 ? _7 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
|
|
199
200
|
}
|
|
200
|
-
else if (((
|
|
201
|
-
this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (
|
|
202
|
-
resubTimeoutMs: (
|
|
203
|
-
logResubMessages: (
|
|
201
|
+
else if (((_8 = config.accountSubscription) === null || _8 === void 0 ? void 0 : _8.type) === 'grpc') {
|
|
202
|
+
this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_9 = config.perpMarketIndexes) !== null && _9 !== void 0 ? _9 : [], (_10 = config.spotMarketIndexes) !== null && _10 !== void 0 ? _10 : [], (_11 = config.oracleInfos) !== null && _11 !== void 0 ? _11 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
203
|
+
resubTimeoutMs: (_12 = config.accountSubscription) === null || _12 === void 0 ? void 0 : _12.resubTimeoutMs,
|
|
204
|
+
logResubMessages: (_13 = config.accountSubscription) === null || _13 === void 0 ? void 0 : _13.logResubMessages,
|
|
204
205
|
});
|
|
205
206
|
}
|
|
206
207
|
else {
|
|
207
|
-
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (
|
|
208
|
-
resubTimeoutMs: (
|
|
209
|
-
logResubMessages: (
|
|
210
|
-
}, (
|
|
208
|
+
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_14 = config.perpMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.spotMarketIndexes) !== null && _15 !== void 0 ? _15 : [], (_16 = config.oracleInfos) !== null && _16 !== void 0 ? _16 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
209
|
+
resubTimeoutMs: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.resubTimeoutMs,
|
|
210
|
+
logResubMessages: (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.logResubMessages,
|
|
211
|
+
}, (_19 = config.accountSubscription) === null || _19 === void 0 ? void 0 : _19.commitment);
|
|
211
212
|
}
|
|
212
213
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
213
214
|
this.metricsEventEmitter = new events_1.EventEmitter();
|
|
@@ -215,14 +216,13 @@ class DriftClient {
|
|
|
215
216
|
this.enableMetricsEvents = true;
|
|
216
217
|
}
|
|
217
218
|
this.txSender =
|
|
218
|
-
(
|
|
219
|
+
(_20 = config.txSender) !== null && _20 !== void 0 ? _20 : new retryTxSender_1.RetryTxSender({
|
|
219
220
|
connection: this.connection,
|
|
220
221
|
wallet: this.wallet,
|
|
221
222
|
opts: this.opts,
|
|
222
223
|
txHandler: this.txHandler,
|
|
223
224
|
});
|
|
224
|
-
this.sbOnDemandProgramdId =
|
|
225
|
-
config_1.configs[(_20 = config.env) !== null && _20 !== void 0 ? _20 : 'mainnet-beta'].SB_ON_DEMAND_PID;
|
|
225
|
+
this.sbOnDemandProgramdId = config_1.configs[this.env].SB_ON_DEMAND_PID;
|
|
226
226
|
}
|
|
227
227
|
getUserMapKey(subAccountId, authority) {
|
|
228
228
|
return `${subAccountId}_${authority.toString()}`;
|
package/package.json
CHANGED
|
@@ -402,7 +402,6 @@ export class PollingDriftClientAccountSubscriber
|
|
|
402
402
|
this.accountsToPoll.clear();
|
|
403
403
|
this.oraclesToPoll.clear();
|
|
404
404
|
this.isSubscribed = false;
|
|
405
|
-
this.accountLoader.accountsToLoad = new Map();
|
|
406
405
|
}
|
|
407
406
|
|
|
408
407
|
async addSpotMarket(marketIndex: number): Promise<boolean> {
|
package/src/driftClient.ts
CHANGED
|
@@ -201,6 +201,7 @@ export class DriftClient {
|
|
|
201
201
|
wallet: IWallet;
|
|
202
202
|
public program: Program;
|
|
203
203
|
provider: AnchorProvider;
|
|
204
|
+
env: DriftEnv;
|
|
204
205
|
opts?: ConfirmOptions;
|
|
205
206
|
useHotWalletAdmin?: boolean;
|
|
206
207
|
users = new Map<string, User>();
|
|
@@ -249,6 +250,7 @@ export class DriftClient {
|
|
|
249
250
|
public constructor(config: DriftClientConfig) {
|
|
250
251
|
this.connection = config.connection;
|
|
251
252
|
this.wallet = config.wallet;
|
|
253
|
+
this.env = config.env ?? 'mainnet-beta';
|
|
252
254
|
this.opts = config.opts || {
|
|
253
255
|
...DEFAULT_CONFIRMATION_OPTS,
|
|
254
256
|
};
|
|
@@ -369,9 +371,9 @@ export class DriftClient {
|
|
|
369
371
|
}
|
|
370
372
|
|
|
371
373
|
this.marketLookupTable = config.marketLookupTable;
|
|
372
|
-
if (
|
|
374
|
+
if (!this.marketLookupTable) {
|
|
373
375
|
this.marketLookupTable = new PublicKey(
|
|
374
|
-
configs[
|
|
376
|
+
configs[this.env].MARKET_LOOKUP_TABLE
|
|
375
377
|
);
|
|
376
378
|
}
|
|
377
379
|
|
|
@@ -437,8 +439,7 @@ export class DriftClient {
|
|
|
437
439
|
txHandler: this.txHandler,
|
|
438
440
|
});
|
|
439
441
|
|
|
440
|
-
this.sbOnDemandProgramdId =
|
|
441
|
-
configs[config.env ?? 'mainnet-beta'].SB_ON_DEMAND_PID;
|
|
442
|
+
this.sbOnDemandProgramdId = configs[this.env].SB_ON_DEMAND_PID;
|
|
442
443
|
}
|
|
443
444
|
|
|
444
445
|
public getUserMapKey(subAccountId: number, authority: PublicKey): string {
|