@metamask/assets-controllers 26.0.0 → 27.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/dist/AccountTrackerController.js +9 -236
- package/dist/AccountTrackerController.js.map +1 -1
- package/dist/AccountTrackerController.mjs +10 -0
- package/dist/AccountTrackerController.mjs.map +1 -0
- package/dist/AssetsContractController.js +17 -384
- package/dist/AssetsContractController.js.map +1 -1
- package/dist/AssetsContractController.mjs +18 -0
- package/dist/AssetsContractController.mjs.map +1 -0
- package/dist/CurrencyRateController.js +10 -157
- package/dist/CurrencyRateController.js.map +1 -1
- package/dist/CurrencyRateController.mjs +11 -0
- package/dist/CurrencyRateController.mjs.map +1 -0
- package/dist/NftController.js +15 -1041
- package/dist/NftController.js.map +1 -1
- package/dist/NftController.mjs +16 -0
- package/dist/NftController.mjs.map +1 -0
- package/dist/NftDetectionController.js +12 -213
- package/dist/NftDetectionController.js.map +1 -1
- package/dist/NftDetectionController.mjs +13 -0
- package/dist/NftDetectionController.mjs.map +1 -0
- package/dist/Standards/ERC20Standard.js +8 -142
- package/dist/Standards/ERC20Standard.js.map +1 -1
- package/dist/Standards/ERC20Standard.mjs +9 -0
- package/dist/Standards/ERC20Standard.mjs.map +1 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +8 -217
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js.map +1 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +9 -0
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +8 -174
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +1 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +9 -0
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -0
- package/dist/TokenBalancesController.js +11 -141
- package/dist/TokenBalancesController.js.map +1 -1
- package/dist/TokenBalancesController.mjs +12 -0
- package/dist/TokenBalancesController.mjs.map +1 -0
- package/dist/TokenDetectionController.js +16 -362
- package/dist/TokenDetectionController.js.map +1 -1
- package/dist/TokenDetectionController.mjs +17 -0
- package/dist/TokenDetectionController.mjs.map +1 -0
- package/dist/TokenListController.js +13 -250
- package/dist/TokenListController.js.map +1 -1
- package/dist/TokenListController.mjs +14 -0
- package/dist/TokenListController.mjs.map +1 -0
- package/dist/TokenRatesController.js +11 -328
- package/dist/TokenRatesController.js.map +1 -1
- package/dist/TokenRatesController.mjs +12 -0
- package/dist/TokenRatesController.mjs.map +1 -0
- package/dist/TokensController.js +15 -629
- package/dist/TokensController.js.map +1 -1
- package/dist/TokensController.mjs +16 -0
- package/dist/TokensController.mjs.map +1 -0
- package/dist/assetsUtil.js +41 -384
- package/dist/assetsUtil.js.map +1 -1
- package/dist/assetsUtil.mjs +42 -0
- package/dist/assetsUtil.mjs.map +1 -0
- package/dist/chunk-23F5W3A2.mjs +157 -0
- package/dist/chunk-23F5W3A2.mjs.map +1 -0
- package/dist/chunk-27KOXCQK.mjs +1 -0
- package/dist/chunk-27KOXCQK.mjs.map +1 -0
- package/dist/chunk-3FMWI46J.mjs +361 -0
- package/dist/chunk-3FMWI46J.mjs.map +1 -0
- package/dist/chunk-3FOTFZIL.mjs +411 -0
- package/dist/chunk-3FOTFZIL.mjs.map +1 -0
- package/dist/chunk-4LY47RPI.mjs +139 -0
- package/dist/chunk-4LY47RPI.mjs.map +1 -0
- package/dist/chunk-5C7ZVZNM.mjs +267 -0
- package/dist/chunk-5C7ZVZNM.mjs.map +1 -0
- package/dist/chunk-64EHFYLM.mjs +245 -0
- package/dist/chunk-64EHFYLM.mjs.map +1 -0
- package/dist/chunk-6C2ZIK7A.js +245 -0
- package/dist/chunk-6C2ZIK7A.js.map +1 -0
- package/dist/chunk-6DTCHPBB.mjs +178 -0
- package/dist/chunk-6DTCHPBB.mjs.map +1 -0
- package/dist/chunk-74IP34EL.js +1177 -0
- package/dist/chunk-74IP34EL.js.map +1 -0
- package/dist/chunk-BZI7P3TD.js +115 -0
- package/dist/chunk-BZI7P3TD.js.map +1 -0
- package/dist/chunk-C4PQK53K.js +32 -0
- package/dist/chunk-C4PQK53K.js.map +1 -0
- package/dist/chunk-CP3HC7AQ.mjs +12 -0
- package/dist/chunk-CP3HC7AQ.mjs.map +1 -0
- package/dist/chunk-GHZX5DE4.js +215 -0
- package/dist/chunk-GHZX5DE4.js.map +1 -0
- package/dist/chunk-GMKIOYCB.js +361 -0
- package/dist/chunk-GMKIOYCB.js.map +1 -0
- package/dist/chunk-H6TOSWUM.js +157 -0
- package/dist/chunk-H6TOSWUM.js.map +1 -0
- package/dist/chunk-HWFBJFHS.js +284 -0
- package/dist/chunk-HWFBJFHS.js.map +1 -0
- package/dist/chunk-J2JQQNHN.mjs +115 -0
- package/dist/chunk-J2JQQNHN.mjs.map +1 -0
- package/dist/chunk-J6HPEQL3.mjs +704 -0
- package/dist/chunk-J6HPEQL3.mjs.map +1 -0
- package/dist/chunk-JC4WAN2J.mjs +1177 -0
- package/dist/chunk-JC4WAN2J.mjs.map +1 -0
- package/dist/chunk-LD4GC7OR.js +139 -0
- package/dist/chunk-LD4GC7OR.js.map +1 -0
- package/dist/chunk-NG2UOKDD.js +178 -0
- package/dist/chunk-NG2UOKDD.js.map +1 -0
- package/dist/chunk-NGIXA5M5.mjs +418 -0
- package/dist/chunk-NGIXA5M5.mjs.map +1 -0
- package/dist/chunk-NLNXQHAU.js +704 -0
- package/dist/chunk-NLNXQHAU.js.map +1 -0
- package/dist/chunk-OBUR4TXH.js +1 -0
- package/dist/chunk-OBUR4TXH.js.map +1 -0
- package/dist/chunk-PAJTKWEC.mjs +246 -0
- package/dist/chunk-PAJTKWEC.mjs.map +1 -0
- package/dist/chunk-PRIXT2R6.js +411 -0
- package/dist/chunk-PRIXT2R6.js.map +1 -0
- package/dist/chunk-PUFSYRJZ.js +74 -0
- package/dist/chunk-PUFSYRJZ.js.map +1 -0
- package/dist/chunk-QHRPRO5U.mjs +74 -0
- package/dist/chunk-QHRPRO5U.mjs.map +1 -0
- package/dist/chunk-QR4CX2JT.mjs +284 -0
- package/dist/chunk-QR4CX2JT.mjs.map +1 -0
- package/dist/chunk-RGHTNZQ6.js +12 -0
- package/dist/chunk-RGHTNZQ6.js.map +1 -0
- package/dist/chunk-TCO22VIO.mjs +32 -0
- package/dist/chunk-TCO22VIO.mjs.map +1 -0
- package/dist/chunk-TDKCVCGP.mjs +215 -0
- package/dist/chunk-TDKCVCGP.mjs.map +1 -0
- package/dist/chunk-UAH5YURZ.js +343 -0
- package/dist/chunk-UAH5YURZ.js.map +1 -0
- package/dist/chunk-V4ZO3F2S.js +246 -0
- package/dist/chunk-V4ZO3F2S.js.map +1 -0
- package/dist/chunk-VDJBJAUB.js +418 -0
- package/dist/chunk-VDJBJAUB.js.map +1 -0
- package/dist/chunk-WRQ7POD7.mjs +343 -0
- package/dist/chunk-WRQ7POD7.mjs.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-YD3NRMFC.js +267 -0
- package/dist/chunk-YD3NRMFC.js.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/constants.js +7 -9
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +8 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/crypto-compare.js +7 -66
- package/dist/crypto-compare.js.map +1 -1
- package/dist/crypto-compare.mjs +8 -0
- package/dist/crypto-compare.mjs.map +1 -0
- package/dist/index.js +72 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -0
- package/dist/index.mjs.map +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.js +1 -3
- package/dist/token-prices-service/abstract-token-prices-service.js.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.mjs +1 -0
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -0
- package/dist/token-prices-service/codefi-v2.js +11 -353
- package/dist/token-prices-service/codefi-v2.js.map +1 -1
- package/dist/token-prices-service/codefi-v2.mjs +12 -0
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -0
- package/dist/token-prices-service/index.js +8 -5
- package/dist/token-prices-service/index.js.map +1 -1
- package/dist/token-prices-service/index.mjs +9 -0
- package/dist/token-prices-service/index.mjs.map +1 -0
- package/dist/token-service.js +14 -133
- package/dist/token-service.js.map +1 -1
- package/dist/token-service.mjs +15 -0
- package/dist/token-service.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/AccountTrackerController.d.ts.map +1 -0
- package/dist/types/AssetsContractController.d.ts.map +1 -0
- package/dist/types/CurrencyRateController.d.ts.map +1 -0
- package/dist/types/NftController.d.ts.map +1 -0
- package/dist/types/NftDetectionController.d.ts.map +1 -0
- package/dist/types/Standards/ERC20Standard.d.ts.map +1 -0
- package/dist/types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +1 -0
- package/dist/types/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +1 -0
- package/dist/types/TokenBalancesController.d.ts.map +1 -0
- package/dist/types/TokenDetectionController.d.ts.map +1 -0
- package/dist/types/TokenListController.d.ts.map +1 -0
- package/dist/types/TokenRatesController.d.ts.map +1 -0
- package/dist/{TokensController.d.ts → types/TokensController.d.ts} +10 -3
- package/dist/types/TokensController.d.ts.map +1 -0
- package/dist/types/assetsUtil.d.ts.map +1 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/crypto-compare.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +1 -0
- package/dist/types/token-prices-service/codefi-v2.d.ts.map +1 -0
- package/dist/types/token-prices-service/index.d.ts.map +1 -0
- package/dist/types/token-service.d.ts.map +1 -0
- package/package.json +24 -14
- package/dist/AccountTrackerController.d.ts.map +0 -1
- package/dist/AssetsContractController.d.ts.map +0 -1
- package/dist/CurrencyRateController.d.ts.map +0 -1
- package/dist/NftController.d.ts.map +0 -1
- package/dist/NftDetectionController.d.ts.map +0 -1
- package/dist/Standards/ERC20Standard.d.ts.map +0 -1
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +0 -1
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +0 -1
- package/dist/TokenBalancesController.d.ts.map +0 -1
- package/dist/TokenDetectionController.d.ts.map +0 -1
- package/dist/TokenListController.d.ts.map +0 -1
- package/dist/TokenRatesController.d.ts.map +0 -1
- package/dist/TokensController.d.ts.map +0 -1
- package/dist/assetsUtil.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/crypto-compare.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.ts.map +0 -1
- package/dist/token-prices-service/codefi-v2.d.ts.map +0 -1
- package/dist/token-prices-service/index.d.ts.map +0 -1
- package/dist/token-service.d.ts.map +0 -1
- /package/dist/{AccountTrackerController.d.ts → types/AccountTrackerController.d.ts} +0 -0
- /package/dist/{AssetsContractController.d.ts → types/AssetsContractController.d.ts} +0 -0
- /package/dist/{CurrencyRateController.d.ts → types/CurrencyRateController.d.ts} +0 -0
- /package/dist/{NftController.d.ts → types/NftController.d.ts} +0 -0
- /package/dist/{NftDetectionController.d.ts → types/NftDetectionController.d.ts} +0 -0
- /package/dist/{Standards → types/Standards}/ERC20Standard.d.ts +0 -0
- /package/dist/{Standards → types/Standards}/NftStandards/ERC1155/ERC1155Standard.d.ts +0 -0
- /package/dist/{Standards → types/Standards}/NftStandards/ERC721/ERC721Standard.d.ts +0 -0
- /package/dist/{TokenBalancesController.d.ts → types/TokenBalancesController.d.ts} +0 -0
- /package/dist/{TokenDetectionController.d.ts → types/TokenDetectionController.d.ts} +0 -0
- /package/dist/{TokenListController.d.ts → types/TokenListController.d.ts} +0 -0
- /package/dist/{TokenRatesController.d.ts → types/TokenRatesController.d.ts} +0 -0
- /package/dist/{assetsUtil.d.ts → types/assetsUtil.d.ts} +0 -0
- /package/dist/{constants.d.ts → types/constants.d.ts} +0 -0
- /package/dist/{crypto-compare.d.ts → types/crypto-compare.d.ts} +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{token-prices-service → types/token-prices-service}/abstract-token-prices-service.d.ts +0 -0
- /package/dist/{token-prices-service → types/token-prices-service}/codefi-v2.d.ts +0 -0
- /package/dist/{token-prices-service → types/token-prices-service}/index.d.ts +0 -0
- /package/dist/{token-service.d.ts → types/token-service.d.ts} +0 -0
|
@@ -1,354 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
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");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var _CodefiTokenPricesServiceV2_tokenPricePolicy;
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.CodefiTokenPricesServiceV2 = exports.SUPPORTED_CHAIN_IDS = exports.SUPPORTED_CURRENCIES = void 0;
|
|
25
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
26
|
-
const utils_1 = require("@metamask/utils");
|
|
27
|
-
const cockatiel_1 = require("cockatiel");
|
|
28
|
-
/**
|
|
29
|
-
* The list of currencies that can be supplied as the `vsCurrency` parameter to
|
|
30
|
-
* the `/spot-prices` endpoint, in lowercase form.
|
|
31
|
-
*/
|
|
32
|
-
exports.SUPPORTED_CURRENCIES = [
|
|
33
|
-
// Bitcoin
|
|
34
|
-
'btc',
|
|
35
|
-
// Ether
|
|
36
|
-
'eth',
|
|
37
|
-
// Litecoin
|
|
38
|
-
'ltc',
|
|
39
|
-
// Bitcoin Cash
|
|
40
|
-
'bch',
|
|
41
|
-
// Binance Coin
|
|
42
|
-
'bnb',
|
|
43
|
-
// EOS
|
|
44
|
-
'eos',
|
|
45
|
-
// XRP
|
|
46
|
-
'xrp',
|
|
47
|
-
// Lumens
|
|
48
|
-
'xlm',
|
|
49
|
-
// Chainlink
|
|
50
|
-
'link',
|
|
51
|
-
// Polkadot
|
|
52
|
-
'dot',
|
|
53
|
-
// Yearn.finance
|
|
54
|
-
'yfi',
|
|
55
|
-
// US Dollar
|
|
56
|
-
'usd',
|
|
57
|
-
// United Arab Emirates Dirham
|
|
58
|
-
'aed',
|
|
59
|
-
// Argentine Peso
|
|
60
|
-
'ars',
|
|
61
|
-
// Australian Dollar
|
|
62
|
-
'aud',
|
|
63
|
-
// Bangladeshi Taka
|
|
64
|
-
'bdt',
|
|
65
|
-
// Bahraini Dinar
|
|
66
|
-
'bhd',
|
|
67
|
-
// Bermudian Dollar
|
|
68
|
-
'bmd',
|
|
69
|
-
// Brazil Real
|
|
70
|
-
'brl',
|
|
71
|
-
// Canadian Dollar
|
|
72
|
-
'cad',
|
|
73
|
-
// Swiss Franc
|
|
74
|
-
'chf',
|
|
75
|
-
// Chilean Peso
|
|
76
|
-
'clp',
|
|
77
|
-
// Chinese Yuan
|
|
78
|
-
'cny',
|
|
79
|
-
// Czech Koruna
|
|
80
|
-
'czk',
|
|
81
|
-
// Danish Krone
|
|
82
|
-
'dkk',
|
|
83
|
-
// Euro
|
|
84
|
-
'eur',
|
|
85
|
-
// British Pound Sterling
|
|
86
|
-
'gbp',
|
|
87
|
-
// Hong Kong Dollar
|
|
88
|
-
'hkd',
|
|
89
|
-
// Hungarian Forint
|
|
90
|
-
'huf',
|
|
91
|
-
// Indonesian Rupiah
|
|
92
|
-
'idr',
|
|
93
|
-
// Israeli New Shekel
|
|
94
|
-
'ils',
|
|
95
|
-
// Indian Rupee
|
|
96
|
-
'inr',
|
|
97
|
-
// Japanese Yen
|
|
98
|
-
'jpy',
|
|
99
|
-
// South Korean Won
|
|
100
|
-
'krw',
|
|
101
|
-
// Kuwaiti Dinar
|
|
102
|
-
'kwd',
|
|
103
|
-
// Sri Lankan Rupee
|
|
104
|
-
'lkr',
|
|
105
|
-
// Burmese Kyat
|
|
106
|
-
'mmk',
|
|
107
|
-
// Mexican Peso
|
|
108
|
-
'mxn',
|
|
109
|
-
// Malaysian Ringgit
|
|
110
|
-
'myr',
|
|
111
|
-
// Nigerian Naira
|
|
112
|
-
'ngn',
|
|
113
|
-
// Norwegian Krone
|
|
114
|
-
'nok',
|
|
115
|
-
// New Zealand Dollar
|
|
116
|
-
'nzd',
|
|
117
|
-
// Philippine Peso
|
|
118
|
-
'php',
|
|
119
|
-
// Pakistani Rupee
|
|
120
|
-
'pkr',
|
|
121
|
-
// Polish Zloty
|
|
122
|
-
'pln',
|
|
123
|
-
// Russian Ruble
|
|
124
|
-
'rub',
|
|
125
|
-
// Saudi Riyal
|
|
126
|
-
'sar',
|
|
127
|
-
// Swedish Krona
|
|
128
|
-
'sek',
|
|
129
|
-
// Singapore Dollar
|
|
130
|
-
'sgd',
|
|
131
|
-
// Thai Baht
|
|
132
|
-
'thb',
|
|
133
|
-
// Turkish Lira
|
|
134
|
-
'try',
|
|
135
|
-
// New Taiwan Dollar
|
|
136
|
-
'twd',
|
|
137
|
-
// Ukrainian hryvnia
|
|
138
|
-
'uah',
|
|
139
|
-
// Venezuelan bolívar fuerte
|
|
140
|
-
'vef',
|
|
141
|
-
// Vietnamese đồng
|
|
142
|
-
'vnd',
|
|
143
|
-
// South African Rand
|
|
144
|
-
'zar',
|
|
145
|
-
// IMF Special Drawing Rights
|
|
146
|
-
'xdr',
|
|
147
|
-
// Silver - Troy Ounce
|
|
148
|
-
'xag',
|
|
149
|
-
// Gold - Troy Ounce
|
|
150
|
-
'xau',
|
|
151
|
-
// Bits
|
|
152
|
-
'bits',
|
|
153
|
-
// Satoshi
|
|
154
|
-
'sats',
|
|
155
|
-
];
|
|
156
|
-
/**
|
|
157
|
-
* The list of chain IDs that can be supplied in the URL for the `/spot-prices`
|
|
158
|
-
* endpoint, but in hexadecimal form (for consistency with how we represent
|
|
159
|
-
* chain IDs in other places).
|
|
160
|
-
*/
|
|
161
|
-
exports.SUPPORTED_CHAIN_IDS = [
|
|
162
|
-
// Ethereum Mainnet
|
|
163
|
-
'0x1',
|
|
164
|
-
// OP Mainnet
|
|
165
|
-
'0xa',
|
|
166
|
-
// Cronos Mainnet
|
|
167
|
-
'0x19',
|
|
168
|
-
// BNB Smart Chain Mainnet
|
|
169
|
-
'0x38',
|
|
170
|
-
// Syscoin Mainnet
|
|
171
|
-
'0x39',
|
|
172
|
-
// OKXChain Mainnet
|
|
173
|
-
'0x42',
|
|
174
|
-
// Hoo Smart Chain
|
|
175
|
-
'0x46',
|
|
176
|
-
// Meter Mainnet
|
|
177
|
-
'0x52',
|
|
178
|
-
// TomoChain
|
|
179
|
-
'0x58',
|
|
180
|
-
// Gnosis
|
|
181
|
-
'0x64',
|
|
182
|
-
// Velas EVM Mainnet
|
|
183
|
-
'0x6a',
|
|
184
|
-
// Fuse Mainnet
|
|
185
|
-
'0x7a',
|
|
186
|
-
// Huobi ECO Chain Mainnet
|
|
187
|
-
'0x80',
|
|
188
|
-
// Polygon Mainnet
|
|
189
|
-
'0x89',
|
|
190
|
-
// Fantom Opera
|
|
191
|
-
'0xfa',
|
|
192
|
-
// Boba Network
|
|
193
|
-
'0x120',
|
|
194
|
-
// KCC Mainnet
|
|
195
|
-
'0x141',
|
|
196
|
-
// zkSync Era Mainnet
|
|
197
|
-
'0x144',
|
|
198
|
-
// Theta Mainnet
|
|
199
|
-
'0x169',
|
|
200
|
-
// Metis Andromeda Mainnet
|
|
201
|
-
'0x440',
|
|
202
|
-
// Moonbeam
|
|
203
|
-
'0x504',
|
|
204
|
-
// Moonriver
|
|
205
|
-
'0x505',
|
|
206
|
-
// Base
|
|
207
|
-
'0x2105',
|
|
208
|
-
// Shiden
|
|
209
|
-
'0x150',
|
|
210
|
-
// Smart Bitcoin Cash
|
|
211
|
-
'0x2710',
|
|
212
|
-
// Arbitrum One
|
|
213
|
-
'0xa4b1',
|
|
214
|
-
// Celo Mainnet
|
|
215
|
-
'0xa4ec',
|
|
216
|
-
// Oasis Emerald
|
|
217
|
-
'0xa516',
|
|
218
|
-
// Avalanche C-Chain
|
|
219
|
-
'0xa86a',
|
|
220
|
-
// Polis Mainnet
|
|
221
|
-
'0x518af',
|
|
222
|
-
// Aurora Mainnet
|
|
223
|
-
'0x4e454152',
|
|
224
|
-
// Harmony Mainnet Shard 0
|
|
225
|
-
'0x63564c40',
|
|
226
|
-
// Linea Mainnet
|
|
227
|
-
'0xe708',
|
|
228
|
-
];
|
|
229
|
-
/**
|
|
230
|
-
* All requests to V2 of the Price API start with this.
|
|
231
|
-
*/
|
|
232
|
-
const BASE_URL = 'https://price-api.metafi.codefi.network/v2';
|
|
233
|
-
const DEFAULT_TOKEN_PRICE_RETRIES = 3;
|
|
234
|
-
// Each update attempt will result (1 + retries) calls if the server is down
|
|
235
|
-
const DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;
|
|
236
|
-
const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
237
|
-
/**
|
|
238
|
-
* This version of the token prices service uses V2 of the Codefi Price API to
|
|
239
|
-
* fetch token prices.
|
|
240
|
-
*/
|
|
241
|
-
class CodefiTokenPricesServiceV2 {
|
|
242
|
-
/**
|
|
243
|
-
* Construct a Codefi Token Price Service.
|
|
244
|
-
*
|
|
245
|
-
* @param options - Constructor options
|
|
246
|
-
* @param options.degradedThreshold - The threshold between "normal" and "degrated" service,
|
|
247
|
-
* in milliseconds.
|
|
248
|
-
* @param options.retries - Number of retry attempts for each token price update.
|
|
249
|
-
* @param options.maximumConsecutiveFailures - The maximum number of consecutive failures
|
|
250
|
-
* allowed before breaking the circuit and pausing further updates.
|
|
251
|
-
* @param options.onBreak - An event handler for when the circuit breaks, useful for capturing
|
|
252
|
-
* metrics about network failures.
|
|
253
|
-
* @param options.onDegraded - An event handler for when the circuit remains closed, but requests
|
|
254
|
-
* are failing or resolving too slowly (i.e. resolving more slowly than the `degradedThreshold).
|
|
255
|
-
* @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks
|
|
256
|
-
* from too many consecutive failures.
|
|
257
|
-
*/
|
|
258
|
-
constructor({ degradedThreshold = DEFAULT_DEGRADED_THRESHOLD, retries = DEFAULT_TOKEN_PRICE_RETRIES, maximumConsecutiveFailures = DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES, onBreak, onDegraded, circuitBreakDuration = 30 * 60 * 1000, } = {}) {
|
|
259
|
-
_CodefiTokenPricesServiceV2_tokenPricePolicy.set(this, void 0);
|
|
260
|
-
// Construct a policy that will retry each update, and halt further updates
|
|
261
|
-
// for a certain period after too many consecutive failures.
|
|
262
|
-
const retryPolicy = (0, cockatiel_1.retry)(cockatiel_1.handleAll, {
|
|
263
|
-
maxAttempts: retries,
|
|
264
|
-
backoff: new cockatiel_1.ExponentialBackoff(),
|
|
265
|
-
});
|
|
266
|
-
const circuitBreakerPolicy = (0, cockatiel_1.circuitBreaker)(cockatiel_1.handleAll, {
|
|
267
|
-
halfOpenAfter: circuitBreakDuration,
|
|
268
|
-
breaker: new cockatiel_1.ConsecutiveBreaker(maximumConsecutiveFailures),
|
|
269
|
-
});
|
|
270
|
-
if (onBreak) {
|
|
271
|
-
circuitBreakerPolicy.onBreak(onBreak);
|
|
272
|
-
}
|
|
273
|
-
if (onDegraded) {
|
|
274
|
-
retryPolicy.onGiveUp(() => {
|
|
275
|
-
if (circuitBreakerPolicy.state === cockatiel_1.CircuitState.Closed) {
|
|
276
|
-
onDegraded();
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
retryPolicy.onSuccess(({ duration }) => {
|
|
280
|
-
if (circuitBreakerPolicy.state === cockatiel_1.CircuitState.Closed &&
|
|
281
|
-
duration > degradedThreshold) {
|
|
282
|
-
onDegraded();
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
__classPrivateFieldSet(this, _CodefiTokenPricesServiceV2_tokenPricePolicy, (0, cockatiel_1.wrap)(retryPolicy, circuitBreakerPolicy), "f");
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Retrieves prices in the given currency for the tokens identified by the
|
|
290
|
-
* given addresses which are expected to live on the given chain.
|
|
291
|
-
*
|
|
292
|
-
* @param args - The arguments to function.
|
|
293
|
-
* @param args.chainId - An EIP-155 chain ID.
|
|
294
|
-
* @param args.tokenAddresses - Addresses for tokens that live on the chain.
|
|
295
|
-
* @param args.currency - The desired currency of the token prices.
|
|
296
|
-
* @returns The prices for the requested tokens.
|
|
297
|
-
*/
|
|
298
|
-
fetchTokenPrices({ chainId, tokenAddresses, currency, }) {
|
|
299
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
-
const chainIdAsNumber = (0, utils_1.hexToNumber)(chainId);
|
|
301
|
-
const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);
|
|
302
|
-
url.searchParams.append('tokenAddresses', tokenAddresses.join(','));
|
|
303
|
-
url.searchParams.append('vsCurrency', currency);
|
|
304
|
-
const pricesByCurrencyByTokenAddress = yield __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_tokenPricePolicy, "f").execute(() => (0, controller_utils_1.handleFetch)(url, { headers: { 'Cache-Control': 'no-cache' } }));
|
|
305
|
-
return tokenAddresses.reduce((obj, tokenAddress) => {
|
|
306
|
-
var _a;
|
|
307
|
-
// The Price API lowercases both currency and token addresses, so we have
|
|
308
|
-
// to keep track of them and make sure we return the original versions.
|
|
309
|
-
const lowercasedTokenAddress = tokenAddress.toLowerCase();
|
|
310
|
-
const lowercasedCurrency = currency.toLowerCase();
|
|
311
|
-
const price = (_a = pricesByCurrencyByTokenAddress[lowercasedTokenAddress]) === null || _a === void 0 ? void 0 : _a[lowercasedCurrency];
|
|
312
|
-
if (!price) {
|
|
313
|
-
// console error instead of throwing to not interrupt the fetching of other tokens in case just one fails
|
|
314
|
-
console.error(`Could not find price for "${tokenAddress}" in "${currency}"`);
|
|
315
|
-
}
|
|
316
|
-
const tokenPrice = {
|
|
317
|
-
tokenAddress,
|
|
318
|
-
value: price,
|
|
319
|
-
currency,
|
|
320
|
-
};
|
|
321
|
-
return Object.assign(Object.assign({}, obj), (tokenPrice.value !== undefined
|
|
322
|
-
? { [tokenAddress]: tokenPrice }
|
|
323
|
-
: {}));
|
|
324
|
-
}, {});
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Type guard for whether the API can return token prices for the given chain
|
|
329
|
-
* ID.
|
|
330
|
-
*
|
|
331
|
-
* @param chainId - The chain ID to check.
|
|
332
|
-
* @returns True if the API supports the chain ID, false otherwise.
|
|
333
|
-
*/
|
|
334
|
-
validateChainIdSupported(chainId) {
|
|
335
|
-
const supportedChainIds = exports.SUPPORTED_CHAIN_IDS;
|
|
336
|
-
return typeof chainId === 'string' && supportedChainIds.includes(chainId);
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Type guard for whether the API can return token prices in the given
|
|
340
|
-
* currency.
|
|
341
|
-
*
|
|
342
|
-
* @param currency - The currency to check. If a string, can be either
|
|
343
|
-
* lowercase or uppercase.
|
|
344
|
-
* @returns True if the API supports the currency, false otherwise.
|
|
345
|
-
*/
|
|
346
|
-
validateCurrencySupported(currency) {
|
|
347
|
-
const supportedCurrencies = exports.SUPPORTED_CURRENCIES;
|
|
348
|
-
return (typeof currency === 'string' &&
|
|
349
|
-
supportedCurrencies.includes(currency.toLowerCase()));
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
exports.CodefiTokenPricesServiceV2 = CodefiTokenPricesServiceV2;
|
|
353
|
-
_CodefiTokenPricesServiceV2_tokenPricePolicy = new WeakMap();
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkUAH5YURZjs = require('../chunk-UAH5YURZ.js');
|
|
6
|
+
require('../chunk-Z4BLTVTB.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.CodefiTokenPricesServiceV2 = _chunkUAH5YURZjs.CodefiTokenPricesServiceV2; exports.SUPPORTED_CHAIN_IDS = _chunkUAH5YURZjs.SUPPORTED_CHAIN_IDS; exports.SUPPORTED_CURRENCIES = _chunkUAH5YURZjs.SUPPORTED_CURRENCIES;
|
|
354
12
|
//# sourceMappingURL=codefi-v2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codefi-v2.js","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAyD;AAEzD,2CAA8C;AAC9C,yCASmB;AAgBnB;;;GAGG;AACU,QAAA,oBAAoB,GAAG;IAClC,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;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G;IACH,wBAAwB,CAAC,OAAgB;QACvC,MAAM,iBAAiB,GAAsB,2BAAmB,CAAC;QACjE,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5E,CAAC;IAED;;;;;;;OAOG;IACH,yBAAyB,CAAC,QAAiB;QACzC,MAAM,mBAAmB,GAAsB,4BAAoB,CAAC;QACpE,OAAO,CACL,OAAO,QAAQ,KAAK,QAAQ;YAC5B,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;CACF;AAxKD,gEAwKC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { hexToNumber } from '@metamask/utils';\nimport {\n circuitBreaker,\n ConsecutiveBreaker,\n ExponentialBackoff,\n handleAll,\n type IPolicy,\n retry,\n wrap,\n CircuitState,\n} from 'cockatiel';\n\nimport type {\n AbstractTokenPricesService,\n TokenPrice,\n TokenPricesByTokenAddress,\n} from './abstract-token-prices-service';\n\n/**\n * The shape of the data that the /spot-prices endpoint returns.\n */\ntype SpotPricesEndpointData<\n TokenAddress extends Hex,\n Currency extends string,\n> = Record<TokenAddress, Record<Currency, number>>;\n\n/**\n * The list of currencies that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint, in lowercase form.\n */\nexport const SUPPORTED_CURRENCIES = [\n // Bitcoin\n 'btc',\n // Ether\n 'eth',\n // Litecoin\n 'ltc',\n // Bitcoin Cash\n 'bch',\n // Binance Coin\n 'bnb',\n // EOS\n 'eos',\n // XRP\n 'xrp',\n // Lumens\n 'xlm',\n // Chainlink\n 'link',\n // Polkadot\n 'dot',\n // Yearn.finance\n 'yfi',\n // US Dollar\n 'usd',\n // United Arab Emirates Dirham\n 'aed',\n // Argentine Peso\n 'ars',\n // Australian Dollar\n 'aud',\n // Bangladeshi Taka\n 'bdt',\n // Bahraini Dinar\n 'bhd',\n // Bermudian Dollar\n 'bmd',\n // Brazil Real\n 'brl',\n // Canadian Dollar\n 'cad',\n // Swiss Franc\n 'chf',\n // Chilean Peso\n 'clp',\n // Chinese Yuan\n 'cny',\n // Czech Koruna\n 'czk',\n // Danish Krone\n 'dkk',\n // Euro\n 'eur',\n // British Pound Sterling\n 'gbp',\n // Hong Kong Dollar\n 'hkd',\n // Hungarian Forint\n 'huf',\n // Indonesian Rupiah\n 'idr',\n // Israeli New Shekel\n 'ils',\n // Indian Rupee\n 'inr',\n // Japanese Yen\n 'jpy',\n // South Korean Won\n 'krw',\n // Kuwaiti Dinar\n 'kwd',\n // Sri Lankan Rupee\n 'lkr',\n // Burmese Kyat\n 'mmk',\n // Mexican Peso\n 'mxn',\n // Malaysian Ringgit\n 'myr',\n // Nigerian Naira\n 'ngn',\n // Norwegian Krone\n 'nok',\n // New Zealand Dollar\n 'nzd',\n // Philippine Peso\n 'php',\n // Pakistani Rupee\n 'pkr',\n // Polish Zloty\n 'pln',\n // Russian Ruble\n 'rub',\n // Saudi Riyal\n 'sar',\n // Swedish Krona\n 'sek',\n // Singapore Dollar\n 'sgd',\n // Thai Baht\n 'thb',\n // Turkish Lira\n 'try',\n // New Taiwan Dollar\n 'twd',\n // Ukrainian hryvnia\n 'uah',\n // Venezuelan bolívar fuerte\n 'vef',\n // Vietnamese đồng\n 'vnd',\n // South African Rand\n 'zar',\n // IMF Special Drawing Rights\n 'xdr',\n // Silver - Troy Ounce\n 'xag',\n // Gold - Troy Ounce\n 'xau',\n // Bits\n 'bits',\n // Satoshi\n 'sats',\n] as const;\n\n/**\n * A currency that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.\n */\ntype SupportedCurrency =\n | (typeof SUPPORTED_CURRENCIES)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES)[number]>;\n\n/**\n * The list of chain IDs that can be supplied in the URL for the `/spot-prices`\n * endpoint, but in hexadecimal form (for consistency with how we represent\n * chain IDs in other places).\n */\nexport const SUPPORTED_CHAIN_IDS = [\n // Ethereum Mainnet\n '0x1',\n // OP Mainnet\n '0xa',\n // Cronos Mainnet\n '0x19',\n // BNB Smart Chain Mainnet\n '0x38',\n // Syscoin Mainnet\n '0x39',\n // OKXChain Mainnet\n '0x42',\n // Hoo Smart Chain\n '0x46',\n // Meter Mainnet\n '0x52',\n // TomoChain\n '0x58',\n // Gnosis\n '0x64',\n // Velas EVM Mainnet\n '0x6a',\n // Fuse Mainnet\n '0x7a',\n // Huobi ECO Chain Mainnet\n '0x80',\n // Polygon Mainnet\n '0x89',\n // Fantom Opera\n '0xfa',\n // Boba Network\n '0x120',\n // KCC Mainnet\n '0x141',\n // zkSync Era Mainnet\n '0x144',\n // Theta Mainnet\n '0x169',\n // Metis Andromeda Mainnet\n '0x440',\n // Moonbeam\n '0x504',\n // Moonriver\n '0x505',\n // Base\n '0x2105',\n // Shiden\n '0x150',\n // Smart Bitcoin Cash\n '0x2710',\n // Arbitrum One\n '0xa4b1',\n // Celo Mainnet\n '0xa4ec',\n // Oasis Emerald\n '0xa516',\n // Avalanche C-Chain\n '0xa86a',\n // Polis Mainnet\n '0x518af',\n // Aurora Mainnet\n '0x4e454152',\n // Harmony Mainnet Shard 0\n '0x63564c40',\n // Linea Mainnet\n '0xe708',\n] as const;\n\n/**\n * A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,\n * but in hexadecimal form (for consistency with how we represent chain IDs in\n * other places).\n */\ntype SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];\n\n/**\n * All requests to V2 of the Price API start with this.\n */\nconst BASE_URL = 'https://price-api.metafi.codefi.network/v2';\n\nconst DEFAULT_TOKEN_PRICE_RETRIES = 3;\n// Each update attempt will result (1 + retries) calls if the server is down\nconst DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES =\n (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;\n\nconst DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\n/**\n * This version of the token prices service uses V2 of the Codefi Price API to\n * fetch token prices.\n */\nexport class CodefiTokenPricesServiceV2\n implements\n AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency>\n{\n #tokenPricePolicy: IPolicy;\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param options - Constructor options\n * @param options.degradedThreshold - The threshold between \"normal\" and \"degrated\" service,\n * in milliseconds.\n * @param options.retries - Number of retry attempts for each token price update.\n * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures\n * allowed before breaking the circuit and pausing further updates.\n * @param options.onBreak - An event handler for when the circuit breaks, useful for capturing\n * metrics about network failures.\n * @param options.onDegraded - An event handler for when the circuit remains closed, but requests\n * are failing or resolving too slowly (i.e. resolving more slowly than the `degradedThreshold).\n * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks\n * from too many consecutive failures.\n */\n constructor({\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_TOKEN_PRICE_RETRIES,\n maximumConsecutiveFailures = DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES,\n onBreak,\n onDegraded,\n circuitBreakDuration = 30 * 60 * 1000,\n }: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n } = {}) {\n // Construct a policy that will retry each update, and halt further updates\n // for a certain period after too many consecutive failures.\n const retryPolicy = retry(handleAll, {\n maxAttempts: retries,\n backoff: new ExponentialBackoff(),\n });\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maximumConsecutiveFailures),\n });\n if (onBreak) {\n circuitBreakerPolicy.onBreak(onBreak);\n }\n if (onDegraded) {\n retryPolicy.onGiveUp(() => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n onDegraded();\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (\n circuitBreakerPolicy.state === CircuitState.Closed &&\n duration > degradedThreshold\n ) {\n onDegraded();\n }\n });\n }\n this.#tokenPricePolicy = wrap(retryPolicy, circuitBreakerPolicy);\n }\n\n /**\n * Retrieves prices in the given currency for the tokens identified by the\n * given addresses which are expected to live on the given chain.\n *\n * @param args - The arguments to function.\n * @param args.chainId - An EIP-155 chain ID.\n * @param args.tokenAddresses - Addresses for tokens that live on the chain.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n async fetchTokenPrices({\n chainId,\n tokenAddresses,\n currency,\n }: {\n chainId: SupportedChainId;\n tokenAddresses: Hex[];\n currency: SupportedCurrency;\n }): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>> {\n const chainIdAsNumber = hexToNumber(chainId);\n\n const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);\n url.searchParams.append('tokenAddresses', tokenAddresses.join(','));\n url.searchParams.append('vsCurrency', currency);\n\n const pricesByCurrencyByTokenAddress: SpotPricesEndpointData<\n Lowercase<Hex>,\n Lowercase<SupportedCurrency>\n > = await this.#tokenPricePolicy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n );\n\n return tokenAddresses.reduce(\n (\n obj: Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>,\n tokenAddress,\n ) => {\n // The Price API lowercases both currency and token addresses, so we have\n // to keep track of them and make sure we return the original versions.\n const lowercasedTokenAddress =\n tokenAddress.toLowerCase() as Lowercase<Hex>;\n const lowercasedCurrency =\n currency.toLowerCase() as Lowercase<SupportedCurrency>;\n\n const price =\n pricesByCurrencyByTokenAddress[lowercasedTokenAddress]?.[\n lowercasedCurrency\n ];\n\n if (!price) {\n // console error instead of throwing to not interrupt the fetching of other tokens in case just one fails\n console.error(\n `Could not find price for \"${tokenAddress}\" in \"${currency}\"`,\n );\n }\n\n const tokenPrice: TokenPrice<Hex, SupportedCurrency> = {\n tokenAddress,\n value: price,\n currency,\n };\n\n return {\n ...obj,\n ...(tokenPrice.value !== undefined\n ? { [tokenAddress]: tokenPrice }\n : {}),\n };\n },\n {},\n ) as Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>;\n }\n\n /**\n * Type guard for whether the API can return token prices for the given chain\n * ID.\n *\n * @param chainId - The chain ID to check.\n * @returns True if the API supports the chain ID, false otherwise.\n */\n validateChainIdSupported(chainId: unknown): chainId is SupportedChainId {\n const supportedChainIds: readonly string[] = SUPPORTED_CHAIN_IDS;\n return typeof chainId === 'string' && supportedChainIds.includes(chainId);\n }\n\n /**\n * Type guard for whether the API can return token prices in the given\n * currency.\n *\n * @param currency - The currency to check. If a string, can be either\n * lowercase or uppercase.\n * @returns True if the API supports the currency, false otherwise.\n */\n validateCurrencySupported(currency: unknown): currency is SupportedCurrency {\n const supportedCurrencies: readonly string[] = SUPPORTED_CURRENCIES;\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CodefiTokenPricesServiceV2,
|
|
3
|
+
SUPPORTED_CHAIN_IDS,
|
|
4
|
+
SUPPORTED_CURRENCIES
|
|
5
|
+
} from "../chunk-WRQ7POD7.mjs";
|
|
6
|
+
import "../chunk-XUI43LEZ.mjs";
|
|
7
|
+
export {
|
|
8
|
+
CodefiTokenPricesServiceV2,
|
|
9
|
+
SUPPORTED_CHAIN_IDS,
|
|
10
|
+
SUPPORTED_CURRENCIES
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=codefi-v2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-OBUR4TXH.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkUAH5YURZjs = require('../chunk-UAH5YURZ.js');
|
|
5
|
+
require('../chunk-Z4BLTVTB.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.CodefiTokenPricesServiceV2 = _chunkUAH5YURZjs.CodefiTokenPricesServiceV2;
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/token-service.js
CHANGED
|
@@ -1,134 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.TOKEN_END_POINT_API = 'https://token-api.metaswap.codefi.network';
|
|
16
|
-
exports.TOKEN_METADATA_NO_SUPPORT_ERROR = 'TokenService Error: Network does not support fetchTokenMetadata';
|
|
17
|
-
/**
|
|
18
|
-
* Get the tokens URL for a specific network.
|
|
19
|
-
*
|
|
20
|
-
* @param chainId - The chain ID of the network the tokens requested are on.
|
|
21
|
-
* @returns The tokens URL.
|
|
22
|
-
*/
|
|
23
|
-
function getTokensURL(chainId) {
|
|
24
|
-
return `${exports.TOKEN_END_POINT_API}/tokens/${(0, controller_utils_1.convertHexToDecimal)(chainId)}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get the token metadata URL for the given network and token.
|
|
28
|
-
*
|
|
29
|
-
* @param chainId - The chain ID of the network the token is on.
|
|
30
|
-
* @param tokenAddress - The token address.
|
|
31
|
-
* @returns The token metadata URL.
|
|
32
|
-
*/
|
|
33
|
-
function getTokenMetadataURL(chainId, tokenAddress) {
|
|
34
|
-
return `${exports.TOKEN_END_POINT_API}/token/${(0, controller_utils_1.convertHexToDecimal)(chainId)}?address=${tokenAddress}`;
|
|
35
|
-
}
|
|
36
|
-
const tenSecondsInMilliseconds = 10000;
|
|
37
|
-
// Token list averages 1.6 MB in size
|
|
38
|
-
// timeoutFetch by default has a 500ms timeout, which will almost always timeout given the response size.
|
|
39
|
-
const defaultTimeout = tenSecondsInMilliseconds;
|
|
40
|
-
/**
|
|
41
|
-
* Fetch the list of token metadata for a given network. This request is cancellable using the
|
|
42
|
-
* abort signal passed in.
|
|
43
|
-
*
|
|
44
|
-
* @param chainId - The chain ID of the network the requested tokens are on.
|
|
45
|
-
* @param abortSignal - The abort signal used to cancel the request if necessary.
|
|
46
|
-
* @param options - Additional fetch options.
|
|
47
|
-
* @param options.timeout - The fetch timeout.
|
|
48
|
-
* @returns The token list, or `undefined` if the request was cancelled.
|
|
49
|
-
*/
|
|
50
|
-
function fetchTokenListByChainId(chainId, abortSignal, { timeout = defaultTimeout } = {}) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const tokenURL = getTokensURL(chainId);
|
|
53
|
-
const response = yield queryApi(tokenURL, abortSignal, timeout);
|
|
54
|
-
if (response) {
|
|
55
|
-
return parseJsonResponse(response);
|
|
56
|
-
}
|
|
57
|
-
return undefined;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
exports.fetchTokenListByChainId = fetchTokenListByChainId;
|
|
61
|
-
/**
|
|
62
|
-
* Fetch metadata for the token address provided for a given network. This request is cancellable
|
|
63
|
-
* using the abort signal passed in.
|
|
64
|
-
*
|
|
65
|
-
* @param chainId - The chain ID of the network the token is on.
|
|
66
|
-
* @param tokenAddress - The address of the token to fetch metadata for.
|
|
67
|
-
* @param abortSignal - The abort signal used to cancel the request if necessary.
|
|
68
|
-
* @param options - Additional fetch options.
|
|
69
|
-
* @param options.timeout - The fetch timeout.
|
|
70
|
-
* @returns The token metadata, or `undefined` if the request was either aborted or failed.
|
|
71
|
-
*/
|
|
72
|
-
function fetchTokenMetadata(chainId, tokenAddress, abortSignal, { timeout = defaultTimeout } = {}) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
if (!(0, assetsUtil_1.isTokenListSupportedForNetwork)(chainId)) {
|
|
75
|
-
throw new Error(exports.TOKEN_METADATA_NO_SUPPORT_ERROR);
|
|
76
|
-
}
|
|
77
|
-
const tokenMetadataURL = getTokenMetadataURL(chainId, tokenAddress);
|
|
78
|
-
const response = yield queryApi(tokenMetadataURL, abortSignal, timeout);
|
|
79
|
-
if (response) {
|
|
80
|
-
return parseJsonResponse(response);
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
exports.fetchTokenMetadata = fetchTokenMetadata;
|
|
86
|
-
/**
|
|
87
|
-
* Perform fetch request against the api.
|
|
88
|
-
*
|
|
89
|
-
* @param apiURL - The URL of the API to fetch.
|
|
90
|
-
* @param abortSignal - The abort signal used to cancel the request if necessary.
|
|
91
|
-
* @param timeout - The fetch timeout.
|
|
92
|
-
* @returns Promise resolving request response.
|
|
93
|
-
*/
|
|
94
|
-
function queryApi(apiURL, abortSignal, timeout) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const fetchOptions = {
|
|
97
|
-
referrer: apiURL,
|
|
98
|
-
referrerPolicy: 'no-referrer-when-downgrade',
|
|
99
|
-
method: 'GET',
|
|
100
|
-
mode: 'cors',
|
|
101
|
-
signal: abortSignal,
|
|
102
|
-
cache: 'default',
|
|
103
|
-
};
|
|
104
|
-
fetchOptions.headers = new window.Headers();
|
|
105
|
-
fetchOptions.headers.set('Content-Type', 'application/json');
|
|
106
|
-
try {
|
|
107
|
-
return yield (0, controller_utils_1.timeoutFetch)(apiURL, fetchOptions, timeout);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
111
|
-
console.log('Request is aborted');
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return undefined;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Parse an API response and return the response JSON data.
|
|
119
|
-
*
|
|
120
|
-
* @param apiResponse - The API response to parse.
|
|
121
|
-
* @returns The response JSON data.
|
|
122
|
-
* @throws Will throw if the response includes an error.
|
|
123
|
-
*/
|
|
124
|
-
function parseJsonResponse(apiResponse) {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
const responseObj = yield apiResponse.json();
|
|
127
|
-
// api may return errors as json without setting an error http status code
|
|
128
|
-
if (responseObj === null || responseObj === void 0 ? void 0 : responseObj.error) {
|
|
129
|
-
throw new Error(`TokenService Error: ${responseObj.error}`);
|
|
130
|
-
}
|
|
131
|
-
return responseObj;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkPUFSYRJZjs = require('./chunk-PUFSYRJZ.js');
|
|
7
|
+
require('./chunk-YD3NRMFC.js');
|
|
8
|
+
require('./chunk-Z4BLTVTB.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.TOKEN_END_POINT_API = _chunkPUFSYRJZjs.TOKEN_END_POINT_API; exports.TOKEN_METADATA_NO_SUPPORT_ERROR = _chunkPUFSYRJZjs.TOKEN_METADATA_NO_SUPPORT_ERROR; exports.fetchTokenListByChainId = _chunkPUFSYRJZjs.fetchTokenListByChainId; exports.fetchTokenMetadata = _chunkPUFSYRJZjs.fetchTokenMetadata;
|
|
134
15
|
//# sourceMappingURL=token-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TOKEN_END_POINT_API,
|
|
3
|
+
TOKEN_METADATA_NO_SUPPORT_ERROR,
|
|
4
|
+
fetchTokenListByChainId,
|
|
5
|
+
fetchTokenMetadata
|
|
6
|
+
} from "./chunk-QHRPRO5U.mjs";
|
|
7
|
+
import "./chunk-5C7ZVZNM.mjs";
|
|
8
|
+
import "./chunk-XUI43LEZ.mjs";
|
|
9
|
+
export {
|
|
10
|
+
TOKEN_END_POINT_API,
|
|
11
|
+
TOKEN_METADATA_NO_SUPPORT_ERROR,
|
|
12
|
+
fetchTokenListByChainId,
|
|
13
|
+
fetchTokenMetadata
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=token-service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|