fix: hide native tokens on Tempo networks (testnet and mainnet)#7882
fix: hide native tokens on Tempo networks (testnet and mainnet)#7882
Conversation
6d12965 to
298d46a
Compare
bb22d25 to
722b537
Compare
8825e0e to
347c3f8
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
ec1001b to
78b9f63
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
78b9f63 to
6f86401
Compare
6f86401 to
d8e4626
Compare
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * 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? * If you had to upgrade a dependency, why did you do so? --> Tempo [asset-controller PR](#7882) uses as `CHAIN_IDS_TO_SKIP_NATIVE_TOKEN` constant in two different controllers. This PR would allow to not have to maintain `CHAIN_IDS_TO_SKIP_NATIVE_TOKEN` in both controllers and use a common `CHAIN_IDS_WITH_NO_NATIVE_TOKEN` instead, for easier maintenance. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: adds a new exported constant and updates the export surface/tests, with no behavioral changes unless consumers opt in to using it. > > **Overview** > Adds `CHAIN_IDS_WITH_NO_NATIVE_TOKEN` to `@metamask/controller-utils`, initially listing Tempo mainnet/testnet CAIP-2 chain IDs for consumers to treat as *no-native-token* chains. > > Updates the package public exports and snapshot test to include the new constant, and documents it in the `controller-utils` changelog. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 51571fe. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
| } | ||
|
|
||
| return true; | ||
| } |
There was a problem hiding this comment.
I don't think we deal with CAIP-2 chain format for evms in this package (assets-controllers) and we are deprecating it soon anyway, You could simplify this a lot by just having the chains constant stored as a hex string.
There was a problem hiding this comment.
Hi Bernardo. I am currently in the (long) process of making a release to centralize the list of Tempo chains so they can be shared in between controllers. Putting them in core/controller-utils:
export const CHAIN_IDS_WITH_NO_NATIVE_TOKEN = [
'eip155:42431', // Tempo Testnet
'eip155:4217', // Tempo Mainnet
] as const;
Are you suggesting that we change the format here ? I originally thought that CAIP2 was the "newer" and hence "wanted" format.
| accountsByChainId, | ||
| ) as [Hex, Record<Hex, { balance: Hex | null }>][]) { | ||
| // Skip native tokens on Tempo networks | ||
| if (shouldHideNativeToken(chainId, true)) { |
There was a problem hiding this comment.
| if (shouldHideNativeToken(chainId, true)) { | |
| if (!shouldIncludeNativeToken(chainId)) { |
| const isNative = caipAsset.assetNamespace === 'slip44'; | ||
| if (shouldHideNativeToken(chainId, isNative)) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
You can get rid of this check for now, there are no multichain (non-evm) tokens that we need to hide.
There was a problem hiding this comment.
I think the intention was to have it "plug and play" if a non-EVM chain was to hide their native token but I suppose WAGNI principle is valid too. I'll remove it since it might allow to remove the shouldHideNativeToken altogether.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
|
@metamaskbot publish-preview |
|
Will add a unit test to go past this 97.99% coverage but doing a preview build for QA in the meantime |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |

Explanation
Context:
Tempo is a EVM-ish chain that doesn't have the concept of native token.
This PR changes the behavior of asset-controller(s) so:
AssetsController.getAssets, in balance fetching (AccountTrackerController and RPC balance fetcher), and in asset selectors so the UI never shows Tempo native tokens.eip155:42431) and Tempo mainnet (eip155:4217) return arbitrary large numbers for native token balances viaeth_getBalance.References
Checklist
Note
Medium Risk
Touches balance-fetching and asset-selection logic, which can impact portfolio totals and token visibility across networks; changes are gated to a specific chain allowlist and backed by targeted tests.
Overview
Native token handling is changed to exclude Tempo networks end-to-end:
AssetsController.getAssetsnow filters out native assets on chain IDs listed inCHAIN_IDS_WITH_NO_NATIVE_TOKEN, and balance fetching inAccountTrackerController/rpc-balance-fetchernow short-circuits native balance retrieval (returning0x0for those addresses) to avoid boguseth_getBalanceresults.Selectors are updated to omit native assets for Tempo chains, and
token-service.tsforcesoccurrenceFloor=1for Tempo Mainnet. New unit tests cover Tempo mainnet/testnet behavior and ensure non-Tempo networks are unaffected; changelogs are updated accordingly.Written by Cursor Bugbot for commit e35e3ee. This will update automatically on new commits. Configure here.