@drift-labs/sdk 2.86.0-beta.1 → 2.86.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/pollingDriftClientAccountSubscriber.js +24 -16
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +25 -32
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/constants/spotMarkets.js +11 -0
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +38 -23
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +55 -38
- package/src/constants/perpMarkets.ts +10 -0
- package/src/constants/spotMarkets.ts +13 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.86.0-beta.
|
|
1
|
+
2.86.0-beta.3
|
|
@@ -47,7 +47,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
47
47
|
this.oracleInfos = oracleInfos;
|
|
48
48
|
}
|
|
49
49
|
await this.updateAccountsToPoll();
|
|
50
|
-
|
|
50
|
+
this.updateOraclesToPoll();
|
|
51
51
|
await this.addToAccountLoader();
|
|
52
52
|
let subscriptionSucceeded = false;
|
|
53
53
|
let retries = 0;
|
|
@@ -59,8 +59,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
59
59
|
if (subscriptionSucceeded) {
|
|
60
60
|
this.eventEmitter.emit('update');
|
|
61
61
|
}
|
|
62
|
-
await this.setPerpOracleMap();
|
|
63
|
-
await this.setSpotOracleMap();
|
|
62
|
+
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
64
63
|
this.isSubscribing = false;
|
|
65
64
|
this.isSubscribed = subscriptionSucceeded;
|
|
66
65
|
this.subscriptionPromiseResolver(subscriptionSucceeded);
|
|
@@ -76,13 +75,15 @@ class PollingDriftClientAccountSubscriber {
|
|
|
76
75
|
publicKey: statePublicKey,
|
|
77
76
|
eventType: 'stateAccountUpdate',
|
|
78
77
|
});
|
|
79
|
-
await
|
|
80
|
-
|
|
78
|
+
await Promise.all([
|
|
79
|
+
this.updatePerpMarketAccountsToPoll(),
|
|
80
|
+
this.updateSpotMarketAccountsToPoll(),
|
|
81
|
+
]);
|
|
81
82
|
}
|
|
82
83
|
async updatePerpMarketAccountsToPoll() {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
84
|
+
await Promise.all(this.perpMarketIndexes.map((marketIndex) => {
|
|
85
|
+
return this.addPerpMarketAccountToPoll(marketIndex);
|
|
86
|
+
}));
|
|
86
87
|
return true;
|
|
87
88
|
}
|
|
88
89
|
async addPerpMarketAccountToPoll(marketIndex) {
|
|
@@ -96,9 +97,9 @@ class PollingDriftClientAccountSubscriber {
|
|
|
96
97
|
return true;
|
|
97
98
|
}
|
|
98
99
|
async updateSpotMarketAccountsToPoll() {
|
|
99
|
-
|
|
100
|
+
await Promise.all(this.spotMarketIndexes.map(async (marketIndex) => {
|
|
100
101
|
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
101
|
-
}
|
|
102
|
+
}));
|
|
102
103
|
return true;
|
|
103
104
|
}
|
|
104
105
|
async addSpotMarketAccountToPoll(marketIndex) {
|
|
@@ -127,12 +128,15 @@ class PollingDriftClientAccountSubscriber {
|
|
|
127
128
|
return true;
|
|
128
129
|
}
|
|
129
130
|
async addToAccountLoader() {
|
|
131
|
+
const accountPromises = [];
|
|
130
132
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
131
|
-
|
|
133
|
+
accountPromises.push(this.addAccountToAccountLoader(accountToPoll));
|
|
132
134
|
}
|
|
135
|
+
const oraclePromises = [];
|
|
133
136
|
for (const [_, oracleToPoll] of this.oraclesToPoll) {
|
|
134
|
-
|
|
137
|
+
oraclePromises.push(this.addOracleToAccountLoader(oracleToPoll));
|
|
135
138
|
}
|
|
139
|
+
await Promise.all([...accountPromises, ...oraclePromises]);
|
|
136
140
|
this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
|
|
137
141
|
this.eventEmitter.emit('error', error);
|
|
138
142
|
});
|
|
@@ -284,33 +288,37 @@ class PollingDriftClientAccountSubscriber {
|
|
|
284
288
|
}
|
|
285
289
|
async setPerpOracleMap() {
|
|
286
290
|
const perpMarkets = this.getMarketAccountsAndSlots();
|
|
291
|
+
const oraclePromises = [];
|
|
287
292
|
for (const perpMarket of perpMarkets) {
|
|
288
293
|
const perpMarketAccount = perpMarket.data;
|
|
289
294
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
290
295
|
const oracle = perpMarketAccount.amm.oracle;
|
|
291
296
|
if (!this.oracles.has(oracle.toBase58())) {
|
|
292
|
-
|
|
297
|
+
oraclePromises.push(this.addOracle({
|
|
293
298
|
publicKey: oracle,
|
|
294
299
|
source: perpMarketAccount.amm.oracleSource,
|
|
295
|
-
});
|
|
300
|
+
}));
|
|
296
301
|
}
|
|
297
302
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
298
303
|
}
|
|
304
|
+
await Promise.all(oraclePromises);
|
|
299
305
|
}
|
|
300
306
|
async setSpotOracleMap() {
|
|
301
307
|
const spotMarkets = this.getSpotMarketAccountsAndSlots();
|
|
308
|
+
const oraclePromises = [];
|
|
302
309
|
for (const spotMarket of spotMarkets) {
|
|
303
310
|
const spotMarketAccount = spotMarket.data;
|
|
304
311
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
305
312
|
const oracle = spotMarketAccount.oracle;
|
|
306
313
|
if (!this.oracles.has(oracle.toBase58())) {
|
|
307
|
-
|
|
314
|
+
oraclePromises.push(this.addOracle({
|
|
308
315
|
publicKey: oracle,
|
|
309
316
|
source: spotMarketAccount.oracleSource,
|
|
310
|
-
});
|
|
317
|
+
}));
|
|
311
318
|
}
|
|
312
319
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
313
320
|
}
|
|
321
|
+
await Promise.all(oraclePromises);
|
|
314
322
|
}
|
|
315
323
|
assertIsSubscribed() {
|
|
316
324
|
if (!this.isSubscribed) {
|
|
@@ -52,24 +52,23 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
52
52
|
this.eventEmitter.emit('stateAccountUpdate', data);
|
|
53
53
|
this.eventEmitter.emit('update');
|
|
54
54
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
await Promise.all([
|
|
56
|
+
// subscribe to market accounts
|
|
57
|
+
this.subscribeToPerpMarketAccounts(),
|
|
58
|
+
// subscribe to spot market accounts
|
|
59
|
+
this.subscribeToSpotMarketAccounts(),
|
|
60
|
+
// subscribe to oracles
|
|
61
|
+
this.subscribeToOracles(),
|
|
62
|
+
]);
|
|
61
63
|
this.eventEmitter.emit('update');
|
|
62
|
-
await this.setPerpOracleMap();
|
|
63
|
-
await this.setSpotOracleMap();
|
|
64
|
+
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
64
65
|
this.isSubscribing = false;
|
|
65
66
|
this.isSubscribed = true;
|
|
66
67
|
this.subscriptionPromiseResolver(true);
|
|
67
68
|
return true;
|
|
68
69
|
}
|
|
69
70
|
async subscribeToPerpMarketAccounts() {
|
|
70
|
-
|
|
71
|
-
await this.subscribeToPerpMarketAccount(marketIndex);
|
|
72
|
-
}
|
|
71
|
+
await Promise.all(this.perpMarketIndexes.map((marketIndex) => this.subscribeToPerpMarketAccount(marketIndex)));
|
|
73
72
|
return true;
|
|
74
73
|
}
|
|
75
74
|
async subscribeToPerpMarketAccount(marketIndex) {
|
|
@@ -83,9 +82,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
83
82
|
return true;
|
|
84
83
|
}
|
|
85
84
|
async subscribeToSpotMarketAccounts() {
|
|
86
|
-
|
|
87
|
-
await this.subscribeToSpotMarketAccount(marketIndex);
|
|
88
|
-
}
|
|
85
|
+
await Promise.all(this.spotMarketIndexes.map((marketIndex) => this.subscribeToSpotMarketAccount(marketIndex)));
|
|
89
86
|
return true;
|
|
90
87
|
}
|
|
91
88
|
async subscribeToSpotMarketAccount(marketIndex) {
|
|
@@ -99,11 +96,9 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
99
96
|
return true;
|
|
100
97
|
}
|
|
101
98
|
async subscribeToOracles() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
}
|
|
99
|
+
await Promise.all(this.oracleInfos
|
|
100
|
+
.filter((oracleInfo) => !oracleInfo.publicKey.equals(web3_js_1.PublicKey.default))
|
|
101
|
+
.map((oracleInfo) => this.subscribeToOracle(oracleInfo)));
|
|
107
102
|
return true;
|
|
108
103
|
}
|
|
109
104
|
async subscribeToOracle(oracleInfo) {
|
|
@@ -119,19 +114,13 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
119
114
|
return true;
|
|
120
115
|
}
|
|
121
116
|
async unsubscribeFromMarketAccounts() {
|
|
122
|
-
|
|
123
|
-
await accountSubscriber.unsubscribe();
|
|
124
|
-
}
|
|
117
|
+
await Promise.all(Array.from(this.perpMarketAccountSubscribers.values()).map((accountSubscriber) => accountSubscriber.unsubscribe()));
|
|
125
118
|
}
|
|
126
119
|
async unsubscribeFromSpotMarketAccounts() {
|
|
127
|
-
|
|
128
|
-
await accountSubscriber.unsubscribe();
|
|
129
|
-
}
|
|
120
|
+
await Promise.all(Array.from(this.spotMarketAccountSubscribers.values()).map((accountSubscriber) => accountSubscriber.unsubscribe()));
|
|
130
121
|
}
|
|
131
122
|
async unsubscribeFromOracles() {
|
|
132
|
-
|
|
133
|
-
await accountSubscriber.unsubscribe();
|
|
134
|
-
}
|
|
123
|
+
await Promise.all(Array.from(this.oracleSubscribers.values()).map((accountSubscriber) => accountSubscriber.unsubscribe()));
|
|
135
124
|
}
|
|
136
125
|
async fetch() {
|
|
137
126
|
if (!this.isSubscribed) {
|
|
@@ -179,6 +168,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
179
168
|
}
|
|
180
169
|
async setPerpOracleMap() {
|
|
181
170
|
const perpMarkets = this.getMarketAccountsAndSlots();
|
|
171
|
+
const addOraclePromises = [];
|
|
182
172
|
for (const perpMarket of perpMarkets) {
|
|
183
173
|
if (!perpMarket) {
|
|
184
174
|
continue;
|
|
@@ -187,16 +177,18 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
187
177
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
188
178
|
const oracle = perpMarketAccount.amm.oracle;
|
|
189
179
|
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
190
|
-
|
|
180
|
+
addOraclePromises.push(this.addOracle({
|
|
191
181
|
publicKey: oracle,
|
|
192
182
|
source: perpMarket.data.amm.oracleSource,
|
|
193
|
-
});
|
|
183
|
+
}));
|
|
194
184
|
}
|
|
195
185
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
196
186
|
}
|
|
187
|
+
await Promise.all(addOraclePromises);
|
|
197
188
|
}
|
|
198
189
|
async setSpotOracleMap() {
|
|
199
190
|
const spotMarkets = this.getSpotMarketAccountsAndSlots();
|
|
191
|
+
const addOraclePromises = [];
|
|
200
192
|
for (const spotMarket of spotMarkets) {
|
|
201
193
|
if (!spotMarket) {
|
|
202
194
|
continue;
|
|
@@ -205,13 +197,14 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
205
197
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
206
198
|
const oracle = spotMarketAccount.oracle;
|
|
207
199
|
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
208
|
-
|
|
200
|
+
addOraclePromises.push(this.addOracle({
|
|
209
201
|
publicKey: oracle,
|
|
210
202
|
source: spotMarketAccount.oracleSource,
|
|
211
|
-
});
|
|
203
|
+
}));
|
|
212
204
|
}
|
|
213
205
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
214
206
|
}
|
|
207
|
+
await Promise.all(addOraclePromises);
|
|
215
208
|
}
|
|
216
209
|
assertIsSubscribed() {
|
|
217
210
|
if (!this.isSubscribed) {
|
|
@@ -653,6 +653,16 @@ exports.MainnetPerpMarkets = [
|
|
|
653
653
|
launchTs: 1719415157000,
|
|
654
654
|
oracleSource: __1.OracleSource.SWITCHBOARD,
|
|
655
655
|
},
|
|
656
|
+
{
|
|
657
|
+
fullName: 'POPCAT',
|
|
658
|
+
category: ['Meme', 'Solana'],
|
|
659
|
+
symbol: 'POPCAT-PERP',
|
|
660
|
+
baseAssetSymbol: 'POPCAT',
|
|
661
|
+
marketIndex: 34,
|
|
662
|
+
oracle: new web3_js_1.PublicKey('2stQe1XLGkuTZ22gQrgZKsb93iG9mWXSLfANMPRjs5Ky'),
|
|
663
|
+
launchTs: 1720013054000,
|
|
664
|
+
oracleSource: __1.OracleSource.SWITCHBOARD,
|
|
665
|
+
},
|
|
656
666
|
];
|
|
657
667
|
exports.PerpMarkets = {
|
|
658
668
|
devnet: exports.DevnetPerpMarkets,
|
|
@@ -268,6 +268,17 @@ exports.MainnetSpotMarkets = [
|
|
|
268
268
|
precisionExp: numericConstants_1.SIX,
|
|
269
269
|
launchTs: 1719415157000,
|
|
270
270
|
},
|
|
271
|
+
{
|
|
272
|
+
symbol: 'POPCAT',
|
|
273
|
+
marketIndex: 20,
|
|
274
|
+
oracle: new web3_js_1.PublicKey('2stQe1XLGkuTZ22gQrgZKsb93iG9mWXSLfANMPRjs5Ky'),
|
|
275
|
+
oracleSource: __1.OracleSource.SWITCHBOARD,
|
|
276
|
+
mint: new web3_js_1.PublicKey('7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr'),
|
|
277
|
+
precision: new __1.BN(10).pow(numericConstants_1.NINE),
|
|
278
|
+
precisionExp: numericConstants_1.NINE,
|
|
279
|
+
launchTs: 1720013054000,
|
|
280
|
+
phoenixMarket: new web3_js_1.PublicKey('31XgvAQ1HgFQEk31KdszbPkVXKaQqB1bgYZPoDrFpSR2'),
|
|
281
|
+
},
|
|
271
282
|
];
|
|
272
283
|
exports.SpotMarkets = {
|
|
273
284
|
devnet: exports.DevnetSpotMarkets,
|
package/package.json
CHANGED
|
@@ -101,7 +101,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
await this.updateAccountsToPoll();
|
|
104
|
-
|
|
104
|
+
this.updateOraclesToPoll();
|
|
105
105
|
await this.addToAccountLoader();
|
|
106
106
|
|
|
107
107
|
let subscriptionSucceeded = false;
|
|
@@ -116,8 +116,7 @@ export class PollingDriftClientAccountSubscriber
|
|
|
116
116
|
this.eventEmitter.emit('update');
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
await this.setPerpOracleMap();
|
|
120
|
-
await this.setSpotOracleMap();
|
|
119
|
+
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
121
120
|
|
|
122
121
|
this.isSubscribing = false;
|
|
123
122
|
this.isSubscribed = subscriptionSucceeded;
|
|
@@ -141,14 +140,18 @@ export class PollingDriftClientAccountSubscriber
|
|
|
141
140
|
eventType: 'stateAccountUpdate',
|
|
142
141
|
});
|
|
143
142
|
|
|
144
|
-
await
|
|
145
|
-
|
|
143
|
+
await Promise.all([
|
|
144
|
+
this.updatePerpMarketAccountsToPoll(),
|
|
145
|
+
this.updateSpotMarketAccountsToPoll(),
|
|
146
|
+
]);
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
async updatePerpMarketAccountsToPoll(): Promise<boolean> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
await Promise.all(
|
|
151
|
+
this.perpMarketIndexes.map((marketIndex) => {
|
|
152
|
+
return this.addPerpMarketAccountToPoll(marketIndex);
|
|
153
|
+
})
|
|
154
|
+
);
|
|
152
155
|
return true;
|
|
153
156
|
}
|
|
154
157
|
|
|
@@ -169,9 +172,11 @@ export class PollingDriftClientAccountSubscriber
|
|
|
169
172
|
}
|
|
170
173
|
|
|
171
174
|
async updateSpotMarketAccountsToPoll(): Promise<boolean> {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
await Promise.all(
|
|
176
|
+
this.spotMarketIndexes.map(async (marketIndex) => {
|
|
177
|
+
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
178
|
+
})
|
|
179
|
+
);
|
|
175
180
|
|
|
176
181
|
return true;
|
|
177
182
|
}
|
|
@@ -209,16 +214,19 @@ export class PollingDriftClientAccountSubscriber
|
|
|
209
214
|
|
|
210
215
|
return true;
|
|
211
216
|
}
|
|
212
|
-
|
|
213
217
|
async addToAccountLoader(): Promise<void> {
|
|
218
|
+
const accountPromises = [];
|
|
214
219
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
215
|
-
|
|
220
|
+
accountPromises.push(this.addAccountToAccountLoader(accountToPoll));
|
|
216
221
|
}
|
|
217
222
|
|
|
223
|
+
const oraclePromises = [];
|
|
218
224
|
for (const [_, oracleToPoll] of this.oraclesToPoll) {
|
|
219
|
-
|
|
225
|
+
oraclePromises.push(this.addOracleToAccountLoader(oracleToPoll));
|
|
220
226
|
}
|
|
221
227
|
|
|
228
|
+
await Promise.all([...accountPromises, ...oraclePromises]);
|
|
229
|
+
|
|
222
230
|
this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
|
|
223
231
|
this.eventEmitter.emit('error', error);
|
|
224
232
|
});
|
|
@@ -446,37 +454,44 @@ export class PollingDriftClientAccountSubscriber
|
|
|
446
454
|
}
|
|
447
455
|
console.log(`Pausing to find oracle ${oracle} failed`);
|
|
448
456
|
}
|
|
449
|
-
|
|
450
457
|
async setPerpOracleMap() {
|
|
451
458
|
const perpMarkets = this.getMarketAccountsAndSlots();
|
|
459
|
+
const oraclePromises = [];
|
|
452
460
|
for (const perpMarket of perpMarkets) {
|
|
453
461
|
const perpMarketAccount = perpMarket.data;
|
|
454
462
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
455
463
|
const oracle = perpMarketAccount.amm.oracle;
|
|
456
464
|
if (!this.oracles.has(oracle.toBase58())) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
465
|
+
oraclePromises.push(
|
|
466
|
+
this.addOracle({
|
|
467
|
+
publicKey: oracle,
|
|
468
|
+
source: perpMarketAccount.amm.oracleSource,
|
|
469
|
+
})
|
|
470
|
+
);
|
|
461
471
|
}
|
|
462
472
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
463
473
|
}
|
|
474
|
+
await Promise.all(oraclePromises);
|
|
464
475
|
}
|
|
465
476
|
|
|
466
477
|
async setSpotOracleMap() {
|
|
467
478
|
const spotMarkets = this.getSpotMarketAccountsAndSlots();
|
|
479
|
+
const oraclePromises = [];
|
|
468
480
|
for (const spotMarket of spotMarkets) {
|
|
469
481
|
const spotMarketAccount = spotMarket.data;
|
|
470
482
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
471
483
|
const oracle = spotMarketAccount.oracle;
|
|
472
484
|
if (!this.oracles.has(oracle.toBase58())) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
485
|
+
oraclePromises.push(
|
|
486
|
+
this.addOracle({
|
|
487
|
+
publicKey: oracle,
|
|
488
|
+
source: spotMarketAccount.oracleSource,
|
|
489
|
+
})
|
|
490
|
+
);
|
|
477
491
|
}
|
|
478
492
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
479
493
|
}
|
|
494
|
+
await Promise.all(oraclePromises);
|
|
480
495
|
}
|
|
481
496
|
|
|
482
497
|
assertIsSubscribed(): void {
|
|
@@ -115,19 +115,18 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
115
115
|
this.eventEmitter.emit('update');
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
await Promise.all([
|
|
119
|
+
// subscribe to market accounts
|
|
120
|
+
this.subscribeToPerpMarketAccounts(),
|
|
121
|
+
// subscribe to spot market accounts
|
|
122
|
+
this.subscribeToSpotMarketAccounts(),
|
|
123
|
+
// subscribe to oracles
|
|
124
|
+
this.subscribeToOracles(),
|
|
125
|
+
]);
|
|
126
126
|
|
|
127
127
|
this.eventEmitter.emit('update');
|
|
128
128
|
|
|
129
|
-
await this.setPerpOracleMap();
|
|
130
|
-
await this.setSpotOracleMap();
|
|
129
|
+
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
131
130
|
|
|
132
131
|
this.isSubscribing = false;
|
|
133
132
|
this.isSubscribed = true;
|
|
@@ -137,9 +136,11 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
async subscribeToPerpMarketAccounts(): Promise<boolean> {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
await Promise.all(
|
|
140
|
+
this.perpMarketIndexes.map((marketIndex) =>
|
|
141
|
+
this.subscribeToPerpMarketAccount(marketIndex)
|
|
142
|
+
)
|
|
143
|
+
);
|
|
143
144
|
return true;
|
|
144
145
|
}
|
|
145
146
|
|
|
@@ -165,9 +166,11 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
async subscribeToSpotMarketAccounts(): Promise<boolean> {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
await Promise.all(
|
|
170
|
+
this.spotMarketIndexes.map((marketIndex) =>
|
|
171
|
+
this.subscribeToSpotMarketAccount(marketIndex)
|
|
172
|
+
)
|
|
173
|
+
);
|
|
171
174
|
return true;
|
|
172
175
|
}
|
|
173
176
|
|
|
@@ -193,11 +196,11 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
async subscribeToOracles(): Promise<boolean> {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
await Promise.all(
|
|
200
|
+
this.oracleInfos
|
|
201
|
+
.filter((oracleInfo) => !oracleInfo.publicKey.equals(PublicKey.default))
|
|
202
|
+
.map((oracleInfo) => this.subscribeToOracle(oracleInfo))
|
|
203
|
+
);
|
|
201
204
|
|
|
202
205
|
return true;
|
|
203
206
|
}
|
|
@@ -232,21 +235,27 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
232
235
|
}
|
|
233
236
|
|
|
234
237
|
async unsubscribeFromMarketAccounts(): Promise<void> {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
await Promise.all(
|
|
239
|
+
Array.from(this.perpMarketAccountSubscribers.values()).map(
|
|
240
|
+
(accountSubscriber) => accountSubscriber.unsubscribe()
|
|
241
|
+
)
|
|
242
|
+
);
|
|
238
243
|
}
|
|
239
244
|
|
|
240
245
|
async unsubscribeFromSpotMarketAccounts(): Promise<void> {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
await Promise.all(
|
|
247
|
+
Array.from(this.spotMarketAccountSubscribers.values()).map(
|
|
248
|
+
(accountSubscriber) => accountSubscriber.unsubscribe()
|
|
249
|
+
)
|
|
250
|
+
);
|
|
244
251
|
}
|
|
245
252
|
|
|
246
253
|
async unsubscribeFromOracles(): Promise<void> {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
await Promise.all(
|
|
255
|
+
Array.from(this.oracleSubscribers.values()).map((accountSubscriber) =>
|
|
256
|
+
accountSubscriber.unsubscribe()
|
|
257
|
+
)
|
|
258
|
+
);
|
|
250
259
|
}
|
|
251
260
|
|
|
252
261
|
public async fetch(): Promise<void> {
|
|
@@ -315,6 +324,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
315
324
|
|
|
316
325
|
async setPerpOracleMap() {
|
|
317
326
|
const perpMarkets = this.getMarketAccountsAndSlots();
|
|
327
|
+
const addOraclePromises = [];
|
|
318
328
|
for (const perpMarket of perpMarkets) {
|
|
319
329
|
if (!perpMarket) {
|
|
320
330
|
continue;
|
|
@@ -323,17 +333,21 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
323
333
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
324
334
|
const oracle = perpMarketAccount.amm.oracle;
|
|
325
335
|
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
336
|
+
addOraclePromises.push(
|
|
337
|
+
this.addOracle({
|
|
338
|
+
publicKey: oracle,
|
|
339
|
+
source: perpMarket.data.amm.oracleSource,
|
|
340
|
+
})
|
|
341
|
+
);
|
|
330
342
|
}
|
|
331
343
|
this.perpOracleMap.set(perpMarketIndex, oracle);
|
|
332
344
|
}
|
|
345
|
+
await Promise.all(addOraclePromises);
|
|
333
346
|
}
|
|
334
347
|
|
|
335
348
|
async setSpotOracleMap() {
|
|
336
349
|
const spotMarkets = this.getSpotMarketAccountsAndSlots();
|
|
350
|
+
const addOraclePromises = [];
|
|
337
351
|
for (const spotMarket of spotMarkets) {
|
|
338
352
|
if (!spotMarket) {
|
|
339
353
|
continue;
|
|
@@ -342,13 +356,16 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
342
356
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
343
357
|
const oracle = spotMarketAccount.oracle;
|
|
344
358
|
if (!this.oracleSubscribers.has(oracle.toBase58())) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
359
|
+
addOraclePromises.push(
|
|
360
|
+
this.addOracle({
|
|
361
|
+
publicKey: oracle,
|
|
362
|
+
source: spotMarketAccount.oracleSource,
|
|
363
|
+
})
|
|
364
|
+
);
|
|
349
365
|
}
|
|
350
366
|
this.spotOracleMap.set(spotMarketIndex, oracle);
|
|
351
367
|
}
|
|
368
|
+
await Promise.all(addOraclePromises);
|
|
352
369
|
}
|
|
353
370
|
|
|
354
371
|
assertIsSubscribed(): void {
|
|
@@ -722,6 +722,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
722
722
|
launchTs: 1719415157000,
|
|
723
723
|
oracleSource: OracleSource.SWITCHBOARD,
|
|
724
724
|
},
|
|
725
|
+
{
|
|
726
|
+
fullName: 'POPCAT',
|
|
727
|
+
category: ['Meme', 'Solana'],
|
|
728
|
+
symbol: 'POPCAT-PERP',
|
|
729
|
+
baseAssetSymbol: 'POPCAT',
|
|
730
|
+
marketIndex: 34,
|
|
731
|
+
oracle: new PublicKey('2stQe1XLGkuTZ22gQrgZKsb93iG9mWXSLfANMPRjs5Ky'),
|
|
732
|
+
launchTs: 1720013054000,
|
|
733
|
+
oracleSource: OracleSource.SWITCHBOARD,
|
|
734
|
+
},
|
|
725
735
|
];
|
|
726
736
|
|
|
727
737
|
export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
|
|
@@ -334,6 +334,19 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
|
|
|
334
334
|
precisionExp: SIX,
|
|
335
335
|
launchTs: 1719415157000,
|
|
336
336
|
},
|
|
337
|
+
{
|
|
338
|
+
symbol: 'POPCAT',
|
|
339
|
+
marketIndex: 20,
|
|
340
|
+
oracle: new PublicKey('2stQe1XLGkuTZ22gQrgZKsb93iG9mWXSLfANMPRjs5Ky'),
|
|
341
|
+
oracleSource: OracleSource.SWITCHBOARD,
|
|
342
|
+
mint: new PublicKey('7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr'),
|
|
343
|
+
precision: new BN(10).pow(NINE),
|
|
344
|
+
precisionExp: NINE,
|
|
345
|
+
launchTs: 1720013054000,
|
|
346
|
+
phoenixMarket: new PublicKey(
|
|
347
|
+
'31XgvAQ1HgFQEk31KdszbPkVXKaQqB1bgYZPoDrFpSR2'
|
|
348
|
+
),
|
|
349
|
+
},
|
|
337
350
|
];
|
|
338
351
|
|
|
339
352
|
export const SpotMarkets: { [key in DriftEnv]: SpotMarketConfig[] } = {
|