@metamask/assets-controllers 40.0.0 → 41.0.0

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 (46) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/AccountTrackerController.d.cts +4 -4
  3. package/dist/AccountTrackerController.d.mts +4 -4
  4. package/dist/CurrencyRateController.cjs +40 -58
  5. package/dist/CurrencyRateController.cjs.map +1 -1
  6. package/dist/CurrencyRateController.d.cts +15 -15
  7. package/dist/CurrencyRateController.d.cts.map +1 -1
  8. package/dist/CurrencyRateController.d.mts +15 -15
  9. package/dist/CurrencyRateController.d.mts.map +1 -1
  10. package/dist/CurrencyRateController.mjs +41 -59
  11. package/dist/CurrencyRateController.mjs.map +1 -1
  12. package/dist/RatesController/RatesController.cjs +1 -1
  13. package/dist/RatesController/RatesController.cjs.map +1 -1
  14. package/dist/RatesController/RatesController.mjs +1 -1
  15. package/dist/RatesController/RatesController.mjs.map +1 -1
  16. package/dist/RatesController/types.cjs.map +1 -1
  17. package/dist/RatesController/types.d.cts +6 -7
  18. package/dist/RatesController/types.d.cts.map +1 -1
  19. package/dist/RatesController/types.d.mts +6 -7
  20. package/dist/RatesController/types.d.mts.map +1 -1
  21. package/dist/RatesController/types.mjs.map +1 -1
  22. package/dist/TokenDetectionController.cjs +53 -14
  23. package/dist/TokenDetectionController.cjs.map +1 -1
  24. package/dist/TokenDetectionController.d.cts +4 -4
  25. package/dist/TokenDetectionController.d.cts.map +1 -1
  26. package/dist/TokenDetectionController.d.mts +4 -4
  27. package/dist/TokenDetectionController.d.mts.map +1 -1
  28. package/dist/TokenDetectionController.mjs +54 -14
  29. package/dist/TokenDetectionController.mjs.map +1 -1
  30. package/dist/TokenListController.cjs.map +1 -1
  31. package/dist/TokenListController.d.cts +5 -5
  32. package/dist/TokenListController.d.cts.map +1 -1
  33. package/dist/TokenListController.d.mts +5 -5
  34. package/dist/TokenListController.d.mts.map +1 -1
  35. package/dist/TokenListController.mjs.map +1 -1
  36. package/dist/TokenRatesController.d.cts +4 -4
  37. package/dist/TokenRatesController.d.mts +4 -4
  38. package/dist/crypto-compare-service/crypto-compare.cjs +8 -6
  39. package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -1
  40. package/dist/crypto-compare-service/crypto-compare.d.cts +1 -1
  41. package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -1
  42. package/dist/crypto-compare-service/crypto-compare.d.mts +1 -1
  43. package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -1
  44. package/dist/crypto-compare-service/crypto-compare.mjs +8 -6
  45. package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
  46. package/package.json +9 -9
@@ -18,5 +18,5 @@ export declare function fetchExchangeRate(currency: string, nativeCurrency: stri
18
18
  * @param includeUSDRate - Whether to add the USD rate to the fetch.
19
19
  * @returns Promise resolving to exchange rates for given currencies.
20
20
  */
21
- export declare function fetchMultiExchangeRate(fiatCurrency: string, cryptocurrencies: string[], includeUSDRate: boolean): Promise<Record<string, Record<string, string>>>;
21
+ export declare function fetchMultiExchangeRate(fiatCurrency: string, cryptocurrencies: string[], includeUSDRate: boolean): Promise<Record<string, Record<string, number>>>;
22
22
  //# sourceMappingURL=crypto-compare.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-compare.d.mts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAmFA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;IACT,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CA6BD;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,cAAc,EAAE,OAAO,GACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAqBjD"}
1
+ {"version":3,"file":"crypto-compare.d.mts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAoFA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;IACT,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC,CA6BD;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,cAAc,EAAE,OAAO,GACtB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAqBjD"}
@@ -28,19 +28,21 @@ function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
28
28
  }
