@metamask-previews/assets-controller 2.1.0-preview-7cbd7910e → 2.2.0-preview-0aca970c8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/AssetsController-method-action-types.cjs.map +1 -1
  3. package/dist/AssetsController-method-action-types.d.cts +16 -1
  4. package/dist/AssetsController-method-action-types.d.cts.map +1 -1
  5. package/dist/AssetsController-method-action-types.d.mts +16 -1
  6. package/dist/AssetsController-method-action-types.d.mts.map +1 -1
  7. package/dist/AssetsController-method-action-types.mjs.map +1 -1
  8. package/dist/AssetsController.cjs +25 -1
  9. package/dist/AssetsController.cjs.map +1 -1
  10. package/dist/AssetsController.d.cts +15 -0
  11. package/dist/AssetsController.d.cts.map +1 -1
  12. package/dist/AssetsController.d.mts +15 -0
  13. package/dist/AssetsController.d.mts.map +1 -1
  14. package/dist/AssetsController.mjs +25 -1
  15. package/dist/AssetsController.mjs.map +1 -1
  16. package/dist/data-sources/AccountsApiDataSource.cjs +1 -1
  17. package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
  18. package/dist/data-sources/AccountsApiDataSource.mjs +1 -1
  19. package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
  20. package/dist/index.cjs +3 -2
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +3 -2
  23. package/dist/index.d.cts.map +1 -1
  24. package/dist/index.d.mts +3 -2
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +1 -1
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/utils/formatExchangeRatesForBridge.cjs +123 -0
  29. package/dist/utils/formatExchangeRatesForBridge.cjs.map +1 -0
  30. package/dist/utils/formatExchangeRatesForBridge.d.cts +65 -0
  31. package/dist/utils/formatExchangeRatesForBridge.d.cts.map +1 -0
  32. package/dist/utils/formatExchangeRatesForBridge.d.mts +65 -0
  33. package/dist/utils/formatExchangeRatesForBridge.d.mts.map +1 -0
  34. package/dist/utils/formatExchangeRatesForBridge.mjs +119 -0
  35. package/dist/utils/formatExchangeRatesForBridge.mjs.map +1 -0
  36. package/dist/utils/index.cjs +8 -0
  37. package/dist/utils/index.cjs.map +1 -0
  38. package/dist/utils/index.d.cts +4 -0
  39. package/dist/utils/index.d.cts.map +1 -0
  40. package/dist/utils/index.d.mts +4 -0
  41. package/dist/utils/index.d.mts.map +1 -0
  42. package/dist/utils/index.mjs +3 -0
  43. package/dist/utils/index.mjs.map +1 -0
  44. package/dist/{utils.cjs → utils/normalizeAssetId.cjs} +1 -1
  45. package/dist/utils/normalizeAssetId.cjs.map +1 -0
  46. package/dist/{utils.d.mts → utils/normalizeAssetId.d.cts} +2 -2
  47. package/dist/utils/normalizeAssetId.d.cts.map +1 -0
  48. package/dist/{utils.d.cts → utils/normalizeAssetId.d.mts} +2 -2
  49. package/dist/utils/normalizeAssetId.d.mts.map +1 -0
  50. package/dist/{utils.mjs → utils/normalizeAssetId.mjs} +1 -1
  51. package/dist/utils/normalizeAssetId.mjs.map +1 -0
  52. package/package.json +1 -1
  53. package/dist/utils.cjs.map +0 -1
  54. package/dist/utils.d.cts.map +0 -1
  55. package/dist/utils.d.mts.map +0 -1
  56. package/dist/utils.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.2.0]
