Skip to content

feat: TokenBalanceController architect handling unprocessed tokens#8132

Open
Prithpal-Sooriya wants to merge 10 commits intomainfrom
cursor/unprocessed-tokens-logic-699d
Open

feat: TokenBalanceController architect handling unprocessed tokens#8132
Prithpal-Sooriya wants to merge 10 commits intomainfrom
cursor/unprocessed-tokens-logic-699d

Conversation

@Prithpal-Sooriya
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya commented Mar 6, 2026

Explanation

  • What is the current state of things and why does it need to change?
    Previously, the AccountsApiBalanceFetcher would zero out balances for non-native tokens it couldn't retrieve. The TokenBalancesController would 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, TokenDetectionController had noisy console.warn logs 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 AccountsApiBalanceFetcher cannot process. These unprocessedTokens are then explicitly passed through the TokenBalancesController to subsequent fetchers. The RpcBalanceFetcher now accepts these unprocessedTokens and, when provided, will only fetch balances for those specific tokens, avoiding redundant work for native or staked tokens. The console.warn logs in TokenDetectionController have also been removed.

  • Are there any changes whose purpose might not obvious to those unfamiliar with the domain?
    The introduction of the unprocessedTokens parameter and its propagation across fetchers is key. When unprocessedTokens are 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, and rpc-balance-fetcher to correctly implement the "unprocessed tokens" handoff and fallback mechanism. TokenDetectionController was updated to remove noisy logs as requested.

Code Walkthrough:
https://www.loom.com/share/c38c5369dcb54d62908747078a899be9

  • If you had to upgrade a dependency, why did you do so?
    No dependency upgrades were required.

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

Open in Web Open in Cursor 

Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
@cursor
Copy link

cursor bot commented Mar 6, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
… 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.
@Prithpal-Sooriya Prithpal-Sooriya changed the title Unprocessed tokens logic feat: TokenBalanceController architect handling unprocessed tokens Mar 6, 2026
- 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.
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review March 6, 2026 18:39
@Prithpal-Sooriya Prithpal-Sooriya requested review from a team as code owners March 6, 2026 18:39
- 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.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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.

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