29
29
  /**
30
30
  * Get the CryptoCompare API URL for getting the conversion rate from a given array of native currencies
31
- * to the given currency. Optionally, the conversion rate from the native currency to USD can also be
31
+ * to the given currencies. Optionally, the conversion rate from the native currency to USD can also be
32
32
  * included in the response.
33
33
  *
34
34
  * @param fsyms - The native currencies to get conversion rates for.
35
- * @param tsyms - The currency to convert to.
35
+ * @param tsyms - The currencies to convert to.
36
36
  * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be included.
37
37
  * @returns The API URL for getting the conversion rates.
38
38
  */
39
39
  function getMultiPricingURL(fsyms, tsyms, includeUSDRate = false) {
40
- const updatedTsyms = includeUSDRate && !tsyms.includes('USD') ? `${tsyms},USD` : tsyms;
40
+ const updatedTsyms = includeUSDRate && !tsyms.some((t) => t.toUpperCase() === 'USD')
41
+ ? [...tsyms, 'USD']
42
+ : tsyms;
41
43
  const params = new URLSearchParams();
42
- params.append('fsyms', fsyms);
43
- params.append('tsyms', updatedTsyms);
44
+ params.append('fsyms', fsyms.join(','));
45
+ params.append('tsyms', updatedTsyms.join(','));
44
46
  const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);
45
47
  url.search = params.toString();
46
48
  return url.toString();
@@ -99,7 +101,7 @@ export async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate
99
101
  * @returns Promise resolving to exchange rates for given currencies.
100
102
  */
