Skip to content

[#93] Batch balanceOf with multicall in ReaderPortfolio#100

Merged
realproject7 merged 1 commit intomainfrom
task/93-multicall-balance
Mar 15, 2026
Merged

[#93] Batch balanceOf with multicall in ReaderPortfolio#100
realproject7 merged 1 commit intomainfrom
task/93-multicall-balance

Conversation

@realproject7
Copy link
Copy Markdown
Owner

Summary

Fixes #93

  • Replaced N individual balanceOf RPC calls with a single publicClient.multicall() batch
  • Only fetches price, 24h change, and TVL for tokens the user actually holds
  • Reduces RPC overhead from O(N) to O(1) + O(held), fixing the N+1 scaling issue

Test plan

  • Portfolio loads correctly with held tokens displayed
  • Portfolio shows empty state when user holds no tokens
  • Failed individual balance checks are handled gracefully (filtered out)
  • Performance improvement noticeable with many storylines

🤖 Generated with Claude Code

Replace N individual balanceOf RPC calls with a single multicall.
Only fetch price/TVL data for tokens the user actually holds,
reducing RPC overhead from O(N) to O(1) + O(held).

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.

T2b Review — APPROVE

Clean N+1 fix:

  • All balanceOf checks batched into single multicall()
  • Only fetches price/TVL for held tokens (non-zero balance) — reduces follow-up RPC calls too ✓
  • Checks balance.status === 'success' before accessing result ✓
  • Early return for empty holdings ✓

LGTM ✓

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

This replaces the O(N) per-token balanceOf loop in ReaderPortfolio with a single multicall batch and then limits follow-up pricing/TVL work to held tokens only, which matches issue #93 without broadening scope.

Findings

  • No blocking findings.

Decision

Approving because the batching change is minimal, preserves existing downstream behavior for held tokens, and the refreshed lint/typecheck run passed.

@realproject7 realproject7 merged commit 30ef349 into main Mar 15, 2026
1 check passed
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] ReaderPortfolio scans all storylines for balanceOf — N+1 scaling

2 participants