@metamask/assets-controllers 38.0.0 → 38.1.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 (372) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/dist/AccountTrackerController.cjs +245 -0
  3. package/dist/AccountTrackerController.cjs.map +1 -0
  4. package/dist/{types/AccountTrackerController.d.ts → AccountTrackerController.d.cts} +6 -6
  5. package/dist/AccountTrackerController.d.cts.map +1 -0
  6. package/dist/AccountTrackerController.d.mts +112 -0
  7. package/dist/AccountTrackerController.d.mts.map +1 -0
  8. package/dist/AccountTrackerController.mjs +244 -8
  9. package/dist/AccountTrackerController.mjs.map +1 -1
  10. package/dist/AssetsContractController.cjs +389 -0
  11. package/dist/AssetsContractController.cjs.map +1 -0
  12. package/dist/{types/AssetsContractController.d.ts → AssetsContractController.d.cts} +9 -9
  13. package/dist/AssetsContractController.d.cts.map +1 -0
  14. package/dist/AssetsContractController.d.mts +277 -0
  15. package/dist/AssetsContractController.d.mts.map +1 -0
  16. package/dist/AssetsContractController.mjs +387 -16
  17. package/dist/AssetsContractController.mjs.map +1 -1
  18. package/dist/CurrencyRateController.cjs +156 -0
  19. package/dist/CurrencyRateController.cjs.map +1 -0
  20. package/dist/{types/CurrencyRateController.d.ts → CurrencyRateController.d.cts} +5 -5
  21. package/dist/CurrencyRateController.d.cts.map +1 -0
  22. package/dist/CurrencyRateController.d.mts +80 -0
  23. package/dist/CurrencyRateController.d.mts.map +1 -0
  24. package/dist/CurrencyRateController.mjs +150 -10
  25. package/dist/CurrencyRateController.mjs.map +1 -1
  26. package/dist/NftController.cjs +1159 -0
  27. package/dist/NftController.cjs.map +1 -0
  28. package/dist/{types/NftController.d.ts → NftController.d.cts} +11 -11
  29. package/dist/NftController.d.cts.map +1 -0
  30. package/dist/NftController.d.mts +424 -0
  31. package/dist/NftController.d.mts.map +1 -0
  32. package/dist/NftController.mjs +1156 -12
  33. package/dist/NftController.mjs.map +1 -1
  34. package/dist/NftDetectionController.cjs +237 -0
  35. package/dist/NftDetectionController.cjs.map +1 -0
  36. package/dist/{types/NftDetectionController.d.ts → NftDetectionController.d.cts} +9 -9
  37. package/dist/NftDetectionController.d.cts.map +1 -0
  38. package/dist/NftDetectionController.d.mts +368 -0
  39. package/dist/NftDetectionController.d.mts.map +1 -0
  40. package/dist/NftDetectionController.mjs +231 -14
  41. package/dist/NftDetectionController.mjs.map +1 -1
  42. package/dist/RatesController/RatesController.cjs +189 -0
  43. package/dist/RatesController/RatesController.cjs.map +1 -0
  44. package/dist/{types/RatesController/RatesController.d.ts → RatesController/RatesController.d.cts} +3 -3
  45. package/dist/RatesController/RatesController.d.cts.map +1 -0
  46. package/dist/RatesController/RatesController.d.mts +44 -0
  47. package/dist/RatesController/RatesController.d.mts.map +1 -0
  48. package/dist/RatesController/RatesController.mjs +183 -12
  49. package/dist/RatesController/RatesController.mjs.map +1 -1
  50. package/dist/RatesController/index.cjs +7 -0
  51. package/dist/RatesController/index.cjs.map +1 -0
  52. package/dist/{types/RatesController/index.d.ts → RatesController/index.d.cts} +3 -3
  53. package/dist/RatesController/index.d.cts.map +1 -0
  54. package/dist/RatesController/index.d.mts +3 -0
  55. package/dist/RatesController/index.d.mts.map +1 -0
  56. package/dist/RatesController/index.mjs +1 -12
  57. package/dist/RatesController/index.mjs.map +1 -1
  58. package/dist/RatesController/types.cjs +3 -0
  59. package/dist/RatesController/types.cjs.map +1 -0
  60. package/dist/{types/RatesController/types.d.ts → RatesController/types.d.cts} +4 -4
  61. package/dist/RatesController/types.d.cts.map +1 -0
  62. package/dist/RatesController/types.d.mts +100 -0
  63. package/dist/RatesController/types.d.mts.map +1 -0
  64. package/dist/RatesController/types.mjs +1 -0
  65. package/dist/RatesController/types.mjs.map +1 -1
  66. package/dist/Standards/ERC20Standard.cjs +124 -0
  67. package/dist/Standards/ERC20Standard.cjs.map +1 -0
  68. package/dist/{types/Standards/ERC20Standard.d.ts → Standards/ERC20Standard.d.cts} +3 -3
  69. package/dist/Standards/ERC20Standard.d.cts.map +1 -0
  70. package/dist/Standards/ERC20Standard.d.mts +49 -0
  71. package/dist/Standards/ERC20Standard.d.mts.map +1 -0
  72. package/dist/Standards/ERC20Standard.mjs +121 -8
  73. package/dist/Standards/ERC20Standard.mjs.map +1 -1
  74. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs +189 -0
  75. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs.map +1 -0
  76. package/dist/{types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts → Standards/NftStandards/ERC1155/ERC1155Standard.d.cts} +3 -3
  77. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.cts.map +1 -0
  78. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts +95 -0
  79. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts.map +1 -0
  80. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +184 -8
  81. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -1
  82. package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +167 -0
  83. package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -0
  84. package/dist/{types/Standards/NftStandards/ERC721/ERC721Standard.d.ts → Standards/NftStandards/ERC721/ERC721Standard.d.cts} +2 -2
  85. package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.cts.map +1 -0
  86. package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts +89 -0
  87. package/dist/Standards/NftStandards/ERC721/ERC721Standard.d.mts.map +1 -0
  88. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +162 -8
  89. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
  90. package/dist/TokenBalancesController.cjs +136 -0
  91. package/dist/TokenBalancesController.cjs.map +1 -0
  92. package/dist/{types/TokenBalancesController.d.ts → TokenBalancesController.d.cts} +7 -7
  93. package/dist/TokenBalancesController.d.cts.map +1 -0
  94. package/dist/TokenBalancesController.d.mts +82 -0
  95. package/dist/TokenBalancesController.d.mts.map +1 -0
  96. package/dist/TokenBalancesController.mjs +129 -10
  97. package/dist/TokenBalancesController.mjs.map +1 -1
  98. package/dist/TokenDetectionController.cjs +368 -0
  99. package/dist/TokenDetectionController.cjs.map +1 -0
  100. package/dist/{types/TokenDetectionController.d.ts → TokenDetectionController.d.cts} +10 -10
  101. package/dist/TokenDetectionController.d.cts.map +1 -0
  102. package/dist/TokenDetectionController.d.mts +109 -0
  103. package/dist/TokenDetectionController.d.mts.map +1 -0
  104. package/dist/TokenDetectionController.mjs +365 -15
  105. package/dist/TokenDetectionController.mjs.map +1 -1
  106. package/dist/TokenListController.cjs +274 -0
  107. package/dist/TokenListController.cjs.map +1 -0
  108. package/dist/{types/TokenListController.d.ts → TokenListController.d.cts} +5 -5
  109. package/dist/TokenListController.d.cts.map +1 -0
  110. package/dist/TokenListController.d.mts +117 -0
  111. package/dist/TokenListController.d.mts.map +1 -0
  112. package/dist/TokenListController.mjs +267 -12
  113. package/dist/TokenListController.mjs.map +1 -1
  114. package/dist/TokenRatesController.cjs +452 -0
  115. package/dist/TokenRatesController.cjs.map +1 -0
  116. package/dist/{types/TokenRatesController.d.ts → TokenRatesController.d.cts} +8 -8
  117. package/dist/TokenRatesController.d.cts.map +1 -0
  118. package/dist/TokenRatesController.d.mts +170 -0
  119. package/dist/TokenRatesController.d.mts.map +1 -0
  120. package/dist/TokenRatesController.mjs +446 -16
  121. package/dist/TokenRatesController.mjs.map +1 -1
  122. package/dist/TokensController.cjs +678 -0
  123. package/dist/TokensController.cjs.map +1 -0
  124. package/dist/{types/TokensController.d.ts → TokensController.d.cts} +9 -9
  125. package/dist/TokensController.d.cts.map +1 -0
  126. package/dist/TokensController.d.mts +165 -0
  127. package/dist/TokensController.d.mts.map +1 -0
  128. package/dist/TokensController.mjs +675 -14
  129. package/dist/TokensController.mjs.map +1 -1
  130. package/dist/assetsUtil.cjs +358 -0
  131. package/dist/assetsUtil.cjs.map +1 -0
  132. package/dist/{types/assetsUtil.d.ts → assetsUtil.d.cts} +7 -7
  133. package/dist/assetsUtil.d.cts.map +1 -0
  134. package/dist/assetsUtil.d.mts +177 -0
  135. package/dist/assetsUtil.d.mts.map +1 -0
  136. package/dist/assetsUtil.mjs +343 -36
  137. package/dist/assetsUtil.mjs.map +1 -1
  138. package/dist/constants.cjs +10 -0
  139. package/dist/constants.cjs.map +1 -0
  140. package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
  141. package/dist/constants.d.cts.map +1 -0
  142. package/dist/constants.d.mts +6 -0
  143. package/dist/constants.d.mts.map +1 -0
  144. package/dist/constants.mjs +6 -7
  145. package/dist/constants.mjs.map +1 -1
  146. package/dist/crypto-compare-service/crypto-compare.cjs +119 -0
  147. package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -0
  148. package/dist/{types/crypto-compare-service/crypto-compare.d.ts → crypto-compare-service/crypto-compare.d.cts} +1 -1
  149. package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -0
  150. package/dist/crypto-compare-service/crypto-compare.d.mts +22 -0
  151. package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -0
  152. package/dist/crypto-compare-service/crypto-compare.mjs +113 -9
  153. package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
  154. package/dist/crypto-compare-service/index.cjs +7 -0
  155. package/dist/crypto-compare-service/index.cjs.map +1 -0
  156. package/dist/crypto-compare-service/index.d.cts +2 -0
  157. package/dist/crypto-compare-service/index.d.cts.map +1 -0
  158. package/dist/crypto-compare-service/index.d.mts +2 -0
  159. package/dist/crypto-compare-service/index.d.mts.map +1 -0
  160. package/dist/crypto-compare-service/index.mjs +1 -10
  161. package/dist/crypto-compare-service/index.mjs.map +1 -1
  162. package/dist/index.cjs +51 -0
  163. package/dist/index.cjs.map +1 -0
  164. package/dist/{types/index.d.ts → index.d.cts} +24 -24
  165. package/dist/index.d.cts.map +1 -0
  166. package/dist/index.d.mts +24 -0
  167. package/dist/index.d.mts.map +1 -0
  168. package/dist/index.mjs +13 -80
  169. package/dist/index.mjs.map +1 -1
  170. package/dist/token-prices-service/abstract-token-prices-service.cjs +3 -0
  171. package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -0
  172. package/dist/{types/token-prices-service/abstract-token-prices-service.d.ts → token-prices-service/abstract-token-prices-service.d.cts} +2 -2
  173. package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -0
  174. package/dist/token-prices-service/abstract-token-prices-service.d.mts +79 -0
  175. package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -0
  176. package/dist/token-prices-service/abstract-token-prices-service.mjs +1 -0
  177. package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
  178. package/dist/token-prices-service/codefi-v2.cjs +352 -0
  179. package/dist/token-prices-service/codefi-v2.cjs.map +1 -0
  180. package/dist/{types/token-prices-service/codefi-v2.d.ts → token-prices-service/codefi-v2.d.cts} +3 -3
  181. package/dist/token-prices-service/codefi-v2.d.cts.map +1 -0
  182. package/dist/token-prices-service/codefi-v2.d.mts +97 -0
  183. package/dist/token-prices-service/codefi-v2.d.mts.map +1 -0
  184. package/dist/token-prices-service/codefi-v2.mjs +347 -12
  185. package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
  186. package/dist/token-prices-service/index.cjs +7 -0
  187. package/dist/token-prices-service/index.cjs.map +1 -0
  188. package/dist/token-prices-service/index.d.cts +3 -0
  189. package/dist/token-prices-service/index.d.cts.map +1 -0
  190. package/dist/token-prices-service/index.d.mts +3 -0
  191. package/dist/token-prices-service/index.d.mts.map +1 -0
  192. package/dist/token-prices-service/index.mjs +1 -10
  193. package/dist/token-prices-service/index.mjs.map +1 -1
  194. package/dist/token-service.cjs +130 -0
  195. package/dist/token-service.cjs.map +1 -0
  196. package/dist/{types/token-service.d.ts → token-service.d.cts} +2 -2
  197. package/dist/token-service.d.cts.map +1 -0
  198. package/dist/token-service.d.mts +31 -0
  199. package/dist/token-service.d.mts.map +1 -0
  200. package/dist/token-service.mjs +124 -14
  201. package/dist/token-service.mjs.map +1 -1
  202. package/package.json +21 -16
  203. package/dist/AccountTrackerController.js +0 -10
  204. package/dist/AccountTrackerController.js.map +0 -1
  205. package/dist/AssetsContractController.js +0 -18
  206. package/dist/AssetsContractController.js.map +0 -1
  207. package/dist/CurrencyRateController.js +0 -12
  208. package/dist/CurrencyRateController.js.map +0 -1
  209. package/dist/NftController.js +0 -14
  210. package/dist/NftController.js.map +0 -1
  211. package/dist/NftDetectionController.js +0 -16
  212. package/dist/NftDetectionController.js.map +0 -1
  213. package/dist/RatesController/RatesController.js +0 -14
  214. package/dist/RatesController/RatesController.js.map +0 -1
  215. package/dist/RatesController/index.js +0 -13
  216. package/dist/RatesController/index.js.map +0 -1
  217. package/dist/RatesController/types.js +0 -1
  218. package/dist/RatesController/types.js.map +0 -1
  219. package/dist/Standards/ERC20Standard.js +0 -9
  220. package/dist/Standards/ERC20Standard.js.map +0 -1
  221. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +0 -9
  222. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js.map +0 -1
  223. package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +0 -9
  224. package/dist/Standards/NftStandards/ERC721/ERC721Standard.js.map +0 -1
  225. package/dist/TokenBalancesController.js +0 -12
  226. package/dist/TokenBalancesController.js.map +0 -1
  227. package/dist/TokenDetectionController.js +0 -17
  228. package/dist/TokenDetectionController.js.map +0 -1
  229. package/dist/TokenListController.js +0 -14
  230. package/dist/TokenListController.js.map +0 -1
  231. package/dist/TokenRatesController.js +0 -18
  232. package/dist/TokenRatesController.js.map +0 -1
  233. package/dist/TokensController.js +0 -16
  234. package/dist/TokensController.js.map +0 -1
  235. package/dist/assetsUtil.js +0 -38
  236. package/dist/assetsUtil.js.map +0 -1
  237. package/dist/chunk-27KOXCQK.mjs +0 -1
  238. package/dist/chunk-27KOXCQK.mjs.map +0 -1
  239. package/dist/chunk-2TZK6YZA.js +0 -1405
  240. package/dist/chunk-2TZK6YZA.js.map +0 -1
  241. package/dist/chunk-3LPQTUGG.js +0 -434
  242. package/dist/chunk-3LPQTUGG.js.map +0 -1
  243. package/dist/chunk-3QDXAE2D.mjs +0 -178
  244. package/dist/chunk-3QDXAE2D.mjs.map +0 -1
  245. package/dist/chunk-46KUC5FH.mjs +0 -434
  246. package/dist/chunk-46KUC5FH.mjs.map +0 -1
  247. package/dist/chunk-4QZESU46.mjs +0 -530
  248. package/dist/chunk-4QZESU46.mjs.map +0 -1
  249. package/dist/chunk-5QLC2MHV.js +0 -215
  250. package/dist/chunk-5QLC2MHV.js.map +0 -1
  251. package/dist/chunk-7K6PSEAA.js +0 -1
  252. package/dist/chunk-7K6PSEAA.js.map +0 -1
  253. package/dist/chunk-AX522TDL.mjs +0 -85
  254. package/dist/chunk-AX522TDL.mjs.map +0 -1
  255. package/dist/chunk-AZSIKIMK.mjs +0 -429
  256. package/dist/chunk-AZSIKIMK.mjs.map +0 -1
  257. package/dist/chunk-BBCZM5P4.js +0 -300
  258. package/dist/chunk-BBCZM5P4.js.map +0 -1
  259. package/dist/chunk-BZEAPSD5.mjs +0 -215
  260. package/dist/chunk-BZEAPSD5.mjs.map +0 -1
  261. package/dist/chunk-C7LNCQXM.mjs +0 -300
  262. package/dist/chunk-C7LNCQXM.mjs.map +0 -1
  263. package/dist/chunk-CP3HC7AQ.mjs +0 -12
  264. package/dist/chunk-CP3HC7AQ.mjs.map +0 -1
  265. package/dist/chunk-FWKV5FGP.mjs +0 -71
  266. package/dist/chunk-FWKV5FGP.mjs.map +0 -1
  267. package/dist/chunk-GDFLKKDY.js +0 -71
  268. package/dist/chunk-GDFLKKDY.js.map +0 -1
  269. package/dist/chunk-GW6RE66P.mjs +0 -210
  270. package/dist/chunk-GW6RE66P.mjs.map +0 -1
  271. package/dist/chunk-HVOIBGYN.js +0 -282
  272. package/dist/chunk-HVOIBGYN.js.map +0 -1
  273. package/dist/chunk-ISK2VSBB.js +0 -178
  274. package/dist/chunk-ISK2VSBB.js.map +0 -1
  275. package/dist/chunk-JCR4H6YL.js +0 -115
  276. package/dist/chunk-JCR4H6YL.js.map +0 -1
  277. package/dist/chunk-JJX7TMH5.mjs +0 -135
  278. package/dist/chunk-JJX7TMH5.mjs.map +0 -1
  279. package/dist/chunk-JMZ7KWJS.js +0 -157
  280. package/dist/chunk-JMZ7KWJS.js.map +0 -1
  281. package/dist/chunk-JYHAAA6W.mjs +0 -1
  282. package/dist/chunk-JYHAAA6W.mjs.map +0 -1
  283. package/dist/chunk-K7A3EOIM.js +0 -85
  284. package/dist/chunk-K7A3EOIM.js.map +0 -1
  285. package/dist/chunk-KPBNX6GP.mjs +0 -215
  286. package/dist/chunk-KPBNX6GP.mjs.map +0 -1
  287. package/dist/chunk-LKVWPNXY.js +0 -429
  288. package/dist/chunk-LKVWPNXY.js.map +0 -1
  289. package/dist/chunk-MZI3SDQN.js +0 -215
  290. package/dist/chunk-MZI3SDQN.js.map +0 -1
  291. package/dist/chunk-NDUMUEE6.js +0 -812
  292. package/dist/chunk-NDUMUEE6.js.map +0 -1
  293. package/dist/chunk-OBUR4TXH.js +0 -1
  294. package/dist/chunk-OBUR4TXH.js.map +0 -1
  295. package/dist/chunk-RGHTNZQ6.js +0 -12
  296. package/dist/chunk-RGHTNZQ6.js.map +0 -1
  297. package/dist/chunk-S5CFNNOM.mjs +0 -115
  298. package/dist/chunk-S5CFNNOM.mjs.map +0 -1
  299. package/dist/chunk-SK2B36Q4.mjs +0 -1405
  300. package/dist/chunk-SK2B36Q4.mjs.map +0 -1
  301. package/dist/chunk-TFLYM4PY.mjs +0 -291
  302. package/dist/chunk-TFLYM4PY.mjs.map +0 -1
  303. package/dist/chunk-TIFLP53R.js +0 -210
  304. package/dist/chunk-TIFLP53R.js.map +0 -1
  305. package/dist/chunk-TTH3ES66.mjs +0 -1
  306. package/dist/chunk-TTH3ES66.mjs.map +0 -1
  307. package/dist/chunk-UKXD6WUT.mjs +0 -157
  308. package/dist/chunk-UKXD6WUT.mjs.map +0 -1
  309. package/dist/chunk-UUF4E7OG.js +0 -530
  310. package/dist/chunk-UUF4E7OG.js.map +0 -1
  311. package/dist/chunk-V6DNVROD.js +0 -348
  312. package/dist/chunk-V6DNVROD.js.map +0 -1
  313. package/dist/chunk-XC3SOOGC.js +0 -1
  314. package/dist/chunk-XC3SOOGC.js.map +0 -1
  315. package/dist/chunk-XMQA5NLX.mjs +0 -812
  316. package/dist/chunk-XMQA5NLX.mjs.map +0 -1
  317. package/dist/chunk-XQO3EG4J.mjs +0 -348
  318. package/dist/chunk-XQO3EG4J.mjs.map +0 -1
  319. package/dist/chunk-XUI43LEZ.mjs +0 -30
  320. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  321. package/dist/chunk-YGGUAMHV.js +0 -135
  322. package/dist/chunk-YGGUAMHV.js.map +0 -1
  323. package/dist/chunk-Z4BLTVTB.js +0 -30
  324. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  325. package/dist/chunk-Z7RMCHD4.mjs +0 -282
  326. package/dist/chunk-Z7RMCHD4.mjs.map +0 -1
  327. package/dist/chunk-ZAR4BIOC.js +0 -291
  328. package/dist/chunk-ZAR4BIOC.js.map +0 -1
  329. package/dist/constants.js +0 -8
  330. package/dist/constants.js.map +0 -1
  331. package/dist/crypto-compare-service/crypto-compare.js +0 -10
  332. package/dist/crypto-compare-service/crypto-compare.js.map +0 -1
  333. package/dist/crypto-compare-service/index.js +0 -11
  334. package/dist/crypto-compare-service/index.js.map +0 -1
  335. package/dist/index.js +0 -81
  336. package/dist/index.js.map +0 -1
  337. package/dist/token-prices-service/abstract-token-prices-service.js +0 -1
  338. package/dist/token-prices-service/abstract-token-prices-service.js.map +0 -1
  339. package/dist/token-prices-service/codefi-v2.js +0 -14
  340. package/dist/token-prices-service/codefi-v2.js.map +0 -1
  341. package/dist/token-prices-service/index.js +0 -11
  342. package/dist/token-prices-service/index.js.map +0 -1
  343. package/dist/token-service.js +0 -15
  344. package/dist/token-service.js.map +0 -1
  345. package/dist/tsconfig.build.tsbuildinfo +0 -1
  346. package/dist/types/AccountTrackerController.d.ts.map +0 -1
  347. package/dist/types/AssetsContractController.d.ts.map +0 -1
  348. package/dist/types/CurrencyRateController.d.ts.map +0 -1
  349. package/dist/types/NftController.d.ts.map +0 -1
  350. package/dist/types/NftDetectionController.d.ts.map +0 -1
  351. package/dist/types/RatesController/RatesController.d.ts.map +0 -1
  352. package/dist/types/RatesController/index.d.ts.map +0 -1
  353. package/dist/types/RatesController/types.d.ts.map +0 -1
  354. package/dist/types/Standards/ERC20Standard.d.ts.map +0 -1
  355. package/dist/types/Standards/NftStandards/ERC1155/ERC1155Standard.d.ts.map +0 -1
  356. package/dist/types/Standards/NftStandards/ERC721/ERC721Standard.d.ts.map +0 -1
  357. package/dist/types/TokenBalancesController.d.ts.map +0 -1
  358. package/dist/types/TokenDetectionController.d.ts.map +0 -1
  359. package/dist/types/TokenListController.d.ts.map +0 -1
  360. package/dist/types/TokenRatesController.d.ts.map +0 -1
  361. package/dist/types/TokensController.d.ts.map +0 -1
  362. package/dist/types/assetsUtil.d.ts.map +0 -1
  363. package/dist/types/constants.d.ts.map +0 -1
  364. package/dist/types/crypto-compare-service/crypto-compare.d.ts.map +0 -1
  365. package/dist/types/crypto-compare-service/index.d.ts +0 -2
  366. package/dist/types/crypto-compare-service/index.d.ts.map +0 -1
  367. package/dist/types/index.d.ts.map +0 -1
  368. package/dist/types/token-prices-service/abstract-token-prices-service.d.ts.map +0 -1
  369. package/dist/types/token-prices-service/codefi-v2.d.ts.map +0 -1
  370. package/dist/types/token-prices-service/index.d.ts +0 -3
  371. package/dist/types/token-prices-service/index.d.ts.map +0 -1
  372. package/dist/types/token-service.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codefi-v2.d.cts","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAa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vE;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,gBAAgB;IAKvE;;;;;;;OAOG;IACH,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,IAAI,iBAAiB;CAO5E"}
