@drift-labs/sdk 2.142.0-beta.9 → 2.142.0
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/grpcDriftClientAccountSubscriberV2.d.ts +46 -5
- package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.js +242 -41
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +6 -3
- package/lib/browser/accounts/grpcMultiAccountSubscriber.js +112 -19
- package/lib/browser/adminClient.d.ts +4 -0
- package/lib/browser/adminClient.js +34 -0
- package/lib/browser/constants/perpMarkets.js +35 -0
- package/lib/browser/constants/spotMarkets.js +4 -4
- package/lib/browser/driftClient.d.ts +35 -5
- package/lib/browser/driftClient.js +41 -14
- package/lib/browser/events/parse.d.ts +2 -0
- package/lib/browser/events/parse.js +94 -1
- package/lib/browser/events/types.d.ts +22 -3
- package/lib/browser/idl/drift.json +105 -6
- package/lib/browser/math/amm.d.ts +1 -0
- package/lib/browser/math/amm.js +28 -4
- package/lib/browser/types.d.ts +20 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts +46 -5
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +242 -41
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +6 -3
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.js +112 -19
- package/lib/node/adminClient.d.ts +4 -0
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +34 -0
- package/lib/node/constants/perpMarkets.d.ts.map +1 -1
- package/lib/node/constants/perpMarkets.js +35 -0
- package/lib/node/constants/spotMarkets.js +4 -4
- package/lib/node/driftClient.d.ts +35 -5
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +41 -14
- package/lib/node/events/parse.d.ts +2 -0
- package/lib/node/events/parse.d.ts.map +1 -1
- package/lib/node/events/parse.js +94 -1
- package/lib/node/events/types.d.ts +22 -3
- package/lib/node/events/types.d.ts.map +1 -1
- package/lib/node/idl/drift.json +105 -6
- package/lib/node/math/amm.d.ts +1 -0
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +28 -4
- package/lib/node/types.d.ts +20 -0
- package/lib/node/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/scripts/client-test.ts +294 -135
- package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +398 -72
- package/src/accounts/grpcMultiAccountSubscriber.ts +163 -31
- package/src/adminClient.ts +74 -0
- package/src/constants/perpMarkets.ts +37 -0
- package/src/constants/spotMarkets.ts +4 -4
- package/src/driftClient.ts +65 -14
- package/src/events/parse.ts +115 -0
- package/src/events/types.ts +26 -2
- package/src/idl/drift.json +105 -6
- package/src/math/amm.ts +52 -8
- package/src/types.ts +22 -0
- package/tests/events/parseLogsForCuUsage.ts +139 -0
|
@@ -1,19 +1,116 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.grpcDriftClientAccountSubscriberV2 = void 0;
|
|
4
|
-
const
|
|
4
|
+
const events_1 = require("events");
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const config_1 = require("../config");
|
|
7
7
|
const pda_1 = require("../addresses/pda");
|
|
8
|
+
const types_1 = require("./types");
|
|
8
9
|
const grpcAccountSubscriber_1 = require("./grpcAccountSubscriber");
|
|
9
10
|
const grpcMultiAccountSubscriber_1 = require("./grpcMultiAccountSubscriber");
|
|
10
11
|
const oracleId_1 = require("../oracles/oracleId");
|
|
11
|
-
|
|
12
|
+
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
class grpcDriftClientAccountSubscriberV2 {
|
|
12
15
|
constructor(grpcConfigs, program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts) {
|
|
13
|
-
super(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts);
|
|
14
16
|
this.perpMarketIndexToAccountPubkeyMap = new Map();
|
|
15
17
|
this.spotMarketIndexToAccountPubkeyMap = new Map();
|
|
18
|
+
this.perpOracleMap = new Map();
|
|
19
|
+
this.perpOracleStringMap = new Map();
|
|
20
|
+
this.spotOracleMap = new Map();
|
|
21
|
+
this.spotOracleStringMap = new Map();
|
|
22
|
+
this.oracleIdToOracleDataMap = new Map();
|
|
23
|
+
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
24
|
+
this.chunks = (array, size) => {
|
|
25
|
+
return new Array(Math.ceil(array.length / size))
|
|
26
|
+
.fill(null)
|
|
27
|
+
.map((_, index) => index * size)
|
|
28
|
+
.map((begin) => array.slice(begin, begin + size));
|
|
29
|
+
};
|
|
30
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
31
|
+
this.isSubscribed = false;
|
|
32
|
+
this.isSubscribing = false;
|
|
33
|
+
this.program = program;
|
|
34
|
+
this.perpMarketIndexes = perpMarketIndexes;
|
|
35
|
+
this.spotMarketIndexes = spotMarketIndexes;
|
|
36
|
+
this.shouldFindAllMarketsAndOracles = shouldFindAllMarketsAndOracles;
|
|
37
|
+
this.oracleInfos = oracleInfos;
|
|
38
|
+
this.initialPerpMarketAccountData = new Map();
|
|
39
|
+
this.initialSpotMarketAccountData = new Map();
|
|
40
|
+
this.initialOraclePriceData = new Map();
|
|
41
|
+
this.perpOracleMap = new Map();
|
|
42
|
+
this.perpOracleStringMap = new Map();
|
|
43
|
+
this.spotOracleMap = new Map();
|
|
44
|
+
this.spotOracleStringMap = new Map();
|
|
16
45
|
this.grpcConfigs = grpcConfigs;
|
|
46
|
+
this.resubOpts = resubOpts;
|
|
47
|
+
this.delistedMarketSetting = delistedMarketSetting;
|
|
48
|
+
}
|
|
49
|
+
async setInitialData() {
|
|
50
|
+
const connection = this.program.provider.connection;
|
|
51
|
+
if (!this.initialPerpMarketAccountData ||
|
|
52
|
+
this.initialPerpMarketAccountData.size === 0) {
|
|
53
|
+
const perpMarketPublicKeys = this.perpMarketIndexes.map((marketIndex) => (0, pda_1.getPerpMarketPublicKeySync)(this.program.programId, marketIndex));
|
|
54
|
+
const perpMarketPublicKeysChunks = this.chunks(perpMarketPublicKeys, 75);
|
|
55
|
+
const perpMarketAccountInfos = (await Promise.all(perpMarketPublicKeysChunks.map((perpMarketPublicKeysChunk) => connection.getMultipleAccountsInfo(perpMarketPublicKeysChunk)))).flat();
|
|
56
|
+
this.initialPerpMarketAccountData = new Map(perpMarketAccountInfos
|
|
57
|
+
.filter((accountInfo) => !!accountInfo)
|
|
58
|
+
.map((accountInfo) => {
|
|
59
|
+
const perpMarket = this.program.coder.accounts.decode('PerpMarket', accountInfo.data);
|
|
60
|
+
return [perpMarket.marketIndex, perpMarket];
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
if (!this.initialSpotMarketAccountData ||
|
|
64
|
+
this.initialSpotMarketAccountData.size === 0) {
|
|
65
|
+
const spotMarketPublicKeys = this.spotMarketIndexes.map((marketIndex) => (0, pda_1.getSpotMarketPublicKeySync)(this.program.programId, marketIndex));
|
|
66
|
+
const spotMarketPublicKeysChunks = this.chunks(spotMarketPublicKeys, 75);
|
|
67
|
+
const spotMarketAccountInfos = (await Promise.all(spotMarketPublicKeysChunks.map((spotMarketPublicKeysChunk) => connection.getMultipleAccountsInfo(spotMarketPublicKeysChunk)))).flat();
|
|
68
|
+
this.initialSpotMarketAccountData = new Map(spotMarketAccountInfos
|
|
69
|
+
.filter((accountInfo) => !!accountInfo)
|
|
70
|
+
.map((accountInfo) => {
|
|
71
|
+
const spotMarket = this.program.coder.accounts.decode('SpotMarket', accountInfo.data);
|
|
72
|
+
return [spotMarket.marketIndex, spotMarket];
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
const oracleAccountPubkeyChunks = this.chunks(this.oracleInfos.map((oracleInfo) => oracleInfo.publicKey), 75);
|
|
76
|
+
const oracleAccountInfos = (await Promise.all(oracleAccountPubkeyChunks.map((oracleAccountPublicKeysChunk) => connection.getMultipleAccountsInfo(oracleAccountPublicKeysChunk)))).flat();
|
|
77
|
+
this.initialOraclePriceData = new Map(this.oracleInfos.reduce((result, oracleInfo, i) => {
|
|
78
|
+
if (!oracleAccountInfos[i]) {
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
const oracleClient = this.oracleClientCache.get(oracleInfo.source, connection, this.program);
|
|
82
|
+
const oraclePriceData = oracleClient.getOraclePriceDataFromBuffer(oracleAccountInfos[i].data);
|
|
83
|
+
result.push([
|
|
84
|
+
(0, oracleId_1.getOracleId)(oracleInfo.publicKey, oracleInfo.source),
|
|
85
|
+
oraclePriceData,
|
|
86
|
+
]);
|
|
87
|
+
return result;
|
|
88
|
+
}, []));
|
|
89
|
+
}
|
|
90
|
+
async addPerpMarket(_marketIndex) {
|
|
91
|
+
if (!this.perpMarketIndexes.includes(_marketIndex)) {
|
|
92
|
+
this.perpMarketIndexes = this.perpMarketIndexes.concat(_marketIndex);
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
async addSpotMarket(_marketIndex) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
async addOracle(oracleInfo) {
|
|
100
|
+
var _a, _c;
|
|
101
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
102
|
+
console.log('[grpcDriftClientAccountSubscriberV2] addOracle');
|
|
103
|
+
}
|
|
104
|
+
if (oracleInfo.publicKey.equals(web3_js_1.PublicKey.default)) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
const exists = this.oracleInfos.some((o) => o.source === oracleInfo.source &&
|
|
108
|
+
o.publicKey.equals(oracleInfo.publicKey));
|
|
109
|
+
if (!exists) {
|
|
110
|
+
this.oracleInfos = this.oracleInfos.concat(oracleInfo);
|
|
111
|
+
}
|
|
112
|
+
(_c = this.oracleMultiSubscriber) === null || _c === void 0 ? void 0 : _c.addAccounts([oracleInfo.publicKey]);
|
|
113
|
+
return true;
|
|
17
114
|
}
|
|
18
115
|
async subscribe() {
|
|
19
116
|
if (this.isSubscribed) {
|
|
@@ -61,6 +158,32 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
61
158
|
this.removeInitialData();
|
|
62
159
|
return true;
|
|
63
160
|
}
|
|
161
|
+
async fetch() {
|
|
162
|
+
var _a, _c, _d, _e;
|
|
163
|
+
await ((_a = this.stateAccountSubscriber) === null || _a === void 0 ? void 0 : _a.fetch());
|
|
164
|
+
await ((_c = this.perpMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.fetch());
|
|
165
|
+
await ((_d = this.spotMarketsSubscriber) === null || _d === void 0 ? void 0 : _d.fetch());
|
|
166
|
+
await ((_e = this.oracleMultiSubscriber) === null || _e === void 0 ? void 0 : _e.fetch());
|
|
167
|
+
}
|
|
168
|
+
assertIsSubscribed() {
|
|
169
|
+
if (!this.isSubscribed) {
|
|
170
|
+
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
getStateAccountAndSlot() {
|
|
174
|
+
this.assertIsSubscribed();
|
|
175
|
+
return this.stateAccountSubscriber.dataAndSlot;
|
|
176
|
+
}
|
|
177
|
+
getMarketAccountsAndSlots() {
|
|
178
|
+
var _a, _c;
|
|
179
|
+
const map = (_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
|
|
180
|
+
return Array.from((_c = map === null || map === void 0 ? void 0 : map.values()) !== null && _c !== void 0 ? _c : []);
|
|
181
|
+
}
|
|
182
|
+
getSpotMarketAccountsAndSlots() {
|
|
183
|
+
var _a, _c;
|
|
184
|
+
const map = (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
|
|
185
|
+
return Array.from((_c = map === null || map === void 0 ? void 0 : map.values()) !== null && _c !== void 0 ? _c : []);
|
|
186
|
+
}
|
|
64
187
|
getMarketAccountAndSlot(marketIndex) {
|
|
65
188
|
var _a;
|
|
66
189
|
return (_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountData(this.perpMarketIndexToAccountPubkeyMap.get(marketIndex));
|
|
@@ -69,8 +192,40 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
69
192
|
var _a;
|
|
70
193
|
return (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountData(this.spotMarketIndexToAccountPubkeyMap.get(marketIndex));
|
|
71
194
|
}
|
|
195
|
+
getOraclePriceDataAndSlot(oracleId) {
|
|
196
|
+
this.assertIsSubscribed();
|
|
197
|
+
// we need to rely on a map we store in this class because the grpcMultiAccountSubscriber does not track a mapping or oracle ID.
|
|
198
|
+
// DO NOT call getAccountData on the oracleMultiSubscriber, it will not return the correct data in certain cases(BONK spot and perp market subscribed too at once).
|
|
199
|
+
return this.oracleIdToOracleDataMap.get(oracleId);
|
|
200
|
+
}
|
|
201
|
+
getOraclePriceDataAndSlotForPerpMarket(marketIndex) {
|
|
202
|
+
const perpMarketAccount = this.getMarketAccountAndSlot(marketIndex);
|
|
203
|
+
const oracle = this.perpOracleMap.get(marketIndex);
|
|
204
|
+
const oracleId = this.perpOracleStringMap.get(marketIndex);
|
|
205
|
+
if (!perpMarketAccount || !oracleId) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
if (!perpMarketAccount.data.amm.oracle.equals(oracle)) {
|
|
209
|
+
// If the oracle has changed, we need to update the oracle map in background
|
|
210
|
+
this.setPerpOracleMap();
|
|
211
|
+
}
|
|
212
|
+
return this.getOraclePriceDataAndSlot(oracleId);
|
|
213
|
+
}
|
|
214
|
+
getOraclePriceDataAndSlotForSpotMarket(marketIndex) {
|
|
215
|
+
const spotMarketAccount = this.getSpotMarketAccountAndSlot(marketIndex);
|
|
216
|
+
const oracle = this.spotOracleMap.get(marketIndex);
|
|
217
|
+
const oracleId = this.spotOracleStringMap.get(marketIndex);
|
|
218
|
+
if (!spotMarketAccount || !oracleId) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
if (!spotMarketAccount.data.oracle.equals(oracle)) {
|
|
222
|
+
// If the oracle has changed, we need to update the oracle map in background
|
|
223
|
+
this.setSpotOracleMap();
|
|
224
|
+
}
|
|
225
|
+
return this.getOraclePriceDataAndSlot(oracleId);
|
|
226
|
+
}
|
|
72
227
|
async setPerpOracleMap() {
|
|
73
|
-
var _a;
|
|
228
|
+
var _a, _c;
|
|
74
229
|
const perpMarketsMap = (_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
|
|
75
230
|
const perpMarkets = Array.from(perpMarketsMap.values());
|
|
76
231
|
const addOraclePromises = [];
|
|
@@ -82,7 +237,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
82
237
|
const perpMarketIndex = perpMarketAccount.marketIndex;
|
|
83
238
|
const oracle = perpMarketAccount.amm.oracle;
|
|
84
239
|
const oracleId = (0, oracleId_1.getOracleId)(oracle, perpMarket.data.amm.oracleSource);
|
|
85
|
-
if (!this.
|
|
240
|
+
if (!((_c = this.oracleMultiSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().has(oracleId))) {
|
|
86
241
|
addOraclePromises.push(this.addOracle({
|
|
87
242
|
publicKey: oracle,
|
|
88
243
|
source: perpMarket.data.amm.oracleSource,
|
|
@@ -94,7 +249,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
94
249
|
await Promise.all(addOraclePromises);
|
|
95
250
|
}
|
|
96
251
|
async setSpotOracleMap() {
|
|
97
|
-
var _a;
|
|
252
|
+
var _a, _c;
|
|
98
253
|
const spotMarketsMap = (_a = this.spotMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap();
|
|
99
254
|
const spotMarkets = Array.from(spotMarketsMap.values());
|
|
100
255
|
const addOraclePromises = [];
|
|
@@ -106,7 +261,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
106
261
|
const spotMarketIndex = spotMarketAccount.marketIndex;
|
|
107
262
|
const oracle = spotMarketAccount.oracle;
|
|
108
263
|
const oracleId = (0, oracleId_1.getOracleId)(oracle, spotMarketAccount.oracleSource);
|
|
109
|
-
if (!this.
|
|
264
|
+
if (!((_c = this.oracleMultiSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().has(oracleId))) {
|
|
110
265
|
addOraclePromises.push(this.addOracle({
|
|
111
266
|
publicKey: oracle,
|
|
112
267
|
source: spotMarketAccount.oracleSource,
|
|
@@ -118,6 +273,10 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
118
273
|
await Promise.all(addOraclePromises);
|
|
119
274
|
}
|
|
120
275
|
async subscribeToPerpMarketAccounts() {
|
|
276
|
+
var _a;
|
|
277
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
278
|
+
console.log('[grpcDriftClientAccountSubscriberV2] subscribeToPerpMarketAccounts');
|
|
279
|
+
}
|
|
121
280
|
const perpMarketIndexToAccountPubkeys = await Promise.all(this.perpMarketIndexes.map(async (marketIndex) => [
|
|
122
281
|
marketIndex,
|
|
123
282
|
await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex),
|
|
@@ -149,6 +308,10 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
149
308
|
return true;
|
|
150
309
|
}
|
|
151
310
|
async subscribeToSpotMarketAccounts() {
|
|
311
|
+
var _a;
|
|
312
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
313
|
+
console.log('[grpcDriftClientAccountSubscriberV2] subscribeToSpotMarketAccounts');
|
|
314
|
+
}
|
|
152
315
|
const spotMarketIndexToAccountPubkeys = await Promise.all(this.spotMarketIndexes.map(async (marketIndex) => [
|
|
153
316
|
marketIndex,
|
|
154
317
|
await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
@@ -180,64 +343,102 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
180
343
|
return true;
|
|
181
344
|
}
|
|
182
345
|
async subscribeToOracles() {
|
|
183
|
-
|
|
184
|
-
|
|
346
|
+
var _a;
|
|
347
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
348
|
+
console.log('grpcDriftClientAccountSubscriberV2 subscribeToOracles');
|
|
349
|
+
}
|
|
350
|
+
const oraclePubkeyToInfosMap = new Map();
|
|
185
351
|
for (const info of this.oracleInfos) {
|
|
186
|
-
const
|
|
187
|
-
if (!
|
|
188
|
-
|
|
189
|
-
uniqueOraclePubkeys.set(id, info);
|
|
352
|
+
const pubkey = info.publicKey.toBase58();
|
|
353
|
+
if (!oraclePubkeyToInfosMap.has(pubkey)) {
|
|
354
|
+
oraclePubkeyToInfosMap.set(pubkey, []);
|
|
190
355
|
}
|
|
356
|
+
oraclePubkeyToInfosMap.get(pubkey).push(info);
|
|
191
357
|
}
|
|
192
|
-
const oraclePubkeys = Array.from(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}, this.resubOpts, undefined, async () => {
|
|
206
|
-
var _a;
|
|
207
|
-
try {
|
|
208
|
-
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
209
|
-
console.log('[grpcDriftClientAccountSubscriberV2] oracle subscriber unsubscribed; resubscribing');
|
|
210
|
-
}
|
|
211
|
-
await this.subscribeToOracles();
|
|
212
|
-
}
|
|
213
|
-
catch (e) {
|
|
214
|
-
console.error('Oracle resubscribe failed:', e);
|
|
358
|
+
const oraclePubkeys = Array.from(new Set(this.oracleInfos.map((info) => info.publicKey)));
|
|
359
|
+
this.oracleMultiSubscriber = await grpcMultiAccountSubscriber_1.grpcMultiAccountSubscriber.create(this.grpcConfigs, 'oracle', this.program, (buffer, pubkey, accountProps) => {
|
|
360
|
+
if (!pubkey) {
|
|
361
|
+
throw new Error('Oracle pubkey missing in decode');
|
|
362
|
+
}
|
|
363
|
+
const client = this.oracleClientCache.get(accountProps.source, this.program.provider.connection, this.program);
|
|
364
|
+
const price = client.getOraclePriceDataFromBuffer(buffer);
|
|
365
|
+
return price;
|
|
366
|
+
}, this.resubOpts, undefined, async () => {
|
|
367
|
+
var _a;
|
|
368
|
+
try {
|
|
369
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
370
|
+
console.log('[grpcDriftClientAccountSubscriberV2] oracle subscriber unsubscribed; resubscribing');
|
|
215
371
|
}
|
|
216
|
-
|
|
372
|
+
await this.subscribeToOracles();
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
console.error('Oracle resubscribe failed:', e);
|
|
376
|
+
}
|
|
377
|
+
}, oraclePubkeyToInfosMap);
|
|
217
378
|
for (const data of this.initialOraclePriceData.entries()) {
|
|
218
379
|
const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
|
|
219
380
|
this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
|
|
381
|
+
this.oracleIdToOracleDataMap.set(data[0], {
|
|
382
|
+
data: data[1],
|
|
383
|
+
slot: 0,
|
|
384
|
+
});
|
|
220
385
|
}
|
|
221
|
-
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
|
|
222
|
-
const
|
|
223
|
-
this.
|
|
386
|
+
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data, context, _b, accountProps) => {
|
|
387
|
+
const oracleId = (0, oracleId_1.getOracleId)(accountId, accountProps.source);
|
|
388
|
+
this.oracleIdToOracleDataMap.set(oracleId, {
|
|
389
|
+
data,
|
|
390
|
+
slot: context.slot,
|
|
391
|
+
});
|
|
392
|
+
this.eventEmitter.emit('oraclePriceUpdate', accountId, accountProps.source, data);
|
|
224
393
|
this.eventEmitter.emit('update');
|
|
225
394
|
});
|
|
226
395
|
return true;
|
|
227
396
|
}
|
|
397
|
+
async handleDelistedMarkets() {
|
|
398
|
+
var _a, _c;
|
|
399
|
+
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Subscribe) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const { perpMarketIndexes, oracles } = (0, utils_1.findDelistedPerpMarketsAndOracles)(Array.from(((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.getAccountDataMap().values()) || []), Array.from(((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.getAccountDataMap().values()) || []));
|
|
403
|
+
// Build array of perp market pubkeys to remove
|
|
404
|
+
const perpMarketPubkeysToRemove = perpMarketIndexes
|
|
405
|
+
.map((marketIndex) => {
|
|
406
|
+
const pubkeyString = this.perpMarketIndexToAccountPubkeyMap.get(marketIndex);
|
|
407
|
+
return pubkeyString ? new web3_js_1.PublicKey(pubkeyString) : null;
|
|
408
|
+
})
|
|
409
|
+
.filter((pubkey) => pubkey !== null);
|
|
410
|
+
// Build array of oracle pubkeys to remove
|
|
411
|
+
const oraclePubkeysToRemove = oracles.map((oracle) => oracle.publicKey);
|
|
412
|
+
// Remove accounts in batches - perp markets
|
|
413
|
+
if (perpMarketPubkeysToRemove.length > 0) {
|
|
414
|
+
await this.perpMarketsSubscriber.removeAccounts(perpMarketPubkeysToRemove);
|
|
415
|
+
}
|
|
416
|
+
// Remove accounts in batches - oracles
|
|
417
|
+
if (oraclePubkeysToRemove.length > 0) {
|
|
418
|
+
await this.oracleMultiSubscriber.removeAccounts(oraclePubkeysToRemove);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
removeInitialData() {
|
|
422
|
+
this.initialPerpMarketAccountData = new Map();
|
|
423
|
+
this.initialSpotMarketAccountData = new Map();
|
|
424
|
+
this.initialOraclePriceData = new Map();
|
|
425
|
+
}
|
|
228
426
|
async unsubscribeFromOracles() {
|
|
229
427
|
if (this.oracleMultiSubscriber) {
|
|
230
428
|
await this.oracleMultiSubscriber.unsubscribe();
|
|
231
429
|
this.oracleMultiSubscriber = undefined;
|
|
232
430
|
return;
|
|
233
431
|
}
|
|
234
|
-
await super.unsubscribeFromOracles();
|
|
235
432
|
}
|
|
236
433
|
async unsubscribe() {
|
|
434
|
+
var _a, _c;
|
|
237
435
|
if (this.isSubscribed) {
|
|
238
436
|
return;
|
|
239
437
|
}
|
|
240
438
|
await this.stateAccountSubscriber.unsubscribe();
|
|
439
|
+
await this.unsubscribeFromOracles();
|
|
440
|
+
await ((_a = this.perpMarketsSubscriber) === null || _a === void 0 ? void 0 : _a.unsubscribe());
|
|
441
|
+
await ((_c = this.spotMarketsSubscriber) === null || _c === void 0 ? void 0 : _c.unsubscribe());
|
|
241
442
|
}
|
|
242
443
|
}
|
|
243
444
|
exports.grpcDriftClientAccountSubscriberV2 = grpcDriftClientAccountSubscriberV2;
|
|
@@ -4,7 +4,7 @@ import { Program } from '@coral-xyz/anchor';
|
|
|
4
4
|
import { Context, PublicKey } from '@solana/web3.js';
|
|
5
5
|
import { Client } from '../isomorphic/grpc';
|
|
6
6
|
import { DataAndSlot, GrpcConfigs, ResubOpts } from './types';
|
|
7
|
-
export declare class grpcMultiAccountSubscriber<T> {
|
|
7
|
+
export declare class grpcMultiAccountSubscriber<T, U = undefined> {
|
|
8
8
|
private client;
|
|
9
9
|
private stream;
|
|
10
10
|
private commitmentLevel;
|
|
@@ -20,12 +20,15 @@ export declare class grpcMultiAccountSubscriber<T> {
|
|
|
20
20
|
private subscribedAccounts;
|
|
21
21
|
private onChangeMap;
|
|
22
22
|
private dataMap;
|
|
23
|
+
private accountPropsMap;
|
|
24
|
+
private bufferMap;
|
|
23
25
|
private constructor();
|
|
24
|
-
static create<U>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string) =>
|
|
26
|
+
static create<T, U = undefined>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string, accountProps?: U) => T, resubOpts?: ResubOpts, clientProp?: Client, onUnsubscribe?: () => Promise<void>, accountPropsMap?: Map<string, U | Array<U>>): Promise<grpcMultiAccountSubscriber<T, U>>;
|
|
25
27
|
setAccountData(accountPubkey: string, data: T, slot?: number): void;
|
|
26
28
|
getAccountData(accountPubkey: string): DataAndSlot<T> | undefined;
|
|
27
29
|
getAccountDataMap(): Map<string, DataAndSlot<T>>;
|
|
28
|
-
|
|
30
|
+
fetch(): Promise<void>;
|
|
31
|
+
subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer, accountProps: U) => void): Promise<void>;
|
|
29
32
|
addAccounts(accounts: PublicKey[]): Promise<void>;
|
|
30
33
|
removeAccounts(accounts: PublicKey[]): Promise<void>;
|
|
31
34
|
unsubscribe(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpcMultiAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcMultiAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"grpcMultiAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcMultiAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAc,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjE,OAAO,EACN,MAAM,EAMN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAiB,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAyB7E,qBAAa,0BAA0B,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS;IACvD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAwD;IACtE,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAC,CAIhB;IACP,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAC,CAAsB;IAErC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,UAAS;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAgC;IAClD,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,WAAW,CAGf;IAEJ,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,eAAe,CAAmC;IAC1D,OAAO,CAAC,SAAS,CAAoC;IAErD,OAAO;WAoBa,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,EAC1C,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,KAAK,CAAC,EACvE,SAAS,CAAC,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EACnC,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,GACzC,OAAO,CAAC,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAwB5C,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAInE,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS;IAIjE,iBAAiB,IAAI,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAI1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAoEtB,SAAS,CACd,QAAQ,EAAE,SAAS,EAAE,EACrB,QAAQ,EAAE,CACT,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,CAAC,KACX,IAAI,GACP,OAAO,CAAC,IAAI,CAAC;IAsIV,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiCjD,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCpD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA4ClC,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,UAAU;CAIlB"}
|
|
@@ -31,13 +31,27 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
31
31
|
const Buffer = __importStar(require("buffer"));
|
|
32
32
|
const bs58_1 = __importDefault(require("bs58"));
|
|
33
33
|
const grpc_1 = require("../isomorphic/grpc");
|
|
34
|
+
function commitmentLevelToCommitment(commitmentLevel) {
|
|
35
|
+
switch (commitmentLevel) {
|
|
36
|
+
case grpc_1.CommitmentLevel.PROCESSED:
|
|
37
|
+
return 'processed';
|
|
38
|
+
case grpc_1.CommitmentLevel.CONFIRMED:
|
|
39
|
+
return 'confirmed';
|
|
40
|
+
case grpc_1.CommitmentLevel.FINALIZED:
|
|
41
|
+
return 'finalized';
|
|
42
|
+
default:
|
|
43
|
+
return 'confirmed';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
34
46
|
class grpcMultiAccountSubscriber {
|
|
35
|
-
constructor(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe) {
|
|
47
|
+
constructor(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe, accountPropsMap) {
|
|
36
48
|
this.isUnsubscribing = false;
|
|
37
49
|
this.receivingData = false;
|
|
38
50
|
this.subscribedAccounts = new Set();
|
|
39
51
|
this.onChangeMap = new Map();
|
|
40
52
|
this.dataMap = new Map();
|
|
53
|
+
this.accountPropsMap = new Map();
|
|
54
|
+
this.bufferMap = new Map();
|
|
41
55
|
this.client = client;
|
|
42
56
|
this.commitmentLevel = commitmentLevel;
|
|
43
57
|
this.accountName = accountName;
|
|
@@ -45,8 +59,9 @@ class grpcMultiAccountSubscriber {
|
|
|
45
59
|
this.decodeBufferFn = decodeBuffer;
|
|
46
60
|
this.resubOpts = resubOpts;
|
|
47
61
|
this.onUnsubscribe = onUnsubscribe;
|
|
62
|
+
this.accountPropsMap = accountPropsMap;
|
|
48
63
|
}
|
|
49
|
-
static async create(grpcConfigs, accountName, program, decodeBuffer, resubOpts, clientProp, onUnsubscribe) {
|
|
64
|
+
static async create(grpcConfigs, accountName, program, decodeBuffer, resubOpts, clientProp, onUnsubscribe, accountPropsMap) {
|
|
50
65
|
var _a, _b;
|
|
51
66
|
const client = clientProp
|
|
52
67
|
? clientProp
|
|
@@ -54,7 +69,7 @@ class grpcMultiAccountSubscriber {
|
|
|
54
69
|
const commitmentLevel =
|
|
55
70
|
// @ts-ignore :: isomorphic exported enum fails typescript but will work at runtime
|
|
56
71
|
(_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : grpc_1.CommitmentLevel.CONFIRMED;
|
|
57
|
-
return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
|
|
72
|
+
return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe, accountPropsMap);
|
|
58
73
|
}
|
|
59
74
|
setAccountData(accountPubkey, data, slot) {
|
|
60
75
|
this.dataMap.set(accountPubkey, { data, slot });
|
|
@@ -65,7 +80,60 @@ class grpcMultiAccountSubscriber {
|
|
|
65
80
|
getAccountDataMap() {
|
|
66
81
|
return this.dataMap;
|
|
67
82
|
}
|
|
83
|
+
async fetch() {
|
|
84
|
+
var _a;
|
|
85
|
+
try {
|
|
86
|
+
// Chunk account IDs into groups of 100 (getMultipleAccounts limit)
|
|
87
|
+
const chunkSize = 100;
|
|
88
|
+
const chunks = [];
|
|
89
|
+
const accountIds = Array.from(this.subscribedAccounts.values());
|
|
90
|
+
for (let i = 0; i < accountIds.length; i += chunkSize) {
|
|
91
|
+
chunks.push(accountIds.slice(i, i + chunkSize));
|
|
92
|
+
}
|
|
93
|
+
// Process all chunks concurrently
|
|
94
|
+
await Promise.all(chunks.map(async (chunk) => {
|
|
95
|
+
const accountAddresses = chunk.map((accountId) => new web3_js_1.PublicKey(accountId));
|
|
96
|
+
const rpcResponseAndContext = await this.program.provider.connection.getMultipleAccountsInfoAndContext(accountAddresses, {
|
|
97
|
+
commitment: commitmentLevelToCommitment(this.commitmentLevel),
|
|
98
|
+
});
|
|
99
|
+
const rpcResponse = rpcResponseAndContext.value;
|
|
100
|
+
const currentSlot = rpcResponseAndContext.context.slot;
|
|
101
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
102
|
+
const accountId = chunk[i];
|
|
103
|
+
const accountInfo = rpcResponse[i];
|
|
104
|
+
if (accountInfo) {
|
|
105
|
+
const prev = this.bufferMap.get(accountId);
|
|
106
|
+
const newBuffer = accountInfo.data;
|
|
107
|
+
if (prev && currentSlot < prev.slot) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (prev &&
|
|
111
|
+
prev.buffer &&
|
|
112
|
+
newBuffer &&
|
|
113
|
+
newBuffer.equals(prev.buffer)) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
this.bufferMap.set(accountId, {
|
|
117
|
+
buffer: newBuffer,
|
|
118
|
+
slot: currentSlot,
|
|
119
|
+
});
|
|
120
|
+
const accountDecoded = this.program.coder.accounts.decode(this.capitalize(this.accountName), newBuffer);
|
|
121
|
+
this.setAccountData(accountId, accountDecoded, currentSlot);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
128
|
+
console.log(`[${this.accountName}] grpcMultiAccountSubscriber error fetching accounts:`, error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
68
132
|
async subscribe(accounts, onChange) {
|
|
133
|
+
var _a;
|
|
134
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
|
|
135
|
+
console.log(`[${this.accountName}] grpcMultiAccountSubscriber subscribe`);
|
|
136
|
+
}
|
|
69
137
|
if (this.listenerId != null || this.isUnsubscribing) {
|
|
70
138
|
return;
|
|
71
139
|
}
|
|
@@ -73,9 +141,9 @@ class grpcMultiAccountSubscriber {
|
|
|
73
141
|
for (const pk of accounts) {
|
|
74
142
|
const key = pk.toBase58();
|
|
75
143
|
this.subscribedAccounts.add(key);
|
|
76
|
-
this.onChangeMap.set(key, (data, ctx, buffer) => {
|
|
144
|
+
this.onChangeMap.set(key, (data, ctx, buffer, accountProps) => {
|
|
77
145
|
this.setAccountData(key, data, ctx.slot);
|
|
78
|
-
onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
|
|
146
|
+
onChange(new web3_js_1.PublicKey(key), data, ctx, buffer, accountProps);
|
|
79
147
|
});
|
|
80
148
|
}
|
|
81
149
|
this.stream =
|
|
@@ -98,7 +166,7 @@ class grpcMultiAccountSubscriber {
|
|
|
98
166
|
transactionsStatus: {},
|
|
99
167
|
};
|
|
100
168
|
this.stream.on('data', (chunk) => {
|
|
101
|
-
var _a;
|
|
169
|
+
var _a, _b;
|
|
102
170
|
if (!chunk.account) {
|
|
103
171
|
return;
|
|
104
172
|
}
|
|
@@ -108,6 +176,17 @@ class grpcMultiAccountSubscriber {
|
|
|
108
176
|
if (!accountPubkey || !this.subscribedAccounts.has(accountPubkey)) {
|
|
109
177
|
return;
|
|
110
178
|
}
|
|
179
|
+
// Touch resub timer on any incoming account update for subscribed keys
|
|
180
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
181
|
+
this.receivingData = true;
|
|
182
|
+
clearTimeout(this.timeoutId);
|
|
183
|
+
this.setTimeout();
|
|
184
|
+
}
|
|
185
|
+
// Skip processing if we already have data for this account at a newer slot
|
|
186
|
+
const existing = this.dataMap.get(accountPubkey);
|
|
187
|
+
if ((existing === null || existing === void 0 ? void 0 : existing.slot) !== undefined && existing.slot > slot) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
111
190
|
const accountInfo = {
|
|
112
191
|
owner: new web3_js_1.PublicKey(chunk.account.account.owner),
|
|
113
192
|
lamports: Number(chunk.account.account.lamports),
|
|
@@ -117,21 +196,36 @@ class grpcMultiAccountSubscriber {
|
|
|
117
196
|
};
|
|
118
197
|
const context = { slot };
|
|
119
198
|
const buffer = accountInfo.data;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
199
|
+
// Check existing buffer for this account and skip if unchanged or slot regressed
|
|
200
|
+
const prevBuffer = this.bufferMap.get(accountPubkey);
|
|
201
|
+
if (prevBuffer && slot < prevBuffer.slot) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (prevBuffer &&
|
|
205
|
+
prevBuffer.buffer &&
|
|
206
|
+
buffer &&
|
|
207
|
+
buffer.equals(prevBuffer.buffer)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this.bufferMap.set(accountPubkey, { buffer, slot });
|
|
211
|
+
const accountProps = (_b = this.accountPropsMap) === null || _b === void 0 ? void 0 : _b.get(accountPubkey);
|
|
212
|
+
const handleDataBuffer = (context, buffer, accountProps) => {
|
|
213
|
+
const data = this.decodeBufferFn
|
|
214
|
+
? this.decodeBufferFn(buffer, accountPubkey, accountProps)
|
|
215
|
+
: this.program.account[this.accountName].coder.accounts.decode(this.capitalize(this.accountName), buffer);
|
|
216
|
+
const handler = this.onChangeMap.get(accountPubkey);
|
|
217
|
+
if (handler) {
|
|
218
|
+
handler(data, context, buffer, accountProps);
|
|
130
219
|
}
|
|
131
|
-
|
|
132
|
-
|
|
220
|
+
};
|
|
221
|
+
if (Array.isArray(accountProps)) {
|
|
222
|
+
for (const props of accountProps) {
|
|
223
|
+
handleDataBuffer(context, buffer, props);
|
|
133
224
|
}
|
|
134
225
|
}
|
|
226
|
+
else {
|
|
227
|
+
handleDataBuffer(context, buffer, accountProps);
|
|
228
|
+
}
|
|
135
229
|
});
|
|
136
230
|
return new Promise((resolve, reject) => {
|
|
137
231
|
this.stream.write(request, (err) => {
|
|
@@ -140,7 +234,6 @@ class grpcMultiAccountSubscriber {
|
|
|
140
234
|
this.listenerId = 1;
|
|
141
235
|
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
142
236
|
this.receivingData = true;
|
|
143
|
-
this.setTimeout();
|
|
144
237
|
}
|
|
145
238
|
resolve();
|
|
146
239
|
}
|
|
@@ -53,6 +53,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
53
53
|
getUpdateAdminIx(admin: PublicKey): Promise<TransactionInstruction>;
|
|
54
54
|
updatePerpMarketCurveUpdateIntensity(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionSignature>;
|
|
55
55
|
getUpdatePerpMarketCurveUpdateIntensityIx(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionInstruction>;
|
|
56
|
+
updatePerpMarketReferencePriceOffsetDeadbandPct(perpMarketIndex: number, referencePriceOffsetDeadbandPct: number): Promise<TransactionSignature>;
|
|
57
|
+
getUpdatePerpMarketReferencePriceOffsetDeadbandPctIx(perpMarketIndex: number, referencePriceOffsetDeadbandPct: number): Promise<TransactionInstruction>;
|
|
56
58
|
updatePerpMarketTargetBaseAssetAmountPerLp(perpMarketIndex: number, targetBaseAssetAmountPerLP: number): Promise<TransactionSignature>;
|
|
57
59
|
updatePerpMarketAmmSummaryStats(perpMarketIndex: number, updateAmmSummaryStats?: boolean, quoteAssetAmountWithUnsettledLp?: BN, netUnsettledFundingPnl?: BN, excludeTotalLiqFee?: boolean): Promise<TransactionSignature>;
|
|
58
60
|
getUpdatePerpMarketAmmSummaryStatsIx(perpMarketIndex: number, updateAmmSummaryStats?: boolean, quoteAssetAmountWithUnsettledLp?: BN, netUnsettledFundingPnl?: BN, excludeTotalLiqFee?: boolean): Promise<TransactionInstruction>;
|
|
@@ -246,5 +248,7 @@ export declare class AdminClient extends DriftClient {
|
|
|
246
248
|
getUpdateFeatureBitFlagsBuilderCodesIx(enable: boolean): Promise<TransactionInstruction>;
|
|
247
249
|
updateFeatureBitFlagsBuilderReferral(enable: boolean): Promise<TransactionSignature>;
|
|
248
250
|
getUpdateFeatureBitFlagsBuilderReferralIx(enable: boolean): Promise<TransactionInstruction>;
|
|
251
|
+
adminDisableUpdatePerpBidAskTwap(authority: PublicKey, disable: boolean): Promise<TransactionSignature>;
|
|
252
|
+
getAdminDisableUpdatePerpBidAskTwapIx(authority: PublicKey, disable: boolean): Promise<TransactionInstruction>;
|
|
249
253
|
}
|
|
250
254
|
//# sourceMappingURL=adminClient.d.ts.map
|