@metamask/assets-controllers 88.0.0 → 89.0.1

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 (124) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/dist/AccountTrackerController.cjs +19 -7
  3. package/dist/AccountTrackerController.cjs.map +1 -1
  4. package/dist/AccountTrackerController.d.cts +1 -1
  5. package/dist/AccountTrackerController.d.cts.map +1 -1
  6. package/dist/AccountTrackerController.d.mts +1 -1
  7. package/dist/AccountTrackerController.d.mts.map +1 -1
  8. package/dist/AccountTrackerController.mjs +19 -7
  9. package/dist/AccountTrackerController.mjs.map +1 -1
  10. package/dist/CurrencyRateController.cjs +67 -15
  11. package/dist/CurrencyRateController.cjs.map +1 -1
  12. package/dist/CurrencyRateController.d.cts +4 -8
  13. package/dist/CurrencyRateController.d.cts.map +1 -1
  14. package/dist/CurrencyRateController.d.mts +4 -8
  15. package/dist/CurrencyRateController.d.mts.map +1 -1
  16. package/dist/CurrencyRateController.mjs +67 -15
  17. package/dist/CurrencyRateController.mjs.map +1 -1
  18. package/dist/DeFiPositionsController/DeFiPositionsController.d.cts +1 -1
  19. package/dist/DeFiPositionsController/DeFiPositionsController.d.mts +1 -1
  20. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts +1 -1
  21. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts +1 -1
  22. package/dist/NftController.cjs +0 -1
  23. package/dist/NftController.cjs.map +1 -1
  24. package/dist/NftController.d.cts.map +1 -1
  25. package/dist/NftController.d.mts.map +1 -1
  26. package/dist/NftController.mjs +0 -1
  27. package/dist/NftController.mjs.map +1 -1
  28. package/dist/NftDetectionController.cjs.map +1 -1
  29. package/dist/NftDetectionController.d.cts +5 -0
  30. package/dist/NftDetectionController.d.cts.map +1 -1
  31. package/dist/NftDetectionController.d.mts +5 -0
  32. package/dist/NftDetectionController.d.mts.map +1 -1
  33. package/dist/NftDetectionController.mjs.map +1 -1
  34. package/dist/RatesController/RatesController.cjs +3 -2
  35. package/dist/RatesController/RatesController.cjs.map +1 -1
  36. package/dist/RatesController/RatesController.d.cts +3 -0
  37. package/dist/RatesController/RatesController.d.cts.map +1 -1
  38. package/dist/RatesController/RatesController.d.mts +3 -0
  39. package/dist/RatesController/RatesController.d.mts.map +1 -1
  40. package/dist/RatesController/RatesController.mjs +3 -2
  41. package/dist/RatesController/RatesController.mjs.map +1 -1
  42. package/dist/RatesController/types.cjs.map +1 -1
  43. package/dist/RatesController/types.d.cts +1 -1
  44. package/dist/RatesController/types.d.cts.map +1 -1
  45. package/dist/RatesController/types.d.mts +1 -1
  46. package/dist/RatesController/types.d.mts.map +1 -1
  47. package/dist/RatesController/types.mjs.map +1 -1
  48. package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -1
  49. package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.cts.map +1 -1
  50. package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts.map +1 -1
  51. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
  52. package/dist/TokenBalancesController.cjs +12 -4
  53. package/dist/TokenBalancesController.cjs.map +1 -1
  54. package/dist/TokenBalancesController.d.cts +1 -1
  55. package/dist/TokenBalancesController.d.cts.map +1 -1
  56. package/dist/TokenBalancesController.d.mts +1 -1
  57. package/dist/TokenBalancesController.d.mts.map +1 -1
  58. package/dist/TokenBalancesController.mjs +12 -4
  59. package/dist/TokenBalancesController.mjs.map +1 -1
  60. package/dist/TokenDetectionController.cjs +30 -11
  61. package/dist/TokenDetectionController.cjs.map +1 -1
  62. package/dist/TokenDetectionController.d.cts +1 -1
  63. package/dist/TokenDetectionController.d.cts.map +1 -1
  64. package/dist/TokenDetectionController.d.mts +1 -1
  65. package/dist/TokenDetectionController.d.mts.map +1 -1
  66. package/dist/TokenDetectionController.mjs +31 -12
  67. package/dist/TokenDetectionController.mjs.map +1 -1
  68. package/dist/TokenListController.d.cts +1 -1
  69. package/dist/TokenListController.d.mts +1 -1
  70. package/dist/TokenRatesController.cjs +34 -52
  71. package/dist/TokenRatesController.cjs.map +1 -1
  72. package/dist/TokenRatesController.d.cts +3 -1
  73. package/dist/TokenRatesController.d.cts.map +1 -1
  74. package/dist/TokenRatesController.d.mts +3 -1
  75. package/dist/TokenRatesController.d.mts.map +1 -1
  76. package/dist/TokenRatesController.mjs +35 -53
  77. package/dist/TokenRatesController.mjs.map +1 -1
  78. package/dist/TokensController.cjs +6 -20
  79. package/dist/TokensController.cjs.map +1 -1
  80. package/dist/TokensController.d.cts +2 -0
  81. package/dist/TokensController.d.cts.map +1 -1
  82. package/dist/TokensController.d.mts +2 -0
  83. package/dist/TokensController.d.mts.map +1 -1
  84. package/dist/TokensController.mjs +6 -20
  85. package/dist/TokensController.mjs.map +1 -1
  86. package/dist/assetsUtil.cjs +2 -46
  87. package/dist/assetsUtil.cjs.map +1 -1
  88. package/dist/assetsUtil.d.cts +2 -0
  89. package/dist/assetsUtil.d.cts.map +1 -1
  90. package/dist/assetsUtil.d.mts +2 -0
  91. package/dist/assetsUtil.d.mts.map +1 -1
  92. package/dist/assetsUtil.mjs +2 -46
  93. package/dist/assetsUtil.mjs.map +1 -1
  94. package/dist/crypto-compare-service/crypto-compare.cjs +1 -8
  95. package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -1
  96. package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -1
  97. package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -1
  98. package/dist/crypto-compare-service/crypto-compare.mjs +1 -8
  99. package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
  100. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +43 -51
  101. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -1
  102. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts +6 -2
  103. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts.map +1 -1
  104. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts +6 -2
  105. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts.map +1 -1
  106. package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs +44 -52
  107. package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -1
  108. package/dist/rpc-service/rpc-balance-fetcher.cjs +1 -1
  109. package/dist/rpc-service/rpc-balance-fetcher.cjs.map +1 -1
  110. package/dist/rpc-service/rpc-balance-fetcher.d.cts +6 -2
  111. package/dist/rpc-service/rpc-balance-fetcher.d.cts.map +1 -1
  112. package/dist/rpc-service/rpc-balance-fetcher.d.mts +6 -2
  113. package/dist/rpc-service/rpc-balance-fetcher.d.mts.map +1 -1
  114. package/dist/rpc-service/rpc-balance-fetcher.mjs +1 -1
  115. package/dist/rpc-service/rpc-balance-fetcher.mjs.map +1 -1
  116. package/dist/token-prices-service/codefi-v2.cjs +2 -0
  117. package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
  118. package/dist/token-prices-service/codefi-v2.d.cts +2 -0
  119. package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
  120. package/dist/token-prices-service/codefi-v2.d.mts +2 -0
  121. package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
  122. package/dist/token-prices-service/codefi-v2.mjs +2 -0
  123. package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
  124. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"RatesController.mjs","sourceRoot":"","sources":["../../src/RatesController/RatesController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAsB,kCAAkC;AAC/E,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAGpC,OAAO,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AAQ/F,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,gCAAc,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AAoB,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,YAAY,CAAC,cAAc,CAAC,GAAG;gBAC7B,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE;gBAC1B,cAAc,EAAE,MAAM,CAAC,YAAY,CAAC;gBACpC,GAAG,CAAC,uBAAA,IAAI,uCAAgB,IAAI,EAAE,iBAAiB,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;aAC/D,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,MAAM,CACT,CAAC,KAAkC,EAAwB,EAAE;YAC3D,OAAO;gBACL,GAAG,KAAK;gBACR,KAAK,EAAE,YAAY;aACpB,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { BaseController, type StateMetadata } from '@metamask/base-controller';\nimport { Mutex } from 'async-mutex';\nimport type { Draft } from 'immer';\n\nimport { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n ConversionRates,\n RatesControllerState,\n RatesControllerOptions,\n RatesControllerMessenger,\n} from './types';\n\nexport const name = 'RatesController';\n\n/**\n * Supported cryptocurrencies that can be used as a base currency. The value needs to be compatible\n * with CryptoCompare's API which is the default source for the rates.\n *\n * See: https://min-api.cryptocompare.com/documentation?key=Price&cat=multipleSymbolsPriceEndpoint\n */\nexport enum Cryptocurrency {\n Btc = 'btc',\n Solana = 'sol',\n}\n\nconst DEFAULT_INTERVAL = 180000;\n\nconst metadata: StateMetadata<RatesControllerState> = {\n fiatCurrency: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n rates: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n cryptocurrencies: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n fiatCurrency: 'usd',\n rates: {\n [Cryptocurrency.Btc]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n [Cryptocurrency.Solana]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n },\n cryptocurrencies: [Cryptocurrency.Btc, Cryptocurrency.Solana],\n};\n\nexport class RatesController extends BaseController<\n typeof name,\n RatesControllerState,\n RatesControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #fetchMultiExchangeRate;\n\n readonly #includeUsdRate;\n\n #intervalLength: number;\n\n #intervalId: NodeJS.Timeout | undefined;\n\n /**\n * Creates a RatesController 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 messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchMultiExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n interval = DEFAULT_INTERVAL,\n messenger,\n state,\n includeUsdRate,\n fetchMultiExchangeRate = defaultFetchExchangeRate,\n }: RatesControllerOptions) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#fetchMultiExchangeRate = fetchMultiExchangeRate;\n this.#intervalLength = interval;\n }\n\n /**\n * Executes a function `callback` within a mutex lock to ensure that only one instance of `callback` runs at a time across all invocations of `#withLock`.\n * This method is useful for synchronizing access to a resource or section of code that should not be executed concurrently.\n *\n * @template R - The return type of the function `callback`.\n * @param callback - A callback to execute once the lock is acquired. This callback can be synchronous or asynchronous.\n * @returns A promise that resolves to the result of the function `callback`. The promise is fulfilled once `callback` has completed execution.\n * @example\n * async function criticalLogic() {\n * // Critical logic code goes here.\n * }\n *\n * // Execute criticalLogic within a lock.\n * const result = await this.#withLock(criticalLogic);\n */\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #withLock<R>(callback: () => R) {\n const releaseLock = await this.#mutex.acquire();\n try {\n return callback();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Executes the polling operation to update rates.\n */\n async #executePoll(): Promise<void> {\n await this.#updateRates();\n }\n\n /**\n * Updates the rates by fetching new data.\n */\n async #updateRates(): Promise<void> {\n await this.#withLock(async () => {\n const { fiatCurrency, cryptocurrencies } = this.state;\n const response: Record<\n Cryptocurrency,\n Record<string, number>\n > = await this.#fetchMultiExchangeRate(\n fiatCurrency,\n cryptocurrencies,\n this.#includeUsdRate,\n );\n\n const updatedRates: ConversionRates = {};\n for (const [cryptocurrency, values] of Object.entries(response)) {\n updatedRates[cryptocurrency] = {\n conversionDate: Date.now(),\n conversionRate: values[fiatCurrency],\n ...(this.#includeUsdRate && { usdConversionRate: values.usd }),\n };\n }\n\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n rates: updatedRates,\n };\n },\n );\n });\n }\n\n /**\n * Starts the polling process.\n */\n async start(): Promise<void> {\n if (this.#intervalId) {\n return;\n }\n\n this.messenger.publish(`${name}:pollingStarted`);\n\n await this.#updateRates();\n\n this.#intervalId = setInterval(() => {\n this.#executePoll().catch(console.error);\n }, this.#intervalLength);\n }\n\n /**\n * Stops the polling process.\n */\n async stop(): Promise<void> {\n if (!this.#intervalId) {\n return;\n }\n\n clearInterval(this.#intervalId);\n this.#intervalId = undefined;\n this.messenger.publish(`${name}:pollingStopped`);\n }\n\n /**\n * Returns the current list of cryptocurrency.\n * @returns The cryptocurrency list.\n */\n getCryptocurrencyList(): Cryptocurrency[] {\n const { cryptocurrencies } = this.state;\n return cryptocurrencies;\n }\n\n /**\n * Sets the list of supported cryptocurrencies.\n * @param cryptocurrencies - The list of supported cryptocurrencies.\n */\n async setCryptocurrencyList(\n cryptocurrencies: Cryptocurrency[],\n ): Promise<void> {\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n cryptocurrencies,\n };\n },\n );\n });\n }\n\n /**\n * Sets the internal fiat currency and update rates accordingly.\n * @param fiatCurrency - The fiat currency.\n */\n async setFiatCurrency(fiatCurrency: string): Promise<void> {\n if (fiatCurrency === '') {\n throw new Error('The currency can not be an empty string');\n }\n\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n fiatCurrency,\n };\n },\n );\n });\n await this.#updateRates();\n }\n}\n"]}
