Skip to content

Commit b9be163

Browse files
authored
fix: grpc sub v2/multi not updating data map (#1940)
1 parent 2353b60 commit b9be163

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

sdk/scripts/client-test.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,29 @@ async function initializeGrpcDriftClientV2() {
9696
driftClient.accountSubscriber.eventEmitter.on(
9797
'perpMarketAccountUpdate',
9898
(data) => {
99-
console.log('Perp market account update:', decodeName(data.name));
100-
const perpMarketData = driftClient.getPerpMarketAccount(
101-
data.marketIndex
102-
);
10399
console.log(
104-
'Perp market data market index:',
105-
perpMarketData?.marketIndex
106-
);
107-
const oracle = driftClient.getOracleDataForPerpMarket(data.marketIndex);
108-
const mmOracle = driftClient.getMMOracleDataForPerpMarket(
109-
data.marketIndex
100+
'Perp market account update:',
101+
decodeName(data.name),
102+
'mmOracleSequenceId:',
103+
data.amm.mmOracleSequenceId.toString()
110104
);
111-
console.log('Perp oracle price:', oracle.price.toString());
112-
console.log('Perp MM oracle price:', mmOracle.price.toString());
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+
// );
113122
perpMarketUpdateCount++;
114123
if (
115124
perpMarketUpdateCount >= 10 &&

sdk/src/accounts/grpcDriftClientAccountSubscriberV2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
246246
);
247247

248248
for (const data of this.initialPerpMarketAccountData.values()) {
249-
this.perpMarketsSubscriber.setAccountData(data.pubkey, data);
249+
this.perpMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
250250
}
251251

252252
await this.perpMarketsSubscriber.subscribe(
@@ -308,7 +308,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
308308
);
309309

310310
for (const data of this.initialSpotMarketAccountData.values()) {
311-
this.spotMarketsSubscriber.setAccountData(data.pubkey, data);
311+
this.spotMarketsSubscriber.setAccountData(data.pubkey.toBase58(), data);
312312
}
313313

314314
await this.spotMarketsSubscriber.subscribe(
@@ -383,7 +383,7 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
383383

384384
for (const data of this.initialOraclePriceData.entries()) {
385385
const { publicKey } = getPublicKeyAndSourceFromOracleId(data[0]);
386-
this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
386+
this.oracleMultiSubscriber.setAccountData(publicKey.toBase58(), data[1]);
387387
}
388388

389389
await this.oracleMultiSubscriber.subscribe(

sdk/src/accounts/grpcMultiAccountSubscriber.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export class grpcMultiAccountSubscriber<T> {
9393
);
9494
}
9595

96-
setAccountData(accountPubkey: PublicKey, data: T, slot?: number): void {
97-
this.dataMap.set(accountPubkey.toBase58(), { data, slot });
96+
setAccountData(accountPubkey: string, data: T, slot?: number): void {
97+
this.dataMap.set(accountPubkey, { data, slot });
9898
}
9999

100100
getAccountData(accountPubkey: string): DataAndSlot<T> | undefined {
@@ -122,9 +122,10 @@ export class grpcMultiAccountSubscriber<T> {
122122
for (const pk of accounts) {
123123
const key = pk.toBase58();
124124
this.subscribedAccounts.add(key);
125-
this.onChangeMap.set(key, (data, ctx, buffer) =>
126-
onChange(new PublicKey(key), data, ctx, buffer)
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+
});
128129
}
129130

130131
this.stream =

0 commit comments

Comments
 (0)