@metamask/assets-controllers 90.0.0 → 92.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/dist/CurrencyRateController.cjs +3 -3
  3. package/dist/CurrencyRateController.cjs.map +1 -1
  4. package/dist/CurrencyRateController.d.cts.map +1 -1
  5. package/dist/CurrencyRateController.d.mts.map +1 -1
  6. package/dist/CurrencyRateController.mjs +3 -3
  7. package/dist/CurrencyRateController.mjs.map +1 -1
  8. package/dist/TokenBalancesController.cjs +48 -10
  9. package/dist/TokenBalancesController.cjs.map +1 -1
  10. package/dist/TokenBalancesController.d.cts +2 -1
  11. package/dist/TokenBalancesController.d.cts.map +1 -1
  12. package/dist/TokenBalancesController.d.mts +2 -1
  13. package/dist/TokenBalancesController.d.mts.map +1 -1
  14. package/dist/TokenBalancesController.mjs +49 -11
  15. package/dist/TokenBalancesController.mjs.map +1 -1
  16. package/dist/TokenDetectionController.cjs +12 -7
  17. package/dist/TokenDetectionController.cjs.map +1 -1
  18. package/dist/TokenDetectionController.d.cts +2 -1
  19. package/dist/TokenDetectionController.d.cts.map +1 -1
  20. package/dist/TokenDetectionController.d.mts +2 -1
  21. package/dist/TokenDetectionController.d.mts.map +1 -1
  22. package/dist/TokenDetectionController.mjs +12 -7
  23. package/dist/TokenDetectionController.mjs.map +1 -1
  24. package/dist/TokenRatesController.cjs +82 -278
  25. package/dist/TokenRatesController.cjs.map +1 -1
  26. package/dist/TokenRatesController.d.cts +9 -35
  27. package/dist/TokenRatesController.d.cts.map +1 -1
  28. package/dist/TokenRatesController.d.mts +9 -35
  29. package/dist/TokenRatesController.d.mts.map +1 -1
  30. package/dist/TokenRatesController.mjs +83 -279
  31. package/dist/TokenRatesController.mjs.map +1 -1
  32. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +2 -3
  33. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
  34. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
  35. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
  36. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs +2 -3
  37. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
  38. package/dist/TokenSearchDiscoveryDataController/types.cjs.map +1 -1
  39. package/dist/TokenSearchDiscoveryDataController/types.d.cts +2 -2
  40. package/dist/TokenSearchDiscoveryDataController/types.d.cts.map +1 -1
  41. package/dist/TokenSearchDiscoveryDataController/types.d.mts +2 -2
  42. package/dist/TokenSearchDiscoveryDataController/types.d.mts.map +1 -1
  43. package/dist/TokenSearchDiscoveryDataController/types.mjs.map +1 -1
  44. package/dist/assetsUtil.cjs +11 -5
  45. package/dist/assetsUtil.cjs.map +1 -1
  46. package/dist/assetsUtil.d.cts +2 -2
  47. package/dist/assetsUtil.d.cts.map +1 -1
  48. package/dist/assetsUtil.d.mts +2 -2
  49. package/dist/assetsUtil.d.mts.map +1 -1
  50. package/dist/assetsUtil.mjs +11 -5
  51. package/dist/assetsUtil.mjs.map +1 -1
  52. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +8 -8
  53. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -1
  54. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts +2 -1
  55. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts.map +1 -1
  56. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts +2 -1
  57. package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts.map +1 -1
  58. package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs +8 -8
  59. package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -1
  60. package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs +18 -8
  61. package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs.map +1 -1
  62. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts +4 -2
  63. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts.map +1 -1
  64. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts +4 -2
  65. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts.map +1 -1
  66. package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs +18 -8
  67. package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs.map +1 -1
  68. package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
  69. package/dist/token-prices-service/abstract-token-prices-service.d.cts +17 -43
  70. package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
  71. package/dist/token-prices-service/abstract-token-prices-service.d.mts +17 -43
  72. package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
  73. package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
  74. package/dist/token-prices-service/codefi-v2.cjs +177 -109
  75. package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
  76. package/dist/token-prices-service/codefi-v2.d.cts +47 -10
  77. package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
  78. package/dist/token-prices-service/codefi-v2.d.mts +47 -10
  79. package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
  80. package/dist/token-prices-service/codefi-v2.mjs +177 -109
  81. package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
  82. package/dist/token-service.cjs +6 -4
  83. package/dist/token-service.cjs.map +1 -1
  84. package/dist/token-service.d.cts +3 -1
  85. package/dist/token-service.d.cts.map +1 -1
  86. package/dist/token-service.d.mts +3 -1
  87. package/dist/token-service.d.mts.map +1 -1
  88. package/dist/token-service.mjs +6 -4
  89. package/dist/token-service.mjs.map +1 -1
  90. package/package.json +14 -24
