Skip to content

refactor(assets-controller): memoize balance call encodings in Multic…#9423

Closed
salimtb wants to merge 2 commits into
mainfrom
refactor/memoize-multicall-balance-encoding
Closed

refactor(assets-controller): memoize balance call encodings in Multic…#9423
salimtb wants to merge 2 commits into
mainfrom
refactor/memoize-multicall-balance-encoding

Conversation

@salimtb

@salimtb salimtb commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

…allClient

Cache encodeBalanceOf and encodeGetEthBalance per account address to avoid redundant ABI encoding when batching many tokens for the same wallet.

Explanation

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Low Risk
Internal performance refactor with no API or balance semantics change; risk is limited to ensuring cached calldata stays identical to prior per-request encoding.

Overview
MulticallClient.batchBalanceOf now builds ERC-20 balanceOf and native getEthBalance calldata once per account (case-insensitive) per invocation, instead of re-encoding for every token row in a batch.

A per-request createBalanceCallDataCache backs multicall aggregate3 assembly via buildAggregate3BalanceCalls, and the same cache is passed through multicall fallback and unsupported-chain single-call paths so ERC-20 fallback reuses encoded calldata. Native balances on those fallback paths still use provider.getBalance (unchanged).

A unit test asserts encoding deduplication (e.g. two balanceOf and one getEthBalance encode for four mixed requests). Changelog updated under Unreleased.

Reviewed by Cursor Bugbot for commit 655f6ec. Bugbot is set up for automated code reviews on this repo. Configure here.

salimtb added 2 commits July 8, 2026 10:39
…allClient

Cache encodeBalanceOf and encodeGetEthBalance per account address to
avoid redundant ABI encoding when batching many tokens for the same
wallet.
@salimtb salimtb marked this pull request as ready for review July 8, 2026 09:18
@salimtb salimtb requested review from a team as code owners July 8, 2026 09:18
@salimtb salimtb temporarily deployed to default-branch July 8, 2026 09:18 — with GitHub Actions Inactive
@salimtb salimtb closed this Jul 8, 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.

1 participant