Skip to content

Commit 55d740f

Browse files
committed
feat: grpc v2 delisted markets handling better optimized
1 parent 758dab4 commit 55d740f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

sdk/src/accounts/grpcDriftClientAccountSubscriberV2.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -691,19 +691,25 @@ export class grpcDriftClientAccountSubscriberV2
691691
Array.from(this.spotMarketsSubscriber?.getAccountDataMap().values() || [])
692692
);
693693

694-
for (const perpMarketIndex of perpMarketIndexes) {
695-
await this.perpMarketsSubscriber.removeAccounts([
696-
new PublicKey(
697-
this.perpMarketIndexToAccountPubkeyMap.get(perpMarketIndex) || ''
698-
),
699-
]);
700-
if (this.delistedMarketSetting === DelistedMarketSetting.Discard) {
701-
this.perpMarketIndexToAccountPubkeyMap.delete(perpMarketIndex);
702-
}
694+
// Build array of perp market pubkeys to remove
695+
const perpMarketPubkeysToRemove = perpMarketIndexes
696+
.map((marketIndex) => {
697+
const pubkeyString = this.perpMarketIndexToAccountPubkeyMap.get(marketIndex);
698+
return pubkeyString ? new PublicKey(pubkeyString) : null;
699+
})
700+
.filter((pubkey) => pubkey !== null) as PublicKey[];
701+
702+
// Build array of oracle pubkeys to remove
703+
const oraclePubkeysToRemove = oracles.map((oracle) => oracle.publicKey);
704+
705+
// Remove accounts in batches - perp markets
706+
if (perpMarketPubkeysToRemove.length > 0) {
707+
await this.perpMarketsSubscriber.removeAccounts(perpMarketPubkeysToRemove);
703708
}
704709

705-
for (const oracle of oracles) {
706-
await this.oracleMultiSubscriber.removeAccounts([oracle.publicKey]);
710+
// Remove accounts in batches - oracles
711+
if (oraclePubkeysToRemove.length > 0) {
712+
await this.oracleMultiSubscriber.removeAccounts(oraclePubkeysToRemove);
707713
}
708714
}
709715

0 commit comments

Comments
 (0)