Skip to content

[#391] Batch RPC calls with multicall on home page#392

Merged
realproject7 merged 2 commits intomainfrom
task/391-batch-multicall
Mar 20, 2026
Merged

[#391] Batch RPC calls with multicall on home page#392
realproject7 merged 2 commits intomainfrom
task/391-batch-multicall

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

  • Add getBatchTokenData() to lib/price.ts — batches priceForNextMint, totalSupply, and tokenBond for all tokens into a single multicall RPC request
  • New BatchTokenDataProvider context component distributes batch results to child cards
  • New StoryGrid wraps the home page card grid with the batch provider
  • StoryCardTVL consumes batch context when available, falls back to individual getTokenTVL() on detail pages
  • Individual getTokenPrice() / getTokenTVL() kept intact for single-story pages

Result: ~32 simultaneous RPC calls → 1 multicall request

Fixes #391

Test plan

  • npm run typecheck — passes
  • npm run lint — passes
  • Manual: verify home page loads without 429 errors
  • Manual: verify TVL values display correctly on story cards

🤖 Generated with Claude Code

Add getBatchTokenData() to lib/price.ts — fetches price + TVL for
all tokens in a single multicall (3 calls per token → 1 RPC request).

Home page now uses StoryGrid → BatchTokenDataProvider context.
StoryCardTVL consumes batch data when available, falls back to
individual fetch on detail pages.

Reduces ~32 simultaneous RPC calls to 1 multicall request.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean multicall batching — 3 calls per token grouped into a single RPC request. Context provider + useQuery with fallback for individual pages is well-structured. StoryCardTVL gracefully falls back when batch context isn't available. CI green.

Minor note (not blocking): getBatchTokenData() in lib/price.ts uses server-side publicClient, but runs in browser via useQuery. Pre-existing pattern (getTokenTVL/getTokenPrice have the same issue), so out of scope for this PR.

Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES

Summary

The batching idea is good, but the new client-side path is wired to the wrong RPC client.

Findings

  • [high] BatchTokenDataProvider is a browser component that calls getBatchTokenData(), but getBatchTokenData() uses the server publicClient from lib/price.ts. That recreates the browser-side transport problem from #389, just through one multicall instead of many individual calls.
    • File: src/components/BatchTokenDataProvider.tsx:30
    • File: lib/price.ts:2
    • File: lib/price.ts:310
    • Suggestion: route this batched home-page fetch through the browser-safe client, or move the batched read to a server-rendered path instead of a client useQuery.

Decision

Requesting changes because the new home-page batching flow currently runs in the browser while still depending on the server RPC client, which can reintroduce the exact browser transport and rate-limit issue this codebase just fixed.

getBatchTokenData() now accepts optional client parameter.
BatchTokenDataProvider passes browserClient (CORS-safe) instead
of server publicClient.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@project7-interns project7-interns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Summary

The browser-side multicall path is now wired correctly. The batch helper accepts an injected client, and the client-side provider passes browserClient for the home-page multicall.

Findings

  • None.

Decision

Approved. The earlier browser-transport regression is resolved, the home page batching approach matches issue #391, and the latest lint-and-typecheck run is green.

@realproject7 realproject7 merged commit 81813d2 into main Mar 20, 2026
1 check passed
@realproject7 realproject7 deleted the task/391-batch-multicall branch March 20, 2026 20:21
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.

[Bug] Home page fires 32+ simultaneous RPC calls — batch with multicall

2 participants