You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Explanation
**Current Issue:**
The `AccountsApiBalanceFetcher` had a bug caused by address format
incompatibility between controllers:
- `TokenBalancesController` uses lowercase addresses for ERC20 tokens
- `AccountTrackerController` uses checksum addresses for native tokens
The original code always checksummed all addresses, causing a wrong
token balances state
**Solution:**
Fixed by implementing conditional address formatting:
- **Native tokens**: Use checksummed addresses (compatible with
`AccountTrackerController`)
- **ERC20 tokens**: Use lowercase addresses (compatible with
`TokenBalancesController`)
Also fixed the `|| ''` fallback bug that could pass empty strings to the
`checksum()` function.
## References
- Fixes duplicate native token entries in `AccountsApiBalanceFetcher` by
ensuring controller-compatible address formatting
## Checklist
- [ ] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Aligns address casing between controllers by conditionally formatting
account addresses in `AccountsApiBalanceFetcher` and updating
`TokenBalancesController` state access; updates changelog.
>
> - **Balances**:
> - `multi-chain-accounts-service/api-balance-fetcher.ts`:
> - Conditionally format `account` per token type (checksum for native
`ZERO_ADDRESS`, original for ERC20) and propagate via `finalAccount`.
> - Track native balances using the formatted key and widen
`ProcessedBalance.account` to `ChecksumAddress | string`.
> - `TokenBalancesController.ts`:
> - Access and write `state.tokenBalances` using `account as
ChecksumAddress` to handle mixed address formats during updates.
> - **Docs**:
> - `CHANGELOG.md`: Add "Fixed" note about address format compatibility
between `TokenBalancesController` and `AccountTrackerController` in
`AccountsApiBalanceFetcher`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
29bd9b8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Bernardo Garces Chapero <[email protected]>
Copy file name to clipboardExpand all lines: packages/assets-controllers/CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
33
33
- Reduce NFT detection API calls by 83% (from 6 calls to 1 call per 100 tokens) by eliminating collection endpoint requests
34
34
- Remove unused collection metadata fields: `contractDeployedAt`, `creator`, and `topBid`
35
35
36
+
### Fixed
37
+
38
+
- Fix address format compatibility between `TokenBalancesController` and `AccountTrackerController` in `AccountsApiBalanceFetcher` ([#6812](https://github.com/MetaMask/core/pull/6812))
0 commit comments