1
+ {"version":3,"file":"RatesController.mjs","sourceRoot":"","sources":["../../src/RatesController/RatesController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAsB,kCAAkC;AAC/E,OAAO,EAAE,KAAK,EAAE,oBAAoB;AASpC,OAAO,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AAE/F,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,gCAAc,CAAA;AAChB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,QAAQ,GAAwC;IACpD,YAAY,EAAE;QACZ,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,KAAK,EAAE;QACL,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,YAAY,EAAE,KAAK;IACnB,KAAK,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-controller';\nimport { Mutex } from 'async-mutex';\nimport type { Draft } from 'immer';\n\nimport type {\n ConversionRates,\n RatesControllerState,\n RatesControllerOptions,\n RatesControllerMessenger,\n} from './types';\nimport { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\n\nexport const name = 'RatesController';\n\n/**\n * Supported cryptocurrencies that can be used as a base currency. The value needs to be compatible\n * with CryptoCompare's API which is the default source for the rates.\n *\n * See: https://min-api.cryptocompare.com/documentation?key=Price&cat=multipleSymbolsPriceEndpoint\n */\nexport enum Cryptocurrency {\n Btc = 'btc',\n Solana = 'sol',\n}\n\nconst DEFAULT_INTERVAL = 180000;\n\nconst metadata: StateMetadata<RatesControllerState> = {\n fiatCurrency: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n rates: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n cryptocurrencies: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: false,\n },\n};\n\nconst defaultState = {\n fiatCurrency: 'usd',\n rates: {\n [Cryptocurrency.Btc]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n [Cryptocurrency.Solana]: {\n conversionDate: 0,\n conversionRate: 0,\n },\n },\n cryptocurrencies: [Cryptocurrency.Btc, Cryptocurrency.Solana],\n};\n\nexport class RatesController extends BaseController<\n typeof name,\n RatesControllerState,\n RatesControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #fetchMultiExchangeRate;\n\n readonly #includeUsdRate;\n\n readonly #intervalLength: number;\n\n #intervalId: NodeJS.Timeout | undefined;\n\n /**\n * Creates a RatesController 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 messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchMultiExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n interval = DEFAULT_INTERVAL,\n messenger,\n state,\n includeUsdRate,\n fetchMultiExchangeRate = defaultFetchExchangeRate,\n }: RatesControllerOptions) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.#includeUsdRate = includeUsdRate;\n this.#fetchMultiExchangeRate = fetchMultiExchangeRate;\n this.#intervalLength = interval;\n }\n\n /**\n * Executes a function `callback` within a mutex lock to ensure that only one instance of `callback` runs at a time across all invocations of `#withLock`.\n * This method is useful for synchronizing access to a resource or section of code that should not be executed concurrently.\n *\n * @template R - The return type of the function `callback`.\n * @param callback - A callback to execute once the lock is acquired. This callback can be synchronous or asynchronous.\n * @returns A promise that resolves to the result of the function `callback`. The promise is fulfilled once `callback` has completed execution.\n * @example\n * async function criticalLogic() {\n * // Critical logic code goes here.\n * }\n *\n * // Execute criticalLogic within a lock.\n * const result = await this.#withLock(criticalLogic);\n */\n async #withLock<R>(callback: () => R) {\n const releaseLock = await this.#mutex.acquire();\n try {\n return callback();\n } finally {\n releaseLock();\n }\n }\n\n /**\n * Executes the polling operation to update rates.\n */\n async #executePoll(): Promise<void> {\n await this.#updateRates();\n }\n\n /**\n * Updates the rates by fetching new data.\n */\n async #updateRates(): Promise<void> {\n await this.#withLock(async () => {\n const { fiatCurrency, cryptocurrencies } = this.state;\n const response: Record<\n Cryptocurrency,\n Record<string, number>\n > = await this.#fetchMultiExchangeRate(\n fiatCurrency,\n cryptocurrencies,\n this.#includeUsdRate,\n );\n\n const updatedRates: ConversionRates = {};\n for (const [cryptocurrency, values] of Object.entries(response)) {\n updatedRates[cryptocurrency] = {\n conversionDate: Date.now(),\n conversionRate: values[fiatCurrency],\n ...(this.#includeUsdRate && { usdConversionRate: values.usd }),\n };\n }\n\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n rates: updatedRates,\n };\n },\n );\n });\n }\n\n /**\n * Starts the polling process.\n */\n async start(): Promise<void> {\n if (this.#intervalId) {\n return;\n }\n\n this.messenger.publish(`${name}:pollingStarted`);\n\n await this.#updateRates();\n\n this.#intervalId = setInterval(() => {\n this.#executePoll().catch(console.error);\n }, this.#intervalLength);\n }\n\n /**\n * Stops the polling process.\n */\n async stop(): Promise<void> {\n if (!this.#intervalId) {\n return;\n }\n\n clearInterval(this.#intervalId);\n this.#intervalId = undefined;\n this.messenger.publish(`${name}:pollingStopped`);\n }\n\n /**\n * Returns the current list of cryptocurrency.\n *\n * @returns The cryptocurrency list.\n */\n getCryptocurrencyList(): Cryptocurrency[] {\n const { cryptocurrencies } = this.state;\n return cryptocurrencies;\n }\n\n /**\n * Sets the list of supported cryptocurrencies.\n *\n * @param cryptocurrencies - The list of supported cryptocurrencies.\n */\n async setCryptocurrencyList(\n cryptocurrencies: Cryptocurrency[],\n ): Promise<void> {\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n cryptocurrencies,\n };\n },\n );\n });\n }\n\n /**\n * Sets the internal fiat currency and update rates accordingly.\n *\n * @param fiatCurrency - The fiat currency.\n */\n async setFiatCurrency(fiatCurrency: string): Promise<void> {\n if (fiatCurrency === '') {\n throw new Error('The currency can not be an empty string');\n }\n\n await this.#withLock(() => {\n this.update(\n (state: Draft<RatesControllerState>): RatesControllerState => {\n return {\n ...state,\n fiatCurrency,\n };\n },\n );\n });\n await this.#updateRates();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = Messenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = Messenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import type { Messenger } from "@metamask/messenger";
3
- import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.cjs";
4
3
  import type { name as ratesControllerName, Cryptocurrency } from "./RatesController.cjs";
4
+ import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.cjs";
5
5
  /**
6
6
  * Represents the conversion rates from one currency to others, including the conversion date.
7
7
  * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., "BTC") to its
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AACpG,OAAO,KAAK,EACV,IAAI,IAAI,mBAAmB,EAC3B,cAAc,EACf,8BAA0B;AAE3B;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC;IACvB;;;OAGG;IACH,gBAAgB,EAAE,cAAc,EAAE,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG,0BAA0B,CACtE,OAAO,mBAAmB,EAC1B,oBAAoB,CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,GAAG,OAAO,mBAAmB,iBAAiB,CAAC;IACrD,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,M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ACpC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACtC;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,wBAAwB,CAAC;CAC1D,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import type { Messenger } from "@metamask/messenger";
3
- import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.mjs";
4
3
  import type { name as ratesControllerName, Cryptocurrency } from "./RatesController.mjs";
4
+ import type { fetchMultiExchangeRate as defaultFetchExchangeRate } from "../crypto-compare-service/index.mjs";
5
5
  /**
6
6
  * Represents the conversion rates from one currency to others, including the conversion date.
7
7
  * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., "BTC") to its
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,sBAAsB,IAAI,wBAAwB,EAAE,4CAAkC;AACpG,OAAO,KAAK,EACV,IAAI,IAAI,mBAAmB,EAC3B,cAAc,EACf,8BAA0B;AAE3B;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC;IACvB;;;OAGG;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AG,6BAA6B,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,SAAS,CAC9C,OAAO,mBAAmB,EAC1B,sBAAsB,EACtB,qBAAqB,CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,wBAAwB,CAAC;IACpC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACtC;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,wBAAwB,CAAC;CAC1D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = Messenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/RatesController/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type {\n name as ratesControllerName,\n Cryptocurrency,\n} from './RatesController';\nimport type { fetchMultiExchangeRate as defaultFetchExchangeRate } from '../crypto-compare-service';\n\n/**\n * Represents the conversion rates from one currency to others, including the conversion date.\n * The `conversionRate` field is a number that maps a cryptocurrency code (e.g., \"BTC\") to its\n * conversion rate.\n * The `usdConversionRate` provides the conversion rate to USD as a number, or `null` if the\n * conversion rate to USD is not available.\n * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.\n */\nexport type Rate = {\n conversionRate: number;\n conversionDate: number;\n usdConversionRate?: number;\n};\n\n/**\n * Represents the conversion rates for multiple cryptocurrencies.\n * Each key is a string representing the cryptocurrency symbol (e.g., \"BTC\", \"SOL\"),\n * and its value is a `Rate` object containing conversion rates from that cryptocurrency\n * to a fiat currencies and an optional USD rate.\n */\nexport type ConversionRates = Record<string, Rate>;\n\n/**\n * Represents the state structure for the RatesController.\n */\nexport type RatesControllerState = {\n /**\n * The fiat currency in which conversion rates are expressed\n * (i.e., the \"to\" currency).\n */\n fiatCurrency: string;\n /**\n * The conversion rates for multiple cryptocurrencies.\n */\n rates: ConversionRates;\n /**\n * A list of supported cryptocurrency symbols.\n * (i.e., the \"from\" currencies).\n */\n cryptocurrencies: Cryptocurrency[];\n};\n\n/**\n * Type definition for RatesController state change events.\n */\nexport type RatesControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Type definition for the RatesController polling started event.\n */\nexport type RatesControllerPollingStartedEvent = {\n type: `${typeof ratesControllerName}:pollingStarted`;\n payload: [];\n};\n\n/**\n * Type definition for the RatesController polling stopped event.\n */\nexport type RatesControllerPollingStoppedEvent = {\n type: `${typeof ratesControllerName}:pollingStopped`;\n payload: [];\n};\n\n/**\n * Defines the events that the RatesController can emit.\n */\nexport type RatesControllerEvents =\n | RatesControllerStateChangeEvent\n | RatesControllerPollingStartedEvent\n | RatesControllerPollingStoppedEvent;\n\nexport type RatesControllerGetStateAction = ControllerGetStateAction<\n typeof ratesControllerName,\n RatesControllerState\n>;\n\n/**\n * Defines the actions that can be performed to get the state of the RatesController.\n */\nexport type RatesControllerActions = RatesControllerGetStateAction;\n\n/**\n * Defines the actions that the RatesController can perform.\n */\nexport type RatesControllerMessenger = Messenger<\n typeof ratesControllerName,\n RatesControllerActions,\n RatesControllerEvents\n>;\n\n/**\n * The options required to initialize a RatesController.\n */\nexport type RatesControllerOptions = {\n /**\n * Whether to include USD rates in the conversion rates.\n */\n includeUsdRate: boolean;\n /**\n * The polling interval in milliseconds.\n */\n interval?: number;\n /**\n * The messenger instance for communication.\n */\n messenger: RatesControllerMessenger;\n /**\n * The initial state of the controller.\n */\n state?: Partial<RatesControllerState>;\n /**\n * The function to fetch exchange rates.\n */\n fetchMultiExchangeRate?: typeof defaultFetchExchangeRate;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ERC721Standard.cjs","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":";;;AAAA,wDAAoD;AAEpD,iEAOoC;AACpC,mEAAwD;AAExD,wDAA0D;AAE1D,MAAa,cAAc;IAGzB,YAAY,QAAsB;QAIlC;;;;;WAKG;QACH,sCAAiC,GAAG,KAAK,EACvC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,+CAA4B,CAC7B,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,wCAAmC,GAAG,KAAK,EACzC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,iDAA8B,CAC/B,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,qCAAgC,GAAG,KAAK,EACtC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI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I,CAAC,CAAC,GAAG,EAAE,EAAE,CAC9C,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;wBACvB,CAAC,CAAC,IAAA,gCAAmB,EAAC,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC;wBAC7C,CAAC,CAAC,GAAG,CACR,CACF;oBACH,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;YAEH,IAAI,KAAK,CAAC;YACV,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC;oBACH,MAAM,QAAQ,GAAG,MAAM,IAAA,+BAAY,EAAC,QAAQ,CAAC,CAAC;oBAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACrC,KAAK,GAAG,MAAM,EAAE,KAAK,CAAC;oBACtB,IAAI,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;wBACjC,KAAK,GAAG,MAAM,IAAA,gCAAmB,EAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;oBAC9D,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,SAAS;gBACX,CAAC;YACH,CAAC;YAED,OAAO;gBACL,QAAQ,EAAE,yBAAM;gBAChB,QAAQ;gBACR,MAAM;gBACN,IAAI;gBACJ,KAAK;aACN,CAAC;QACJ,CAAC,CAAC;QA1MA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAwGD;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,OAAe;QAC/C,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAAC,OAAO,EAAE,6BAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CAwFF;AA/MD,wCA+MC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n timeoutFetch,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC721,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { abiERC721 } from '@metamask/metamask-eth-abis';\n\nimport { getFormattedIpfsUrl } from '../../../assetsUtil';\n\nexport class ERC721Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC721Metadata interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Metadata interface.\n */\n contractSupportsMetadataInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_METADATA_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721Enumerable interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.\n */\n contractSupportsEnumerableInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_ENUMERABLE_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721 interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721 interface.\n */\n contractSupportsBase721Interface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);\n };\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getNftTokenId = async (\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.tokenOfOwnerByIndex(selectedAddress, index);\n };\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n getTokenURI = async (address: string, tokenId: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n const supportsMetadata = await this.contractSupportsMetadataInterface(\n address,\n );\n if (!supportsMetadata) {\n // Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.\n // This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).\n // As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.\n console.error('Contract does not support ERC721 metadata interface.');\n }\n return contract.tokenURI(tokenId);\n };\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n getAssetName = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.name();\n };\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n getAssetSymbol = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.symbol();\n };\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getOwnerOf(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.ownerOf(tokenId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private readonly contractSupportsInterface = async (\n address: string,\n interfaceId: string,\n ): Promise<boolean> => {\n const contract = new Contract(address, abiERC721, this.provider);\n try {\n return await contract.supportsInterface(interfaceId);\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n return false;\n }\n throw err;\n }\n };\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param ipfsGateway - The user's preferred IPFS gateway.\n * @param tokenId - tokenId of a given token in the contract.\n * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.\n */\n getDetails = async (\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n symbol: string | undefined;\n name: string | undefined;\n image: string | undefined;\n }> => {\n const isERC721 = await this.contractSupportsBase721Interface(address);\n if (!isERC721) {\n throw new Error(\"This isn't a valid ERC721 contract\");\n }\n\n const [symbol, name, tokenURI] = await Promise.all([\n safelyExecute(() => this.getAssetSymbol(address)),\n safelyExecute(() => this.getAssetName(address)),\n tokenId\n ? safelyExecute(() =>\n this.getTokenURI(address, tokenId).then((uri) =>\n uri.startsWith('ipfs://')\n ? getFormattedIpfsUrl(ipfsGateway, uri, true)\n : uri,\n ),\n )\n : undefined,\n ]);\n\n let image;\n if (tokenURI) {\n try {\n const response = await timeoutFetch(tokenURI);\n const object = await response.json();\n image = object?.image;\n if (image?.startsWith('ipfs://')) {\n image = await getFormattedIpfsUrl(ipfsGateway, image, true);\n }\n } catch {\n // ignore\n }\n }\n\n return {\n standard: ERC721,\n tokenURI,\n symbol,\n name,\n image,\n };\n };\n}\n"]}
1
+ {"version":3,"file":"ERC721Standard.cjs","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":";;;AAAA,wDAAoD;AAEpD,iEAOoC;AACpC,mEAAwD;AAExD,wDAA0D;AAE1D,MAAa,cAAc;IAGzB,YAAY,QAAsB;QAIlC;;;;;WAKG;QACH,sCAAiC,GAAG,KAAK,EACvC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,+CAA4B,CAC7B,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,wCAAmC,GAAG,KAAK,EACzC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,iDAA8B,CAC/B,CAAC;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A9MD,wCA8MC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n timeoutFetch,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC721,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { abiERC721 } from '@metamask/metamask-eth-abis';\n\nimport { getFormattedIpfsUrl } from '../../../assetsUtil';\n\nexport class ERC721Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC721Metadata interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Metadata interface.\n */\n contractSupportsMetadataInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_METADATA_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721Enumerable interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.\n */\n contractSupportsEnumerableInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_ENUMERABLE_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721 interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721 interface.\n */\n contractSupportsBase721Interface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);\n };\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getNftTokenId = async (\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.tokenOfOwnerByIndex(selectedAddress, index);\n };\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n getTokenURI = async (address: string, tokenId: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n const supportsMetadata =\n await this.contractSupportsMetadataInterface(address);\n if (!supportsMetadata) {\n // Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.\n // This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).\n // As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.\n console.error('Contract does not support ERC721 metadata interface.');\n }\n return contract.tokenURI(tokenId);\n };\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n getAssetName = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.name();\n };\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n getAssetSymbol = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.symbol();\n };\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getOwnerOf(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.ownerOf(tokenId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private readonly contractSupportsInterface = async (\n address: string,\n interfaceId: string,\n ): Promise<boolean> => {\n const contract = new Contract(address, abiERC721, this.provider);\n try {\n return await contract.supportsInterface(interfaceId);\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n return false;\n }\n throw err;\n }\n };\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param ipfsGateway - The user's preferred IPFS gateway.\n * @param tokenId - tokenId of a given token in the contract.\n * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.\n */\n getDetails = async (\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n symbol: string | undefined;\n name: string | undefined;\n image: string | undefined;\n }> => {\n const isERC721 = await this.contractSupportsBase721Interface(address);\n if (!isERC721) {\n throw new Error(\"This isn't a valid ERC721 contract\");\n }\n\n const [symbol, name, tokenURI] = await Promise.all([\n safelyExecute(() => this.getAssetSymbol(address)),\n safelyExecute(() => this.getAssetName(address)),\n tokenId\n ? safelyExecute(() =>\n this.getTokenURI(address, tokenId).then((uri) =>\n uri.startsWith('ipfs://')\n ? getFormattedIpfsUrl(ipfsGateway, uri, true)\n : uri,\n ),\n )\n : undefined,\n ]);\n\n let image;\n if (tokenURI) {\n try {\n const response = await timeoutFetch(tokenURI);\n const object = await response.json();\n image = object?.image;\n if (image?.startsWith('ipfs://')) {\n image = await getFormattedIpfsUrl(ipfsGateway, image, true);\n }\n } catch {\n // ignore\n }\n }\n\n return {\n standard: ERC721,\n tokenURI,\n symbol,\n name,\n image,\n };\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ERC721Standard.d.cts","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,iCAAiC;AAa7D,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,QAAQ,EAAE,YAAY;IAIlC;;;;;OAKG;IACH,iCAAiC,YACtB,MAAM,KACd,QAAQ,OAAO,CAAC,CAKjB;IAEF;;;;;OAKG;IACH,mCAAmC,YACxB,MAAM,KACd,QAAQ,OAAO,CAAC,CA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EF;;;;;;;OAOG;IACH,aAAa,YACF,MAAM,mBACE,MAAM,SAChB,MAAM,KACZ,QAAQ,MAAM,CAAC,CAGhB;IAEF;;;;;;OAMG;IACH,WAAW,YAAmB,MAAM,WAAW,MAAM,KAAG,QAAQ,MAAM,CAAC,CAWrE;IAEF;;;;;OAKG;IACH,YAAY,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGrD;IAEF;;;;;OAKG;IACH,cAAc,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGvD;IAEF;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAiBxC;IAEF;;;;;;;OAOG;IACH,UAAU,YACC,MAAM,eACF,MAAM,YACT,MAAM;kBAEN,MAAM;kBACN,MAAM,GAAG,SAAS;gBACpB,MAAM,GAAG,SAAS;cACpB,MAAM,GAAG,SAAS;eACjB,MAAM,GAAG,SAAS;OA0CzB;CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"ERC721Standard.d.mts","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,iCAAiC;AAa7D,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,QAAQ,EAAE,YAAY;IAIlC;;;;;OAKG;IACH,iCAAiC,YACtB,MAAM,KACd,QAAQ,OAAO,CAAC,CAKjB;IAEF;;;;;OAKG;IACH,mCAAmC,YACxB,MAAM,KACd,QAAQ,OAAO,CAAC,CAKjB;IAEF;;;;;OAKG;IACH,gCAAgC,YACrB,MAAM,KACd,QAAQ,OAAO,CAAC,CAEjB;IAEF;;;;;;;OAOG;IACH,aAAa,YACF,MAAM,mBACE,MAAM,SAChB,MAAM,KACZ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,KAAG,QAAQ,MAAM,CAAC,CAWrE;IAEF;;;;;OAKG;IACH,YAAY,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGrD;IAEF;;;;;OAKG;IACH,cAAc,YAAmB,MAAM,KAAG,QAAQ,MAAM,CAAC,CAGvD;IAEF;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKnE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAiBxC;IAEF;;;;;;;OAOG;IACH,UAAU,YACC,MAAM,eACF,MAAM,YACT,MAAM;kBAEN,MAAM;kBACN,MAAM,GAAG,SAAS;gBACpB,MAAM,GAAG,SAAS;cACpB,MAAM,GAAG,SAAS;eACjB,MAAM,GAAG,SAAS;OA0CzB;CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"ERC721Standard.mjs","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AAEpD,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,MAAM,EACN,aAAa,EACd,mCAAmC;AACpC,OAAO,EAAE,SAAS,EAAE,oCAAoC;AAExD,OAAO,EAAE,mBAAmB,EAAE,gCAA4B;AAE1D,MAAM,OAAO,cAAc;IAGzB,YAAY,QAAsB;QAIlC;;;;;WAKG;QACH,sCAAiC,GAAG,KAAK,EACvC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,4BAA4B,CAC7B,CAAC;QACJ,CAAC,CAAC;QAEF;;;;;WAKG;QACH,wCAAmC,GAAG,KAAK,EACzC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAAO,EACP,8BAA8B,CAC/B,CAAC;QACJ,CAAC,CA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CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAC9C,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;wBACvB,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC;wBAC7C,CAAC,CAAC,GAAG,CACR,CACF;oBACH,CAAC,CAAC,SAAS;aACd,CAAC,CAAC;YAEH,IAAI,KAAK,CAAC;YACV,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC;oBACH,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC;oBAC9C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACrC,KAAK,GAAG,MAAM,EAAE,KAAK,CAAC;oBACtB,IAAI,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;wBACjC,KAAK,GAAG,MAAM,mBAAmB,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;oBAC9D,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,SAAS;gBACX,CAAC;YACH,CAAC;YAED,OAAO;gBACL,QAAQ,EAAE,MAAM;gBAChB,QAAQ;gBACR,MAAM;gBACN,IAAI;gBACJ,KAAK;aACN,CAAC;QACJ,CAAC,CAAC;QA1MA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAwGD;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,OAAe;QAC/C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CAwFF","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n timeoutFetch,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC721,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { abiERC721 } from '@metamask/metamask-eth-abis';\n\nimport { getFormattedIpfsUrl } from '../../../assetsUtil';\n\nexport class ERC721Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC721Metadata interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Metadata interface.\n */\n contractSupportsMetadataInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_METADATA_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721Enumerable interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.\n */\n contractSupportsEnumerableInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_ENUMERABLE_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721 interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721 interface.\n */\n contractSupportsBase721Interface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);\n };\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getNftTokenId = async (\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.tokenOfOwnerByIndex(selectedAddress, index);\n };\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n getTokenURI = async (address: string, tokenId: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n const supportsMetadata = await this.contractSupportsMetadataInterface(\n address,\n );\n if (!supportsMetadata) {\n // Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.\n // This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).\n // As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.\n console.error('Contract does not support ERC721 metadata interface.');\n }\n return contract.tokenURI(tokenId);\n };\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n getAssetName = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.name();\n };\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n getAssetSymbol = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.symbol();\n };\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getOwnerOf(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.ownerOf(tokenId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private readonly contractSupportsInterface = async (\n address: string,\n interfaceId: string,\n ): Promise<boolean> => {\n const contract = new Contract(address, abiERC721, this.provider);\n try {\n return await contract.supportsInterface(interfaceId);\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n return false;\n }\n throw err;\n }\n };\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param ipfsGateway - The user's preferred IPFS gateway.\n * @param tokenId - tokenId of a given token in the contract.\n * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.\n */\n getDetails = async (\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n symbol: string | undefined;\n name: string | undefined;\n image: string | undefined;\n }> => {\n const isERC721 = await this.contractSupportsBase721Interface(address);\n if (!isERC721) {\n throw new Error(\"This isn't a valid ERC721 contract\");\n }\n\n const [symbol, name, tokenURI] = await Promise.all([\n safelyExecute(() => this.getAssetSymbol(address)),\n safelyExecute(() => this.getAssetName(address)),\n tokenId\n ? safelyExecute(() =>\n this.getTokenURI(address, tokenId).then((uri) =>\n uri.startsWith('ipfs://')\n ? getFormattedIpfsUrl(ipfsGateway, uri, true)\n : uri,\n ),\n )\n : undefined,\n ]);\n\n let image;\n if (tokenURI) {\n try {\n const response = await timeoutFetch(tokenURI);\n const object = await response.json();\n image = object?.image;\n if (image?.startsWith('ipfs://')) {\n image = await getFormattedIpfsUrl(ipfsGateway, image, true);\n }\n } catch {\n // ignore\n }\n }\n\n return {\n standard: ERC721,\n tokenURI,\n symbol,\n name,\n image,\n };\n };\n}\n"]}
1
+ {"version":3,"file":"ERC721Standard.mjs","sourceRoot":"","sources":["../../../../src/Standards/NftStandards/ERC721/ERC721Standard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AAEpD,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,MAAM,EACN,aAAa,EACd,mCAAmC;AACpC,OAAO,EAAE,SAAS,EAAE,oCAAoC;AAExD,OAAO,EAAE,mBAAmB,EAAE,gCAA4B;AAE1D,MAAM,OAAO,cAAc;IAGzB,YAAY,QAAsB;QAIlC;;;;;WAKG;QACH,sCAAiC,GAAG,KAAK,EACvC,OAAe,EACG,EAAE;YACpB,OAAO,IAAI,CAAC,yBAAyB,CACnC,OAA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,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CAwFF","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport {\n timeoutFetch,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC721,\n safelyExecute,\n} from '@metamask/controller-utils';\nimport { abiERC721 } from '@metamask/metamask-eth-abis';\n\nimport { getFormattedIpfsUrl } from '../../../assetsUtil';\n\nexport class ERC721Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Query if contract implements ERC721Metadata interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Metadata interface.\n */\n contractSupportsMetadataInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_METADATA_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721Enumerable interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721Enumerable interface.\n */\n contractSupportsEnumerableInterface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(\n address,\n ERC721_ENUMERABLE_INTERFACE_ID,\n );\n };\n\n /**\n * Query if contract implements ERC721 interface.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to whether the contract implements ERC721 interface.\n */\n contractSupportsBase721Interface = async (\n address: string,\n ): Promise<boolean> => {\n return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);\n };\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getNftTokenId = async (\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.tokenOfOwnerByIndex(selectedAddress, index);\n };\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n getTokenURI = async (address: string, tokenId: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n const supportsMetadata =\n await this.contractSupportsMetadataInterface(address);\n if (!supportsMetadata) {\n // Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.\n // This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).\n // As of today, ERC404 is unofficial but some people use it, the contract does not support Metadata interface, but it has the tokenURI() fct.\n console.error('Contract does not support ERC721 metadata interface.');\n }\n return contract.tokenURI(tokenId);\n };\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n getAssetName = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.name();\n };\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n getAssetSymbol = async (address: string): Promise<string> => {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.symbol();\n };\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getOwnerOf(address: string, tokenId: string): Promise<string> {\n const contract = new Contract(address, abiERC721, this.provider);\n return contract.ownerOf(tokenId);\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param interfaceId - Interface identifier.\n * @returns Promise resolving to whether the contract implements `interfaceID`.\n */\n private readonly contractSupportsInterface = async (\n address: string,\n interfaceId: string,\n ): Promise<boolean> => {\n const contract = new Contract(address, abiERC721, this.provider);\n try {\n return await contract.supportsInterface(interfaceId);\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n return false;\n }\n throw err;\n }\n };\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param ipfsGateway - The user's preferred IPFS gateway.\n * @param tokenId - tokenId of a given token in the contract.\n * @returns Promise resolving an object containing the standard, tokenURI, symbol and name of the given contract/tokenId pair.\n */\n getDetails = async (\n address: string,\n ipfsGateway: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI: string | undefined;\n symbol: string | undefined;\n name: string | undefined;\n image: string | undefined;\n }> => {\n const isERC721 = await this.contractSupportsBase721Interface(address);\n if (!isERC721) {\n throw new Error(\"This isn't a valid ERC721 contract\");\n }\n\n const [symbol, name, tokenURI] = await Promise.all([\n safelyExecute(() => this.getAssetSymbol(address)),\n safelyExecute(() => this.getAssetName(address)),\n tokenId\n ? safelyExecute(() =>\n this.getTokenURI(address, tokenId).then((uri) =>\n uri.startsWith('ipfs://')\n ? getFormattedIpfsUrl(ipfsGateway, uri, true)\n : uri,\n ),\n )\n : undefined,\n ]);\n\n let image;\n if (tokenURI) {\n try {\n const response = await timeoutFetch(tokenURI);\n const object = await response.json();\n image = object?.image;\n if (image?.startsWith('ipfs://')) {\n image = await getFormattedIpfsUrl(ipfsGateway, image, true);\n }\n } catch {\n // ignore\n }\n }\n\n return {\n standard: ERC721,\n tokenURI,\n symbol,\n name,\n image,\n };\n };\n}\n"]}
@@ -466,18 +466,26 @@ class TokenBalancesController extends (0, polling_controller_1.StaticIntervalPol
466
466
  continue;
467
467
  }
468
468
  try {
469
- const balances = await fetcher.fetch({
469
+ const result = await fetcher.fetch({
470
470
  chainIds: supportedChains,
471
471
  queryAllAccounts: queryAllAccounts ?? __classPrivateFieldGet(this, _TokenBalancesController_queryAllAccounts, "f"),
472
472
  selectedAccount: selected,
473
473
  allAccounts,
474
474
  });
475
- if (balances && balances.length > 0) {
476
- aggregated.push(...balances);
475
+ if (result.balances && result.balances.length > 0) {
476
+ aggregated.push(...result.balances);
477
477
  // Remove chains that were successfully processed
478
- const processedChains = new Set(balances.map((b) => b.chainId));
478
+ const processedChains = new Set(result.balances.map((b) => b.chainId));
479
479
  remainingChains = remainingChains.filter((chain) => !processedChains.has(chain));
480
480
  }
481
+ // Add unprocessed chains back to remainingChains for next fetcher
482
+ if (result.unprocessedChainIds &&
483
+ result.unprocessedChainIds.length > 0) {
484
+ const currentRemainingChains = remainingChains;
485
+ const chainsToAdd = result.unprocessedChainIds.filter((chainId) => supportedChains.includes(chainId) &&
486
+ !currentRemainingChains.includes(chainId));
487
+ remainingChains.push(...chainsToAdd);
488
+ }
481
489
  }
482
490
  catch (error) {
483
491
  console.warn(`Balance fetcher failed for chains ${supportedChains.join(', ')}: ${String(error)}`);