@metamask/assets-controllers 29.0.0 → 30.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.
- package/CHANGELOG.md +25 -1
- package/README.md +29 -0
- package/dist/AssetsContractController.js +6 -6
- package/dist/AssetsContractController.mjs +5 -5
- package/dist/CurrencyRateController.js +4 -3
- package/dist/CurrencyRateController.mjs +3 -2
- package/dist/NftController.js +3 -3
- package/dist/NftController.mjs +2 -2
- package/dist/NftDetectionController.js +2 -2
- package/dist/NftDetectionController.mjs +1 -1
- package/dist/RatesController/RatesController.js +14 -0
- package/dist/RatesController/RatesController.mjs +14 -0
- package/dist/RatesController/index.js +13 -0
- package/dist/RatesController/index.js.map +1 -0
- package/dist/RatesController/index.mjs +13 -0
- package/dist/RatesController/index.mjs.map +1 -0
- package/dist/RatesController/types.js +1 -0
- package/dist/RatesController/types.js.map +1 -0
- package/dist/RatesController/types.mjs +1 -0
- package/dist/RatesController/types.mjs.map +1 -0
- package/dist/Standards/ERC20Standard.js +3 -3
- package/dist/Standards/ERC20Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +2 -2
- package/dist/TokenDetectionController.js +3 -3
- package/dist/TokenDetectionController.mjs +2 -2
- package/dist/TokenListController.js +4 -4
- package/dist/TokenListController.mjs +3 -3
- package/dist/TokenRatesController.js +6 -4
- package/dist/TokenRatesController.mjs +5 -3
- package/dist/TokensController.js +6 -6
- package/dist/TokensController.mjs +5 -5
- package/dist/assetsUtil.js +2 -2
- package/dist/assetsUtil.mjs +1 -1
- package/dist/{chunk-OHSQRYVL.js → chunk-3R43XIIX.js} +17 -6
- package/dist/chunk-3R43XIIX.js.map +1 -0
- package/dist/{chunk-S6CZP74C.mjs → chunk-46UZDIXW.mjs} +35 -12
- package/dist/chunk-46UZDIXW.mjs.map +1 -0
- package/dist/{chunk-QHU4H6HP.js → chunk-4ODKGWYQ.js} +7 -7
- package/dist/{chunk-DEQZ35QE.js → chunk-5F5EQAX5.js} +7 -7
- package/dist/{chunk-IOQX3VTD.js → chunk-6W5EQ3JQ.js} +56 -42
- package/dist/chunk-6W5EQ3JQ.js.map +1 -0
- package/dist/chunk-7K6PSEAA.js +1 -0
- package/dist/chunk-7K6PSEAA.js.map +1 -0
- package/dist/{chunk-6XOM7KOQ.mjs → chunk-7MMEHAKG.mjs} +7 -7
- package/dist/{chunk-V46CHMOU.mjs → chunk-ASA5RLBY.mjs} +2 -2
- package/dist/chunk-B5YVX5IO.mjs +202 -0
- package/dist/chunk-B5YVX5IO.mjs.map +1 -0
- package/dist/{chunk-BO2WZDUM.js → chunk-B5YY22QQ.js} +3 -3
- package/dist/{chunk-QWACHXRH.mjs → chunk-B6W4CQOR.mjs} +2 -2
- package/dist/chunk-B6W4CQOR.mjs.map +1 -0
- package/dist/{chunk-3ZHN4GFT.js → chunk-BOTVAG4A.js} +5 -5
- package/dist/chunk-CNKVITJO.mjs +66 -0
- package/dist/chunk-CNKVITJO.mjs.map +1 -0
- package/dist/{chunk-LLYYJY7H.mjs → chunk-D3K5MPMW.mjs} +2 -2
- package/dist/{chunk-LRKDZWS6.js → chunk-ELSMS5S7.js} +3 -3
- package/dist/chunk-ELSMS5S7.js.map +1 -0
- package/dist/{chunk-X2MMIBYW.js → chunk-FMZML3V5.js} +7 -5
- package/dist/chunk-FMZML3V5.js.map +1 -0
- package/dist/{chunk-I53XGBU3.js → chunk-HDI4L2DD.js} +5 -5
- package/dist/chunk-JYHAAA6W.mjs +1 -0
- package/dist/chunk-JYHAAA6W.mjs.map +1 -0
- package/dist/{chunk-ASFD56OL.mjs → chunk-KOKB6U4Z.mjs} +7 -5
- package/dist/{chunk-ASFD56OL.mjs.map → chunk-KOKB6U4Z.mjs.map} +1 -1
- package/dist/{chunk-KM3J4DO6.js → chunk-LAU6ZDZR.js} +37 -14
- package/dist/chunk-LAU6ZDZR.js.map +1 -0
- package/dist/{chunk-S7UA2DU7.mjs → chunk-LZ5ZGQEX.mjs} +2 -2
- package/dist/{chunk-SOK5YX7I.js → chunk-MBCN3MNX.js} +11 -11
- package/dist/{chunk-5MRF7YPD.mjs → chunk-MHN7CJCZ.mjs} +6 -6
- package/dist/{chunk-D3PCUDTX.mjs → chunk-MR6EF4B7.mjs} +2 -2
- package/dist/{chunk-LS6R3HQL.js → chunk-NEXY7SE2.js} +2 -2
- package/dist/chunk-NEXY7SE2.js.map +1 -0
- package/dist/{chunk-X5PLVMOQ.mjs → chunk-Q5JRBGWO.mjs} +2 -2
- package/dist/chunk-Q5JRBGWO.mjs.map +1 -0
- package/dist/chunk-TTH3ES66.mjs +1 -0
- package/dist/chunk-TTH3ES66.mjs.map +1 -0
- package/dist/{chunk-OBOWNEJU.js → chunk-U3DJJN4X.js} +4 -4
- package/dist/chunk-WB6KJX4N.js +66 -0
- package/dist/chunk-WB6KJX4N.js.map +1 -0
- package/dist/{chunk-OWTCG2N3.mjs → chunk-X4FFNQHE.mjs} +53 -39
- package/dist/chunk-X4FFNQHE.mjs.map +1 -0
- package/dist/chunk-XC3SOOGC.js +1 -0
- package/dist/chunk-XC3SOOGC.js.map +1 -0
- package/dist/{chunk-RUE635TV.mjs → chunk-XHMM35YT.mjs} +3 -3
- package/dist/{chunk-OSEZFHQ3.mjs → chunk-Y35SM7TO.mjs} +19 -14
- package/dist/chunk-Y35SM7TO.mjs.map +1 -0
- package/dist/chunk-YIFA2HXH.js +202 -0
- package/dist/chunk-YIFA2HXH.js.map +1 -0
- package/dist/{chunk-NXGX7LZJ.mjs → chunk-Z3OQU4XW.mjs} +17 -6
- package/dist/chunk-Z3OQU4XW.mjs.map +1 -0
- package/dist/{chunk-4FMVFW2T.js → chunk-Z6TBQQE5.js} +20 -15
- package/dist/chunk-Z6TBQQE5.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.js +10 -0
- package/dist/crypto-compare-service/crypto-compare.js.map +1 -0
- package/dist/crypto-compare-service/crypto-compare.mjs +10 -0
- package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -0
- package/dist/crypto-compare-service/index.js +11 -0
- package/dist/crypto-compare-service/index.js.map +1 -0
- package/dist/crypto-compare-service/index.mjs +11 -0
- package/dist/crypto-compare-service/index.mjs.map +1 -0
- package/dist/index.js +24 -16
- package/dist/index.mjs +25 -17
- package/dist/token-prices-service/codefi-v2.js +4 -2
- package/dist/token-prices-service/codefi-v2.mjs +5 -3
- package/dist/token-prices-service/index.js +2 -2
- package/dist/token-prices-service/index.mjs +1 -1
- package/dist/token-service.js +3 -3
- package/dist/token-service.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/CurrencyRateController.d.ts +1 -1
- package/dist/types/CurrencyRateController.d.ts.map +1 -1
- package/dist/types/NftController.d.ts +3 -3
- package/dist/types/NftController.d.ts.map +1 -1
- package/dist/types/NftDetectionController.d.ts.map +1 -1
- package/dist/types/RatesController/RatesController.d.ts +44 -0
- package/dist/types/RatesController/RatesController.d.ts.map +1 -0
- package/dist/types/RatesController/index.d.ts +3 -0
- package/dist/types/RatesController/index.d.ts.map +1 -0
- package/dist/types/RatesController/types.d.ts +100 -0
- package/dist/types/RatesController/types.d.ts.map +1 -0
- package/dist/types/TokenRatesController.d.ts +26 -4
- package/dist/types/TokenRatesController.d.ts.map +1 -1
- package/dist/types/TokensController.d.ts +1 -1
- package/dist/types/TokensController.d.ts.map +1 -1
- package/dist/types/crypto-compare-service/crypto-compare.d.ts +22 -0
- package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +1 -0
- package/dist/types/crypto-compare-service/index.d.ts +2 -0
- package/dist/types/crypto-compare-service/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts +18 -0
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +1 -1
- package/dist/types/token-prices-service/codefi-v2.d.ts +7 -0
- package/dist/types/token-prices-service/codefi-v2.d.ts.map +1 -1
- package/dist/types/token-service.d.ts +1 -1
- package/dist/types/token-service.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-4FMVFW2T.js.map +0 -1
- package/dist/chunk-DYH5P3VY.js +0 -35
- package/dist/chunk-DYH5P3VY.js.map +0 -1
- package/dist/chunk-IOQX3VTD.js.map +0 -1
- package/dist/chunk-KM3J4DO6.js.map +0 -1
- package/dist/chunk-LRKDZWS6.js.map +0 -1
- package/dist/chunk-LS6R3HQL.js.map +0 -1
- package/dist/chunk-NXGX7LZJ.mjs.map +0 -1
- package/dist/chunk-OHSQRYVL.js.map +0 -1
- package/dist/chunk-OSEZFHQ3.mjs.map +0 -1
- package/dist/chunk-OWTCG2N3.mjs.map +0 -1
- package/dist/chunk-PWZE6KJV.mjs +0 -35
- package/dist/chunk-PWZE6KJV.mjs.map +0 -1
- package/dist/chunk-QWACHXRH.mjs.map +0 -1
- package/dist/chunk-S6CZP74C.mjs.map +0 -1
- package/dist/chunk-X2MMIBYW.js.map +0 -1
- package/dist/chunk-X5PLVMOQ.mjs.map +0 -1
- package/dist/crypto-compare.js +0 -8
- package/dist/crypto-compare.mjs +0 -8
- package/dist/types/crypto-compare.d.ts +0 -13
- package/dist/types/crypto-compare.d.ts.map +0 -1
- /package/dist/{crypto-compare.js.map → RatesController/RatesController.js.map} +0 -0
- /package/dist/{crypto-compare.mjs.map → RatesController/RatesController.mjs.map} +0 -0
- /package/dist/{chunk-QHU4H6HP.js.map → chunk-4ODKGWYQ.js.map} +0 -0
- /package/dist/{chunk-DEQZ35QE.js.map → chunk-5F5EQAX5.js.map} +0 -0
- /package/dist/{chunk-6XOM7KOQ.mjs.map → chunk-7MMEHAKG.mjs.map} +0 -0
- /package/dist/{chunk-V46CHMOU.mjs.map → chunk-ASA5RLBY.mjs.map} +0 -0
- /package/dist/{chunk-BO2WZDUM.js.map → chunk-B5YY22QQ.js.map} +0 -0
- /package/dist/{chunk-3ZHN4GFT.js.map → chunk-BOTVAG4A.js.map} +0 -0
- /package/dist/{chunk-LLYYJY7H.mjs.map → chunk-D3K5MPMW.mjs.map} +0 -0
- /package/dist/{chunk-I53XGBU3.js.map → chunk-HDI4L2DD.js.map} +0 -0
- /package/dist/{chunk-S7UA2DU7.mjs.map → chunk-LZ5ZGQEX.mjs.map} +0 -0
- /package/dist/{chunk-SOK5YX7I.js.map → chunk-MBCN3MNX.js.map} +0 -0
- /package/dist/{chunk-5MRF7YPD.mjs.map → chunk-MHN7CJCZ.mjs.map} +0 -0
- /package/dist/{chunk-D3PCUDTX.mjs.map → chunk-MR6EF4B7.mjs.map} +0 -0
- /package/dist/{chunk-OBOWNEJU.js.map → chunk-U3DJJN4X.js.map} +0 -0
- /package/dist/{chunk-RUE635TV.mjs.map → chunk-XHMM35YT.mjs.map} +0 -0
|
@@ -65,7 +65,7 @@ var formatIconUrlWithProxy = ({
|
|
|
65
65
|
tokenAddress
|
|
66
66
|
}) => {
|
|
67
67
|
const chainIdDecimal = convertHexToDecimal(chainId).toString();
|
|
68
|
-
return `https://static.
|
|
68
|
+
return `https://static.cx.metamask.io/api/v1/tokenIcons/${chainIdDecimal}/${tokenAddress.toLowerCase()}.png`;
|
|
69
69
|
};
|
|
70
70
|
var SupportedTokenDetectionNetworks = /* @__PURE__ */ ((SupportedTokenDetectionNetworks2) => {
|
|
71
71
|
SupportedTokenDetectionNetworks2["mainnet"] = "0x1";
|
|
@@ -206,4 +206,4 @@ export {
|
|
|
206
206
|
reduceInBatchesSerially,
|
|
207
207
|
fetchTokenContractExchangeRates
|
|
208
208
|
};
|
|
209
|
-
//# sourceMappingURL=chunk-
|
|
209
|
+
//# sourceMappingURL=chunk-Q5JRBGWO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/assetsUtil.ts"],"sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport {\n convertHexToDecimal,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { CID } from 'multiformats/cid';\n\nimport type { Nft, NftMetadata } from './NftController';\nimport type { AbstractTokenPricesService } from './token-prices-service';\nimport { type ContractExchangeRates } from './TokenRatesController';\n\n/**\n * The maximum number of token addresses that should be sent to the Price API in\n * a single request.\n */\nexport const TOKEN_PRICES_BATCH_SIZE = 30;\n\n/**\n * Compares nft metadata entries to any nft entry.\n * We need this method when comparing a new fetched nft metadata, in case a entry changed to a defined value,\n * there's a need to update the nft in state.\n *\n * @param newNftMetadata - Nft metadata object.\n * @param nft - Nft object to compare with.\n * @returns Whether there are differences.\n */\nexport function compareNftMetadata(newNftMetadata: NftMetadata, nft: Nft) {\n const keys: (keyof NftMetadata)[] = [\n 'image',\n 'backgroundColor',\n 'imagePreview',\n 'imageThumbnail',\n 'imageOriginal',\n 'animation',\n 'animationOriginal',\n 'externalLink',\n 'tokenURI',\n ];\n const differentValues = keys.reduce((value, key) => {\n if (newNftMetadata[key] && newNftMetadata[key] !== nft[key]) {\n return value + 1;\n }\n return value;\n }, 0);\n return differentValues > 0;\n}\n\nconst aggregatorNameByKey: Record<string, string> = {\n aave: 'Aave',\n bancor: 'Bancor',\n cmc: 'CMC',\n cryptocom: 'Crypto.com',\n coinGecko: 'CoinGecko',\n oneInch: '1inch',\n paraswap: 'Paraswap',\n pmm: 'PMM',\n zapper: 'Zapper',\n zerion: 'Zerion',\n zeroEx: '0x',\n synthetix: 'Synthetix',\n yearn: 'Yearn',\n apeswap: 'ApeSwap',\n binanceDex: 'BinanceDex',\n pancakeTop100: 'PancakeTop100',\n pancakeExtended: 'PancakeExtended',\n balancer: 'Balancer',\n quickswap: 'QuickSwap',\n matcha: 'Matcha',\n pangolinDex: 'PangolinDex',\n pangolinDexStableCoin: 'PangolinDexStableCoin',\n pangolinDexAvaxBridge: 'PangolinDexAvaxBridge',\n traderJoe: 'TraderJoe',\n airswapLight: 'AirswapLight',\n kleros: 'Kleros',\n};\n\n/**\n * Formats aggregator names to presentable format.\n *\n * @param aggregators - List of token list names in camelcase.\n * @returns Formatted aggregator names.\n */\nexport const formatAggregatorNames = (aggregators: string[]) => {\n return aggregators.map(\n (key) =>\n aggregatorNameByKey[key] ||\n `${key[0].toUpperCase()}${key.substring(1, key.length)}`,\n );\n};\n\n/**\n * Format token list assets to use image proxy from Codefi.\n *\n * @param params - Object that contains chainID and tokenAddress.\n * @param params.chainId - ChainID of network in 0x-prefixed hexadecimal format.\n * @param params.tokenAddress - Address of token in mixed or lowercase.\n * @returns Formatted image url\n */\nexport const formatIconUrlWithProxy = ({\n chainId,\n tokenAddress,\n}: {\n chainId: Hex;\n tokenAddress: string;\n}) => {\n const chainIdDecimal = convertHexToDecimal(chainId).toString();\n return `https://static.cx.metamask.io/api/v1/tokenIcons/${chainIdDecimal}/${tokenAddress.toLowerCase()}.png`;\n};\n\n/**\n * Networks where token detection is supported - Values are in hex format\n */\nexport enum SupportedTokenDetectionNetworks {\n mainnet = '0x1', // decimal: 1\n bsc = '0x38', // decimal: 56\n polygon = '0x89', // decimal: 137\n avax = '0xa86a', // decimal: 43114\n aurora = '0x4e454152', // decimal: 1313161554\n linea_goerli = '0xe704', // decimal: 59140\n linea_mainnet = '0xe708', // decimal: 59144\n arbitrum = '0xa4b1', // decimal: 42161\n optimism = '0xa', // decimal: 10\n base = '0x2105', // decimal: 8453\n zksync = '0x144', // decimal: 324\n cronos = '0x19', // decimal: 25\n celo = '0xa4ec', // decimal: 42220\n gnosis = '0x64', // decimal: 100\n fantom = '0xfa', // decimal: 250\n polygon_zkevm = '0x44d', // decimal: 1101\n moonbeam = '0x504', // decimal: 1284\n moonriver = '0x505', // decimal: 1285\n}\n\n/**\n * Check if token detection is enabled for certain networks.\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports token detection\n */\nexport function isTokenDetectionSupportedForNetwork(chainId: Hex): boolean {\n return Object.values<Hex>(SupportedTokenDetectionNetworks).includes(chainId);\n}\n\n/**\n * Check if token list polling is enabled for a given network.\n * Currently this method is used to support e2e testing for consumers of this package.\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports tokenlists\n */\nexport function isTokenListSupportedForNetwork(chainId: Hex): boolean {\n return isTokenDetectionSupportedForNetwork(chainId);\n}\n\n/**\n * Removes IPFS protocol prefix from input string.\n *\n * @param ipfsUrl - An IPFS url (e.g. ipfs://{content id})\n * @returns IPFS content identifier and (possibly) path in a string\n * @throws Will throw if the url passed is not IPFS.\n */\nexport function removeIpfsProtocolPrefix(ipfsUrl: string) {\n if (ipfsUrl.startsWith('ipfs://ipfs/')) {\n return ipfsUrl.replace('ipfs://ipfs/', '');\n } else if (ipfsUrl.startsWith('ipfs://')) {\n return ipfsUrl.replace('ipfs://', '');\n }\n // this method should not be used with non-ipfs urls (i.e. startsWith('ipfs://') === true)\n throw new Error('this method should not be used with non ipfs urls');\n}\n\n/**\n * Extracts content identifier and path from an input string.\n *\n * @param ipfsUrl - An IPFS URL minus the IPFS protocol prefix\n * @returns IFPS content identifier (cid) and sub path as string.\n * @throws Will throw if the url passed is not ipfs.\n */\nexport function getIpfsCIDv1AndPath(ipfsUrl: string): {\n cid: string;\n path?: string;\n} {\n const url = removeIpfsProtocolPrefix(ipfsUrl);\n\n // check if there is a path\n // (CID is everything preceding first forward slash, path is everything after)\n const index = url.indexOf('/');\n const cid = index !== -1 ? url.substring(0, index) : url;\n const path = index !== -1 ? url.substring(index) : undefined;\n\n // We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)\n // because most cid v0s appear to be incompatible with IPFS subdomains\n return {\n cid: CID.parse(cid).toV1().toString(),\n path,\n };\n}\n\n/**\n * Formats URL correctly for use retrieving assets hosted on IPFS.\n *\n * @param ipfsGateway - The users preferred IPFS gateway (full URL or just host).\n * @param ipfsUrl - The IFPS URL pointed at the asset.\n * @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.\n * @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.\n */\nexport function getFormattedIpfsUrl(\n ipfsGateway: string,\n ipfsUrl: string,\n subdomainSupported: boolean,\n): string {\n const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));\n if (subdomainSupported) {\n const { cid, path } = getIpfsCIDv1AndPath(ipfsUrl);\n return `${protocol}//${cid}.ipfs.${host}${path ?? ''}`;\n }\n const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);\n return `${origin}/ipfs/${cidAndPath}`;\n}\n\n/**\n * Adds URL protocol prefix to input URL string if missing.\n *\n * @param urlString - An IPFS URL.\n * @returns A URL with a https:// prepended.\n */\nexport function addUrlProtocolPrefix(urlString: string): string {\n if (!urlString.match(/(^http:\\/\\/)|(^https:\\/\\/)/u)) {\n return `https://${urlString}`;\n }\n return urlString;\n}\n\n/**\n * Converts an Ethers BigNumber to a BN.\n *\n * @param bigNumber - An Ethers BigNumber instance.\n * @returns A BN object.\n */\nexport function ethersBigNumberToBN(bigNumber: BigNumber): BN {\n return new BN(remove0x(bigNumber.toHexString()), 'hex');\n}\n\n/**\n * Partitions a list of values into groups that are at most `batchSize` in\n * length.\n *\n * @param values - The list of values.\n * @param args - The remaining arguments.\n * @param args.batchSize - The desired maximum number of values per batch.\n * @returns The list of batches.\n */\nexport function divideIntoBatches<Value>(\n values: Value[],\n { batchSize }: { batchSize: number },\n): Value[][] {\n const batches = [];\n for (let i = 0; i < values.length; i += batchSize) {\n batches.push(values.slice(i, i + batchSize));\n }\n return batches;\n}\n\n/**\n * Constructs an object from processing batches of the given values\n * sequentially.\n *\n * @param args - The arguments to this function.\n * @param args.values - A list of values to iterate over.\n * @param args.batchSize - The maximum number of values in each batch.\n * @param args.eachBatch - A function to call for each batch. This function is\n * similar to the function that `Array.prototype.reduce` takes, in that it\n * receives the object that is being built, each batch in the list of batches\n * and the index, and should return an updated version of the object.\n * @param args.initialResult - The initial value of the final data structure,\n * i.e., the value that will be fed into the first call of `eachBatch`.\n * @returns The built object.\n */\nexport async function reduceInBatchesSerially<\n Value,\n Result extends Record<PropertyKey, unknown>,\n>({\n values,\n batchSize,\n eachBatch,\n initialResult,\n}: {\n values: Value[];\n batchSize: number;\n eachBatch: (\n workingResult: Partial<Result>,\n batch: Value[],\n index: number,\n ) => Partial<Result> | Promise<Partial<Result>>;\n initialResult: Partial<Result>;\n}): Promise<Result> {\n const batches = divideIntoBatches(values, { batchSize });\n let workingResult = initialResult;\n for (const [index, batch] of batches.entries()) {\n workingResult = await eachBatch(workingResult, batch, index);\n }\n // There's no way around this — we have to assume that in the end, the result\n // matches the intended type.\n const finalResult = workingResult as Result;\n return finalResult;\n}\n\n/**\n * Retrieves token prices for a set of contract addresses in a specific currency and chainId.\n *\n * @param args - The arguments to function.\n * @param args.tokenPricesService - An object in charge of retrieving token prices.\n * @param args.nativeCurrency - The native currency to request price in.\n * @param args.tokenAddresses - The list of contract addresses.\n * @param args.chainId - The chainId of the tokens.\n * @returns The prices for the requested tokens.\n */\nexport async function fetchTokenContractExchangeRates({\n tokenPricesService,\n nativeCurrency,\n tokenAddresses,\n chainId,\n}: {\n tokenPricesService: AbstractTokenPricesService;\n nativeCurrency: string;\n tokenAddresses: Hex[];\n chainId: Hex;\n}): Promise<ContractExchangeRates> {\n const isChainIdSupported =\n tokenPricesService.validateChainIdSupported(chainId);\n const isCurrencySupported =\n tokenPricesService.validateCurrencySupported(nativeCurrency);\n\n if (!isChainIdSupported || !isCurrencySupported) {\n return {};\n }\n\n const tokenPricesByTokenAddress = await reduceInBatchesSerially<\n Hex,\n Awaited<ReturnType<AbstractTokenPricesService['fetchTokenPrices']>>\n >({\n values: [...tokenAddresses].sort(),\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n eachBatch: async (allTokenPricesByTokenAddress, batch) => {\n const tokenPricesByTokenAddressForBatch =\n await tokenPricesService.fetchTokenPrices({\n tokenAddresses: batch,\n chainId,\n currency: nativeCurrency,\n });\n\n return {\n ...allTokenPricesByTokenAddress,\n ...tokenPricesByTokenAddressForBatch,\n };\n },\n initialResult: {},\n });\n\n return Object.entries(tokenPricesByTokenAddress).reduce(\n (obj, [tokenAddress, tokenPrice]) => {\n return {\n ...obj,\n [toChecksumHexAddress(tokenAddress)]: tokenPrice?.value,\n };\n },\n {},\n );\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AACf,SAAS,WAAW;AAUb,IAAM,0BAA0B;AAWhC,SAAS,mBAAmB,gBAA6B,KAAU;AACxE,QAAM,OAA8B;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,kBAAkB,KAAK,OAAO,CAAC,OAAO,QAAQ;AAClD,QAAI,eAAe,GAAG,KAAK,eAAe,GAAG,MAAM,IAAI,GAAG,GAAG;AAC3D,aAAO,QAAQ;AAAA,IACjB;AACA,WAAO;AAAA,EACT,GAAG,CAAC;AACJ,SAAO,kBAAkB;AAC3B;AAEA,IAAM,sBAA8C;AAAA,EAClD,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,WAAW;AAAA,EACX,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AAAA,EACV,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,uBAAuB;AAAA,EACvB,uBAAuB;AAAA,EACvB,WAAW;AAAA,EACX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AAkB,QAAQ,EAAE,UAAU,CAAC;AACvD,MAAI,gBAAgB;AACpB,aAAW,CAAC,OAAO,KAAK,KAAK,QAAQ,QAAQ,GAAG;AAC9C,oBAAgB,MAAM,UAAU,eAAe,OAAO,KAAK;AAAA,EAC7D;AAGA,QAAM,cAAc;AACpB,SAAO;AACT;AAYA,eAAsB,gCAAgC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKmC;AACjC,QAAM,qBACJ,mBAAmB,yBAAyB,OAAO;AACrD,QAAM,sBACJ,mBAAmB,0BAA0B,cAAc;AAE7D,MAAI,CAAC,sBAAsB,CAAC,qBAAqB;AAC/C,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,4BAA4B,MAAM,wBAGtC;AAAA,IACA,QAAQ,CAAC,GAAG,cAAc,EAAE,KAAK;AAAA,IACjC,WAAW;AAAA,IACX,WAAW,OAAO,8BAA8B,UAAU;AACxD,YAAM,oCACJ,MAAM,mBAAmB,iBAAiB;AAAA,QACxC,gBAAgB;AAAA,QAChB;AAAA,QACA,UAAU;AAAA,MACZ,CAAC;AAEH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,IACF;AAAA,IACA,eAAe,CAAC;AAAA,EAClB,CAAC;AAED,SAAO,OAAO,QAAQ,yBAAyB,EAAE;AAAA,IAC/C,CAAC,KAAK,CAAC,cAAc,UAAU,MAAM;AACnC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,qBAAqB,YAAY,CAAC,GAAG,YAAY;AAAA,MACpD;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":["SupportedTokenDetectionNetworks"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-TTH3ES66.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNEXY7SE2js = require('./chunk-NEXY7SE2.js');
|
|
4
4
|
|
|
5
5
|
// src/Standards/NftStandards/ERC721/ERC721Standard.ts
|
|
6
6
|
var _contracts = require('@ethersproject/contracts');
|
|
@@ -133,7 +133,7 @@ var ERC721Standard = class {
|
|
|
133
133
|
_controllerutils.safelyExecute.call(void 0, () => this.getAssetName(address)),
|
|
134
134
|
tokenId ? _controllerutils.safelyExecute.call(void 0,
|
|
135
135
|
() => this.getTokenURI(address, tokenId).then(
|
|
136
|
-
(uri) => uri.startsWith("ipfs://") ?
|
|
136
|
+
(uri) => uri.startsWith("ipfs://") ? _chunkNEXY7SE2js.getFormattedIpfsUrl.call(void 0, ipfsGateway, uri, true) : uri
|
|
137
137
|
)
|
|
138
138
|
) : void 0
|
|
139
139
|
]);
|
|
@@ -144,7 +144,7 @@ var ERC721Standard = class {
|
|
|
144
144
|
const object = await response.json();
|
|
145
145
|
image = object?.image;
|
|
146
146
|
if (image?.startsWith("ipfs://")) {
|
|
147
|
-
image =
|
|
147
|
+
image = _chunkNEXY7SE2js.getFormattedIpfsUrl.call(void 0, ipfsGateway, image, true);
|
|
148
148
|
}
|
|
149
149
|
} catch {
|
|
150
150
|
}
|
|
@@ -175,4 +175,4 @@ var ERC721Standard = class {
|
|
|
175
175
|
|
|
176
176
|
|
|
177
177
|
exports.ERC721Standard = ERC721Standard;
|
|
178
|
-
//# sourceMappingURL=chunk-
|
|
178
|
+
//# sourceMappingURL=chunk-U3DJJN4X.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/crypto-compare-service/crypto-compare.ts
|
|
2
|
+
var _controllerutils = require('@metamask/controller-utils');
|
|
3
|
+
var nativeSymbolOverrides = /* @__PURE__ */ new Map([["MNT", "MANTLE"]]);
|
|
4
|
+
var CRYPTO_COMPARE_DOMAIN = "https://min-api.cryptocompare.com";
|
|
5
|
+
function getPricingURL(currentCurrency, nativeCurrency, includeUSDRate) {
|
|
6
|
+
nativeCurrency = nativeCurrency.toUpperCase();
|
|
7
|
+
const fsym = nativeSymbolOverrides.get(nativeCurrency) ?? nativeCurrency;
|
|
8
|
+
return `${CRYPTO_COMPARE_DOMAIN}/data/price?fsym=${fsym}&tsyms=${currentCurrency.toUpperCase()}${includeUSDRate && currentCurrency.toUpperCase() !== "USD" ? ",USD" : ""}`;
|
|
9
|
+
}
|
|
10
|
+
function getMultiPricingURL(fsyms, tsyms, includeUSDRate = false) {
|
|
11
|
+
const updatedTsyms = includeUSDRate && !tsyms.includes("USD") ? `${tsyms},USD` : tsyms;
|
|
12
|
+
const params = new URLSearchParams();
|
|
13
|
+
params.append("fsyms", fsyms);
|
|
14
|
+
params.append("tsyms", updatedTsyms);
|
|
15
|
+
const url = new URL(`${CRYPTO_COMPARE_DOMAIN}/data/pricemulti`);
|
|
16
|
+
url.search = params.toString();
|
|
17
|
+
return url.toString();
|
|
18
|
+
}
|
|
19
|
+
function handleErrorResponse(json) {
|
|
20
|
+
if (json.Response === "Error") {
|
|
21
|
+
throw new Error(json.Message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function fetchExchangeRate(currency, nativeCurrency, includeUSDRate) {
|
|
25
|
+
const json = await _controllerutils.handleFetch.call(void 0,
|
|
26
|
+
getPricingURL(currency, nativeCurrency, includeUSDRate)
|
|
27
|
+
);
|
|
28
|
+
handleErrorResponse(json);
|
|
29
|
+
const conversionRate = Number(json[currency.toUpperCase()]);
|
|
30
|
+
const usdConversionRate = Number(json.USD);
|
|
31
|
+
if (!Number.isFinite(conversionRate)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Invalid response for ${currency.toUpperCase()}: ${json[currency.toUpperCase()]}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (includeUSDRate && !Number.isFinite(usdConversionRate)) {
|
|
37
|
+
throw new Error(`Invalid response for usdConversionRate: ${json.USD}`);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
conversionRate,
|
|
41
|
+
usdConversionRate
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async function fetchMultiExchangeRate(fiatCurrency, cryptocurrencies, includeUSDRate) {
|
|
45
|
+
const url = getMultiPricingURL(
|
|
46
|
+
Object.values(cryptocurrencies).join(","),
|
|
47
|
+
fiatCurrency,
|
|
48
|
+
includeUSDRate
|
|
49
|
+
);
|
|
50
|
+
const response = await _controllerutils.handleFetch.call(void 0, url);
|
|
51
|
+
handleErrorResponse(response);
|
|
52
|
+
const rates = {};
|
|
53
|
+
for (const [cryptocurrency, values] of Object.entries(response)) {
|
|
54
|
+
rates[cryptocurrency.toLowerCase()] = {
|
|
55
|
+
[fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],
|
|
56
|
+
...includeUSDRate && { usd: values.USD }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return rates;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
exports.fetchExchangeRate = fetchExchangeRate; exports.fetchMultiExchangeRate = fetchMultiExchangeRate;
|
|
66
|
+
//# sourceMappingURL=chunk-WB6KJX4N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/crypto-compare-service/crypto-compare.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAM5B,IAAM,wBAAwB,oBAAI,IAAI,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEzD,IAAM,wBAAwB;AAa9B,SAAS,cACP,iBACA,gBACA,gBACA;AACA,mBAAiB,eAAe,YAAY;AAC5C,QAAM,OAAO,sBAAsB,IAAI,cAAc,KAAK;AAC1D,SACE,GAAG,qBAAqB,oBACrB,IAAI,UAAU,gBAAgB,YAAY,CAAC,GAC3C,kBAAkB,gBAAgB,YAAY,MAAM,QA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,CAAC;AACvD,aAAW,CAAC,gBAAgB,MAAM,KAAK,OAAO,QAAQ,QAAQ,GAGzD;AACH,UAAM,eAAe,YAAY,CAAC,IAAI;AAAA,MACpC,CAAC,aAAa,YAAY,CAAC,GAAG,OAAO,aAAa,YAAY,CAAC;AAAA,MAC/D,GAAI,kBAAkB,EAAE,KAAK,OAAO,IAAI;AAAA,IAC1C;AAAA,EACF;AAEA,SAAO;AACT","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([['MNT', 'MANTLE']]);\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 */\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 json[currency.toUpperCase()]\n }`,\n );\n }\n\n if (includeUSDRate && !Number.isFinite(usdConversionRate)) {\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,10 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ZERO_ADDRESS
|
|
3
|
+
} from "./chunk-Y35SM7TO.mjs";
|
|
1
4
|
import {
|
|
2
5
|
fetchExchangeRate
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CNKVITJO.mjs";
|
|
4
7
|
import {
|
|
5
8
|
TOKEN_PRICES_BATCH_SIZE,
|
|
6
9
|
reduceInBatchesSerially
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-Q5JRBGWO.mjs";
|
|
8
11
|
import {
|
|
9
12
|
__privateAdd,
|
|
10
13
|
__privateGet,
|
|
@@ -154,8 +157,7 @@ var TokenRatesController = class extends StaticIntervalPollingControllerV1 {
|
|
|
154
157
|
allDetectedTokens: {}
|
|
155
158
|
};
|
|
156
159
|
this.defaultState = {
|
|
157
|
-
|
|
158
|
-
contractExchangeRatesByChainId: {}
|
|
160
|
+
marketData: {}
|
|
159
161
|
};
|
|
160
162
|
this.initialize();
|
|
161
163
|
this.setIntervalLength(interval);
|
|
@@ -180,10 +182,13 @@ var TokenRatesController = class extends StaticIntervalPollingControllerV1 {
|
|
|
180
182
|
await this.updateExchangeRates();
|
|
181
183
|
}
|
|
182
184
|
});
|
|
183
|
-
onNetworkStateChange(async ({
|
|
184
|
-
const
|
|
185
|
+
onNetworkStateChange(async ({ selectedNetworkClientId }) => {
|
|
186
|
+
const selectedNetworkClient = getNetworkClientById(
|
|
187
|
+
selectedNetworkClientId
|
|
188
|
+
);
|
|
189
|
+
const { chainId, ticker } = selectedNetworkClient.configuration;
|
|
185
190
|
if (this.config.chainId !== chainId || this.config.nativeCurrency !== ticker) {
|
|
186
|
-
this.update({
|
|
191
|
+
this.update({ ...this.defaultState });
|
|
187
192
|
this.configure({ chainId, nativeCurrency: ticker });
|
|
188
193
|
if (__privateGet(this, _pollState) === "Active" /* Active */) {
|
|
189
194
|
await this.updateExchangeRates();
|
|
@@ -231,9 +236,6 @@ var TokenRatesController = class extends StaticIntervalPollingControllerV1 {
|
|
|
231
236
|
return;
|
|
232
237
|
}
|
|
233
238
|
const tokenAddresses = __privateMethod(this, _getTokenAddresses, getTokenAddresses_fn).call(this, chainId);
|
|
234
|
-
if (tokenAddresses.length === 0) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
239
|
const updateKey = `${chainId}:${nativeCurrency}`;
|
|
238
240
|
if (updateKey in __privateGet(this, _inProcessExchangeRateUpdates)) {
|
|
239
241
|
await __privateGet(this, _inProcessExchangeRateUpdates)[updateKey];
|
|
@@ -246,27 +248,18 @@ var TokenRatesController = class extends StaticIntervalPollingControllerV1 {
|
|
|
246
248
|
} = createDeferredPromise({ suppressUnhandledRejection: true });
|
|
247
249
|
__privateGet(this, _inProcessExchangeRateUpdates)[updateKey] = inProgressUpdate;
|
|
248
250
|
try {
|
|
249
|
-
const
|
|
251
|
+
const contractInformations = await __privateMethod(this, _fetchAndMapExchangeRates, fetchAndMapExchangeRates_fn).call(this, {
|
|
250
252
|
tokenAddresses,
|
|
251
253
|
chainId,
|
|
252
254
|
nativeCurrency
|
|
253
255
|
});
|
|
254
|
-
const
|
|
255
|
-
const updatedContractExchangeRates = chainId === this.config.chainId && nativeCurrency === this.config.nativeCurrency ? newContractExchangeRates : existingContractExchangeRates;
|
|
256
|
-
const existingContractExchangeRatesForChainId = this.state.contractExchangeRatesByChainId[chainId] ?? {};
|
|
257
|
-
const updatedContractExchangeRatesForChainId = {
|
|
258
|
-
...this.state.contractExchangeRatesByChainId,
|
|
256
|
+
const marketData = {
|
|
259
257
|
[chainId]: {
|
|
260
|
-
...
|
|
261
|
-
[nativeCurrency]: {
|
|
262
|
-
...existingContractExchangeRatesForChainId[nativeCurrency],
|
|
263
|
-
...newContractExchangeRates
|
|
264
|
-
}
|
|
258
|
+
...contractInformations ?? {}
|
|
265
259
|
}
|
|
266
260
|
};
|
|
267
261
|
this.update({
|
|
268
|
-
|
|
269
|
-
contractExchangeRatesByChainId: updatedContractExchangeRatesForChainId
|
|
262
|
+
marketData
|
|
270
263
|
});
|
|
271
264
|
updateSucceeded();
|
|
272
265
|
} catch (error) {
|
|
@@ -327,10 +320,11 @@ fetchAndMapExchangeRates_fn = async function({
|
|
|
327
320
|
}) {
|
|
328
321
|
if (!__privateGet(this, _tokenPricesService).validateChainIdSupported(chainId)) {
|
|
329
322
|
return tokenAddresses.reduce((obj, tokenAddress) => {
|
|
330
|
-
|
|
323
|
+
obj = {
|
|
331
324
|
...obj,
|
|
332
325
|
[tokenAddress]: void 0
|
|
333
326
|
};
|
|
327
|
+
return obj;
|
|
334
328
|
}, {});
|
|
335
329
|
}
|
|
336
330
|
if (__privateGet(this, _tokenPricesService).validateCurrencySupported(nativeCurrency)) {
|
|
@@ -351,6 +345,7 @@ fetchAndMapExchangeRatesForSupportedNativeCurrency_fn = async function({
|
|
|
351
345
|
chainId,
|
|
352
346
|
nativeCurrency
|
|
353
347
|
}) {
|
|
348
|
+
let contractNativeInformations;
|
|
354
349
|
const tokenPricesByTokenAddress = await reduceInBatchesSerially({
|
|
355
350
|
values: [...tokenAddresses].sort(),
|
|
356
351
|
batchSize: TOKEN_PRICES_BATCH_SIZE,
|
|
@@ -367,12 +362,27 @@ fetchAndMapExchangeRatesForSupportedNativeCurrency_fn = async function({
|
|
|
367
362
|
},
|
|
368
363
|
initialResult: {}
|
|
369
364
|
});
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
365
|
+
contractNativeInformations = tokenPricesByTokenAddress;
|
|
366
|
+
if (tokenAddresses.length === 0) {
|
|
367
|
+
const contractNativeInformationsNative = await __privateGet(this, _tokenPricesService).fetchTokenPrices({
|
|
368
|
+
tokenAddresses: [],
|
|
369
|
+
chainId,
|
|
370
|
+
currency: nativeCurrency
|
|
371
|
+
});
|
|
372
|
+
contractNativeInformations = {
|
|
373
|
+
[ZERO_ADDRESS]: {
|
|
374
|
+
currency: nativeCurrency,
|
|
375
|
+
...contractNativeInformationsNative[ZERO_ADDRESS]
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return Object.entries(contractNativeInformations).reduce(
|
|
380
|
+
(obj, [tokenAddress, token]) => {
|
|
381
|
+
obj = {
|
|
373
382
|
...obj,
|
|
374
|
-
[tokenAddress]:
|
|
383
|
+
[tokenAddress.toLowerCase()]: { ...token }
|
|
375
384
|
};
|
|
385
|
+
return obj;
|
|
376
386
|
},
|
|
377
387
|
{}
|
|
378
388
|
);
|
|
@@ -383,7 +393,7 @@ fetchAndMapExchangeRatesForUnsupportedNativeCurrency_fn = async function({
|
|
|
383
393
|
nativeCurrency
|
|
384
394
|
}) {
|
|
385
395
|
const [
|
|
386
|
-
|
|
396
|
+
contractExchangeInformations,
|
|
387
397
|
fallbackCurrencyToNativeCurrencyConversionRate
|
|
388
398
|
] = await Promise.all([
|
|
389
399
|
__privateMethod(this, _fetchAndMapExchangeRatesForSupportedNativeCurrency, fetchAndMapExchangeRatesForSupportedNativeCurrency_fn).call(this, {
|
|
@@ -399,15 +409,19 @@ fetchAndMapExchangeRatesForUnsupportedNativeCurrency_fn = async function({
|
|
|
399
409
|
if (fallbackCurrencyToNativeCurrencyConversionRate === null) {
|
|
400
410
|
return {};
|
|
401
411
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
412
|
+
const updatedContractExchangeRates = Object.entries(
|
|
413
|
+
contractExchangeInformations
|
|
414
|
+
).reduce((acc, [tokenAddress, token]) => {
|
|
415
|
+
acc = {
|
|
416
|
+
...acc,
|
|
417
|
+
[tokenAddress]: {
|
|
418
|
+
...token,
|
|
419
|
+
value: token.value ? token.value * fallbackCurrencyToNativeCurrencyConversionRate : void 0
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
return acc;
|
|
423
|
+
}, {});
|
|
424
|
+
return updatedContractExchangeRates;
|
|
411
425
|
};
|
|
412
426
|
var TokenRatesController_default = TokenRatesController;
|
|
413
427
|
|
|
@@ -415,4 +429,4 @@ export {
|
|
|
415
429
|
TokenRatesController,
|
|
416
430
|
TokenRatesController_default
|
|
417
431
|
};
|
|
418
|
-
//# sourceMappingURL=chunk-
|
|
432
|
+
//# sourceMappingURL=chunk-X4FFNQHE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/TokenRatesController.ts"],"sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport {\n safelyExecute,\n toChecksumHexAddress,\n FALL_BACK_VS_CURRENCY,\n toHex,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkController,\n NetworkState,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller';\nimport type { PreferencesState } from '@metamask/preferences-controller';\nimport { createDeferredPromise, type Hex } from '@metamask/utils';\nimport { isEqual } from 'lodash';\n\nimport { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from './assetsUtil';\nimport { fetchExchangeRate as fetchNativeCurrencyExchangeRate } from './crypto-compare-service';\nimport type { AbstractTokenPricesService } from './token-prices-service/abstract-token-prices-service';\nimport { ZERO_ADDRESS } from './token-prices-service/codefi-v2';\nimport type { TokensState } from './TokensController';\n\n/**\n * @type Token\n *\n * Token representation\n * @property address - Hex address of the token contract\n * @property decimals - Number of decimals the token uses\n * @property symbol - Symbol of the token\n * @property image - Image of the token, url or bit32 image\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface Token {\n address: string;\n decimals: number;\n symbol: string;\n aggregators?: string[];\n image?: string;\n balanceError?: unknown;\n isERC721?: boolean;\n name?: string;\n}\n\n/**\n * @type TokenRatesConfig\n *\n * Token rates controller configuration\n * @property interval - Polling interval used to fetch new token rates\n * @property nativeCurrency - Current native currency selected to use base of rates\n * @property chainId - Current network chainId\n * @property tokens - List of tokens to track exchange rates for\n * @property threshold - Threshold to invalidate the supportedChains\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TokenRatesConfig extends BaseConfig {\n interval: number;\n nativeCurrency: string;\n chainId: Hex;\n selectedAddress: string;\n allTokens: { [chainId: Hex]: { [key: string]: Token[] } };\n allDetectedTokens: { [chainId: Hex]: { [key: string]: Token[] } };\n threshold: number;\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface ContractExchangeRates {\n [address: string]: number | undefined;\n}\n\ntype MarketDataDetails = {\n tokenAddress: `0x${string}`;\n value: number;\n currency: string;\n allTimeHigh: number;\n allTimeLow: number;\n circulatingSupply: number;\n dilutedMarketCap: number;\n high1d: number;\n low1d: number;\n marketCap: number;\n marketCapPercentChange1d: number;\n price: number;\n priceChange1d: number;\n pricePercentChange1d: number;\n pricePercentChange1h: number;\n pricePercentChange1y: number;\n pricePercentChange7d: number;\n pricePercentChange14d: number;\n pricePercentChange30d: number;\n pricePercentChange200d: number;\n totalVolume: number;\n};\n\nexport type ContractMarketData = Record<Hex, MarketDataDetails>;\n\nenum PollState {\n Active = 'Active',\n Inactive = 'Inactive',\n}\n\n/**\n * @type TokenRatesState\n *\n * Token rates controller state\n * @property marketData - Market data for tokens, keyed by chain ID and then token contract address.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TokenRatesState extends BaseState {\n marketData: Record<Hex, Record<Hex, MarketDataDetails>>;\n}\n\n/**\n * Uses the CryptoCompare API to fetch the exchange rate between one currency\n * and another, i.e., the multiplier to apply the amount of one currency in\n * order to convert it to another.\n *\n * @param args - The arguments to this function.\n * @param args.from - The currency to convert from.\n * @param args.to - The currency to convert to.\n * @returns The exchange rate between `fromCurrency` to `toCurrency` if one\n * exists, or null if one does not.\n */\nasync function getCurrencyConversionRate({\n from,\n to,\n}: {\n from: string;\n to: string;\n}) {\n const includeUSDRate = false;\n try {\n const result = await fetchNativeCurrencyExchangeRate(\n to,\n from,\n includeUSDRate,\n );\n return result.conversionRate;\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.includes('market does not exist for this coin pair')\n ) {\n return null;\n }\n throw error;\n }\n}\n\n/**\n * Controller that passively polls on a set interval for token-to-fiat exchange rates\n * for tokens stored in the TokensController\n */\nexport class TokenRatesController extends StaticIntervalPollingControllerV1<\n TokenRatesConfig,\n TokenRatesState\n> {\n private handle?: ReturnType<typeof setTimeout>;\n\n #pollState = PollState.Inactive;\n\n #tokenPricesService: AbstractTokenPricesService;\n\n #inProcessExchangeRateUpdates: Record<`${Hex}:${string}`, Promise<void>> = {};\n\n /**\n * Name of this controller used during composition\n */\n override name = 'TokenRatesController';\n\n private readonly getNetworkClientById: NetworkController['getNetworkClientById'];\n\n /**\n * Creates a TokenRatesController instance.\n *\n * @param options - The controller options.\n * @param options.interval - The polling interval in ms\n * @param options.threshold - The duration in ms before metadata fetched from CoinGecko is considered stale\n * @param options.getNetworkClientById - Gets the network client with the given id from the NetworkController.\n * @param options.chainId - The chain ID of the current network.\n * @param options.ticker - The ticker for the current network.\n * @param options.selectedAddress - The current selected address.\n * @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes.\n * @param options.onTokensStateChange - Allows subscribing to token controller state changes.\n * @param options.onNetworkStateChange - Allows subscribing to network state changes.\n * @param options.tokenPricesService - An object in charge of retrieving token prices.\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(\n {\n interval = 3 * 60 * 1000,\n threshold = 6 * 60 * 60 * 1000,\n getNetworkClientById,\n chainId: initialChainId,\n ticker: initialTicker,\n selectedAddress: initialSelectedAddress,\n onPreferencesStateChange,\n onTokensStateChange,\n onNetworkStateChange,\n tokenPricesService,\n }: {\n interval?: number;\n threshold?: number;\n getNetworkClientById: NetworkController['getNetworkClientById'];\n chainId: Hex;\n ticker: string;\n selectedAddress: string;\n onPreferencesStateChange: (\n listener: (preferencesState: PreferencesState) => void,\n ) => void;\n onTokensStateChange: (\n listener: (tokensState: TokensState) => void,\n ) => void;\n onNetworkStateChange: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n tokenPricesService: AbstractTokenPricesService;\n },\n config?: Partial<TokenRatesConfig>,\n state?: Partial<TokenRatesState>,\n ) {\n super(config, state);\n this.defaultConfig = {\n interval,\n threshold,\n disabled: false,\n nativeCurrency: initialTicker,\n chainId: initialChainId,\n selectedAddress: initialSelectedAddress,\n allTokens: {}, // TODO: initialize these correctly, maybe as part of BaseControllerV2 migration\n allDetectedTokens: {},\n };\n\n this.defaultState = {\n marketData: {},\n };\n this.initialize();\n this.setIntervalLength(interval);\n this.getNetworkClientById = getNetworkClientById;\n this.#tokenPricesService = tokenPricesService;\n\n if (config?.disabled) {\n this.configure({ disabled: true }, false, false);\n }\n\n onPreferencesStateChange(async ({ selectedAddress }) => {\n if (this.config.selectedAddress !== selectedAddress) {\n this.configure({ selectedAddress });\n if (this.#pollState === PollState.Active) {\n await this.updateExchangeRates();\n }\n }\n });\n\n onTokensStateChange(async ({ allTokens, allDetectedTokens }) => {\n const previousTokenAddresses = this.#getTokenAddresses(\n this.config.chainId,\n );\n this.configure({ allTokens, allDetectedTokens });\n const newTokenAddresses = this.#getTokenAddresses(this.config.chainId);\n if (\n !isEqual(previousTokenAddresses, newTokenAddresses) &&\n this.#pollState === PollState.Active\n ) {\n await this.updateExchangeRates();\n }\n });\n\n onNetworkStateChange(async ({ selectedNetworkClientId }) => {\n const selectedNetworkClient = getNetworkClientById(\n selectedNetworkClientId,\n );\n const { chainId, ticker } = selectedNetworkClient.configuration;\n\n if (\n this.config.chainId !== chainId ||\n this.config.nativeCurrency !== ticker\n ) {\n this.update({ ...this.defaultState });\n this.configure({ chainId, nativeCurrency: ticker });\n if (this.#pollState === PollState.Active) {\n await this.updateExchangeRates();\n }\n }\n });\n }\n\n /**\n * Get the user's tokens for the given chain.\n *\n * @param chainId - The chain ID.\n * @returns The list of tokens addresses for the current chain\n */\n #getTokenAddresses(chainId: Hex): Hex[] {\n const { allTokens, allDetectedTokens } = this.config;\n const tokens = allTokens[chainId]?.[this.config.selectedAddress] || [];\n const detectedTokens =\n allDetectedTokens[chainId]?.[this.config.selectedAddress] || [];\n\n return [\n ...new Set(\n [...tokens, ...detectedTokens].map((token) =>\n toHex(toChecksumHexAddress(token.address)),\n ),\n ),\n ].sort();\n }\n\n /**\n * Start (or restart) polling.\n */\n async start() {\n this.#stopPoll();\n this.#pollState = PollState.Active;\n await this.#poll();\n }\n\n /**\n * Stop polling.\n */\n stop() {\n this.#stopPoll();\n this.#pollState = PollState.Inactive;\n }\n\n /**\n * Clear the active polling timer, if present.\n */\n #stopPoll() {\n if (this.handle) {\n clearTimeout(this.handle);\n }\n }\n\n /**\n * Poll for exchange rate updates.\n */\n async #poll() {\n await safelyExecute(() => this.updateExchangeRates());\n\n // Poll using recursive `setTimeout` instead of `setInterval` so that\n // requests don't stack if they take longer than the polling interval\n this.handle = setTimeout(() => {\n this.#poll();\n }, this.config.interval);\n }\n\n /**\n * Updates exchange rates for all tokens.\n */\n async updateExchangeRates() {\n const { chainId, nativeCurrency } = this.config;\n await this.updateExchangeRatesByChainId({\n chainId,\n nativeCurrency,\n });\n }\n\n /**\n * Updates exchange rates for all tokens.\n *\n * @param options - The options to fetch exchange rates.\n * @param options.chainId - The chain ID.\n * @param options.nativeCurrency - The ticker for the chain.\n */\n async updateExchangeRatesByChainId({\n chainId,\n nativeCurrency,\n }: {\n chainId: Hex;\n nativeCurrency: string;\n }) {\n if (this.disabled) {\n return;\n }\n\n const tokenAddresses = this.#getTokenAddresses(chainId);\n\n const updateKey: `${Hex}:${string}` = `${chainId}:${nativeCurrency}`;\n if (updateKey in this.#inProcessExchangeRateUpdates) {\n // This prevents redundant updates\n // This promise is resolved after the in-progress update has finished,\n // and state has been updated.\n await this.#inProcessExchangeRateUpdates[updateKey];\n return;\n }\n\n const {\n promise: inProgressUpdate,\n resolve: updateSucceeded,\n reject: updateFailed,\n } = createDeferredPromise({ suppressUnhandledRejection: true });\n this.#inProcessExchangeRateUpdates[updateKey] = inProgressUpdate;\n\n try {\n const contractInformations = await this.#fetchAndMapExchangeRates({\n tokenAddresses,\n chainId,\n nativeCurrency,\n });\n\n const marketData = {\n [chainId]: {\n ...(contractInformations ?? {}),\n },\n };\n\n this.update({\n marketData,\n });\n updateSucceeded();\n } catch (error: unknown) {\n updateFailed(error);\n throw error;\n } finally {\n delete this.#inProcessExchangeRateUpdates[updateKey];\n }\n }\n\n /**\n * Uses the token prices service to retrieve exchange rates for tokens in a\n * particular currency.\n *\n * If the price API does not support the given chain ID, returns an empty\n * object.\n *\n * If the price API does not support the given currency, retrieves exchange\n * rates in a known currency instead, then converts those rates using the\n * exchange rate between the known currency and desired currency.\n *\n * @param args - The arguments to this function.\n * @param args.tokenAddresses - Addresses for tokens.\n * @param args.chainId - The EIP-155 ID of the chain where the tokens live.\n * @param args.nativeCurrency - The native currency in which to request\n * exchange rates.\n * @returns A map from token address to its exchange rate in the native\n * currency, or an empty map if no exchange rates can be obtained for the\n * chain ID.\n */\n async #fetchAndMapExchangeRates({\n tokenAddresses,\n chainId,\n nativeCurrency,\n }: {\n tokenAddresses: Hex[];\n chainId: Hex;\n nativeCurrency: string;\n }): Promise<ContractMarketData> {\n if (!this.#tokenPricesService.validateChainIdSupported(chainId)) {\n return tokenAddresses.reduce((obj, tokenAddress) => {\n obj = {\n ...obj,\n [tokenAddress]: undefined,\n };\n\n return obj;\n }, {});\n }\n\n if (this.#tokenPricesService.validateCurrencySupported(nativeCurrency)) {\n return await this.#fetchAndMapExchangeRatesForSupportedNativeCurrency({\n tokenAddresses,\n chainId,\n nativeCurrency,\n });\n }\n return await this.#fetchAndMapExchangeRatesForUnsupportedNativeCurrency({\n tokenAddresses,\n nativeCurrency,\n });\n }\n\n /**\n * Updates token rates for the given networkClientId\n *\n * @param networkClientId - The network client ID used to get a ticker value.\n * @returns The controller state.\n */\n async _executePoll(networkClientId: NetworkClientId): Promise<void> {\n const networkClient = this.getNetworkClientById(networkClientId);\n await this.updateExchangeRatesByChainId({\n chainId: networkClient.configuration.chainId,\n nativeCurrency: networkClient.configuration.ticker,\n });\n }\n\n /**\n * Retrieves prices in the given currency for the given tokens on the given\n * chain. Ensures that token addresses are checksum addresses.\n *\n * @param args - The arguments to this function.\n * @param args.tokenAddresses - Addresses for tokens.\n * @param args.chainId - The EIP-155 ID of the chain where the tokens live.\n * @param args.nativeCurrency - The native currency in which to request\n * prices.\n * @returns A map of the token addresses (as checksums) to their prices in the\n * native currency.\n */\n async #fetchAndMapExchangeRatesForSupportedNativeCurrency({\n tokenAddresses,\n chainId,\n nativeCurrency,\n }: {\n tokenAddresses: Hex[];\n chainId: Hex;\n nativeCurrency: string;\n }): Promise<ContractMarketData> {\n let contractNativeInformations;\n const tokenPricesByTokenAddress = await reduceInBatchesSerially<\n Hex,\n Awaited<ReturnType<AbstractTokenPricesService['fetchTokenPrices']>>\n >({\n values: [...tokenAddresses].sort(),\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n eachBatch: async (allTokenPricesByTokenAddress, batch) => {\n const tokenPricesByTokenAddressForBatch =\n await this.#tokenPricesService.fetchTokenPrices({\n tokenAddresses: batch,\n chainId,\n currency: nativeCurrency,\n });\n\n return {\n ...allTokenPricesByTokenAddress,\n ...tokenPricesByTokenAddressForBatch,\n };\n },\n initialResult: {},\n });\n contractNativeInformations = tokenPricesByTokenAddress;\n\n // fetch for native token\n if (tokenAddresses.length === 0) {\n const contractNativeInformationsNative =\n await this.#tokenPricesService.fetchTokenPrices({\n tokenAddresses: [],\n chainId,\n currency: nativeCurrency,\n });\n\n contractNativeInformations = {\n [ZERO_ADDRESS]: {\n currency: nativeCurrency,\n ...contractNativeInformationsNative[ZERO_ADDRESS],\n },\n };\n }\n return Object.entries(contractNativeInformations).reduce(\n (obj, [tokenAddress, token]) => {\n obj = {\n ...obj,\n [tokenAddress.toLowerCase()]: { ...token },\n };\n\n return obj;\n },\n {},\n );\n }\n\n /**\n * If the price API does not support a given native currency, then we need to\n * convert it to a fallback currency and feed that currency into the price\n * API, then convert the prices to our desired native currency.\n *\n * @param args - The arguments to this function.\n * @param args.tokenAddresses - Addresses for tokens.\n * @param args.nativeCurrency - The native currency in which to request\n * prices.\n * @returns A map of the token addresses (as checksums) to their prices in the\n * native currency.\n */\n async #fetchAndMapExchangeRatesForUnsupportedNativeCurrency({\n tokenAddresses,\n nativeCurrency,\n }: {\n tokenAddresses: Hex[];\n nativeCurrency: string;\n }): Promise<ContractMarketData> {\n const [\n contractExchangeInformations,\n fallbackCurrencyToNativeCurrencyConversionRate,\n ] = await Promise.all([\n this.#fetchAndMapExchangeRatesForSupportedNativeCurrency({\n tokenAddresses,\n chainId: this.config.chainId,\n nativeCurrency: FALL_BACK_VS_CURRENCY,\n }),\n getCurrencyConversionRate({\n from: FALL_BACK_VS_CURRENCY,\n to: nativeCurrency,\n }),\n ]);\n\n if (fallbackCurrencyToNativeCurrencyConversionRate === null) {\n return {};\n }\n\n const updatedContractExchangeRates = Object.entries(\n contractExchangeInformations,\n ).reduce((acc, [tokenAddress, token]) => {\n acc = {\n ...acc,\n [tokenAddress]: {\n ...token,\n value: token.value\n ? token.value * fallbackCurrencyToNativeCurrencyConversionRate\n : undefined,\n },\n };\n return acc;\n }, {});\n\n return updatedContractExchangeRates;\n }\n}\n\nexport default TokenRatesController;\n"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,SAAS,yCAAyC;AAElD,SAAS,6BAAuC;AAChD,SAAS,eAAe;AAoHxB,eAAe,0BAA0B;AAAA,EACvC;AAAA,EACA;AACF,GAGG;AACD,QAAM,iBAAiB;AACvB,MAAI;AACF,UAAM,SAAS,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,WAAO,OAAO;AAAA,EAChB,SAAS,OAAO;AACd,QACE,iBAAiB,SACjB,MAAM,QAAQ,SAAS,0CAA0C,GACjE;AACA,aAAO;AAAA,IACT;AACA,UAAM;AAAA,EACR;AACF;AA3JA;AAiKO,IAAM,uBAAN,cAAmC,kCAGxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiCA,YACE;AAAA,IACE,WAAW,IAAI,KAAK;AAAA,IACpB,YAAY,IAAI,KAAK,KAAK;AAAA,IAC1B;AAAA,IACA,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAkBA,QACA,OACA;AACA,UAAM,QAAQ,KAAK;AAwErB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCA;AAAA;AAAA;AAAA;AASA;AAAA;AAAA;AAAA,uBAAM;AAsGN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AA2DN;AAAA;AAAA;AAAA;AA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
import {
|
|
2
2
|
fetchTokenListByChainId
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Z3OQU4XW.mjs";
|
|
4
4
|
import {
|
|
5
5
|
formatAggregatorNames,
|
|
6
6
|
formatIconUrlWithProxy,
|
|
7
7
|
isTokenListSupportedForNetwork
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-Q5JRBGWO.mjs";
|
|
9
9
|
import {
|
|
10
10
|
__privateAdd,
|
|
11
11
|
__privateMethod
|
|
@@ -281,4 +281,4 @@ export {
|
|
|
281
281
|
TokenListController,
|
|
282
282
|
TokenListController_default
|
|
283
283
|
};
|
|
284
|
-
//# sourceMappingURL=chunk-
|
|
284
|
+
//# sourceMappingURL=chunk-XHMM35YT.mjs.map
|
|
@@ -140,6 +140,7 @@ var SUPPORTED_CURRENCIES = [
|
|
|
140
140
|
// Satoshi
|
|
141
141
|
"sats"
|
|
142
142
|
];
|
|
143
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
143
144
|
var SUPPORTED_CHAIN_IDS = [
|
|
144
145
|
// Ethereum Mainnet
|
|
145
146
|
"0x1",
|
|
@@ -208,7 +209,7 @@ var SUPPORTED_CHAIN_IDS = [
|
|
|
208
209
|
// Linea Mainnet
|
|
209
210
|
"0xe708"
|
|
210
211
|
];
|
|
211
|
-
var BASE_URL = "https://price
|
|
212
|
+
var BASE_URL = "https://price.api.cx.metamask.io/v2";
|
|
212
213
|
var DEFAULT_TOKEN_PRICE_RETRIES = 3;
|
|
213
214
|
var DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;
|
|
214
215
|
var DEFAULT_DEGRADED_THRESHOLD = 5e3;
|
|
@@ -281,29 +282,32 @@ var CodefiTokenPricesServiceV2 = class {
|
|
|
281
282
|
}) {
|
|
282
283
|
const chainIdAsNumber = hexToNumber(chainId);
|
|
283
284
|
const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);
|
|
284
|
-
url.searchParams.append(
|
|
285
|
+
url.searchParams.append(
|
|
286
|
+
"tokenAddresses",
|
|
287
|
+
[ZERO_ADDRESS, ...tokenAddresses].join(",")
|
|
288
|
+
);
|
|
285
289
|
url.searchParams.append("vsCurrency", currency);
|
|
286
|
-
|
|
290
|
+
url.searchParams.append("includeMarketData", "true");
|
|
291
|
+
const addressCryptoDataMap = await __privateGet(this, _tokenPricePolicy).execute(
|
|
287
292
|
() => handleFetch(url, { headers: { "Cache-Control": "no-cache" } })
|
|
288
293
|
);
|
|
289
|
-
return tokenAddresses.reduce(
|
|
294
|
+
return [ZERO_ADDRESS, ...tokenAddresses].reduce(
|
|
290
295
|
(obj, tokenAddress) => {
|
|
291
296
|
const lowercasedTokenAddress = tokenAddress.toLowerCase();
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
console.error(
|
|
296
|
-
`Could not find price for "${tokenAddress}" in "${currency}"`
|
|
297
|
-
);
|
|
297
|
+
const marketData = addressCryptoDataMap[lowercasedTokenAddress];
|
|
298
|
+
if (marketData === void 0) {
|
|
299
|
+
return obj;
|
|
298
300
|
}
|
|
299
|
-
const
|
|
301
|
+
const { price } = marketData;
|
|
302
|
+
const token = {
|
|
300
303
|
tokenAddress,
|
|
301
304
|
value: price,
|
|
302
|
-
currency
|
|
305
|
+
currency,
|
|
306
|
+
...marketData
|
|
303
307
|
};
|
|
304
308
|
return {
|
|
305
309
|
...obj,
|
|
306
|
-
|
|
310
|
+
[tokenAddress]: token
|
|
307
311
|
};
|
|
308
312
|
},
|
|
309
313
|
{}
|
|
@@ -337,7 +341,8 @@ _tokenPricePolicy = new WeakMap();
|
|
|
337
341
|
|
|
338
342
|
export {
|
|
339
343
|
SUPPORTED_CURRENCIES,
|
|
344
|
+
ZERO_ADDRESS,
|
|
340
345
|
SUPPORTED_CHAIN_IDS,
|
|
341
346
|
CodefiTokenPricesServiceV2
|
|
342
347
|
};
|
|
343
|
-
//# sourceMappingURL=chunk-
|
|
348
|
+
//# sourceMappingURL=chunk-Y35SM7TO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/token-prices-service/codefi-v2.ts"],"sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { hexToNumber } from '@metamask/utils';\nimport {\n circuitBreaker,\n ConsecutiveBreaker,\n ExponentialBackoff,\n handleAll,\n type IPolicy,\n retry,\n wrap,\n CircuitState,\n} from 'cockatiel';\n\nimport type {\n AbstractTokenPricesService,\n TokenPrice,\n TokenPricesByTokenAddress,\n} from './abstract-token-prices-service';\n\n/**\n * The list of currencies that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint, in lowercase form.\n */\nexport const SUPPORTED_CURRENCIES = [\n // Bitcoin\n 'btc',\n // Ether\n 'eth',\n // Litecoin\n 'ltc',\n // Bitcoin Cash\n 'bch',\n // Binance Coin\n 'bnb',\n // EOS\n 'eos',\n // XRP\n 'xrp',\n // Lumens\n 'xlm',\n // Chainlink\n 'link',\n // Polkadot\n 'dot',\n // Yearn.finance\n 'yfi',\n // US Dollar\n 'usd',\n // United Arab Emirates Dirham\n 'aed',\n // Argentine Peso\n 'ars',\n // Australian Dollar\n 'aud',\n // Bangladeshi Taka\n 'bdt',\n // Bahraini Dinar\n 'bhd',\n // Bermudian Dollar\n 'bmd',\n // Brazil Real\n 'brl',\n // Canadian Dollar\n 'cad',\n // Swiss Franc\n 'chf',\n // Chilean Peso\n 'clp',\n // Chinese Yuan\n 'cny',\n // Czech Koruna\n 'czk',\n // Danish Krone\n 'dkk',\n // Euro\n 'eur',\n // British Pound Sterling\n 'gbp',\n // Hong Kong Dollar\n 'hkd',\n // Hungarian Forint\n 'huf',\n // Indonesian Rupiah\n 'idr',\n // Israeli New Shekel\n 'ils',\n // Indian Rupee\n 'inr',\n // Japanese Yen\n 'jpy',\n // South Korean Won\n 'krw',\n // Kuwaiti Dinar\n 'kwd',\n // Sri Lankan Rupee\n 'lkr',\n // Burmese Kyat\n 'mmk',\n // Mexican Peso\n 'mxn',\n // Malaysian Ringgit\n 'myr',\n // Nigerian Naira\n 'ngn',\n // Norwegian Krone\n 'nok',\n // New Zealand Dollar\n 'nzd',\n // Philippine Peso\n 'php',\n // Pakistani Rupee\n 'pkr',\n // Polish Zloty\n 'pln',\n // Russian Ruble\n 'rub',\n // Saudi Riyal\n 'sar',\n // Swedish Krona\n 'sek',\n // Singapore Dollar\n 'sgd',\n // Thai Baht\n 'thb',\n // Turkish Lira\n 'try',\n // New Taiwan Dollar\n 'twd',\n // Ukrainian hryvnia\n 'uah',\n // Venezuelan bolívar fuerte\n 'vef',\n // Vietnamese đồng\n 'vnd',\n // South African Rand\n 'zar',\n // IMF Special Drawing Rights\n 'xdr',\n // Silver - Troy Ounce\n 'xag',\n // Gold - Troy Ounce\n 'xau',\n // Bits\n 'bits',\n // Satoshi\n 'sats',\n] as const;\n\n/**\n * Represents the zero address, commonly used as a placeholder in blockchain transactions.\n * In the context of fetching market data, the zero address is utilized to retrieve information\n * specifically for native currencies. This allows for a standardized approach to query market\n * data for blockchain-native assets without a specific contract address.\n */\nexport const ZERO_ADDRESS: Hex =\n '0x0000000000000000000000000000000000000000' as const;\n\n/**\n * A currency that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.\n */\ntype SupportedCurrency =\n | (typeof SUPPORTED_CURRENCIES)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES)[number]>;\n\n/**\n * The list of chain IDs that can be supplied in the URL for the `/spot-prices`\n * endpoint, but in hexadecimal form (for consistency with how we represent\n * chain IDs in other places).\n * @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.\n */\nexport const SUPPORTED_CHAIN_IDS = [\n // Ethereum Mainnet\n '0x1',\n // OP Mainnet\n '0xa',\n // Cronos Mainnet\n '0x19',\n // BNB Smart Chain Mainnet\n '0x38',\n // Syscoin Mainnet\n '0x39',\n // OKXChain Mainnet\n '0x42',\n // Hoo Smart Chain\n '0x46',\n // Meter Mainnet\n '0x52',\n // TomoChain\n '0x58',\n // Gnosis\n '0x64',\n // Velas EVM Mainnet\n '0x6a',\n // Fuse Mainnet\n '0x7a',\n // Huobi ECO Chain Mainnet\n '0x80',\n // Polygon Mainnet\n '0x89',\n // Fantom Opera\n '0xfa',\n // Boba Network\n '0x120',\n // KCC Mainnet\n '0x141',\n // zkSync Era Mainnet\n '0x144',\n // Theta Mainnet\n '0x169',\n // Metis Andromeda Mainnet\n '0x440',\n // Moonbeam\n '0x504',\n // Moonriver\n '0x505',\n // Base\n '0x2105',\n // Shiden\n '0x150',\n // Smart Bitcoin Cash\n '0x2710',\n // Arbitrum One\n '0xa4b1',\n // Celo Mainnet\n '0xa4ec',\n // Oasis Emerald\n '0xa516',\n // Avalanche C-Chain\n '0xa86a',\n // Polis Mainnet\n '0x518af',\n // Aurora Mainnet\n '0x4e454152',\n // Harmony Mainnet Shard 0\n '0x63564c40',\n // Linea Mainnet\n '0xe708',\n] as const;\n\n/**\n * A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,\n * but in hexadecimal form (for consistency with how we represent chain IDs in\n * other places).\n */\ntype SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];\n\n/**\n * All requests to V2 of the Price API start with this.\n */\nconst BASE_URL = 'https://price.api.cx.metamask.io/v2';\n\nconst DEFAULT_TOKEN_PRICE_RETRIES = 3;\n// Each update attempt will result (1 + retries) calls if the server is down\nconst DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES =\n (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;\n\nconst DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\n/**\n * The shape of the data that the /spot-prices endpoint returns.\n */\ntype MarketData = {\n /**\n * The all-time highest price of the token.\n */\n allTimeHigh: number;\n /**\n * The all-time lowest price of the token.\n */\n allTimeLow: number;\n /**\n * The number of tokens currently in circulation.\n */\n circulatingSupply: number;\n /**\n * The market cap calculated using the diluted supply.\n */\n dilutedMarketCap: number;\n /**\n * The highest price of the token in the last 24 hours.\n */\n high1d: number;\n /**\n * The lowest price of the token in the last 24 hours.\n */\n low1d: number;\n /**\n * The current market capitalization of the token.\n */\n marketCap: number;\n /**\n * The percentage change in market capitalization over the last 24 hours.\n */\n marketCapPercentChange1d: number;\n /**\n * The current price of the token.\n */\n price: number;\n /**\n * The absolute change in price over the last 24 hours.\n */\n priceChange1d: number;\n /**\n * The percentage change in price over the last 24 hours.\n */\n pricePercentChange1d: number;\n /**\n * The percentage change in price over the last hour.\n */\n pricePercentChange1h: number;\n /**\n * The percentage change in price over the last year.\n */\n pricePercentChange1y: number;\n /**\n * The percentage change in price over the last 7 days.\n */\n pricePercentChange7d: number;\n /**\n * The percentage change in price over the last 14 days.\n */\n pricePercentChange14d: number;\n /**\n * The percentage change in price over the last 30 days.\n */\n pricePercentChange30d: number;\n /**\n * The percentage change in price over the last 200 days.\n */\n pricePercentChange200d: number;\n /**\n * The total trading volume of the token in the last 24 hours.\n */\n totalVolume: number;\n};\n\ntype MarketDataByTokenAddress = { [address: Hex]: MarketData };\n/**\n * This version of the token prices service uses V2 of the Codefi Price API to\n * fetch token prices.\n */\nexport class CodefiTokenPricesServiceV2\n implements\n AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency>\n{\n #tokenPricePolicy: IPolicy;\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param options - Constructor options\n * @param options.degradedThreshold - The threshold between \"normal\" and \"degrated\" service,\n * in milliseconds.\n * @param options.retries - Number of retry attempts for each token price update.\n * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures\n * allowed before breaking the circuit and pausing further updates.\n * @param options.onBreak - An event handler for when the circuit breaks, useful for capturing\n * metrics about network failures.\n * @param options.onDegraded - An event handler for when the circuit remains closed, but requests\n * are failing or resolving too slowly (i.e. resolving more slowly than the `degradedThreshold).\n * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks\n * from too many consecutive failures.\n */\n constructor({\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_TOKEN_PRICE_RETRIES,\n maximumConsecutiveFailures = DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES,\n onBreak,\n onDegraded,\n circuitBreakDuration = 30 * 60 * 1000,\n }: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n } = {}) {\n // Construct a policy that will retry each update, and halt further updates\n // for a certain period after too many consecutive failures.\n const retryPolicy = retry(handleAll, {\n maxAttempts: retries,\n backoff: new ExponentialBackoff(),\n });\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maximumConsecutiveFailures),\n });\n if (onBreak) {\n circuitBreakerPolicy.onBreak(onBreak);\n }\n if (onDegraded) {\n retryPolicy.onGiveUp(() => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n onDegraded();\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (\n circuitBreakerPolicy.state === CircuitState.Closed &&\n duration > degradedThreshold\n ) {\n onDegraded();\n }\n });\n }\n this.#tokenPricePolicy = wrap(retryPolicy, circuitBreakerPolicy);\n }\n\n /**\n * Retrieves prices in the given currency for the tokens identified by the\n * given addresses which are expected to live on the given chain.\n *\n * @param args - The arguments to function.\n * @param args.chainId - An EIP-155 chain ID.\n * @param args.tokenAddresses - Addresses for tokens that live on the chain.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n async fetchTokenPrices({\n chainId,\n tokenAddresses,\n currency,\n }: {\n chainId: SupportedChainId;\n tokenAddresses: Hex[];\n currency: SupportedCurrency;\n }): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>> {\n const chainIdAsNumber = hexToNumber(chainId);\n\n const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);\n url.searchParams.append(\n 'tokenAddresses',\n [ZERO_ADDRESS, ...tokenAddresses].join(','),\n );\n url.searchParams.append('vsCurrency', currency);\n url.searchParams.append('includeMarketData', 'true');\n\n const addressCryptoDataMap: MarketDataByTokenAddress =\n await this.#tokenPricePolicy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n );\n\n return [ZERO_ADDRESS, ...tokenAddresses].reduce(\n (\n obj: Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>,\n tokenAddress,\n ) => {\n // The Price API lowercases both currency and token addresses, so we have\n // to keep track of them and make sure we return the original versions.\n const lowercasedTokenAddress =\n tokenAddress.toLowerCase() as Lowercase<Hex>;\n\n const marketData = addressCryptoDataMap[lowercasedTokenAddress];\n\n if (marketData === undefined) {\n return obj;\n }\n\n const { price } = marketData;\n\n const token: TokenPrice<Hex, SupportedCurrency> = {\n tokenAddress,\n value: price,\n currency,\n ...marketData,\n };\n\n return {\n ...obj,\n [tokenAddress]: token,\n };\n },\n {},\n ) as Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>;\n }\n\n /**\n * Type guard for whether the API can return token prices for the given chain\n * ID.\n *\n * @param chainId - The chain ID to check.\n * @returns True if the API supports the chain ID, false otherwise.\n */\n validateChainIdSupported(chainId: unknown): chainId is SupportedChainId {\n const supportedChainIds: readonly string[] = SUPPORTED_CHAIN_IDS;\n return typeof chainId === 'string' && supportedChainIds.includes(chainId);\n }\n\n /**\n * Type guard for whether the API can return token prices in the given\n * currency.\n *\n * @param currency - The currency to check. If a string, can be either\n * lowercase or uppercase.\n * @returns True if the API supports the currency, false otherwise.\n */\n validateCurrencySupported(currency: unknown): currency is SupportedCurrency {\n const supportedCurrencies: readonly string[] = SUPPORTED_CURRENCIES;\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n}\n"],"mappings":";;;;;;;AAAA,SAA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