feat: TokenBalanceController architect handling unprocessed tokens#8132
Open
Prithpal-Sooriya wants to merge 10 commits intomainfrom
Open
feat: TokenBalanceController architect handling unprocessed tokens#8132Prithpal-Sooriya wants to merge 10 commits intomainfrom
Prithpal-Sooriya wants to merge 10 commits intomainfrom
Conversation
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
|
Cursor Agent can help with this pull request. Just |
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Prithpal-Sooriya
commented
Mar 6, 2026
packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.ts
Outdated
Show resolved
Hide resolved
Prithpal-Sooriya
commented
Mar 6, 2026
packages/assets-controllers/src/multi-chain-accounts-service/api-balance-fetcher.ts
Show resolved
Hide resolved
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Prithpal-Sooriya
commented
Mar 6, 2026
Prithpal-Sooriya
commented
Mar 6, 2026
Prithpal-Sooriya
commented
Mar 6, 2026
… and improve unprocessed token handling - Updated #balanceFetchers to include fetcher names for better traceability. - Simplified unprocessed token management by introducing previous state tracking. - Enhanced error reporting for unprocessed tokens during balance fetching. - Refactored balance fetching logic to streamline processing across multiple chains.
…processed chain handling - Added logic to aggregate balances and filter out processed chains. - Implemented handling for unprocessed chains and tokens, ensuring they are detected and processed correctly. - Introduced error handling for token detection calls to prevent application crashes on failures.
- Updated test descriptions for clarity on unprocessed token handling. - Improved token address handling by ensuring consistent formatting. - Enhanced logic to correctly manage unprocessed tokens for selected and excluded accounts. - Removed redundant test cases to streamline the testing process.
- Updated account address handling to use ChecksumAddress type for improved type safety. - Simplified token address mapping by removing unnecessary lowercase transformations. - Enhanced logic for managing account token groups to ensure consistency across different account formats.
Prithpal-Sooriya
commented
Mar 6, 2026
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
- Introduced a new variable for unprocessed chain IDs to enhance clarity. - Updated logic to aggregate remaining chains more efficiently by combining existing and unprocessed chains. - Improved readability and maintainability of the code structure.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
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
What is the current state of things and why does it need to change?
Previously, the
AccountsApiBalanceFetcherwould zero out balances for non-native tokens it couldn't retrieve. TheTokenBalancesControllerwould then only pass on unsupported chains to subsequent fetchers. This prevented the RPC balance fetcher from attempting to retrieve balances for these "missed" tokens. Additionally,TokenDetectionControllerhad noisyconsole.warnlogs for token metadata cache misses.What is the solution your changes offer and how does it work?
This PR modifies the balance fetching flow to return "unprocessed tokens" for non-native tokens that the
AccountsApiBalanceFetchercannot process. TheseunprocessedTokensare then explicitly passed through theTokenBalancesControllerto subsequent fetchers. TheRpcBalanceFetchernow accepts theseunprocessedTokensand, when provided, will only fetch balances for those specific tokens, avoiding redundant work for native or staked tokens. Theconsole.warnlogs inTokenDetectionControllerhave also been removed.Are there any changes whose purpose might not obvious to those unfamiliar with the domain?
The introduction of the
unprocessedTokensparameter and its propagation across fetchers is key. WhenunprocessedTokensare present, the RPC fetcher operates in a targeted mode, only querying for the specified ERC-20 tokens, rather than performing a full chain-wide balance fetch.If your primary goal was to update one package but you found you had to update another one along the way, why did you do so?
The change required modifications across
api-balance-fetcher,TokenBalancesController, andrpc-balance-fetcherto correctly implement the "unprocessed tokens" handoff and fallback mechanism.TokenDetectionControllerwas updated to remove noisy logs as requested.Code Walkthrough:
https://www.loom.com/share/c38c5369dcb54d62908747078a899be9
No dependency upgrades were required.
References
Checklist