@drift-labs/sdk 2.95.0-beta.16 → 2.95.0-beta.18
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/pollingDriftClientAccountSubscriber.d.ts +3 -1
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +14 -4
- package/lib/accounts/types.d.ts +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +3 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +18 -5
- package/lib/driftClient.js +6 -2
- package/lib/idl/drift.json +8 -3
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +17 -5
- package/src/accounts/types.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +22 -6
- package/src/driftClient.ts +11 -2
- package/src/idl/drift.json +8 -3
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.95.0-beta.
|
|
1
|
+
2.95.0-beta.18
|
|
@@ -24,8 +24,10 @@ export declare class PollingDriftClientAccountSubscriber implements DriftClientA
|
|
|
24
24
|
state?: DataAndSlot<StateAccount>;
|
|
25
25
|
perpMarket: Map<number, DataAndSlot<PerpMarketAccount>>;
|
|
26
26
|
perpOracleMap: Map<number, PublicKey>;
|
|
27
|
+
perpOracleStringMap: Map<number, string>;
|
|
27
28
|
spotMarket: Map<number, DataAndSlot<SpotMarketAccount>>;
|
|
28
29
|
spotOracleMap: Map<number, PublicKey>;
|
|
30
|
+
spotOracleStringMap: Map<number, string>;
|
|
29
31
|
oracles: Map<string, DataAndSlot<OraclePriceData>>;
|
|
30
32
|
user?: DataAndSlot<UserAccount>;
|
|
31
33
|
private isSubscribing;
|
|
@@ -58,7 +60,7 @@ export declare class PollingDriftClientAccountSubscriber implements DriftClientA
|
|
|
58
60
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
59
61
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
60
62
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
61
|
-
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
63
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey | string): DataAndSlot<OraclePriceData> | undefined;
|
|
62
64
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
63
65
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
64
66
|
updateAccountLoaderPollingFrequency(pollingFrequency: number): void;
|
|
@@ -9,6 +9,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
9
9
|
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
10
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
11
11
|
const config_1 = require("../config");
|
|
12
|
+
const ORACLE_DEFAULT_KEY = web3_js_1.PublicKey.default.toBase58();
|
|
12
13
|
class PollingDriftClientAccountSubscriber {
|
|
13
14
|
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles) {
|
|
14
15
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
@@ -16,8 +17,10 @@ class PollingDriftClientAccountSubscriber {
|
|
|
16
17
|
this.oraclesToPoll = new Map();
|
|
17
18
|
this.perpMarket = new Map();
|
|
18
19
|
this.perpOracleMap = new Map();
|
|
20
|
+
this.perpOracleStringMap = new Map();
|
|
19
21
|
this.spotMarket = new Map();
|
|
20
22
|
this.spotOracleMap = new Map();
|
|
23
|
+
this.spotOracleStringMap = new Map();
|
|
21
24
|
this.oracles = new Map();
|
|
22
25
|
this.isSubscribing = false;
|
|
23
26
|
this.isSubscribed = false;
|
|
@@ -300,6 +303,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
300
303
|
}));
|
|
301
304
|
}
|
|
302
305
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
306
|
+
this.perpOracleStringMap.set(perpMarketIndex, oracle.toBase58());
|
|
303
307
|
}
|
|
304
308
|
await Promise.all(oraclePromises);
|
|
305
309
|
}
|
|
@@ -317,6 +321,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
317
321
|
}));
|
|
318
322
|
}
|
|
319
323
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
324
|
+
this.spotOracleStringMap.set(spotMarketIndex, oracle.toBase58());
|
|
320
325
|
}
|
|
321
326
|
await Promise.all(oraclePromises);
|
|
322
327
|
}
|
|
@@ -343,17 +348,21 @@ class PollingDriftClientAccountSubscriber {
|
|
|
343
348
|
}
|
|
344
349
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
345
350
|
this.assertIsSubscribed();
|
|
346
|
-
|
|
351
|
+
const oracleString = typeof oraclePublicKey === 'string'
|
|
352
|
+
? oraclePublicKey
|
|
353
|
+
: oraclePublicKey.toBase58();
|
|
354
|
+
if (oracleString === ORACLE_DEFAULT_KEY) {
|
|
347
355
|
return {
|
|
348
356
|
data: quoteAssetOracleClient_1.QUOTE_ORACLE_PRICE_DATA,
|
|
349
357
|
slot: 0,
|
|
350
358
|
};
|
|
351
359
|
}
|
|
352
|
-
return this.oracles.get(
|
|
360
|
+
return this.oracles.get(oracleString);
|
|
353
361
|
}
|
|
354
362
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex) {
|
|
355
363
|
const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
|
|
356
364
|
const oracle = this.perpOracleMap.get(marketIndex);
|
|
365
|
+
const oracleString = this.perpOracleStringMap.get(marketIndex);
|
|
357
366
|
if (!perpMarketAccount || !oracle) {
|
|
358
367
|
return undefined;
|
|
359
368
|
}
|
|
@@ -361,11 +370,12 @@ class PollingDriftClientAccountSubscriber {
|
|
|
361
370
|
// If the oracle has changed, we need to update the oracle map in background
|
|
362
371
|
this.setPerpOracleMap();
|
|
363
372
|
}
|
|
364
|
-
return this.getOraclePriceDataAndSlot(
|
|
373
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
365
374
|
}
|
|
366
375
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex) {
|
|
367
376
|
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
368
377
|
const oracle = this.spotOracleMap.get(marketIndex);
|
|
378
|
+
const oracleString = this.spotOracleStringMap.get(marketIndex);
|
|
369
379
|
if (!spotMarketAccount || !oracle) {
|
|
370
380
|
return undefined;
|
|
371
381
|
}
|
|
@@ -373,7 +383,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
373
383
|
// If the oracle has changed, we need to update the oracle map in background
|
|
374
384
|
this.setSpotOracleMap();
|
|
375
385
|
}
|
|
376
|
-
return this.getOraclePriceDataAndSlot(
|
|
386
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
377
387
|
}
|
|
378
388
|
updateAccountLoaderPollingFrequency(pollingFrequency) {
|
|
379
389
|
this.accountLoader.updatePollingFrequency(pollingFrequency);
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface DriftClientAccountSubscriber {
|
|
|
45
45
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
46
46
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
47
47
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
48
|
-
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
48
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey | string): DataAndSlot<OraclePriceData> | undefined;
|
|
49
49
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
50
50
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
51
51
|
updateAccountLoaderPollingFrequency?: (pollingFrequency: number) => void;
|
|
@@ -22,8 +22,10 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
22
22
|
stateAccountSubscriber?: AccountSubscriber<StateAccount>;
|
|
23
23
|
perpMarketAccountSubscribers: Map<number, AccountSubscriber<PerpMarketAccount>>;
|
|
24
24
|
perpOracleMap: Map<number, PublicKey>;
|
|
25
|
+
perpOracleStringMap: Map<number, string>;
|
|
25
26
|
spotMarketAccountSubscribers: Map<number, AccountSubscriber<SpotMarketAccount>>;
|
|
26
27
|
spotOracleMap: Map<number, PublicKey>;
|
|
28
|
+
spotOracleStringMap: Map<number, string>;
|
|
27
29
|
oracleSubscribers: Map<string, AccountSubscriber<OraclePriceData>>;
|
|
28
30
|
initialPerpMarketAccountData: Map<number, PerpMarketAccount>;
|
|
29
31
|
initialSpotMarketAccountData: Map<number, SpotMarketAccount>;
|
|
@@ -57,7 +59,7 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
57
59
|
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
58
60
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
59
61
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
60
|
-
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
62
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey | string): DataAndSlot<OraclePriceData> | undefined;
|
|
61
63
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
62
64
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
63
65
|
}
|
|
@@ -9,13 +9,16 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
9
9
|
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
10
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
11
11
|
const config_1 = require("../config");
|
|
12
|
+
const ORACLE_DEFAULT_KEY = web3_js_1.PublicKey.default.toBase58();
|
|
12
13
|
class WebSocketDriftClientAccountSubscriber {
|
|
13
14
|
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, resubOpts, commitment) {
|
|
14
15
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
15
16
|
this.perpMarketAccountSubscribers = new Map();
|
|
16
17
|
this.perpOracleMap = new Map();
|
|
18
|
+
this.perpOracleStringMap = new Map();
|
|
17
19
|
this.spotMarketAccountSubscribers = new Map();
|
|
18
20
|
this.spotOracleMap = new Map();
|
|
21
|
+
this.spotOracleStringMap = new Map();
|
|
19
22
|
this.oracleSubscribers = new Map();
|
|
20
23
|
this.isSubscribing = false;
|
|
21
24
|
this.isSubscribed = false;
|
|
@@ -146,7 +149,10 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
146
149
|
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('oracle', this.program, oracleInfo.publicKey, (buffer) => {
|
|
147
150
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
148
151
|
}, this.resubOpts, this.commitment);
|
|
149
|
-
|
|
152
|
+
const initialOraclePriceData = this.initialOraclePriceData.get(oracleString);
|
|
153
|
+
if (initialOraclePriceData) {
|
|
154
|
+
accountSubscriber.setData(initialOraclePriceData);
|
|
155
|
+
}
|
|
150
156
|
await accountSubscriber.subscribe((data) => {
|
|
151
157
|
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey, data);
|
|
152
158
|
this.eventEmitter.emit('update');
|
|
@@ -224,6 +230,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
224
230
|
}));
|
|
225
231
|
}
|
|
226
232
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
233
|
+
this.perpOracleStringMap.set(perpMarketIndex, oracle.toBase58());
|
|
227
234
|
}
|
|
228
235
|
await Promise.all(addOraclePromises);
|
|
229
236
|
}
|
|
@@ -244,6 +251,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
244
251
|
}));
|
|
245
252
|
}
|
|
246
253
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
254
|
+
this.spotOracleStringMap.set(spotMarketIndex, oracle.toBase58());
|
|
247
255
|
}
|
|
248
256
|
await Promise.all(addOraclePromises);
|
|
249
257
|
}
|
|
@@ -272,17 +280,21 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
272
280
|
}
|
|
273
281
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
274
282
|
this.assertIsSubscribed();
|
|
275
|
-
|
|
283
|
+
const oracleString = typeof oraclePublicKey === 'string'
|
|
284
|
+
? oraclePublicKey
|
|
285
|
+
: oraclePublicKey.toBase58();
|
|
286
|
+
if (oracleString === ORACLE_DEFAULT_KEY) {
|
|
276
287
|
return {
|
|
277
288
|
data: quoteAssetOracleClient_1.QUOTE_ORACLE_PRICE_DATA,
|
|
278
289
|
slot: 0,
|
|
279
290
|
};
|
|
280
291
|
}
|
|
281
|
-
return this.oracleSubscribers.get(
|
|
292
|
+
return this.oracleSubscribers.get(oracleString).dataAndSlot;
|
|
282
293
|
}
|
|
283
294
|
getOraclePriceDataAndSlotForPerpMarket(marketIndex) {
|
|
284
295
|
const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
|
|
285
296
|
const oracle = this.perpOracleMap.get(marketIndex);
|
|
297
|
+
const oracleString = this.perpOracleStringMap.get(marketIndex);
|
|
286
298
|
if (!perpMarketAccount || !oracle) {
|
|
287
299
|
return undefined;
|
|
288
300
|
}
|
|
@@ -290,11 +302,12 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
290
302
|
// If the oracle has changed, we need to update the oracle map in background
|
|
291
303
|
this.setPerpOracleMap();
|
|
292
304
|
}
|
|
293
|
-
return this.getOraclePriceDataAndSlot(
|
|
305
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
294
306
|
}
|
|
295
307
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex) {
|
|
296
308
|
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
297
309
|
const oracle = this.spotOracleMap.get(marketIndex);
|
|
310
|
+
const oracleString = this.spotOracleStringMap.get(marketIndex);
|
|
298
311
|
if (!spotMarketAccount || !oracle) {
|
|
299
312
|
return undefined;
|
|
300
313
|
}
|
|
@@ -302,7 +315,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
302
315
|
// If the oracle has changed, we need to update the oracle map in background
|
|
303
316
|
this.setSpotOracleMap();
|
|
304
317
|
}
|
|
305
|
-
return this.getOraclePriceDataAndSlot(
|
|
318
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
306
319
|
}
|
|
307
320
|
}
|
|
308
321
|
exports.WebSocketDriftClientAccountSubscriber = WebSocketDriftClientAccountSubscriber;
|
package/lib/driftClient.js
CHANGED
|
@@ -309,7 +309,7 @@ class DriftClient {
|
|
|
309
309
|
return this.accountSubscriber.getSpotMarketAccountAndSlot(numericConstants_1.QUOTE_SPOT_MARKET_INDEX).data;
|
|
310
310
|
}
|
|
311
311
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
312
|
-
return this.accountSubscriber.getOraclePriceDataAndSlot(oraclePublicKey);
|
|
312
|
+
return this.accountSubscriber.getOraclePriceDataAndSlot(oraclePublicKey.toBase58());
|
|
313
313
|
}
|
|
314
314
|
async getSerumV3FulfillmentConfig(serumMarket) {
|
|
315
315
|
const address = await (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
@@ -1725,10 +1725,14 @@ class DriftClient {
|
|
|
1725
1725
|
writablePerpMarketIndexes: [marketIndex],
|
|
1726
1726
|
writableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
1727
1727
|
});
|
|
1728
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
1728
1729
|
return await this.program.instruction.settleExpiredMarket(marketIndex, {
|
|
1729
1730
|
accounts: {
|
|
1730
1731
|
state: await this.getStatePublicKey(),
|
|
1731
|
-
|
|
1732
|
+
admin: this.isSubscribed
|
|
1733
|
+
? this.getStateAccount().admin
|
|
1734
|
+
: this.wallet.publicKey,
|
|
1735
|
+
perpMarket: perpMarketPublicKey,
|
|
1732
1736
|
},
|
|
1733
1737
|
remainingAccounts,
|
|
1734
1738
|
});
|
package/lib/idl/drift.json
CHANGED
|
@@ -1606,15 +1606,20 @@
|
|
|
1606
1606
|
{
|
|
1607
1607
|
"name": "settleExpiredMarket",
|
|
1608
1608
|
"accounts": [
|
|
1609
|
+
{
|
|
1610
|
+
"name": "admin",
|
|
1611
|
+
"isMut": false,
|
|
1612
|
+
"isSigner": true
|
|
1613
|
+
},
|
|
1609
1614
|
{
|
|
1610
1615
|
"name": "state",
|
|
1611
1616
|
"isMut": false,
|
|
1612
1617
|
"isSigner": false
|
|
1613
1618
|
},
|
|
1614
1619
|
{
|
|
1615
|
-
"name": "
|
|
1616
|
-
"isMut":
|
|
1617
|
-
"isSigner":
|
|
1620
|
+
"name": "perpMarket",
|
|
1621
|
+
"isMut": true,
|
|
1622
|
+
"isSigner": false
|
|
1618
1623
|
}
|
|
1619
1624
|
],
|
|
1620
1625
|
"args": [
|
package/package.json
CHANGED
|
@@ -28,6 +28,8 @@ import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
|
28
28
|
import { QUOTE_ORACLE_PRICE_DATA } from '../oracles/quoteAssetOracleClient';
|
|
29
29
|
import { findAllMarketAndOracles } from '../config';
|
|
30
30
|
|
|
31
|
+
const ORACLE_DEFAULT_KEY = PublicKey.default.toBase58();
|
|
32
|
+
|
|
31
33
|
export class PollingDriftClientAccountSubscriber
|
|
32
34
|
implements DriftClientAccountSubscriber
|
|
33
35
|
{
|
|
@@ -50,8 +52,10 @@ export class PollingDriftClientAccountSubscriber
|
|
|
50
52
|
state?: DataAndSlot<StateAccount>;
|
|
51
53
|
perpMarket = new Map<number, DataAndSlot<PerpMarketAccount>>();
|
|
52
54
|
perpOracleMap = new Map<number, PublicKey>();
|
|
55
|
+
perpOracleStringMap = new Map<number, string>();
|
|
53
56
|
spotMarket = new Map<number, DataAndSlot<SpotMarketAccount>>();
|
|
54
57
|
spotOracleMap = new Map<number, PublicKey>();
|
|
58
|
+
spotOracleStringMap = new Map<number, string>();
|
|
55
59
|
oracles = new Map<string, DataAndSlot<OraclePriceData>>();
|
|
56
60
|
user?: DataAndSlot<UserAccount>;
|
|
57
61
|
|
|
@@ -470,6 +474,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
470
474
|
);
|
|
471
475
|
}
|
|
472
476
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
477
|
+
this.perpOracleStringMap.set(perpMarketIndex, oracle.toBase58());
|
|
473
478
|
}
|
|
474
479
|
await Promise.all(oraclePromises);
|
|
475
480
|
}
|
|
@@ -490,6 +495,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
490
495
|
);
|
|
491
496
|
}
|
|
492
497
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
498
|
+
this.spotOracleStringMap.set(spotMarketIndex, oracle.toBase58());
|
|
493
499
|
}
|
|
494
500
|
await Promise.all(oraclePromises);
|
|
495
501
|
}
|
|
@@ -528,17 +534,21 @@ export class PollingDriftClientAccountSubscriber
|
|
|
528
534
|
}
|
|
529
535
|
|
|
530
536
|
public getOraclePriceDataAndSlot(
|
|
531
|
-
oraclePublicKey: PublicKey
|
|
537
|
+
oraclePublicKey: PublicKey | string
|
|
532
538
|
): DataAndSlot<OraclePriceData> | undefined {
|
|
533
539
|
this.assertIsSubscribed();
|
|
534
|
-
|
|
540
|
+
const oracleString =
|
|
541
|
+
typeof oraclePublicKey === 'string'
|
|
542
|
+
? oraclePublicKey
|
|
543
|
+
: oraclePublicKey.toBase58();
|
|
544
|
+
if (oracleString === ORACLE_DEFAULT_KEY) {
|
|
535
545
|
return {
|
|
536
546
|
data: QUOTE_ORACLE_PRICE_DATA,
|
|
537
547
|
slot: 0,
|
|
538
548
|
};
|
|
539
549
|
}
|
|
540
550
|
|
|
541
|
-
return this.oracles.get(
|
|
551
|
+
return this.oracles.get(oracleString);
|
|
542
552
|
}
|
|
543
553
|
|
|
544
554
|
public getOraclePriceDataAndSlotForPerpMarket(
|
|
@@ -546,6 +556,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
546
556
|
): DataAndSlot<OraclePriceData> | undefined {
|
|
547
557
|
const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
|
|
548
558
|
const oracle = this.perpOracleMap.get(marketIndex);
|
|
559
|
+
const oracleString = this.perpOracleStringMap.get(marketIndex);
|
|
549
560
|
|
|
550
561
|
if (!perpMarketAccount || !oracle) {
|
|
551
562
|
return undefined;
|
|
@@ -556,7 +567,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
556
567
|
this.setPerpOracleMap();
|
|
557
568
|
}
|
|
558
569
|
|
|
559
|
-
return this.getOraclePriceDataAndSlot(
|
|
570
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
560
571
|
}
|
|
561
572
|
|
|
562
573
|
public getOraclePriceDataAndSlotForSpotMarket(
|
|
@@ -564,6 +575,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
564
575
|
): DataAndSlot<OraclePriceData> | undefined {
|
|
565
576
|
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
566
577
|
const oracle = this.spotOracleMap.get(marketIndex);
|
|
578
|
+
const oracleString = this.spotOracleStringMap.get(marketIndex);
|
|
567
579
|
if (!spotMarketAccount || !oracle) {
|
|
568
580
|
return undefined;
|
|
569
581
|
}
|
|
@@ -573,7 +585,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
573
585
|
this.setSpotOracleMap();
|
|
574
586
|
}
|
|
575
587
|
|
|
576
|
-
return this.getOraclePriceDataAndSlot(
|
|
588
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
577
589
|
}
|
|
578
590
|
|
|
579
591
|
public updateAccountLoaderPollingFrequency(pollingFrequency: number): void {
|
package/src/accounts/types.ts
CHANGED
|
@@ -72,7 +72,7 @@ export interface DriftClientAccountSubscriber {
|
|
|
72
72
|
): DataAndSlot<SpotMarketAccount> | undefined;
|
|
73
73
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
74
74
|
getOraclePriceDataAndSlot(
|
|
75
|
-
oraclePublicKey: PublicKey
|
|
75
|
+
oraclePublicKey: PublicKey | string
|
|
76
76
|
): DataAndSlot<OraclePriceData> | undefined;
|
|
77
77
|
getOraclePriceDataAndSlotForPerpMarket(
|
|
78
78
|
marketIndex: number
|
|
@@ -24,6 +24,8 @@ import * as Buffer from 'buffer';
|
|
|
24
24
|
import { QUOTE_ORACLE_PRICE_DATA } from '../oracles/quoteAssetOracleClient';
|
|
25
25
|
import { findAllMarketAndOracles } from '../config';
|
|
26
26
|
|
|
27
|
+
const ORACLE_DEFAULT_KEY = PublicKey.default.toBase58();
|
|
28
|
+
|
|
27
29
|
export class WebSocketDriftClientAccountSubscriber
|
|
28
30
|
implements DriftClientAccountSubscriber
|
|
29
31
|
{
|
|
@@ -45,11 +47,13 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
45
47
|
AccountSubscriber<PerpMarketAccount>
|
|
46
48
|
>();
|
|
47
49
|
perpOracleMap = new Map<number, PublicKey>();
|
|
50
|
+
perpOracleStringMap = new Map<number, string>();
|
|
48
51
|
spotMarketAccountSubscribers = new Map<
|
|
49
52
|
number,
|
|
50
53
|
AccountSubscriber<SpotMarketAccount>
|
|
51
54
|
>();
|
|
52
55
|
spotOracleMap = new Map<number, PublicKey>();
|
|
56
|
+
spotOracleStringMap = new Map<number, string>();
|
|
53
57
|
oracleSubscribers = new Map<string, AccountSubscriber<OraclePriceData>>();
|
|
54
58
|
|
|
55
59
|
initialPerpMarketAccountData: Map<number, PerpMarketAccount>;
|
|
@@ -315,7 +319,11 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
315
319
|
this.resubOpts,
|
|
316
320
|
this.commitment
|
|
317
321
|
);
|
|
318
|
-
|
|
322
|
+
const initialOraclePriceData =
|
|
323
|
+
this.initialOraclePriceData.get(oracleString);
|
|
324
|
+
if (initialOraclePriceData) {
|
|
325
|
+
accountSubscriber.setData(initialOraclePriceData);
|
|
326
|
+
}
|
|
319
327
|
await accountSubscriber.subscribe((data: OraclePriceData) => {
|
|
320
328
|
this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey, data);
|
|
321
329
|
this.eventEmitter.emit('update');
|
|
@@ -432,6 +440,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
432
440
|
);
|
|
433
441
|
}
|
|
434
442
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
443
|
+
this.perpOracleStringMap.set(perpMarketIndex, oracle.toBase58());
|
|
435
444
|
}
|
|
436
445
|
await Promise.all(addOraclePromises);
|
|
437
446
|
}
|
|
@@ -455,6 +464,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
455
464
|
);
|
|
456
465
|
}
|
|
457
466
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
467
|
+
this.spotOracleStringMap.set(spotMarketIndex, oracle.toBase58());
|
|
458
468
|
}
|
|
459
469
|
await Promise.all(addOraclePromises);
|
|
460
470
|
}
|
|
@@ -499,16 +509,20 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
499
509
|
}
|
|
500
510
|
|
|
501
511
|
public getOraclePriceDataAndSlot(
|
|
502
|
-
oraclePublicKey: PublicKey
|
|
512
|
+
oraclePublicKey: PublicKey | string
|
|
503
513
|
): DataAndSlot<OraclePriceData> | undefined {
|
|
504
514
|
this.assertIsSubscribed();
|
|
505
|
-
|
|
515
|
+
const oracleString =
|
|
516
|
+
typeof oraclePublicKey === 'string'
|
|
517
|
+
? oraclePublicKey
|
|
518
|
+
: oraclePublicKey.toBase58();
|
|
519
|
+
if (oracleString === ORACLE_DEFAULT_KEY) {
|
|
506
520
|
return {
|
|
507
521
|
data: QUOTE_ORACLE_PRICE_DATA,
|
|
508
522
|
slot: 0,
|
|
509
523
|
};
|
|
510
524
|
}
|
|
511
|
-
return this.oracleSubscribers.get(
|
|
525
|
+
return this.oracleSubscribers.get(oracleString).dataAndSlot;
|
|
512
526
|
}
|
|
513
527
|
|
|
514
528
|
public getOraclePriceDataAndSlotForPerpMarket(
|
|
@@ -516,6 +530,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
516
530
|
): DataAndSlot<OraclePriceData> | undefined {
|
|
517
531
|
const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
|
|
518
532
|
const oracle = this.perpOracleMap.get(marketIndex);
|
|
533
|
+
const oracleString = this.perpOracleStringMap.get(marketIndex);
|
|
519
534
|
if (!perpMarketAccount || !oracle) {
|
|
520
535
|
return undefined;
|
|
521
536
|
}
|
|
@@ -525,7 +540,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
525
540
|
this.setPerpOracleMap();
|
|
526
541
|
}
|
|
527
542
|
|
|
528
|
-
return this.getOraclePriceDataAndSlot(
|
|
543
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
529
544
|
}
|
|
530
545
|
|
|
531
546
|
public getOraclePriceDataAndSlotForSpotMarket(
|
|
@@ -533,6 +548,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
533
548
|
): DataAndSlot<OraclePriceData> | undefined {
|
|
534
549
|
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
535
550
|
const oracle = this.spotOracleMap.get(marketIndex);
|
|
551
|
+
const oracleString = this.spotOracleStringMap.get(marketIndex);
|
|
536
552
|
if (!spotMarketAccount || !oracle) {
|
|
537
553
|
return undefined;
|
|
538
554
|
}
|
|
@@ -542,6 +558,6 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
542
558
|
this.setSpotOracleMap();
|
|
543
559
|
}
|
|
544
560
|
|
|
545
|
-
return this.getOraclePriceDataAndSlot(
|
|
561
|
+
return this.getOraclePriceDataAndSlot(oracleString);
|
|
546
562
|
}
|
|
547
563
|
}
|
package/src/driftClient.ts
CHANGED
|
@@ -538,7 +538,9 @@ export class DriftClient {
|
|
|
538
538
|
public getOraclePriceDataAndSlot(
|
|
539
539
|
oraclePublicKey: PublicKey
|
|
540
540
|
): DataAndSlot<OraclePriceData> | undefined {
|
|
541
|
-
return this.accountSubscriber.getOraclePriceDataAndSlot(
|
|
541
|
+
return this.accountSubscriber.getOraclePriceDataAndSlot(
|
|
542
|
+
oraclePublicKey.toBase58()
|
|
543
|
+
);
|
|
542
544
|
}
|
|
543
545
|
|
|
544
546
|
public async getSerumV3FulfillmentConfig(
|
|
@@ -3221,11 +3223,18 @@ export class DriftClient {
|
|
|
3221
3223
|
writablePerpMarketIndexes: [marketIndex],
|
|
3222
3224
|
writableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
3223
3225
|
});
|
|
3226
|
+
const perpMarketPublicKey = await getPerpMarketPublicKey(
|
|
3227
|
+
this.program.programId,
|
|
3228
|
+
marketIndex
|
|
3229
|
+
);
|
|
3224
3230
|
|
|
3225
3231
|
return await this.program.instruction.settleExpiredMarket(marketIndex, {
|
|
3226
3232
|
accounts: {
|
|
3227
3233
|
state: await this.getStatePublicKey(),
|
|
3228
|
-
|
|
3234
|
+
admin: this.isSubscribed
|
|
3235
|
+
? this.getStateAccount().admin
|
|
3236
|
+
: this.wallet.publicKey,
|
|
3237
|
+
perpMarket: perpMarketPublicKey,
|
|
3229
3238
|
},
|
|
3230
3239
|
remainingAccounts,
|
|
3231
3240
|
});
|
package/src/idl/drift.json
CHANGED
|
@@ -1606,15 +1606,20 @@
|
|
|
1606
1606
|
{
|
|
1607
1607
|
"name": "settleExpiredMarket",
|
|
1608
1608
|
"accounts": [
|
|
1609
|
+
{
|
|
1610
|
+
"name": "admin",
|
|
1611
|
+
"isMut": false,
|
|
1612
|
+
"isSigner": true
|
|
1613
|
+
},
|
|
1609
1614
|
{
|
|
1610
1615
|
"name": "state",
|
|
1611
1616
|
"isMut": false,
|
|
1612
1617
|
"isSigner": false
|
|
1613
1618
|
},
|
|
1614
1619
|
{
|
|
1615
|
-
"name": "
|
|
1616
|
-
"isMut":
|
|
1617
|
-
"isSigner":
|
|
1620
|
+
"name": "perpMarket",
|
|
1621
|
+
"isMut": true,
|
|
1622
|
+
"isSigner": false
|
|
1618
1623
|
}
|
|
1619
1624
|
],
|
|
1620
1625
|
"args": [
|