11
+
12
+ ### Added
13
+
14
+ - Add `getExchangeRatesForBridge()` method and `AssetsController:getExchangeRatesForBridge` messenger action. Returns bridge-compatible exchange rate state (`conversionRates`, `currencyRates`, `marketData`, `currentCurrency`) derived from `assetsPrice` and `selectedCurrency`, for use when the bridge uses AssetsController for rates ([#8076](https://github.com/MetaMask/core/pull/8076))
15
+
16
+ ### Changed
17
+
18
+ - `getExchangeRatesForBridge()` / `formatExchangeRatesForBridge` return value: `conversionRates` now includes only non-EVM assets (EVM rates remain in `currencyRates` and `marketData`); the `currency` field in conversionRates entries is resolved from `selectedCurrency` via the same CAIP currency map as MultichainAssetsRatesController (no longer hardcoded); EVM entries in `marketData` now include full price/market data (e.g. `id`, `marketCap`, `allTimeHigh`) in addition to bridge fields ([#8076](https://github.com/MetaMask/core/pull/8076))
19
+
10
20
  ## [2.1.0]
11
21
 
12
22
  ### Added
@@ -128,7 +138,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
128
138
  - Refactor `RpcDataSource` to delegate polling to `BalanceFetcher` and `TokenDetector` services ([#7709](https://github.com/MetaMask/core/pull/7709))
129
139
  - Refactor `BalanceFetcher` and `TokenDetector` to extend `StaticIntervalPollingControllerOnly` for independent polling management ([#7709](https://github.com/MetaMask/core/pull/7709))
130
140
 
131
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.1.0...HEAD
141
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.2.0...HEAD
142
+ [2.2.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.1.0...@metamask/assets-controller@2.2.0
132
143
  [2.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.0.2...@metamask/assets-controller@2.1.0
133
144
  [2.0.2]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.0.1...@metamask/assets-controller@2.0.2
134
145
  [2.0.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@2.0.0...@metamask/assets-controller@2.0.1
@@ -1 +1 @@
1
- {"version":3,"file":"AssetsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden.\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
1
+ {"version":3,"file":"AssetsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Returns exchange rates in the format expected by the bridge controller\n * (conversionRates, currencyRates, marketData, currentCurrency) so that\n * when useAssetsControllerForRates is true the bridge can use a single\n * action instead of MultichainAssetsRatesController, TokenRatesController,\n * and CurrencyRateController.\n *\n * @param options - Optional options for bridge rate conversion.\n * @param options.usdToSelectedCurrencyRate - When selectedCurrency is not 'usd', pass 1 USD = this many units of selected currency so that currencyRates and conversionRates use correct user-currency vs USD values; otherwise the bridge USD conversion will be wrong for non-USD currencies.\n * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.\n */\nexport type AssetsControllerGetExchangeRatesForBridgeAction = {\n type: `AssetsController:getExchangeRatesForBridge`;\n handler: AssetsController['getExchangeRatesForBridge'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden.\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerGetExchangeRatesForBridgeAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
@@ -19,6 +19,21 @@ export type AssetsControllerGetAssetsPriceAction = {
19
19
  type: `AssetsController:getAssetsPrice`;
20
20
  handler: AssetsController['getAssetsPrice'];
21
21
  };
22
+ /**
23
+ * Returns exchange rates in the format expected by the bridge controller
24
+ * (conversionRates, currencyRates, marketData, currentCurrency) so that
25
+ * when useAssetsControllerForRates is true the bridge can use a single
26
+ * action instead of MultichainAssetsRatesController, TokenRatesController,
27
+ * and CurrencyRateController.
28
+ *
29
+ * @param options - Optional options for bridge rate conversion.
30
+ * @param options.usdToSelectedCurrencyRate - When selectedCurrency is not 'usd', pass 1 USD = this many units of selected currency so that currencyRates and conversionRates use correct user-currency vs USD values; otherwise the bridge USD conversion will be wrong for non-USD currencies.
31
+ * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.
32
+ */
33
+ export type AssetsControllerGetExchangeRatesForBridgeAction = {
34
+ type: `AssetsController:getExchangeRatesForBridge`;
35
+ handler: AssetsController['getExchangeRatesForBridge'];
36
+ };
22
37
  /**
23
38
  * Add a custom asset for an account.
24
39
  * Custom assets are included in subscription and fetch operations.
@@ -79,5 +94,5 @@ export type AssetsControllerUnhideAssetAction = {
79
94
  /**
80
95
  * Union of all AssetsController action types.
81
96
  */
82
- export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAssetsPriceAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction;
97
+ export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAssetsPriceAction | AssetsControllerGetExchangeRatesForBridgeAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction;
83
98
  //# sourceMappingURL=AssetsController-method-action-types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,CAAC"}
1
+ {"version":3,"file":"AssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,+CAA+C,GAC/C,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,CAAC"}
@@ -19,6 +19,21 @@ export type AssetsControllerGetAssetsPriceAction = {
19
19
  type: `AssetsController:getAssetsPrice`;
20
20
  handler: AssetsController['getAssetsPrice'];
21
21
  };
22
+ /**
23
+ * Returns exchange rates in the format expected by the bridge controller
24
+ * (conversionRates, currencyRates, marketData, currentCurrency) so that
25
+ * when useAssetsControllerForRates is true the bridge can use a single
26
+ * action instead of MultichainAssetsRatesController, TokenRatesController,
27
+ * and CurrencyRateController.
28
+ *
29
+ * @param options - Optional options for bridge rate conversion.
30
+ * @param options.usdToSelectedCurrencyRate - When selectedCurrency is not 'usd', pass 1 USD = this many units of selected currency so that currencyRates and conversionRates use correct user-currency vs USD values; otherwise the bridge USD conversion will be wrong for non-USD currencies.
31
+ * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.
32
+ */
33
+ export type AssetsControllerGetExchangeRatesForBridgeAction = {
34
+ type: `AssetsController:getExchangeRatesForBridge`;
35
+ handler: AssetsController['getExchangeRatesForBridge'];
36
+ };
22
37
  /**
23
38
  * Add a custom asset for an account.
24
39
  * Custom assets are included in subscription and fetch operations.
@@ -79,5 +94,5 @@ export type AssetsControllerUnhideAssetAction = {
79
94
  /**
80
95
  * Union of all AssetsController action types.
81
96
  */
82
- export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAssetsPriceAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction;
97
+ export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAssetsPriceAction | AssetsControllerGetExchangeRatesForBridgeAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction;
83
98
  //# sourceMappingURL=AssetsController-method-action-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,CAAC"}
1
+ {"version":3,"file":"AssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,+CAA+C,GAC/C,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"AssetsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden.\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
1
+ {"version":3,"file":"AssetsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Returns exchange rates in the format expected by the bridge controller\n * (conversionRates, currencyRates, marketData, currentCurrency) so that\n * when useAssetsControllerForRates is true the bridge can use a single\n * action instead of MultichainAssetsRatesController, TokenRatesController,\n * and CurrencyRateController.\n *\n * @param options - Optional options for bridge rate conversion.\n * @param options.usdToSelectedCurrencyRate - When selectedCurrency is not 'usd', pass 1 USD = this many units of selected currency so that currencyRates and conversionRates use correct user-currency vs USD values; otherwise the bridge USD conversion will be wrong for non-USD currencies.\n * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.\n */\nexport type AssetsControllerGetExchangeRatesForBridgeAction = {\n type: `AssetsController:getExchangeRatesForBridge`;\n handler: AssetsController['getExchangeRatesForBridge'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden.\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerGetExchangeRatesForBridgeAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
@@ -32,7 +32,7 @@ const TokenDataSource_1 = require("./data-sources/TokenDataSource.cjs");
32
32
  const logger_1 = require("./logger.cjs");
33
33
  const DetectionMiddleware_1 = require("./middlewares/DetectionMiddleware.cjs");
34
34
  const ParallelMiddleware_1 = require("./middlewares/ParallelMiddleware.cjs");
35
- const utils_2 = require("./utils.cjs");
35
+ const utils_2 = require("./utils/index.cjs");
36
36
  // ============================================================================
37
37
  // CONTROLLER CONSTANTS
38
38
  // ============================================================================
@@ -43,6 +43,7 @@ const MESSENGER_EXPOSED_METHODS = [
43
43
  'getAssetsBalance',
44
44
  'getAssetMetadata',
45
45
  'getAssetsPrice',
46
+ 'getExchangeRatesForBridge',
46
47
  'addCustomAsset',
47
48
  'removeCustomAsset',
48
49
  'getCustomAssets',
@@ -417,6 +418,28 @@ class AssetsController extends base_controller_1.BaseController {
417
418
  }
418
419
  return result;
419
420
  }
421
+ /**
422
+ * Returns exchange rates in the format expected by the bridge controller
423
+ * (conversionRates, currencyRates, marketData, currentCurrency) so that
424
+ * when useAssetsControllerForRates is true the bridge can use a single
425
+ * action instead of MultichainAssetsRatesController, TokenRatesController,
426
+ * and CurrencyRateController.
427
+ *
428
+ * @param options - Optional options for bridge rate conversion.
429
+ * @param options.usdToSelectedCurrencyRate - When selectedCurrency is not 'usd', pass 1 USD = this many units of selected currency so that currencyRates and conversionRates use correct user-currency vs USD values; otherwise the bridge USD conversion will be wrong for non-USD currencies.
430
+ * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.
431
+ */
432
+ getExchangeRatesForBridge(options) {
433
+ const { nativeAssetIdentifiers } = this.messenger.call('NetworkEnablementController:getState');
434
+ const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
435
+ return (0, utils_2.formatExchangeRatesForBridge)({
436
+ assetsPrice: this.state.assetsPrice,
437
+ selectedCurrency: this.state.selectedCurrency,
438
+ nativeAssetIdentifiers,
439
+ networkConfigurationsByChainId,
440
+ usdToSelectedCurrencyRate: options?.usdToSelectedCurrencyRate,
441
+ });
442
+ }
420
443
  // ============================================================================
421
444
  // CUSTOM ASSETS MANAGEMENT
422
445
  // ============================================================================
@@ -699,6 +722,7 @@ class AssetsController extends base_controller_1.BaseController {
699
722
  this.messenger.unregisterActionHandler('AssetsController:getAssetsBalance');
700
723
  this.messenger.unregisterActionHandler('AssetsController:getAssetMetadata');
701
724
  this.messenger.unregisterActionHandler('AssetsController:getAssetsPrice');
725
+ this.messenger.unregisterActionHandler('AssetsController:getExchangeRatesForBridge');
702
726
  this.messenger.unregisterActionHandler('AssetsController:addCustomAsset');
703
727
  this.messenger.unregisterActionHandler('AssetsController:removeCustomAsset');
704
728
  this.messenger.unregisterActionHandler('AssetsController:getCustomAssets');