@@ -0,0 +1,97 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ import type { AbstractTokenPricesService, TokenPricesByTokenAddress } from "./abstract-token-prices-service.mjs";
3
+ /**
4
+ * The list of currencies that can be supplied as the `vsCurrency` parameter to
5
+ * the `/spot-prices` endpoint, in lowercase form.
6
+ */
7
+ 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
+ /**
9
+ * Represents the zero address, commonly used as a placeholder in blockchain transactions.
10
+ * In the context of fetching market data, the zero address is utilized to retrieve information
11
+ * specifically for native currencies. This allows for a standardized approach to query market
12
+ * data for blockchain-native assets without a specific contract address.
13
+ */
14
+ export declare const ZERO_ADDRESS: Hex;
15
+ /**
16
+ * A currency that can be supplied as the `vsCurrency` parameter to
17
+ * the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.
18
+ */
19
+ type SupportedCurrency = (typeof SUPPORTED_CURRENCIES)[number] | Uppercase<(typeof SUPPORTED_CURRENCIES)[number]>;
20
+ /**
21
+ * The list of chain IDs that can be supplied in the URL for the `/spot-prices`
22
+ * endpoint, but in hexadecimal form (for consistency with how we represent
23
+ * chain IDs in other places).
24
+ * @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.
25
+ */
26
+ 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"];
27
+ /**
28
+ * A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,
29
+ * but in hexadecimal form (for consistency with how we represent chain IDs in
30
+ * other places).
31
+ */
32
+ type SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
33
+ /**
34
+ * This version of the token prices service uses V2 of the Codefi Price API to
35
+ * fetch token prices.
36
+ */
37
+ export declare class CodefiTokenPricesServiceV2 implements AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency> {
38
+ #private;
39
+ /**
40
+ * Construct a Codefi Token Price Service.
41
+ *
42
+ * @param options - Constructor options
43
+ * @param options.degradedThreshold - The threshold between "normal" and "degrated" service,
44
+ * in milliseconds.
45
+ * @param options.retries - Number of retry attempts for each token price update.
46
+ * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures
47
+ * allowed before breaking the circuit and pausing further updates.
48
+ * @param options.onBreak - An event handler for when the circuit breaks, useful for capturing
49
+ * metrics about network failures.
50
+ * @param options.onDegraded - An event handler for when the circuit remains closed, but requests
51
+ * are failing or resolving too slowly (i.e. resolving more slowly than the `degradedThreshold).
52
+ * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks
53
+ * from too many consecutive failures.
54
+ */
55
+ constructor({ degradedThreshold, retries, maximumConsecutiveFailures, onBreak, onDegraded, circuitBreakDuration, }?: {
56
+ degradedThreshold?: number;
57
+ retries?: number;
58
+ maximumConsecutiveFailures?: number;
59
+ onBreak?: () => void;
60
+ onDegraded?: () => void;
61
+ circuitBreakDuration?: number;
62
+ });
63
+ /**
64
+ * Retrieves prices in the given currency for the tokens identified by the
65
+ * given addresses which are expected to live on the given chain.
66
+ *
67
+ * @param args - The arguments to function.
68
+ * @param args.chainId - An EIP-155 chain ID.
69
+ * @param args.tokenAddresses - Addresses for tokens that live on the chain.
70
+ * @param args.currency - The desired currency of the token prices.
71
+ * @returns The prices for the requested tokens.
72
+ */
73
+ fetchTokenPrices({ chainId, tokenAddresses, currency, }: {
74
+ chainId: SupportedChainId;
75
+ tokenAddresses: Hex[];
76
+ currency: SupportedCurrency;
77
+ }): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>>;
78
+ /**
79
+ * Type guard for whether the API can return token prices for the given chain
80
+ * ID.
81
+ *
82
+ * @param chainId - The chain ID to check.
83
+ * @returns True if the API supports the chain ID, false otherwise.
84
+ */
85
+ validateChainIdSupported(chainId: unknown): chainId is SupportedChainId;
86
+ /**
87
+ * Type guard for whether the API can return token prices in the given
88
+ * currency.
89
+ *
90
+ * @param currency - The currency to check. If a string, can be either
91
+ * lowercase or uppercase.
92
+ * @returns True if the API supports the currency, false otherwise.
93
+ */
94
+ validateCurrencySupported(currency: unknown): currency is SupportedCurrency;
95
+ }
96
+ export {};
97
+ //# sourceMappingURL=codefi-v2.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codefi-v2.d.mts","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAa3C,OAAO,KAAK,EACV,0BAA0B,EAE1B,yBAAyB,EAC1B,4CAAwC;AAEzC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,ybA2HvB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,GAC4B,CAAC;AAExD;;;GAGG;AACH,KAAK,iBAAiB,GAClB,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,GACrC,SAAS,CAAC,CAAC,OAAO,oBAA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6
- } from "../chunk-XQO3EG4J.mjs";
7
- import "../chunk-XUI43LEZ.mjs";
8
- export {
9
- CodefiTokenPricesServiceV2,
10
- SUPPORTED_CHAIN_IDS,
11
- SUPPORTED_CURRENCIES,
12
- ZERO_ADDRESS
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ 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");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
13
6
  };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _CodefiTokenPricesServiceV2_tokenPricePolicy;
