@metamask-previews/assets-controllers 89.0.1-preview-f83c2058 → 90.0.0-preview-4ed214fa
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 +18 -11
- package/dist/CurrencyRateController.cjs +3 -3
- package/dist/CurrencyRateController.cjs.map +1 -1
- package/dist/CurrencyRateController.d.cts.map +1 -1
- package/dist/CurrencyRateController.d.mts.map +1 -1
- package/dist/CurrencyRateController.mjs +3 -3
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +278 -82
- package/dist/TokenRatesController.cjs.map +1 -1
- package/dist/TokenRatesController.d.cts +35 -9
- package/dist/TokenRatesController.d.cts.map +1 -1
- package/dist/TokenRatesController.d.mts +35 -9
- package/dist/TokenRatesController.d.mts.map +1 -1
- package/dist/TokenRatesController.mjs +279 -83
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +3 -2
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs +3 -2
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.cts +2 -2
- package/dist/TokenSearchDiscoveryDataController/types.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.d.mts +2 -2
- package/dist/TokenSearchDiscoveryDataController/types.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/types.mjs.map +1 -1
- package/dist/assetsUtil.cjs +5 -11
- package/dist/assetsUtil.cjs.map +1 -1
- package/dist/assetsUtil.d.cts +2 -2
- package/dist/assetsUtil.d.cts.map +1 -1
- package/dist/assetsUtil.d.mts +2 -2
- package/dist/assetsUtil.d.mts.map +1 -1
- package/dist/assetsUtil.mjs +5 -11
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/selectors/token-selectors.cjs +45 -3
- package/dist/selectors/token-selectors.cjs.map +1 -1
- package/dist/selectors/token-selectors.d.cts +35 -20
- package/dist/selectors/token-selectors.d.cts.map +1 -1
- package/dist/selectors/token-selectors.d.mts +35 -20
- package/dist/selectors/token-selectors.d.mts.map +1 -1
- package/dist/selectors/token-selectors.mjs +45 -3
- package/dist/selectors/token-selectors.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.cts +43 -17
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.mts +43 -17
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +109 -175
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.cts +10 -47
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.mts +10 -47
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
- package/dist/token-prices-service/codefi-v2.mjs +109 -175
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/package.json +21 -21
|
@@ -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,
|
|
3
|
+
import type { AbstractTokenPricesService, ExchangeRatesByCurrency, TokenPricesByTokenAddress } from "./abstract-token-prices-service.cjs";
|
|
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", "
|
|
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"];
|
|
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,45 +22,6 @@ 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 '0x92': "eip155:146/slip44:10007";
|
|
38
|
-
readonly '0xfa': "eip155:250/slip44:1007";
|
|
39
|
-
readonly '0x141': "eip155:321/erc20:0x0000000000000000000000000000000000000000";
|
|
40
|
-
readonly '0x144': "eip155:324/slip44:60";
|
|
41
|
-
readonly '0x169': "eip155:361/erc20:0x0000000000000000000000000000000000000000";
|
|
42
|
-
readonly '0x440': "eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
|
|
43
|
-
readonly '0x44d': "eip155:1101/slip44:60";
|
|
44
|
-
readonly '0x504': "eip155:1284/slip44:1284";
|
|
45
|
-
readonly '0x505': "eip155:1285/slip44:1285";
|
|
46
|
-
readonly '0x531': "eip155:1329/slip44:19000118";
|
|
47
|
-
readonly '0x1388': "eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
|
|
48
|
-
readonly '0x2105': "eip155:8453/slip44:60";
|
|
49
|
-
readonly '0x2710': "eip155:10000/erc20:0x0000000000000000000000000000000000000000";
|
|
50
|
-
readonly '0xa4b1': "eip155:42161/slip44:60";
|
|
51
|
-
readonly '0xa4ec': "eip155:42220/slip44:52752";
|
|
52
|
-
readonly '0xa516': "eip155:42262/erc20:0x0000000000000000000000000000000000000000";
|
|
53
|
-
readonly '0xa86a': "eip155:43114/slip44:9005";
|
|
54
|
-
readonly '0xe708': "eip155:59144/slip44:60";
|
|
55
|
-
readonly '0x13c31': "eip155:81457/erc20:0x0000000000000000000000000000000000000000";
|
|
56
|
-
readonly '0x17dcd': "eip155:97741/erc20:0x0000000000000000000000000000000000000000";
|
|
57
|
-
readonly '0x518af': null;
|
|
58
|
-
readonly '0x82750': "eip155:534352/slip44:60";
|
|
59
|
-
readonly '0x4e454152': "eip155:60/slip44:60";
|
|
60
|
-
readonly '0x63564c40': "eip155:1666600000/slip44:1023";
|
|
61
|
-
readonly '0x279f': "eip155:143/slip44:268435779";
|
|
62
|
-
readonly '0x3e7': "eip155:999/slip44:2457";
|
|
63
|
-
};
|
|
64
25
|
/**
|
|
65
26
|
* A currency that can be supplied as the `vsCurrency` parameter to
|
|
66
27
|
* the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.
|
|
@@ -73,7 +34,7 @@ type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number] | Uppercase<(type
|
|
|
73
34
|
*
|
|
74
35
|
* @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.
|
|
75
36
|
*/
|
|
76
|
-
export declare const SUPPORTED_CHAIN_IDS:
|
|
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"];
|
|
77
38
|
/**
|
|
78
39
|
* A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,
|
|
79
40
|
* but in hexadecimal form (for consistency with how we represent chain IDs in
|
|
@@ -84,7 +45,7 @@ type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
84
45
|
* This version of the token prices service uses V2 of the Codefi Price API to
|
|
85
46
|
* fetch token prices.
|
|
86
47
|
*/
|
|
87
|
-
export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, SupportedCurrency> {
|
|
48
|
+
export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency> {
|
|
88
49
|
#private;
|
|
89
50
|
/**
|
|
90
51
|
* Construct a Codefi Token Price Service.
|
|
@@ -153,14 +114,16 @@ export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesSe
|
|
|
153
114
|
* given addresses which are expected to live on the given chain.
|
|
154
115
|
*
|
|
155
116
|
* @param args - The arguments to function.
|
|
156
|
-
* @param args.
|
|
117
|
+
* @param args.chainId - An EIP-155 chain ID.
|
|
118
|
+
* @param args.tokenAddresses - Addresses for tokens that live on the chain.
|
|
157
119
|
* @param args.currency - The desired currency of the token prices.
|
|
158
120
|
* @returns The prices for the requested tokens.
|
|
159
121
|
*/
|
|
160
|
-
fetchTokenPrices({
|
|
161
|
-
|
|
122
|
+
fetchTokenPrices({ chainId, tokenAddresses, currency, }: {
|
|
123
|
+
chainId: SupportedChainId;
|
|
124
|
+
tokenAddresses: Hex[];
|
|
162
125
|
currency: SupportedCurrency;
|
|
163
|
-
}): Promise<
|
|
126
|
+
}): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>>;
|
|
164
127
|
/**
|
|
165
128
|
* Retrieves exchange rates in the given base currency.
|
|
166
129
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codefi-v2.d.cts","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"codefi-v2.d.cts","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,CAAC,MAAM,CAAC,CAAC,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,yVA2EtB,CAAC;AAEX;;;;GAIG;AACH,KAAK,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAwF7D;;;GAGG;AACH,qBAAa,0BACX,YACE,0BAA0B,CAAC,gBAAgB,EAAE,GAAG,EAAE,iBAAiB,CAAC;;IAItE;;;;;;;;;;;;OAYG;gBACS,IAAI,CAAC,EAAE;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B;IAED;;;;;;;;;;;;;;;;;;OAkBG;gBAES,IAAI,CAAC,EAAE;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;QACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B;IA+BD;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIrD;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAI3D;;;;;;;;;OASG;IACG,gBAAgB,CAAC,EACrB,OAAO,EACP,cAAc,EACd,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,gBAAgB,CAAC;QAC1B,cAAc,EAAE,GAAG,EAAE,CAAC;QACtB,QAAQ,EAAE,iBAAiB,CAAC;KAC7B,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC;IA+CvE;;;;;;;;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,
|
|
3
|
+
import type { AbstractTokenPricesService, ExchangeRatesByCurrency, TokenPricesByTokenAddress } 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", "
|
|
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"];
|
|
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,45 +22,6 @@ 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 '0x92': "eip155:146/slip44:10007";
|
|
38
|
-
readonly '0xfa': "eip155:250/slip44:1007";
|
|
39
|
-
readonly '0x141': "eip155:321/erc20:0x0000000000000000000000000000000000000000";
|
|
40
|
-
readonly '0x144': "eip155:324/slip44:60";
|
|
41
|
-
readonly '0x169': "eip155:361/erc20:0x0000000000000000000000000000000000000000";
|
|
42
|
-
readonly '0x440': "eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
|
|
43
|
-
readonly '0x44d': "eip155:1101/slip44:60";
|
|
44
|
-
readonly '0x504': "eip155:1284/slip44:1284";
|
|
45
|
-
readonly '0x505': "eip155:1285/slip44:1285";
|
|
46
|
-
readonly '0x531': "eip155:1329/slip44:19000118";
|
|
47
|
-
readonly '0x1388': "eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000";
|
|
48
|
-
readonly '0x2105': "eip155:8453/slip44:60";
|
|
49
|
-
readonly '0x2710': "eip155:10000/erc20:0x0000000000000000000000000000000000000000";
|
|
50
|
-
readonly '0xa4b1': "eip155:42161/slip44:60";
|
|
51
|
-
readonly '0xa4ec': "eip155:42220/slip44:52752";
|
|
52
|
-
readonly '0xa516': "eip155:42262/erc20:0x0000000000000000000000000000000000000000";
|
|
53
|
-
readonly '0xa86a': "eip155:43114/slip44:9005";
|
|
54
|
-
readonly '0xe708': "eip155:59144/slip44:60";
|
|
55
|
-
readonly '0x13c31': "eip155:81457/erc20:0x0000000000000000000000000000000000000000";
|
|
56
|
-
readonly '0x17dcd': "eip155:97741/erc20:0x0000000000000000000000000000000000000000";
|
|
57
|
-
readonly '0x518af': null;
|
|
58
|
-
readonly '0x82750': "eip155:534352/slip44:60";
|
|
59
|
-
readonly '0x4e454152': "eip155:60/slip44:60";
|
|
60
|
-
readonly '0x63564c40': "eip155:1666600000/slip44:1023";
|
|
61
|
-
readonly '0x279f': "eip155:143/slip44:268435779";
|
|
62
|
-
readonly '0x3e7': "eip155:999/slip44:2457";
|
|
63
|
-
};
|
|
64
25
|
/**
|
|
65
26
|
* A currency that can be supplied as the `vsCurrency` parameter to
|
|
66
27
|
* the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.
|
|
@@ -73,7 +34,7 @@ type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number] | Uppercase<(type
|
|
|
73
34
|
*
|
|
74
35
|
* @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.
|
|
75
36
|
*/
|
|
76
|
-
export declare const SUPPORTED_CHAIN_IDS:
|
|
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"];
|
|
77
38
|
/**
|
|
78
39
|
* A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,
|
|
79
40
|
* but in hexadecimal form (for consistency with how we represent chain IDs in
|
|
@@ -84,7 +45,7 @@ type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
84
45
|
* This version of the token prices service uses V2 of the Codefi Price API to
|
|
85
46
|
* fetch token prices.
|
|
86
47
|
*/
|
|
87
|
-
export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, SupportedCurrency> {
|
|
48
|
+
export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency> {
|
|
88
49
|
#private;
|
|
89
50
|
/**
|
|
90
51
|
* Construct a Codefi Token Price Service.
|
|
@@ -153,14 +114,16 @@ export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesSe
|
|
|
153
114
|
* given addresses which are expected to live on the given chain.
|
|
154
115
|
*
|
|
155
116
|
* @param args - The arguments to function.
|
|
156
|
-
* @param args.
|
|
117
|
+
* @param args.chainId - An EIP-155 chain ID.
|
|
118
|
+
* @param args.tokenAddresses - Addresses for tokens that live on the chain.
|
|
157
119
|
* @param args.currency - The desired currency of the token prices.
|
|
158
120
|
* @returns The prices for the requested tokens.
|
|
159
121
|
*/
|
|
160
|
-
fetchTokenPrices({
|
|
161
|
-
|
|
122
|
+
fetchTokenPrices({ chainId, tokenAddresses, currency, }: {
|
|
123
|
+
chainId: SupportedChainId;
|
|
124
|
+
tokenAddresses: Hex[];
|
|
162
125
|
currency: SupportedCurrency;
|
|
163
|
-
}): Promise<
|
|
126
|
+
}): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>>;
|
|
164
127
|
/**
|
|
165
128
|
* Retrieves exchange rates in the given base currency.
|
|
166
129
|
*
|
|
@@ -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,
|
|
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,CAAC,MAAM,CAAC,CAAC,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,yVA2EtB,CAAC;AAEX;;;;GAIG;AACH,KAAK,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAwF7D;;;GAGG;AACH,qBAAa,0BACX,YACE,0BAA0B,CAAC,gBAAgB,EAAE,GAAG,EAAE,iBAAiB,CAAC;;IAItE;;;;;;;;;;;;OAYG;gBACS,IAAI,CAAC,EAAE;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B;IAED;;;;;;;;;;;;;;;;;;OAkBG;gBAES,IAAI,CAAC,EAAE;QACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,0BAA0B,CAAC,EAAE,MAAM,CAAC;QACpC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;QACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B;IA+BD;;;;;;OAMG;IACH,OAAO,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAIrD;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAI3D;;;;;;;;;OASG;IACG,gBAAgB,CAAC,EACrB,OAAO,EACP,cAAc,EACd,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,gBAAgB,CAAC;QAC1B,cAAc,EAAE,GAAG,EAAE,CAAC;QACtB,QAAQ,EAAE,iBAAiB,CAAC;KAC7B,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC;IA+CvE;;;;;;;;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"}
|
|
@@ -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
|
|
12
|
+
var _CodefiTokenPricesServiceV2_policy;
|
|
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
|
|
14
|
+
import { hexToNumber } 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,8 +71,6 @@ export const SUPPORTED_CURRENCIES = [
|
|
|
71
71
|
'eur',
|
|
72
72
|
// British Pound Sterling
|
|
73
73
|
'gbp',
|
|
74
|
-
// Georgian Lari
|
|
75
|
-
'gel',
|
|
76
74
|
// Hong Kong Dollar
|
|
77
75
|
'hkd',
|
|
78
76
|
// Hungarian Forint
|
|
@@ -141,52 +139,6 @@ export const SUPPORTED_CURRENCIES = [
|
|
|
141
139
|
'bits',
|
|
142
140
|
// Satoshi
|
|
143
141
|
'sats',
|
|
144
|
-
// Colombian Peso
|
|
145
|
-
'cop',
|
|
146
|
-
// Kenyan Shilling
|
|
147
|
-
'kes',
|
|
148
|
-
// Romanian Leu
|
|
149
|
-
'ron',
|
|
150
|
-
// Dominican Peso
|
|
151
|
-
'dop',
|
|
152
|
-
// Costa Rican Colón
|
|
153
|
-
'crc',
|
|
154
|
-
// Honduran Lempira
|
|
155
|
-
'hnl',
|
|
156
|
-
// Zambian Kwacha
|
|
157
|
-
'zmw',
|
|
158
|
-
// Salvadoran Colón
|
|
159
|
-
'svc',
|
|
160
|
-
// Bosnia-Herzegovina Convertible Mark
|
|
161
|
-
'bam',
|
|
162
|
-
// Peruvian Sol
|
|
163
|
-
'pen',
|
|
164
|
-
// Guatemalan Quetzal
|
|
165
|
-
'gtq',
|
|
166
|
-
// Lebanese Pound
|
|
167
|
-
'lbp',
|
|
168
|
-
// Armenian Dram
|
|
169
|
-
'amd',
|
|
170
|
-
// Solana
|
|
171
|
-
'sol',
|
|
172
|
-
// Sei
|
|
173
|
-
'sei',
|
|
174
|
-
// Sonic
|
|
175
|
-
'sonic',
|
|
176
|
-
// Tron
|
|
177
|
-
'trx',
|
|
178
|
-
// Taiko
|
|
179
|
-
'taiko',
|
|
180
|
-
// Pepu
|
|
181
|
-
'pepu',
|
|
182
|
-
// Polygon
|
|
183
|
-
'pol',
|
|
184
|
-
// Mantle
|
|
185
|
-
'mnt',
|
|
186
|
-
// Onomy
|
|
187
|
-
'nom',
|
|
188
|
-
// Avalanche
|
|
189
|
-
'avax',
|
|
190
142
|
];
|
|
191
143
|
/**
|
|
192
144
|
* Represents the zero address, commonly used as a placeholder in blockchain transactions.
|
|
@@ -200,9 +152,7 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
|
200
152
|
* Only for chains whose native tokens have a specific address.
|
|
201
153
|
*/
|
|
202
154
|
const chainIdToNativeTokenAddress = {
|
|
203
|
-
'0x89': '0x0000000000000000000000000000000000001010',
|
|
204
|
-
'0x440': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Metis Andromeda
|
|
205
|
-
'0x1388': '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // Mantle
|
|
155
|
+
'0x89': '0x0000000000000000000000000000000000001010',
|
|
206
156
|
};
|
|
207
157
|
/**
|
|
208
158
|
* Returns the address that should be used to query the price api for the
|
|
@@ -213,47 +163,6 @@ const chainIdToNativeTokenAddress = {
|
|
|
213
163
|
* @returns The address of the chain's native token.
|
|
214
164
|
*/
|
|
215
165
|
export const getNativeTokenAddress = (chainId) => chainIdToNativeTokenAddress[chainId] ?? ZERO_ADDRESS;
|
|
216
|
-
// Source: https://github.com/consensys-vertical-apps/va-mmcx-price-api/blob/main/src/constants/slip44.ts
|
|
217
|
-
// We can only support PricesAPI V3 for EVM chains that have a CAIP-19 native asset mapping.
|
|
218
|
-
export const SPOT_PRICES_SUPPORT_INFO = {
|
|
219
|
-
'0x1': 'eip155:1/slip44:60', // Ethereum Mainnet - Native symbol: ETH
|
|
220
|
-
'0xa': 'eip155:10/slip44:60', // OP Mainnet - Native symbol: ETH
|
|
221
|
-
'0x19': 'eip155:25/slip44:394', // Cronos Mainnet - Native symbol: CRO
|
|
222
|
-
'0x38': 'eip155:56/slip44:714', // BNB Smart Chain Mainnet - Native symbol: BNB
|
|
223
|
-
'0x39': 'eip155:57/erc20:0x0000000000000000000000000000000000000000', // 'eip155:57/slip44:57', // Syscoin Mainnet - Native symbol: SYS
|
|
224
|
-
'0x52': null, // 'eip155:82/slip44:18000', // Meter Mainnet - Native symbol: MTR
|
|
225
|
-
'0x58': 'eip155:88/erc20:0x0000000000000000000000000000000000000000', // 'eip155:88/slip44:889', // TomoChain - Native symbol: TOMO
|
|
226
|
-
'0x64': 'eip155:100/slip44:700', // Gnosis (formerly xDAI Chain) - Native symbol: xDAI
|
|
227
|
-
'0x6a': 'eip155:106/erc20:0x0000000000000000000000000000000000000000', // 'eip155:106/slip44:5655640', // Velas EVM Mainnet - Native symbol: VLX
|
|
228
|
-
'0x80': 'eip155:128/erc20:0x0000000000000000000000000000000000000000', // 'eip155:128/slip44:1010', // Huobi ECO Chain Mainnet - Native symbol: HT
|
|
229
|
-
'0x89': 'eip155:137/slip44:966', // Polygon Mainnet - Native symbol: POL
|
|
230
|
-
'0x92': 'eip155:146/slip44:10007', // Sonic Mainnet - Native symbol: S
|
|
231
|
-
'0xfa': 'eip155:250/slip44:1007', // Fantom Opera - Native symbol: FTM
|
|
232
|
-
'0x141': 'eip155:321/erc20:0x0000000000000000000000000000000000000000', // 'eip155:321/slip44:641', // KCC Mainnet - Native symbol: KCS
|
|
233
|
-
'0x144': 'eip155:324/slip44:60', // zkSync Era Mainnet (Ethereum L2) - Native symbol: ETH
|
|
234
|
-
'0x169': 'eip155:361/erc20:0x0000000000000000000000000000000000000000', // 'eip155:361/slip44:589', // Theta Mainnet - Native symbol: TFUEL
|
|
235
|
-
'0x440': 'eip155:1088/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // 'eip155:1088/slip44:XXX', // Metis Andromeda Mainnet (Ethereum L2) - Native symbol: METIS
|
|
236
|
-
'0x44d': 'eip155:1101/slip44:60', // Polygon zkEVM mainnet - Native symbol: ETH
|
|
237
|
-
'0x504': 'eip155:1284/slip44:1284', // Moonbeam - Native symbol: GLMR
|
|
238
|
-
'0x505': 'eip155:1285/slip44:1285', // Moonriver - Native symbol: MOVR
|
|
239
|
-
'0x531': 'eip155:1329/slip44:19000118', // Sei Mainnet - Native symbol: SEI
|
|
240
|
-
'0x1388': 'eip155:5000/erc20:0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000', // 'eip155:5000/slip44:XXX', // Mantle - Native symbol: MNT
|
|
241
|
-
'0x2105': 'eip155:8453/slip44:60', // Base - Native symbol: ETH
|
|
242
|
-
'0x2710': 'eip155:10000/erc20:0x0000000000000000000000000000000000000000', // 'eip155:10000/slip44:145', // Smart Bitcoin Cash - Native symbol: BCH
|
|
243
|
-
'0xa4b1': 'eip155:42161/slip44:60', // Arbitrum One - Native symbol: ETH
|
|
244
|
-
'0xa4ec': 'eip155:42220/slip44:52752', // Celo Mainnet - Native symbol: CELO
|
|
245
|
-
'0xa516': 'eip155:42262/erc20:0x0000000000000000000000000000000000000000', // 'eip155:42262/slip44:474', // Oasis Emerald - Native symbol: ROSE
|
|
246
|
-
'0xa86a': 'eip155:43114/slip44:9005', // Avalanche C-Chain - Native symbol: AVAX
|
|
247
|
-
'0xe708': 'eip155:59144/slip44:60', // Linea Mainnet - Native symbol: ETH
|
|
248
|
-
'0x13c31': 'eip155:81457/erc20:0x0000000000000000000000000000000000000000', // 'eip155:81457/slip44:60', // Blast Mainnet - Native symbol: ETH
|
|
249
|
-
'0x17dcd': 'eip155:97741/erc20:0x0000000000000000000000000000000000000000', // 'eip155:97741/slip44:XXX', // Pepe Unchained Mainnet - Native symbol: PEPU
|
|
250
|
-
'0x518af': null, // 'eip155:333999/slip44:1997', // Polis Mainnet - Native symbol: POLIS
|
|
251
|
-
'0x82750': 'eip155:534352/slip44:60', // Scroll Mainnet - Native symbol: ETH
|
|
252
|
-
'0x4e454152': 'eip155:60/slip44:60', // Aurora Mainnet (Ethereum L2 on NEAR) - Native symbol: ETH
|
|
253
|
-
'0x63564c40': 'eip155:1666600000/slip44:1023', // Harmony Mainnet Shard 0 - Native symbol: ONE
|
|
254
|
-
'0x279f': 'eip155:143/slip44:268435779', // Monad Testnet - Native symbol: MON
|
|
255
|
-
'0x3e7': 'eip155:999/slip44:2457', // HyperEVM - Native symbol: ETH
|
|
256
|
-
};
|
|
257
166
|
/**
|
|
258
167
|
* The list of chain IDs that can be supplied in the URL for the `/spot-prices`
|
|
259
168
|
* endpoint, but in hexadecimal form (for consistency with how we represent
|
|
@@ -261,22 +170,93 @@ export const SPOT_PRICES_SUPPORT_INFO = {
|
|
|
261
170
|
*
|
|
262
171
|
* @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.
|
|
263
172
|
*/
|
|
264
|
-
export const SUPPORTED_CHAIN_IDS =
|
|
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
|
+
];
|
|
265
249
|
/**
|
|
266
|
-
*
|
|
267
|
-
* Only includes chain IDs from SPOT_PRICES_SUPPORT_INFO that have a non-null CAIP-19 value.
|
|
250
|
+
* All requests to V2 of the Price API start with this.
|
|
268
251
|
*/
|
|
269
|
-
const
|
|
252
|
+
const BASE_URL = 'https://price.api.cx.metamask.io/v2';
|
|
270
253
|
const BASE_URL_V1 = 'https://price.api.cx.metamask.io/v1';
|
|
271
|
-
const BASE_URL_V2 = 'https://price.api.cx.metamask.io/v2';
|
|
272
|
-
const BASE_URL_V3 = 'https://price.api.cx.metamask.io/v3';
|
|
273
254
|
/**
|
|
274
255
|
* This version of the token prices service uses V2 of the Codefi Price API to
|
|
275
256
|
* fetch token prices.
|
|
276
257
|
*/
|
|
277
258
|
export class CodefiTokenPricesServiceV2 {
|
|
278
259
|
constructor({ degradedThreshold = DEFAULT_DEGRADED_THRESHOLD, retries = DEFAULT_MAX_RETRIES, maximumConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES, onBreak, onDegraded, circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION, } = {}) {
|
|
279
|
-
_CodefiTokenPricesServiceV2_instances.add(this);
|
|
280
260
|
_CodefiTokenPricesServiceV2_policy.set(this, void 0);
|
|
281
261
|
__classPrivateFieldSet(this, _CodefiTokenPricesServiceV2_policy, createServicePolicy({
|
|
282
262
|
maxRetries: retries,
|
|
@@ -316,14 +296,36 @@ export class CodefiTokenPricesServiceV2 {
|
|
|
316
296
|
* given addresses which are expected to live on the given chain.
|
|
317
297
|
*
|
|
318
298
|
* @param args - The arguments to function.
|
|
319
|
-
* @param args.
|
|
299
|
+
* @param args.chainId - An EIP-155 chain ID.
|
|
300
|
+
* @param args.tokenAddresses - Addresses for tokens that live on the chain.
|
|
320
301
|
* @param args.currency - The desired currency of the token prices.
|
|
321
302
|
* @returns The prices for the requested tokens.
|
|
322
303
|
*/
|
|
323
|
-
async fetchTokenPrices({
|
|
324
|
-
const
|
|
325
|
-
const
|
|
326
|
-
|
|
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
|
+
}, {});
|
|
327
329
|
}
|
|
328
330
|
/**
|
|
329
331
|
* Retrieves exchange rates in the given base currency.
|
|
@@ -424,73 +426,5 @@ export class CodefiTokenPricesServiceV2 {
|
|
|
424
426
|
supportedCurrencies.includes(currency.toLowerCase()));
|
|
425
427
|
}
|
|
426
428
|
}
|
|
427
|
-
_CodefiTokenPricesServiceV2_policy = new WeakMap()
|
|
428
|
-
const assetsWithIds = assets
|
|
429
|
-
// Filter out assets that are not supported by V3 of the Price API.
|
|
430
|
-
.filter((asset) => SUPPORTED_CHAIN_IDS_V3.includes(asset.chainId))
|
|
431
|
-
.map((asset) => {
|
|
432
|
-
const caipChainId = toCaipChainId(KnownCaipNamespace.Eip155, hexToNumber(asset.chainId).toString());
|
|
433
|
-
const nativeAddress = getNativeTokenAddress(asset.chainId);
|
|
434
|
-
return {
|
|
435
|
-
...asset,
|
|
436
|
-
assetId: (nativeAddress.toLowerCase() ===
|
|
437
|
-
asset.tokenAddress.toLowerCase()
|
|
438
|
-
? SPOT_PRICES_SUPPORT_INFO[asset.chainId]
|
|
439
|
-
: `${caipChainId}/erc20:${asset.tokenAddress.toLowerCase()}`),
|
|
440
|
-
};
|
|
441
|
-
})
|
|
442
|
-
.filter((asset) => asset.assetId);
|
|
443
|
-
if (assetsWithIds.length === 0) {
|
|
444
|
-
return [];
|
|
445
|
-
}
|
|
446
|
-
const url = new URL(`${BASE_URL_V3}/spot-prices`);
|
|
447
|
-
url.searchParams.append('assetIds', assetsWithIds.map((asset) => asset.assetId).join(','));
|
|
448
|
-
url.searchParams.append('vsCurrency', currency);
|
|
449
|
-
url.searchParams.append('includeMarketData', 'true');
|
|
450
|
-
const addressCryptoDataMap = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_policy, "f").execute(() => handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }));
|
|
451
|
-
return assetsWithIds
|
|
452
|
-
.map((assetWithId) => {
|
|
453
|
-
const marketData = addressCryptoDataMap[assetWithId.assetId];
|
|
454
|
-
if (!marketData) {
|
|
455
|
-
return undefined;
|
|
456
|
-
}
|
|
457
|
-
return {
|
|
458
|
-
...marketData,
|
|
459
|
-
...assetWithId,
|
|
460
|
-
currency,
|
|
461
|
-
};
|
|
462
|
-
})
|
|
463
|
-
.filter((entry) => Boolean(entry));
|
|
464
|
-
}, _CodefiTokenPricesServiceV2_fetchTokenPricesV2 = async function _CodefiTokenPricesServiceV2_fetchTokenPricesV2(assets, currency) {
|
|
465
|
-
const v2SupportedAssets = assets.filter((asset) => !SUPPORTED_CHAIN_IDS_V3.includes(asset.chainId));
|
|
466
|
-
const assetsByChainId = v2SupportedAssets.reduce((acc, { chainId, tokenAddress }) => {
|
|
467
|
-
(acc[chainId] ?? (acc[chainId] = [])).push(tokenAddress);
|
|
468
|
-
return acc;
|
|
469
|
-
}, {});
|
|
470
|
-
const promises = Object.entries(assetsByChainId).map(async ([chainId, tokenAddresses]) => {
|
|
471
|
-
if (tokenAddresses.length === 0) {
|
|
472
|
-
return [];
|
|
473
|
-
}
|
|
474
|
-
const url = new URL(`${BASE_URL_V2}/chains/${chainId}/spot-prices`);
|
|
475
|
-
url.searchParams.append('tokenAddresses', tokenAddresses.join(','));
|
|
476
|
-
url.searchParams.append('vsCurrency', currency);
|
|
477
|
-
url.searchParams.append('includeMarketData', 'true');
|
|
478
|
-
const addressCryptoDataMap = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_policy, "f").execute(() => handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }));
|
|
479
|
-
return tokenAddresses
|
|
480
|
-
.map((tokenAddress) => {
|
|
481
|
-
const marketData = addressCryptoDataMap[tokenAddress.toLowerCase()];
|
|
482
|
-
if (!marketData) {
|
|
483
|
-
return undefined;
|
|
484
|
-
}
|
|
485
|
-
return {
|
|
486
|
-
...marketData,
|
|
487
|
-
tokenAddress,
|
|
488
|
-
chainId: chainId,
|
|
489
|
-
currency,
|
|
490
|
-
};
|
|
491
|
-
})
|
|
492
|
-
.filter((entry) => Boolean(entry));
|
|
493
|
-
});
|
|
494
|
-
return await Promise.allSettled(promises).then((results) => results.flatMap((result) => result.status === 'fulfilled' ? result.value : []));
|
|
495
|
-
};
|
|
429
|
+
_CodefiTokenPricesServiceV2_policy = new WeakMap();
|
|
496
430
|
//# sourceMappingURL=codefi-v2.mjs.map
|