@@ -1 +1 @@
1
- {"version":3,"file":"codefi-v2.d.cts","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names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AAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIrD;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAI3D;;;;;;;;OAQG;IACG,gBAAgB,CAAC,EACrB,MAAM,EACN,QAAQ,GACT,EAAE;QACD,MAAM,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACrD,QAAQ,EAAE,iBAAiB,CAAC;KAC7B,GAAG,OAAO,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,EAAE,CAAC;IAuI1E;;;;;;;;OAQG;IACG,kBAAkB,CAAC,EACvB,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,EAAE;QACD,YAAY,EAAE,iBAAiB,CAAC;QAChC,cAAc,EAAE,OAAO,CAAC;QACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;KAC5B,GAAG,OAAO,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;IAqFvD;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,gBAAgB;IAKvE;;;;;;;OAOG;IACH,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,iBAAiB;CAO5E"}
@@ -1,11 +1,11 @@
1
1
  import type { ServicePolicy } from "@metamask/controller-utils";
2
2
  import type { Hex } from "@metamask/utils";
3
- import type { AbstractTokenPricesService, ExchangeRatesByCurrency, TokenPricesByTokenAddress } from "./abstract-token-prices-service.mjs";
3
+ import type { AbstractTokenPricesService, EvmAssetAddressWithChain, EvmAssetWithMarketData, ExchangeRatesByCurrency } from "./abstract-token-prices-service.mjs";
4
4
  /**
5
5
  * The list of currencies that can be supplied as the `vsCurrency` parameter to
6
6
  * the `/spot-prices` endpoint, in lowercase form.
7
7
  */
