@metamask-previews/assets-controllers 110.0.0-preview-6cd1bb2f5 → 110.0.1-preview-2296abeaf
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 +15 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.cjs +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.cjs.map +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.cts +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.cts.map +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.mts +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.d.mts.map +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.mjs +1 -1
- package/dist/DeFiPositionsController/group-defi-positions-v6.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +1 -1
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.cts +1 -1
- package/dist/token-prices-service/codefi-v2.d.mts +1 -1
- package/dist/token-prices-service/codefi-v2.mjs +1 -1
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [110.0.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump `@metamask/core-backend` from `^7.0.0` to `^8.0.0` ([#9693](https://github.com/MetaMask/core/pull/9693))
|
|
15
|
+
- Bump `@metamask/transaction-controller` from `^69.2.1` to `^69.3.0` ([#9693](https://github.com/MetaMask/core/pull/9693))
|
|
16
|
+
- Bump `@metamask/keyring-api` from `^23.5.0` to `^23.7.0` ([#9676](https://github.com/MetaMask/core/pull/9676))
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Fix Arc (`5042`/`0x13b2`) native asset ID in `codefi-v2.ts`, from the `erc20:0x0` zero-address placeholder to `slip44:5042` now that Arc has a real SLIP-44 registry entry for its native USDC ([#9681](https://github.com/MetaMask/core/pull/9681))
|
|
21
|
+
- Treat `loan` (not `lending`) as the DeFi liability position type in `DEFI_POSITION_LIABILITY_TYPES`, matching corrected Accounts API v6 position types ([#9683](https://github.com/MetaMask/core/pull/9683))
|
|
22
|
+
|
|
10
23
|
## [110.0.0]
|
|
11
24
|
|
|
12
25
|
### Added
|
|
@@ -3334,7 +3347,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
3334
3347
|
|
|
3335
3348
|
- Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
|
|
3336
3349
|
|
|
3337
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@110.0.
|
|
3350
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@110.0.1...HEAD
|
|
3351
|
+
[110.0.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@110.0.0...@metamask/assets-controllers@110.0.1
|
|
3338
3352
|
[110.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@109.4.1...@metamask/assets-controllers@110.0.0
|
|
3339
3353
|
[109.4.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@109.4.0...@metamask/assets-controllers@109.4.1
|
|
3340
3354
|
[109.4.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@109.3.1...@metamask/assets-controllers@109.4.0
|
|
@@ -14,7 +14,7 @@ exports.DEFI_POSITION_TYPES = core_backend_1.V6_DEFI_POSITION_TYPES;
|
|
|
14
14
|
* Position types whose fiat value is a liability and is subtracted from the
|
|
15
15
|
* protocol group's aggregated `marketValue`.
|
|
16
16
|
*/
|
|
17
|
-
exports.DEFI_POSITION_LIABILITY_TYPES = new Set(['
|
|
17
|
+
exports.DEFI_POSITION_LIABILITY_TYPES = new Set(['loan']);
|
|
18
18
|
// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple
|
|
19
19
|
// underlyings. Display-only.
|
|
20
20
|
const SYMBOL_PRIORITY = ['ETH', 'WETH'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-defi-positions-v6.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":";;;AAAA,yDAAgE;AAYhE,2CAKyB;AAEzB,+EAA+E;AAC/E,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AAEjE;;;GAGG;AACU,QAAA,mBAAmB,GAAG,qCAAsB,CAAC;AAQ1D;;;GAGG;AACU,QAAA,6BAA6B,GACxC,IAAI,GAAG,CAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAuFzC,gFAAgF;AAChF,6BAA6B;AAC7B,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAIxC;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,OAAsB;IAClD,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;QAChD,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;QACtD,MAAM,iBAAiB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CACzE,KAAK,EACL,GAAG,CACJ,CAAC;QAEF,OAAO,GAAG,wBAAwB,6BAA6B,iBAAiB,MAAM,CAAC;IACzF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,yBA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AO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,kBAAkB,EAAE,CAAC;QAC1D,MAAM,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAhGD,oDAgGC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['lending']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"group-defi-positions-v6.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":";;;AAAA,yDAAgE;AAYhE,2CAKyB;AAEzB,+EAA+E;AAC/E,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AAEjE;;;GAGG;AACU,QAAA,mBAAmB,GAAG,qCAAsB,CAAC;AAQ1D;;;GAGG;AACU,QAAA,6BAA6B,GACxC,IAAI,GAAG,CAAmB,CAAC,MAAM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/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['loan']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
|
|
|
4
4
|
* Possible `positionType` values from Accounts API v6 DeFi metadata.
|
|
5
5
|
* Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.
|
|
6
6
|
*/
|
|
7
|
-
export declare const DEFI_POSITION_TYPES: readonly ["deposit", "
|
|
7
|
+
export declare const DEFI_POSITION_TYPES: readonly ["deposit", "loan", "locked", "staked", "reward", "wallet", "investment"];
|
|
8
8
|
/**
|
|
9
9
|
* The specific module or functionality within a DeFi protocol where a position
|
|
10
10
|
* is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-defi-positions-v6.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EACnB,+BAA+B;AAChC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AAWzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"group-defi-positions-v6.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,E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;IACrB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,SAAS,EAAE,yBAAyB,EAAE,CAAC;IACvC;;;OAGG;IACH,QAAQ,EAAE,0BAA0B,EAAE,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,EAAE,CAAC;CAClD,CAAC;AAyJF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,kBAAkB,EAC5B,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,sBAAsB,CA6FxB"}
|
|
@@ -4,7 +4,7 @@ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
|
|
|
4
4
|
* Possible `positionType` values from Accounts API v6 DeFi metadata.
|
|
5
5
|
* Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.
|
|
6
6
|
*/
|
|
7
|
-
export declare const DEFI_POSITION_TYPES: readonly ["deposit", "
|
|
7
|
+
export declare const DEFI_POSITION_TYPES: readonly ["deposit", "loan", "locked", "staked", "reward", "wallet", "investment"];
|
|
8
8
|
/**
|
|
9
9
|
* The specific module or functionality within a DeFi protocol where a position
|
|
10
10
|
* is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-defi-positions-v6.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EACnB,+BAA+B;AAChC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AAWzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"group-defi-positions-v6.d.mts","sourceRoot":"","sources":["../../src/DeFiPosition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M,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,SAAS,EAAE,yBAAyB,EAAE,CAAC;IACvC;;;OAGG;IACH,QAAQ,EAAE,0BAA0B,EAAE,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,EAAE,CAAC;CAClD,CAAC;AAyJF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,kBAAkB,EAC5B,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,sBAAsB,CA6FxB"}
|
|
@@ -11,7 +11,7 @@ export const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;
|
|
|
11
11
|
* Position types whose fiat value is a liability and is subtracted from the
|
|
12
12
|
* protocol group's aggregated `marketValue`.
|
|
13
13
|
*/
|
|
14
|
-
export const DEFI_POSITION_LIABILITY_TYPES = new Set(['
|
|
14
|
+
export const DEFI_POSITION_LIABILITY_TYPES = new Set(['loan']);
|
|
15
15
|
// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple
|
|
16
16
|
// underlyings. Display-only.
|
|
17
17
|
const SYMBOL_PRIORITY = ['ETH', 'WETH'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-defi-positions-v6.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,+BAA+B;AAYhE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EACjB,wBAAwB;AAEzB,+EAA+E;AAC/E,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AAEjE;;;GAGG;A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AAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['lending']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"group-defi-positions-v6.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,+BAA+B;AAYhE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EACjB,wBAAwB;AAEzB,+EAA+E;AAC/E,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AAEjE;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAQ1D;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GACxC,IAAI,GAAG,CAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;AAuFtC,gFAAgF;AAChF,6BAA6B;AAC7B,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAIxC;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,OAAsB;IAClD,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,OAAO,C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,UAAU;iBACjC,CAAC,CAAC;YACL,CAAC;YAED,sEAAsE;YACtE,wDAAwD;YACxD,IAAI,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAC/B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,KAAK,WAAW,CAC3C,CAAC;YACF,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;gBACzC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,kBAAkB,EAAE,CAAC;QAC1D,MAAM,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['loan']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
|
|
@@ -274,7 +274,7 @@ exports.SPOT_PRICES_SUPPORT_INFO = {
|
|
|
274
274
|
'0x1079': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset
|
|
275
275
|
'0x10e6': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH
|
|
276
276
|
'0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT
|
|
277
|
-
'0x13b2': 'eip155:5042/
|
|
277
|
+
'0x13b2': 'eip155:5042/slip44:5042', // Arc - Native symbol: USDC
|
|
278
278
|
'0x1b58': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA
|
|
279
279
|
'0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH
|
|
280
280
|
'0x1237': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codefi-v2.cjs","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAOoC;AAGpC,2CAKyB;AAYzB;;;;GAIG;AACU,QAAA,6BAA6B,GAAG;IAC3C,UAAU;IACV,KAAK;IACL,QAAQ;IACR,KAAK;IACL,WAAW;IACX,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,SAAS;IACT,KAAK;IACL,YAAY;IACZ,MAAM;IACN,WAAW;IACX,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,YAAY;IACZ,KAAK;IACL,8BAA8B;IAC9B,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL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GAAG,2BAAmB,CAAC,CAAC;SAC3D,CAAC;QACF,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ,IAAI,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,CACtE,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,yBAAyB,CAAC,QAAiB;QACzC,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;QACrD,OAAO,CACL,OAAO,QAAQ,KAAK,QAAQ;YAC5B,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,yBAAyB;QAC7B,OAAO,wBAAwB,EAAE,CAAC;IACpC,CAAC;CACF;AA5XD,gEA4XC","sourcesContent":["import {\n createServicePolicy,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n handleFetch,\n} from '@metamask/controller-utils';\nimport type { ServicePolicy } from '@metamask/controller-utils';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\nimport {\n hexToNumber,\n KnownCaipNamespace,\n numberToHex,\n toCaipChainId,\n} from '@metamask/utils';\n\nimport type { MarketDataDetails } from '../TokenRatesController.js';\nimport type {\n AbstractTokenPricesService,\n EvmAssetAddressWithChain,\n EvmAssetWithId,\n EvmAssetWithMarketData,\n ExchangeRatesByCurrency,\n NativeAssetIdentifiersMap,\n} from './abstract-token-prices-service.js';\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 * This is the fallback list used when the API is unavailable.\n */\nexport const SUPPORTED_CURRENCIES_FALLBACK = [\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 // Georgian Lari\n 'gel',\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 // Monad\n 'mon',\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 // Colombian Peso\n 'cop',\n // Kenyan Shilling\n 'kes',\n // Romanian Leu\n 'ron',\n // Dominican Peso\n 'dop',\n // Costa Rican Colón\n 'crc',\n // Honduran Lempira\n 'hnl',\n // Zambian Kwacha\n 'zmw',\n // Salvadoran Colón\n 'svc',\n // Bosnia-Herzegovina Convertible Mark\n 'bam',\n // Peruvian Sol\n 'pen',\n // Guatemalan Quetzal\n 'gtq',\n // Lebanese Pound\n 'lbp',\n // Armenian Dram\n 'amd',\n // Solana\n 'sol',\n // Sei\n 'sei',\n // Sonic\n 'sonic',\n // Tron\n 'trx',\n // Taiko\n 'taiko',\n // Pepu\n 'pepu',\n // Polygon\n 'pol',\n // Mantle\n 'mnt',\n // Onomy\n 'nom',\n // Avalanche\n 'avax',\n // Apechain\n 'ape',\n] as const;\n\n/**\n * @deprecated Use `getSupportedCurrencies()` or `fetchSupportedCurrencies()` instead.\n * This is an alias for backward compatibility.\n */\nexport const SUPPORTED_CURRENCIES = SUPPORTED_CURRENCIES_FALLBACK;\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 mapping from chain id to the address of the chain's native token.\n * Only for chains whose native tokens have a specific address.\n */\nconst chainIdToNativeTokenAddress: Record<Hex, Hex> = {\n '0x89': '0x0000000000000000000000000000000000001010', // Polygon\n '0x440': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda\n '0x1388': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle\n};\n\n/**\n * Returns the address that should be used to query the price api for the\n * chain's native token. On most chains, this is signified by the zero address.\n * But on some chains, the native token has a specific address.\n *\n * @param chainId - The hexadecimal chain id.\n * @returns The address of the chain's native token.\n */\nexport const getNativeTokenAddress = (chainId: Hex): Hex =>\n chainIdToNativeTokenAddress[chainId] ?? ZERO_ADDRESS;\n\n// Source: https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts\n// This list is ONLY for chains that are supported by the Price API v3/spot-prices endpoint.\n// Please check that endpoint returns a price for the given assetId before including it in this list.\n// Please include a comment with the name of the chain and the native symbol.\n// Please keep the list sorted by chain ID.\nexport const SPOT_PRICES_SUPPORT_INFO = {\n '0x1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH\n '0xa': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH\n '0x19': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO\n '0x1e': 'eip155:30/slip44:137', // Rootstock Mainnet - Native symbol: RBTC\n '0x2a': 'eip155:42/erc20:0x0000000000000000000000000000000000000000', // Lukso - native symbol: LYX\n '0x32': 'eip155:50/erc20:0x0000000000000000000000000000000000000000', // xdc-network - native symbol: XDC\n '0x38': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB\n '0x39': 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS\n '0x52': 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR\n '0x58': 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO\n '0x64': 'eip155:100/erc20:0x0000000000000000000000000000000000000000', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI\n '0x6a': 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX\n '0x7a': 'eip155:122/erc20:0x0000000000000000000000000000000000000000', // Fuse Mainnet - Native symbol: FUSE\n '0x80': 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT\n '0x89': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL\n '0x8f': 'eip155:143/slip44:268435779', // Monad Mainnet - Native symbol: MON\n '0x92': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S\n '0xc4': 'eip155:196/erc20:0x0000000000000000000000000000000000000000', // X Layer Mainnet - Native symbol: OKB\n '0xe8': 'eip155:232/erc20:0x0000000000000000000000000000000000000000', // Lens Mainnet - Native symbol: GHO\n '0xfa': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM\n '0xfc': 'eip155:252/erc20:0x0000000000000000000000000000000000000000', // Fraxtal - native symbol: FRAX\n '0x120': 'eip155:288/slip44:60', // Boba Network (Ethereum L2) - Native symbol: ETH\n '0x141': 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS\n '0x144': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH\n '0x150': 'eip155:336/slip44:809', // Shiden - Native symbol: SDN\n '0x169': 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL\n '0x2eb': 'eip155:747/slip44:539', // Flow evm - Native symbol: Flow\n '0x3dc': 'eip155:988/erc20:0x0000000000000000000000000000000000000000', // Stable - Native symbol: USDT0\n '0x3e7': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: HYPE\n '0x440': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS\n '0x44d': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH\n '0x504': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR\n '0x505': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR\n '0x531': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI\n '0x6f0': 'eip155:1776/slip44:22000119', // Injective Mainnet - Native symbol: INJ\n '0x74c': 'eip155:1868/erc20:0x0000000000000000000000000000000000000000', // Soneium - Native symbol: ETH\n '0x9dd': 'eip155:2525/erc20:0x0000000000000000000000000000000000000000', // inEVM Mainnet - Native symbol: INV\n '0xab5': 'eip155:2741/erc20:0x0000000000000000000000000000000000000000', // Abstract - Native symbol: ETH\n '0x1079': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset\n '0x10e6': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH\n '0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT\n '0x13b2': 'eip155:5042/erc20:0x0000000000000000000000000000000000000000', // Arc - Native symbol: USDC\n '0x1b58': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA\n '0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH\n '0x1237': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH\n '0x2611': 'eip155:9745/erc20:0x0000000000000000000000000000000000000000', // Plasma mainnet - native symbol: XPL\n '0x2710': 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH\n '0x8173': 'eip155:33139/erc20:0x0000000000000000000000000000000000000000', // Apechain Mainnet - Native symbol: APE\n '0xa3c3': 'eip155:41923/erc20:0x0000000000000000000000000000000000000000', // EDU Chain - Native symbol: EDU\n '0xa4b1': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH\n '0xa4ec': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO\n '0xa516': 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE\n '0xa5bf': 'eip155:42431/slip44:60', // Tempo Testnet Moderato - No native asset\n '0xa729': 'eip155:42793/erc20:0x0000000000000000000000000000000000000000', // Etherlink - Native symbol: XTZ (Tezos L2)\n '0xa867': 'eip155:43111/erc20:0x0000000000000000000000000000000000000000', // Hemi - Native symbol: ETH\n '0xa86a': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX\n '0xdef1': 'eip155:57073/slip44:60', // Ink Mainnet - Native symbol: ETH\n '0xe708': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH\n '0xed88': 'eip155:60808/erc20:0x0000000000000000000000000000000000000000', // BOB - Native symbol: ETH\n '0x10b3e': 'eip155:68414/erc20:0x0000000000000000000000000000000000000000', // MapleStory Universe - no slip44\n '0x11d9b': 'eip155:73115/erc20:0x0000000000000000000000000000000000000000', // ICB Network - Native symbol: ICBX,\n '0x138de': 'eip155:80094/erc20:0x0000000000000000000000000000000000000000', // Berachain - Native symbol: Bera',\n '0x13e31': 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH\n '0x15b38': 'eip155:88888/erc20:0x0000000000000000000000000000000000000000', // Chiliz Chain - Native symbol: CHZ\n '0x17dcd': 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // Pepe Unchained Mainnet - Native symbol: PEPU\n '0x18232': 'eip155:98866/erc20:0x0000000000000000000000000000000000000000', // Plume Mainnet - Narive symbol: Plume\n '0x28c58': 'eip155:167000/slip44:60', // Taiko Mainnet - Native symbol: ETH\n '0x518af': 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS\n '0x82750': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH\n '0xb67d2': 'eip155:747474/erc20:0x0000000000000000000000000000000000000000', // katana - Native symbol: ETH\n '0xf043a': 'eip155:984122/erc20:0x0000000000000000000000000000000000000000', // Forma - Native symbol: TIA (Celestia)\n '0x15f900': 'eip155:1440000/erc20:0x0000000000000000000000000000000000000000', // xrpl-evm - native symbol: XRP\n '0x4e454152': 'eip155:1313161554/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH\n '0x63564c40': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE\n} as const;\n\n// MISSING CHAINS WITH NO NATIVE ASSET PRICES\n// '0x42': 'eip155:66/slip44:996', // OKXChain Mainnet - Native symbol: OKT\n// '0x46': 'eip155:70/slip44:1170', // Hoo Smart Chain - Native symbol: HOO\n// '0x926': 'eip155:2342/erc20:0x0000000000000000000000000000000000000000', // Omnia Chain - Native symbol: OMNIA\n// '0x407b': 'eip155:16507/erc20:0x0000000000000000000000000000000000000000', // Genesys Mainnet - Native symbol: GSYS\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_FALLBACK)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES_FALLBACK)[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 *\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 = Object.keys(\n SPOT_PRICES_SUPPORT_INFO,\n) as (keyof typeof SPOT_PRICES_SUPPORT_INFO)[];\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\nconst BASE_URL_V1 = 'https://price.api.cx.metamask.io/v1';\n\nconst BASE_URL_V2 = 'https://price.api.cx.metamask.io/v2';\n\nconst BASE_URL_V3 = 'https://price.api.cx.metamask.io/v3';\n\n/**\n * Response type for the /v2/supportedNetworks endpoint.\n */\ntype SupportedNetworksResponse = {\n fullSupport: string[];\n partialSupport: {\n spotPricesV2: string[];\n spotPricesV3: string[];\n };\n};\n\n/**\n * In-memory store for the last successfully fetched supported networks.\n */\nlet lastFetchedSupportedNetworks: SupportedNetworksResponse | null = null;\n\n/**\n * In-flight promise to prevent concurrent requests to the supported networks endpoint.\n */\nlet runningSupportedNetworksRequest: Promise<SupportedNetworksResponse> | null =\n null;\n\n/**\n * Converts a CAIP-2 chain ID (e.g., 'eip155:1') to a hex chain ID (e.g., '0x1').\n *\n * @param caipChainId - The CAIP-2 chain ID string.\n * @returns The hex chain ID or null if not an EIP-155 chain.\n */\nfunction caipChainIdToHex(caipChainId: string): Hex | null {\n const match = caipChainId.match(/^eip155:(\\d+)$/u);\n if (!match) {\n return null;\n }\n return numberToHex(parseInt(match[1], 10));\n}\n\n/**\n * Executes the actual fetch to the supported networks endpoint.\n * Handles errors internally by falling back to the hardcoded list,\n * and clears the in-flight promise when done.\n *\n * @returns The supported networks response.\n */\nasync function executeSupportedNetworksFetch(): Promise<SupportedNetworksResponse> {\n try {\n const url = `${BASE_URL_V2}/supportedNetworks`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (\n response &&\n typeof response === 'object' &&\n 'fullSupport' in response &&\n 'partialSupport' in response\n ) {\n lastFetchedSupportedNetworks = response as SupportedNetworksResponse;\n return lastFetchedSupportedNetworks;\n }\n\n // Invalid response format, fall back to hardcoded list\n return getSupportedNetworksFallback();\n } catch {\n // On any error, fall back to the hardcoded list\n return getSupportedNetworksFallback();\n } finally {\n // Clear the in-flight promise once the request completes\n runningSupportedNetworksRequest = null;\n }\n}\n\n/**\n * Fetches the list of supported networks from the API.\n * Falls back to the hardcoded list if the fetch fails.\n * Deduplicates concurrent requests by returning the same promise if a fetch is already in progress.\n *\n * @returns The supported networks response.\n */\nexport async function fetchSupportedNetworks(): Promise<SupportedNetworksResponse> {\n // If a fetch is already in progress, return the same promise\n if (runningSupportedNetworksRequest) {\n return runningSupportedNetworksRequest;\n }\n\n // Start a new fetch and cache the promise\n runningSupportedNetworksRequest = executeSupportedNetworksFetch();\n\n return runningSupportedNetworksRequest;\n}\n\n/**\n * Synchronously gets the list of supported networks.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The supported networks response.\n */\nexport function getSupportedNetworks(): SupportedNetworksResponse {\n if (lastFetchedSupportedNetworks !== null) {\n return lastFetchedSupportedNetworks;\n }\n return getSupportedNetworksFallback();\n}\n\n/**\n * Generates a fallback supported networks response from the hardcoded SPOT_PRICES_SUPPORT_INFO.\n *\n * @returns A SupportedNetworksResponse derived from hardcoded data.\n */\nfunction getSupportedNetworksFallback(): SupportedNetworksResponse {\n const caipChainIds = Object.keys(SPOT_PRICES_SUPPORT_INFO).map((hexChainId) =>\n toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(hexChainId as Hex).toString(),\n ),\n );\n\n return {\n fullSupport: caipChainIds.slice(0, 11), // First 11 chains as \"full support\"\n partialSupport: {\n spotPricesV2: caipChainIds,\n spotPricesV3: caipChainIds,\n },\n };\n}\n\n/**\n * Resets the supported networks cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedNetworksCache(): void {\n lastFetchedSupportedNetworks = null;\n runningSupportedNetworksRequest = null;\n}\n\n/**\n * Gets the list of supported chain IDs for spot prices v3 as hex values.\n *\n * @returns Array of hex chain IDs supported by spot prices v3.\n */\nfunction getSupportedChainIdsV3AsHex(): Hex[] {\n const supportedNetworks = getSupportedNetworks();\n const allV3Chains = [\n ...supportedNetworks.fullSupport,\n ...supportedNetworks.partialSupport.spotPricesV3,\n ];\n\n return allV3Chains\n .map(caipChainIdToHex)\n .filter((hexChainId): hexChainId is Hex => hexChainId !== null);\n}\n\n/**\n * In-memory store for the last successfully fetched supported currencies.\n */\nlet lastFetchedCurrencies: string[] | null = null;\n\n/**\n * Fetches the list of supported currencies from the API.\n * Falls back to the hardcoded list if the fetch fails.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport async function fetchSupportedCurrencies(): Promise<string[]> {\n try {\n const url = `${BASE_URL_V1}/supportedVsCurrencies`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (Array.isArray(response)) {\n const currencies = response.map((currency: string) =>\n currency.toLowerCase(),\n );\n lastFetchedCurrencies = currencies;\n return currencies;\n }\n\n // Invalid response format, fall back to hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n } catch {\n // On any error, fall back to the hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n }\n}\n\n/**\n * Synchronously gets the list of supported currencies.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport function getSupportedCurrencies(): readonly string[] {\n if (lastFetchedCurrencies !== null) {\n return lastFetchedCurrencies;\n }\n return SUPPORTED_CURRENCIES_FALLBACK;\n}\n\n/**\n * Resets the supported currencies cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedCurrenciesCache(): void {\n lastFetchedCurrencies = null;\n}\n\n/**\n * Derives the CAIP-19 asset ID used to query the Price API for a token on a\n * given chain.\n *\n * For native tokens, uses the hardcoded {@link SPOT_PRICES_SUPPORT_INFO} entry\n * when defined, otherwise falls back to the provided native asset identifiers\n * (sourced from NetworkEnablementController). For ERC20 tokens, constructs the\n * CAIP-19 ID dynamically.\n *\n * @param args - The arguments to this function.\n * @param args.chainId - The hexadecimal chain ID the token lives on.\n * @param args.tokenAddress - The token's address.\n * @param args.nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset\n * identifiers, used as a fallback for native tokens.\n * @returns The CAIP-19 asset ID, or undefined if it cannot be determined.\n */\nexport function getAssetId({\n chainId,\n tokenAddress,\n nativeAssetIdentifiers = {},\n}: {\n chainId: Hex;\n tokenAddress: string;\n nativeAssetIdentifiers?: NativeAssetIdentifiersMap;\n}): CaipAssetType | undefined {\n try {\n const caipChainId = toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(chainId).toString(),\n );\n\n const nativeAddress = getNativeTokenAddress(chainId);\n const isNativeToken =\n nativeAddress.toLowerCase() === tokenAddress.toLowerCase();\n\n if (isNativeToken) {\n const hardcodedId = (\n SPOT_PRICES_SUPPORT_INFO as Partial<Record<Hex, string>>\n )[chainId];\n return (hardcodedId ?? nativeAssetIdentifiers[caipChainId]) as\n | CaipAssetType\n | undefined;\n }\n\n return `${caipChainId}/erc20:${tokenAddress.toLowerCase()}` as CaipAssetType;\n } catch {\n // This block should never be reached as long as using Typescript, but added for safety.\n return undefined;\n }\n}\n\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 implements AbstractTokenPricesService<\n SupportedChainId,\n SupportedCurrency\n> {\n readonly #policy: ServicePolicy;\n\n /**\n * Map of CAIP-2 chain IDs to their native asset identifiers.\n * Updated via setNativeAssetIdentifiers().\n */\n #nativeAssetIdentifiers: NativeAssetIdentifiersMap = {};\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n });\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @deprecated This signature is deprecated; please use the `onBreak` and\n * `onDegraded` methods instead.\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.onBreak - Callback for when the circuit breaks, useful\n * for capturing metrics about network failures.\n * @param args.onDegraded - Callback for when the API responds successfully\n * but takes too long to respond (5 seconds or more).\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n });\n\n constructor({\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_MAX_RETRIES,\n maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n onBreak,\n onDegraded,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n }: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n } = {}) {\n this.#policy = createServicePolicy({\n maxRetries: retries,\n maxConsecutiveFailures: maximumConsecutiveFailures,\n circuitBreakDuration,\n degradedThreshold,\n });\n if (onBreak) {\n this.#policy.onBreak(onBreak);\n }\n if (onDegraded) {\n this.#policy.onDegraded(onDegraded);\n }\n }\n\n /**\n * Listens for when the request to the API fails too many times in a row.\n *\n * @param args - The same arguments that {@link ServicePolicy.onBreak}\n * takes.\n * @returns What {@link ServicePolicy.onBreak} returns.\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Listens for when the API is degraded.\n *\n * @param args - The same arguments that {@link ServicePolicy.onDegraded}\n * takes.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n /**\n * Sets the native asset identifiers map for resolving native token CAIP-19 IDs.\n * This should be called with data from NetworkEnablementController.state.nativeAssetIdentifiers.\n *\n * @param nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset identifiers.\n */\n setNativeAssetIdentifiers(\n nativeAssetIdentifiers: NativeAssetIdentifiersMap,\n ): void {\n this.#nativeAssetIdentifiers = nativeAssetIdentifiers;\n }\n\n /**\n * Updates the supported networks cache by fetching from the API.\n * This should be called periodically to keep the supported networks list fresh.\n *\n * @returns The updated supported networks response.\n */\n async updateSupportedNetworks(): Promise<SupportedNetworksResponse> {\n return fetchSupportedNetworks();\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.assets - The assets to get prices for.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n async fetchTokenPrices({\n assets,\n currency,\n }: {\n assets: EvmAssetAddressWithChain<SupportedChainId>[];\n currency: SupportedCurrency;\n }): Promise<EvmAssetWithMarketData<SupportedChainId, SupportedCurrency>[]> {\n // Refresh supported networks in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedNetworks handles errors internally and always resolves\n if (!lastFetchedSupportedNetworks) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedNetworks();\n }\n\n // Get dynamically fetched supported chain IDs for V3\n const supportedChainIdsV3 = getSupportedChainIdsV3AsHex();\n\n const assetsWithIds: EvmAssetWithId<SupportedChainId>[] = assets\n // Filter out assets that are not supported by V3 of the Price API.\n .filter((asset) => supportedChainIdsV3.includes(asset.chainId))\n .map((asset) => {\n const assetId = getAssetId({\n chainId: asset.chainId,\n tokenAddress: asset.tokenAddress,\n nativeAssetIdentifiers: this.#nativeAssetIdentifiers,\n });\n\n if (!assetId) {\n return undefined;\n }\n\n return {\n ...asset,\n assetId,\n };\n })\n .filter(\n (asset): asset is EvmAssetWithId<SupportedChainId> =>\n asset !== undefined,\n );\n\n if (assetsWithIds.length === 0) {\n return [];\n }\n\n const url = new URL(`${BASE_URL_V3}/spot-prices`);\n url.searchParams.append(\n 'assetIds',\n assetsWithIds.map((asset) => asset.assetId).join(','),\n );\n url.searchParams.append('vsCurrency', currency);\n url.searchParams.append('includeMarketData', 'true');\n\n const addressCryptoDataMap: {\n [assetId: CaipAssetType]: Omit<\n MarketDataDetails,\n 'currency' | 'tokenAddress'\n >;\n } = await this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n );\n\n return assetsWithIds\n .map((assetWithId) => {\n const marketData = addressCryptoDataMap[assetWithId.assetId];\n\n if (!marketData) {\n return undefined;\n }\n\n return {\n ...marketData,\n ...assetWithId,\n currency,\n };\n })\n .filter((entry): entry is NonNullable<typeof entry> => Boolean(entry));\n }\n\n /**\n * Retrieves exchange rates in the given base currency.\n *\n * @param args - The arguments to this function.\n * @param args.baseCurrency - The desired base currency of the exchange rates.\n * @param args.includeUsdRate - Whether to include the USD rate in the response.\n * @param args.cryptocurrencies - The cryptocurrencies to get exchange rates for.\n * @returns The exchange rates for the requested base currency.\n */\n async fetchExchangeRates({\n baseCurrency,\n includeUsdRate,\n cryptocurrencies,\n }: {\n baseCurrency: SupportedCurrency;\n includeUsdRate: boolean;\n cryptocurrencies: string[];\n }): Promise<ExchangeRatesByCurrency<SupportedCurrency>> {\n // Refresh supported currencies in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedCurrencies handles errors internally and always resolves\n if (!lastFetchedCurrencies) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedCurrencies();\n }\n\n const url = new URL(`${BASE_URL_V1}/exchange-rates`);\n url.searchParams.append('baseCurrency', baseCurrency);\n\n const urlUsd = new URL(`${BASE_URL_V1}/exchange-rates`);\n urlUsd.searchParams.append('baseCurrency', 'usd');\n\n const [exchangeRatesResult, exchangeRatesResultUsd] =\n await Promise.allSettled([\n this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n ),\n ...(includeUsdRate && baseCurrency.toLowerCase() !== 'usd'\n ? [\n this.#policy.execute(() =>\n handleFetch(urlUsd, {\n headers: { 'Cache-Control': 'no-cache' },\n }),\n ),\n ]\n : []),\n ]);\n\n // Handle resolved/rejected\n const exchangeRates =\n exchangeRatesResult.status === 'fulfilled'\n ? exchangeRatesResult.value\n : {};\n const exchangeRatesUsd =\n exchangeRatesResultUsd?.status === 'fulfilled'\n ? exchangeRatesResultUsd.value\n : {};\n\n if (exchangeRatesResult.status === 'rejected') {\n throw new Error('Failed to fetch');\n }\n\n const filteredExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRates[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRates[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (Object.keys(filteredExchangeRates).length === 0) {\n throw new Error(\n 'None of the cryptocurrencies are supported by price api',\n );\n }\n\n const filteredUsdExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRatesUsd[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRatesUsd[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (baseCurrency.toLowerCase() === 'usd') {\n Object.keys(filteredExchangeRates).forEach((key) => {\n filteredExchangeRates[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n usd: filteredExchangeRates[key as SupportedCurrency]?.value,\n };\n });\n return filteredExchangeRates;\n }\n if (!includeUsdRate) {\n return filteredExchangeRates;\n }\n\n const merged = Object.keys(filteredExchangeRates).reduce((acc, key) => {\n acc[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n ...(filteredUsdExchangeRates[key as SupportedCurrency]?.value\n ? { usd: filteredUsdExchangeRates[key as SupportedCurrency]?.value }\n : {}),\n };\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n return merged;\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 // Use dynamically fetched supported networks\n const supportedChainIds = getSupportedChainIdsV3AsHex();\n // Also include the hardcoded fallback list for backwards compatibility\n const allSupportedChainIds: readonly string[] = [\n ...new Set([...supportedChainIds, ...SUPPORTED_CHAIN_IDS]),\n ];\n return (\n typeof chainId === 'string' && allSupportedChainIds.includes(chainId)\n );\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 = getSupportedCurrencies();\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n\n /**\n * Fetches the list of supported currencies from the API.\n *\n * @returns The list of supported currencies.\n */\n async updateSupportedCurrencies(): Promise<string[]> {\n return fetchSupportedCurrencies();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"codefi-v2.cjs","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAOoC;AAGpC,2CAKyB;AAYzB;;;;GAIG;AACU,QAAA,6BAA6B,GAAG;IAC3C,UAAU;IACV,KAAK;IACL,QAAQ;IACR,KAAK;IACL,WAAW;IACX,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,SAAS;IACT,KAAK;IACL,YAAY;IACZ,MAAM;IACN,WAAW;IACX,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,YAAY;IACZ,KAAK;IACL,8BAA8B;IAC9B,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,cAAc;IACd,KAAK;IACL,kBAAkB;IAClB,KAAK;IACL,cAAc;IACd,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,OAAO;IACP,KAAK;IACL,yBAAyB;IACzB,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL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AC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,yBAAyB;QAC7B,OAAO,wBAAwB,EAAE,CAAC;IACpC,CAAC;CACF;AA5XD,gEA4XC","sourcesContent":["import {\n createServicePolicy,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n handleFetch,\n} from '@metamask/controller-utils';\nimport type { ServicePolicy } from '@metamask/controller-utils';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\nimport {\n hexToNumber,\n KnownCaipNamespace,\n numberToHex,\n toCaipChainId,\n} from '@metamask/utils';\n\nimport type { MarketDataDetails } from '../TokenRatesController.js';\nimport type {\n AbstractTokenPricesService,\n EvmAssetAddressWithChain,\n EvmAssetWithId,\n EvmAssetWithMarketData,\n ExchangeRatesByCurrency,\n NativeAssetIdentifiersMap,\n} from './abstract-token-prices-service.js';\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 * This is the fallback list used when the API is unavailable.\n */\nexport const SUPPORTED_CURRENCIES_FALLBACK = [\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 // Georgian Lari\n 'gel',\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 // Monad\n 'mon',\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 // Colombian Peso\n 'cop',\n // Kenyan Shilling\n 'kes',\n // Romanian Leu\n 'ron',\n // Dominican Peso\n 'dop',\n // Costa Rican Colón\n 'crc',\n // Honduran Lempira\n 'hnl',\n // Zambian Kwacha\n 'zmw',\n // Salvadoran Colón\n 'svc',\n // Bosnia-Herzegovina Convertible Mark\n 'bam',\n // Peruvian Sol\n 'pen',\n // Guatemalan Quetzal\n 'gtq',\n // Lebanese Pound\n 'lbp',\n // Armenian Dram\n 'amd',\n // Solana\n 'sol',\n // Sei\n 'sei',\n // Sonic\n 'sonic',\n // Tron\n 'trx',\n // Taiko\n 'taiko',\n // Pepu\n 'pepu',\n // Polygon\n 'pol',\n // Mantle\n 'mnt',\n // Onomy\n 'nom',\n // Avalanche\n 'avax',\n // Apechain\n 'ape',\n] as const;\n\n/**\n * @deprecated Use `getSupportedCurrencies()` or `fetchSupportedCurrencies()` instead.\n * This is an alias for backward compatibility.\n */\nexport const SUPPORTED_CURRENCIES = SUPPORTED_CURRENCIES_FALLBACK;\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 mapping from chain id to the address of the chain's native token.\n * Only for chains whose native tokens have a specific address.\n */\nconst chainIdToNativeTokenAddress: Record<Hex, Hex> = {\n '0x89': '0x0000000000000000000000000000000000001010', // Polygon\n '0x440': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda\n '0x1388': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle\n};\n\n/**\n * Returns the address that should be used to query the price api for the\n * chain's native token. On most chains, this is signified by the zero address.\n * But on some chains, the native token has a specific address.\n *\n * @param chainId - The hexadecimal chain id.\n * @returns The address of the chain's native token.\n */\nexport const getNativeTokenAddress = (chainId: Hex): Hex =>\n chainIdToNativeTokenAddress[chainId] ?? ZERO_ADDRESS;\n\n// Source: https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts\n// This list is ONLY for chains that are supported by the Price API v3/spot-prices endpoint.\n// Please check that endpoint returns a price for the given assetId before including it in this list.\n// Please include a comment with the name of the chain and the native symbol.\n// Please keep the list sorted by chain ID.\nexport const SPOT_PRICES_SUPPORT_INFO = {\n '0x1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH\n '0xa': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH\n '0x19': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO\n '0x1e': 'eip155:30/slip44:137', // Rootstock Mainnet - Native symbol: RBTC\n '0x2a': 'eip155:42/erc20:0x0000000000000000000000000000000000000000', // Lukso - native symbol: LYX\n '0x32': 'eip155:50/erc20:0x0000000000000000000000000000000000000000', // xdc-network - native symbol: XDC\n '0x38': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB\n '0x39': 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS\n '0x52': 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR\n '0x58': 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO\n '0x64': 'eip155:100/erc20:0x0000000000000000000000000000000000000000', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI\n '0x6a': 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX\n '0x7a': 'eip155:122/erc20:0x0000000000000000000000000000000000000000', // Fuse Mainnet - Native symbol: FUSE\n '0x80': 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT\n '0x89': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL\n '0x8f': 'eip155:143/slip44:268435779', // Monad Mainnet - Native symbol: MON\n '0x92': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S\n '0xc4': 'eip155:196/erc20:0x0000000000000000000000000000000000000000', // X Layer Mainnet - Native symbol: OKB\n '0xe8': 'eip155:232/erc20:0x0000000000000000000000000000000000000000', // Lens Mainnet - Native symbol: GHO\n '0xfa': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM\n '0xfc': 'eip155:252/erc20:0x0000000000000000000000000000000000000000', // Fraxtal - native symbol: FRAX\n '0x120': 'eip155:288/slip44:60', // Boba Network (Ethereum L2) - Native symbol: ETH\n '0x141': 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS\n '0x144': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH\n '0x150': 'eip155:336/slip44:809', // Shiden - Native symbol: SDN\n '0x169': 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL\n '0x2eb': 'eip155:747/slip44:539', // Flow evm - Native symbol: Flow\n '0x3dc': 'eip155:988/erc20:0x0000000000000000000000000000000000000000', // Stable - Native symbol: USDT0\n '0x3e7': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: HYPE\n '0x440': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS\n '0x44d': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH\n '0x504': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR\n '0x505': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR\n '0x531': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI\n '0x6f0': 'eip155:1776/slip44:22000119', // Injective Mainnet - Native symbol: INJ\n '0x74c': 'eip155:1868/erc20:0x0000000000000000000000000000000000000000', // Soneium - Native symbol: ETH\n '0x9dd': 'eip155:2525/erc20:0x0000000000000000000000000000000000000000', // inEVM Mainnet - Native symbol: INV\n '0xab5': 'eip155:2741/erc20:0x0000000000000000000000000000000000000000', // Abstract - Native symbol: ETH\n '0x1079': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset\n '0x10e6': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH\n '0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT\n '0x13b2': 'eip155:5042/slip44:5042', // Arc - Native symbol: USDC\n '0x1b58': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA\n '0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH\n '0x1237': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH\n '0x2611': 'eip155:9745/erc20:0x0000000000000000000000000000000000000000', // Plasma mainnet - native symbol: XPL\n '0x2710': 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH\n '0x8173': 'eip155:33139/erc20:0x0000000000000000000000000000000000000000', // Apechain Mainnet - Native symbol: APE\n '0xa3c3': 'eip155:41923/erc20:0x0000000000000000000000000000000000000000', // EDU Chain - Native symbol: EDU\n '0xa4b1': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH\n '0xa4ec': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO\n '0xa516': 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE\n '0xa5bf': 'eip155:42431/slip44:60', // Tempo Testnet Moderato - No native asset\n '0xa729': 'eip155:42793/erc20:0x0000000000000000000000000000000000000000', // Etherlink - Native symbol: XTZ (Tezos L2)\n '0xa867': 'eip155:43111/erc20:0x0000000000000000000000000000000000000000', // Hemi - Native symbol: ETH\n '0xa86a': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX\n '0xdef1': 'eip155:57073/slip44:60', // Ink Mainnet - Native symbol: ETH\n '0xe708': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH\n '0xed88': 'eip155:60808/erc20:0x0000000000000000000000000000000000000000', // BOB - Native symbol: ETH\n '0x10b3e': 'eip155:68414/erc20:0x0000000000000000000000000000000000000000', // MapleStory Universe - no slip44\n '0x11d9b': 'eip155:73115/erc20:0x0000000000000000000000000000000000000000', // ICB Network - Native symbol: ICBX,\n '0x138de': 'eip155:80094/erc20:0x0000000000000000000000000000000000000000', // Berachain - Native symbol: Bera',\n '0x13e31': 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH\n '0x15b38': 'eip155:88888/erc20:0x0000000000000000000000000000000000000000', // Chiliz Chain - Native symbol: CHZ\n '0x17dcd': 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // Pepe Unchained Mainnet - Native symbol: PEPU\n '0x18232': 'eip155:98866/erc20:0x0000000000000000000000000000000000000000', // Plume Mainnet - Narive symbol: Plume\n '0x28c58': 'eip155:167000/slip44:60', // Taiko Mainnet - Native symbol: ETH\n '0x518af': 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS\n '0x82750': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH\n '0xb67d2': 'eip155:747474/erc20:0x0000000000000000000000000000000000000000', // katana - Native symbol: ETH\n '0xf043a': 'eip155:984122/erc20:0x0000000000000000000000000000000000000000', // Forma - Native symbol: TIA (Celestia)\n '0x15f900': 'eip155:1440000/erc20:0x0000000000000000000000000000000000000000', // xrpl-evm - native symbol: XRP\n '0x4e454152': 'eip155:1313161554/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH\n '0x63564c40': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE\n} as const;\n\n// MISSING CHAINS WITH NO NATIVE ASSET PRICES\n// '0x42': 'eip155:66/slip44:996', // OKXChain Mainnet - Native symbol: OKT\n// '0x46': 'eip155:70/slip44:1170', // Hoo Smart Chain - Native symbol: HOO\n// '0x926': 'eip155:2342/erc20:0x0000000000000000000000000000000000000000', // Omnia Chain - Native symbol: OMNIA\n// '0x407b': 'eip155:16507/erc20:0x0000000000000000000000000000000000000000', // Genesys Mainnet - Native symbol: GSYS\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_FALLBACK)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES_FALLBACK)[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 *\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 = Object.keys(\n SPOT_PRICES_SUPPORT_INFO,\n) as (keyof typeof SPOT_PRICES_SUPPORT_INFO)[];\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\nconst BASE_URL_V1 = 'https://price.api.cx.metamask.io/v1';\n\nconst BASE_URL_V2 = 'https://price.api.cx.metamask.io/v2';\n\nconst BASE_URL_V3 = 'https://price.api.cx.metamask.io/v3';\n\n/**\n * Response type for the /v2/supportedNetworks endpoint.\n */\ntype SupportedNetworksResponse = {\n fullSupport: string[];\n partialSupport: {\n spotPricesV2: string[];\n spotPricesV3: string[];\n };\n};\n\n/**\n * In-memory store for the last successfully fetched supported networks.\n */\nlet lastFetchedSupportedNetworks: SupportedNetworksResponse | null = null;\n\n/**\n * In-flight promise to prevent concurrent requests to the supported networks endpoint.\n */\nlet runningSupportedNetworksRequest: Promise<SupportedNetworksResponse> | null =\n null;\n\n/**\n * Converts a CAIP-2 chain ID (e.g., 'eip155:1') to a hex chain ID (e.g., '0x1').\n *\n * @param caipChainId - The CAIP-2 chain ID string.\n * @returns The hex chain ID or null if not an EIP-155 chain.\n */\nfunction caipChainIdToHex(caipChainId: string): Hex | null {\n const match = caipChainId.match(/^eip155:(\\d+)$/u);\n if (!match) {\n return null;\n }\n return numberToHex(parseInt(match[1], 10));\n}\n\n/**\n * Executes the actual fetch to the supported networks endpoint.\n * Handles errors internally by falling back to the hardcoded list,\n * and clears the in-flight promise when done.\n *\n * @returns The supported networks response.\n */\nasync function executeSupportedNetworksFetch(): Promise<SupportedNetworksResponse> {\n try {\n const url = `${BASE_URL_V2}/supportedNetworks`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (\n response &&\n typeof response === 'object' &&\n 'fullSupport' in response &&\n 'partialSupport' in response\n ) {\n lastFetchedSupportedNetworks = response as SupportedNetworksResponse;\n return lastFetchedSupportedNetworks;\n }\n\n // Invalid response format, fall back to hardcoded list\n return getSupportedNetworksFallback();\n } catch {\n // On any error, fall back to the hardcoded list\n return getSupportedNetworksFallback();\n } finally {\n // Clear the in-flight promise once the request completes\n runningSupportedNetworksRequest = null;\n }\n}\n\n/**\n * Fetches the list of supported networks from the API.\n * Falls back to the hardcoded list if the fetch fails.\n * Deduplicates concurrent requests by returning the same promise if a fetch is already in progress.\n *\n * @returns The supported networks response.\n */\nexport async function fetchSupportedNetworks(): Promise<SupportedNetworksResponse> {\n // If a fetch is already in progress, return the same promise\n if (runningSupportedNetworksRequest) {\n return runningSupportedNetworksRequest;\n }\n\n // Start a new fetch and cache the promise\n runningSupportedNetworksRequest = executeSupportedNetworksFetch();\n\n return runningSupportedNetworksRequest;\n}\n\n/**\n * Synchronously gets the list of supported networks.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The supported networks response.\n */\nexport function getSupportedNetworks(): SupportedNetworksResponse {\n if (lastFetchedSupportedNetworks !== null) {\n return lastFetchedSupportedNetworks;\n }\n return getSupportedNetworksFallback();\n}\n\n/**\n * Generates a fallback supported networks response from the hardcoded SPOT_PRICES_SUPPORT_INFO.\n *\n * @returns A SupportedNetworksResponse derived from hardcoded data.\n */\nfunction getSupportedNetworksFallback(): SupportedNetworksResponse {\n const caipChainIds = Object.keys(SPOT_PRICES_SUPPORT_INFO).map((hexChainId) =>\n toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(hexChainId as Hex).toString(),\n ),\n );\n\n return {\n fullSupport: caipChainIds.slice(0, 11), // First 11 chains as \"full support\"\n partialSupport: {\n spotPricesV2: caipChainIds,\n spotPricesV3: caipChainIds,\n },\n };\n}\n\n/**\n * Resets the supported networks cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedNetworksCache(): void {\n lastFetchedSupportedNetworks = null;\n runningSupportedNetworksRequest = null;\n}\n\n/**\n * Gets the list of supported chain IDs for spot prices v3 as hex values.\n *\n * @returns Array of hex chain IDs supported by spot prices v3.\n */\nfunction getSupportedChainIdsV3AsHex(): Hex[] {\n const supportedNetworks = getSupportedNetworks();\n const allV3Chains = [\n ...supportedNetworks.fullSupport,\n ...supportedNetworks.partialSupport.spotPricesV3,\n ];\n\n return allV3Chains\n .map(caipChainIdToHex)\n .filter((hexChainId): hexChainId is Hex => hexChainId !== null);\n}\n\n/**\n * In-memory store for the last successfully fetched supported currencies.\n */\nlet lastFetchedCurrencies: string[] | null = null;\n\n/**\n * Fetches the list of supported currencies from the API.\n * Falls back to the hardcoded list if the fetch fails.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport async function fetchSupportedCurrencies(): Promise<string[]> {\n try {\n const url = `${BASE_URL_V1}/supportedVsCurrencies`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (Array.isArray(response)) {\n const currencies = response.map((currency: string) =>\n currency.toLowerCase(),\n );\n lastFetchedCurrencies = currencies;\n return currencies;\n }\n\n // Invalid response format, fall back to hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n } catch {\n // On any error, fall back to the hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n }\n}\n\n/**\n * Synchronously gets the list of supported currencies.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport function getSupportedCurrencies(): readonly string[] {\n if (lastFetchedCurrencies !== null) {\n return lastFetchedCurrencies;\n }\n return SUPPORTED_CURRENCIES_FALLBACK;\n}\n\n/**\n * Resets the supported currencies cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedCurrenciesCache(): void {\n lastFetchedCurrencies = null;\n}\n\n/**\n * Derives the CAIP-19 asset ID used to query the Price API for a token on a\n * given chain.\n *\n * For native tokens, uses the hardcoded {@link SPOT_PRICES_SUPPORT_INFO} entry\n * when defined, otherwise falls back to the provided native asset identifiers\n * (sourced from NetworkEnablementController). For ERC20 tokens, constructs the\n * CAIP-19 ID dynamically.\n *\n * @param args - The arguments to this function.\n * @param args.chainId - The hexadecimal chain ID the token lives on.\n * @param args.tokenAddress - The token's address.\n * @param args.nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset\n * identifiers, used as a fallback for native tokens.\n * @returns The CAIP-19 asset ID, or undefined if it cannot be determined.\n */\nexport function getAssetId({\n chainId,\n tokenAddress,\n nativeAssetIdentifiers = {},\n}: {\n chainId: Hex;\n tokenAddress: string;\n nativeAssetIdentifiers?: NativeAssetIdentifiersMap;\n}): CaipAssetType | undefined {\n try {\n const caipChainId = toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(chainId).toString(),\n );\n\n const nativeAddress = getNativeTokenAddress(chainId);\n const isNativeToken =\n nativeAddress.toLowerCase() === tokenAddress.toLowerCase();\n\n if (isNativeToken) {\n const hardcodedId = (\n SPOT_PRICES_SUPPORT_INFO as Partial<Record<Hex, string>>\n )[chainId];\n return (hardcodedId ?? nativeAssetIdentifiers[caipChainId]) as\n | CaipAssetType\n | undefined;\n }\n\n return `${caipChainId}/erc20:${tokenAddress.toLowerCase()}` as CaipAssetType;\n } catch {\n // This block should never be reached as long as using Typescript, but added for safety.\n return undefined;\n }\n}\n\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 implements AbstractTokenPricesService<\n SupportedChainId,\n SupportedCurrency\n> {\n readonly #policy: ServicePolicy;\n\n /**\n * Map of CAIP-2 chain IDs to their native asset identifiers.\n * Updated via setNativeAssetIdentifiers().\n */\n #nativeAssetIdentifiers: NativeAssetIdentifiersMap = {};\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n });\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @deprecated This signature is deprecated; please use the `onBreak` and\n * `onDegraded` methods instead.\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.onBreak - Callback for when the circuit breaks, useful\n * for capturing metrics about network failures.\n * @param args.onDegraded - Callback for when the API responds successfully\n * but takes too long to respond (5 seconds or more).\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n });\n\n constructor({\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_MAX_RETRIES,\n maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n onBreak,\n onDegraded,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n }: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n } = {}) {\n this.#policy = createServicePolicy({\n maxRetries: retries,\n maxConsecutiveFailures: maximumConsecutiveFailures,\n circuitBreakDuration,\n degradedThreshold,\n });\n if (onBreak) {\n this.#policy.onBreak(onBreak);\n }\n if (onDegraded) {\n this.#policy.onDegraded(onDegraded);\n }\n }\n\n /**\n * Listens for when the request to the API fails too many times in a row.\n *\n * @param args - The same arguments that {@link ServicePolicy.onBreak}\n * takes.\n * @returns What {@link ServicePolicy.onBreak} returns.\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Listens for when the API is degraded.\n *\n * @param args - The same arguments that {@link ServicePolicy.onDegraded}\n * takes.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n /**\n * Sets the native asset identifiers map for resolving native token CAIP-19 IDs.\n * This should be called with data from NetworkEnablementController.state.nativeAssetIdentifiers.\n *\n * @param nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset identifiers.\n */\n setNativeAssetIdentifiers(\n nativeAssetIdentifiers: NativeAssetIdentifiersMap,\n ): void {\n this.#nativeAssetIdentifiers = nativeAssetIdentifiers;\n }\n\n /**\n * Updates the supported networks cache by fetching from the API.\n * This should be called periodically to keep the supported networks list fresh.\n *\n * @returns The updated supported networks response.\n */\n async updateSupportedNetworks(): Promise<SupportedNetworksResponse> {\n return fetchSupportedNetworks();\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.assets - The assets to get prices for.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n async fetchTokenPrices({\n assets,\n currency,\n }: {\n assets: EvmAssetAddressWithChain<SupportedChainId>[];\n currency: SupportedCurrency;\n }): Promise<EvmAssetWithMarketData<SupportedChainId, SupportedCurrency>[]> {\n // Refresh supported networks in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedNetworks handles errors internally and always resolves\n if (!lastFetchedSupportedNetworks) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedNetworks();\n }\n\n // Get dynamically fetched supported chain IDs for V3\n const supportedChainIdsV3 = getSupportedChainIdsV3AsHex();\n\n const assetsWithIds: EvmAssetWithId<SupportedChainId>[] = assets\n // Filter out assets that are not supported by V3 of the Price API.\n .filter((asset) => supportedChainIdsV3.includes(asset.chainId))\n .map((asset) => {\n const assetId = getAssetId({\n chainId: asset.chainId,\n tokenAddress: asset.tokenAddress,\n nativeAssetIdentifiers: this.#nativeAssetIdentifiers,\n });\n\n if (!assetId) {\n return undefined;\n }\n\n return {\n ...asset,\n assetId,\n };\n })\n .filter(\n (asset): asset is EvmAssetWithId<SupportedChainId> =>\n asset !== undefined,\n );\n\n if (assetsWithIds.length === 0) {\n return [];\n }\n\n const url = new URL(`${BASE_URL_V3}/spot-prices`);\n url.searchParams.append(\n 'assetIds',\n assetsWithIds.map((asset) => asset.assetId).join(','),\n );\n url.searchParams.append('vsCurrency', currency);\n url.searchParams.append('includeMarketData', 'true');\n\n const addressCryptoDataMap: {\n [assetId: CaipAssetType]: Omit<\n MarketDataDetails,\n 'currency' | 'tokenAddress'\n >;\n } = await this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n );\n\n return assetsWithIds\n .map((assetWithId) => {\n const marketData = addressCryptoDataMap[assetWithId.assetId];\n\n if (!marketData) {\n return undefined;\n }\n\n return {\n ...marketData,\n ...assetWithId,\n currency,\n };\n })\n .filter((entry): entry is NonNullable<typeof entry> => Boolean(entry));\n }\n\n /**\n * Retrieves exchange rates in the given base currency.\n *\n * @param args - The arguments to this function.\n * @param args.baseCurrency - The desired base currency of the exchange rates.\n * @param args.includeUsdRate - Whether to include the USD rate in the response.\n * @param args.cryptocurrencies - The cryptocurrencies to get exchange rates for.\n * @returns The exchange rates for the requested base currency.\n */\n async fetchExchangeRates({\n baseCurrency,\n includeUsdRate,\n cryptocurrencies,\n }: {\n baseCurrency: SupportedCurrency;\n includeUsdRate: boolean;\n cryptocurrencies: string[];\n }): Promise<ExchangeRatesByCurrency<SupportedCurrency>> {\n // Refresh supported currencies in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedCurrencies handles errors internally and always resolves\n if (!lastFetchedCurrencies) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedCurrencies();\n }\n\n const url = new URL(`${BASE_URL_V1}/exchange-rates`);\n url.searchParams.append('baseCurrency', baseCurrency);\n\n const urlUsd = new URL(`${BASE_URL_V1}/exchange-rates`);\n urlUsd.searchParams.append('baseCurrency', 'usd');\n\n const [exchangeRatesResult, exchangeRatesResultUsd] =\n await Promise.allSettled([\n this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n ),\n ...(includeUsdRate && baseCurrency.toLowerCase() !== 'usd'\n ? [\n this.#policy.execute(() =>\n handleFetch(urlUsd, {\n headers: { 'Cache-Control': 'no-cache' },\n }),\n ),\n ]\n : []),\n ]);\n\n // Handle resolved/rejected\n const exchangeRates =\n exchangeRatesResult.status === 'fulfilled'\n ? exchangeRatesResult.value\n : {};\n const exchangeRatesUsd =\n exchangeRatesResultUsd?.status === 'fulfilled'\n ? exchangeRatesResultUsd.value\n : {};\n\n if (exchangeRatesResult.status === 'rejected') {\n throw new Error('Failed to fetch');\n }\n\n const filteredExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRates[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRates[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (Object.keys(filteredExchangeRates).length === 0) {\n throw new Error(\n 'None of the cryptocurrencies are supported by price api',\n );\n }\n\n const filteredUsdExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRatesUsd[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRatesUsd[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (baseCurrency.toLowerCase() === 'usd') {\n Object.keys(filteredExchangeRates).forEach((key) => {\n filteredExchangeRates[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n usd: filteredExchangeRates[key as SupportedCurrency]?.value,\n };\n });\n return filteredExchangeRates;\n }\n if (!includeUsdRate) {\n return filteredExchangeRates;\n }\n\n const merged = Object.keys(filteredExchangeRates).reduce((acc, key) => {\n acc[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n ...(filteredUsdExchangeRates[key as SupportedCurrency]?.value\n ? { usd: filteredUsdExchangeRates[key as SupportedCurrency]?.value }\n : {}),\n };\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n return merged;\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 // Use dynamically fetched supported networks\n const supportedChainIds = getSupportedChainIdsV3AsHex();\n // Also include the hardcoded fallback list for backwards compatibility\n const allSupportedChainIds: readonly string[] = [\n ...new Set([...supportedChainIds, ...SUPPORTED_CHAIN_IDS]),\n ];\n return (\n typeof chainId === 'string' && allSupportedChainIds.includes(chainId)\n );\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 = getSupportedCurrencies();\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n\n /**\n * Fetches the list of supported currencies from the API.\n *\n * @returns The list of supported currencies.\n */\n async updateSupportedCurrencies(): Promise<string[]> {\n return fetchSupportedCurrencies();\n }\n}\n"]}
|
|
@@ -70,7 +70,7 @@ export declare const SPOT_PRICES_SUPPORT_INFO: {
|
|
|
70
70
|
readonly '0x1079': "eip155:4217/slip44:60";
|
|
71
71
|
readonly '0x10e6': "eip155:4326/erc20:0x0000000000000000000000000000000000000000";
|
|
72
72
|
readonly '0x1388': "eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
|
|
73
|
-
readonly '0x13b2': "eip155:5042/
|
|
73
|
+
readonly '0x13b2': "eip155:5042/slip44:5042";
|
|
74
74
|
readonly '0x1b58': "eip155:7000/slip44:7000";
|
|
75
75
|
readonly '0x2105': "eip155:8453/slip44:60";
|
|
76
76
|
readonly '0x1237': "eip155:4663/slip44:60";
|
|
@@ -70,7 +70,7 @@ export declare const SPOT_PRICES_SUPPORT_INFO: {
|
|
|
70
70
|
readonly '0x1079': "eip155:4217/slip44:60";
|
|
71
71
|
readonly '0x10e6': "eip155:4326/erc20:0x0000000000000000000000000000000000000000";
|
|
72
72
|
readonly '0x1388': "eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
|
|
73
|
-
readonly '0x13b2': "eip155:5042/
|
|
73
|
+
readonly '0x13b2': "eip155:5042/slip44:5042";
|
|
74
74
|
readonly '0x1b58': "eip155:7000/slip44:7000";
|
|
75
75
|
readonly '0x2105': "eip155:8453/slip44:60";
|
|
76
76
|
readonly '0x1237': "eip155:4663/slip44:60";
|
|
@@ -270,7 +270,7 @@ export const SPOT_PRICES_SUPPORT_INFO = {
|
|
|
270
270
|
'0x1079': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset
|
|
271
271
|
'0x10e6': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH
|
|
272
272
|
'0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT
|
|
273
|
-
'0x13b2': 'eip155:5042/
|
|
273
|
+
'0x13b2': 'eip155:5042/slip44:5042', // Arc - Native symbol: USDC
|
|
274
274
|
'0x1b58': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA
|
|
275
275
|
'0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH
|
|
276
276
|
'0x1237': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codefi-v2.mjs","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,aAAa,EACd,wBAAwB;AAYzB;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,UAAU;IACV,KAAK;IACL,QAAQ;IACR,KAAK;IACL,WAAW;IACX,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,SAAS;IACT,KAAK;IACL,YAAY;IACZ,MAAM;IACN,WAAW;IACX,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,YAAY;IACZ,KAAK;IACL,8BAA8B;IAC9B,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,cAAc;IACd,KAAK;IACL,kBAAkB;IAClB,KAAK;IACL,cAAc;IACd,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,OAAO;IACP,KAAK;IACL,yBAAyB;IACzB,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,mBAAmB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AC,WAAW,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,yBAAyB;QAC7B,OAAO,wBAAwB,EAAE,CAAC;IACpC,CAAC;CACF","sourcesContent":["import {\n createServicePolicy,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n handleFetch,\n} from '@metamask/controller-utils';\nimport type { ServicePolicy } from '@metamask/controller-utils';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\nimport {\n hexToNumber,\n KnownCaipNamespace,\n numberToHex,\n toCaipChainId,\n} from '@metamask/utils';\n\nimport type { MarketDataDetails } from '../TokenRatesController.js';\nimport type {\n AbstractTokenPricesService,\n EvmAssetAddressWithChain,\n EvmAssetWithId,\n EvmAssetWithMarketData,\n ExchangeRatesByCurrency,\n NativeAssetIdentifiersMap,\n} from './abstract-token-prices-service.js';\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 * This is the fallback list used when the API is unavailable.\n */\nexport const SUPPORTED_CURRENCIES_FALLBACK = [\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 // Georgian Lari\n 'gel',\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 // Monad\n 'mon',\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 // Colombian Peso\n 'cop',\n // Kenyan Shilling\n 'kes',\n // Romanian Leu\n 'ron',\n // Dominican Peso\n 'dop',\n // Costa Rican Colón\n 'crc',\n // Honduran Lempira\n 'hnl',\n // Zambian Kwacha\n 'zmw',\n // Salvadoran Colón\n 'svc',\n // Bosnia-Herzegovina Convertible Mark\n 'bam',\n // Peruvian Sol\n 'pen',\n // Guatemalan Quetzal\n 'gtq',\n // Lebanese Pound\n 'lbp',\n // Armenian Dram\n 'amd',\n // Solana\n 'sol',\n // Sei\n 'sei',\n // Sonic\n 'sonic',\n // Tron\n 'trx',\n // Taiko\n 'taiko',\n // Pepu\n 'pepu',\n // Polygon\n 'pol',\n // Mantle\n 'mnt',\n // Onomy\n 'nom',\n // Avalanche\n 'avax',\n // Apechain\n 'ape',\n] as const;\n\n/**\n * @deprecated Use `getSupportedCurrencies()` or `fetchSupportedCurrencies()` instead.\n * This is an alias for backward compatibility.\n */\nexport const SUPPORTED_CURRENCIES = SUPPORTED_CURRENCIES_FALLBACK;\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 mapping from chain id to the address of the chain's native token.\n * Only for chains whose native tokens have a specific address.\n */\nconst chainIdToNativeTokenAddress: Record<Hex, Hex> = {\n '0x89': '0x0000000000000000000000000000000000001010', // Polygon\n '0x440': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda\n '0x1388': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle\n};\n\n/**\n * Returns the address that should be used to query the price api for the\n * chain's native token. On most chains, this is signified by the zero address.\n * But on some chains, the native token has a specific address.\n *\n * @param chainId - The hexadecimal chain id.\n * @returns The address of the chain's native token.\n */\nexport const getNativeTokenAddress = (chainId: Hex): Hex =>\n chainIdToNativeTokenAddress[chainId] ?? ZERO_ADDRESS;\n\n// Source: https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts\n// This list is ONLY for chains that are supported by the Price API v3/spot-prices endpoint.\n// Please check that endpoint returns a price for the given assetId before including it in this list.\n// Please include a comment with the name of the chain and the native symbol.\n// Please keep the list sorted by chain ID.\nexport const SPOT_PRICES_SUPPORT_INFO = {\n '0x1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH\n '0xa': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH\n '0x19': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO\n '0x1e': 'eip155:30/slip44:137', // Rootstock Mainnet - Native symbol: RBTC\n '0x2a': 'eip155:42/erc20:0x0000000000000000000000000000000000000000', // Lukso - native symbol: LYX\n '0x32': 'eip155:50/erc20:0x0000000000000000000000000000000000000000', // xdc-network - native symbol: XDC\n '0x38': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB\n '0x39': 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS\n '0x52': 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR\n '0x58': 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO\n '0x64': 'eip155:100/erc20:0x0000000000000000000000000000000000000000', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI\n '0x6a': 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX\n '0x7a': 'eip155:122/erc20:0x0000000000000000000000000000000000000000', // Fuse Mainnet - Native symbol: FUSE\n '0x80': 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT\n '0x89': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL\n '0x8f': 'eip155:143/slip44:268435779', // Monad Mainnet - Native symbol: MON\n '0x92': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S\n '0xc4': 'eip155:196/erc20:0x0000000000000000000000000000000000000000', // X Layer Mainnet - Native symbol: OKB\n '0xe8': 'eip155:232/erc20:0x0000000000000000000000000000000000000000', // Lens Mainnet - Native symbol: GHO\n '0xfa': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM\n '0xfc': 'eip155:252/erc20:0x0000000000000000000000000000000000000000', // Fraxtal - native symbol: FRAX\n '0x120': 'eip155:288/slip44:60', // Boba Network (Ethereum L2) - Native symbol: ETH\n '0x141': 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS\n '0x144': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH\n '0x150': 'eip155:336/slip44:809', // Shiden - Native symbol: SDN\n '0x169': 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL\n '0x2eb': 'eip155:747/slip44:539', // Flow evm - Native symbol: Flow\n '0x3dc': 'eip155:988/erc20:0x0000000000000000000000000000000000000000', // Stable - Native symbol: USDT0\n '0x3e7': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: HYPE\n '0x440': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS\n '0x44d': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH\n '0x504': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR\n '0x505': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR\n '0x531': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI\n '0x6f0': 'eip155:1776/slip44:22000119', // Injective Mainnet - Native symbol: INJ\n '0x74c': 'eip155:1868/erc20:0x0000000000000000000000000000000000000000', // Soneium - Native symbol: ETH\n '0x9dd': 'eip155:2525/erc20:0x0000000000000000000000000000000000000000', // inEVM Mainnet - Native symbol: INV\n '0xab5': 'eip155:2741/erc20:0x0000000000000000000000000000000000000000', // Abstract - Native symbol: ETH\n '0x1079': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset\n '0x10e6': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH\n '0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT\n '0x13b2': 'eip155:5042/erc20:0x0000000000000000000000000000000000000000', // Arc - Native symbol: USDC\n '0x1b58': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA\n '0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH\n '0x1237': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH\n '0x2611': 'eip155:9745/erc20:0x0000000000000000000000000000000000000000', // Plasma mainnet - native symbol: XPL\n '0x2710': 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH\n '0x8173': 'eip155:33139/erc20:0x0000000000000000000000000000000000000000', // Apechain Mainnet - Native symbol: APE\n '0xa3c3': 'eip155:41923/erc20:0x0000000000000000000000000000000000000000', // EDU Chain - Native symbol: EDU\n '0xa4b1': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH\n '0xa4ec': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO\n '0xa516': 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE\n '0xa5bf': 'eip155:42431/slip44:60', // Tempo Testnet Moderato - No native asset\n '0xa729': 'eip155:42793/erc20:0x0000000000000000000000000000000000000000', // Etherlink - Native symbol: XTZ (Tezos L2)\n '0xa867': 'eip155:43111/erc20:0x0000000000000000000000000000000000000000', // Hemi - Native symbol: ETH\n '0xa86a': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX\n '0xdef1': 'eip155:57073/slip44:60', // Ink Mainnet - Native symbol: ETH\n '0xe708': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH\n '0xed88': 'eip155:60808/erc20:0x0000000000000000000000000000000000000000', // BOB - Native symbol: ETH\n '0x10b3e': 'eip155:68414/erc20:0x0000000000000000000000000000000000000000', // MapleStory Universe - no slip44\n '0x11d9b': 'eip155:73115/erc20:0x0000000000000000000000000000000000000000', // ICB Network - Native symbol: ICBX,\n '0x138de': 'eip155:80094/erc20:0x0000000000000000000000000000000000000000', // Berachain - Native symbol: Bera',\n '0x13e31': 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH\n '0x15b38': 'eip155:88888/erc20:0x0000000000000000000000000000000000000000', // Chiliz Chain - Native symbol: CHZ\n '0x17dcd': 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // Pepe Unchained Mainnet - Native symbol: PEPU\n '0x18232': 'eip155:98866/erc20:0x0000000000000000000000000000000000000000', // Plume Mainnet - Narive symbol: Plume\n '0x28c58': 'eip155:167000/slip44:60', // Taiko Mainnet - Native symbol: ETH\n '0x518af': 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS\n '0x82750': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH\n '0xb67d2': 'eip155:747474/erc20:0x0000000000000000000000000000000000000000', // katana - Native symbol: ETH\n '0xf043a': 'eip155:984122/erc20:0x0000000000000000000000000000000000000000', // Forma - Native symbol: TIA (Celestia)\n '0x15f900': 'eip155:1440000/erc20:0x0000000000000000000000000000000000000000', // xrpl-evm - native symbol: XRP\n '0x4e454152': 'eip155:1313161554/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH\n '0x63564c40': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE\n} as const;\n\n// MISSING CHAINS WITH NO NATIVE ASSET PRICES\n// '0x42': 'eip155:66/slip44:996', // OKXChain Mainnet - Native symbol: OKT\n// '0x46': 'eip155:70/slip44:1170', // Hoo Smart Chain - Native symbol: HOO\n// '0x926': 'eip155:2342/erc20:0x0000000000000000000000000000000000000000', // Omnia Chain - Native symbol: OMNIA\n// '0x407b': 'eip155:16507/erc20:0x0000000000000000000000000000000000000000', // Genesys Mainnet - Native symbol: GSYS\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_FALLBACK)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES_FALLBACK)[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 *\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 = Object.keys(\n SPOT_PRICES_SUPPORT_INFO,\n) as (keyof typeof SPOT_PRICES_SUPPORT_INFO)[];\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\nconst BASE_URL_V1 = 'https://price.api.cx.metamask.io/v1';\n\nconst BASE_URL_V2 = 'https://price.api.cx.metamask.io/v2';\n\nconst BASE_URL_V3 = 'https://price.api.cx.metamask.io/v3';\n\n/**\n * Response type for the /v2/supportedNetworks endpoint.\n */\ntype SupportedNetworksResponse = {\n fullSupport: string[];\n partialSupport: {\n spotPricesV2: string[];\n spotPricesV3: string[];\n };\n};\n\n/**\n * In-memory store for the last successfully fetched supported networks.\n */\nlet lastFetchedSupportedNetworks: SupportedNetworksResponse | null = null;\n\n/**\n * In-flight promise to prevent concurrent requests to the supported networks endpoint.\n */\nlet runningSupportedNetworksRequest: Promise<SupportedNetworksResponse> | null =\n null;\n\n/**\n * Converts a CAIP-2 chain ID (e.g., 'eip155:1') to a hex chain ID (e.g., '0x1').\n *\n * @param caipChainId - The CAIP-2 chain ID string.\n * @returns The hex chain ID or null if not an EIP-155 chain.\n */\nfunction caipChainIdToHex(caipChainId: string): Hex | null {\n const match = caipChainId.match(/^eip155:(\\d+)$/u);\n if (!match) {\n return null;\n }\n return numberToHex(parseInt(match[1], 10));\n}\n\n/**\n * Executes the actual fetch to the supported networks endpoint.\n * Handles errors internally by falling back to the hardcoded list,\n * and clears the in-flight promise when done.\n *\n * @returns The supported networks response.\n */\nasync function executeSupportedNetworksFetch(): Promise<SupportedNetworksResponse> {\n try {\n const url = `${BASE_URL_V2}/supportedNetworks`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (\n response &&\n typeof response === 'object' &&\n 'fullSupport' in response &&\n 'partialSupport' in response\n ) {\n lastFetchedSupportedNetworks = response as SupportedNetworksResponse;\n return lastFetchedSupportedNetworks;\n }\n\n // Invalid response format, fall back to hardcoded list\n return getSupportedNetworksFallback();\n } catch {\n // On any error, fall back to the hardcoded list\n return getSupportedNetworksFallback();\n } finally {\n // Clear the in-flight promise once the request completes\n runningSupportedNetworksRequest = null;\n }\n}\n\n/**\n * Fetches the list of supported networks from the API.\n * Falls back to the hardcoded list if the fetch fails.\n * Deduplicates concurrent requests by returning the same promise if a fetch is already in progress.\n *\n * @returns The supported networks response.\n */\nexport async function fetchSupportedNetworks(): Promise<SupportedNetworksResponse> {\n // If a fetch is already in progress, return the same promise\n if (runningSupportedNetworksRequest) {\n return runningSupportedNetworksRequest;\n }\n\n // Start a new fetch and cache the promise\n runningSupportedNetworksRequest = executeSupportedNetworksFetch();\n\n return runningSupportedNetworksRequest;\n}\n\n/**\n * Synchronously gets the list of supported networks.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The supported networks response.\n */\nexport function getSupportedNetworks(): SupportedNetworksResponse {\n if (lastFetchedSupportedNetworks !== null) {\n return lastFetchedSupportedNetworks;\n }\n return getSupportedNetworksFallback();\n}\n\n/**\n * Generates a fallback supported networks response from the hardcoded SPOT_PRICES_SUPPORT_INFO.\n *\n * @returns A SupportedNetworksResponse derived from hardcoded data.\n */\nfunction getSupportedNetworksFallback(): SupportedNetworksResponse {\n const caipChainIds = Object.keys(SPOT_PRICES_SUPPORT_INFO).map((hexChainId) =>\n toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(hexChainId as Hex).toString(),\n ),\n );\n\n return {\n fullSupport: caipChainIds.slice(0, 11), // First 11 chains as \"full support\"\n partialSupport: {\n spotPricesV2: caipChainIds,\n spotPricesV3: caipChainIds,\n },\n };\n}\n\n/**\n * Resets the supported networks cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedNetworksCache(): void {\n lastFetchedSupportedNetworks = null;\n runningSupportedNetworksRequest = null;\n}\n\n/**\n * Gets the list of supported chain IDs for spot prices v3 as hex values.\n *\n * @returns Array of hex chain IDs supported by spot prices v3.\n */\nfunction getSupportedChainIdsV3AsHex(): Hex[] {\n const supportedNetworks = getSupportedNetworks();\n const allV3Chains = [\n ...supportedNetworks.fullSupport,\n ...supportedNetworks.partialSupport.spotPricesV3,\n ];\n\n return allV3Chains\n .map(caipChainIdToHex)\n .filter((hexChainId): hexChainId is Hex => hexChainId !== null);\n}\n\n/**\n * In-memory store for the last successfully fetched supported currencies.\n */\nlet lastFetchedCurrencies: string[] | null = null;\n\n/**\n * Fetches the list of supported currencies from the API.\n * Falls back to the hardcoded list if the fetch fails.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport async function fetchSupportedCurrencies(): Promise<string[]> {\n try {\n const url = `${BASE_URL_V1}/supportedVsCurrencies`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (Array.isArray(response)) {\n const currencies = response.map((currency: string) =>\n currency.toLowerCase(),\n );\n lastFetchedCurrencies = currencies;\n return currencies;\n }\n\n // Invalid response format, fall back to hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n } catch {\n // On any error, fall back to the hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n }\n}\n\n/**\n * Synchronously gets the list of supported currencies.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport function getSupportedCurrencies(): readonly string[] {\n if (lastFetchedCurrencies !== null) {\n return lastFetchedCurrencies;\n }\n return SUPPORTED_CURRENCIES_FALLBACK;\n}\n\n/**\n * Resets the supported currencies cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedCurrenciesCache(): void {\n lastFetchedCurrencies = null;\n}\n\n/**\n * Derives the CAIP-19 asset ID used to query the Price API for a token on a\n * given chain.\n *\n * For native tokens, uses the hardcoded {@link SPOT_PRICES_SUPPORT_INFO} entry\n * when defined, otherwise falls back to the provided native asset identifiers\n * (sourced from NetworkEnablementController). For ERC20 tokens, constructs the\n * CAIP-19 ID dynamically.\n *\n * @param args - The arguments to this function.\n * @param args.chainId - The hexadecimal chain ID the token lives on.\n * @param args.tokenAddress - The token's address.\n * @param args.nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset\n * identifiers, used as a fallback for native tokens.\n * @returns The CAIP-19 asset ID, or undefined if it cannot be determined.\n */\nexport function getAssetId({\n chainId,\n tokenAddress,\n nativeAssetIdentifiers = {},\n}: {\n chainId: Hex;\n tokenAddress: string;\n nativeAssetIdentifiers?: NativeAssetIdentifiersMap;\n}): CaipAssetType | undefined {\n try {\n const caipChainId = toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(chainId).toString(),\n );\n\n const nativeAddress = getNativeTokenAddress(chainId);\n const isNativeToken =\n nativeAddress.toLowerCase() === tokenAddress.toLowerCase();\n\n if (isNativeToken) {\n const hardcodedId = (\n SPOT_PRICES_SUPPORT_INFO as Partial<Record<Hex, string>>\n )[chainId];\n return (hardcodedId ?? nativeAssetIdentifiers[caipChainId]) as\n | CaipAssetType\n | undefined;\n }\n\n return `${caipChainId}/erc20:${tokenAddress.toLowerCase()}` as CaipAssetType;\n } catch {\n // This block should never be reached as long as using Typescript, but added for safety.\n return undefined;\n }\n}\n\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 implements AbstractTokenPricesService<\n SupportedChainId,\n SupportedCurrency\n> {\n readonly #policy: ServicePolicy;\n\n /**\n * Map of CAIP-2 chain IDs to their native asset identifiers.\n * Updated via setNativeAssetIdentifiers().\n */\n #nativeAssetIdentifiers: NativeAssetIdentifiersMap = {};\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n });\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @deprecated This signature is deprecated; please use the `onBreak` and\n * `onDegraded` methods instead.\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.onBreak - Callback for when the circuit breaks, useful\n * for capturing metrics about network failures.\n * @param args.onDegraded - Callback for when the API responds successfully\n * but takes too long to respond (5 seconds or more).\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n });\n\n constructor({\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_MAX_RETRIES,\n maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n onBreak,\n onDegraded,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n }: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n } = {}) {\n this.#policy = createServicePolicy({\n maxRetries: retries,\n maxConsecutiveFailures: maximumConsecutiveFailures,\n circuitBreakDuration,\n degradedThreshold,\n });\n if (onBreak) {\n this.#policy.onBreak(onBreak);\n }\n if (onDegraded) {\n this.#policy.onDegraded(onDegraded);\n }\n }\n\n /**\n * Listens for when the request to the API fails too many times in a row.\n *\n * @param args - The same arguments that {@link ServicePolicy.onBreak}\n * takes.\n * @returns What {@link ServicePolicy.onBreak} returns.\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Listens for when the API is degraded.\n *\n * @param args - The same arguments that {@link ServicePolicy.onDegraded}\n * takes.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n /**\n * Sets the native asset identifiers map for resolving native token CAIP-19 IDs.\n * This should be called with data from NetworkEnablementController.state.nativeAssetIdentifiers.\n *\n * @param nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset identifiers.\n */\n setNativeAssetIdentifiers(\n nativeAssetIdentifiers: NativeAssetIdentifiersMap,\n ): void {\n this.#nativeAssetIdentifiers = nativeAssetIdentifiers;\n }\n\n /**\n * Updates the supported networks cache by fetching from the API.\n * This should be called periodically to keep the supported networks list fresh.\n *\n * @returns The updated supported networks response.\n */\n async updateSupportedNetworks(): Promise<SupportedNetworksResponse> {\n return fetchSupportedNetworks();\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.assets - The assets to get prices for.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n async fetchTokenPrices({\n assets,\n currency,\n }: {\n assets: EvmAssetAddressWithChain<SupportedChainId>[];\n currency: SupportedCurrency;\n }): Promise<EvmAssetWithMarketData<SupportedChainId, SupportedCurrency>[]> {\n // Refresh supported networks in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedNetworks handles errors internally and always resolves\n if (!lastFetchedSupportedNetworks) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedNetworks();\n }\n\n // Get dynamically fetched supported chain IDs for V3\n const supportedChainIdsV3 = getSupportedChainIdsV3AsHex();\n\n const assetsWithIds: EvmAssetWithId<SupportedChainId>[] = assets\n // Filter out assets that are not supported by V3 of the Price API.\n .filter((asset) => supportedChainIdsV3.includes(asset.chainId))\n .map((asset) => {\n const assetId = getAssetId({\n chainId: asset.chainId,\n tokenAddress: asset.tokenAddress,\n nativeAssetIdentifiers: this.#nativeAssetIdentifiers,\n });\n\n if (!assetId) {\n return undefined;\n }\n\n return {\n ...asset,\n assetId,\n };\n })\n .filter(\n (asset): asset is EvmAssetWithId<SupportedChainId> =>\n asset !== undefined,\n );\n\n if (assetsWithIds.length === 0) {\n return [];\n }\n\n const url = new URL(`${BASE_URL_V3}/spot-prices`);\n url.searchParams.append(\n 'assetIds',\n assetsWithIds.map((asset) => asset.assetId).join(','),\n );\n url.searchParams.append('vsCurrency', currency);\n url.searchParams.append('includeMarketData', 'true');\n\n const addressCryptoDataMap: {\n [assetId: CaipAssetType]: Omit<\n MarketDataDetails,\n 'currency' | 'tokenAddress'\n >;\n } = await this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n );\n\n return assetsWithIds\n .map((assetWithId) => {\n const marketData = addressCryptoDataMap[assetWithId.assetId];\n\n if (!marketData) {\n return undefined;\n }\n\n return {\n ...marketData,\n ...assetWithId,\n currency,\n };\n })\n .filter((entry): entry is NonNullable<typeof entry> => Boolean(entry));\n }\n\n /**\n * Retrieves exchange rates in the given base currency.\n *\n * @param args - The arguments to this function.\n * @param args.baseCurrency - The desired base currency of the exchange rates.\n * @param args.includeUsdRate - Whether to include the USD rate in the response.\n * @param args.cryptocurrencies - The cryptocurrencies to get exchange rates for.\n * @returns The exchange rates for the requested base currency.\n */\n async fetchExchangeRates({\n baseCurrency,\n includeUsdRate,\n cryptocurrencies,\n }: {\n baseCurrency: SupportedCurrency;\n includeUsdRate: boolean;\n cryptocurrencies: string[];\n }): Promise<ExchangeRatesByCurrency<SupportedCurrency>> {\n // Refresh supported currencies in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedCurrencies handles errors internally and always resolves\n if (!lastFetchedCurrencies) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedCurrencies();\n }\n\n const url = new URL(`${BASE_URL_V1}/exchange-rates`);\n url.searchParams.append('baseCurrency', baseCurrency);\n\n const urlUsd = new URL(`${BASE_URL_V1}/exchange-rates`);\n urlUsd.searchParams.append('baseCurrency', 'usd');\n\n const [exchangeRatesResult, exchangeRatesResultUsd] =\n await Promise.allSettled([\n this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n ),\n ...(includeUsdRate && baseCurrency.toLowerCase() !== 'usd'\n ? [\n this.#policy.execute(() =>\n handleFetch(urlUsd, {\n headers: { 'Cache-Control': 'no-cache' },\n }),\n ),\n ]\n : []),\n ]);\n\n // Handle resolved/rejected\n const exchangeRates =\n exchangeRatesResult.status === 'fulfilled'\n ? exchangeRatesResult.value\n : {};\n const exchangeRatesUsd =\n exchangeRatesResultUsd?.status === 'fulfilled'\n ? exchangeRatesResultUsd.value\n : {};\n\n if (exchangeRatesResult.status === 'rejected') {\n throw new Error('Failed to fetch');\n }\n\n const filteredExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRates[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRates[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (Object.keys(filteredExchangeRates).length === 0) {\n throw new Error(\n 'None of the cryptocurrencies are supported by price api',\n );\n }\n\n const filteredUsdExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRatesUsd[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRatesUsd[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (baseCurrency.toLowerCase() === 'usd') {\n Object.keys(filteredExchangeRates).forEach((key) => {\n filteredExchangeRates[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n usd: filteredExchangeRates[key as SupportedCurrency]?.value,\n };\n });\n return filteredExchangeRates;\n }\n if (!includeUsdRate) {\n return filteredExchangeRates;\n }\n\n const merged = Object.keys(filteredExchangeRates).reduce((acc, key) => {\n acc[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n ...(filteredUsdExchangeRates[key as SupportedCurrency]?.value\n ? { usd: filteredUsdExchangeRates[key as SupportedCurrency]?.value }\n : {}),\n };\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n return merged;\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 // Use dynamically fetched supported networks\n const supportedChainIds = getSupportedChainIdsV3AsHex();\n // Also include the hardcoded fallback list for backwards compatibility\n const allSupportedChainIds: readonly string[] = [\n ...new Set([...supportedChainIds, ...SUPPORTED_CHAIN_IDS]),\n ];\n return (\n typeof chainId === 'string' && allSupportedChainIds.includes(chainId)\n );\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 = getSupportedCurrencies();\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n\n /**\n * Fetches the list of supported currencies from the API.\n *\n * @returns The list of supported currencies.\n */\n async updateSupportedCurrencies(): Promise<string[]> {\n return fetchSupportedCurrencies();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"codefi-v2.mjs","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,aAAa,EACd,wBAAwB;AAYzB;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,UAAU;IACV,KAAK;IACL,QAAQ;IACR,KAAK;IACL,WAAW;IACX,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,SAAS;IACT,KAAK;IACL,YAAY;IACZ,MAAM;IACN,WAAW;IACX,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,YAAY;IACZ,KAAK;IACL,8BAA8B;IAC9B,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,cAAc;IACd,KAAK;IACL,kBAAkB;IAClB,KAAK;IACL,cAAc;IACd,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,OAAO;IACP,KAAK;IACL,yBAAyB;IACzB,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL,qBAAqB;IACrB,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAA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FAILURES,\n DEFAULT_MAX_RETRIES,\n handleFetch,\n} from '@metamask/controller-utils';\nimport type { ServicePolicy } from '@metamask/controller-utils';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\nimport {\n hexToNumber,\n KnownCaipNamespace,\n numberToHex,\n toCaipChainId,\n} from '@metamask/utils';\n\nimport type { MarketDataDetails } from '../TokenRatesController.js';\nimport type {\n AbstractTokenPricesService,\n EvmAssetAddressWithChain,\n EvmAssetWithId,\n EvmAssetWithMarketData,\n ExchangeRatesByCurrency,\n NativeAssetIdentifiersMap,\n} from './abstract-token-prices-service.js';\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 * This is the fallback list used when the API is unavailable.\n */\nexport const SUPPORTED_CURRENCIES_FALLBACK = [\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 // Georgian Lari\n 'gel',\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 // Monad\n 'mon',\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 // Colombian Peso\n 'cop',\n // Kenyan Shilling\n 'kes',\n // Romanian Leu\n 'ron',\n // Dominican Peso\n 'dop',\n // Costa Rican Colón\n 'crc',\n // Honduran Lempira\n 'hnl',\n // Zambian Kwacha\n 'zmw',\n // Salvadoran Colón\n 'svc',\n // Bosnia-Herzegovina Convertible Mark\n 'bam',\n // Peruvian Sol\n 'pen',\n // Guatemalan Quetzal\n 'gtq',\n // Lebanese Pound\n 'lbp',\n // Armenian Dram\n 'amd',\n // Solana\n 'sol',\n // Sei\n 'sei',\n // Sonic\n 'sonic',\n // Tron\n 'trx',\n // Taiko\n 'taiko',\n // Pepu\n 'pepu',\n // Polygon\n 'pol',\n // Mantle\n 'mnt',\n // Onomy\n 'nom',\n // Avalanche\n 'avax',\n // Apechain\n 'ape',\n] as const;\n\n/**\n * @deprecated Use `getSupportedCurrencies()` or `fetchSupportedCurrencies()` instead.\n * This is an alias for backward compatibility.\n */\nexport const SUPPORTED_CURRENCIES = SUPPORTED_CURRENCIES_FALLBACK;\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 mapping from chain id to the address of the chain's native token.\n * Only for chains whose native tokens have a specific address.\n */\nconst chainIdToNativeTokenAddress: Record<Hex, Hex> = {\n '0x89': '0x0000000000000000000000000000000000001010', // Polygon\n '0x440': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda\n '0x1388': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle\n};\n\n/**\n * Returns the address that should be used to query the price api for the\n * chain's native token. On most chains, this is signified by the zero address.\n * But on some chains, the native token has a specific address.\n *\n * @param chainId - The hexadecimal chain id.\n * @returns The address of the chain's native token.\n */\nexport const getNativeTokenAddress = (chainId: Hex): Hex =>\n chainIdToNativeTokenAddress[chainId] ?? ZERO_ADDRESS;\n\n// Source: https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts\n// This list is ONLY for chains that are supported by the Price API v3/spot-prices endpoint.\n// Please check that endpoint returns a price for the given assetId before including it in this list.\n// Please include a comment with the name of the chain and the native symbol.\n// Please keep the list sorted by chain ID.\nexport const SPOT_PRICES_SUPPORT_INFO = {\n '0x1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH\n '0xa': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH\n '0x19': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO\n '0x1e': 'eip155:30/slip44:137', // Rootstock Mainnet - Native symbol: RBTC\n '0x2a': 'eip155:42/erc20:0x0000000000000000000000000000000000000000', // Lukso - native symbol: LYX\n '0x32': 'eip155:50/erc20:0x0000000000000000000000000000000000000000', // xdc-network - native symbol: XDC\n '0x38': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB\n '0x39': 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS\n '0x52': 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR\n '0x58': 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO\n '0x64': 'eip155:100/erc20:0x0000000000000000000000000000000000000000', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI\n '0x6a': 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX\n '0x7a': 'eip155:122/erc20:0x0000000000000000000000000000000000000000', // Fuse Mainnet - Native symbol: FUSE\n '0x80': 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT\n '0x89': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL\n '0x8f': 'eip155:143/slip44:268435779', // Monad Mainnet - Native symbol: MON\n '0x92': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S\n '0xc4': 'eip155:196/erc20:0x0000000000000000000000000000000000000000', // X Layer Mainnet - Native symbol: OKB\n '0xe8': 'eip155:232/erc20:0x0000000000000000000000000000000000000000', // Lens Mainnet - Native symbol: GHO\n '0xfa': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM\n '0xfc': 'eip155:252/erc20:0x0000000000000000000000000000000000000000', // Fraxtal - native symbol: FRAX\n '0x120': 'eip155:288/slip44:60', // Boba Network (Ethereum L2) - Native symbol: ETH\n '0x141': 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS\n '0x144': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH\n '0x150': 'eip155:336/slip44:809', // Shiden - Native symbol: SDN\n '0x169': 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL\n '0x2eb': 'eip155:747/slip44:539', // Flow evm - Native symbol: Flow\n '0x3dc': 'eip155:988/erc20:0x0000000000000000000000000000000000000000', // Stable - Native symbol: USDT0\n '0x3e7': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: HYPE\n '0x440': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS\n '0x44d': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH\n '0x504': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR\n '0x505': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR\n '0x531': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI\n '0x6f0': 'eip155:1776/slip44:22000119', // Injective Mainnet - Native symbol: INJ\n '0x74c': 'eip155:1868/erc20:0x0000000000000000000000000000000000000000', // Soneium - Native symbol: ETH\n '0x9dd': 'eip155:2525/erc20:0x0000000000000000000000000000000000000000', // inEVM Mainnet - Native symbol: INV\n '0xab5': 'eip155:2741/erc20:0x0000000000000000000000000000000000000000', // Abstract - Native symbol: ETH\n '0x1079': 'eip155:4217/slip44:60', // Tempo Mainnet - No native asset\n '0x10e6': 'eip155:4326/erc20:0x0000000000000000000000000000000000000000', // MegaETH Mainnet - Native symbol: ETH\n '0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle - Native symbol: MNT\n '0x13b2': 'eip155:5042/slip44:5042', // Arc - Native symbol: USDC\n '0x1b58': 'eip155:7000/slip44:7000', // ZetaChain - Native symbol: ZETA\n '0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH\n '0x1237': 'eip155:4663/slip44:60', // Robinhood Chain - Native symbol: ETH\n '0x2611': 'eip155:9745/erc20:0x0000000000000000000000000000000000000000', // Plasma mainnet - native symbol: XPL\n '0x2710': 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH\n '0x8173': 'eip155:33139/erc20:0x0000000000000000000000000000000000000000', // Apechain Mainnet - Native symbol: APE\n '0xa3c3': 'eip155:41923/erc20:0x0000000000000000000000000000000000000000', // EDU Chain - Native symbol: EDU\n '0xa4b1': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH\n '0xa4ec': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO\n '0xa516': 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE\n '0xa5bf': 'eip155:42431/slip44:60', // Tempo Testnet Moderato - No native asset\n '0xa729': 'eip155:42793/erc20:0x0000000000000000000000000000000000000000', // Etherlink - Native symbol: XTZ (Tezos L2)\n '0xa867': 'eip155:43111/erc20:0x0000000000000000000000000000000000000000', // Hemi - Native symbol: ETH\n '0xa86a': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX\n '0xdef1': 'eip155:57073/slip44:60', // Ink Mainnet - Native symbol: ETH\n '0xe708': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH\n '0xed88': 'eip155:60808/erc20:0x0000000000000000000000000000000000000000', // BOB - Native symbol: ETH\n '0x10b3e': 'eip155:68414/erc20:0x0000000000000000000000000000000000000000', // MapleStory Universe - no slip44\n '0x11d9b': 'eip155:73115/erc20:0x0000000000000000000000000000000000000000', // ICB Network - Native symbol: ICBX,\n '0x138de': 'eip155:80094/erc20:0x0000000000000000000000000000000000000000', // Berachain - Native symbol: Bera',\n '0x13e31': 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH\n '0x15b38': 'eip155:88888/erc20:0x0000000000000000000000000000000000000000', // Chiliz Chain - Native symbol: CHZ\n '0x17dcd': 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // Pepe Unchained Mainnet - Native symbol: PEPU\n '0x18232': 'eip155:98866/erc20:0x0000000000000000000000000000000000000000', // Plume Mainnet - Narive symbol: Plume\n '0x28c58': 'eip155:167000/slip44:60', // Taiko Mainnet - Native symbol: ETH\n '0x518af': 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS\n '0x82750': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH\n '0xb67d2': 'eip155:747474/erc20:0x0000000000000000000000000000000000000000', // katana - Native symbol: ETH\n '0xf043a': 'eip155:984122/erc20:0x0000000000000000000000000000000000000000', // Forma - Native symbol: TIA (Celestia)\n '0x15f900': 'eip155:1440000/erc20:0x0000000000000000000000000000000000000000', // xrpl-evm - native symbol: XRP\n '0x4e454152': 'eip155:1313161554/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH\n '0x63564c40': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE\n} as const;\n\n// MISSING CHAINS WITH NO NATIVE ASSET PRICES\n// '0x42': 'eip155:66/slip44:996', // OKXChain Mainnet - Native symbol: OKT\n// '0x46': 'eip155:70/slip44:1170', // Hoo Smart Chain - Native symbol: HOO\n// '0x926': 'eip155:2342/erc20:0x0000000000000000000000000000000000000000', // Omnia Chain - Native symbol: OMNIA\n// '0x407b': 'eip155:16507/erc20:0x0000000000000000000000000000000000000000', // Genesys Mainnet - Native symbol: GSYS\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_FALLBACK)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES_FALLBACK)[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 *\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 = Object.keys(\n SPOT_PRICES_SUPPORT_INFO,\n) as (keyof typeof SPOT_PRICES_SUPPORT_INFO)[];\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\nconst BASE_URL_V1 = 'https://price.api.cx.metamask.io/v1';\n\nconst BASE_URL_V2 = 'https://price.api.cx.metamask.io/v2';\n\nconst BASE_URL_V3 = 'https://price.api.cx.metamask.io/v3';\n\n/**\n * Response type for the /v2/supportedNetworks endpoint.\n */\ntype SupportedNetworksResponse = {\n fullSupport: string[];\n partialSupport: {\n spotPricesV2: string[];\n spotPricesV3: string[];\n };\n};\n\n/**\n * In-memory store for the last successfully fetched supported networks.\n */\nlet lastFetchedSupportedNetworks: SupportedNetworksResponse | null = null;\n\n/**\n * In-flight promise to prevent concurrent requests to the supported networks endpoint.\n */\nlet runningSupportedNetworksRequest: Promise<SupportedNetworksResponse> | null =\n null;\n\n/**\n * Converts a CAIP-2 chain ID (e.g., 'eip155:1') to a hex chain ID (e.g., '0x1').\n *\n * @param caipChainId - The CAIP-2 chain ID string.\n * @returns The hex chain ID or null if not an EIP-155 chain.\n */\nfunction caipChainIdToHex(caipChainId: string): Hex | null {\n const match = caipChainId.match(/^eip155:(\\d+)$/u);\n if (!match) {\n return null;\n }\n return numberToHex(parseInt(match[1], 10));\n}\n\n/**\n * Executes the actual fetch to the supported networks endpoint.\n * Handles errors internally by falling back to the hardcoded list,\n * and clears the in-flight promise when done.\n *\n * @returns The supported networks response.\n */\nasync function executeSupportedNetworksFetch(): Promise<SupportedNetworksResponse> {\n try {\n const url = `${BASE_URL_V2}/supportedNetworks`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (\n response &&\n typeof response === 'object' &&\n 'fullSupport' in response &&\n 'partialSupport' in response\n ) {\n lastFetchedSupportedNetworks = response as SupportedNetworksResponse;\n return lastFetchedSupportedNetworks;\n }\n\n // Invalid response format, fall back to hardcoded list\n return getSupportedNetworksFallback();\n } catch {\n // On any error, fall back to the hardcoded list\n return getSupportedNetworksFallback();\n } finally {\n // Clear the in-flight promise once the request completes\n runningSupportedNetworksRequest = null;\n }\n}\n\n/**\n * Fetches the list of supported networks from the API.\n * Falls back to the hardcoded list if the fetch fails.\n * Deduplicates concurrent requests by returning the same promise if a fetch is already in progress.\n *\n * @returns The supported networks response.\n */\nexport async function fetchSupportedNetworks(): Promise<SupportedNetworksResponse> {\n // If a fetch is already in progress, return the same promise\n if (runningSupportedNetworksRequest) {\n return runningSupportedNetworksRequest;\n }\n\n // Start a new fetch and cache the promise\n runningSupportedNetworksRequest = executeSupportedNetworksFetch();\n\n return runningSupportedNetworksRequest;\n}\n\n/**\n * Synchronously gets the list of supported networks.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The supported networks response.\n */\nexport function getSupportedNetworks(): SupportedNetworksResponse {\n if (lastFetchedSupportedNetworks !== null) {\n return lastFetchedSupportedNetworks;\n }\n return getSupportedNetworksFallback();\n}\n\n/**\n * Generates a fallback supported networks response from the hardcoded SPOT_PRICES_SUPPORT_INFO.\n *\n * @returns A SupportedNetworksResponse derived from hardcoded data.\n */\nfunction getSupportedNetworksFallback(): SupportedNetworksResponse {\n const caipChainIds = Object.keys(SPOT_PRICES_SUPPORT_INFO).map((hexChainId) =>\n toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(hexChainId as Hex).toString(),\n ),\n );\n\n return {\n fullSupport: caipChainIds.slice(0, 11), // First 11 chains as \"full support\"\n partialSupport: {\n spotPricesV2: caipChainIds,\n spotPricesV3: caipChainIds,\n },\n };\n}\n\n/**\n * Resets the supported networks cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedNetworksCache(): void {\n lastFetchedSupportedNetworks = null;\n runningSupportedNetworksRequest = null;\n}\n\n/**\n * Gets the list of supported chain IDs for spot prices v3 as hex values.\n *\n * @returns Array of hex chain IDs supported by spot prices v3.\n */\nfunction getSupportedChainIdsV3AsHex(): Hex[] {\n const supportedNetworks = getSupportedNetworks();\n const allV3Chains = [\n ...supportedNetworks.fullSupport,\n ...supportedNetworks.partialSupport.spotPricesV3,\n ];\n\n return allV3Chains\n .map(caipChainIdToHex)\n .filter((hexChainId): hexChainId is Hex => hexChainId !== null);\n}\n\n/**\n * In-memory store for the last successfully fetched supported currencies.\n */\nlet lastFetchedCurrencies: string[] | null = null;\n\n/**\n * Fetches the list of supported currencies from the API.\n * Falls back to the hardcoded list if the fetch fails.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport async function fetchSupportedCurrencies(): Promise<string[]> {\n try {\n const url = `${BASE_URL_V1}/supportedVsCurrencies`;\n const response = await handleFetch(url, {\n headers: { 'Cache-Control': 'no-cache' },\n });\n\n if (Array.isArray(response)) {\n const currencies = response.map((currency: string) =>\n currency.toLowerCase(),\n );\n lastFetchedCurrencies = currencies;\n return currencies;\n }\n\n // Invalid response format, fall back to hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n } catch {\n // On any error, fall back to the hardcoded list\n return [...SUPPORTED_CURRENCIES_FALLBACK];\n }\n}\n\n/**\n * Synchronously gets the list of supported currencies.\n * Returns the last fetched value if available, otherwise returns the fallback list.\n *\n * @returns The list of supported currencies in lowercase.\n */\nexport function getSupportedCurrencies(): readonly string[] {\n if (lastFetchedCurrencies !== null) {\n return lastFetchedCurrencies;\n }\n return SUPPORTED_CURRENCIES_FALLBACK;\n}\n\n/**\n * Resets the supported currencies cache.\n * This is primarily intended for testing purposes.\n */\nexport function resetSupportedCurrenciesCache(): void {\n lastFetchedCurrencies = null;\n}\n\n/**\n * Derives the CAIP-19 asset ID used to query the Price API for a token on a\n * given chain.\n *\n * For native tokens, uses the hardcoded {@link SPOT_PRICES_SUPPORT_INFO} entry\n * when defined, otherwise falls back to the provided native asset identifiers\n * (sourced from NetworkEnablementController). For ERC20 tokens, constructs the\n * CAIP-19 ID dynamically.\n *\n * @param args - The arguments to this function.\n * @param args.chainId - The hexadecimal chain ID the token lives on.\n * @param args.tokenAddress - The token's address.\n * @param args.nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset\n * identifiers, used as a fallback for native tokens.\n * @returns The CAIP-19 asset ID, or undefined if it cannot be determined.\n */\nexport function getAssetId({\n chainId,\n tokenAddress,\n nativeAssetIdentifiers = {},\n}: {\n chainId: Hex;\n tokenAddress: string;\n nativeAssetIdentifiers?: NativeAssetIdentifiersMap;\n}): CaipAssetType | undefined {\n try {\n const caipChainId = toCaipChainId(\n KnownCaipNamespace.Eip155,\n hexToNumber(chainId).toString(),\n );\n\n const nativeAddress = getNativeTokenAddress(chainId);\n const isNativeToken =\n nativeAddress.toLowerCase() === tokenAddress.toLowerCase();\n\n if (isNativeToken) {\n const hardcodedId = (\n SPOT_PRICES_SUPPORT_INFO as Partial<Record<Hex, string>>\n )[chainId];\n return (hardcodedId ?? nativeAssetIdentifiers[caipChainId]) as\n | CaipAssetType\n | undefined;\n }\n\n return `${caipChainId}/erc20:${tokenAddress.toLowerCase()}` as CaipAssetType;\n } catch {\n // This block should never be reached as long as using Typescript, but added for safety.\n return undefined;\n }\n}\n\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 implements AbstractTokenPricesService<\n SupportedChainId,\n SupportedCurrency\n> {\n readonly #policy: ServicePolicy;\n\n /**\n * Map of CAIP-2 chain IDs to their native asset identifiers.\n * Updated via setNativeAssetIdentifiers().\n */\n #nativeAssetIdentifiers: NativeAssetIdentifiersMap = {};\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n circuitBreakDuration?: number;\n });\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @deprecated This signature is deprecated; please use the `onBreak` and\n * `onDegraded` methods instead.\n * @param args - The arguments.\n * @param args.degradedThreshold - The length of time (in milliseconds)\n * that governs when the service is regarded as degraded (affecting when\n * `onDegraded` is called). Defaults to 5 seconds.\n * @param args.retries - Number of retry attempts for each fetch request.\n * @param args.maximumConsecutiveFailures - The maximum number of consecutive\n * failures allowed before breaking the circuit and pausing further updates.\n * @param args.onBreak - Callback for when the circuit breaks, useful\n * for capturing metrics about network failures.\n * @param args.onDegraded - Callback for when the API responds successfully\n * but takes too long to respond (5 seconds or more).\n * @param args.circuitBreakDuration - The amount of time to wait when the\n * circuit breaks from too many consecutive failures.\n */\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n constructor(args?: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n });\n\n constructor({\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_MAX_RETRIES,\n maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n onBreak,\n onDegraded,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n }: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n } = {}) {\n this.#policy = createServicePolicy({\n maxRetries: retries,\n maxConsecutiveFailures: maximumConsecutiveFailures,\n circuitBreakDuration,\n degradedThreshold,\n });\n if (onBreak) {\n this.#policy.onBreak(onBreak);\n }\n if (onDegraded) {\n this.#policy.onDegraded(onDegraded);\n }\n }\n\n /**\n * Listens for when the request to the API fails too many times in a row.\n *\n * @param args - The same arguments that {@link ServicePolicy.onBreak}\n * takes.\n * @returns What {@link ServicePolicy.onBreak} returns.\n */\n onBreak(\n ...args: Parameters<ServicePolicy['onBreak']>\n ): ReturnType<ServicePolicy['onBreak']> {\n return this.#policy.onBreak(...args);\n }\n\n /**\n * Listens for when the API is degraded.\n *\n * @param args - The same arguments that {@link ServicePolicy.onDegraded}\n * takes.\n * @returns What {@link ServicePolicy.onDegraded} returns.\n */\n onDegraded(\n ...args: Parameters<ServicePolicy['onDegraded']>\n ): ReturnType<ServicePolicy['onDegraded']> {\n return this.#policy.onDegraded(...args);\n }\n\n /**\n * Sets the native asset identifiers map for resolving native token CAIP-19 IDs.\n * This should be called with data from NetworkEnablementController.state.nativeAssetIdentifiers.\n *\n * @param nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset identifiers.\n */\n setNativeAssetIdentifiers(\n nativeAssetIdentifiers: NativeAssetIdentifiersMap,\n ): void {\n this.#nativeAssetIdentifiers = nativeAssetIdentifiers;\n }\n\n /**\n * Updates the supported networks cache by fetching from the API.\n * This should be called periodically to keep the supported networks list fresh.\n *\n * @returns The updated supported networks response.\n */\n async updateSupportedNetworks(): Promise<SupportedNetworksResponse> {\n return fetchSupportedNetworks();\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.assets - The assets to get prices for.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n async fetchTokenPrices({\n assets,\n currency,\n }: {\n assets: EvmAssetAddressWithChain<SupportedChainId>[];\n currency: SupportedCurrency;\n }): Promise<EvmAssetWithMarketData<SupportedChainId, SupportedCurrency>[]> {\n // Refresh supported networks in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedNetworks handles errors internally and always resolves\n if (!lastFetchedSupportedNetworks) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedNetworks();\n }\n\n // Get dynamically fetched supported chain IDs for V3\n const supportedChainIdsV3 = getSupportedChainIdsV3AsHex();\n\n const assetsWithIds: EvmAssetWithId<SupportedChainId>[] = assets\n // Filter out assets that are not supported by V3 of the Price API.\n .filter((asset) => supportedChainIdsV3.includes(asset.chainId))\n .map((asset) => {\n const assetId = getAssetId({\n chainId: asset.chainId,\n tokenAddress: asset.tokenAddress,\n nativeAssetIdentifiers: this.#nativeAssetIdentifiers,\n });\n\n if (!assetId) {\n return undefined;\n }\n\n return {\n ...asset,\n assetId,\n };\n })\n .filter(\n (asset): asset is EvmAssetWithId<SupportedChainId> =>\n asset !== undefined,\n );\n\n if (assetsWithIds.length === 0) {\n return [];\n }\n\n const url = new URL(`${BASE_URL_V3}/spot-prices`);\n url.searchParams.append(\n 'assetIds',\n assetsWithIds.map((asset) => asset.assetId).join(','),\n );\n url.searchParams.append('vsCurrency', currency);\n url.searchParams.append('includeMarketData', 'true');\n\n const addressCryptoDataMap: {\n [assetId: CaipAssetType]: Omit<\n MarketDataDetails,\n 'currency' | 'tokenAddress'\n >;\n } = await this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n );\n\n return assetsWithIds\n .map((assetWithId) => {\n const marketData = addressCryptoDataMap[assetWithId.assetId];\n\n if (!marketData) {\n return undefined;\n }\n\n return {\n ...marketData,\n ...assetWithId,\n currency,\n };\n })\n .filter((entry): entry is NonNullable<typeof entry> => Boolean(entry));\n }\n\n /**\n * Retrieves exchange rates in the given base currency.\n *\n * @param args - The arguments to this function.\n * @param args.baseCurrency - The desired base currency of the exchange rates.\n * @param args.includeUsdRate - Whether to include the USD rate in the response.\n * @param args.cryptocurrencies - The cryptocurrencies to get exchange rates for.\n * @returns The exchange rates for the requested base currency.\n */\n async fetchExchangeRates({\n baseCurrency,\n includeUsdRate,\n cryptocurrencies,\n }: {\n baseCurrency: SupportedCurrency;\n includeUsdRate: boolean;\n cryptocurrencies: string[];\n }): Promise<ExchangeRatesByCurrency<SupportedCurrency>> {\n // Refresh supported currencies in background (non-blocking)\n // This ensures the list stays fresh during normal polling\n // Note: fetchSupportedCurrencies handles errors internally and always resolves\n if (!lastFetchedCurrencies) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchSupportedCurrencies();\n }\n\n const url = new URL(`${BASE_URL_V1}/exchange-rates`);\n url.searchParams.append('baseCurrency', baseCurrency);\n\n const urlUsd = new URL(`${BASE_URL_V1}/exchange-rates`);\n urlUsd.searchParams.append('baseCurrency', 'usd');\n\n const [exchangeRatesResult, exchangeRatesResultUsd] =\n await Promise.allSettled([\n this.#policy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n ),\n ...(includeUsdRate && baseCurrency.toLowerCase() !== 'usd'\n ? [\n this.#policy.execute(() =>\n handleFetch(urlUsd, {\n headers: { 'Cache-Control': 'no-cache' },\n }),\n ),\n ]\n : []),\n ]);\n\n // Handle resolved/rejected\n const exchangeRates =\n exchangeRatesResult.status === 'fulfilled'\n ? exchangeRatesResult.value\n : {};\n const exchangeRatesUsd =\n exchangeRatesResultUsd?.status === 'fulfilled'\n ? exchangeRatesResultUsd.value\n : {};\n\n if (exchangeRatesResult.status === 'rejected') {\n throw new Error('Failed to fetch');\n }\n\n const filteredExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRates[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRates[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (Object.keys(filteredExchangeRates).length === 0) {\n throw new Error(\n 'None of the cryptocurrencies are supported by price api',\n );\n }\n\n const filteredUsdExchangeRates = cryptocurrencies.reduce((acc, key) => {\n if (exchangeRatesUsd[key.toLowerCase() as SupportedCurrency]) {\n acc[key.toLowerCase() as SupportedCurrency] =\n exchangeRatesUsd[key.toLowerCase() as SupportedCurrency];\n }\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n if (baseCurrency.toLowerCase() === 'usd') {\n Object.keys(filteredExchangeRates).forEach((key) => {\n filteredExchangeRates[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n usd: filteredExchangeRates[key as SupportedCurrency]?.value,\n };\n });\n return filteredExchangeRates;\n }\n if (!includeUsdRate) {\n return filteredExchangeRates;\n }\n\n const merged = Object.keys(filteredExchangeRates).reduce((acc, key) => {\n acc[key as SupportedCurrency] = {\n ...filteredExchangeRates[key as SupportedCurrency],\n ...(filteredUsdExchangeRates[key as SupportedCurrency]?.value\n ? { usd: filteredUsdExchangeRates[key as SupportedCurrency]?.value }\n : {}),\n };\n return acc;\n }, {} as ExchangeRatesByCurrency<SupportedCurrency>);\n\n return merged;\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 // Use dynamically fetched supported networks\n const supportedChainIds = getSupportedChainIdsV3AsHex();\n // Also include the hardcoded fallback list for backwards compatibility\n const allSupportedChainIds: readonly string[] = [\n ...new Set([...supportedChainIds, ...SUPPORTED_CHAIN_IDS]),\n ];\n return (\n typeof chainId === 'string' && allSupportedChainIds.includes(chainId)\n );\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 = getSupportedCurrencies();\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n\n /**\n * Fetches the list of supported currencies from the API.\n *\n * @returns The list of supported currencies.\n */\n async updateSupportedCurrencies(): Promise<string[]> {\n return fetchSupportedCurrencies();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/assets-controllers",
|
|
3
|
-
"version": "110.0.
|
|
3
|
+
"version": "110.0.1-preview-2296abeaf",
|
|
4
4
|
"description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"@metamask/base-controller": "^9.1.0",
|
|
69
69
|
"@metamask/contract-metadata": "^2.4.0",
|
|
70
70
|
"@metamask/controller-utils": "^12.3.0",
|
|
71
|
-
"@metamask/core-backend": "^
|
|
71
|
+
"@metamask/core-backend": "^8.0.0",
|
|
72
72
|
"@metamask/eth-query": "^4.0.0",
|
|
73
|
-
"@metamask/keyring-api": "^23.
|
|
73
|
+
"@metamask/keyring-api": "^23.7.0",
|
|
74
74
|
"@metamask/keyring-controller": "^27.1.0",
|
|
75
75
|
"@metamask/messenger": "^2.0.0",
|
|
76
76
|
"@metamask/metamask-eth-abis": "^3.1.1",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"@metamask/snaps-sdk": "^11.0.0",
|
|
88
88
|
"@metamask/snaps-utils": "^12.1.2",
|
|
89
89
|
"@metamask/storage-service": "^1.0.2",
|
|
90
|
-
"@metamask/transaction-controller": "^69.
|
|
90
|
+
"@metamask/transaction-controller": "^69.3.0",
|
|
91
91
|
"@metamask/utils": "^11.11.0",
|
|
92
92
|
"@tanstack/query-core": "^5.62.16",
|
|
93
93
|
"@types/bn.js": "^5.1.5",
|
|
@@ -104,11 +104,11 @@
|
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@babel/runtime": "^7.23.9",
|
|
107
|
-
"@metamask/account-api": "^1.
|
|
107
|
+
"@metamask/account-api": "^1.1.1",
|
|
108
108
|
"@metamask/auto-changelog": "^6.1.0",
|
|
109
109
|
"@metamask/ethjs-provider-http": "^0.3.0",
|
|
110
|
-
"@metamask/keyring-internal-api": "^11.0.
|
|
111
|
-
"@metamask/keyring-snap-client": "^9.2.
|
|
110
|
+
"@metamask/keyring-internal-api": "^11.0.2",
|
|
111
|
+
"@metamask/keyring-snap-client": "^9.2.1",
|
|
112
112
|
"@metamask/providers": "^22.1.0",
|
|
113
113
|
"@ts-bridge/cli": "^0.6.4",
|
|
114
114
|
"@types/jest": "^30.0.0",
|