feat: add new action to use on bridge controller#8076
Merged
Conversation
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.
Comment on lines
+1146
to
+1152
| return formatExchangeRatesForBridge({ | ||
| assetsPrice: this.state.assetsPrice, | ||
| selectedCurrency: this.state.selectedCurrency, | ||
| nativeAssetIdentifiers, | ||
| networkConfigurationsByChainId, | ||
| usdToSelectedCurrencyRate: options?.usdToSelectedCurrencyRate, | ||
| }); |
Contributor
There was a problem hiding this comment.
Nice abstraction. This is valid, fair enough.
Prithpal-Sooriya
approved these changes
Mar 2, 2026
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?
The bridge controller can use either legacy controllers (MultichainAssetsRatesController, TokenRatesController, CurrencyRateController) or the unified AssetsController for exchange rates when
useAssetsControllerForRatesis true. When using AssetsController, the bridge needs a single action that returns the same shape:conversionRates,currencyRates,marketData, andcurrentCurrency. Previously there was no such action on AssetsController, and the formatting logic (which assets go in conversionRates, which currency string to use, and how rich EVM marketData entries are) did not fully match bridge expectations.What is the solution your changes offer and how does it work?
getExchangeRatesForBridge()on AssetsController and register theAssetsController:getExchangeRatesForBridgemessenger action. It calls the existingformatExchangeRatesForBridgehelper withstate.assetsPriceandstate.selectedCurrency, and returns the bridge-compatible object.swift:0/iso4217:USD. Resolve the CAIP currency fromselectedCurrencyusingMAP_CAIP_CURRENCIESfrom@metamask/assets-controllers, with fallback to USD, matching MultichainAssetsRatesController.AssetsControllerso all controller actions are exported from one place. MovenormalizeAssetIdintoutils/and re-export from the utils barrel for clearer structure.Are there any changes whose purpose might not be obvious to those unfamiliar with the domain?
conversionRatesis intentionally limited to non-EVM assets because the bridge uses it for non-EVM chains; EVM rates are consumed fromcurrencyRatesandmarketData.MAP_CAIP_CURRENCIESfrom@metamask/assets-controllersso that assets-controller can use the same currency mapping without duplicating it (and to avoid a circular dependency from assets-controllers → assets-controller).If you had to update another package along the way, why?
MAP_CAIP_CURRENCIESfrom the MultichainAssetsRatesController (and from the package index) so thatformatExchangeRatesForBridgein assets-controller can import it and resolve the selected currency to the same CAIP string (e.g.swift:0/iso4217:EUR) that MultichainAssetsRatesController uses. This keeps a single source of truth for the currency map.If you had to upgrade a dependency, why?
References
useAssetsControllerForRates) will callAssetsController:getExchangeRatesForBridgeto get rates when this PR is merged.Checklist
Note
Medium Risk
Changes how exchange-rate data is shaped and converted for bridge consumers (including non-USD currency handling and EVM vs non-EVM separation), which could affect quotes if formatting or currency conversion is incorrect. The scope is contained and covered by new unit tests, but it touches pricing/market-data output used in bridge flows.
Overview
Adds
AssetsController:getExchangeRatesForBridge(andgetExchangeRatesForBridge()) to return a single bridge-compatible exchange-rate payload (conversionRates,currencyRates,marketData,currentCurrency) derived fromassetsPrice+selectedCurrency.Introduces
formatExchangeRatesForBridgeto produce the bridge shape, including: non-EVM-only entries inconversionRates, EVM native/token data incurrencyRates/marketData(with richer market fields), and optionalusdToSelectedCurrencyRateto correctly represent user-currency vs USD rates.Exports the shared currency mapping by re-exporting
MAP_CAIP_CURRENCIESfrom@metamask/assets-controllers, and reorganizes/exports new utils/types (formatExchangeRatesForBridge,normalizeAssetId) with added tests covering edge cases (invalid prices, ms timestamps, multi-chain EVM).Written by Cursor Bugbot for commit 0db7602. This will update automatically on new commits. Configure here.