Skip to content

fix(prices): Batch Alchemy token price requests to avoid 429 - #2536

Open
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/batch-alchemy-prices
Open

sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/batch-alchemy-prices

Conversation

@sentry

@sentry sentry Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the AxiosError: Request failed with status code 429 issue observed on iOS, which was caused by exceeding Alchemy's 10,000 token_price requests/hour rate limit.

Root Cause:
The hooks/useBalances.ts file was making N parallel GET /by-symbol requests to Alchemy for N token symbols via Promise.allSettled(symbolsToFetch.map(s => fetchTokenPriceUsd(s))). Each fetchTokenPriceUsd call in lib/api.ts made a single HTTP request, leading to a fan-out that quickly exhausted the rate limit.

Solution:

  1. lib/api.ts: Introduced a new exported function fetchTokenPricesUsdBatch(symbols: string[]). This function accepts an array of token symbols and makes a single GET /by-symbol request to Alchemy, utilizing the endpoint's ability to handle multiple symbols via repeated ?symbols= query parameters. It returns a Record<string, number> mapping symbols to their USD prices, gracefully handling unpriced or failed requests.
  2. hooks/useBalances.ts: Modified the useBalances hook to replace the Promise.allSettled fan-out with a single call to fetchTokenPricesUsdBatch(symbolsToFetch). The import for fetchTokenPriceUsd was removed from this file as it's no longer directly used here.
  3. lib/__tests__/alchemyTokenPrices.test.ts: Added comprehensive unit tests for fetchTokenPricesUsdBatch to ensure correct batching, parsing of responses, and error handling.

The existing fetchTokenPriceUsd function remains unchanged to support its other callers (e.g., useEstimateGas.ts, useNativePriceUsd.ts, useToken.tsx).

Fixes SOLID-ZZ

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@vercel

vercel Bot commented Sep 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
solid-app Ignored Ignored Preview Sep 20, 2026 10:42am UTC
solid-app-staging Ignored Ignored Preview Sep 20, 2026 10:42am UTC

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants