Skip to content

fix: use new controller on bridge#8090

Open
salimtb wants to merge 7 commits intomainfrom
fix/use-new-controller-on-bridge
Open

fix: use new controller on bridge#8090
salimtb wants to merge 7 commits intomainfrom
fix/use-new-controller-on-bridge

Conversation

@salimtb
Copy link
Contributor

@salimtb salimtb commented Mar 2, 2026

Explanation

What is the current state of things and why does it need to change?

The bridge controller currently reads exchange rates only from the legacy assets stack: MultichainAssetsRatesController, TokenRatesController, and CurrencyRateController. We want to support the new @metamask/assets-controller, which exposes a single bridge-oriented API (AssetsController:getExchangeRatesForBridge) and will eventually replace the old controllers for bridge/swap flows.

What is the solution your changes offer and how does it work?

  • Optional getUseAssetsControllerForRates
    The BridgeController constructor now accepts an optional getUseAssetsControllerForRates?: () => boolean. When this function is provided and returns true, the controller uses AssetsController:getExchangeRatesForBridge for all exchange-rate lookups and for the currency used when fetching asset prices. When it is not provided or returns false, behavior is unchanged and the legacy controllers are used.

  • Selector and type alignment
    ExchangeRateSourcesForLookup and the internal selector logic were updated so they accept both the legacy controller state shape and the shape returned by getExchangeRatesForBridge. Types from @metamask/assets-controllers are used where possible; the bridge format is supported via optional/union types so a single selector works for both code paths.

Are there any changes whose purpose might not be obvious to those unfamiliar with the domain?

  • The selector accepts a union of controller-state shapes (e.g. Record<Hex, …> vs Record<string, …>) and uses narrow casts when indexing, so that the same selectors work whether the host uses the new assets-controller or the legacy controllers.
  • getUseAssetsControllerForRates is a function (not a boolean) so the host can decide at call time (e.g. from a feature flag or config) without re-creating the controller.

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?

Only @metamask/bridge-controller was changed. It already depended on @metamask/assets-controller for the AssetsControllerGetExchangeRatesForBridgeAction type; no other packages were modified.

If you had to upgrade a dependency, why did you do so?

No dependency upgrades were made in this PR.

References

  • PR: fix: use new controller on bridge #8090 (this PR)
  • No linked issues. Consumers can adopt the new behavior by passing getUseAssetsControllerForRates (e.g. returning the value of a feature flag) when constructing BridgeController.

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

Note

Medium Risk
Changes how bridge exchange rates and selected currency are sourced when an optional constructor flag is enabled, which can affect quote pricing/metrics if the new rates shape differs or is incomplete. Default behavior remains unchanged, reducing rollout risk.

Overview
Adds an optional BridgeController constructor hook, getUseAssetsControllerForRates, to switch exchange-rate lookups from the legacy rate controllers to AssetsController:getExchangeRatesForBridge (including using its currentCurrency for price fetches).

Updates exchange-rate selector typing/logic (ExchangeRateSourcesForLookup and getExchangeRateByChainIdAndAddress) to accept both the legacy state shape and the AssetsController bridge rates shape, and adds test coverage validating the correct controller calls for each path. Also wires in @metamask/assets-controller as a dependency/TS project reference and documents the option in the changelog.

Written by Cursor Bugbot for commit 0d44fa4. This will update automatically on new commits. Configure here.

@salimtb salimtb changed the title Fix/use new controller on bridge Fix: use new controller on bridge Mar 2, 2026
@salimtb salimtb changed the title Fix: use new controller on bridge fix: use new controller on bridge Mar 2, 2026
@salimtb
Copy link
Contributor Author

salimtb commented Mar 2, 2026

@metamaskbot publish-preview

@salimtb salimtb marked this pull request as ready for review March 2, 2026 23:52
@salimtb salimtb requested review from a team as code owners March 2, 2026 23:53
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 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@salimtb
Copy link
Contributor Author

salimtb commented Mar 3, 2026

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "4.1.1-preview-0d44fa472",
  "@metamask-previews/accounts-controller": "36.0.1-preview-0d44fa472",
  "@metamask-previews/address-book-controller": "7.0.1-preview-0d44fa472",
  "@metamask-previews/ai-controllers": "0.1.0-preview-0d44fa472",
  "@metamask-previews/analytics-controller": "1.0.0-preview-0d44fa472",
  "@metamask-previews/analytics-data-regulation-controller": "0.0.0-preview-0d44fa472",
  "@metamask-previews/announcement-controller": "8.0.0-preview-0d44fa472",
  "@metamask-previews/app-metadata-controller": "2.0.0-preview-0d44fa472",
  "@metamask-previews/approval-controller": "8.0.0-preview-0d44fa472",
  "@metamask-previews/assets-controller": "2.2.0-preview-0d44fa472",
  "@metamask-previews/assets-controllers": "100.0.3-preview-0d44fa472",
  "@metamask-previews/base-controller": "9.0.0-preview-0d44fa472",
  "@metamask-previews/base-data-service": "0.0.0-preview-0d44fa472",
  "@metamask-previews/bridge-controller": "67.4.0-preview-0d44fa472",
  "@metamask-previews/bridge-status-controller": "67.0.1-preview-0d44fa472",
  "@metamask-previews/build-utils": "3.0.4-preview-0d44fa472",
  "@metamask-previews/chain-agnostic-permission": "1.4.0-preview-0d44fa472",
  "@metamask-previews/claims-controller": "0.4.2-preview-0d44fa472",
  "@metamask-previews/client-controller": "1.0.0-preview-0d44fa472",
  "@metamask-previews/compliance-controller": "1.0.1-preview-0d44fa472",
  "@metamask-previews/composable-controller": "12.0.0-preview-0d44fa472",
  "@metamask-previews/connectivity-controller": "0.1.0-preview-0d44fa472",
  "@metamask-previews/controller-utils": "11.19.0-preview-0d44fa472",
  "@metamask-previews/core-backend": "6.0.0-preview-0d44fa472",
  "@metamask-previews/delegation-controller": "2.0.1-preview-0d44fa472",
  "@metamask-previews/earn-controller": "11.1.1-preview-0d44fa472",
  "@metamask-previews/eip-5792-middleware": "3.0.0-preview-0d44fa472",
  "@metamask-previews/eip-7702-internal-rpc-middleware": "0.1.0-preview-0d44fa472",
  "@metamask-previews/eip1193-permission-middleware": "1.0.3-preview-0d44fa472",
  "@metamask-previews/ens-controller": "19.0.3-preview-0d44fa472",
  "@metamask-previews/error-reporting-service": "3.0.1-preview-0d44fa472",
  "@metamask-previews/eth-block-tracker": "15.0.1-preview-0d44fa472",
  "@metamask-previews/eth-json-rpc-middleware": "23.1.0-preview-0d44fa472",
  "@metamask-previews/eth-json-rpc-provider": "6.0.0-preview-0d44fa472",
  "@metamask-previews/foundryup": "1.0.1-preview-0d44fa472",
  "@metamask-previews/gas-fee-controller": "26.0.3-preview-0d44fa472",
  "@metamask-previews/gator-permissions-controller": "2.0.0-preview-0d44fa472",
  "@metamask-previews/geolocation-controller": "0.0.0-preview-0d44fa472",
  "@metamask-previews/json-rpc-engine": "10.2.3-preview-0d44fa472",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.8-preview-0d44fa472",
  "@metamask-previews/keyring-controller": "25.1.0-preview-0d44fa472",
  "@metamask-previews/logging-controller": "7.0.1-preview-0d44fa472",
  "@metamask-previews/message-manager": "14.1.0-preview-0d44fa472",
  "@metamask-previews/messenger": "0.3.0-preview-0d44fa472",
  "@metamask-previews/multichain-account-service": "7.0.0-preview-0d44fa472",
  "@metamask-previews/multichain-api-middleware": "1.2.7-preview-0d44fa472",
  "@metamask-previews/multichain-network-controller": "3.0.4-preview-0d44fa472",
  "@metamask-previews/multichain-transactions-controller": "7.0.1-preview-0d44fa472",
  "@metamask-previews/name-controller": "9.0.0-preview-0d44fa472",
  "@metamask-previews/network-controller": "30.0.0-preview-0d44fa472",
  "@metamask-previews/network-enablement-controller": "4.1.2-preview-0d44fa472",
  "@metamask-previews/notification-services-controller": "22.0.0-preview-0d44fa472",
  "@metamask-previews/permission-controller": "12.2.0-preview-0d44fa472",
  "@metamask-previews/permission-log-controller": "5.0.0-preview-0d44fa472",
  "@metamask-previews/perps-controller": "0.0.0-preview-0d44fa472",
  "@metamask-previews/phishing-controller": "16.3.0-preview-0d44fa472",
  "@metamask-previews/polling-controller": "16.0.3-preview-0d44fa472",
  "@metamask-previews/preferences-controller": "22.1.0-preview-0d44fa472",
  "@metamask-previews/profile-metrics-controller": "3.0.1-preview-0d44fa472",
  "@metamask-previews/profile-sync-controller": "27.1.0-preview-0d44fa472",
  "@metamask-previews/ramps-controller": "10.0.0-preview-0d44fa472",
  "@metamask-previews/rate-limit-controller": "7.0.0-preview-0d44fa472",
  "@metamask-previews/remote-feature-flag-controller": "4.1.0-preview-0d44fa472",
  "@metamask-previews/sample-controllers": "4.0.3-preview-0d44fa472",
  "@metamask-previews/seedless-onboarding-controller": "8.1.0-preview-0d44fa472",
  "@metamask-previews/selected-network-controller": "26.0.3-preview-0d44fa472",
  "@metamask-previews/shield-controller": "5.0.1-preview-0d44fa472",
  "@metamask-previews/signature-controller": "39.0.4-preview-0d44fa472",
  "@metamask-previews/storage-service": "1.0.0-preview-0d44fa472",
  "@metamask-previews/subscription-controller": "6.0.0-preview-0d44fa472",
  "@metamask-previews/transaction-controller": "62.19.0-preview-0d44fa472",
  "@metamask-previews/transaction-pay-controller": "16.1.1-preview-0d44fa472",
  "@metamask-previews/user-operation-controller": "41.0.3-preview-0d44fa472"
}

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