From 5610b6fb126e7b3b181d6f18754e877709f54728 Mon Sep 17 00:00:00 2001 From: doomsower <12031673+doomsower@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:58:12 -0300 Subject: [PATCH] fix: skip empty requests --- src/services/RedstoneServiceV3.ts | 39 +++++++++++++------------------ 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/services/RedstoneServiceV3.ts b/src/services/RedstoneServiceV3.ts index fda294e..1e1a6e5 100644 --- a/src/services/RedstoneServiceV3.ts +++ b/src/services/RedstoneServiceV3.ts @@ -34,13 +34,6 @@ import type { PriceOnDemandExtras, PriceUpdate } from "./liquidate/index.js"; import type { RedstoneFeed } from "./OracleServiceV3.js"; import type OracleServiceV3 from "./OracleServiceV3.js"; -interface RedstoneRequest { - originalToken: Address; - tokenOrTicker: Address; - reserve: boolean; - dataFeedId: string; -} - interface TimestampedCalldata { callData: `0x${string}`; ts: number; @@ -59,12 +52,6 @@ export type RedstonePriceFeed = Extract< { type: PriceFeedType.REDSTONE_ORACLE } >; -const HISTORICAL_BLOCKLIST = new Set([ - // "rsETH_FUNDAMENTAL", - // "weETH_FUNDAMENTAL", - // "ezETH_FUNDAMENTAL", -]); - @DI.Injectable(DI.Redstone) export class RedstoneServiceV3 { @Logger("Redstone") @@ -327,6 +314,7 @@ export class RedstoneServiceV3 { const cacheAllowed = this.config.optimistic; const networkUpdates: RedstoneUpdate[] = []; + let networkResponses: PriceOnDemandExtras[] = []; const cachedResponses: PriceOnDemandExtras[] = []; for (const upd of updates) { @@ -339,16 +327,21 @@ export class RedstoneServiceV3 { } } - const networkResponses = await this.#fetchRedstonePayloadForManualUsage( - networkUpdates, - dataServiceId, - uniqueSignersCount, - ); - - if (cacheAllowed) { - for (const resp of networkResponses) { - const key = redstoneCacheKey(resp, dataServiceId, uniqueSignersCount); - this.#optimisticCache.set(key, resp); + if (networkUpdates.length) { + logger.debug( + `fetching ${networkUpdates.length} redstone updates: ${printFeeds(networkUpdates)}`, + ); + networkResponses = await this.#fetchRedstonePayloadForManualUsage( + networkUpdates, + dataServiceId, + uniqueSignersCount, + ); + if (cacheAllowed) { + for (const resp of networkResponses) { + const key = redstoneCacheKey(resp, dataServiceId, uniqueSignersCount); + this.#optimisticCache.set(key, resp); + logger.debug(`cached response for ${key}`); + } } }