@metamask-previews/assets-controllers 51.0.2-preview-edbe12d8 → 51.0.2-preview-4a9b4a93
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.
- package/CHANGELOG.md +4 -0
- package/dist/Standards/ERC20Standard.cjs +1 -1
- package/dist/Standards/ERC20Standard.cjs.map +1 -1
- package/dist/Standards/ERC20Standard.mjs +3 -3
- package/dist/Standards/ERC20Standard.mjs.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.cjs +5 -3
- package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -1
- package/dist/crypto-compare-service/crypto-compare.mjs +5 -3
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Bump `@ethereumjs/util` from `^8.1.0` to `^9.1.0` ([#5347](https://github.com/MetaMask/core/pull/5347))
|
|
13
|
+
|
|
10
14
|
## [51.0.2]
|
|
11
15
|
|
|
12
16
|
### Fixed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ERC20Standard.cjs","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ERC20Standard.cjs","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAC/C,wDAAoD;AAEpD,mDAAmD;AACnD,iEAAmD;AACnD,mEAAuD;AACvD,2CAAsE;AAGtE,kDAAoD;AAEpD,MAAa,aAAa;IAGxB,YAAY,QAAsB;QAChC,I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AAW,CAAC,CAAC,CAAC,CAAC,SAAS;SAClE,CAAC,CAAC;QACH,OAAO;YACL,QAAQ;YACR,MAAM;YACN,OAAO;YACP,QAAQ,EAAE,wBAAK;SAChB,CAAC;IACJ,CAAC;CACF;AAhID,sCAgIC","sourcesContent":["import { bytesToUtf8 } from '@ethereumjs/util';\nimport { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport { decodeSingle } from '@metamask/abi-utils';\nimport { ERC20 } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { assertIsStrictHexString, hexToBytes } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { ethersBigNumberToBN } from '../assetsUtil';\n\nexport class ERC20Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Get balance or count for current account on specific asset contract.\n *\n * @param address - Asset ERC20 contract address.\n * @param selectedAddress - Current account public address.\n * @returns Promise resolving to BN object containing balance for current account on specific asset contract.\n */\n async getBalanceOf(address: string, selectedAddress: string): Promise<BN> {\n const contract = new Contract(address, abiERC20, this.provider);\n const balance = await contract.balanceOf(selectedAddress);\n return ethersBigNumberToBN(balance);\n }\n\n /**\n * Query for the decimals for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'decimals'.\n */\n async getTokenDecimals(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const decimals = await contract.decimals();\n return decimals.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token decimals');\n }\n throw err;\n }\n }\n\n /**\n * Query for the name for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'name'.\n */\n async getTokenName(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const name = await contract.name();\n return name.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token name');\n }\n throw err;\n }\n }\n\n /**\n * Query for symbol for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n async getTokenSymbol(address: string): Promise<string> {\n // Signature for calling `symbol()`\n const payload = { to: address, data: '0x95d89b41' };\n const result = await this.provider.call(payload);\n assertIsStrictHexString(result);\n // Parse as string - treat empty string as failure\n try {\n const decoded = decodeSingle('string', result);\n if (decoded?.length > 0) {\n return decoded;\n }\n } catch {\n // Ignore error\n }\n\n // Parse as bytes - treat empty string as failure\n try {\n const utf8 = bytesToUtf8(hexToBytes(result));\n if (utf8.length > 0) {\n return utf8;\n }\n } catch {\n // Ignore error\n }\n\n throw new Error('Failed to parse token symbol');\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param userAddress - The public address for the currently active user's account.\n * @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.\n */\n async getDetails(\n address: string,\n userAddress?: string,\n ): Promise<{\n standard: string;\n symbol: string | undefined;\n decimals: string | undefined;\n balance: BN | undefined;\n }> {\n const [decimals, symbol, balance] = await Promise.all([\n this.getTokenDecimals(address),\n this.getTokenSymbol(address),\n userAddress ? this.getBalanceOf(address, userAddress) : undefined,\n ]);\n return {\n decimals,\n symbol,\n balance,\n standard: ERC20,\n };\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bytesToUtf8 } from "@ethereumjs/util";
|
|
2
2
|
import { Contract } from "@ethersproject/contracts";
|
|
3
3
|
import { decodeSingle } from "@metamask/abi-utils";
|
|
4
4
|
import { ERC20 } from "@metamask/controller-utils";
|
|
5
5
|
import { abiERC20 } from "@metamask/metamask-eth-abis";
|
|
6
|
-
import { assertIsStrictHexString } from "@metamask/utils";
|
|
6
|
+
import { assertIsStrictHexString, hexToBytes } from "@metamask/utils";
|
|
7
7
|
import { ethersBigNumberToBN } from "../assetsUtil.mjs";
|
|
8
8
|
export class ERC20Standard {
|
|
9
9
|
constructor(provider) {
|
|
@@ -86,7 +86,7 @@ export class ERC20Standard {
|
|
|
86
86
|
}
|
|
87
87
|
// Parse as bytes - treat empty string as failure
|
|
88
88
|
try {
|
|
89
|
-
const utf8 =
|
|
89
|
+
const utf8 = bytesToUtf8(hexToBytes(result));
|
|
90
90
|
if (utf8.length > 0) {
|
|
91
91
|
return utf8;
|
|
92
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ERC20Standard.mjs","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ERC20Standard.mjs","sourceRoot":"","sources":["../../src/Standards/ERC20Standard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,yBAAyB;AAC/C,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AAEpD,OAAO,EAAE,YAAY,EAAE,4BAA4B;AACnD,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AACvD,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,wBAAwB;AAGtE,OAAO,EAAE,mBAAmB,EAAE,0BAAsB;AAEpD,MAAM,OAAO,aAAa;IAGxB,YAAY,QAAsB;QAChC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,eAAuB;QACzD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChE,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QAC1D,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAA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IAAI,CAAC,OAAO,CAAC,CAAC;QACjD,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAChC,kDAAkD;QAClD,IAAI;YACF,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,OAAO,EAAE,MAAM,GAAG,CAAC,EAAE;gBACvB,OAAO,OAAO,CAAC;aAChB;SACF;QAAC,MAAM;YACN,eAAe;SAChB;QAED,iDAAiD;QACjD,IAAI;YACF,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;YAC7C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnB,OAAO,IAAI,CAAC;aACb;SACF;QAAC,MAAM;YACN,eAAe;SAChB;QAED,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CACd,OAAe,EACf,WAAoB;QAOpB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACpD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAC9B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAC5B,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;SAClE,CAAC,CAAC;QACH,OAAO;YACL,QAAQ;YACR,MAAM;YACN,OAAO;YACP,QAAQ,EAAE,KAAK;SAChB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { bytesToUtf8 } from '@ethereumjs/util';\nimport { Contract } from '@ethersproject/contracts';\nimport type { Web3Provider } from '@ethersproject/providers';\nimport { decodeSingle } from '@metamask/abi-utils';\nimport { ERC20 } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { assertIsStrictHexString, hexToBytes } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { ethersBigNumberToBN } from '../assetsUtil';\n\nexport class ERC20Standard {\n private readonly provider: Web3Provider;\n\n constructor(provider: Web3Provider) {\n this.provider = provider;\n }\n\n /**\n * Get balance or count for current account on specific asset contract.\n *\n * @param address - Asset ERC20 contract address.\n * @param selectedAddress - Current account public address.\n * @returns Promise resolving to BN object containing balance for current account on specific asset contract.\n */\n async getBalanceOf(address: string, selectedAddress: string): Promise<BN> {\n const contract = new Contract(address, abiERC20, this.provider);\n const balance = await contract.balanceOf(selectedAddress);\n return ethersBigNumberToBN(balance);\n }\n\n /**\n * Query for the decimals for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'decimals'.\n */\n async getTokenDecimals(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const decimals = await contract.decimals();\n return decimals.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token decimals');\n }\n throw err;\n }\n }\n\n /**\n * Query for the name for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract string.\n * @returns Promise resolving to the 'name'.\n */\n async getTokenName(address: string): Promise<string> {\n const contract = new Contract(address, abiERC20, this.provider);\n try {\n const name = await contract.name();\n return name.toString();\n } catch (err) {\n // Mirror previous implementation\n if (\n err instanceof Error &&\n err.message.includes('call revert exception')\n ) {\n throw new Error('Failed to parse token name');\n }\n throw err;\n }\n }\n\n /**\n * Query for symbol for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n async getTokenSymbol(address: string): Promise<string> {\n // Signature for calling `symbol()`\n const payload = { to: address, data: '0x95d89b41' };\n const result = await this.provider.call(payload);\n assertIsStrictHexString(result);\n // Parse as string - treat empty string as failure\n try {\n const decoded = decodeSingle('string', result);\n if (decoded?.length > 0) {\n return decoded;\n }\n } catch {\n // Ignore error\n }\n\n // Parse as bytes - treat empty string as failure\n try {\n const utf8 = bytesToUtf8(hexToBytes(result));\n if (utf8.length > 0) {\n return utf8;\n }\n } catch {\n // Ignore error\n }\n\n throw new Error('Failed to parse token symbol');\n }\n\n /**\n * Query if a contract implements an interface.\n *\n * @param address - Asset contract address.\n * @param userAddress - The public address for the currently active user's account.\n * @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair.\n */\n async getDetails(\n address: string,\n userAddress?: string,\n ): Promise<{\n standard: string;\n symbol: string | undefined;\n decimals: string | undefined;\n balance: BN | undefined;\n }> {\n const [decimals, symbol, balance] = await Promise.all([\n this.getTokenDecimals(address),\n this.getTokenSymbol(address),\n userAddress ? this.getBalanceOf(address, userAddress) : undefined,\n ]);\n return {\n decimals,\n symbol,\n balance,\n standard: ERC20,\n };\n }\n}\n"]}
|
|
@@ -24,10 +24,8 @@ const CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';
|
|
|
24
24
|
* @returns The API URL for getting the conversion rate.
|
|
25
25
|
*/
|
|
26
26
|
function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
|
|
27
|
-
nativeCurrency = nativeCurrency.toUpperCase();
|
|
28
|
-
const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
|
|
29
27
|
return (`${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +
|
|
30
|
-
`${
|
|
28
|
+
`${nativeCurrency}&tsyms=${currentCurrency}` +
|
|
31
29
|
`${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`);
|
|
32
30
|
}
|
|
33
31
|
/**
|
|
@@ -76,6 +74,10 @@ function handleErrorResponse(json) {
|
|
|
76
74
|
* @returns Promise resolving to exchange rate for given currency.
|
|
77
75
|
*/
|
|
78
76
|
async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate) {
|
|
77
|
+
currency = currency.toUpperCase();
|
|
78
|
+
nativeCurrency = nativeCurrency.toUpperCase();
|
|
79
|
+
currency = nativeSymbolOverrides.get(currency) ?? currency;
|
|
80
|
+
nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
|
|
79
81
|
const json = await (0, controller_utils_1.handleFetch)(getPricingURL(currency, nativeCurrency, includeUSDRate));
|
|
80
82
|
handleErrorResponse(json);
|
|
81
83
|
const conversionRate = Number(json[currency.toUpperCase()]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-compare.cjs","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":";;;AAAA,iEAAyD;AAEzD,kDAA8C;AAE9C;;;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,
|
|
1
|
+
{"version":3,"file":"crypto-compare.cjs","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":";;;AAAA,iEAAyD;AAEzD,kDAA8C;AAE9C;;;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,OAAO,CACL,GAAG,qBAAqB,mBAAmB;QAC3C,GAAG,cAAc,UAAU,eAAe,EAAE;QAC5C,GAAG,cAAc,IAAI,eAAe,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,C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tE,MAAM,QAAQ,GAAG,MAAM,IAAA,8BAAW,EAAC,GAAG,CAAC,CAAC;IACxC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAE9B,MAAM,KAAK,GAA2C,EAAE,CAAC;IACzD,KAAK,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAG3D,EAAE;QACH,MAAM,GAAG,GAAG,IAAA,0BAAa,EAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;QACjE,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,cAAc,CAAC,WAAW,EAAE,CAAC,GAAG;YAC1D,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAChE,GAAG,CAAC,cAAc,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;SAC3C,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA1BD,wDA0BC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getKeyByValue } from '../assetsUtil';\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 return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${nativeCurrency}&tsyms=${currentCurrency}` +\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 currency = currency.toUpperCase();\n nativeCurrency = nativeCurrency.toUpperCase();\n currency = nativeSymbolOverrides.get(currency) ?? currency;\n nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\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 fsyms = cryptocurrencies.map(\n (nativeCurrency) =>\n nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency,\n );\n const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);\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 const key = getKeyByValue(nativeSymbolOverrides, cryptocurrency);\n rates[key?.toLowerCase() ?? cryptocurrency.toLowerCase()] = {\n [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],\n ...(includeUSDRate && { usd: values.USD }),\n };\n }\n\n return rates;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-compare.d.cts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto-compare.d.cts","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,CAkCD;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,CAsBjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-compare.d.mts","sourceRoot":"","sources":["../../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":"
|
|
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,CAkCD;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,CAsBjD"}
|
|
@@ -21,10 +21,8 @@ const CRYPTO_COMPARE_DOMAIN = 'https://min-api.cryptocompare.com';
|
|
|
21
21
|
* @returns The API URL for getting the conversion rate.
|
|
22
22
|
*/
|
|
23
23
|
function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
|
|
24
|
-
nativeCurrency = nativeCurrency.toUpperCase();
|
|
25
|
-
const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
|
|
26
24
|
return (`${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +
|
|
27
|
-
`${
|
|
25
|
+
`${nativeCurrency}&tsyms=${currentCurrency}` +
|
|
28
26
|
`${includeUSDRate && currentCurrency.toUpperCase() !== 'USD' ? ',USD' : ''}`);
|
|
29
27
|
}
|
|
30
28
|
/**
|
|
@@ -73,6 +71,10 @@ function handleErrorResponse(json) {
|
|
|
73
71
|
* @returns Promise resolving to exchange rate for given currency.
|
|
74
72
|
*/
|
|
75
73
|
export async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate) {
|
|
74
|
+
currency = currency.toUpperCase();
|
|
75
|
+
nativeCurrency = nativeCurrency.toUpperCase();
|
|
76
|
+
currency = nativeSymbolOverrides.get(currency) ?? currency;
|
|
77
|
+
nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
|
|
76
78
|
const json = await handleFetch(getPricingURL(currency, nativeCurrency, includeUSDRate));
|
|
77
79
|
handleErrorResponse(json);
|
|
78
80
|
const conversionRate = Number(json[currency.toUpperCase()]);
|
|
@@ -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,OAAO,EAAE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AC,GAAG,EAAE,WAAW,EAAE,IAAI,cAAc,CAAC,WAAW,EAAE,CAAC,GAAG;YAC1D,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAChE,GAAG,CAAC,cAAc,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;SAC3C,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getKeyByValue } from '../assetsUtil';\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 return (\n `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=` +\n `${nativeCurrency}&tsyms=${currentCurrency}` +\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 currency = currency.toUpperCase();\n nativeCurrency = nativeCurrency.toUpperCase();\n currency = nativeSymbolOverrides.get(currency) ?? currency;\n nativeCurrency = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;\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 fsyms = cryptocurrencies.map(\n (nativeCurrency) =>\n nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency,\n );\n const url = getMultiPricingURL(fsyms, [fiatCurrency], includeUSDRate);\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 const key = getKeyByValue(nativeSymbolOverrides, cryptocurrency);\n rates[key?.toLowerCase() ?? 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-previews/assets-controllers",
|
|
3
|
-
"version": "51.0.2-preview-
|
|
3
|
+
"version": "51.0.2-preview-4a9b4a93",
|
|
4
4
|
"description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@ethereumjs/util": "^
|
|
50
|
+
"@ethereumjs/util": "^9.1.0",
|
|
51
51
|
"@ethersproject/abi": "^5.7.0",
|
|
52
52
|
"@ethersproject/address": "^5.7.0",
|
|
53
53
|
"@ethersproject/bignumber": "^5.7.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@metamask/auto-changelog": "^3.4.4",
|
|
83
83
|
"@metamask/ethjs-provider-http": "^0.3.0",
|
|
84
84
|
"@metamask/keyring-controller": "^19.2.1",
|
|
85
|
-
"@metamask/keyring-internal-api": "^
|
|
85
|
+
"@metamask/keyring-internal-api": "^5.0.0",
|
|
86
86
|
"@metamask/keyring-snap-client": "^4.0.1",
|
|
87
87
|
"@metamask/network-controller": "^22.2.1",
|
|
88
88
|
"@metamask/permission-controller": "^11.0.6",
|