101
103
  export async function fetchMultiExchangeRate(fiatCurrency, cryptocurrencies, includeUSDRate) {
102
- const url = getMultiPricingURL(Object.values(cryptocurrencies).join(','), fiatCurrency, includeUSDRate);
104
+ const url = getMultiPricingURL(cryptocurrencies, [fiatCurrency], includeUSDRate);
103
105
  const response = await handleFetch(url);
104
106
  handleErrorResponse(response);
105
107
  const rates = {};
@@ -1 +1 @@
1
- {"version":3,"file":"crypto-compare.mjs","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAEzD;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,CAAC,KAAK,EAAE,QAAQ,CAAC;IACjB,CAAC,MAAM,EAAE,SAAS,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,mCAAmC,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CACpB,eAAuB,EACvB,cAAsB,EACtB,cAAwB;IAExB,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAC9C,MAAM,IAAI,GAAG,qBAAqB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC;IACzE,OAAO,CACL,GAAG,qBAAqB,mBAAmB;QAC3C,GAAG,IAAI,UAAU,eAAe,CAAC,WAAW,EAAE,EAAE;QAChD,GAAG,cAAc,IAAI,eAAe,CAAC,WAAW,EAAE,KAAK,KAAK,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C;SAC3C,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([\n ['MNT', 'MANTLE'],\n ['OMNI', 'OMNINET'],\n]);\n\nconst CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n nativeCurrency = nativeCurrency.toUpperCase();\n const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from a given array of native currencies\n * to the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param fsyms - The native currencies to get conversion rates for.\n * @param tsyms - The currency to convert to.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be included.\n * @returns The API URL for getting the conversion rates.\n */\nfunction getMultiPricingURL(\n fsyms: string,\n tsyms: string,\n includeUSDRate = false,\n) {\n const updatedTsyms =\n includeUSDRate && !tsyms.includes('USD') ? `${tsyms},USD` : tsyms;\n\n const params = new URLSearchParams();\n params.append('fsyms', fsyms);\n params.append('tsyms', updatedTsyms);\n\n const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);\n url.search = params.toString();\n\n return url.toString();\n}\n\n/**\n * Handles an error response from the CryptoCompare API.\n * Expected error response format\n * { Response: \"Error\", Message: \"...\", HasWarning: false }\n *\n * @param json - The JSON response from the CryptoCompare API.\n * @param json.Response - The response status.\n * @param json.Message - The error message.\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\nfunction handleErrorResponse(json: { Response?: string; Message?: string }) {\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n handleErrorResponse(json);\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n\n/**\n * Fetches the exchange rates for multiple currencies.\n *\n * @param fiatCurrency - The currency of the rates (ISO 4217).\n * @param cryptocurrencies - The cryptocurrencies to get conversion rates for. Min length: 1. Max length: 300.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rates for given currencies.\n */\nexport async function fetchMultiExchangeRate(\n fiatCurrency: string,\n cryptocurrencies: string[],\n includeUSDRate: boolean,\n): Promise<Record<string, Record<string, string>>> {\n const url = getMultiPricingURL(\n Object.values(cryptocurrencies).join(','),\n fiatCurrency,\n includeUSDRate,\n );\n const response = await handleFetch(url);\n handleErrorResponse(response);\n\n const rates: Record<string, Record<string, string>> = {};\n for (const [cryptocurrency, values] of Object.entries(response) as [\n string,\n Record<string, string>,\n ][]) {\n rates[cryptocurrency.toLowerCase()] = {\n [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],\n ...(includeUSDRate && { usd: values.USD }),\n };\n }\n\n return rates;\n}\n"]}
1
+ {"version":3,"file":"crypto-compare.mjs","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAEzD;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,CAAC,KAAK,EAAE,QAAQ,CAAC;IACjB,CAAC,MAAM,EAAE,SAAS,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,mCAAmC,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CACpB,eAAuB,EACvB,cAAsB,EACtB,cAAwB;IAExB,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAC9C,MAAM,IAAI,GAAG,qBAAqB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC;IACzE,OAAO,CACL,GAAG,qBAAqB,mBAAmB;QAC3C,GAAG,IAAI,UAAU,eAAe,CAAC,WAAW,EAAE,EAAE;QAChD,GAAG,cAAc,IAAI,eAAe,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAC7E,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SA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ACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\n/**\n * A map from native currency symbol to CryptoCompare identifier.\n * This is only needed when the values don't match.\n */\nconst nativeSymbolOverrides = new Map([\n ['MNT', 'MANTLE'],\n ['OMNI', 'OMNINET'],\n]);\n\nconst CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from the given native currency to\n * the given currency. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param currentCurrency - The currency to get a conversion rate for.\n * @param nativeCurrency - The native currency to convert from.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be\n * included in the response as well.\n * @returns The API URL for getting the conversion rate.\n */\nfunction getPricingURL(\n currentCurrency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n) {\n nativeCurrency = nativeCurrency.toUpperCase();\n const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\n return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${fsym}&tsyms=${currentCurrency.toUpperCase()}` +\n `${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`\n );\n}\n\n/**\n * Get the CryptoCompare API URL for getting the conversion rate from a given array of native currencies\n * to the given currencies. Optionally, the conversion rate from the native currency to USD can also be\n * included in the response.\n *\n * @param fsyms - The native currencies to get conversion rates for.\n * @param tsyms - The currencies to convert to.\n * @param includeUSDRate - Whether or not the native currency to USD conversion rate should be included.\n * @returns The API URL for getting the conversion rates.\n */\nfunction getMultiPricingURL(\n fsyms: string[],\n tsyms: string[],\n includeUSDRate = false,\n) {\n const updatedTsyms =\n includeUSDRate && !tsyms.some((t) => t.toUpperCase() === 'USD')\n ? [...tsyms, 'USD']\n : tsyms;\n\n const params = new URLSearchParams();\n params.append('fsyms', fsyms.join(','));\n params.append('tsyms', updatedTsyms.join(','));\n\n const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);\n url.search = params.toString();\n return url.toString();\n}\n\n/**\n * Handles an error response from the CryptoCompare API.\n * Expected error response format\n * { Response: \"Error\", Message: \"...\", HasWarning: false }\n *\n * @param json - The JSON response from the CryptoCompare API.\n * @param json.Response - The response status.\n * @param json.Message - The error message.\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\nfunction handleErrorResponse(json: { Response?: string; Message?: string }) {\n if (json.Response === 'Error') {\n throw new Error(json.Message);\n }\n}\n\n/**\n * Fetches the exchange rate for a given currency.\n *\n * @param currency - ISO 4217 currency code.\n * @param nativeCurrency - Symbol for base asset.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rate for given currency.\n */\nexport async function fetchExchangeRate(\n currency: string,\n nativeCurrency: string,\n includeUSDRate?: boolean,\n): Promise<{\n conversionRate: number;\n usdConversionRate: number;\n}> {\n const json = await handleFetch(\n getPricingURL(currency, nativeCurrency, includeUSDRate),\n );\n\n handleErrorResponse(json);\n const conversionRate = Number(json[currency.toUpperCase()]);\n\n const usdConversionRate = Number(json.USD);\n if (!Number.isFinite(conversionRate)) {\n throw new Error(\n `Invalid response for ${currency.toUpperCase()}: ${\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);\n }\n\n return {\n conversionRate,\n usdConversionRate,\n };\n}\n\n/**\n * Fetches the exchange rates for multiple currencies.\n *\n * @param fiatCurrency - The currency of the rates (ISO 4217).\n * @param cryptocurrencies - The cryptocurrencies to get conversion rates for. Min length: 1. Max length: 300.\n * @param includeUSDRate - Whether to add the USD rate to the fetch.\n * @returns Promise resolving to exchange rates for given currencies.\n */\nexport async function fetchMultiExchangeRate(\n fiatCurrency: string,\n cryptocurrencies: string[],\n includeUSDRate: boolean,\n): Promise<Record<string, Record<string, number>>> {\n const url = getMultiPricingURL(\n cryptocurrencies,\n [fiatCurrency],\n includeUSDRate,\n );\n const response = await handleFetch(url);\n handleErrorResponse(response);\n\n const rates: Record<string, Record<string, number>> = {};\n for (const [cryptocurrency, values] of Object.entries(response) as [\n string,\n Record<string, number>,\n ][]) {\n rates[cryptocurrency.toLowerCase()] = {\n [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],\n ...(includeUSDRate && { usd: values.USD }),\n };\n }\n\n return rates;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/assets-controllers",
3
- "version": "40.0.0",
3
+ "version": "41.0.0",
4
4
  "description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -53,12 +53,12 @@
53
53
  "@ethersproject/contracts": "^5.7.0",
54
54
  "@ethersproject/providers": "^5.7.0",
55
55
  "@metamask/abi-utils": "^2.0.3",
56
- "@metamask/base-controller": "^7.0.1",
56
+ "@metamask/base-controller": "^7.0.2",
57
57
  "@metamask/contract-metadata": "^2.4.0",
58
- "@metamask/controller-utils": "^11.4.0",
58
+ "@metamask/controller-utils": "^11.4.2",
59
59
  "@metamask/eth-query": "^4.0.0",
60
60
  "@metamask/metamask-eth-abis": "^3.1.1",
61
- "@metamask/polling-controller": "^12.0.0",
61
+ "@metamask/polling-controller": "^12.0.1",
62
62
  "@metamask/rpc-errors": "^7.0.1",
63
63
  "@metamask/utils": "^10.0.0",
64
64
  "@types/bn.js": "^5.1.5",
@@ -73,14 +73,14 @@
73
73
  "uuid": "^8.3.2"
74
74
  },
75
75
  "devDependencies": {
76
- "@metamask/accounts-controller": "^18.2.2",
77
- "@metamask/approval-controller": "^7.1.0",
76
+ "@metamask/accounts-controller": "^18.2.3",
77
+ "@metamask/approval-controller": "^7.1.1",
78
78
  "@metamask/auto-changelog": "^3.4.4",
79
79
  "@metamask/ethjs-provider-http": "^0.3.0",
80
80
  "@metamask/keyring-api": "^8.1.3",
81
- "@metamask/keyring-controller": "^17.3.0",
82
- "@metamask/network-controller": "^22.0.0",
83
- "@metamask/preferences-controller": "^13.1.0",
81
+ "@metamask/keyring-controller": "^17.3.1",
82
+ "@metamask/network-controller": "^22.0.1",
83
+ "@metamask/preferences-controller": "^13.2.0",
84
84
  "@types/jest": "^27.4.1",
85
85
  "@types/lodash": "^4.14.191",
86
86
  "@types/node": "^16.18.54",