13
+ import { handleFetch } from "@metamask/controller-utils";
14
+ import { hexToNumber } from "@metamask/utils";
15
+ import $cockatiel from "cockatiel";
16
+ const { circuitBreaker, ConsecutiveBreaker, ExponentialBackoff, handleAll, retry, wrap, CircuitState } = $cockatiel;
17
+ /**
18
+ * The list of currencies that can be supplied as the `vsCurrency` parameter to
19
+ * the `/spot-prices` endpoint, in lowercase form.
20
+ */
21
+ export const SUPPORTED_CURRENCIES = [
22
+ // Bitcoin
23
+ 'btc',
24
+ // Ether
25
+ 'eth',
26
+ // Litecoin
27
+ 'ltc',
28
+ // Bitcoin Cash
29
+ 'bch',
30
+ // Binance Coin
31
+ 'bnb',
32
+ // EOS
33
+ 'eos',
34
+ // XRP
35
+ 'xrp',
36
+ // Lumens
37
+ 'xlm',
38
+ // Chainlink
39
+ 'link',
40
+ // Polkadot
41
+ 'dot',
42
+ // Yearn.finance
43
+ 'yfi',
44
+ // US Dollar
45
+ 'usd',
46
+ // United Arab Emirates Dirham
47
+ 'aed',
48
+ // Argentine Peso
49
+ 'ars',
50
+ // Australian Dollar
51
+ 'aud',
52
+ // Bangladeshi Taka
53
+ 'bdt',
54
+ // Bahraini Dinar
55
+ 'bhd',
56
+ // Bermudian Dollar
57
+ 'bmd',
58
+ // Brazil Real
59
+ 'brl',
60
+ // Canadian Dollar
61
+ 'cad',
62
+ // Swiss Franc
63
+ 'chf',
64
+ // Chilean Peso
65
+ 'clp',
66
+ // Chinese Yuan
67
+ 'cny',
68
+ // Czech Koruna
69
+ 'czk',
70
+ // Danish Krone
71
+ 'dkk',
72
+ // Euro
73
+ 'eur',
74
+ // British Pound Sterling
75
+ 'gbp',
76
+ // Hong Kong Dollar
77
+ 'hkd',
78
+ // Hungarian Forint
79
+ 'huf',
80
+ // Indonesian Rupiah
81
+ 'idr',
82
+ // Israeli New Shekel
83
+ 'ils',
84
+ // Indian Rupee
85
+ 'inr',
86
+ // Japanese Yen
87
+ 'jpy',
88
+ // South Korean Won
89
+ 'krw',
90
+ // Kuwaiti Dinar
91
+ 'kwd',
92
+ // Sri Lankan Rupee
93
+ 'lkr',
94
+ // Burmese Kyat
95
+ 'mmk',
96
+ // Mexican Peso
97
+ 'mxn',
98
+ // Malaysian Ringgit
99
+ 'myr',
100
+ // Nigerian Naira
101
+ 'ngn',
102
+ // Norwegian Krone
103
+ 'nok',
104
+ // New Zealand Dollar
105
+ 'nzd',
106
+ // Philippine Peso
107
+ 'php',
108
+ // Pakistani Rupee
109
+ 'pkr',
110
+ // Polish Zloty
111
+ 'pln',
112
+ // Russian Ruble
113
+ 'rub',
114
+ // Saudi Riyal
115
+ 'sar',
116
+ // Swedish Krona
117
+ 'sek',
118
+ // Singapore Dollar
119
+ 'sgd',
120
+ // Thai Baht
121
+ 'thb',
122
+ // Turkish Lira
123
+ 'try',
124
+ // New Taiwan Dollar
125
+ 'twd',
126
+ // Ukrainian hryvnia
127
+ 'uah',
128
+ // Venezuelan bolívar fuerte
129
+ 'vef',
130
+ // Vietnamese đồng
131
+ 'vnd',
132
+ // South African Rand
133
+ 'zar',
134
+ // IMF Special Drawing Rights
135
+ 'xdr',
136
+ // Silver - Troy Ounce
137
+ 'xag',
138
+ // Gold - Troy Ounce
139
+ 'xau',
140
+ // Bits
141
+ 'bits',
142
+ // Satoshi
143
+ 'sats',
144
+ ];
145
+ /**
146
+ * Represents the zero address, commonly used as a placeholder in blockchain transactions.
147
+ * In the context of fetching market data, the zero address is utilized to retrieve information
148
+ * specifically for native currencies. This allows for a standardized approach to query market
149
+ * data for blockchain-native assets without a specific contract address.
150
+ */
151
+ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
152
+ /**
153
+ * The list of chain IDs that can be supplied in the URL for the `/spot-prices`
154
+ * endpoint, but in hexadecimal form (for consistency with how we represent
155
+ * chain IDs in other places).
156
+ * @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.
157
+ */
158
+ export const SUPPORTED_CHAIN_IDS = [
159
+ // Ethereum Mainnet
160
+ '0x1',
161
+ // OP Mainnet
162
+ '0xa',
163
+ // Cronos Mainnet
164
+ '0x19',
165
+ // BNB Smart Chain Mainnet
166
+ '0x38',
167
+ // Syscoin Mainnet
168
+ '0x39',
169
+ // OKXChain Mainnet
170
+ '0x42',
171
+ // Hoo Smart Chain
172
+ '0x46',
173
+ // Meter Mainnet
174
+ '0x52',
175
+ // TomoChain
176
+ '0x58',
177
+ // Gnosis
178
+ '0x64',
179
+ // Velas EVM Mainnet
180
+ '0x6a',
181
+ // Fuse Mainnet
182
+ '0x7a',
183
+ // Huobi ECO Chain Mainnet
184
+ '0x80',
185
+ // Polygon Mainnet
186
+ '0x89',
187
+ // Fantom Opera
188
+ '0xfa',
189
+ // Boba Network
190
+ '0x120',
191
+ // KCC Mainnet
192
+ '0x141',
193
+ // zkSync Era Mainnet
194
+ '0x144',
195
+ // Theta Mainnet
196
+ '0x169',
197
+ // Metis Andromeda Mainnet
198
+ '0x440',
199
+ // Moonbeam
200
+ '0x504',
201
+ // Moonriver
202
+ '0x505',
203
+ // Mantle
204
+ '0x1388',
205
+ // Base
206
+ '0x2105',
207
+ // Shiden
208
+ '0x150',
209
+ // Smart Bitcoin Cash
210
+ '0x2710',
211
+ // Arbitrum One
212
+ '0xa4b1',
213
+ // Celo Mainnet
214
+ '0xa4ec',
215
+ // Oasis Emerald
216
+ '0xa516',
217
+ // Avalanche C-Chain
218
+ '0xa86a',
219
+ // Polis Mainnet
220
+ '0x518af',
221
+ // Aurora Mainnet
222
+ '0x4e454152',
223
+ // Harmony Mainnet Shard 0
224
+ '0x63564c40',
225
+ // Linea Mainnet
226
+ '0xe708',
227
+ ];
228
+ /**
229
+ * All requests to V2 of the Price API start with this.
230
+ */
231
+ const BASE_URL = 'https://price.api.cx.metamask.io/v2';
232
+ const DEFAULT_TOKEN_PRICE_RETRIES = 3;
233
+ // Each update attempt will result (1 + retries) calls if the server is down
234
+ const DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;
235
+ const DEFAULT_DEGRADED_THRESHOLD = 5000;
236
+ /**
237
+ * This version of the token prices service uses V2 of the Codefi Price API to
238
+ * fetch token prices.
239
+ */
240
+ export class CodefiTokenPricesServiceV2 {
241
+ /**
242
+ * Construct a Codefi Token Price Service.
243
+ *
244
+ * @param options - Constructor options
245
+ * @param options.degradedThreshold - The threshold between "normal" and "degrated" service,
246
+ * in milliseconds.
247
+ * @param options.retries - Number of retry attempts for each token price update.
248
+ * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures
249
+ * allowed before breaking the circuit and pausing further updates.
250
+ * @param options.onBreak - An event handler for when the circuit breaks, useful for capturing
251
+ * metrics about network failures.
252
+ * @param options.onDegraded - An event handler for when the circuit remains closed, but requests
253
+ * are failing or resolving too slowly (i.e. resolving more slowly than the `degradedThreshold).
254
+ * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks
255
+ * from too many consecutive failures.
256
+ */
257
+ constructor({ degradedThreshold = DEFAULT_DEGRADED_THRESHOLD, retries = DEFAULT_TOKEN_PRICE_RETRIES, maximumConsecutiveFailures = DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES, onBreak, onDegraded, circuitBreakDuration = 30 * 60 * 1000, } = {}) {
258
+ _CodefiTokenPricesServiceV2_tokenPricePolicy.set(this, void 0);
259
+ // Construct a policy that will retry each update, and halt further updates
260
+ // for a certain period after too many consecutive failures.
261
+ const retryPolicy = retry(handleAll, {
262
+ maxAttempts: retries,
263
+ backoff: new ExponentialBackoff(),
264
+ });
265
+ const circuitBreakerPolicy = circuitBreaker(handleAll, {
266
+ halfOpenAfter: circuitBreakDuration,
267
+ breaker: new ConsecutiveBreaker(maximumConsecutiveFailures),
268
+ });
269
+ if (onBreak) {
270
+ circuitBreakerPolicy.onBreak(onBreak);
271
+ }
272
+ if (onDegraded) {
273
+ retryPolicy.onGiveUp(() => {
274
+ if (circuitBreakerPolicy.state === CircuitState.Closed) {
275
+ onDegraded();
276
+ }
277
+ });
278
+ retryPolicy.onSuccess(({ duration }) => {
279
+ if (circuitBreakerPolicy.state === CircuitState.Closed &&
280
+ duration > degradedThreshold) {
281
+ onDegraded();
282
+ }
283
+ });
284
+ }
285
+ __classPrivateFieldSet(this, _CodefiTokenPricesServiceV2_tokenPricePolicy, wrap(retryPolicy, circuitBreakerPolicy), "f");
286
+ }
287
+ /**
288
+ * Retrieves prices in the given currency for the tokens identified by the
289
+ * given addresses which are expected to live on the given chain.
290
+ *
291
+ * @param args - The arguments to function.
292
+ * @param args.chainId - An EIP-155 chain ID.
293
+ * @param args.tokenAddresses - Addresses for tokens that live on the chain.
294
+ * @param args.currency - The desired currency of the token prices.
295
+ * @returns The prices for the requested tokens.
296
+ */
297
+ async fetchTokenPrices({ chainId, tokenAddresses, currency, }) {
298
+ const chainIdAsNumber = hexToNumber(chainId);
299
+ const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);
300
+ url.searchParams.append('tokenAddresses', [ZERO_ADDRESS, ...tokenAddresses].join(','));
301
+ url.searchParams.append('vsCurrency', currency);
302
+ url.searchParams.append('includeMarketData', 'true');
303
+ const addressCryptoDataMap = await __classPrivateFieldGet(this, _CodefiTokenPricesServiceV2_tokenPricePolicy, "f").execute(() => handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }));
304
+ return [ZERO_ADDRESS, ...tokenAddresses].reduce((obj, tokenAddress) => {
305
+ // The Price API lowercases both currency and token addresses, so we have
306
+ // to keep track of them and make sure we return the original versions.
307
+ const lowercasedTokenAddress = tokenAddress.toLowerCase();
308
+ const marketData = addressCryptoDataMap[lowercasedTokenAddress];
309
+ if (!marketData) {
310
+ return obj;
311
+ }
312
+ const token = {
313
+ tokenAddress,
314
+ currency,
315
+ ...marketData,
316
+ };
317
+ return {
318
+ ...obj,
319
+ [tokenAddress]: token,
320
+ };
321
+ }, {});
322
+ }
323
+ /**
324
+ * Type guard for whether the API can return token prices for the given chain
325
+ * ID.
326
+ *
327
+ * @param chainId - The chain ID to check.
328
+ * @returns True if the API supports the chain ID, false otherwise.
329
+ */
330
+ validateChainIdSupported(chainId) {
331
+ const supportedChainIds = SUPPORTED_CHAIN_IDS;
332
+ return typeof chainId === 'string' && supportedChainIds.includes(chainId);
333
+ }
334
+ /**
335
+ * Type guard for whether the API can return token prices in the given
336
+ * currency.
337
+ *
338
+ * @param currency - The currency to check. If a string, can be either
339
+ * lowercase or uppercase.
340
+ * @returns True if the API supports the currency, false otherwise.
341
+ */
342
+ validateCurrencySupported(currency) {
343
+ const supportedCurrencies = SUPPORTED_CURRENCIES;
344
+ return (typeof currency === 'string' &&
345
+ supportedCurrencies.includes(currency.toLowerCase()));
346
+ }
347
+ }
348
+ _CodefiTokenPricesServiceV2_tokenPricePolicy = new WeakMap();
14
349
  //# sourceMappingURL=codefi-v2.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"codefi-v2.mjs","sourceRoot":"","sources":["../../src/token-prices-service/codefi-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAEzD,OAAO,EAAE,WAAW,EAAE,wBAAwB;;;AAkB9C;;;GAGG;AACH,MAAM,CAAC,MAAM,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;IACN,KAAK;IACL,SAAS;IACT,KAAK;IACL,YAAY;IACZ,MAAM;IACN,WAAW;IACX,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,YAAY;IACZ,KAAK;IACL,8BAA8B;IAC9B,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,iBAAiB;IACjB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,cAAc;IACd,KAAK;IACL,kBAAkB;IAClB,KAAK;IACL,cAAc;IACd,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,OAAO;IACP,KAAK;IACL,yBAAyB;IACzB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,oBAAoB;IACpB,KAAK;IACL,qBAAqB;IACrB,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,gBAAgB;IAChB,KAAK;IACL,mBAAmB;IACnB,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,KAAK;IACL,oBAAoB;IACpB,K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EAAyE;YACzE,uEAAuE;YACvE,MAAM,sBAAsB,GAC1B,YAAY,CAAC,WAAW,EAAoB,CAAC;YAE/C,MAAM,UAAU,GAAG,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;YAEhE,IAAI,CAAC,UAAU,EAAE;gBACf,OAAO,GAAG,CAAC;aACZ;YAED,MAAM,KAAK,GAAuC;gBAChD,YAAY;gBACZ,QAAQ;gBACR,GAAG,UAAU;aACd,CAAC;YAEF,OAAO;gBACL,GAAG,GAAG;gBACN,CAAC,YAAY,CAAC,EAAE,KAAK;aACtB,CAAC;QACJ,CAAC,EACD,EAAE,CAC2D,CAAC;IAClE,CAAC;IAED;;;;;;OAMG;IACH,wBAAwB,CAAC,OAAgB;QACvC,MAAM,iBAAiB,GAAsB,mBAAmB,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,oBAAoB,CAAC;QACpE,OAAO,CACL,OAAO,QAAQ,KAAK,QAAQ;YAC5B,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { hexToNumber } from '@metamask/utils';\nimport {\n circuitBreaker,\n ConsecutiveBreaker,\n ExponentialBackoff,\n handleAll,\n type IPolicy,\n retry,\n wrap,\n CircuitState,\n} from 'cockatiel';\n\nimport type {\n AbstractTokenPricesService,\n TokenPrice,\n TokenPricesByTokenAddress,\n} from './abstract-token-prices-service';\n\n/**\n * The list of currencies that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint, in lowercase form.\n */\nexport const SUPPORTED_CURRENCIES = [\n // Bitcoin\n 'btc',\n // Ether\n 'eth',\n // Litecoin\n 'ltc',\n // Bitcoin Cash\n 'bch',\n // Binance Coin\n 'bnb',\n // EOS\n 'eos',\n // XRP\n 'xrp',\n // Lumens\n 'xlm',\n // Chainlink\n 'link',\n // Polkadot\n 'dot',\n // Yearn.finance\n 'yfi',\n // US Dollar\n 'usd',\n // United Arab Emirates Dirham\n 'aed',\n // Argentine Peso\n 'ars',\n // Australian Dollar\n 'aud',\n // Bangladeshi Taka\n 'bdt',\n // Bahraini Dinar\n 'bhd',\n // Bermudian Dollar\n 'bmd',\n // Brazil Real\n 'brl',\n // Canadian Dollar\n 'cad',\n // Swiss Franc\n 'chf',\n // Chilean Peso\n 'clp',\n // Chinese Yuan\n 'cny',\n // Czech Koruna\n 'czk',\n // Danish Krone\n 'dkk',\n // Euro\n 'eur',\n // British Pound Sterling\n 'gbp',\n // Hong Kong Dollar\n 'hkd',\n // Hungarian Forint\n 'huf',\n // Indonesian Rupiah\n 'idr',\n // Israeli New Shekel\n 'ils',\n // Indian Rupee\n 'inr',\n // Japanese Yen\n 'jpy',\n // South Korean Won\n 'krw',\n // Kuwaiti Dinar\n 'kwd',\n // Sri Lankan Rupee\n 'lkr',\n // Burmese Kyat\n 'mmk',\n // Mexican Peso\n 'mxn',\n // Malaysian Ringgit\n 'myr',\n // Nigerian Naira\n 'ngn',\n // Norwegian Krone\n 'nok',\n // New Zealand Dollar\n 'nzd',\n // Philippine Peso\n 'php',\n // Pakistani Rupee\n 'pkr',\n // Polish Zloty\n 'pln',\n // Russian Ruble\n 'rub',\n // Saudi Riyal\n 'sar',\n // Swedish Krona\n 'sek',\n // Singapore Dollar\n 'sgd',\n // Thai Baht\n 'thb',\n // Turkish Lira\n 'try',\n // New Taiwan Dollar\n 'twd',\n // Ukrainian hryvnia\n 'uah',\n // Venezuelan bolívar fuerte\n 'vef',\n // Vietnamese đồng\n 'vnd',\n // South African Rand\n 'zar',\n // IMF Special Drawing Rights\n 'xdr',\n // Silver - Troy Ounce\n 'xag',\n // Gold - Troy Ounce\n 'xau',\n // Bits\n 'bits',\n // Satoshi\n 'sats',\n] as const;\n\n/**\n * Represents the zero address, commonly used as a placeholder in blockchain transactions.\n * In the context of fetching market data, the zero address is utilized to retrieve information\n * specifically for native currencies. This allows for a standardized approach to query market\n * data for blockchain-native assets without a specific contract address.\n */\nexport const ZERO_ADDRESS: Hex =\n '0x0000000000000000000000000000000000000000' as const;\n\n/**\n * A currency that can be supplied as the `vsCurrency` parameter to\n * the `/spot-prices` endpoint. Covers both uppercase and lowercase versions.\n */\ntype SupportedCurrency =\n | (typeof SUPPORTED_CURRENCIES)[number]\n | Uppercase<(typeof SUPPORTED_CURRENCIES)[number]>;\n\n/**\n * The list of chain IDs that can be supplied in the URL for the `/spot-prices`\n * endpoint, but in hexadecimal form (for consistency with how we represent\n * chain IDs in other places).\n * @see Used by {@link CodefiTokenPricesServiceV2} to validate that a given chain ID is supported by V2 of the Codefi Price API.\n */\nexport const SUPPORTED_CHAIN_IDS = [\n // Ethereum Mainnet\n '0x1',\n // OP Mainnet\n '0xa',\n // Cronos Mainnet\n '0x19',\n // BNB Smart Chain Mainnet\n '0x38',\n // Syscoin Mainnet\n '0x39',\n // OKXChain Mainnet\n '0x42',\n // Hoo Smart Chain\n '0x46',\n // Meter Mainnet\n '0x52',\n // TomoChain\n '0x58',\n // Gnosis\n '0x64',\n // Velas EVM Mainnet\n '0x6a',\n // Fuse Mainnet\n '0x7a',\n // Huobi ECO Chain Mainnet\n '0x80',\n // Polygon Mainnet\n '0x89',\n // Fantom Opera\n '0xfa',\n // Boba Network\n '0x120',\n // KCC Mainnet\n '0x141',\n // zkSync Era Mainnet\n '0x144',\n // Theta Mainnet\n '0x169',\n // Metis Andromeda Mainnet\n '0x440',\n // Moonbeam\n '0x504',\n // Moonriver\n '0x505',\n // Mantle\n '0x1388',\n // Base\n '0x2105',\n // Shiden\n '0x150',\n // Smart Bitcoin Cash\n '0x2710',\n // Arbitrum One\n '0xa4b1',\n // Celo Mainnet\n '0xa4ec',\n // Oasis Emerald\n '0xa516',\n // Avalanche C-Chain\n '0xa86a',\n // Polis Mainnet\n '0x518af',\n // Aurora Mainnet\n '0x4e454152',\n // Harmony Mainnet Shard 0\n '0x63564c40',\n // Linea Mainnet\n '0xe708',\n] as const;\n\n/**\n * A chain ID that can be supplied in the URL for the `/spot-prices` endpoint,\n * but in hexadecimal form (for consistency with how we represent chain IDs in\n * other places).\n */\ntype SupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];\n\n/**\n * All requests to V2 of the Price API start with this.\n */\nconst BASE_URL = 'https://price.api.cx.metamask.io/v2';\n\nconst DEFAULT_TOKEN_PRICE_RETRIES = 3;\n// Each update attempt will result (1 + retries) calls if the server is down\nconst DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES =\n (1 + DEFAULT_TOKEN_PRICE_RETRIES) * 3;\n\nconst DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\n/**\n * The shape of the data that the /spot-prices endpoint returns.\n */\ntype MarketData = {\n /**\n * The all-time highest price of the token.\n */\n allTimeHigh: number;\n /**\n * The all-time lowest price of the token.\n */\n allTimeLow: number;\n /**\n * The number of tokens currently in circulation.\n */\n circulatingSupply: number;\n /**\n * The market cap calculated using the diluted supply.\n */\n dilutedMarketCap: number;\n /**\n * The highest price of the token in the last 24 hours.\n */\n high1d: number;\n /**\n * The lowest price of the token in the last 24 hours.\n */\n low1d: number;\n /**\n * The current market capitalization of the token.\n */\n marketCap: number;\n /**\n * The percentage change in market capitalization over the last 24 hours.\n */\n marketCapPercentChange1d: number;\n /**\n * The current price of the token.\n */\n price: number;\n /**\n * The absolute change in price over the last 24 hours.\n */\n priceChange1d: number;\n /**\n * The percentage change in price over the last 24 hours.\n */\n pricePercentChange1d: number;\n /**\n * The percentage change in price over the last hour.\n */\n pricePercentChange1h: number;\n /**\n * The percentage change in price over the last year.\n */\n pricePercentChange1y: number;\n /**\n * The percentage change in price over the last 7 days.\n */\n pricePercentChange7d: number;\n /**\n * The percentage change in price over the last 14 days.\n */\n pricePercentChange14d: number;\n /**\n * The percentage change in price over the last 30 days.\n */\n pricePercentChange30d: number;\n /**\n * The percentage change in price over the last 200 days.\n */\n pricePercentChange200d: number;\n /**\n * The total trading volume of the token in the last 24 hours.\n */\n totalVolume: number;\n};\n\ntype MarketDataByTokenAddress = { [address: Hex]: MarketData };\n/**\n * This version of the token prices service uses V2 of the Codefi Price API to\n * fetch token prices.\n */\nexport class CodefiTokenPricesServiceV2\n implements\n AbstractTokenPricesService<SupportedChainId, Hex, SupportedCurrency>\n{\n #tokenPricePolicy: IPolicy;\n\n /**\n * Construct a Codefi Token Price Service.\n *\n * @param options - Constructor options\n * @param options.degradedThreshold - The threshold between \"normal\" and \"degrated\" service,\n * in milliseconds.\n * @param options.retries - Number of retry attempts for each token price update.\n * @param options.maximumConsecutiveFailures - The maximum number of consecutive failures\n * allowed before breaking the circuit and pausing further updates.\n * @param options.onBreak - An event handler for when the circuit breaks, useful for capturing\n * metrics about network failures.\n * @param options.onDegraded - An event handler for when the circuit remains closed, but requests\n * are failing or resolving too slowly (i.e. resolving more slowly than the `degradedThreshold).\n * @param options.circuitBreakDuration - The amount of time to wait when the circuit breaks\n * from too many consecutive failures.\n */\n constructor({\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n retries = DEFAULT_TOKEN_PRICE_RETRIES,\n maximumConsecutiveFailures = DEFAULT_TOKEN_PRICE_MAX_CONSECUTIVE_FAILURES,\n onBreak,\n onDegraded,\n circuitBreakDuration = 30 * 60 * 1000,\n }: {\n degradedThreshold?: number;\n retries?: number;\n maximumConsecutiveFailures?: number;\n onBreak?: () => void;\n onDegraded?: () => void;\n circuitBreakDuration?: number;\n } = {}) {\n // Construct a policy that will retry each update, and halt further updates\n // for a certain period after too many consecutive failures.\n const retryPolicy = retry(handleAll, {\n maxAttempts: retries,\n backoff: new ExponentialBackoff(),\n });\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maximumConsecutiveFailures),\n });\n if (onBreak) {\n circuitBreakerPolicy.onBreak(onBreak);\n }\n if (onDegraded) {\n retryPolicy.onGiveUp(() => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n onDegraded();\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (\n circuitBreakerPolicy.state === CircuitState.Closed &&\n duration > degradedThreshold\n ) {\n onDegraded();\n }\n });\n }\n this.#tokenPricePolicy = wrap(retryPolicy, circuitBreakerPolicy);\n }\n\n /**\n * Retrieves prices in the given currency for the tokens identified by the\n * given addresses which are expected to live on the given chain.\n *\n * @param args - The arguments to function.\n * @param args.chainId - An EIP-155 chain ID.\n * @param args.tokenAddresses - Addresses for tokens that live on the chain.\n * @param args.currency - The desired currency of the token prices.\n * @returns The prices for the requested tokens.\n */\n async fetchTokenPrices({\n chainId,\n tokenAddresses,\n currency,\n }: {\n chainId: SupportedChainId;\n tokenAddresses: Hex[];\n currency: SupportedCurrency;\n }): Promise<Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>> {\n const chainIdAsNumber = hexToNumber(chainId);\n\n const url = new URL(`${BASE_URL}/chains/${chainIdAsNumber}/spot-prices`);\n url.searchParams.append(\n 'tokenAddresses',\n [ZERO_ADDRESS, ...tokenAddresses].join(','),\n );\n url.searchParams.append('vsCurrency', currency);\n url.searchParams.append('includeMarketData', 'true');\n\n const addressCryptoDataMap: MarketDataByTokenAddress =\n await this.#tokenPricePolicy.execute(() =>\n handleFetch(url, { headers: { 'Cache-Control': 'no-cache' } }),\n );\n\n return [ZERO_ADDRESS, ...tokenAddresses].reduce(\n (\n obj: Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>,\n tokenAddress,\n ) => {\n // The Price API lowercases both currency and token addresses, so we have\n // to keep track of them and make sure we return the original versions.\n const lowercasedTokenAddress =\n tokenAddress.toLowerCase() as Lowercase<Hex>;\n\n const marketData = addressCryptoDataMap[lowercasedTokenAddress];\n\n if (!marketData) {\n return obj;\n }\n\n const token: TokenPrice<Hex, SupportedCurrency> = {\n tokenAddress,\n currency,\n ...marketData,\n };\n\n return {\n ...obj,\n [tokenAddress]: token,\n };\n },\n {},\n ) as Partial<TokenPricesByTokenAddress<Hex, SupportedCurrency>>;\n }\n\n /**\n * Type guard for whether the API can return token prices for the given chain\n * ID.\n *\n * @param chainId - The chain ID to check.\n * @returns True if the API supports the chain ID, false otherwise.\n */\n validateChainIdSupported(chainId: unknown): chainId is SupportedChainId {\n const supportedChainIds: readonly string[] = SUPPORTED_CHAIN_IDS;\n return typeof chainId === 'string' && supportedChainIds.includes(chainId);\n }\n\n /**\n * Type guard for whether the API can return token prices in the given\n * currency.\n *\n * @param currency - The currency to check. If a string, can be either\n * lowercase or uppercase.\n * @returns True if the API supports the currency, false otherwise.\n */\n validateCurrencySupported(currency: unknown): currency is SupportedCurrency {\n const supportedCurrencies: readonly string[] = SUPPORTED_CURRENCIES;\n return (\n typeof currency === 'string' &&\n supportedCurrencies.includes(currency.toLowerCase())\n );\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUPPORTED_CHAIN_IDS = exports.CodefiTokenPricesServiceV2 = void 0;
