@drift-labs/sdk 2.103.0-beta.7 → 2.103.0-beta.8
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/grpcDriftClientAccountSubscriber.js +4 -5
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/browser/accounts/pollingDriftClientAccountSubscriber.js +27 -30
- package/lib/browser/accounts/types.d.ts +2 -2
- package/lib/browser/accounts/utils.d.ts +2 -2
- package/lib/browser/accounts/utils.js +3 -13
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +25 -31
- package/lib/browser/config.js +4 -5
- package/lib/browser/driftClient.d.ts +2 -2
- package/lib/browser/driftClient.js +2 -3
- package/lib/browser/types.d.ts +0 -14
- package/lib/browser/types.js +1 -16
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.js +4 -5
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +27 -30
- package/lib/node/accounts/types.d.ts +2 -2
- package/lib/node/accounts/utils.d.ts +2 -2
- package/lib/node/accounts/utils.js +3 -13
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +25 -31
- package/lib/node/config.js +4 -5
- package/lib/node/driftClient.d.ts +2 -2
- package/lib/node/driftClient.js +2 -3
- package/lib/node/types.d.ts +0 -14
- package/lib/node/types.js +1 -16
- package/package.json +1 -1
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +4 -10
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +33 -47
- package/src/accounts/types.ts +2 -6
- package/src/accounts/utils.ts +6 -23
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +27 -39
- package/src/config.ts +7 -11
- package/src/driftClient.ts +2 -5
- package/src/types.ts +0 -15
- package/lib/browser/oracles/oracleId.d.ts +0 -4
- package/lib/browser/oracles/oracleId.js +0 -36
- package/lib/node/oracles/oracleId.d.ts +0 -4
- package/lib/node/oracles/oracleId.js +0 -36
- package/src/oracles/oracleId.ts +0 -27
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.103.0-beta.
|
|
1
|
+
2.103.0-beta.8
|
|
@@ -5,7 +5,6 @@ const webSocketDriftClientAccountSubscriber_1 = require("./webSocketDriftClientA
|
|
|
5
5
|
const config_1 = require("../config");
|
|
6
6
|
const pda_1 = require("../addresses/pda");
|
|
7
7
|
const grpcAccountSubscriber_1 = require("./grpcAccountSubscriber");
|
|
8
|
-
const oracleId_1 = require("../oracles/oracleId");
|
|
9
8
|
class gprcDriftClientAccountSubscriber extends webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber {
|
|
10
9
|
constructor(grpcConfigs, program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts) {
|
|
11
10
|
super(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts);
|
|
@@ -81,17 +80,17 @@ class gprcDriftClientAccountSubscriber extends webSocketDriftClientAccountSubscr
|
|
|
81
80
|
return true;
|
|
82
81
|
}
|
|
83
82
|
async subscribeToOracle(oracleInfo) {
|
|
84
|
-
const
|
|
83
|
+
const oracleString = oracleInfo.publicKey.toString();
|
|
85
84
|
const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection, this.program);
|
|
86
85
|
const accountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'oracle', this.program, oracleInfo.publicKey, (buffer) => {
|
|
87
86
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
88
87
|
}, this.resubOpts);
|
|
89
|
-
accountSubscriber.setData(this.initialOraclePriceData.get(
|
|
88
|
+
accountSubscriber.setData(this.initialOraclePriceData.get(oracleString));
|
|
90
89
|
await accountSubscriber.subscribe((data) => {
|
|
91
|
-
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey,
|
|
90
|
+
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey, data);
|
|
92
91
|
this.eventEmitter.emit('update');
|
|
93
92
|
});
|
|
94
|
-
this.oracleSubscribers.set(
|
|
93
|
+
this.oracleSubscribers.set(oracleString, accountSubscriber);
|
|
95
94
|
return true;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -62,7 +62,7 @@ export declare class PollingDriftClientAccountSubscriber implements DriftClientA
|
|
|
62
62
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
63
63
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
64
64
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
65
|
-
getOraclePriceDataAndSlot(
|
|
65
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey | string): DataAndSlot<OraclePriceData> | undefined;
|
|
66
66
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
67
67
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
68
68
|
updateAccountLoaderPollingFrequency(pollingFrequency: number): void;
|
|
@@ -3,15 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PollingDriftClientAccountSubscriber = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const events_1 = require("events");
|
|
6
|
-
const types_2 = require("../types");
|
|
7
6
|
const pda_1 = require("../addresses/pda");
|
|
8
7
|
const utils_1 = require("./utils");
|
|
9
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
10
9
|
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
11
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
12
11
|
const config_1 = require("../config");
|
|
13
|
-
const
|
|
14
|
-
const ORACLE_DEFAULT_ID = (0, oracleId_1.getOracleId)(web3_js_1.PublicKey.default, types_2.OracleSource.QUOTE_ASSET);
|
|
12
|
+
const ORACLE_DEFAULT_KEY = web3_js_1.PublicKey.default.toBase58();
|
|
15
13
|
class PollingDriftClientAccountSubscriber {
|
|
16
14
|
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting) {
|
|
17
15
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
@@ -128,7 +126,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
128
126
|
return true;
|
|
129
127
|
}
|
|
130
128
|
addOracleToPoll(oracleInfo) {
|
|
131
|
-
this.oraclesToPoll.set(
|
|
129
|
+
this.oraclesToPoll.set(oracleInfo.publicKey.toString(), {
|
|
132
130
|
publicKey: oracleInfo.publicKey,
|
|
133
131
|
source: oracleInfo.source,
|
|
134
132
|
});
|
|
@@ -173,7 +171,6 @@ class PollingDriftClientAccountSubscriber {
|
|
|
173
171
|
}
|
|
174
172
|
async addOracleToAccountLoader(oracleToPoll) {
|
|
175
173
|
const oracleClient = this.oracleClientCache.get(oracleToPoll.source, this.program.provider.connection, this.program);
|
|
176
|
-
const oracleId = (0, oracleId_1.getOracleId)(oracleToPoll.publicKey, oracleToPoll.source);
|
|
177
174
|
oracleToPoll.callbackId = await this.accountLoader.addAccount(oracleToPoll.publicKey, (buffer, slot) => {
|
|
178
175
|
if (!buffer)
|
|
179
176
|
return;
|
|
@@ -182,8 +179,8 @@ class PollingDriftClientAccountSubscriber {
|
|
|
182
179
|
data: oraclePriceData,
|
|
183
180
|
slot,
|
|
184
181
|
};
|
|
185
|
-
this.oracles.set(
|
|
186
|
-
this.eventEmitter.emit('oraclePriceUpdate', oracleToPoll.publicKey,
|
|
182
|
+
this.oracles.set(oracleToPoll.publicKey.toString(), dataAndSlot);
|
|
183
|
+
this.eventEmitter.emit('oraclePriceUpdate', oracleToPoll.publicKey, oraclePriceData);
|
|
187
184
|
this.eventEmitter.emit('update');
|
|
188
185
|
});
|
|
189
186
|
}
|
|
@@ -220,7 +217,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
220
217
|
if (buffer) {
|
|
221
218
|
const oracleClient = this.oracleClientCache.get(oracleToPoll.source, this.program.provider.connection, this.program);
|
|
222
219
|
const oraclePriceData = oracleClient.getOraclePriceDataFromBuffer(buffer);
|
|
223
|
-
this.oracles.set(
|
|
220
|
+
this.oracles.set(oracleToPoll.publicKey.toString(), {
|
|
224
221
|
data: oraclePriceData,
|
|
225
222
|
slot,
|
|
226
223
|
});
|
|
@@ -268,19 +265,19 @@ class PollingDriftClientAccountSubscriber {
|
|
|
268
265
|
return true;
|
|
269
266
|
}
|
|
270
267
|
async addOracle(oracleInfo) {
|
|
271
|
-
const oracleId = (0, oracleId_1.getOracleId)(oracleInfo.publicKey, oracleInfo.source);
|
|
272
268
|
if (oracleInfo.publicKey.equals(web3_js_1.PublicKey.default) ||
|
|
273
|
-
this.oracles.has(
|
|
269
|
+
this.oracles.has(oracleInfo.publicKey.toBase58())) {
|
|
274
270
|
return true;
|
|
275
271
|
}
|
|
272
|
+
const oracleString = oracleInfo.publicKey.toBase58();
|
|
276
273
|
// this func can be called multiple times before the first pauseForOracleToBeAdded finishes
|
|
277
274
|
// avoid adding to oraclesToPoll multiple time
|
|
278
|
-
if (!this.oraclesToPoll.has(
|
|
275
|
+
if (!this.oraclesToPoll.has(oracleString)) {
|
|
279
276
|
this.addOracleToPoll(oracleInfo);
|
|
280
|
-
const oracleToPoll = this.oraclesToPoll.get(
|
|
277
|
+
const oracleToPoll = this.oraclesToPoll.get(oracleString);
|
|
281
278
|
await this.addOracleToAccountLoader(oracleToPoll);
|
|
282
279
|
}
|
|
283
|
-
await this.pauseForOracleToBeAdded(3,
|
|
280
|
+
await this.pauseForOracleToBeAdded(3, oracleString);
|
|
284
281
|
return true;
|
|
285
282
|
}
|
|
286
283
|
async pauseForOracleToBeAdded(tries, oracle) {
|
|
@@ -301,15 +298,14 @@ class PollingDriftClientAccountSubscriber {
|
|
|
301
298
|
const perpMarketAccount = perpMarket.data;
|
|
302
299
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
303
300
|
const oracle = perpMarketAccount.amm.oracle;
|
|
304
|
-
|
|
305
|
-
if (!this.oracles.has(oracleId)) {
|
|
301
|
+
if (!this.oracles.has(oracle.toBase58())) {
|
|
306
302
|
oraclePromises.push(this.addOracle({
|
|
307
303
|
publicKey: oracle,
|
|
308
304
|
source: perpMarketAccount.amm.oracleSource,
|
|
309
305
|
}));
|
|
310
306
|
}
|
|
311
307
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
312
|
-
this.perpOracleStringMap.set(perpMarketIndex,
|
|
308
|
+
this.perpOracleStringMap.set(perpMarketIndex, oracle.toBase58());
|
|
313
309
|
}
|
|
314
310
|
await Promise.all(oraclePromises);
|
|
315
311
|
}
|
|
@@ -320,15 +316,14 @@ class PollingDriftClientAccountSubscriber {
|
|
|
320
316
|
const spotMarketAccount = spotMarket.data;
|
|
321
317
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
322
318
|
const oracle = spotMarketAccount.oracle;
|
|
323
|
-
|
|
324
|
-
if (!this.oracles.has(oracleId)) {
|
|
319
|
+
if (!this.oracles.has(oracle.toBase58())) {
|
|
325
320
|
oraclePromises.push(this.addOracle({
|
|
326
321
|
publicKey: oracle,
|
|
327
322
|
source: spotMarketAccount.oracleSource,
|
|
328
323
|
}));
|
|
329
324
|
}
|
|
330
325
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
331
|
-
this.spotOracleStringMap.set(spotMarketIndex,
|
|
326
|
+
this.spotOracleStringMap.set(spotMarketIndex, oracle.toBase58());
|
|
332
327
|
}
|
|
333
328
|
await Promise.all(oraclePromises);
|
|
334
329
|
}
|
|
@@ -346,11 +341,10 @@ class PollingDriftClientAccountSubscriber {
|
|
|
346
341
|
}
|
|
347
342
|
}
|
|
348
343
|
for (const oracle of oracles) {
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
this.accountLoader.removeAccount(oracle.publicKey, callbackId);
|
|
344
|
+
const callbackId = this.oraclesToPoll.get(oracle.toBase58()).callbackId;
|
|
345
|
+
this.accountLoader.removeAccount(oracle, callbackId);
|
|
352
346
|
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Discard) {
|
|
353
|
-
this.oracles.delete(
|
|
347
|
+
this.oracles.delete(oracle.toBase58());
|
|
354
348
|
}
|
|
355
349
|
}
|
|
356
350
|
}
|
|
@@ -375,20 +369,23 @@ class PollingDriftClientAccountSubscriber {
|
|
|
375
369
|
getSpotMarketAccountsAndSlots() {
|
|
376
370
|
return Array.from(this.spotMarket.values());
|
|
377
371
|
}
|
|
378
|
-
getOraclePriceDataAndSlot(
|
|
372
|
+
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
379
373
|
this.assertIsSubscribed();
|
|
380
|
-
|
|
374
|
+
const oracleString = typeof oraclePublicKey === 'string'
|
|
375
|
+
? oraclePublicKey
|
|
376
|
+
: oraclePublicKey.toBase58();
|
|
377
|
+
if (oracleString === ORACLE_DEFAULT_KEY) {
|
|
381
378
|
return {
|
|
382
379
|
data: quoteAssetOracleClient_1.QUOTE_ORACLE_PRICE_DATA,
|
|
383
380
|
slot: 0,
|
|
384
381
|
};
|
|
385
382
|
}
|
|
386
|
-
return this.oracles.get(
|
|
383
|
+
return this.oracles.get(oracleString);
|
|
387
384
|
}
|
|
388
385
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex) {
|
|
389
386
|
const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
|
|
390
387
|
const oracle = this.perpOracleMap.get(marketIndex);
|
|
391
|
-
const
|
|
388
|
+
const oracleString = this.perpOracleStringMap.get(marketIndex);
|
|
392
389
|
if (!perpMarketAccount || !oracle) {
|
|
393
390
|
return undefined;
|
|
394
391
|
}
|
|
@@ -396,12 +393,12 @@ class PollingDriftClientAccountSubscriber {
|
|
|
396
393
|
// If the oracle has changed, we need to update the oracle map in background
|
|
397
394
|
this.setPerpOracleMap();
|
|
398
395
|
}
|
|
399
|
-
return this.getOraclePriceDataAndSlot(
|
|
396
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
400
397
|
}
|
|
401
398
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex) {
|
|
402
399
|
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
403
400
|
const oracle = this.spotOracleMap.get(marketIndex);
|
|
404
|
-
const
|
|
401
|
+
const oracleString = this.spotOracleStringMap.get(marketIndex);
|
|
405
402
|
if (!spotMarketAccount || !oracle) {
|
|
406
403
|
return undefined;
|
|
407
404
|
}
|
|
@@ -409,7 +406,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
409
406
|
// If the oracle has changed, we need to update the oracle map in background
|
|
410
407
|
this.setSpotOracleMap();
|
|
411
408
|
}
|
|
412
|
-
return this.getOraclePriceDataAndSlot(
|
|
409
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
413
410
|
}
|
|
414
411
|
updateAccountLoaderPollingFrequency(pollingFrequency) {
|
|
415
412
|
this.accountLoader.updatePollingFrequency(pollingFrequency);
|
|
@@ -26,7 +26,7 @@ export interface DriftClientAccountEvents {
|
|
|
26
26
|
stateAccountUpdate: (payload: StateAccount) => void;
|
|
27
27
|
perpMarketAccountUpdate: (payload: PerpMarketAccount) => void;
|
|
28
28
|
spotMarketAccountUpdate: (payload: SpotMarketAccount) => void;
|
|
29
|
-
oraclePriceUpdate: (publicKey: PublicKey,
|
|
29
|
+
oraclePriceUpdate: (publicKey: PublicKey, data: OraclePriceData) => void;
|
|
30
30
|
userAccountUpdate: (payload: UserAccount) => void;
|
|
31
31
|
update: void;
|
|
32
32
|
error: (e: Error) => void;
|
|
@@ -47,7 +47,7 @@ export interface DriftClientAccountSubscriber {
|
|
|
47
47
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
48
48
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
49
49
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
50
|
-
getOraclePriceDataAndSlot(
|
|
50
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey | string): DataAndSlot<OraclePriceData> | undefined;
|
|
51
51
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
52
52
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
53
53
|
updateAccountLoaderPollingFrequency?: (pollingFrequency: number) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
1
2
|
import { DataAndSlot } from './types';
|
|
2
3
|
import { PerpMarketAccount, SpotMarketAccount } from '../types';
|
|
3
|
-
import { OracleInfo } from '../oracles/types';
|
|
4
4
|
export declare function capitalize(value: string): string;
|
|
5
5
|
export declare function findDelistedPerpMarketsAndOracles(perpMarkets: DataAndSlot<PerpMarketAccount>[], spotMarkets: DataAndSlot<SpotMarketAccount>[]): {
|
|
6
6
|
perpMarketIndexes: number[];
|
|
7
|
-
oracles:
|
|
7
|
+
oracles: PublicKey[];
|
|
8
8
|
};
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findDelistedPerpMarketsAndOracles = exports.capitalize = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
-
const oracleId_1 = require("../oracles/oracleId");
|
|
6
5
|
function capitalize(value) {
|
|
7
6
|
return value[0].toUpperCase() + value.slice(1);
|
|
8
7
|
}
|
|
@@ -16,30 +15,21 @@ function findDelistedPerpMarketsAndOracles(perpMarkets, spotMarkets) {
|
|
|
16
15
|
}
|
|
17
16
|
if ((0, types_1.isVariant)(perpMarket.data.status, 'delisted')) {
|
|
18
17
|
delistedPerpMarketIndexes.push(perpMarket.data.marketIndex);
|
|
19
|
-
delistedOracles.push(
|
|
20
|
-
publicKey: perpMarket.data.amm.oracle,
|
|
21
|
-
source: perpMarket.data.amm.oracleSource,
|
|
22
|
-
});
|
|
18
|
+
delistedOracles.push(perpMarket.data.amm.oracle);
|
|
23
19
|
}
|
|
24
20
|
}
|
|
25
21
|
// make sure oracle isn't used by spot market
|
|
26
22
|
const filteredDelistedOracles = [];
|
|
27
23
|
for (const delistedOracle of delistedOracles) {
|
|
28
|
-
let isUsedBySpotMarket = false;
|
|
29
24
|
for (const spotMarket of spotMarkets) {
|
|
30
25
|
if (!spotMarket.data) {
|
|
31
26
|
continue;
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
const spotMarketOracleId = (0, oracleId_1.getOracleId)(spotMarket.data.oracle, spotMarket.data.oracleSource);
|
|
35
|
-
if (spotMarketOracleId === delistedOracleId) {
|
|
36
|
-
isUsedBySpotMarket = true;
|
|
28
|
+
if (spotMarket.data.oracle.equals(delistedOracle)) {
|
|
37
29
|
break;
|
|
38
30
|
}
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
filteredDelistedOracles.push(delistedOracle);
|
|
42
|
-
}
|
|
32
|
+
filteredDelistedOracles.push(delistedOracle);
|
|
43
33
|
}
|
|
44
34
|
return {
|
|
45
35
|
perpMarketIndexes: delistedPerpMarketIndexes,
|
|
@@ -60,7 +60,7 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
60
60
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
61
61
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
62
62
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
63
|
-
getOraclePriceDataAndSlot(
|
|
63
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey | string): DataAndSlot<OraclePriceData> | undefined;
|
|
64
64
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
65
65
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
66
66
|
}
|
|
@@ -10,9 +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
|
const utils_1 = require("./utils");
|
|
13
|
-
const
|
|
14
|
-
const types_2 = require("../types");
|
|
15
|
-
const ORACLE_DEFAULT_ID = (0, oracleId_1.getOracleId)(web3_js_1.PublicKey.default, types_2.OracleSource.QUOTE_ASSET);
|
|
13
|
+
const ORACLE_DEFAULT_KEY = web3_js_1.PublicKey.default.toBase58();
|
|
16
14
|
class WebSocketDriftClientAccountSubscriber {
|
|
17
15
|
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts, commitment) {
|
|
18
16
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
@@ -111,10 +109,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
111
109
|
}
|
|
112
110
|
const oracleClient = this.oracleClientCache.get(oracleInfo.source, connection, this.program);
|
|
113
111
|
const oraclePriceData = oracleClient.getOraclePriceDataFromBuffer(oracleAccountInfos[i].data);
|
|
114
|
-
result.push([
|
|
115
|
-
(0, oracleId_1.getOracleId)(oracleInfo.publicKey, oracleInfo.source),
|
|
116
|
-
oraclePriceData,
|
|
117
|
-
]);
|
|
112
|
+
result.push([oracleInfo.publicKey.toString(), oraclePriceData]);
|
|
118
113
|
return result;
|
|
119
114
|
}, []));
|
|
120
115
|
}
|
|
@@ -160,20 +155,20 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
160
155
|
return true;
|
|
161
156
|
}
|
|
162
157
|
async subscribeToOracle(oracleInfo) {
|
|
163
|
-
const
|
|
158
|
+
const oracleString = oracleInfo.publicKey.toString();
|
|
164
159
|
const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection, this.program);
|
|
165
160
|
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('oracle', this.program, oracleInfo.publicKey, (buffer) => {
|
|
166
161
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
167
162
|
}, this.resubOpts, this.commitment);
|
|
168
|
-
const initialOraclePriceData = this.initialOraclePriceData.get(
|
|
163
|
+
const initialOraclePriceData = this.initialOraclePriceData.get(oracleString);
|
|
169
164
|
if (initialOraclePriceData) {
|
|
170
165
|
accountSubscriber.setData(initialOraclePriceData);
|
|
171
166
|
}
|
|
172
167
|
await accountSubscriber.subscribe((data) => {
|
|
173
|
-
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey,
|
|
168
|
+
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey, data);
|
|
174
169
|
this.eventEmitter.emit('update');
|
|
175
170
|
});
|
|
176
|
-
this.oracleSubscribers.set(
|
|
171
|
+
this.oracleSubscribers.set(oracleString, accountSubscriber);
|
|
177
172
|
return true;
|
|
178
173
|
}
|
|
179
174
|
async unsubscribeFromMarketAccounts() {
|
|
@@ -221,8 +216,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
221
216
|
return subscriptionSuccess;
|
|
222
217
|
}
|
|
223
218
|
async addOracle(oracleInfo) {
|
|
224
|
-
|
|
225
|
-
if (this.oracleSubscribers.has(oracleId)) {
|
|
219
|
+
if (this.oracleSubscribers.has(oracleInfo.publicKey.toString())) {
|
|
226
220
|
return true;
|
|
227
221
|
}
|
|
228
222
|
if (oracleInfo.publicKey.equals(web3_js_1.PublicKey.default)) {
|
|
@@ -240,15 +234,14 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
240
234
|
const perpMarketAccount = perpMarket.data;
|
|
241
235
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
242
236
|
const oracle = perpMarketAccount.amm.oracle;
|
|
243
|
-
|
|
244
|
-
if (!this.oracleSubscribers.has(oracleId)) {
|
|
237
|
+
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
245
238
|
addOraclePromises.push(this.addOracle({
|
|
246
239
|
publicKey: oracle,
|
|
247
240
|
source: perpMarket.data.amm.oracleSource,
|
|
248
241
|
}));
|
|
249
242
|
}
|
|
250
243
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
251
|
-
this.perpOracleStringMap.set(perpMarketIndex,
|
|
244
|
+
this.perpOracleStringMap.set(perpMarketIndex, oracle.toBase58());
|
|
252
245
|
}
|
|
253
246
|
await Promise.all(addOraclePromises);
|
|
254
247
|
}
|
|
@@ -262,15 +255,14 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
262
255
|
const spotMarketAccount = spotMarket.data;
|
|
263
256
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
264
257
|
const oracle = spotMarketAccount.oracle;
|
|
265
|
-
|
|
266
|
-
if (!this.oracleSubscribers.has(oracleId)) {
|
|
258
|
+
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
267
259
|
addOraclePromises.push(this.addOracle({
|
|
268
260
|
publicKey: oracle,
|
|
269
261
|
source: spotMarketAccount.oracleSource,
|
|
270
262
|
}));
|
|
271
263
|
}
|
|
272
264
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
273
|
-
this.spotOracleStringMap.set(spotMarketIndex,
|
|
265
|
+
this.spotOracleStringMap.set(spotMarketIndex, oracle.toBase58());
|
|
274
266
|
}
|
|
275
267
|
await Promise.all(addOraclePromises);
|
|
276
268
|
}
|
|
@@ -288,10 +280,9 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
288
280
|
}
|
|
289
281
|
}
|
|
290
282
|
for (const oracle of oracles) {
|
|
291
|
-
|
|
292
|
-
await this.oracleSubscribers.get(oracleId).unsubscribe();
|
|
283
|
+
await this.oracleSubscribers.get(oracle.toBase58()).unsubscribe();
|
|
293
284
|
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Discard) {
|
|
294
|
-
this.oracleSubscribers.delete(
|
|
285
|
+
this.oracleSubscribers.delete(oracle.toBase58());
|
|
295
286
|
}
|
|
296
287
|
}
|
|
297
288
|
}
|
|
@@ -318,41 +309,44 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
318
309
|
getSpotMarketAccountsAndSlots() {
|
|
319
310
|
return Array.from(this.spotMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
|
|
320
311
|
}
|
|
321
|
-
getOraclePriceDataAndSlot(
|
|
312
|
+
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
322
313
|
this.assertIsSubscribed();
|
|
323
|
-
|
|
314
|
+
const oracleString = typeof oraclePublicKey === 'string'
|
|
315
|
+
? oraclePublicKey
|
|
316
|
+
: oraclePublicKey.toBase58();
|
|
317
|
+
if (oracleString === ORACLE_DEFAULT_KEY) {
|
|
324
318
|
return {
|
|
325
319
|
data: quoteAssetOracleClient_1.QUOTE_ORACLE_PRICE_DATA,
|
|
326
320
|
slot: 0,
|
|
327
321
|
};
|
|
328
322
|
}
|
|
329
|
-
return this.oracleSubscribers.get(
|
|
323
|
+
return this.oracleSubscribers.get(oracleString).dataAndSlot;
|
|
330
324
|
}
|
|
331
325
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex) {
|
|
332
326
|
const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
|
|
333
327
|
const oracle = this.perpOracleMap.get(marketIndex);
|
|
334
|
-
const
|
|
335
|
-
if (!perpMarketAccount || !
|
|
328
|
+
const oracleString = this.perpOracleStringMap.get(marketIndex);
|
|
329
|
+
if (!perpMarketAccount || !oracle) {
|
|
336
330
|
return undefined;
|
|
337
331
|
}
|
|
338
332
|
if (!perpMarketAccount.data.amm.oracle.equals(oracle)) {
|
|
339
333
|
// If the oracle has changed, we need to update the oracle map in background
|
|
340
334
|
this.setPerpOracleMap();
|
|
341
335
|
}
|
|
342
|
-
return this.getOraclePriceDataAndSlot(
|
|
336
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
343
337
|
}
|
|
344
338
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex) {
|
|
345
339
|
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
346
340
|
const oracle = this.spotOracleMap.get(marketIndex);
|
|
347
|
-
const
|
|
348
|
-
if (!spotMarketAccount || !
|
|
341
|
+
const oracleString = this.spotOracleStringMap.get(marketIndex);
|
|
342
|
+
if (!spotMarketAccount || !oracle) {
|
|
349
343
|
return undefined;
|
|
350
344
|
}
|
|
351
345
|
if (!spotMarketAccount.data.oracle.equals(oracle)) {
|
|
352
346
|
// If the oracle has changed, we need to update the oracle map in background
|
|
353
347
|
this.setSpotOracleMap();
|
|
354
348
|
}
|
|
355
|
-
return this.getOraclePriceDataAndSlot(
|
|
349
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
356
350
|
}
|
|
357
351
|
}
|
|
358
352
|
exports.WebSocketDriftClientAccountSubscriber = WebSocketDriftClientAccountSubscriber;
|
package/lib/browser/config.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.findAllMarketAndOracles = exports.getMarketsAndOraclesForSubscription =
|
|
|
4
4
|
const perpMarkets_1 = require("./constants/perpMarkets");
|
|
5
5
|
const spotMarkets_1 = require("./constants/spotMarkets");
|
|
6
6
|
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
|
7
|
-
const oracleId_1 = require("./oracles/oracleId");
|
|
8
7
|
exports.DRIFT_PROGRAM_ID = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
|
|
9
8
|
exports.DRIFT_ORACLE_RECEIVER_ID = 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha';
|
|
10
9
|
exports.SWIFT_ID = 'SW1fThqrxLzVprnCMpiybiqYQfoNCdduC5uWsSUKChS';
|
|
@@ -75,14 +74,14 @@ function getMarketsAndOraclesForSubscription(env, perpMarkets, spotMarkets) {
|
|
|
75
74
|
const oracleInfos = new Map();
|
|
76
75
|
for (const market of perpMarketsToUse) {
|
|
77
76
|
perpMarketIndexes.push(market.marketIndex);
|
|
78
|
-
oracleInfos.set(
|
|
77
|
+
oracleInfos.set(market.oracle.toString(), {
|
|
79
78
|
publicKey: market.oracle,
|
|
80
79
|
source: market.oracleSource,
|
|
81
80
|
});
|
|
82
81
|
}
|
|
83
82
|
for (const spotMarket of spotMarketsToUse) {
|
|
84
83
|
spotMarketIndexes.push(spotMarket.marketIndex);
|
|
85
|
-
oracleInfos.set(
|
|
84
|
+
oracleInfos.set(spotMarket.oracle.toString(), {
|
|
86
85
|
publicKey: spotMarket.oracle,
|
|
87
86
|
source: spotMarket.oracleSource,
|
|
88
87
|
});
|
|
@@ -103,7 +102,7 @@ async function findAllMarketAndOracles(program) {
|
|
|
103
102
|
for (const perpMarketProgramAccount of perpMarketProgramAccounts) {
|
|
104
103
|
const perpMarket = perpMarketProgramAccount.account;
|
|
105
104
|
perpMarketIndexes.push(perpMarket.marketIndex);
|
|
106
|
-
oracleInfos.set(
|
|
105
|
+
oracleInfos.set(perpMarket.amm.oracle.toString(), {
|
|
107
106
|
publicKey: perpMarket.amm.oracle,
|
|
108
107
|
source: perpMarket.amm.oracleSource,
|
|
109
108
|
});
|
|
@@ -111,7 +110,7 @@ async function findAllMarketAndOracles(program) {
|
|
|
111
110
|
for (const spotMarketProgramAccount of spotMarketProgramAccounts) {
|
|
112
111
|
const spotMarket = spotMarketProgramAccount.account;
|
|
113
112
|
spotMarketIndexes.push(spotMarket.marketIndex);
|
|
114
|
-
oracleInfos.set(
|
|
113
|
+
oracleInfos.set(spotMarket.oracle.toString(), {
|
|
115
114
|
publicKey: spotMarket.oracle,
|
|
116
115
|
source: spotMarket.oracleSource,
|
|
117
116
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as anchor from '@coral-xyz/anchor';
|
|
6
6
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
7
7
|
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
8
|
-
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams,
|
|
8
|
+
import { DriftClientMetricsEvents, HighLeverageModeConfig, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, RFQMakerOrderParams, RFQMatch, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SwiftOrderParamsMessage, SwiftServerMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount } from './types';
|
|
9
9
|
import { AccountMeta, AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, Connection, Keypair, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
10
10
|
import { TokenFaucet } from './tokenFaucet';
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
@@ -109,7 +109,7 @@ export declare class DriftClient {
|
|
|
109
109
|
forceGetSpotMarketAccount(marketIndex: number): Promise<SpotMarketAccount | undefined>;
|
|
110
110
|
getSpotMarketAccounts(): SpotMarketAccount[];
|
|
111
111
|
getQuoteSpotMarketAccount(): SpotMarketAccount;
|
|
112
|
-
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey
|
|
112
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
113
113
|
getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
|
|
114
114
|
getSerumV3FulfillmentConfigs(): Promise<SerumV3FulfillmentConfigAccount[]>;
|
|
115
115
|
getPhoenixV1FulfillmentConfig(phoenixMarket: PublicKey): Promise<PhoenixV1FulfillmentConfigAccount>;
|
|
@@ -70,7 +70,6 @@ const on_demand_1 = require("@switchboard-xyz/on-demand");
|
|
|
70
70
|
const grpcDriftClientAccountSubscriber_1 = require("./accounts/grpcDriftClientAccountSubscriber");
|
|
71
71
|
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
72
72
|
const digest_1 = require("./util/digest");
|
|
73
|
-
const oracleId_1 = require("./oracles/oracleId");
|
|
74
73
|
/**
|
|
75
74
|
* # DriftClient
|
|
76
75
|
* 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.
|
|
@@ -339,8 +338,8 @@ class DriftClient {
|
|
|
339
338
|
getQuoteSpotMarketAccount() {
|
|
340
339
|
return this.accountSubscriber.getSpotMarketAccountAndSlot(numericConstants_1.QUOTE_SPOT_MARKET_INDEX).data;
|
|
341
340
|
}
|
|
342
|
-
getOraclePriceDataAndSlot(oraclePublicKey
|
|
343
|
-
return this.accountSubscriber.getOraclePriceDataAndSlot(
|
|
341
|
+
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
342
|
+
return this.accountSubscriber.getOraclePriceDataAndSlot(oraclePublicKey.toBase58());
|
|
344
343
|
}
|
|
345
344
|
async getSerumV3FulfillmentConfig(serumMarket) {
|
|
346
345
|
const address = await (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -198,20 +198,6 @@ export declare class OracleSource {
|
|
|
198
198
|
switchboardOnDemand: {};
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
-
export declare class OracleSourceNum {
|
|
202
|
-
static readonly PYTH = 0;
|
|
203
|
-
static readonly PYTH_1K = 1;
|
|
204
|
-
static readonly PYTH_1M = 2;
|
|
205
|
-
static readonly PYTH_PULL = 3;
|
|
206
|
-
static readonly PYTH_1K_PULL = 4;
|
|
207
|
-
static readonly PYTH_1M_PULL = 5;
|
|
208
|
-
static readonly SWITCHBOARD = 6;
|
|
209
|
-
static readonly QUOTE_ASSET = 7;
|
|
210
|
-
static readonly PYTH_STABLE_COIN = 8;
|
|
211
|
-
static readonly PYTH_STABLE_COIN_PULL = 9;
|
|
212
|
-
static readonly PRELAUNCH = 10;
|
|
213
|
-
static readonly SWITCHBOARD_ON_DEMAND = 11;
|
|
214
|
-
}
|
|
215
201
|
export declare class OrderType {
|
|
216
202
|
static readonly LIMIT: {
|
|
217
203
|
limit: {};
|
package/lib/browser/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SwapReduceOnly = exports.PlaceAndTakeOrderSuccessCondition = exports.ReferrerStatus = exports.DefaultOrderParams = exports.ModifyOrderPolicy = exports.PostOnlyParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.SettlePnlMode = exports.StakeAction = exports.SpotFulfillmentConfigStatus = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.
|
|
3
|
+
exports.SwapReduceOnly = exports.PlaceAndTakeOrderSuccessCondition = exports.ReferrerStatus = exports.DefaultOrderParams = exports.ModifyOrderPolicy = exports.PostOnlyParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.SettlePnlMode = exports.StakeAction = exports.SpotFulfillmentConfigStatus = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.MarginMode = exports.UserStatus = exports.InsuranceFundOperation = exports.SpotOperation = exports.PerpOperation = exports.MarketStatus = exports.ExchangeStatus = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
// # Utility Types / Enums / Constants
|
|
6
6
|
var ExchangeStatus;
|
|
@@ -122,21 +122,6 @@ OracleSource.PYTH_STABLE_COIN = { pythStableCoin: {} };
|
|
|
122
122
|
OracleSource.PYTH_STABLE_COIN_PULL = { pythStableCoinPull: {} };
|
|
123
123
|
OracleSource.Prelaunch = { prelaunch: {} };
|
|
124
124
|
OracleSource.SWITCHBOARD_ON_DEMAND = { switchboardOnDemand: {} };
|
|
125
|
-
class OracleSourceNum {
|
|
126
|
-
}
|
|
127
|
-
exports.OracleSourceNum = OracleSourceNum;
|
|
128
|
-
OracleSourceNum.PYTH = 0;
|
|
129
|
-
OracleSourceNum.PYTH_1K = 1;
|
|
130
|
-
OracleSourceNum.PYTH_1M = 2;
|
|
131
|
-
OracleSourceNum.PYTH_PULL = 3;
|
|
132
|
-
OracleSourceNum.PYTH_1K_PULL = 4;
|
|
133
|
-
OracleSourceNum.PYTH_1M_PULL = 5;
|
|
134
|
-
OracleSourceNum.SWITCHBOARD = 6;
|
|
135
|
-
OracleSourceNum.QUOTE_ASSET = 7;
|
|
136
|
-
OracleSourceNum.PYTH_STABLE_COIN = 8;
|
|
137
|
-
OracleSourceNum.PYTH_STABLE_COIN_PULL = 9;
|
|
138
|
-
OracleSourceNum.PRELAUNCH = 10;
|
|
139
|
-
OracleSourceNum.SWITCHBOARD_ON_DEMAND = 11;
|
|
140
125
|
class OrderType {
|
|
141
126
|
}
|
|
142
127
|
exports.OrderType = OrderType;
|
|
@@ -5,7 +5,6 @@ const webSocketDriftClientAccountSubscriber_1 = require("./webSocketDriftClientA
|
|
|
5
5
|
const config_1 = require("../config");
|
|
6
6
|
const pda_1 = require("../addresses/pda");
|
|
7
7
|
const grpcAccountSubscriber_1 = require("./grpcAccountSubscriber");
|
|
8
|
-
const oracleId_1 = require("../oracles/oracleId");
|
|
9
8
|
class gprcDriftClientAccountSubscriber extends webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber {
|
|
10
9
|
constructor(grpcConfigs, program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts) {
|
|
11
10
|
super(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts);
|
|
@@ -81,17 +80,17 @@ class gprcDriftClientAccountSubscriber extends webSocketDriftClientAccountSubscr
|
|
|
81
80
|
return true;
|
|
82
81
|
}
|
|
83
82
|
async subscribeToOracle(oracleInfo) {
|
|
84
|
-
const
|
|
83
|
+
const oracleString = oracleInfo.publicKey.toString();
|
|
85
84
|
const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection, this.program);
|
|
86
85
|
const accountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'oracle', this.program, oracleInfo.publicKey, (buffer) => {
|
|
87
86
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
88
87
|
}, this.resubOpts);
|
|
89
|
-
accountSubscriber.setData(this.initialOraclePriceData.get(
|
|
88
|
+
accountSubscriber.setData(this.initialOraclePriceData.get(oracleString));
|
|
90
89
|
await accountSubscriber.subscribe((data) => {
|
|
91
|
-
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey,
|
|
90
|
+
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey, data);
|
|
92
91
|
this.eventEmitter.emit('update');
|
|
93
92
|
});
|
|
94
|
-
this.oracleSubscribers.set(
|
|
93
|
+
this.oracleSubscribers.set(oracleString, accountSubscriber);
|
|
95
94
|
return true;
|
|
96
95
|
}
|
|
97
96
|
}
|