improve(PriceClient): Gracefully fallback when price feed queries fail#1293
improve(PriceClient): Gracefully fallback when price feed queries fail#1293nicholaspai wants to merge 1 commit intomasterfrom
Conversation
- `acrossApi.ts`: Return undefined for a specific token price query if unavailable rather than throwing if any individual query fails - `priceClient.ts`: When falling back to the next `priceFeed`, only query token addresses that we don't have a price for. This allows the `priceFeed. getPricesByAddress()` to "partially resolve", like in the case when querying the Across API via the `acrossApi` adapter.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36fe897f4b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Only request prices for addresses that are not already in the price cache. | ||
| const _addrsToRequest = addrsToRequest.filter((address) => !priceCache[address.toLowerCase()]); |
There was a problem hiding this comment.
Request missed tokens instead of filtering them out
PriceClient#getPricesByAddress writes a placeholder entry into priceCache for every miss before it calls updatePrices(), so priceCache[address.toLowerCase()] is always truthy for every token that actually needs fetching. This new filter therefore turns _addrsToRequest into [] on every first lookup and every expired lookup, meaning no adapter is queried, updateCache() sees no expected tokens, and callers get the placeholder { price: 0, timestamp: 0 } back instead of a real price or an error. That makes cache misses fail silently for all consumers, not just the partial Across-API case this patch is targeting.
Useful? React with 👍 / 👎.
acrossApi.ts: Return undefined for a specific token price query if unavailable rather than throwing if any individual query failspriceClient.ts: When falling back to the nextpriceFeed, only query token addresses that we don't have a price for. This allows thepriceFeed. getPricesByAddress()to "partially resolve", like in the case when querying the Across API via theacrossApiadapter.