@metamask-previews/assets-controllers 113.0.1-preview-d4ac59b6e → 113.0.1-preview-0439f4dd7

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 (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/CurrencyRateController-method-action-types.d.ts +9 -1
  3. package/dist/CurrencyRateController-method-action-types.d.ts.map +1 -1
  4. package/dist/CurrencyRateController-method-action-types.js.map +1 -1
  5. package/dist/CurrencyRateController.d.ts.map +1 -1
  6. package/dist/CurrencyRateController.js +2 -0
  7. package/dist/CurrencyRateController.js.map +1 -1
  8. package/dist/DeFiPositionsController/DeFiPositionsController-method-action-types.d.ts +18 -0
  9. package/dist/DeFiPositionsController/DeFiPositionsController-method-action-types.d.ts.map +1 -0
  10. package/dist/DeFiPositionsController/DeFiPositionsController-method-action-types.js +6 -0
  11. package/dist/DeFiPositionsController/DeFiPositionsController-method-action-types.js.map +1 -0
  12. package/dist/DeFiPositionsController/DeFiPositionsController.d.ts +2 -1
  13. package/dist/DeFiPositionsController/DeFiPositionsController.d.ts.map +1 -1
  14. package/dist/DeFiPositionsController/DeFiPositionsController.js +5 -0
  15. package/dist/DeFiPositionsController/DeFiPositionsController.js.map +1 -1
  16. package/dist/NftController-method-action-types.d.ts +110 -0
  17. package/dist/NftController-method-action-types.d.ts.map +1 -0
  18. package/dist/NftController-method-action-types.js +6 -0
  19. package/dist/NftController-method-action-types.js.map +1 -0
  20. package/dist/NftController.d.ts +2 -1
  21. package/dist/NftController.d.ts.map +1 -1
  22. package/dist/NftController.js +10 -0
  23. package/dist/NftController.js.map +1 -1
  24. package/dist/NftDetectionController-method-action-types.d.ts +24 -0
  25. package/dist/NftDetectionController-method-action-types.d.ts.map +1 -0
  26. package/dist/NftDetectionController-method-action-types.js +6 -0
  27. package/dist/NftDetectionController-method-action-types.js.map +1 -0
  28. package/dist/NftDetectionController.d.ts +4 -2
  29. package/dist/NftDetectionController.d.ts.map +1 -1
  30. package/dist/NftDetectionController.js +2 -0
  31. package/dist/NftDetectionController.js.map +1 -1
  32. package/dist/TokenDetectionController-method-action-types.d.ts +9 -1
  33. package/dist/TokenDetectionController-method-action-types.d.ts.map +1 -1
  34. package/dist/TokenDetectionController-method-action-types.js.map +1 -1
  35. package/dist/TokenDetectionController.d.ts.map +1 -1
  36. package/dist/TokenDetectionController.js +2 -0
  37. package/dist/TokenDetectionController.js.map +1 -1
  38. package/dist/index.d.ts +5 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/token-prices-service/codefi-v2.d.ts +1 -1
  42. package/dist/token-prices-service/codefi-v2.d.ts.map +1 -1
  43. package/dist/token-prices-service/codefi-v2.js +1 -1
  44. package/dist/token-prices-service/codefi-v2.js.map +1 -1
  45. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Expose `startPolling` and `stopPollingByToken` through CurrencyRateController messenger ([#11247](https://github.com/MetaMask/core/pull/11247))
13
+ - Expose `isNftOwner`, `addNftVerifyOwnership`, `addNft`, `removeNft`, `removeAndIgnoreNft`, `checkAndUpdateSingleNftOwnershipStatus`, and `checkAndUpdateAllNftsOwnershipStatus` through NftController messenger ([#11247](https://github.com/MetaMask/core/pull/11247))
14
+ - Expose `detectNfts` through NftDetectionController messenger ([#11247](https://github.com/MetaMask/core/pull/11247))
15
+ - Expose `startPolling` and `stopPollingByToken` through TokenDetectionController messenger ([#11247](https://github.com/MetaMask/core/pull/11247))
16
+ - Expose `startPolling` and `stopPollingByToken` through DeFiPositionsController messenger ([#11247](https://github.com/MetaMask/core/pull/11247))
17
+
18
+ ### Changed
19
+
20
+ - Use SLIP-44 coin type 16661 for the 0G native asset price lookup ([#11221](https://github.com/MetaMask/core/pull/11221))
21
+
10
22
  ## [113.0.1]
11
23
 
12
24
  ### Changed
@@ -21,8 +21,16 @@ export type CurrencyRateControllerUpdateExchangeRateAction = {
21
21
  type: `CurrencyRateController:updateExchangeRate`;
22
22
  handler: CurrencyRateController['updateExchangeRate'];
23
23
  };
24
+ export type CurrencyRateControllerStartPollingAction = {
25
+ type: `CurrencyRateController:startPolling`;
26
+ handler: CurrencyRateController['startPolling'];
27
+ };
28
+ export type CurrencyRateControllerStopPollingByPollingTokenAction = {
29
+ type: `CurrencyRateController:stopPollingByPollingToken`;
30
+ handler: CurrencyRateController['stopPollingByPollingToken'];
31
+ };
24
32
  /**
25
33
  * Union of all CurrencyRateController action types.
26
34
  */
27
- export type CurrencyRateControllerMethodActions = CurrencyRateControllerSetCurrentCurrencyAction | CurrencyRateControllerUpdateExchangeRateAction;
35
+ export type CurrencyRateControllerMethodActions = CurrencyRateControllerSetCurrentCurrencyAction | CurrencyRateControllerUpdateExchangeRateAction | CurrencyRateControllerStartPollingAction | CurrencyRateControllerStopPollingByPollingTokenAction;
28
36
  //# sourceMappingURL=CurrencyRateController-method-action-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyRateController-method-action-types.d.ts","sourceRoot":"","sources":["../src/CurrencyRateController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,8CAA8C,GAC9C,8CAA8C,CAAC"}
1
+ {"version":3,"file":"CurrencyRateController-method-action-types.d.ts","sourceRoot":"","sources":["../src/CurrencyRateController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,sBAAsB,CAAC,2BAA2B,CAAC,CAAC;CAC9D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,8CAA8C,GAC9C,8CAA8C,GAC9C,wCAAwC,GACxC,qDAAqD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyRateController-method-action-types.js","sourceRoot":"","sources":["../src/CurrencyRateController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { CurrencyRateController } from './CurrencyRateController.js';\n\n/**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\nexport type CurrencyRateControllerSetCurrentCurrencyAction = {\n type: `CurrencyRateController:setCurrentCurrency`;\n handler: CurrencyRateController['setCurrentCurrency'];\n};\n\n/**\n * Updates the exchange rate for the current currency and native currency pairs.\n *\n * @param nativeCurrencies - The native currency symbols to fetch exchange rates for.\n */\nexport type CurrencyRateControllerUpdateExchangeRateAction = {\n type: `CurrencyRateController:updateExchangeRate`;\n handler: CurrencyRateController['updateExchangeRate'];\n};\n\n/**\n * Union of all CurrencyRateController action types.\n */\nexport type CurrencyRateControllerMethodActions =\n | CurrencyRateControllerSetCurrentCurrencyAction\n | CurrencyRateControllerUpdateExchangeRateAction;\n"]}
1
+ {"version":3,"file":"CurrencyRateController-method-action-types.js","sourceRoot":"","sources":["../src/CurrencyRateController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { CurrencyRateController } from './CurrencyRateController.js';\n\n/**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\nexport type CurrencyRateControllerSetCurrentCurrencyAction = {\n type: `CurrencyRateController:setCurrentCurrency`;\n handler: CurrencyRateController['setCurrentCurrency'];\n};\n\n/**\n * Updates the exchange rate for the current currency and native currency pairs.\n *\n * @param nativeCurrencies - The native currency symbols to fetch exchange rates for.\n */\nexport type CurrencyRateControllerUpdateExchangeRateAction = {\n type: `CurrencyRateController:updateExchangeRate`;\n handler: CurrencyRateController['updateExchangeRate'];\n};\n\nexport type CurrencyRateControllerStartPollingAction = {\n type: `CurrencyRateController:startPolling`;\n handler: CurrencyRateController['startPolling'];\n};\n\nexport type CurrencyRateControllerStopPollingByPollingTokenAction = {\n type: `CurrencyRateController:stopPollingByPollingToken`;\n handler: CurrencyRateController['stopPollingByPollingToken'];\n};\n\n/**\n * Union of all CurrencyRateController action types.\n */\nexport type CurrencyRateControllerMethodActions =\n | CurrencyRateControllerSetCurrentCurrencyAction\n | CurrencyRateControllerUpdateExchangeRateAction\n | CurrencyRateControllerStartPollingAction\n | CurrencyRateControllerStopPollingByPollingTokenAction;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyRateController.d.ts","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names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GG;AACH,qBAAa,sBAAuB,SAAQ,4BAC1C,OAAO,IAAI,EACX,iBAAiB,EACjB,qBAAqB,CACtB;;IAWC;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,EACV,cAAsB,EACtB,QAAiB,EACjB,mBAAgC,EAChC,YAAmC,EACnC,SAAS,EACT,KAAK,EACL,kBAAkB,GACnB,EAAE;QACD,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,qBAAqB,CAAC;QACjC,KAAK,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACnC,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC;QACpC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC;QAC7B,kBAAkB,EAAE,0BAA0B,CAAC;KAChD,EAqBA;IAmBD;;;;OAIG;IACG,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB/D;IA4ND;;;;OAIG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GACvC,OAAO,CAAC,IAAI,CAAC,CA4Cf;IAED;;;;OAIG;IACM,OAAO,IAAI,IAAI,CAGvB;IAED;;;;;OAKG;IACG,YAAY,CAAC,EACjB,gBAAgB,GACjB,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAO1C;CACF;eAEc,sBAAsB"}
1
+ {"version":3,"file":"CurrencyRateController.d.ts","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AAKnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAEhC,MAAM,8BAA8B,CAAC;AAKtC,OAAO,KAAK,EAAE,mCA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EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,qBAAqB,CAAC;QACjC,KAAK,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACnC,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC;QACpC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC;QAC7B,kBAAkB,EAAE,0BAA0B,CAAC;KAChD,EAqBA;IAmBD;;;;OAIG;IACG,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB/D;IA4ND;;;;OAIG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GACvC,OAAO,CAAC,IAAI,CAAC,CA4Cf;IAED;;;;OAIG;IACM,OAAO,IAAI,IAAI,CAGvB;IAED;;;;;OAKG;IACG,YAAY,CAAC,EACjB,gBAAgB,GACjB,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAO1C;CACF;eAEc,sBAAsB"}
@@ -4,6 +4,8 @@ import { Mutex } from 'async-mutex';
4
4
  import { getNativeTokenAddress } from './token-prices-service/codefi-v2.js';
5
5
  const name = 'CurrencyRateController';
6
6
  const MESSENGER_EXPOSED_METHODS = [
7
+ 'startPolling',
8
+ 'stopPollingByPollingToken',
7
9
  'setCurrentCurrency',
8
10
  'updateExchangeRate',
9
11
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyRateController.js","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAOpC,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAyB5E,MAAM,IAAI,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CAAC,qBAAqB;oBACvB,CAAC,CAAC,cAAc,CAAC;gBACnB,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,+BAA+B,CACtD,uBAAuB,CACxB,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;gBACpB,KAAK,CAAC,aAAa,GAAG;oBACpB,GAAG,KAAK,CAAC,aAAa;oBACtB,GAAG,KAAK;iBACT,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YACxD,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACM,OAAO;QACd,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,EACjB,gBAAgB,GACS;QACzB,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;YACzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkConfiguration,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport type { CurrencyRateControllerMethodActions } from './CurrencyRateController-method-action-types.js';\nimport type { AbstractTokenPricesService } from './token-prices-service/abstract-token-prices-service.js';\nimport { getNativeTokenAddress } from './token-prices-service/codefi-v2.js';\n\n/**\n * currencyRates - Object keyed by native currency\n *\n * currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n *\n * currencyRates.conversionRate - Conversion rate from current base asset to the current currency\n *\n * currentCurrency - Currently-active ISO 4217 currency code\n *\n * usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n currentCurrency: string;\n currencyRates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'CurrencyRateController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'setCurrentCurrency',\n 'updateExchangeRate',\n] as const;\n\nexport type CurrencyRateStateChange = ControllerStateChangeEvent<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerEvents = CurrencyRateStateChange;\n\nexport type CurrencyRateControllerGetStateAction = ControllerGetStateAction<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerActions =\n | CurrencyRateControllerGetStateAction\n | CurrencyRateControllerMethodActions;\n\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetStateAction;\n\nexport type CurrencyRateMessenger = Messenger<\n typeof name,\n CurrencyRateControllerActions | AllowedActions,\n CurrencyRateControllerEvents\n>;\n\nconst metadata: StateMetadata<CurrencyRateState> = {\n currentCurrency: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n currencyRates: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nconst defaultState = {\n currentCurrency: 'usd',\n currencyRates: {\n ETH: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\n/** The input to start polling for the {@link CurrencyRateController} */\ntype CurrencyRatePollingInput = {\n nativeCurrencies: string[];\n};\n\nconst boundedPrecisionNumber = (value: number, precision = 9): number =>\n Number(value.toFixed(precision));\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\n/** Result from attempting to fetch rates from an API */\ntype FetchRatesResult = {\n /** Successfully fetched rates */\n rates: CurrencyRateState['currencyRates'];\n /** Currencies that failed and need fallback or null state */\n failedCurrencies: Record<string, string>;\n};\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\nexport class CurrencyRateController extends StaticIntervalPollingController<CurrencyRatePollingInput>()<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #includeUsdRate: boolean;\n\n readonly #useExternalServices: () => boolean;\n\n readonly #tokenPricesService: AbstractTokenPricesService;\n\n readonly #isDeprecated: () => boolean;\n\n /**\n * Creates a CurrencyRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messenger.\n * @param options.state - Initial state to set on this controller.\n * @param options.useExternalServices - Feature Switch for using external services (default: true)\n * @param options.tokenPricesService - An object in charge of retrieving token prices\n * @param options.isDeprecated - Optional function that returns true to completely\n * disable this controller (no requests, no state updates). When it returns\n * `true`, `currencyRates` is reset to `{}` at construction and at every entry point,\n * so no stale rates remain in state. The function is evaluated dynamically\n * on each entry point so it can be toggled at runtime. Intended for use when\n * a higher-level controller (e.g. AssetsController) supersedes this one.\n */\n constructor({\n includeUsdRate = false,\n interval = 180000,\n useExternalServices = () => true,\n isDeprecated = (): boolean => false,\n messenger,\n state,\n tokenPricesService,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: CurrencyRateMessenger;\n state?: Partial<CurrencyRateState>;\n useExternalServices?: () => boolean;\n isDeprecated?: () => boolean;\n tokenPricesService: AbstractTokenPricesService;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#useExternalServices = useExternalServices;\n this.setIntervalLength(interval);\n this.#tokenPricesService = tokenPricesService;\n this.#isDeprecated = isDeprecated;\n\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n }\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Clears all persisted `currencyRates` so that no stale rates remain in state.\n *\n * Called from every entry point when `isDeprecated()` is true so that a\n * runtime toggle propagates to state immediately, even if the controller was\n * originally constructed while it was enabled. The update is skipped when\n * `currencyRates` is already empty to avoid emitting redundant state changes.\n */\n #enforceDisabledState(): void {\n if (Object.keys(this.state.currencyRates).length === 0) {\n return;\n }\n this.update((state) => {\n state.currencyRates = {};\n });\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string): Promise<void> {\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n return;\n }\n\n const releaseLock = await this.#mutex.acquire();\n const nativeCurrencies = Object.keys(this.state.currencyRates);\n try {\n this.update(() => {\n return {\n ...defaultState,\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.updateExchangeRate(nativeCurrencies);\n }\n\n /**\n * Attempts to fetch exchange rates from the primary Price API.\n *\n * @param nativeCurrenciesToFetch - Map of native currency to the currency symbol to fetch.\n * @param currentCurrency - The current fiat currency to get rates for.\n * @returns Object containing successful rates and currencies that failed.\n */\n async #fetchRatesFromPriceApi(\n nativeCurrenciesToFetch: Record<string, string>,\n currentCurrency: string,\n ): Promise<FetchRatesResult> {\n const rates: CurrencyRateState['currencyRates'] = {};\n let failedCurrencies: Record<string, string> = {};\n\n try {\n const response = await this.#tokenPricesService.fetchExchangeRates({\n baseCurrency: currentCurrency,\n includeUsdRate: this.#includeUsdRate,\n cryptocurrencies: [...new Set(Object.values(nativeCurrenciesToFetch))],\n });\n\n Object.entries(nativeCurrenciesToFetch).forEach(\n ([nativeCurrency, fetchedCurrency]) => {\n const rate = response[fetchedCurrency.toLowerCase()];\n\n if (rate?.value) {\n rates[nativeCurrency] = {\n conversionDate: Date.now() / 1000,\n conversionRate: boundedPrecisionNumber(1 / rate.value),\n usdConversionRate: rate?.usd\n ? boundedPrecisionNumber(1 / rate.usd)\n : null,\n };\n } else {\n failedCurrencies[nativeCurrency] = fetchedCurrency;\n }\n },\n );\n } catch (error) {\n console.error('Failed to fetch exchange rates.', error);\n failedCurrencies = { ...nativeCurrenciesToFetch };\n }\n\n return { rates, failedCurrencies };\n }\n\n /**\n * Fetches exchange rates from the token prices service as a fallback.\n * This method is designed to never throw - all errors are handled internally\n * and result in currencies being marked as failed.\n *\n * @param currenciesToFetch - Map of native currencies that need fallback fetching.\n * @param currentCurrency - The current fiat currency to get rates for.\n * @returns Object containing successful rates and currencies that failed.\n */\n async #fetchRatesFromTokenPricesService(\n currenciesToFetch: Record<string, string>,\n currentCurrency: string,\n ): Promise<FetchRatesResult> {\n try {\n const rates: CurrencyRateState['currencyRates'] = {};\n const failedCurrencies: Record<string, string> = {};\n\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n const networkConfigurations =\n networkControllerState.networkConfigurationsByChainId;\n\n // Build a map of nativeCurrency -> chainId for currencies to fetch\n const currencyToChainIds = Object.entries(currenciesToFetch).reduce<\n Record<string, { fetchedCurrency: string; chainId: Hex }>\n >((acc, [nativeCurrency, fetchedCurrency]) => {\n const matchingEntry = (\n Object.entries(networkConfigurations) as [Hex, NetworkConfiguration][]\n ).find(\n ([, config]) =>\n config.nativeCurrency.toUpperCase() ===\n fetchedCurrency.toUpperCase(),\n );\n\n if (matchingEntry) {\n acc[nativeCurrency] = { fetchedCurrency, chainId: matchingEntry[0] };\n } else {\n // No matching network configuration - mark as failed\n failedCurrencies[nativeCurrency] = fetchedCurrency;\n }\n return acc;\n }, {});\n\n const currencyToChainIdsEntries = Object.entries(currencyToChainIds);\n const ratesResults = await Promise.allSettled(\n currencyToChainIdsEntries.map(async ([nativeCurrency, { chainId }]) => {\n const nativeTokenAddress = getNativeTokenAddress(chainId);\n const tokenPrices = await this.#tokenPricesService.fetchTokenPrices({\n assets: [{ chainId, tokenAddress: nativeTokenAddress }],\n currency: currentCurrency,\n });\n\n const tokenPrice = tokenPrices.find(\n (item) =>\n item.tokenAddress.toLowerCase() ===\n nativeTokenAddress.toLowerCase(),\n );\n\n return {\n nativeCurrency,\n conversionDate: tokenPrice ? Date.now() / 1000 : null,\n conversionRate: tokenPrice?.price\n ? boundedPrecisionNumber(tokenPrice.price)\n : null,\n usdConversionRate: null,\n };\n }),\n );\n\n ratesResults.forEach((result, index) => {\n const [nativeCurrency, { fetchedCurrency, chainId }] =\n currencyToChainIdsEntries[index];\n\n if (result.status === 'fulfilled' && result.value.conversionRate) {\n rates[nativeCurrency] = {\n conversionDate: result.value.conversionDate,\n conversionRate: result.value.conversionRate,\n usdConversionRate: result.value.usdConversionRate,\n };\n } else {\n if (result.status === 'rejected') {\n console.error(\n `Failed to fetch token price for ${nativeCurrency} on chain ${chainId}`,\n result.reason,\n );\n }\n failedCurrencies[nativeCurrency] = fetchedCurrency;\n }\n });\n\n return { rates, failedCurrencies };\n } catch (error) {\n console.error(\n 'Failed to fetch exchange rates from token prices service.',\n error,\n );\n // Return all currencies as failed\n return { rates: {}, failedCurrencies: { ...currenciesToFetch } };\n }\n }\n\n /**\n * Creates null rate entries for currencies that couldn't be fetched.\n *\n * @param currencies - Array of currency symbols to create null entries for.\n * @returns Null rate entries for all provided currencies.\n */\n #createNullRatesForCurrencies(\n currencies: string[],\n ): CurrencyRateState['currencyRates'] {\n return currencies.reduce<CurrencyRateState['currencyRates']>(\n (acc, nativeCurrency) => {\n acc[nativeCurrency] = {\n conversionDate: null,\n conversionRate: null,\n usdConversionRate: null,\n };\n return acc;\n },\n {},\n );\n }\n\n /**\n * Fetches exchange rates with fallback logic.\n * First tries the Price API, then falls back to token prices service for any failed currencies.\n *\n * @param nativeCurrenciesToFetch - Map of native currency to the currency symbol to fetch.\n * @returns Exchange rates for all requested currencies.\n */\n async #fetchExchangeRatesWithFallback(\n nativeCurrenciesToFetch: Record<string, string>,\n ): Promise<CurrencyRateState['currencyRates']> {\n const { currentCurrency } = this.state;\n\n // Step 1: Try the Price API exchange rates first\n const {\n rates: ratesPriceApi,\n failedCurrencies: failedCurrenciesFromPriceApi,\n } = await this.#fetchRatesFromPriceApi(\n nativeCurrenciesToFetch,\n currentCurrency,\n );\n\n // Step 2: If all currencies succeeded, return early\n if (Object.keys(failedCurrenciesFromPriceApi).length === 0) {\n return ratesPriceApi;\n }\n\n // Step 3: Fallback using token prices service for failed currencies\n const {\n rates: ratesFromFallback,\n failedCurrencies: failedCurrenciesFromFallback,\n } = await this.#fetchRatesFromTokenPricesService(\n failedCurrenciesFromPriceApi,\n currentCurrency,\n );\n\n // Step 4: Create null rates for currencies that failed both approaches\n const nullRates = this.#createNullRatesForCurrencies(\n Object.keys(failedCurrenciesFromFallback),\n );\n\n // Step 5: Merge all results - Price API rates take priority, then fallback, then null rates\n return {\n ...nullRates,\n ...ratesFromFallback,\n ...ratesPriceApi,\n };\n }\n\n /**\n * Updates the exchange rate for the current currency and native currency pairs.\n *\n * @param nativeCurrencies - The native currency symbols to fetch exchange rates for.\n */\n async updateExchangeRate(\n nativeCurrencies: (string | undefined)[],\n ): Promise<void> {\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n return;\n }\n\n if (!this.#useExternalServices()) {\n return;\n }\n\n const releaseLock = await this.#mutex.acquire();\n try {\n // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.\n // Map each native currency to the symbol we want to fetch for it.\n const testnetSymbols = Object.values(TESTNET_TICKER_SYMBOLS);\n const nativeCurrenciesToFetch = nativeCurrencies.reduce<\n Record<string, string>\n >((acc, nativeCurrency) => {\n if (!nativeCurrency) {\n return acc;\n }\n\n acc[nativeCurrency] = testnetSymbols.includes(nativeCurrency)\n ? FALL_BACK_VS_CURRENCY\n : nativeCurrency;\n return acc;\n }, {});\n\n const rates = await this.#fetchExchangeRatesWithFallback(\n nativeCurrenciesToFetch,\n );\n\n this.update((state) => {\n state.currencyRates = {\n ...state.currencyRates,\n ...rates,\n };\n });\n } catch (error) {\n console.error('Failed to fetch exchange rates.', error);\n throw error;\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy(): void {\n super.destroy();\n this.stopAllPolling();\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @param input - The input for the poll.\n * @param input.nativeCurrencies - The native currency symbols to poll prices for.\n */\n async _executePoll({\n nativeCurrencies,\n }: CurrencyRatePollingInput): Promise<void> {\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n return;\n }\n\n await this.updateExchangeRate(nativeCurrencies);\n }\n}\n\nexport default CurrencyRateController;\n"]}
1
+ {"version":3,"file":"CurrencyRateController.js","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAOpC,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAyB5E,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAEtC,MAAM,yBAAyB,GAAG;IAChC,cAAc;IACd,2BAA2B;IAC3B,oBAAoB;IACpB,oBAAoB;CACZ,CAAC;AA4BX,MAAM,QAAQ,GAAqC;IACjD,eAAe,EAAE;QACf,kBAAkB,EAAE,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B,CACtD,uBAAuB,CACxB,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;gBACpB,KAAK,CAAC,aAAa,GAAG;oBACpB,GAAG,KAAK,CAAC,aAAa;oBACtB,GAAG,KAAK;iBACT,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YACxD,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACM,OAAO;QACd,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,EACjB,gBAAgB,GACS;QACzB,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;YACzB,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,MAAM,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkConfiguration,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport type { CurrencyRateControllerMethodActions } from './CurrencyRateController-method-action-types.js';\nimport type { AbstractTokenPricesService } from './token-prices-service/abstract-token-prices-service.js';\nimport { getNativeTokenAddress } from './token-prices-service/codefi-v2.js';\n\n/**\n * currencyRates - Object keyed by native currency\n *\n * currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n *\n * currencyRates.conversionRate - Conversion rate from current base asset to the current currency\n *\n * currentCurrency - Currently-active ISO 4217 currency code\n *\n * usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n currentCurrency: string;\n currencyRates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'CurrencyRateController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'startPolling',\n 'stopPollingByPollingToken',\n 'setCurrentCurrency',\n 'updateExchangeRate',\n] as const;\n\nexport type CurrencyRateStateChange = ControllerStateChangeEvent<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerEvents = CurrencyRateStateChange;\n\nexport type CurrencyRateControllerGetStateAction = ControllerGetStateAction<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerActions =\n | CurrencyRateControllerGetStateAction\n | CurrencyRateControllerMethodActions;\n\ntype AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetStateAction;\n\nexport type CurrencyRateMessenger = Messenger<\n typeof name,\n CurrencyRateControllerActions | AllowedActions,\n CurrencyRateControllerEvents\n>;\n\nconst metadata: StateMetadata<CurrencyRateState> = {\n currentCurrency: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n currencyRates: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nconst defaultState = {\n currentCurrency: 'usd',\n currencyRates: {\n ETH: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\n/** The input to start polling for the {@link CurrencyRateController} */\ntype CurrencyRatePollingInput = {\n nativeCurrencies: string[];\n};\n\nconst boundedPrecisionNumber = (value: number, precision = 9): number =>\n Number(value.toFixed(precision));\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\n/** Result from attempting to fetch rates from an API */\ntype FetchRatesResult = {\n /** Successfully fetched rates */\n rates: CurrencyRateState['currencyRates'];\n /** Currencies that failed and need fallback or null state */\n failedCurrencies: Record<string, string>;\n};\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\nexport class CurrencyRateController extends StaticIntervalPollingController<CurrencyRatePollingInput>()<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #includeUsdRate: boolean;\n\n readonly #useExternalServices: () => boolean;\n\n readonly #tokenPricesService: AbstractTokenPricesService;\n\n readonly #isDeprecated: () => boolean;\n\n /**\n * Creates a CurrencyRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messenger.\n * @param options.state - Initial state to set on this controller.\n * @param options.useExternalServices - Feature Switch for using external services (default: true)\n * @param options.tokenPricesService - An object in charge of retrieving token prices\n * @param options.isDeprecated - Optional function that returns true to completely\n * disable this controller (no requests, no state updates). When it returns\n * `true`, `currencyRates` is reset to `{}` at construction and at every entry point,\n * so no stale rates remain in state. The function is evaluated dynamically\n * on each entry point so it can be toggled at runtime. Intended for use when\n * a higher-level controller (e.g. AssetsController) supersedes this one.\n */\n constructor({\n includeUsdRate = false,\n interval = 180000,\n useExternalServices = () => true,\n isDeprecated = (): boolean => false,\n messenger,\n state,\n tokenPricesService,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: CurrencyRateMessenger;\n state?: Partial<CurrencyRateState>;\n useExternalServices?: () => boolean;\n isDeprecated?: () => boolean;\n tokenPricesService: AbstractTokenPricesService;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#useExternalServices = useExternalServices;\n this.setIntervalLength(interval);\n this.#tokenPricesService = tokenPricesService;\n this.#isDeprecated = isDeprecated;\n\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n }\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Clears all persisted `currencyRates` so that no stale rates remain in state.\n *\n * Called from every entry point when `isDeprecated()` is true so that a\n * runtime toggle propagates to state immediately, even if the controller was\n * originally constructed while it was enabled. The update is skipped when\n * `currencyRates` is already empty to avoid emitting redundant state changes.\n */\n #enforceDisabledState(): void {\n if (Object.keys(this.state.currencyRates).length === 0) {\n return;\n }\n this.update((state) => {\n state.currencyRates = {};\n });\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string): Promise<void> {\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n return;\n }\n\n const releaseLock = await this.#mutex.acquire();\n const nativeCurrencies = Object.keys(this.state.currencyRates);\n try {\n this.update(() => {\n return {\n ...defaultState,\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.updateExchangeRate(nativeCurrencies);\n }\n\n /**\n * Attempts to fetch exchange rates from the primary Price API.\n *\n * @param nativeCurrenciesToFetch - Map of native currency to the currency symbol to fetch.\n * @param currentCurrency - The current fiat currency to get rates for.\n * @returns Object containing successful rates and currencies that failed.\n */\n async #fetchRatesFromPriceApi(\n nativeCurrenciesToFetch: Record<string, string>,\n currentCurrency: string,\n ): Promise<FetchRatesResult> {\n const rates: CurrencyRateState['currencyRates'] = {};\n let failedCurrencies: Record<string, string> = {};\n\n try {\n const response = await this.#tokenPricesService.fetchExchangeRates({\n baseCurrency: currentCurrency,\n includeUsdRate: this.#includeUsdRate,\n cryptocurrencies: [...new Set(Object.values(nativeCurrenciesToFetch))],\n });\n\n Object.entries(nativeCurrenciesToFetch).forEach(\n ([nativeCurrency, fetchedCurrency]) => {\n const rate = response[fetchedCurrency.toLowerCase()];\n\n if (rate?.value) {\n rates[nativeCurrency] = {\n conversionDate: Date.now() / 1000,\n conversionRate: boundedPrecisionNumber(1 / rate.value),\n usdConversionRate: rate?.usd\n ? boundedPrecisionNumber(1 / rate.usd)\n : null,\n };\n } else {\n failedCurrencies[nativeCurrency] = fetchedCurrency;\n }\n },\n );\n } catch (error) {\n console.error('Failed to fetch exchange rates.', error);\n failedCurrencies = { ...nativeCurrenciesToFetch };\n }\n\n return { rates, failedCurrencies };\n }\n\n /**\n * Fetches exchange rates from the token prices service as a fallback.\n * This method is designed to never throw - all errors are handled internally\n * and result in currencies being marked as failed.\n *\n * @param currenciesToFetch - Map of native currencies that need fallback fetching.\n * @param currentCurrency - The current fiat currency to get rates for.\n * @returns Object containing successful rates and currencies that failed.\n */\n async #fetchRatesFromTokenPricesService(\n currenciesToFetch: Record<string, string>,\n currentCurrency: string,\n ): Promise<FetchRatesResult> {\n try {\n const rates: CurrencyRateState['currencyRates'] = {};\n const failedCurrencies: Record<string, string> = {};\n\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n const networkConfigurations =\n networkControllerState.networkConfigurationsByChainId;\n\n // Build a map of nativeCurrency -> chainId for currencies to fetch\n const currencyToChainIds = Object.entries(currenciesToFetch).reduce<\n Record<string, { fetchedCurrency: string; chainId: Hex }>\n >((acc, [nativeCurrency, fetchedCurrency]) => {\n const matchingEntry = (\n Object.entries(networkConfigurations) as [Hex, NetworkConfiguration][]\n ).find(\n ([, config]) =>\n config.nativeCurrency.toUpperCase() ===\n fetchedCurrency.toUpperCase(),\n );\n\n if (matchingEntry) {\n acc[nativeCurrency] = { fetchedCurrency, chainId: matchingEntry[0] };\n } else {\n // No matching network configuration - mark as failed\n failedCurrencies[nativeCurrency] = fetchedCurrency;\n }\n return acc;\n }, {});\n\n const currencyToChainIdsEntries = Object.entries(currencyToChainIds);\n const ratesResults = await Promise.allSettled(\n currencyToChainIdsEntries.map(async ([nativeCurrency, { chainId }]) => {\n const nativeTokenAddress = getNativeTokenAddress(chainId);\n const tokenPrices = await this.#tokenPricesService.fetchTokenPrices({\n assets: [{ chainId, tokenAddress: nativeTokenAddress }],\n currency: currentCurrency,\n });\n\n const tokenPrice = tokenPrices.find(\n (item) =>\n item.tokenAddress.toLowerCase() ===\n nativeTokenAddress.toLowerCase(),\n );\n\n return {\n nativeCurrency,\n conversionDate: tokenPrice ? Date.now() / 1000 : null,\n conversionRate: tokenPrice?.price\n ? boundedPrecisionNumber(tokenPrice.price)\n : null,\n usdConversionRate: null,\n };\n }),\n );\n\n ratesResults.forEach((result, index) => {\n const [nativeCurrency, { fetchedCurrency, chainId }] =\n currencyToChainIdsEntries[index];\n\n if (result.status === 'fulfilled' && result.value.conversionRate) {\n rates[nativeCurrency] = {\n conversionDate: result.value.conversionDate,\n conversionRate: result.value.conversionRate,\n usdConversionRate: result.value.usdConversionRate,\n };\n } else {\n if (result.status === 'rejected') {\n console.error(\n `Failed to fetch token price for ${nativeCurrency} on chain ${chainId}`,\n result.reason,\n );\n }\n failedCurrencies[nativeCurrency] = fetchedCurrency;\n }\n });\n\n return { rates, failedCurrencies };\n } catch (error) {\n console.error(\n 'Failed to fetch exchange rates from token prices service.',\n error,\n );\n // Return all currencies as failed\n return { rates: {}, failedCurrencies: { ...currenciesToFetch } };\n }\n }\n\n /**\n * Creates null rate entries for currencies that couldn't be fetched.\n *\n * @param currencies - Array of currency symbols to create null entries for.\n * @returns Null rate entries for all provided currencies.\n */\n #createNullRatesForCurrencies(\n currencies: string[],\n ): CurrencyRateState['currencyRates'] {\n return currencies.reduce<CurrencyRateState['currencyRates']>(\n (acc, nativeCurrency) => {\n acc[nativeCurrency] = {\n conversionDate: null,\n conversionRate: null,\n usdConversionRate: null,\n };\n return acc;\n },\n {},\n );\n }\n\n /**\n * Fetches exchange rates with fallback logic.\n * First tries the Price API, then falls back to token prices service for any failed currencies.\n *\n * @param nativeCurrenciesToFetch - Map of native currency to the currency symbol to fetch.\n * @returns Exchange rates for all requested currencies.\n */\n async #fetchExchangeRatesWithFallback(\n nativeCurrenciesToFetch: Record<string, string>,\n ): Promise<CurrencyRateState['currencyRates']> {\n const { currentCurrency } = this.state;\n\n // Step 1: Try the Price API exchange rates first\n const {\n rates: ratesPriceApi,\n failedCurrencies: failedCurrenciesFromPriceApi,\n } = await this.#fetchRatesFromPriceApi(\n nativeCurrenciesToFetch,\n currentCurrency,\n );\n\n // Step 2: If all currencies succeeded, return early\n if (Object.keys(failedCurrenciesFromPriceApi).length === 0) {\n return ratesPriceApi;\n }\n\n // Step 3: Fallback using token prices service for failed currencies\n const {\n rates: ratesFromFallback,\n failedCurrencies: failedCurrenciesFromFallback,\n } = await this.#fetchRatesFromTokenPricesService(\n failedCurrenciesFromPriceApi,\n currentCurrency,\n );\n\n // Step 4: Create null rates for currencies that failed both approaches\n const nullRates = this.#createNullRatesForCurrencies(\n Object.keys(failedCurrenciesFromFallback),\n );\n\n // Step 5: Merge all results - Price API rates take priority, then fallback, then null rates\n return {\n ...nullRates,\n ...ratesFromFallback,\n ...ratesPriceApi,\n };\n }\n\n /**\n * Updates the exchange rate for the current currency and native currency pairs.\n *\n * @param nativeCurrencies - The native currency symbols to fetch exchange rates for.\n */\n async updateExchangeRate(\n nativeCurrencies: (string | undefined)[],\n ): Promise<void> {\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n return;\n }\n\n if (!this.#useExternalServices()) {\n return;\n }\n\n const releaseLock = await this.#mutex.acquire();\n try {\n // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.\n // Map each native currency to the symbol we want to fetch for it.\n const testnetSymbols = Object.values(TESTNET_TICKER_SYMBOLS);\n const nativeCurrenciesToFetch = nativeCurrencies.reduce<\n Record<string, string>\n >((acc, nativeCurrency) => {\n if (!nativeCurrency) {\n return acc;\n }\n\n acc[nativeCurrency] = testnetSymbols.includes(nativeCurrency)\n ? FALL_BACK_VS_CURRENCY\n : nativeCurrency;\n return acc;\n }, {});\n\n const rates = await this.#fetchExchangeRatesWithFallback(\n nativeCurrenciesToFetch,\n );\n\n this.update((state) => {\n state.currencyRates = {\n ...state.currencyRates,\n ...rates,\n };\n });\n } catch (error) {\n console.error('Failed to fetch exchange rates.', error);\n throw error;\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy(): void {\n super.destroy();\n this.stopAllPolling();\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @param input - The input for the poll.\n * @param input.nativeCurrencies - The native currency symbols to poll prices for.\n */\n async _executePoll({\n nativeCurrencies,\n }: CurrencyRatePollingInput): Promise<void> {\n if (this.#isDeprecated()) {\n this.#enforceDisabledState();\n return;\n }\n\n await this.updateExchangeRate(nativeCurrencies);\n }\n}\n\nexport default CurrencyRateController;\n"]}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { DeFiPositionsController } from './DeFiPositionsController.js';
6
+ export type DeFiPositionsControllerStartPollingAction = {
7
+ type: `DeFiPositionsController:startPolling`;
8
+ handler: DeFiPositionsController['startPolling'];
9
+ };
10
+ export type DeFiPositionsControllerStopPollingByPollingTokenAction = {
11
+ type: `DeFiPositionsController:stopPollingByPollingToken`;
12
+ handler: DeFiPositionsController['stopPollingByPollingToken'];
13
+ };
14
+ /**
15
+ * Union of all DeFiPositionsController action types.
16
+ */
17
+ export type DeFiPositionsControllerMethodActions = DeFiPositionsControllerStartPollingAction | DeFiPositionsControllerStopPollingByPollingTokenAction;
18
+ //# sourceMappingURL=DeFiPositionsController-method-action-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeFiPositionsController-method-action-types.d.ts","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAE5E,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,uBAAuB,CAAC,cAAc,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,sDAAsD,GAAG;IACnE,IAAI,EAAE,mDAAmD,CAAC;IAC1D,OAAO,EAAE,uBAAuB,CAAC,2BAA2B,CAAC,CAAC;CAC/D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAC5C,yCAAyC,GACzC,sDAAsD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=DeFiPositionsController-method-action-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeFiPositionsController-method-action-types.js","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { DeFiPositionsController } from './DeFiPositionsController.js';\n\nexport type DeFiPositionsControllerStartPollingAction = {\n type: `DeFiPositionsController:startPolling`;\n handler: DeFiPositionsController['startPolling'];\n};\n\nexport type DeFiPositionsControllerStopPollingByPollingTokenAction = {\n type: `DeFiPositionsController:stopPollingByPollingToken`;\n handler: DeFiPositionsController['stopPollingByPollingToken'];\n};\n\n/**\n * Union of all DeFiPositionsController action types.\n */\nexport type DeFiPositionsControllerMethodActions =\n | DeFiPositionsControllerStartPollingAction\n | DeFiPositionsControllerStopPollingByPollingTokenAction;\n"]}
@@ -4,6 +4,7 @@ import type { KeyringControllerLockEvent } from '@metamask/keyring-controller';
4
4
  import type { Messenger } from '@metamask/messenger';
5
5
  import type { TransactionControllerTransactionConfirmedEvent } from '@metamask/transaction-controller';
6
6
  import type { Hex } from '@metamask/utils';
7
+ import type { DeFiPositionsControllerMethodActions } from './DeFiPositionsController-method-action-types.js';
7
8
  import type { GroupedDeFiPositions } from './group-defi-positions.js';
8
9
  declare const controllerName = "DeFiPositionsController";
9
10
  export type GroupedDeFiPositionsPerChain = {
@@ -39,7 +40,7 @@ export type DeFiPositionsControllerState = {
39
40
  };
40
41
  };
41
42
  export declare const getDefaultDefiPositionsControllerState: () => DeFiPositionsControllerState;
42
- export type DeFiPositionsControllerActions = DeFiPositionsControllerGetStateAction;
43
+ export type DeFiPositionsControllerActions = DeFiPositionsControllerGetStateAction | DeFiPositionsControllerMethodActions;
43
44
  export type DeFiPositionsControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DeFiPositionsControllerState>;
44
45
  export type DeFiPositionsControllerEvents = DeFiPositionsControllerStateChangeEvent;
45
46
  export type DeFiPositionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DeFiPositionsControllerState>;
@@ -1 +1 @@
1
- {"version":3,"file":"DeFiPositionsController.d.ts","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8DAA8D,EAC9D,oDAAoD,EACrD,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,8CAA8C,EAAE,MAAM,kCAAkC,CAAC;AACvG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAM3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAItE,QAAA,MAAM,cAAc,4BAA4B,CAAC;AAEjD,MAAM,MAAM,4BAA4B,GAAG;IACzC,CAAC,KAAK,EA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,OAAO,cAAc,EACrB,8BAA8B,GAAG,cAAc,EAC/C,6BAA6B,GAAG,aAAa,CAC9C,CAAC;;;;;;;;;;;;;;;;AAEF;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,6BAC3C,OAAO,cAAc,EACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IASC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,SAAsB,EACtB,UAAU,GACX,EAAE;QACD,SAAS,EAAE,gCAAgC,CAAC;QAC5C,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;QAC1B,UAAU,CAAC,EAAE,cAAc,CAAC;KAC7B,EA+CA;IAEK,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAgBlC;CAiEF"}
1
+ {"version":3,"file":"DeFiPositionsController.d.ts","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8DAA8D,EAC9D,oDAAoD,EACrD,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,8CAA8C,EAAE,MAAM,kCAAkC,CAAC;AACvG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,kDAAkD,CAAC;AAI7G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAItE,QAAA,MAAM,cAAc,4BAA4B,CAAC;AAOjD,MAAM,MAAM,4BAA4B,GAAG;IACzC,CAAC,KAAK,EAAE,GAAG,GAAG,oBAAoB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,K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,CAC9C,CAAC;;;;;;;;;;;;;;;;AAEF;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,6BAC3C,OAAO,cAAc,EACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IASC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,SAAsB,EACtB,UAAU,GACX,EAAE;QACD,SAAS,EAAE,gCAAgC,CAAC;QAC5C,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC;QAC1B,UAAU,CAAC,EAAE,cAAc,CAAC;KAC7B,EAoDA;IAEK,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAgBlC;CAiEF"}
@@ -5,6 +5,10 @@ import { buildPositionFetcher } from './fetch-positions.js';
5
5
  import { groupDeFiPositions } from './group-defi-positions.js';
6
6
  const TEN_MINUTES_IN_MS = 600_000;
7
7
  const controllerName = 'DeFiPositionsController';
8
+ const MESSENGER_EXPOSED_METHODS = [
9
+ 'startPolling',
10
+ 'stopPollingByPollingToken',
11
+ ];
8
12
  const controllerMetadata = {
9
13
  allDeFiPositions: {
10
14
  includeInStateLogs: false,
@@ -69,6 +73,7 @@ export class DeFiPositionsController extends StaticIntervalPollingController() {
69
73
  await this.#updateAccountPositions(selectedAddress);
70
74
  });
71
75
  this.#trackEvent = trackEvent;
76
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
72
77
  }
73
78
  async _executePoll() {
74
79
  if (!this.#isEnabled()) {
@@ -1 +1 @@
1
- {"version":3,"file":"DeFiPositionsController.js","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAI/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAA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QAClC,CAAC;IACH,CAAC;IAED,qBAAqB;QACnB,OAAO,IAAI,CAAC,SAAS;aAClB,IAAI,CAAC,2DAA2D,CAAC;aACjE,IAAI,CAAC,CAAC,OAAwB,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACnE,EAAE,OAAO,CAAC;IACd,CAAC;CACF","sourcesContent":["import type {\n AccountTreeControllerGetAccountsFromSelectedAccountGroupAction,\n AccountTreeControllerSelectedAccountGroupChangeEvent,\n} from '@metamask/account-tree-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { isEvmAccountType } from '@metamask/keyring-api';\nimport type { KeyringControllerLockEvent } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionControllerTransactionConfirmedEvent } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { calculateDeFiPositionMetrics } from './calculate-defi-metrics.js';\nimport type { DefiPositionResponse } from './fetch-positions.js';\nimport { buildPositionFetcher } from './fetch-positions.js';\nimport { groupDeFiPositions } from './group-defi-positions.js';\nimport type { GroupedDeFiPositions } from './group-defi-positions.js';\n\nconst TEN_MINUTES_IN_MS = 600_000;\n\nconst controllerName = 'DeFiPositionsController';\n\nexport type GroupedDeFiPositionsPerChain = {\n [chain: Hex]: GroupedDeFiPositions;\n};\n\nexport type TrackingEventPayload = {\n event: string;\n category: string;\n properties: {\n totalPositions: number;\n totalMarketValueUSD: number;\n breakdown?: {\n protocolId: string;\n marketValueUSD: number;\n chainId: Hex;\n count: number;\n }[];\n };\n};\n\ntype TrackEventHook = (event: TrackingEventPayload) => void;\n\nexport type DeFiPositionsControllerState = {\n /**\n * Object containing DeFi positions per account and network\n */\n allDeFiPositions: {\n [accountAddress: string]: GroupedDeFiPositionsPerChain | null;\n };\n\n /**\n * Object containing DeFi positions count per account\n */\n allDeFiPositionsCount: {\n [accountAddress: string]: number;\n };\n};\n\nconst controllerMetadata: StateMetadata<DeFiPositionsControllerState> = {\n allDeFiPositions: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n allDeFiPositionsCount: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n};\n\nexport const getDefaultDefiPositionsControllerState =\n (): DeFiPositionsControllerState => {\n return {\n allDeFiPositions: {},\n allDeFiPositionsCount: {},\n };\n };\n\nexport type DeFiPositionsControllerActions =\n DeFiPositionsControllerGetStateAction;\n\nexport type DeFiPositionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DeFiPositionsControllerState\n>;\n\nexport type DeFiPositionsControllerEvents =\n DeFiPositionsControllerStateChangeEvent;\n\nexport type DeFiPositionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n DeFiPositionsControllerState\n >;\n\n/**\n * The external actions available to the {@link DeFiPositionsController}.\n */\nexport type AllowedActions =\n AccountTreeControllerGetAccountsFromSelectedAccountGroupAction;\n\n/**\n * The external events available to the {@link DeFiPositionsController}.\n */\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | TransactionControllerTransactionConfirmedEvent\n | AccountTreeControllerSelectedAccountGroupChangeEvent;\n\n/**\n * The messenger of the {@link DeFiPositionsController}.\n */\nexport type DeFiPositionsControllerMessenger = Messenger<\n typeof controllerName,\n DeFiPositionsControllerActions | AllowedActions,\n DeFiPositionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that stores assets and exposes convenience methods\n */\nexport class DeFiPositionsController extends StaticIntervalPollingController()<\n typeof controllerName,\n DeFiPositionsControllerState,\n DeFiPositionsControllerMessenger\n> {\n readonly #fetchPositions: (\n accountAddress: string,\n ) => Promise<DefiPositionResponse[]>;\n\n readonly #isEnabled: () => boolean;\n\n readonly #trackEvent?: TrackEventHook;\n\n /**\n * DeFiPositionsController constuctor\n *\n * @param options - Constructor options.\n * @param options.messenger - The controller messenger.\n * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)\n * @param options.trackEvent - Function to track events. (default: undefined)\n */\n constructor({\n messenger,\n isEnabled = () => true,\n trackEvent,\n }: {\n messenger: DeFiPositionsControllerMessenger;\n isEnabled?: () => boolean;\n trackEvent?: TrackEventHook;\n }) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n messenger,\n state: getDefaultDefiPositionsControllerState(),\n });\n\n this.setIntervalLength(TEN_MINUTES_IN_MS);\n\n this.#fetchPositions = buildPositionFetcher();\n this.#isEnabled = isEnabled;\n\n this.messenger.subscribe('KeyringController:lock', () => {\n this.stopAllPolling();\n });\n\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n async (transactionMeta) => {\n const selectedAddress = this.#getSelectedEvmAdress();\n\n if (\n selectedAddress?.toLowerCase() !==\n transactionMeta.txParams.from.toLowerCase()\n ) {\n return;\n }\n\n await this.#updateAccountPositions(selectedAddress);\n },\n );\n\n this.messenger.subscribe(\n 'AccountTreeController:selectedAccountGroupChange',\n async () => {\n const selectedAddress = this.#getSelectedEvmAdress();\n\n if (!selectedAddress) {\n return;\n }\n\n await this.#updateAccountPositions(selectedAddress);\n },\n );\n\n this.#trackEvent = trackEvent;\n }\n\n async _executePoll(): Promise<void> {\n if (!this.#isEnabled()) {\n return;\n }\n\n const selectedAddress = this.#getSelectedEvmAdress();\n\n if (!selectedAddress) {\n return;\n }\n\n const accountPositions = await this.#fetchAccountPositions(selectedAddress);\n\n this.update((state) => {\n state.allDeFiPositions[selectedAddress] = accountPositions;\n });\n }\n\n async #updateAccountPositions(accountAddress: string): Promise<void> {\n if (!this.#isEnabled()) {\n return;\n }\n\n const accountPositionsPerChain =\n await this.#fetchAccountPositions(accountAddress);\n\n this.update((state) => {\n state.allDeFiPositions[accountAddress] = accountPositionsPerChain;\n });\n }\n\n async #fetchAccountPositions(\n accountAddress: string,\n ): Promise<GroupedDeFiPositionsPerChain | null> {\n try {\n const defiPositionsResponse = await this.#fetchPositions(accountAddress);\n\n const groupedDeFiPositions = groupDeFiPositions(defiPositionsResponse);\n\n try {\n this.#updatePositionsCountMetrics(groupedDeFiPositions, accountAddress);\n } catch (error) {\n console.error(\n `Failed to update positions count for account ${accountAddress}:`,\n error,\n );\n }\n\n return groupedDeFiPositions;\n } catch {\n return null;\n }\n }\n\n #updatePositionsCountMetrics(\n groupedDeFiPositions: GroupedDeFiPositionsPerChain,\n accountAddress: string,\n ) {\n // If no track event passed then skip the metrics update\n if (!this.#trackEvent) {\n return;\n }\n\n const defiMetrics = calculateDeFiPositionMetrics(groupedDeFiPositions);\n const { totalPositions } = defiMetrics.properties;\n\n if (totalPositions !== this.state.allDeFiPositionsCount[accountAddress]) {\n this.update((state) => {\n state.allDeFiPositionsCount[accountAddress] = totalPositions;\n });\n\n this.#trackEvent?.(defiMetrics);\n }\n }\n\n #getSelectedEvmAdress(): string | undefined {\n return this.messenger\n .call('AccountTreeController:getAccountsFromSelectedAccountGroup')\n .find((account: InternalAccount) => isEvmAccountType(account.type))\n ?.address;\n }\n}\n"]}
1
+ {"version":3,"file":"DeFiPositionsController.js","sourceRoot":"","sources":["../../src/DeFiPositionsController/DeFiPositionsController.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAI/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAG3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM,yBAAyB,GAAG;IAChC,cAAc;IACd,2BAA2B;CACnB,CAAC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QACnB,OAAO,IAAI,CAAC,SAAS;aAClB,IAAI,CAAC,2DAA2D,CAAC;aACjE,IAAI,CAAC,CAAC,OAAwB,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACnE,EAAE,OAAO,CAAC;IACd,CAAC;CACF","sourcesContent":["import type {\n AccountTreeControllerGetAccountsFromSelectedAccountGroupAction,\n AccountTreeControllerSelectedAccountGroupChangeEvent,\n} from '@metamask/account-tree-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { isEvmAccountType } from '@metamask/keyring-api';\nimport type { KeyringControllerLockEvent } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionControllerTransactionConfirmedEvent } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { calculateDeFiPositionMetrics } from './calculate-defi-metrics.js';\nimport type { DeFiPositionsControllerMethodActions } from './DeFiPositionsController-method-action-types.js';\nimport type { DefiPositionResponse } from './fetch-positions.js';\nimport { buildPositionFetcher } from './fetch-positions.js';\nimport { groupDeFiPositions } from './group-defi-positions.js';\nimport type { GroupedDeFiPositions } from './group-defi-positions.js';\n\nconst TEN_MINUTES_IN_MS = 600_000;\n\nconst controllerName = 'DeFiPositionsController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'startPolling',\n 'stopPollingByPollingToken',\n] as const;\n\nexport type GroupedDeFiPositionsPerChain = {\n [chain: Hex]: GroupedDeFiPositions;\n};\n\nexport type TrackingEventPayload = {\n event: string;\n category: string;\n properties: {\n totalPositions: number;\n totalMarketValueUSD: number;\n breakdown?: {\n protocolId: string;\n marketValueUSD: number;\n chainId: Hex;\n count: number;\n }[];\n };\n};\n\ntype TrackEventHook = (event: TrackingEventPayload) => void;\n\nexport type DeFiPositionsControllerState = {\n /**\n * Object containing DeFi positions per account and network\n */\n allDeFiPositions: {\n [accountAddress: string]: GroupedDeFiPositionsPerChain | null;\n };\n\n /**\n * Object containing DeFi positions count per account\n */\n allDeFiPositionsCount: {\n [accountAddress: string]: number;\n };\n};\n\nconst controllerMetadata: StateMetadata<DeFiPositionsControllerState> = {\n allDeFiPositions: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n allDeFiPositionsCount: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n};\n\nexport const getDefaultDefiPositionsControllerState =\n (): DeFiPositionsControllerState => {\n return {\n allDeFiPositions: {},\n allDeFiPositionsCount: {},\n };\n };\n\nexport type DeFiPositionsControllerActions =\n | DeFiPositionsControllerGetStateAction\n | DeFiPositionsControllerMethodActions;\n\nexport type DeFiPositionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DeFiPositionsControllerState\n>;\n\nexport type DeFiPositionsControllerEvents =\n DeFiPositionsControllerStateChangeEvent;\n\nexport type DeFiPositionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n DeFiPositionsControllerState\n >;\n\n/**\n * The external actions available to the {@link DeFiPositionsController}.\n */\nexport type AllowedActions =\n AccountTreeControllerGetAccountsFromSelectedAccountGroupAction;\n\n/**\n * The external events available to the {@link DeFiPositionsController}.\n */\nexport type AllowedEvents =\n | KeyringControllerLockEvent\n | TransactionControllerTransactionConfirmedEvent\n | AccountTreeControllerSelectedAccountGroupChangeEvent;\n\n/**\n * The messenger of the {@link DeFiPositionsController}.\n */\nexport type DeFiPositionsControllerMessenger = Messenger<\n typeof controllerName,\n DeFiPositionsControllerActions | AllowedActions,\n DeFiPositionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that stores assets and exposes convenience methods\n */\nexport class DeFiPositionsController extends StaticIntervalPollingController()<\n typeof controllerName,\n DeFiPositionsControllerState,\n DeFiPositionsControllerMessenger\n> {\n readonly #fetchPositions: (\n accountAddress: string,\n ) => Promise<DefiPositionResponse[]>;\n\n readonly #isEnabled: () => boolean;\n\n readonly #trackEvent?: TrackEventHook;\n\n /**\n * DeFiPositionsController constuctor\n *\n * @param options - Constructor options.\n * @param options.messenger - The controller messenger.\n * @param options.isEnabled - Function that returns whether the controller is enabled. (default: () => true)\n * @param options.trackEvent - Function to track events. (default: undefined)\n */\n constructor({\n messenger,\n isEnabled = () => true,\n trackEvent,\n }: {\n messenger: DeFiPositionsControllerMessenger;\n isEnabled?: () => boolean;\n trackEvent?: TrackEventHook;\n }) {\n super({\n name: controllerName,\n metadata: controllerMetadata,\n messenger,\n state: getDefaultDefiPositionsControllerState(),\n });\n\n this.setIntervalLength(TEN_MINUTES_IN_MS);\n\n this.#fetchPositions = buildPositionFetcher();\n this.#isEnabled = isEnabled;\n\n this.messenger.subscribe('KeyringController:lock', () => {\n this.stopAllPolling();\n });\n\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n async (transactionMeta) => {\n const selectedAddress = this.#getSelectedEvmAdress();\n\n if (\n selectedAddress?.toLowerCase() !==\n transactionMeta.txParams.from.toLowerCase()\n ) {\n return;\n }\n\n await this.#updateAccountPositions(selectedAddress);\n },\n );\n\n this.messenger.subscribe(\n 'AccountTreeController:selectedAccountGroupChange',\n async () => {\n const selectedAddress = this.#getSelectedEvmAdress();\n\n if (!selectedAddress) {\n return;\n }\n\n await this.#updateAccountPositions(selectedAddress);\n },\n );\n\n this.#trackEvent = trackEvent;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n async _executePoll(): Promise<void> {\n if (!this.#isEnabled()) {\n return;\n }\n\n const selectedAddress = this.#getSelectedEvmAdress();\n\n if (!selectedAddress) {\n return;\n }\n\n const accountPositions = await this.#fetchAccountPositions(selectedAddress);\n\n this.update((state) => {\n state.allDeFiPositions[selectedAddress] = accountPositions;\n });\n }\n\n async #updateAccountPositions(accountAddress: string): Promise<void> {\n if (!this.#isEnabled()) {\n return;\n }\n\n const accountPositionsPerChain =\n await this.#fetchAccountPositions(accountAddress);\n\n this.update((state) => {\n state.allDeFiPositions[accountAddress] = accountPositionsPerChain;\n });\n }\n\n async #fetchAccountPositions(\n accountAddress: string,\n ): Promise<GroupedDeFiPositionsPerChain | null> {\n try {\n const defiPositionsResponse = await this.#fetchPositions(accountAddress);\n\n const groupedDeFiPositions = groupDeFiPositions(defiPositionsResponse);\n\n try {\n this.#updatePositionsCountMetrics(groupedDeFiPositions, accountAddress);\n } catch (error) {\n console.error(\n `Failed to update positions count for account ${accountAddress}:`,\n error,\n );\n }\n\n return groupedDeFiPositions;\n } catch {\n return null;\n }\n }\n\n #updatePositionsCountMetrics(\n groupedDeFiPositions: GroupedDeFiPositionsPerChain,\n accountAddress: string,\n ) {\n // If no track event passed then skip the metrics update\n if (!this.#trackEvent) {\n return;\n }\n\n const defiMetrics = calculateDeFiPositionMetrics(groupedDeFiPositions);\n const { totalPositions } = defiMetrics.properties;\n\n if (totalPositions !== this.state.allDeFiPositionsCount[accountAddress]) {\n this.update((state) => {\n state.allDeFiPositionsCount[accountAddress] = totalPositions;\n });\n\n this.#trackEvent?.(defiMetrics);\n }\n }\n\n #getSelectedEvmAdress(): string | undefined {\n return this.messenger\n .call('AccountTreeController:getAccountsFromSelectedAccountGroup')\n .find((account: InternalAccount) => isEvmAccountType(account.type))\n ?.address;\n }\n}\n"]}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { NftController } from './NftController.js';
6
+ /**
7
+ * Checks the ownership of a ERC-721 or ERC-1155 NFT for a given address.
8
+ *
9
+ * @param ownerAddress - User public address.
10
+ * @param nftAddress - NFT contract address.
11
+ * @param tokenId - NFT token ID.
12
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
13
+ * @param options - Optional parameters.
14
+ * @param options.standard - The NFT standard ('ERC721' or 'ERC1155'). When provided, only the
15
+ * relevant ownership check is performed, halving the number of RPC subcalls.
16
+ * @returns Promise resolving the NFT ownership.
17
+ */
18
+ export type NftControllerIsNftOwnerAction = {
19
+ type: `NftController:isNftOwner`;
20
+ handler: NftController['isNftOwner'];
21
+ };
22
+ /**
23
+ * Verifies currently selected address owns entered NFT address/tokenId combo and
24
+ * adds the NFT and respective NFT contract to the stored NFT and NFT contracts lists.
25
+ *
26
+ * @param address - Hex address of the NFT contract.
27
+ * @param tokenId - The NFT identifier.
28
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
29
+ * @param options - an object of arguments
30
+ * @param options.userAddress - The address of the current user.
31
+ * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp. Defaults to `Source.Custom`; pass `Source.Detected` when refreshing existing NFTs.
32
+ */
33
+ export type NftControllerAddNftVerifyOwnershipAction = {
34
+ type: `NftController:addNftVerifyOwnership`;
35
+ handler: NftController['addNftVerifyOwnership'];
36
+ };
37
+ /**
38
+ * Adds an NFT and respective NFT contract to the stored NFT and NFT contracts lists.
39
+ *
40
+ * @param tokenAddress - Hex address of the NFT contract.
41
+ * @param tokenId - The NFT identifier.
42
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
43
+ * @param options - an object of arguments
44
+ * @param options.nftMetadata - NFT optional metadata.
45
+ * @param options.userAddress - The address of the current user.
46
+ * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp. Defaults to `Source.Custom`; pass `Source.Detected` when refreshing existing NFTs.
47
+ * @returns Promise resolving to the current NFT list.
48
+ */
49
+ export type NftControllerAddNftAction = {
50
+ type: `NftController:addNft`;
51
+ handler: NftController['addNft'];
52
+ };
53
+ /**
54
+ * Removes an NFT from the stored token list.
55
+ *
56
+ * @param address - Hex address of the NFT contract.
57
+ * @param tokenId - Token identifier of the NFT.
58
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
59
+ * @param options - an object of arguments
60
+ * @param options.userAddress - The address of the account where the NFT is being removed.
61
+ */
62
+ export type NftControllerRemoveNftAction = {
63
+ type: `NftController:removeNft`;
64
+ handler: NftController['removeNft'];
65
+ };
66
+ /**
67
+ * Removes an NFT from the stored token list and saves it in ignored NFTs list.
68
+ *
69
+ * @param address - Hex address of the NFT contract.
70
+ * @param tokenId - Token identifier of the NFT.
71
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
72
+ * @param options - an object of arguments
73
+ * @param options.userAddress - The address of the account where the NFT is being removed.
74
+ */
75
+ export type NftControllerRemoveAndIgnoreNftAction = {
76
+ type: `NftController:removeAndIgnoreNft`;
77
+ handler: NftController['removeAndIgnoreNft'];
78
+ };
79
+ /**
80
+ * Checks whether input NFT is still owned by the user
81
+ * and updates the isCurrentlyOwned value on the NFT object accordingly.
82
+ *
83
+ * @param nft - The NFT object to check and update.
84
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
85
+ * @param accountParams - The userAddress to check ownership against.
86
+ * @param accountParams.userAddress - the address passed through the confirmed transaction flow to ensure assets are stored to the correct account
87
+ * @returns the NFT with the updated isCurrentlyOwned value
88
+ */
89
+ export type NftControllerCheckAndUpdateSingleNftOwnershipStatusAction = {
90
+ type: `NftController:checkAndUpdateSingleNftOwnershipStatus`;
91
+ handler: NftController['checkAndUpdateSingleNftOwnershipStatus'];
92
+ };
93
+ /**
94
+ * Checks whether NFTs associated with current selectedAddress/chainId combination are still owned by the user
95
+ * And updates the isCurrentlyOwned value on each accordingly.
96
+ * Uses Multicall3 to batch all ownership checks into a single RPC request when available.
97
+ *
98
+ * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.
99
+ * @param options - an object of arguments
100
+ * @param options.userAddress - The address of the account where the NFT ownership status is checked/updated.
101
+ */
102
+ export type NftControllerCheckAndUpdateAllNftsOwnershipStatusAction = {
103
+ type: `NftController:checkAndUpdateAllNftsOwnershipStatus`;
104
+ handler: NftController['checkAndUpdateAllNftsOwnershipStatus'];
105
+ };
106
+ /**
107
+ * Union of all NftController action types.
108
+ */
109
+ export type NftControllerMethodActions = NftControllerIsNftOwnerAction | NftControllerAddNftVerifyOwnershipAction | NftControllerAddNftAction | NftControllerRemoveNftAction | NftControllerRemoveAndIgnoreNftAction | NftControllerCheckAndUpdateSingleNftOwnershipStatusAction | NftControllerCheckAndUpdateAllNftsOwnershipStatusAction;
110
+ //# sourceMappingURL=NftController-method-action-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NftController-method-action-types.d.ts","sourceRoot":"","sources":["../src/NftController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,aAAa,CAAC,uBAAuB,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACrC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE,sDAAsD,CAAC;IAC7D,OAAO,EAAE,aAAa,CAAC,wCAAwC,CAAC,CAAC;CAClE,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,aAAa,CAAC,sCAAsC,CAAC,CAAC;CAChE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAClC,6BAA6B,GAC7B,wCAAwC,GACxC,yBAAyB,GACzB,4BAA4B,GAC5B,qCAAqC,GACrC,yDAAyD,GACzD,uDAAuD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=NftController-method-action-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NftController-method-action-types.js","sourceRoot":"","sources":["../src/NftController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NftController } from './NftController.js';\n\n/**\n * Checks the ownership of a ERC-721 or ERC-1155 NFT for a given address.\n *\n * @param ownerAddress - User public address.\n * @param nftAddress - NFT contract address.\n * @param tokenId - NFT token ID.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - Optional parameters.\n * @param options.standard - The NFT standard ('ERC721' or 'ERC1155'). When provided, only the\n * relevant ownership check is performed, halving the number of RPC subcalls.\n * @returns Promise resolving the NFT ownership.\n */\nexport type NftControllerIsNftOwnerAction = {\n type: `NftController:isNftOwner`;\n handler: NftController['isNftOwner'];\n};\n\n/**\n * Verifies currently selected address owns entered NFT address/tokenId combo and\n * adds the NFT and respective NFT contract to the stored NFT and NFT contracts lists.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the current user.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp. Defaults to `Source.Custom`; pass `Source.Detected` when refreshing existing NFTs.\n */\nexport type NftControllerAddNftVerifyOwnershipAction = {\n type: `NftController:addNftVerifyOwnership`;\n handler: NftController['addNftVerifyOwnership'];\n};\n\n/**\n * Adds an NFT and respective NFT contract to the stored NFT and NFT contracts lists.\n *\n * @param tokenAddress - Hex address of the NFT contract.\n * @param tokenId - The NFT identifier.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.nftMetadata - NFT optional metadata.\n * @param options.userAddress - The address of the current user.\n * @param options.source - Whether the NFT was detected, added manually or suggested by a dapp. Defaults to `Source.Custom`; pass `Source.Detected` when refreshing existing NFTs.\n * @returns Promise resolving to the current NFT list.\n */\nexport type NftControllerAddNftAction = {\n type: `NftController:addNft`;\n handler: NftController['addNft'];\n};\n\n/**\n * Removes an NFT from the stored token list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\nexport type NftControllerRemoveNftAction = {\n type: `NftController:removeNft`;\n handler: NftController['removeNft'];\n};\n\n/**\n * Removes an NFT from the stored token list and saves it in ignored NFTs list.\n *\n * @param address - Hex address of the NFT contract.\n * @param tokenId - Token identifier of the NFT.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the account where the NFT is being removed.\n */\nexport type NftControllerRemoveAndIgnoreNftAction = {\n type: `NftController:removeAndIgnoreNft`;\n handler: NftController['removeAndIgnoreNft'];\n};\n\n/**\n * Checks whether input NFT is still owned by the user\n * and updates the isCurrentlyOwned value on the NFT object accordingly.\n *\n * @param nft - The NFT object to check and update.\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param accountParams - The userAddress to check ownership against.\n * @param accountParams.userAddress - the address passed through the confirmed transaction flow to ensure assets are stored to the correct account\n * @returns the NFT with the updated isCurrentlyOwned value\n */\nexport type NftControllerCheckAndUpdateSingleNftOwnershipStatusAction = {\n type: `NftController:checkAndUpdateSingleNftOwnershipStatus`;\n handler: NftController['checkAndUpdateSingleNftOwnershipStatus'];\n};\n\n/**\n * Checks whether NFTs associated with current selectedAddress/chainId combination are still owned by the user\n * And updates the isCurrentlyOwned value on each accordingly.\n * Uses Multicall3 to batch all ownership checks into a single RPC request when available.\n *\n * @param networkClientId - The networkClientId that can be used to identify the network client to use for this request.\n * @param options - an object of arguments\n * @param options.userAddress - The address of the account where the NFT ownership status is checked/updated.\n */\nexport type NftControllerCheckAndUpdateAllNftsOwnershipStatusAction = {\n type: `NftController:checkAndUpdateAllNftsOwnershipStatus`;\n handler: NftController['checkAndUpdateAllNftsOwnershipStatus'];\n};\n\n/**\n * Union of all NftController action types.\n */\nexport type NftControllerMethodActions =\n | NftControllerIsNftOwnerAction\n | NftControllerAddNftVerifyOwnershipAction\n | NftControllerAddNftAction\n | NftControllerRemoveNftAction\n | NftControllerRemoveAndIgnoreNftAction\n | NftControllerCheckAndUpdateSingleNftOwnershipStatusAction\n | NftControllerCheckAndUpdateAllNftsOwnershipStatusAction;\n"]}
@@ -9,6 +9,7 @@ import type { PreferencesControllerStateChangeEvent } from '@metamask/preference
9
9
  import type { Hex } from '@metamask/utils';
10
10
  import type { AssetsContractControllerGetERC1155TokenURIAction, AssetsContractControllerGetERC721AssetNameAction, AssetsContractControllerGetERC721AssetSymbolAction, AssetsContractControllerGetERC721TokenURIAction } from './AssetsContractController-method-action-types.js';
11
11
  import { Source } from './constants.js';
12
+ import type { NftControllerMethodActions } from './NftController-method-action-types.js';
12
13
  import type { Collection, Attributes, LastSale, TopBid } from './NftDetectionController.js';
13
14
  export type NFTStandardType = 'ERC721' | 'ERC1155';
14
15
  type SuggestedNftMeta = {
@@ -183,7 +184,7 @@ type NftAsset = {
183
184
  */
184
185
  declare const controllerName = "NftController";
185
186
  export type NftControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NftControllerState>;
186
- export type NftControllerActions = NftControllerGetStateAction;
187
+ export type NftControllerActions = NftControllerGetStateAction | NftControllerMethodActions;
187
188
  /**
188
189
  * The external actions available to the {@link NftController}.
189
190
  */
@@ -1 +1 @@
1
- {"version":3,"file":"NftController.d.ts","sourceRoot":"","sources":["../src/NftController.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,+CAA+C,EAC/C,kCAAkC,EAClC,0CAA0C,EAC3C,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,0BAA0B,EAC1B,wBAAwB,EAEzB,MAAM,2BAA2B,CAAC;AAiBnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,eAAe,EACf,mDAAmD,EACnD,2CAA2C,EAC5C,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,+BAA+B,CAAC;AAK1F,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,kCAAkC,CAAC;AAE9F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAM3C,OAAO,KAAK,EACV,gDAAgD,EAChD,gDAAgD,EAChD,kDAAkD,EAClD,+CAA+C,EAChD,MAAM,mDAAmD,CAAC;AAO3D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,KAAK,EAGV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,MAAM,EACP,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEnD,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,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ACrB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG,GACX,IAAI,CA4BN;IAED;;;;;;;OAOG;IACH,wCAAwC,CACtC,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG,GACX,OAAO,CA2BT;IAEK,gBAAgB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAsB3E;IA2CD;;OAEG;IACH,UAAU,IAAI,IAAI,CAIjB;CAuIF;eAEc,aAAa"}
@@ -37,6 +37,15 @@ const ALL_NFTS_CONTRACTS_STATE_KEY = 'allNftContracts';
37
37
  * The name of the {@link NftController}.
38
38
  */
39
39
  const controllerName = 'NftController';
40
+ const MESSENGER_EXPOSED_METHODS = [
41
+ 'addNft',
42
+ 'addNftVerifyOwnership',
43
+ 'removeAndIgnoreNft',
44
+ 'removeNft',
45
+ 'checkAndUpdateAllNftsOwnershipStatus',
46
+ 'checkAndUpdateSingleNftOwnershipStatus',
47
+ 'isNftOwner',
48
+ ];
40
49
  export const getDefaultNftControllerState = () => ({
41
50
  allNftContracts: {},
42
51
  allNfts: {},
@@ -85,6 +94,7 @@ export class NftController extends BaseController {
85
94
  this.#onNftAdded = onNftAdded;
86
95
  this.messenger.subscribe('PreferencesController:stateChange', this.#onPreferencesControllerStateChange.bind(this));
87
96
  this.messenger.subscribe('AccountsController:selectedEvmAccountChange', this.#onSelectedAccountChange.bind(this));
97
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
88
98
  }
89
99
  /**
90
100
  * Handles the state change of the preference controller.