@drift-labs/sdk 2.142.0-beta.7 → 2.142.0-beta.9
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.js +5 -5
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/grpcMultiAccountSubscriber.js +6 -3
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +5 -5
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.js +6 -3
- package/package.json +1 -1
- package/scripts/client-test.ts +21 -12
- package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +11 -5
- package/src/accounts/grpcMultiAccountSubscriber.ts +6 -5
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.142.0-beta.
|
|
1
|
+
2.142.0-beta.9
|
|
@@ -123,7 +123,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
123
123
|
await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex),
|
|
124
124
|
]));
|
|
125
125
|
for (const [marketIndex, accountPubkey,] of perpMarketIndexToAccountPubkeys) {
|
|
126
|
-
this.perpMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey);
|
|
126
|
+
this.perpMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey.toBase58());
|
|
127
127
|
}
|
|
128
128
|
const perpMarketPubkeys = perpMarketIndexToAccountPubkeys.map(([_, accountPubkey]) => accountPubkey);
|
|
129
129
|
this.perpMarketsSubscriber =
|
|
@@ -140,7 +140,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
142
|
for (const data of this.initialPerpMarketAccountData.values()) {
|
|
143
|
-
this.perpMarketsSubscriber.setAccountData(data.pubkey, data);
|
|
143
|
+
this.perpMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
|
|
144
144
|
}
|
|
145
145
|
await this.perpMarketsSubscriber.subscribe(perpMarketPubkeys, (_accountId, data) => {
|
|
146
146
|
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
@@ -154,7 +154,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
154
154
|
await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
155
155
|
]));
|
|
156
156
|
for (const [marketIndex, accountPubkey,] of spotMarketIndexToAccountPubkeys) {
|
|
157
|
-
this.spotMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey);
|
|
157
|
+
this.spotMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey.toBase58());
|
|
158
158
|
}
|
|
159
159
|
const spotMarketPubkeys = spotMarketIndexToAccountPubkeys.map(([_, accountPubkey]) => accountPubkey);
|
|
160
160
|
this.spotMarketsSubscriber =
|
|
@@ -171,7 +171,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
for (const data of this.initialSpotMarketAccountData.values()) {
|
|
174
|
-
this.spotMarketsSubscriber.setAccountData(data.pubkey, data);
|
|
174
|
+
this.spotMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
|
|
175
175
|
}
|
|
176
176
|
await this.spotMarketsSubscriber.subscribe(spotMarketPubkeys, (_accountId, data) => {
|
|
177
177
|
this.eventEmitter.emit('spotMarketAccountUpdate', data);
|
|
@@ -216,7 +216,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
216
216
|
});
|
|
217
217
|
for (const data of this.initialOraclePriceData.entries()) {
|
|
218
218
|
const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
|
|
219
|
-
this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
|
|
219
|
+
this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
|
|
220
220
|
}
|
|
221
221
|
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
|
|
222
222
|
const source = pubkeyToSource.get(accountId.toBase58());
|
|
@@ -22,8 +22,8 @@ export declare class grpcMultiAccountSubscriber<T> {
|
|
|
22
22
|
private dataMap;
|
|
23
23
|
private constructor();
|
|
24
24
|
static create<U>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string) => U, resubOpts?: ResubOpts, clientProp?: Client, onUnsubscribe?: () => Promise<void>): Promise<grpcMultiAccountSubscriber<U>>;
|
|
25
|
-
setAccountData(accountPubkey:
|
|
26
|
-
getAccountData(accountPubkey:
|
|
25
|
+
setAccountData(accountPubkey: string, data: T, slot?: number): void;
|
|
26
|
+
getAccountData(accountPubkey: string): DataAndSlot<T> | undefined;
|
|
27
27
|
getAccountDataMap(): Map<string, DataAndSlot<T>>;
|
|
28
28
|
subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
|
|
29
29
|
addAccounts(accounts: PublicKey[]): Promise<void>;
|
|
@@ -57,10 +57,10 @@ class grpcMultiAccountSubscriber {
|
|
|
57
57
|
return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
|
|
58
58
|
}
|
|
59
59
|
setAccountData(accountPubkey, data, slot) {
|
|
60
|
-
this.dataMap.set(accountPubkey
|
|
60
|
+
this.dataMap.set(accountPubkey, { data, slot });
|
|
61
61
|
}
|
|
62
62
|
getAccountData(accountPubkey) {
|
|
63
|
-
return this.dataMap.get(accountPubkey
|
|
63
|
+
return this.dataMap.get(accountPubkey);
|
|
64
64
|
}
|
|
65
65
|
getAccountDataMap() {
|
|
66
66
|
return this.dataMap;
|
|
@@ -73,7 +73,10 @@ class grpcMultiAccountSubscriber {
|
|
|
73
73
|
for (const pk of accounts) {
|
|
74
74
|
const key = pk.toBase58();
|
|
75
75
|
this.subscribedAccounts.add(key);
|
|
76
|
-
this.onChangeMap.set(key, (data, ctx, buffer) =>
|
|
76
|
+
this.onChangeMap.set(key, (data, ctx, buffer) => {
|
|
77
|
+
this.setAccountData(key, data, ctx.slot);
|
|
78
|
+
onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
|
|
79
|
+
});
|
|
77
80
|
}
|
|
78
81
|
this.stream =
|
|
79
82
|
(await this.client.subscribe());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpcDriftClientAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcDriftClientAccountSubscriberV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQ5C,OAAO,EACN,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAgB,MAAM,UAAU,CAAC;AAM9E,qBAAa,kCAAmC,SAAQ,qCAAqC;IAC5F,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAAqB,CAAC,CAA8C;IAC5E,OAAO,CAAC,iCAAiC,
|
|
1
|
+
{"version":3,"file":"grpcDriftClientAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcDriftClientAccountSubscriberV2.ts"],"names":[],"mappings":"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AC;IAS9B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAO3C"}
|
|
@@ -123,7 +123,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
123
123
|
await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex),
|
|
124
124
|
]));
|
|
125
125
|
for (const [marketIndex, accountPubkey,] of perpMarketIndexToAccountPubkeys) {
|
|
126
|
-
this.perpMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey);
|
|
126
|
+
this.perpMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey.toBase58());
|
|
127
127
|
}
|
|
128
128
|
const perpMarketPubkeys = perpMarketIndexToAccountPubkeys.map(([_, accountPubkey]) => accountPubkey);
|
|
129
129
|
this.perpMarketsSubscriber =
|
|
@@ -140,7 +140,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
142
|
for (const data of this.initialPerpMarketAccountData.values()) {
|
|
143
|
-
this.perpMarketsSubscriber.setAccountData(data.pubkey, data);
|
|
143
|
+
this.perpMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
|
|
144
144
|
}
|
|
145
145
|
await this.perpMarketsSubscriber.subscribe(perpMarketPubkeys, (_accountId, data) => {
|
|
146
146
|
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
@@ -154,7 +154,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
154
154
|
await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
155
155
|
]));
|
|
156
156
|
for (const [marketIndex, accountPubkey,] of spotMarketIndexToAccountPubkeys) {
|
|
157
|
-
this.spotMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey);
|
|
157
|
+
this.spotMarketIndexToAccountPubkeyMap.set(marketIndex, accountPubkey.toBase58());
|
|
158
158
|
}
|
|
159
159
|
const spotMarketPubkeys = spotMarketIndexToAccountPubkeys.map(([_, accountPubkey]) => accountPubkey);
|
|
160
160
|
this.spotMarketsSubscriber =
|
|
@@ -171,7 +171,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
for (const data of this.initialSpotMarketAccountData.values()) {
|
|
174
|
-
this.spotMarketsSubscriber.setAccountData(data.pubkey, data);
|
|
174
|
+
this.spotMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
|
|
175
175
|
}
|
|
176
176
|
await this.spotMarketsSubscriber.subscribe(spotMarketPubkeys, (_accountId, data) => {
|
|
177
177
|
this.eventEmitter.emit('spotMarketAccountUpdate', data);
|
|
@@ -216,7 +216,7 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
216
216
|
});
|
|
217
217
|
for (const data of this.initialOraclePriceData.entries()) {
|
|
218
218
|
const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
|
|
219
|
-
this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
|
|
219
|
+
this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
|
|
220
220
|
}
|
|
221
221
|
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
|
|
222
222
|
const source = pubkeyToSource.get(accountId.toBase58());
|
|
@@ -22,8 +22,8 @@ export declare class grpcMultiAccountSubscriber<T> {
|
|
|
22
22
|
private dataMap;
|
|
23
23
|
private constructor();
|
|
24
24
|
static create<U>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string) => U, resubOpts?: ResubOpts, clientProp?: Client, onUnsubscribe?: () => Promise<void>): Promise<grpcMultiAccountSubscriber<U>>;
|
|
25
|
-
setAccountData(accountPubkey:
|
|
26
|
-
getAccountData(accountPubkey:
|
|
25
|
+
setAccountData(accountPubkey: string, data: T, slot?: number): void;
|
|
26
|
+
getAccountData(accountPubkey: string): DataAndSlot<T> | undefined;
|
|
27
27
|
getAccountDataMap(): Map<string, DataAndSlot<T>>;
|
|
28
28
|
subscribe(accounts: PublicKey[], onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
|
|
29
29
|
addAccounts(accounts: PublicKey[]): 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,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIrD,OAAO,EACN,MAAM,EAMN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAU9D,qBAAa,0BAA0B,CAAC,CAAC;IACxC,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,CAAyC;IAChE,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;IAEpD,OAAO;WAkBa,MAAM,CAAC,CAAC,EAC3B,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,Y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AE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,EACrD,SAAS,CAAC,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACjC,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC;IAuBzC,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,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,KACV,IAAI,GACP,OAAO,CAAC,IAAI,CAAC;IAgGV,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"}
|
|
@@ -57,10 +57,10 @@ class grpcMultiAccountSubscriber {
|
|
|
57
57
|
return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
|
|
58
58
|
}
|
|
59
59
|
setAccountData(accountPubkey, data, slot) {
|
|
60
|
-
this.dataMap.set(accountPubkey
|
|
60
|
+
this.dataMap.set(accountPubkey, { data, slot });
|
|
61
61
|
}
|
|
62
62
|
getAccountData(accountPubkey) {
|
|
63
|
-
return this.dataMap.get(accountPubkey
|
|
63
|
+
return this.dataMap.get(accountPubkey);
|
|
64
64
|
}
|
|
65
65
|
getAccountDataMap() {
|
|
66
66
|
return this.dataMap;
|
|
@@ -73,7 +73,10 @@ class grpcMultiAccountSubscriber {
|
|
|
73
73
|
for (const pk of accounts) {
|
|
74
74
|
const key = pk.toBase58();
|
|
75
75
|
this.subscribedAccounts.add(key);
|
|
76
|
-
this.onChangeMap.set(key, (data, ctx, buffer) =>
|
|
76
|
+
this.onChangeMap.set(key, (data, ctx, buffer) => {
|
|
77
|
+
this.setAccountData(key, data, ctx.slot);
|
|
78
|
+
onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
|
|
79
|
+
});
|
|
77
80
|
}
|
|
78
81
|
this.stream =
|
|
79
82
|
(await this.client.subscribe());
|
package/package.json
CHANGED
package/scripts/client-test.ts
CHANGED
|
@@ -96,20 +96,29 @@ async function initializeGrpcDriftClientV2() {
|
|
|
96
96
|
driftClient.accountSubscriber.eventEmitter.on(
|
|
97
97
|
'perpMarketAccountUpdate',
|
|
98
98
|
(data) => {
|
|
99
|
-
console.log('Perp market account update:', decodeName(data.name));
|
|
100
|
-
const perpMarketData = driftClient.getPerpMarketAccount(
|
|
101
|
-
data.marketIndex
|
|
102
|
-
);
|
|
103
99
|
console.log(
|
|
104
|
-
'Perp market
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const mmOracle = driftClient.getMMOracleDataForPerpMarket(
|
|
109
|
-
data.marketIndex
|
|
100
|
+
'Perp market account update:',
|
|
101
|
+
decodeName(data.name),
|
|
102
|
+
'mmOracleSequenceId:',
|
|
103
|
+
data.amm.mmOracleSequenceId.toString()
|
|
110
104
|
);
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
// const perpMarketData = driftClient.getPerpMarketAccount(
|
|
106
|
+
// data.marketIndex
|
|
107
|
+
// );
|
|
108
|
+
// console.log(
|
|
109
|
+
// 'Perp market data market index:',
|
|
110
|
+
// perpMarketData?.marketIndex
|
|
111
|
+
// );
|
|
112
|
+
// const oracle = driftClient.getOracleDataForPerpMarket(data.marketIndex);
|
|
113
|
+
// const mmOracle = driftClient.getMMOracleDataForPerpMarket(
|
|
114
|
+
// data.marketIndex
|
|
115
|
+
// );
|
|
116
|
+
// console.log('Perp oracle price:', oracle.price.toString());
|
|
117
|
+
// console.log('Perp MM oracle price:', mmOracle.price.toString());
|
|
118
|
+
// console.log(
|
|
119
|
+
// 'Perp MM oracle sequence id:',
|
|
120
|
+
// perpMarketData?.amm?.mmOracleSequenceId?.toString()
|
|
121
|
+
// );
|
|
113
122
|
perpMarketUpdateCount++;
|
|
114
123
|
if (
|
|
115
124
|
perpMarketUpdateCount >= 10 &&
|
|
@@ -213,7 +213,10 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
213
213
|
marketIndex,
|
|
214
214
|
accountPubkey,
|
|
215
215
|
] of perpMarketIndexToAccountPubkeys) {
|
|
216
|
-
this.perpMarketIndexToAccountPubkeyMap.set(
|
|
216
|
+
this.perpMarketIndexToAccountPubkeyMap.set(
|
|
217
|
+
marketIndex,
|
|
218
|
+
accountPubkey.toBase58()
|
|
219
|
+
);
|
|
217
220
|
}
|
|
218
221
|
|
|
219
222
|
const perpMarketPubkeys = perpMarketIndexToAccountPubkeys.map(
|
|
@@ -243,7 +246,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
243
246
|
);
|
|
244
247
|
|
|
245
248
|
for (const data of this.initialPerpMarketAccountData.values()) {
|
|
246
|
-
this.perpMarketsSubscriber.setAccountData(data.pubkey, data);
|
|
249
|
+
this.perpMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
|
|
247
250
|
}
|
|
248
251
|
|
|
249
252
|
await this.perpMarketsSubscriber.subscribe(
|
|
@@ -272,7 +275,10 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
272
275
|
marketIndex,
|
|
273
276
|
accountPubkey,
|
|
274
277
|
] of spotMarketIndexToAccountPubkeys) {
|
|
275
|
-
this.spotMarketIndexToAccountPubkeyMap.set(
|
|
278
|
+
this.spotMarketIndexToAccountPubkeyMap.set(
|
|
279
|
+
marketIndex,
|
|
280
|
+
accountPubkey.toBase58()
|
|
281
|
+
);
|
|
276
282
|
}
|
|
277
283
|
|
|
278
284
|
const spotMarketPubkeys = spotMarketIndexToAccountPubkeys.map(
|
|
@@ -302,7 +308,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
302
308
|
);
|
|
303
309
|
|
|
304
310
|
for (const data of this.initialSpotMarketAccountData.values()) {
|
|
305
|
-
this.spotMarketsSubscriber.setAccountData(data.pubkey, data);
|
|
311
|
+
this.spotMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
|
|
306
312
|
}
|
|
307
313
|
|
|
308
314
|
await this.spotMarketsSubscriber.subscribe(
|
|
@@ -377,7 +383,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
377
383
|
|
|
378
384
|
for (const data of this.initialOraclePriceData.entries()) {
|
|
379
385
|
const { publicKey } = getPublicKeyAndSourceFromOracleId(data[0]);
|
|
380
|
-
this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
|
|
386
|
+
this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
|
|
381
387
|
}
|
|
382
388
|
|
|
383
389
|
await this.oracleMultiSubscriber.subscribe(
|
|
@@ -93,8 +93,8 @@ export class grpcMultiAccountSubscriber<T> {
|
|
|
93
93
|
);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
setAccountData(accountPubkey:
|
|
97
|
-
this.dataMap.set(accountPubkey
|
|
96
|
+
setAccountData(accountPubkey: string, data: T, slot?: number): void {
|
|
97
|
+
this.dataMap.set(accountPubkey, { data, slot });
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
getAccountData(accountPubkey: string): DataAndSlot<T> | undefined {
|
|
@@ -122,9 +122,10 @@ export class grpcMultiAccountSubscriber<T> {
|
|
|
122
122
|
for (const pk of accounts) {
|
|
123
123
|
const key = pk.toBase58();
|
|
124
124
|
this.subscribedAccounts.add(key);
|
|
125
|
-
this.onChangeMap.set(key, (data, ctx, buffer) =>
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
this.onChangeMap.set(key, (data, ctx, buffer) => {
|
|
126
|
+
this.setAccountData(key, data, ctx.slot);
|
|
127
|
+
onChange(new PublicKey(key), data, ctx, buffer);
|
|
128
|
+
});
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
this.stream =
|