fix: resolve balance aggregation issue for large token decimals#9653
Open
Prithpal-Sooriya wants to merge 2 commits into
Open
fix: resolve balance aggregation issue for large token decimals#9653Prithpal-Sooriya wants to merge 2 commits into
Prithpal-Sooriya wants to merge 2 commits into
Conversation
removes old behaviour that was kept prior to WS issues around data in incorrect format, but now has been fixed
Prithpal-Sooriya
temporarily deployed
to
default-branch
July 24, 2026 14:47 — with
GitHub Actions
Inactive
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Removes old behaviour that was kept prior from WS issues around data in incorrect format, but now has been fixed.
Also did some test spec cleaning...
References
Checklist
Note
Medium Risk
Changes how all aggregated balances and wallet/group fiat totals are computed; wrong if any caller still stores raw base units in
assetsBalance, but the PR assumes that path is obsolete.Overview
Fixes incorrect portfolio totals when token balances are large human-readable amounts (e.g. ~54B tokens with 9 decimals).
Balance aggregation in
balance.tsno longer runs the legacyscaleToHumanIfRawheuristic that divided amounts ≥10^decimalsby10^decimals.assetsBalanceis always human-readable now that upstream websocket/format issues are fixed, so that path was shrinking valid balances and dropping them from fiat totals.The same fix applies to
getAggregatedBalanceForAccount,getAggregatedBalanceForAccountIds,calculateBalanceForAllWallets, andcalculateBalanceChangeForAccountGroup.Tests were refactored with shared fixtures and a regression case for large balances; changelog updated under Unreleased → Fixed.
Reviewed by Cursor Bugbot for commit a3ea429. Bugbot is set up for automated code reviews on this repo. Configure here.