Skip to content

Harden fetchAndTestRpcs parsing against DefiLlama format changes and add RPC fallbacks#638

Draft
Copilot wants to merge 4 commits into
masterfrom
copilot/fix-fetch-and-test-rpcs-failure
Draft

Harden fetchAndTestRpcs parsing against DefiLlama format changes and add RPC fallbacks#638
Copilot wants to merge 4 commits into
masterfrom
copilot/fix-fetch-and-test-rpcs-failure

Conversation

Copy link
Copy Markdown

Copilot AI commented May 20, 2026

Fixes #637

fetchAndTestRpcs was failing due to brittle parsing of DefiLlama's extraRpcs.js source file, which could leave tested RPC sets empty. This update replaces the custom JS parser with a simple JSON fetch and guarantees fallback RPCs when any step fails.

What changed

  • src/hooks/rpcParsing.ts — replaced ~150-line balanced-segment JS parser with a fetchRpcsFromChainlist() function that fetches chainid.network/chains.json (a stable JSON endpoint), filters for required chains (1, 122, 42220, 50), and strips non-HTTP(S) URLs. No custom parsing, no eval(), no regex on JS source.
  • src/hooks/useWeb3.tsx — updated fetchAndTestRpcs to call fetchRpcsFromChainlist() directly, removed the CHAINLIST_URL constant and chainMapping object, and added rpcInitializationPromise = null in the catch block so the app can retry on failure without a page reload.
  • src/hooks/rpcParsing.test.ts — updated to test the new API: live fetch against chainid.network asserting all 4 chains return valid HTTP(S) URLs, plus a unit test for FALLBACK_RPCS_BY_CHAIN.

Test evidence

image

Full suite: 44 tests passing, 7 pre-existing failures unrelated to this PR (@sushiswap/sdk pnpm hoisting, @reown/appkit ESM — both present on master).

pnpm lint — clean.

pnpm build — fails with pre-existing @ethersproject/bignumber rollup resolution error (pnpm hoisting incompatibility, not introduced by this branch).

@github-project-automation github-project-automation Bot moved this to Prepare AI Task in GoodBounties May 20, 2026
Copilot AI linked an issue May 20, 2026 that may be closed by this pull request
2 tasks
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 20, 2026

Deploying goodprotocolui with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8beaa6a
Status: ✅  Deploy successful!
Preview URL: https://196d3774.goodprotocolui.pages.dev
Branch Preview URL: https://copilot-fix-fetch-and-test-r.goodprotocolui.pages.dev

View logs

@sirpy
Copy link
Copy Markdown
Contributor

sirpy commented May 20, 2026

@L03TJ3

Copilot AI changed the title [WIP] Fix bug with fetchAndTestRpcs failing Harden fetchAndTestRpcs parsing against DefiLlama format changes and add RPC fallbacks May 20, 2026
Copilot finished work on behalf of sirpy May 20, 2026 09:03
Copilot AI requested a review from sirpy May 20, 2026 09:03
@GoodDollar GoodDollar deleted a comment from wbrasilsousa May 21, 2026
@Gutopro
Copy link
Copy Markdown
Collaborator

Gutopro commented May 21, 2026

Handoff — ready for review @L03TJ3

What changed from the Copilot PR

The original implementation fetched a raw .js source file from DefiLlama and used a custom ~150-line balanced-segment scanner to extract RPC arrays from it. Per the bounty scope ("heavily simplified, not over-engineered"), I replaced this entirely.

rpcParsing.ts now calls fetchRpcsFromChainlist() which fetches chainid.network/chains.json — a proper JSON endpoint — and filters results to the 4 required chains with HTTP(S) URLs only. The file is ~25 lines. No custom parser, no JS source fetching.

In useWeb3.tsx, added the missing rpcInitializationPromise = null reset in the catch block so the app can retry after a failure without a full page reload. Also removed the now-unnecessary CHAINLIST_URL constant and chainMapping object.

What was tested

  • Live fetch test against chainid.network — all 4 chains (1, 122, 42220, 50) return non-empty HTTP(S) URLs ✓
  • FALLBACK_RPCS_BY_CHAIN unit test — all 4 chains covered with valid URLs ✓
  • pnpm lint — clean ✓
  • Full jest suite — 44 passing, 7 pre-existing failures not introduced by this branch ✓

Remaining risks

  • chainid.network/chains.json schema could change — if the rpc field is renamed, parsing silently returns empty arrays and falls back to constants
  • Fallback RPC URLs need periodic maintenance as endpoints may go offline

@L03TJ3 L03TJ3 removed this from GoodBounties May 22, 2026
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.

[Plan] Bug: fetchAndTestRpcs failing

4 participants