8
- export declare const SUPPORTED_CURRENCIES: readonly ["btc", "eth", "ltc", "bch", "bnb", "eos", "xrp", "xlm", "link", "dot", "yfi", "usd", "aed", "ars", "aud", "bdt", "bhd", "bmd", "brl", "cad", "chf", "clp", "cny", "czk", "dkk", "eur", "gbp", "hkd", "huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php", "pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar", "xdr", "xag", "xau", "bits", "sats"];
8
+ export declare const SUPPORTED_CURRENCIES: readonly ["btc", "eth", "ltc", "bch", "bnb", "eos", "xrp", "xlm", "link", "dot", "yfi", "usd", "aed", "ars", "aud", "bdt", "bhd", "bmd", "brl", "cad", "chf", "clp", "cny", "czk", "dkk", "eur", "gbp", "gel", "hkd", "huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "mon", "ngn", "nok", "nzd", "php", "pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar", "xdr", "xag", "xau", "bits", "sats", "cop", "kes", "ron", "dop", "crc", "hnl", "zmw", "svc", "bam", "pen", "gtq", "lbp", "amd", "sol", "sei", "sonic", "trx", "taiko", "pepu", "pol", "mnt", "nom", "avax"];
9
9
  /**
10
10
  * Represents the zero address, commonly used as a placeholder in blockchain transactions.
11
11
  * In the context of fetching market data, the zero address is utilized to retrieve information
@@ -22,6 +22,45 @@ export declare const ZERO_ADDRESS: Hex;
22
22
  * @returns The address of the chain's native token.
23
23
  */
24
24
  export declare const getNativeTokenAddress: (chainId: Hex) => Hex;
25
+ export declare const SPOT_PRICES_SUPPORT_INFO: {
26
+ readonly '0x1': "eip155:1/slip44:60";
27
+ readonly '0xa': "eip155:10/slip44:60";
28
+ readonly '0x19': "eip155:25/slip44:394";
29
+ readonly '0x38': "eip155:56/slip44:714";
30
+ readonly '0x39': "eip155:57/erc20:0x0000000000000000000000000000000000000000";
31
+ readonly '0x52': null;
32
+ readonly '0x58': "eip155:88/erc20:0x0000000000000000000000000000000000000000";
33
+ readonly '0x64': "eip155:100/slip44:700";
34
+ readonly '0x6a': "eip155:106/erc20:0x0000000000000000000000000000000000000000";
35
+ readonly '0x80': "eip155:128/erc20:0x0000000000000000000000000000000000000000";
36
+ readonly '0x89': "eip155:137/slip44:966";
37
+ readonly '0x8f': null;
38
+ readonly '0x92': "eip155:146/slip44:10007";
39
+ readonly '0xfa': "eip155:250/slip44:1007";
40
+ readonly '0x141': "eip155:321/erc20:0x0000000000000000000000000000000000000000";
41
+ readonly '0x144': "eip155:324/slip44:60";
42
+ readonly '0x169': "eip155:361/erc20:0x0000000000000000000000000000000000000000";
43
+ readonly '0x3e7': "eip155:999/slip44:2457";
44
+ readonly '0x440': "eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
45
+ readonly '0x44d': "eip155:1101/slip44:60";
46
+ readonly '0x504': "eip155:1284/slip44:1284";
47
+ readonly '0x505': "eip155:1285/slip44:1285";
48
+ readonly '0x531': "eip155:1329/slip44:19000118";
49
+ readonly '0x1388': "eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
50
+ readonly '0x2105': "eip155:8453/slip44:60";
51
+ readonly '0x2710': "eip155:10000/erc20:0x0000000000000000000000000000000000000000";
52
+ readonly '0xa4b1': "eip155:42161/slip44:60";
53
+ readonly '0xa4ec': "eip155:42220/slip44:52752";
54
+ readonly '0xa516': "eip155:42262/erc20:0x0000000000000000000000000000000000000000";
55
+ readonly '0xa86a': "eip155:43114/slip44:9005";
56
+ readonly '0xe708': "eip155:59144/slip44:60";
57
+ readonly '0x13c31': "eip155:81457/erc20:0x0000000000000000000000000000000000000000";
58
+ readonly '0x17dcd': "eip155:97741/erc20:0x0000000000000000000000000000000000000000";
59
+ readonly '0x518af': null;
60
+ readonly '0x82750': "eip155:534352/slip44:60";
61
+ readonly '0x4e454152': "eip155:60/slip44:60";
62
+ readonly '0x63564c40': "eip155:1666600000/slip44:1023";
63
+ };
25
64
  /**
26
65
  * A currency that can be supplied as the `vsCurrency` parameter to
27
66
  * the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.
@@ -34,7 +73,7 @@ type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number] | Uppercase<(type
34
73
  *
35
74
  * @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.
36
75
  */
37
- export declare const SUPPORTED_CHAIN_IDS: readonly ["0x1", "0xa", "0x19", "0x38", "0x39", "0x42", "0x46", "0x52", "0x58", "0x64", "0x6a", "0x7a", "0x80", "0x89", "0xfa", "0x120", "0x141", "0x144", "0x169", "0x440", "0x504", "0x505", "0x1388", "0x2105", "0x150", "0x2710", "0xa4b1", "0xa4ec", "0xa516", "0xa86a", "0x518af", "0x4e454152", "0x63564c40", "0xe708", "0x531", "0x92", "0x8f"];
76
+ export declare const SUPPORTED_CHAIN_IDS: ("0x1" | "0x89" | "0x38" | "0x2105" | "0xa" | "0xa4b1" | "0x82750" | "0x531" | "0x8f" | "0xe708" | "0x440" | "0x1388" | "0x19" | "0x39" | "0x52" | "0x58" | "0x64" | "0x6a" | "0x80" | "0x92" | "0xfa" | "0x141" | "0x144" | "0x169" | "0x3e7" | "0x44d" | "0x504" | "0x505" | "0x2710" | "0xa4ec" | "0xa516" | "0xa86a" | "0x13c31" | "0x17dcd" | "0x518af" | "0x4e454152" | "0x63564c40")[];
38
77
  /**
39
78
  * A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,
40
79
  * but in hexadecimal form (for consistency with how we represent chain IDs in
@@ -45,7 +84,7 @@ type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
45
84
  * This version of the token prices service uses V2 of the Codefi Price API to
46
85
  * fetch token prices.
47
86
  */
48
- export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency> {
87
+ export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, SupportedCurrency> {
49
88
  #private;
50
89
  /**
51
90
  * Construct a Codefi Token Price Service.
@@ -114,16 +153,14 @@ export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesSe
114
153
  * given addresses which are expected to live on the given chain.
115
154
  *
116
155
  * @param args - The arguments to function.
117
- * @param args.chainId - An EIP-155 chain ID.
118
- * @param args.tokenAddresses - Addresses for tokens that live on the chain.
156
+ * @param args.assets - The assets to get prices for.
119
157
  * @param args.currency - The desired currency of the token prices.
120
158
  * @returns The prices for the requested tokens.
121
159
  */
122
- fetchTokenPrices({ chainId, tokenAddresses, currency, }: {
123
- chainId: SupportedChainId;
124
- tokenAddresses: Hex[];
160
+ fetchTokenPrices({ assets, currency, }: {
161
+ assets: EvmAssetAddressWithChain<SupportedChainId>[];
125
162
  currency: SupportedCurrency;
126
- }): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>>;
163
+ }): Promise<EvmAssetWithMarketData<SupportedChainId, SupportedCurrency>[]>;
127
164
  /**
128
165
  * Retrieves exchange rates in the given base currency.
129
166
  *
@@ -1 +1 @@
1
- {"version":3,"file":"codefi-v2.d.mts","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EACV,0BAA0B,EAC1B,uBAAuB,EAEvB,yBAAyB,EAC1B,4CAAwC;AAEzC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,ybA2HvB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,GAC4B,CAAC;AAUxD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,GAAG,KAAG,GACC,CAAC;AAEvD;;;GAGG;AACH,KAAK,iBAAiB,GAClB,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,GACrC,SAAS,CAAC,CAAC,OAAO,oBAAoB,CAAC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iB,CAAC;QAChC,cAAc,EAAE,OAAO,CAAC;QACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;KAC5B,GAAG,OAAO,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;IAqFvD;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,gBAAgB;IAKvE;;;;;;;OAOG;IACH,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,iBAAiB;CAO5E"}
@@ -9,9 +9,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _CodefiTokenPricesServiceV2_policy;
12
+ var _CodefiTokenPricesServiceV2_instances, _CodefiTokenPricesServiceV2_policy, _CodefiTokenPricesServiceV2_fetchTokenPricesV3, _CodefiTokenPricesServiceV2_fetchTokenPricesV2;
13
13
  import { createServicePolicy, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, handleFetch } from "@metamask/controller-utils";
14
- import { hexToNumber } from "@metamask/utils";
14
+ import { hexToNumber, KnownCaipNamespace, toCaipChainId } from "@metamask/utils";
15
15
  /**
16
16
  * The list of currencies that can be supplied as the `vsCurrency` parameter to
17
17
  * the `/spot-prices` endpoint, in lowercase form.
@@ -71,6 +71,8 @@ export const SUPPORTED_CURRENCIES = [
71
71
  'eur',
72
72
  // British Pound Sterling
73
73
  'gbp',
74
+ // Georgian Lari
75
+ 'gel',
74
76
  // Hong Kong Dollar
75
77
  'hkd',
76
78
  // Hungarian Forint
@@ -95,6 +97,8 @@ export const SUPPORTED_CURRENCIES = [
95
97
  'mxn',
96
98
  // Malaysian Ringgit
97
99
  'myr',
100
+ // Monad
101
+ 'mon',
98
102
  // Nigerian Naira
99
103
  'ngn',
100
104
  // Norwegian Krone
@@ -139,6 +143,52 @@ export const SUPPORTED_CURRENCIES = [
139
143
  'bits',
140
144
  // Satoshi
141
145
  'sats',
146
+ // Colombian Peso
147
+ 'cop',
148
+ // Kenyan Shilling
149
+ 'kes',
150
+ // Romanian Leu
151
+ 'ron',
152
+ // Dominican Peso
153
+ 'dop',
154
+ // Costa Rican Colón
155
+ 'crc',
156
+ // Honduran Lempira
157
+ 'hnl',
158
+ // Zambian Kwacha
159
+ 'zmw',
160
+ // Salvadoran Colón
161
+ 'svc',
162
+ // Bosnia-Herzegovina Convertible Mark
163
+ 'bam',
164
+ // Peruvian Sol
165
+ 'pen',
166
+ // Guatemalan Quetzal
167
+ 'gtq',
168
+ // Lebanese Pound
169
+ 'lbp',
170
+ // Armenian Dram
171
+ 'amd',
172
+ // Solana
173
+ 'sol',
174
+ // Sei
175
+ 'sei',
176
+ // Sonic
177
+ 'sonic',
178
+ // Tron
179
+ 'trx',
180
+ // Taiko
181
+ 'taiko',
182
+ // Pepu
183
+ 'pepu',
184
+ // Polygon
185
+ 'pol',
186
+ // Mantle
187
+ 'mnt',
188
+ // Onomy
189
+ 'nom',
190
+ // Avalanche
191
+ 'avax',
142
192
  ];
143
193
  /**
144
194
  * Represents the zero address, commonly used as a placeholder in blockchain transactions.
@@ -152,7 +202,9 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
152
202
  * Only for chains whose native tokens have a specific address.
153
203
  */
154
204
  const chainIdToNativeTokenAddress = {
155
- '0x89': '0x0000000000000000000000000000000000001010',
205
+ '0x89': '0x0000000000000000000000000000000000001010', // Polygon
206
+ '0x440': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda
207
+ '0x1388': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle
156
208
  };
157
209
  /**
158
210
  * Returns the address that should be used to query the price api for the
@@ -163,6 +215,47 @@ const chainIdToNativeTokenAddress = {
163
215
  * @returns The address of the chain's native token.
164
216
  */
165
217
  export const getNativeTokenAddress = (chainId) => chainIdToNativeTokenAddress[chainId] ?? ZERO_ADDRESS;
218
+ // Source: https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts
219
+ // We can only support PricesAPI V3 for EVM chains that have a CAIP-19 native asset mapping.
220
+ export const SPOT_PRICES_SUPPORT_INFO = {
221
+ '0x1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH
222
+ '0xa': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH
223
+ '0x19': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO
224
+ '0x38': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB
225
+ '0x39': 'eip155:57/erc20:0x0000000000000000000000000000000000000000', // 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS
226
+ '0x52': null, // 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR
227
+ '0x58': 'eip155:88/erc20:0x0000000000000000000000000000000000000000', // 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO
228
+ '0x64': 'eip155:100/slip44:700', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI
229
+ '0x6a': 'eip155:106/erc20:0x0000000000000000000000000000000000000000', // 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX
230
+ '0x80': 'eip155:128/erc20:0x0000000000000000000000000000000000000000', // 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT
231
+ '0x89': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL
232
+ '0x8f': null, // 'eip155:143/slip44:268435779', // Monad Mainnet - Native symbol: MON
233
+ '0x92': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S
234
+ '0xfa': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM
235
+ '0x141': 'eip155:321/erc20:0x0000000000000000000000000000000000000000', // 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS
236
+ '0x144': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH
237
+ '0x169': 'eip155:361/erc20:0x0000000000000000000000000000000000000000', // 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL
238
+ '0x3e7': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: ETH
239
+ '0x440': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // 'eip155:1088/slip44:XXX', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS
240
+ '0x44d': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH
241
+ '0x504': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR
242
+ '0x505': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR
243
+ '0x531': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI
244
+ '0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // 'eip155:5000/slip44:XXX', // Mantle - Native symbol: MNT
245
+ '0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH
246
+ '0x2710': 'eip155:10000/erc20:0x0000000000000000000000000000000000000000', // 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH
247
+ '0xa4b1': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH
248
+ '0xa4ec': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO
249
+ '0xa516': 'eip155:42262/erc20:0x0000000000000000000000000000000000000000', // 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE
250
+ '0xa86a': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX
251
+ '0xe708': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH
252
+ '0x13c31': 'eip155:81457/erc20:0x0000000000000000000000000000000000000000', // 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH
253
+ '0x17dcd': 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // 'eip155:97741/slip44:XXX', // Pepe Unchained Mainnet - Native symbol: PEPU
254
+ '0x518af': null, // 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS
255
+ '0x82750': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH
256
+ '0x4e454152': 'eip155:60/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH
257
+ '0x63564c40': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE
258
+ };
166
259
  /**
167
260
  * The list of chain IDs that can be supplied in the URL for the `/spot-prices`
168
261
  * endpoint, but in hexadecimal form (for consistency with how we represent
@@ -170,93 +263,22 @@ export const getNativeTokenAddress = (chainId) => chainIdToNativeTokenAddress[ch
170
263
  *
171
264
  * @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.
172
265
  */
173
- export const SUPPORTED_CHAIN_IDS = [
174
- // Ethereum Mainnet
175
- '0x1',
176
- // OP Mainnet
177
- '0xa',
178
- // Cronos Mainnet
179
- '0x19',
180
- // BNB Smart Chain Mainnet
181
- '0x38',
182
- // Syscoin Mainnet
183
- '0x39',
184
- // OKXChain Mainnet
185
- '0x42',
186
- // Hoo Smart Chain
187
- '0x46',
188
- // Meter Mainnet
189
- '0x52',
190
- // TomoChain
191
- '0x58',
192
- // Gnosis
193
- '0x64',
194
- // Velas EVM Mainnet
195
- '0x6a',
196
- // Fuse Mainnet
197
- '0x7a',
198
- // Huobi ECO Chain Mainnet
199
- '0x80',
200
- // Polygon Mainnet
201
- '0x89',
202
- // Fantom Opera
203
- '0xfa',
204
- // Boba Network
205
- '0x120',
206
- // KCC Mainnet
207
- '0x141',
208
- // zkSync Era Mainnet
209
- '0x144',
210
- // Theta Mainnet
211
- '0x169',
212
- // Metis Andromeda Mainnet
213
- '0x440',
214
- // Moonbeam
215
- '0x504',
216
- // Moonriver
217
- '0x505',
218
- // Mantle
219
- '0x1388',
220
- // Base
221
- '0x2105',
222
- // Shiden
223
- '0x150',
224
- // Smart Bitcoin Cash
225
- '0x2710',
226
- // Arbitrum One
227
- '0xa4b1',
228
- // Celo Mainnet
229
- '0xa4ec',
230
- // Oasis Emerald
231
- '0xa516',
232
- // Avalanche C-Chain
233
- '0xa86a',
234
- // Polis Mainnet
235
- '0x518af',
236
- // Aurora Mainnet
237
- '0x4e454152',
238
- // Harmony Mainnet Shard 0
239
- '0x63564c40',
240
- // Linea Mainnet
241
- '0xe708',
242
- // Sei Mainnet
243
- '0x531',
244
- // Sonic Mainnet
245
- '0x92',
246
- // Monad Mainnet
247
- '0x8f',
248
- ];
266
+ export const SUPPORTED_CHAIN_IDS = Object.keys(SPOT_PRICES_SUPPORT_INFO);
249
267
  /**
250
- * All requests to V2 of the Price API start with this.
268
+ * The list of chain IDs that are supported by V3 of the Codefi Price API.
269
+ * Only includes chain IDs from SPOT_PRICES_SUPPORT_INFO that have a non-null CAIP-19 value.
251
270
  */
252
- const BASE_URL = 'https://price.api.cx.metamask.io/v2';
271
+ const SUPPORTED_CHAIN_IDS_V3 = Object.keys(SPOT_PRICES_SUPPORT_INFO).filter((chainId) => SPOT_PRICES_SUPPORT_INFO[chainId] !== null);
253
272
  const BASE_URL_V1 = 'https://price.api.cx.metamask.io/v1';
273
+ const BASE_URL_V2 = 'https://price.api.cx.metamask.io/v2';
274
+ const BASE_URL_V3 = 'https://price.api.cx.metamask.io/v3';
254
275
  /**
255
276
  * This version of the token prices service uses V2 of the Codefi Price API to
256
277
  * fetch token prices.
257
278
  */
258
279
  export class CodefiTokenPricesServiceV2 {
259
280
  constructor({ degradedThreshold = DEFAULT_DEGRADED_THRESHOLD, retries = DEFAULT_MAX_RETRIES, maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES, onBreak, onDegraded, circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION, } = {}) {
281
+ _CodefiTokenPricesServiceV2_instances.add(this);
260
282
  _CodefiTokenPricesServiceV2_policy.set(this, void 0);
261
283
  __classPrivateFieldSet(this, _CodefiTokenPricesServiceV2_policy, createServicePolicy({
262
284
  maxRetries: retries,
@@ -296,36 +318,14 @@ export class CodefiTokenPricesServiceV2 {
296
318
  * given addresses which are expected to live on the given chain.
297
319
  *
298
320
  * @param args - The arguments to function.
299
- * @param args.chainId - An EIP-155 chain ID.
300
- * @param args.tokenAddresses - Addresses for tokens that live on the chain.
321
+ * @param args.assets - The assets to get prices for.
301
322
  * @param args.currency - The desired currency of the token prices.
302
323
  * @returns The prices for the requested tokens.
303
324
  */
304
- async fetchTokenPrices({ chainId, tokenAddresses, currency, }) {
305
- const chainIdAsNumber = hexToNumber(chainId);
306
- const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);
307
- url.searchParams.append('tokenAddresses', [getNativeTokenAddress(chainId), ...tokenAddresses].join(','));
308
- url.searchParams.append('vsCurrency', currency);
309
- url.searchParams.append('includeMarketData', 'true');
310
- const addressCryptoDataMap = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_policy, "f").execute(() => handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }));
311
- return [getNativeTokenAddress(chainId), ...tokenAddresses].reduce((obj, tokenAddress) => {
312
- // The Price API lowercases both currency and token addresses, so we have
313
- // to keep track of them and make sure we return the original versions.
314
- const lowercasedTokenAddress = tokenAddress.toLowerCase();
315
- const marketData = addressCryptoDataMap[lowercasedTokenAddress];
316
- if (!marketData) {
317
- return obj;
318
- }
319
- const token = {
320
- tokenAddress,
321
- currency,
322
- ...marketData,
323
- };
324
- return {
325
- ...obj,
326
- [tokenAddress]: token,
327
- };
328
- }, {});
325
+ async fetchTokenPrices({ assets, currency, }) {
326
+ const v3Assets = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_instances, "m", _CodefiTokenPricesServiceV2_fetchTokenPricesV3).call(this, assets, currency);
327
+ const v2Assets = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_instances, "m", _CodefiTokenPricesServiceV2_fetchTokenPricesV2).call(this, assets, currency);
328
+ return [...v3Assets, ...v2Assets];
329
329
  }
330
330
  /**
331
331
  * Retrieves exchange rates in the given base currency.
@@ -426,5 +426,73 @@ export class CodefiTokenPricesServiceV2 {
426
426
  supportedCurrencies.includes(currency.toLowerCase()));
427
427
  }
428
428
  }
429
- _CodefiTokenPricesServiceV2_policy = new WeakMap();
429
+ _CodefiTokenPricesServiceV2_policy = new WeakMap(), _CodefiTokenPricesServiceV2_instances = new WeakSet(), _CodefiTokenPricesServiceV2_fetchTokenPricesV3 = async function _CodefiTokenPricesServiceV2_fetchTokenPricesV3(assets, currency) {
430
+ const assetsWithIds = assets
431
+ // Filter out assets that are not supported by V3 of the Price API.
432
+ .filter((asset) => SUPPORTED_CHAIN_IDS_V3.includes(asset.chainId))
433
+ .map((asset) => {
434
+ const caipChainId = toCaipChainId(KnownCaipNamespace.Eip155, hexToNumber(asset.chainId).toString());
435
+ const nativeAddress = getNativeTokenAddress(asset.chainId);
436
+ return {
437
+ ...asset,
438
+ assetId: (nativeAddress.toLowerCase() ===
439
+ asset.tokenAddress.toLowerCase()
440
+ ? SPOT_PRICES_SUPPORT_INFO[asset.chainId]
441
+ : `${caipChainId}/erc20:${asset.tokenAddress.toLowerCase()}`),
442
+ };
443
+ })
444
+ .filter((asset) => asset.assetId);
445
+ if (assetsWithIds.length === 0) {
446
+ return [];
447
+ }
448
+ const url = new URL(`${BASE_URL_V3}/spot-prices`);
449
+ url.searchParams.append('assetIds', assetsWithIds.map((asset) => asset.assetId).join(','));
450
+ url.searchParams.append('vsCurrency', currency);
451
+ url.searchParams.append('includeMarketData', 'true');
452
+ const addressCryptoDataMap = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_policy, "f").execute(() => handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }));
453
+ return assetsWithIds
454
+ .map((assetWithId) => {
455
+ const marketData = addressCryptoDataMap[assetWithId.assetId];
456
+ if (!marketData) {
457
+ return undefined;
458
+ }
459
+ return {
460
+ ...marketData,
461
+ ...assetWithId,
462
+ currency,
463
+ };
464
+ })
465
+ .filter((entry) => Boolean(entry));
466
+ }, _CodefiTokenPricesServiceV2_fetchTokenPricesV2 = async function _CodefiTokenPricesServiceV2_fetchTokenPricesV2(assets, currency) {
467
+ const v2SupportedAssets = assets.filter((asset) => !SUPPORTED_CHAIN_IDS_V3.includes(asset.chainId));
468
+ const assetsByChainId = v2SupportedAssets.reduce((acc, { chainId, tokenAddress }) => {
469
+ (acc[chainId] ?? (acc[chainId] = [])).push(tokenAddress);
470
+ return acc;
471
+ }, {});
472
+ const promises = Object.entries(assetsByChainId).map(async ([chainId, tokenAddresses]) => {
473
+ if (tokenAddresses.length === 0) {
474
+ return [];
475
+ }
476
+ const url = new URL(`${BASE_URL_V2}/chains/${chainId}/spot-prices`);
477
+ url.searchParams.append('tokenAddresses', tokenAddresses.join(','));
478
+ url.searchParams.append('vsCurrency', currency);
479
+ url.searchParams.append('includeMarketData', 'true');
480
+ const addressCryptoDataMap = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_policy, "f").execute(() => handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }));
481
+ return tokenAddresses
482
+ .map((tokenAddress) => {
483
+ const marketData = addressCryptoDataMap[tokenAddress.toLowerCase()];
484
+ if (!marketData) {
485
+ return undefined;
486
+ }
487
+ return {
488
+ ...marketData,
489
+ tokenAddress,
490
+ chainId: chainId,
491
+ currency,
492
+ };
493
+ })
494
+ .filter((entry) => Boolean(entry));
495
+ });
496
+ return await Promise.allSettled(promises).then((results) => results.flatMap((result) => result.status === 'fulfilled' ? result.value : []));
497
+ };
430
498
  //# sourceMappingURL=codefi-v2.mjs.map