4
+ var codefi_v2_1 = require("./codefi-v2.cjs");
5
+ Object.defineProperty(exports, "CodefiTokenPricesServiceV2", { enumerable: true, get: function () { return codefi_v2_1.CodefiTokenPricesServiceV2; } });
6
+ Object.defineProperty(exports, "SUPPORTED_CHAIN_IDS", { enumerable: true, get: function () { return codefi_v2_1.SUPPORTED_CHAIN_IDS; } });
7
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/token-prices-service/index.ts"],"names":[],"mappings":";;;AACA,6CAA8E;AAArE,uHAAA,0BAA0B,OAAA;AAAE,gHAAA,mBAAmB,OAAA","sourcesContent":["export type { AbstractTokenPricesService } from './abstract-token-prices-service';\nexport { CodefiTokenPricesServiceV2, SUPPORTED_CHAIN_IDS } from './codefi-v2';\n"]}
@@ -0,0 +1,3 @@
1
+ export type { AbstractTokenPricesService } from "./abstract-token-prices-service.cjs";
2
+ export { CodefiTokenPricesServiceV2, SUPPORTED_CHAIN_IDS } from "./codefi-v2.cjs";
3
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/token-prices-service/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,0BAA0B,EAAE,4CAAwC;AAClF,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,wBAAoB"}
@@ -0,0 +1,3 @@
1
+ export type { AbstractTokenPricesService } from "./abstract-token-prices-service.mjs";
2
+ export { CodefiTokenPricesServiceV2, SUPPORTED_CHAIN_IDS } from "./codefi-v2.mjs";
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/token-prices-service/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,0BAA0B,EAAE,4CAAwC;AAClF,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,wBAAoB"}
@@ -1,11 +1,2 @@
1
- import "../chunk-27KOXCQK.mjs";
2
- import {
3
- CodefiTokenPricesServiceV2,
4
- SUPPORTED_CHAIN_IDS
5
- } from "../chunk-XQO3EG4J.mjs";
6
- import "../chunk-XUI43LEZ.mjs";
7
- export {
8
- CodefiTokenPricesServiceV2,
9
- SUPPORTED_CHAIN_IDS
10
- };
1
+ export { CodefiTokenPricesServiceV2, SUPPORTED_CHAIN_IDS } from "./codefi-v2.mjs";
11
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/token-prices-service/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,wBAAoB","sourcesContent":["export type { AbstractTokenPricesService } from './abstract-token-prices-service';\nexport { CodefiTokenPricesServiceV2, SUPPORTED_CHAIN_IDS } from './codefi-v2';\n"]}