@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,177 @@
1
+ import type { BigNumber } from "@ethersproject/bignumber";
2
+ import type { Hex } from "@metamask/utils";
3
+ import BN from "bn.js";
4
+ import type { Nft, NftMetadata } from "./NftController.mjs";
5
+ import type { AbstractTokenPricesService } from "./token-prices-service/index.mjs";
6
+ import { type ContractExchangeRates } from "./TokenRatesController.mjs";
7
+ /**
8
+ * The maximum number of token addresses that should be sent to the Price API in
9
+ * a single request.
10
+ */
11
+ export declare const TOKEN_PRICES_BATCH_SIZE = 30;
12
+ /**
13
+ * Compares nft metadata entries to any nft entry.
14
+ * We need this method when comparing a new fetched nft metadata, in case a entry changed to a defined value,
15
+ * there's a need to update the nft in state.
16
+ *
17
+ * @param newNftMetadata - Nft metadata object.
18
+ * @param nft - Nft object to compare with.
19
+ * @returns Whether there are differences.
20
+ */
21
+ export declare function compareNftMetadata(newNftMetadata: NftMetadata, nft: Nft): boolean;
22
+ /**
23
+ * Checks whether the existing nft object has all the keys of the new incoming nft metadata object
24
+ * @param newNftMetadata - New nft metadata object
25
+ * @param nft - Existing nft object to compare with
26
+ * @returns Whether the existing nft object has all the new keys from the new Nft metadata object
27
+ */
28
+ export declare function hasNewCollectionFields(newNftMetadata: NftMetadata, nft: Nft): boolean;
29
+ /**
30
+ * Formats aggregator names to presentable format.
31
+ *
32
+ * @param aggregators - List of token list names in camelcase.
33
+ * @returns Formatted aggregator names.
34
+ */
35
+ export declare const formatAggregatorNames: (aggregators: string[]) => string[];
36
+ /**
37
+ * Format token list assets to use image proxy from Codefi.
38
+ *
39
+ * @param params - Object that contains chainID and tokenAddress.
40
+ * @param params.chainId - ChainID of network in 0x-prefixed hexadecimal format.
41
+ * @param params.tokenAddress - Address of token in mixed or lowercase.
42
+ * @returns Formatted image url
43
+ */
44
+ export declare const formatIconUrlWithProxy: ({ chainId, tokenAddress, }: {
45
+ chainId: Hex;
46
+ tokenAddress: string;
47
+ }) => string;
48
+ /**
49
+ * Networks where token detection is supported - Values are in hex format
50
+ */
51
+ export declare enum SupportedTokenDetectionNetworks {
52
+ mainnet = "0x1",
53
+ bsc = "0x38",
54
+ polygon = "0x89",
55
+ avax = "0xa86a",
56
+ aurora = "0x4e454152",
57
+ linea_goerli = "0xe704",
58
+ linea_mainnet = "0xe708",
59
+ arbitrum = "0xa4b1",
60
+ optimism = "0xa",
61
+ base = "0x2105",
62
+ zksync = "0x144",
63
+ cronos = "0x19",
64
+ celo = "0xa4ec",
65
+ gnosis = "0x64",
66
+ fantom = "0xfa",
67
+ polygon_zkevm = "0x44d",
68
+ moonbeam = "0x504",
69
+ moonriver = "0x505"
70
+ }
71
+ /**
72
+ * Check if token detection is enabled for certain networks.
73
+ *
74
+ * @param chainId - ChainID of network
75
+ * @returns Whether the current network supports token detection
76
+ */
77
+ export declare function isTokenDetectionSupportedForNetwork(chainId: Hex): boolean;
78
+ /**
79
+ * Check if token list polling is enabled for a given network.
80
+ * Currently this method is used to support e2e testing for consumers of this package.
81
+ *
82
+ * @param chainId - ChainID of network
83
+ * @returns Whether the current network supports tokenlists
84
+ */
85
+ export declare function isTokenListSupportedForNetwork(chainId: Hex): boolean;
86
+ /**
87
+ * Removes IPFS protocol prefix from input string.
88
+ *
89
+ * @param ipfsUrl - An IPFS url (e.g. ipfs://{content id})
90
+ * @returns IPFS content identifier and (possibly) path in a string
91
+ * @throws Will throw if the url passed is not IPFS.
92
+ */
93
+ export declare function removeIpfsProtocolPrefix(ipfsUrl: string): string;
94
+ /**
95
+ * Extracts content identifier and path from an input string.
96
+ *
97
+ * @param ipfsUrl - An IPFS URL minus the IPFS protocol prefix
98
+ * @returns IFPS content identifier (cid) and sub path as string.
99
+ * @throws Will throw if the url passed is not ipfs.
100
+ */
101
+ export declare function getIpfsCIDv1AndPath(ipfsUrl: string): Promise<{
102
+ cid: string;
103
+ path?: string;
104
+ }>;
105
+ /**
106
+ * Formats URL correctly for use retrieving assets hosted on IPFS.
107
+ *
108
+ * @param ipfsGateway - The users preferred IPFS gateway (full URL or just host).
109
+ * @param ipfsUrl - The IFPS URL pointed at the asset.
110
+ * @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.
111
+ * @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.
112
+ */
113
+ export declare function getFormattedIpfsUrl(ipfsGateway: string, ipfsUrl: string, subdomainSupported: boolean): Promise<string>;
114
+ /**
115
+ * Adds URL protocol prefix to input URL string if missing.
116
+ *
117
+ * @param urlString - An IPFS URL.
118
+ * @returns A URL with a https:// prepended.
119
+ */
120
+ export declare function addUrlProtocolPrefix(urlString: string): string;
121
+ /**
122
+ * Converts an Ethers BigNumber to a BN.
123
+ *
124
+ * @param bigNumber - An Ethers BigNumber instance.
125
+ * @returns A BN object.
126
+ */
127
+ export declare function ethersBigNumberToBN(bigNumber: BigNumber): BN;
128
+ /**
129
+ * Partitions a list of values into groups that are at most `batchSize` in
130
+ * length.
131
+ *
132
+ * @param values - The list of values.
133
+ * @param args - The remaining arguments.
134
+ * @param args.batchSize - The desired maximum number of values per batch.
135
+ * @returns The list of batches.
136
+ */
137
+ export declare function divideIntoBatches<Value>(values: Value[], { batchSize }: {
138
+ batchSize: number;
139
+ }): Value[][];
140
+ /**
141
+ * Constructs an object from processing batches of the given values
142
+ * sequentially.
143
+ *
144
+ * @param args - The arguments to this function.
145
+ * @param args.values - A list of values to iterate over.
146
+ * @param args.batchSize - The maximum number of values in each batch.
147
+ * @param args.eachBatch - A function to call for each batch. This function is
148
+ * similar to the function that `Array.prototype.reduce` takes, in that it
149
+ * receives the object that is being built, each batch in the list of batches
150
+ * and the index, and should return an updated version of the object.
151
+ * @param args.initialResult - The initial value of the final data structure,
152
+ * i.e., the value that will be fed into the first call of `eachBatch`.
153
+ * @returns The built object.
154
+ */
155
+ export declare function reduceInBatchesSerially<Value, Result extends Record<PropertyKey, unknown>>({ values, batchSize, eachBatch, initialResult, }: {
156
+ values: Value[];
157
+ batchSize: number;
158
+ eachBatch: (workingResult: Partial<Result>, batch: Value[], index: number) => Partial<Result> | Promise<Partial<Result>>;
159
+ initialResult: Partial<Result>;
160
+ }): Promise<Result>;
161
+ /**
162
+ * Retrieves token prices for a set of contract addresses in a specific currency and chainId.
163
+ *
164
+ * @param args - The arguments to function.
165
+ * @param args.tokenPricesService - An object in charge of retrieving token prices.
166
+ * @param args.nativeCurrency - The native currency to request price in.
167
+ * @param args.tokenAddresses - The list of contract addresses.
168
+ * @param args.chainId - The chainId of the tokens.
169
+ * @returns The prices for the requested tokens.
170
+ */
171
+ export declare function fetchTokenContractExchangeRates({ tokenPricesService, nativeCurrency, tokenAddresses, chainId, }: {
172
+ tokenPricesService: AbstractTokenPricesService;
173
+ nativeCurrency: string;
174
+ tokenAddresses: Hex[];
175
+ chainId: Hex;
176
+ }): Promise<ContractExchangeRates>;
177
+ //# sourceMappingURL=assetsUtil.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assetsUtil.d.mts","sourceRoot":"","sources":["../src/assetsUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iCAAiC;AAK1D,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAAE,cAAc;AAEvB,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,4BAAwB;AACxD,OAAO,KAAK,EAAE,0BAA0B,EAAE,yCAA+B;AACzE,OAAO,EAAE,KAAK,qBAAqB,EAAE,mCAA+B;AAEpE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,WAmBvE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,WAAW,EAC3B,GAAG,EAAE,GAAG,GACP,OAAO,CAKT;AA+BD;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,gBAAiB,MAAM,EAAE,aAM1D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB;aAIxB,GAAG;kBACE,MAAM;YAMrB,CAAC;AAEF;;GAEG;AACH,oBAAY,+BAA+B;IAGzC,OAAO,QAAQ;IAGf,GAAG,SAAS;IAGZ,OA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AAuB,CAC3C,KAAK,EACL,MAAM,SAAS,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EAC3C,EACA,MAAM,EACN,SAAS,EACT,SAAS,EACT,aAAa,GACd,EAAE;IACD,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,CACT,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,EAC9B,KAAK,EAAE,KAAK,EAAE,EACd,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CAChC,GAAG,OAAO,CAAC,MAAM,CAAC,CAUlB;AAED;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CAAC,EACpD,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,OAAO,GACR,EAAE;IACD,kBAAkB,EAAE,0BAA0B,CAAC;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,GAAG,EAAE,CAAC;IACtB,OAAO,EAAE,GAAG,CAAC;CACd,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAyCjC"}
@@ -1,38 +1,345 @@
1
- import {
2
- SupportedTokenDetectionNetworks,
3
- TOKEN_PRICES_BATCH_SIZE,
4
- addUrlProtocolPrefix,
5
- compareNftMetadata,
6
- divideIntoBatches,
7
- ethersBigNumberToBN,
8
- fetchTokenContractExchangeRates,
9
- formatAggregatorNames,
10
- formatIconUrlWithProxy,
11
- getFormattedIpfsUrl,
12
- getIpfsCIDv1AndPath,
13
- hasNewCollectionFields,
14
- isTokenDetectionSupportedForNetwork,
15
- isTokenListSupportedForNetwork,
16
- reduceInBatchesSerially,
17
- removeIpfsProtocolPrefix
18
- } from "./chunk-BZEAPSD5.mjs";
19
- import "./chunk-XUI43LEZ.mjs";
20
- export {
21
- SupportedTokenDetectionNetworks,
22
- TOKEN_PRICES_BATCH_SIZE,
23
- addUrlProtocolPrefix,
24
- compareNftMetadata,
25
- divideIntoBatches,
26
- ethersBigNumberToBN,
27
- fetchTokenContractExchangeRates,
28
- formatAggregatorNames,
29
- formatIconUrlWithProxy,
30
- getFormattedIpfsUrl,
31
- getIpfsCIDv1AndPath,
32
- hasNewCollectionFields,
33
- isTokenDetectionSupportedForNetwork,
34
- isTokenListSupportedForNetwork,
35
- reduceInBatchesSerially,
36
- removeIpfsProtocolPrefix
1
+ function $importDefault(module) {
2
+ if (module?.__esModule) {
3
+ return module.default;
4
+ }
5
+ return module;
6
+ }
7
+ import { convertHexToDecimal, toChecksumHexAddress } from "@metamask/controller-utils";
8
+ import { remove0x } from "@metamask/utils";
9
+ import $BN from "bn.js";
10
+ const BN = $importDefault($BN);
11
+ /**
12
+ * The maximum number of token addresses that should be sent to the Price API in
13
+ * a single request.
14
+ */
15
+ export const TOKEN_PRICES_BATCH_SIZE = 30;
16
+ /**
17
+ * Compares nft metadata entries to any nft entry.
18
+ * We need this method when comparing a new fetched nft metadata, in case a entry changed to a defined value,
19
+ * there's a need to update the nft in state.
20
+ *
21
+ * @param newNftMetadata - Nft metadata object.
22
+ * @param nft - Nft object to compare with.
23
+ * @returns Whether there are differences.
24
+ */
25
+ export function compareNftMetadata(newNftMetadata, nft) {
26
+ const keys = [
27
+ 'image',
28
+ 'backgroundColor',
29
+ 'imagePreview',
30
+ 'imageThumbnail',
31
+ 'imageOriginal',
32
+ 'animation',
33
+ 'animationOriginal',
34
+ 'externalLink',
35
+ 'tokenURI',
36
+ ];
37
+ const differentValues = keys.reduce((value, key) => {
38
+ if (newNftMetadata[key] && newNftMetadata[key] !== nft[key]) {
39
+ return value + 1;
40
+ }
41
+ return value;
42
+ }, 0);
43
+ return differentValues > 0;
44
+ }
45
+ /**
46
+ * Checks whether the existing nft object has all the keys of the new incoming nft metadata object
47
+ * @param newNftMetadata - New nft metadata object
48
+ * @param nft - Existing nft object to compare with
49
+ * @returns Whether the existing nft object has all the new keys from the new Nft metadata object
50
+ */
51
+ export function hasNewCollectionFields(newNftMetadata, nft) {
52
+ const keysNewNftMetadata = Object.keys(newNftMetadata.collection ?? {});
53
+ const keysExistingNft = new Set(Object.keys(nft.collection ?? {}));
54
+ return keysNewNftMetadata.some((key) => !keysExistingNft.has(key));
55
+ }
56
+ const aggregatorNameByKey = {
57
+ aave: 'Aave',
58
+ bancor: 'Bancor',
59
+ cmc: 'CMC',
60
+ cryptocom: 'Crypto.com',
61
+ coinGecko: 'CoinGecko',
62
+ oneInch: '1inch',
63
+ paraswap: 'Paraswap',
64
+ pmm: 'PMM',
65
+ zapper: 'Zapper',
66
+ zerion: 'Zerion',
67
+ zeroEx: '0x',
68
+ synthetix: 'Synthetix',
69
+ yearn: 'Yearn',
70
+ apeswap: 'ApeSwap',
71
+ binanceDex: 'BinanceDex',
72
+ pancakeTop100: 'PancakeTop100',
73
+ pancakeExtended: 'PancakeExtended',
74
+ balancer: 'Balancer',
75
+ quickswap: 'QuickSwap',
76
+ matcha: 'Matcha',
77
+ pangolinDex: 'PangolinDex',
78
+ pangolinDexStableCoin: 'PangolinDexStableCoin',
79
+ pangolinDexAvaxBridge: 'PangolinDexAvaxBridge',
80
+ traderJoe: 'TraderJoe',
81
+ airswapLight: 'AirswapLight',
82
+ kleros: 'Kleros',
37
83
  };
84
+ /**
85
+ * Formats aggregator names to presentable format.
86
+ *
87
+ * @param aggregators - List of token list names in camelcase.
88
+ * @returns Formatted aggregator names.
89
+ */
90
+ export const formatAggregatorNames = (aggregators) => {
91
+ return aggregators.map((key) => aggregatorNameByKey[key] ||
92
+ `${key[0].toUpperCase()}${key.substring(1, key.length)}`);
93
+ };
94
+ /**
95
+ * Format token list assets to use image proxy from Codefi.
96
+ *
97
+ * @param params - Object that contains chainID and tokenAddress.
98
+ * @param params.chainId - ChainID of network in 0x-prefixed hexadecimal format.
99
+ * @param params.tokenAddress - Address of token in mixed or lowercase.
100
+ * @returns Formatted image url
101
+ */
102
+ export const formatIconUrlWithProxy = ({ chainId, tokenAddress, }) => {
103
+ const chainIdDecimal = convertHexToDecimal(chainId).toString();
104
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
105
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
106
+ return `https://static.cx.metamask.io/api/v1/tokenIcons/${chainIdDecimal}/${tokenAddress.toLowerCase()}.png`;
107
+ };
108
+ /**
109
+ * Networks where token detection is supported - Values are in hex format
110
+ */
111
+ export var SupportedTokenDetectionNetworks;
112
+ (function (SupportedTokenDetectionNetworks) {
113
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
114
+ // eslint-disable-next-line @typescript-eslint/naming-convention
115
+ SupportedTokenDetectionNetworks["mainnet"] = "0x1";
116
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
117
+ // eslint-disable-next-line @typescript-eslint/naming-convention
118
+ SupportedTokenDetectionNetworks["bsc"] = "0x38";
119
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
120
+ // eslint-disable-next-line @typescript-eslint/naming-convention
121
+ SupportedTokenDetectionNetworks["polygon"] = "0x89";
122
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
123
+ // eslint-disable-next-line @typescript-eslint/naming-convention
124
+ SupportedTokenDetectionNetworks["avax"] = "0xa86a";
125
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
126
+ // eslint-disable-next-line @typescript-eslint/naming-convention
127
+ SupportedTokenDetectionNetworks["aurora"] = "0x4e454152";
128
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
129
+ // eslint-disable-next-line @typescript-eslint/naming-convention
130
+ SupportedTokenDetectionNetworks["linea_goerli"] = "0xe704";
131
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
132
+ // eslint-disable-next-line @typescript-eslint/naming-convention
133
+ SupportedTokenDetectionNetworks["linea_mainnet"] = "0xe708";
134
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
135
+ // eslint-disable-next-line @typescript-eslint/naming-convention
136
+ SupportedTokenDetectionNetworks["arbitrum"] = "0xa4b1";
137
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
138
+ // eslint-disable-next-line @typescript-eslint/naming-convention
139
+ SupportedTokenDetectionNetworks["optimism"] = "0xa";
140
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
141
+ // eslint-disable-next-line @typescript-eslint/naming-convention
142
+ SupportedTokenDetectionNetworks["base"] = "0x2105";
143
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
144
+ // eslint-disable-next-line @typescript-eslint/naming-convention
145
+ SupportedTokenDetectionNetworks["zksync"] = "0x144";
146
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
147
+ // eslint-disable-next-line @typescript-eslint/naming-convention
148
+ SupportedTokenDetectionNetworks["cronos"] = "0x19";
149
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
150
+ // eslint-disable-next-line @typescript-eslint/naming-convention
151
+ SupportedTokenDetectionNetworks["celo"] = "0xa4ec";
152
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
153
+ // eslint-disable-next-line @typescript-eslint/naming-convention
154
+ SupportedTokenDetectionNetworks["gnosis"] = "0x64";
155
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
156
+ // eslint-disable-next-line @typescript-eslint/naming-convention
157
+ SupportedTokenDetectionNetworks["fantom"] = "0xfa";
158
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
159
+ // eslint-disable-next-line @typescript-eslint/naming-convention
160
+ SupportedTokenDetectionNetworks["polygon_zkevm"] = "0x44d";
161
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
162
+ // eslint-disable-next-line @typescript-eslint/naming-convention
163
+ SupportedTokenDetectionNetworks["moonbeam"] = "0x504";
164
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
165
+ // eslint-disable-next-line @typescript-eslint/naming-convention
166
+ SupportedTokenDetectionNetworks["moonriver"] = "0x505";
167
+ })(SupportedTokenDetectionNetworks || (SupportedTokenDetectionNetworks = {}));
168
+ /**
169
+ * Check if token detection is enabled for certain networks.
170
+ *
171
+ * @param chainId - ChainID of network
172
+ * @returns Whether the current network supports token detection
173
+ */
174
+ export function isTokenDetectionSupportedForNetwork(chainId) {
175
+ return Object.values(SupportedTokenDetectionNetworks).includes(chainId);
176
+ }
177
+ /**
178
+ * Check if token list polling is enabled for a given network.
179
+ * Currently this method is used to support e2e testing for consumers of this package.
180
+ *
181
+ * @param chainId - ChainID of network
182
+ * @returns Whether the current network supports tokenlists
183
+ */
184
+ export function isTokenListSupportedForNetwork(chainId) {
185
+ return isTokenDetectionSupportedForNetwork(chainId);
186
+ }
187
+ /**
188
+ * Removes IPFS protocol prefix from input string.
189
+ *
190
+ * @param ipfsUrl - An IPFS url (e.g. ipfs://{content id})
191
+ * @returns IPFS content identifier and (possibly) path in a string
192
+ * @throws Will throw if the url passed is not IPFS.
193
+ */
194
+ export function removeIpfsProtocolPrefix(ipfsUrl) {
195
+ if (ipfsUrl.startsWith('ipfs://ipfs/')) {
196
+ return ipfsUrl.replace('ipfs://ipfs/', '');
197
+ }
198
+ else if (ipfsUrl.startsWith('ipfs://')) {
199
+ return ipfsUrl.replace('ipfs://', '');
200
+ }
201
+ // this method should not be used with non-ipfs urls (i.e. startsWith('ipfs://') === true)
202
+ throw new Error('this method should not be used with non ipfs urls');
203
+ }
204
+ /**
205
+ * Extracts content identifier and path from an input string.
206
+ *
207
+ * @param ipfsUrl - An IPFS URL minus the IPFS protocol prefix
208
+ * @returns IFPS content identifier (cid) and sub path as string.
209
+ * @throws Will throw if the url passed is not ipfs.
210
+ */
211
+ export async function getIpfsCIDv1AndPath(ipfsUrl) {
212
+ const url = removeIpfsProtocolPrefix(ipfsUrl);
213
+ // check if there is a path
214
+ // (CID is everything preceding first forward slash, path is everything after)
215
+ const index = url.indexOf('/');
216
+ const cid = index !== -1 ? url.substring(0, index) : url;
217
+ const path = index !== -1 ? url.substring(index) : undefined;
218
+ const { CID } = await import("multiformats");
219
+ // We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)
220
+ // because most cid v0s appear to be incompatible with IPFS subdomains
221
+ return {
222
+ cid: CID.parse(cid).toV1().toString(),
223
+ path,
224
+ };
225
+ }
226
+ /**
227
+ * Formats URL correctly for use retrieving assets hosted on IPFS.
228
+ *
229
+ * @param ipfsGateway - The users preferred IPFS gateway (full URL or just host).
230
+ * @param ipfsUrl - The IFPS URL pointed at the asset.
231
+ * @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.
232
+ * @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.
233
+ */
234
+ export async function getFormattedIpfsUrl(ipfsGateway, ipfsUrl, subdomainSupported) {
235
+ const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));
236
+ if (subdomainSupported) {
237
+ const { cid, path } = await getIpfsCIDv1AndPath(ipfsUrl);
238
+ return `${protocol}//${cid}.ipfs.${host}${path ?? ''}`;
239
+ }
240
+ const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);
241
+ return `${origin}/ipfs/${cidAndPath}`;
242
+ }
243
+ /**
244
+ * Adds URL protocol prefix to input URL string if missing.
245
+ *
246
+ * @param urlString - An IPFS URL.
247
+ * @returns A URL with a https:// prepended.
248
+ */
249
+ export function addUrlProtocolPrefix(urlString) {
250
+ if (!urlString.match(/(^http:\/\/)|(^https:\/\/)/u)) {
251
+ return `https://${urlString}`;
252
+ }
253
+ return urlString;
254
+ }
255
+ /**
256
+ * Converts an Ethers BigNumber to a BN.
257
+ *
258
+ * @param bigNumber - An Ethers BigNumber instance.
259
+ * @returns A BN object.
260
+ */
261
+ export function ethersBigNumberToBN(bigNumber) {
262
+ return new BN(remove0x(bigNumber.toHexString()), 'hex');
263
+ }
264
+ /**
265
+ * Partitions a list of values into groups that are at most `batchSize` in
266
+ * length.
267
+ *
268
+ * @param values - The list of values.
269
+ * @param args - The remaining arguments.
270
+ * @param args.batchSize - The desired maximum number of values per batch.
271
+ * @returns The list of batches.
272
+ */
273
+ export function divideIntoBatches(values, { batchSize }) {
274
+ const batches = [];
275
+ for (let i = 0; i < values.length; i += batchSize) {
276
+ batches.push(values.slice(i, i + batchSize));
277
+ }
278
+ return batches;
279
+ }
280
+ /**
281
+ * Constructs an object from processing batches of the given values
282
+ * sequentially.
283
+ *
284
+ * @param args - The arguments to this function.
285
+ * @param args.values - A list of values to iterate over.
286
+ * @param args.batchSize - The maximum number of values in each batch.
287
+ * @param args.eachBatch - A function to call for each batch. This function is
288
+ * similar to the function that `Array.prototype.reduce` takes, in that it
289
+ * receives the object that is being built, each batch in the list of batches
290
+ * and the index, and should return an updated version of the object.
291
+ * @param args.initialResult - The initial value of the final data structure,
292
+ * i.e., the value that will be fed into the first call of `eachBatch`.
293
+ * @returns The built object.
294
+ */
295
+ export async function reduceInBatchesSerially({ values, batchSize, eachBatch, initialResult, }) {
296
+ const batches = divideIntoBatches(values, { batchSize });
297
+ let workingResult = initialResult;
298
+ for (const [index, batch] of batches.entries()) {
299
+ workingResult = await eachBatch(workingResult, batch, index);
300
+ }
301
+ // There's no way around this — we have to assume that in the end, the result
302
+ // matches the intended type.
303
+ const finalResult = workingResult;
304
+ return finalResult;
305
+ }
306
+ /**
307
+ * Retrieves token prices for a set of contract addresses in a specific currency and chainId.
308
+ *
309
+ * @param args - The arguments to function.
310
+ * @param args.tokenPricesService - An object in charge of retrieving token prices.
311
+ * @param args.nativeCurrency - The native currency to request price in.
312
+ * @param args.tokenAddresses - The list of contract addresses.
313
+ * @param args.chainId - The chainId of the tokens.
314
+ * @returns The prices for the requested tokens.
315
+ */
316
+ export async function fetchTokenContractExchangeRates({ tokenPricesService, nativeCurrency, tokenAddresses, chainId, }) {
317
+ const isChainIdSupported = tokenPricesService.validateChainIdSupported(chainId);
318
+ const isCurrencySupported = tokenPricesService.validateCurrencySupported(nativeCurrency);
319
+ if (!isChainIdSupported || !isCurrencySupported) {
320
+ return {};
321
+ }
322
+ const tokenPricesByTokenAddress = await reduceInBatchesSerially({
323
+ values: [...tokenAddresses].sort(),
324
+ batchSize: TOKEN_PRICES_BATCH_SIZE,
325
+ eachBatch: async (allTokenPricesByTokenAddress, batch) => {
326
+ const tokenPricesByTokenAddressForBatch = await tokenPricesService.fetchTokenPrices({
327
+ tokenAddresses: batch,
328
+ chainId,
329
+ currency: nativeCurrency,
330
+ });
331
+ return {
332
+ ...allTokenPricesByTokenAddress,
333
+ ...tokenPricesByTokenAddressForBatch,
334
+ };
335
+ },
336
+ initialResult: {},
337
+ });
338
+ return Object.entries(tokenPricesByTokenAddress).reduce((obj, [tokenAddress, tokenPrice]) => {
339
+ return {
340
+ ...obj,
341
+ [toChecksumHexAddress(tokenAddress)]: tokenPrice?.price,
342
+ };
343
+ }, {});
344
+ }
38
345
  //# sourceMappingURL=assetsUtil.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"assetsUtil.mjs","sourceRoot":"","sources":["../src/assetsUtil.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACrB,mCAAmC;AAEpC,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAC3C,OAAO,GAAE,cAAc;;AAMvB;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,cAA2B,EAAE,GAAQ;IACtE,MAAM,IAAI,GAA0B;QAClC,OAAO;QACP,iBAAiB;QACjB,cAAc;QACd,gBAAgB;QAChB,eAAe;QACf,WAAW;QACX,mBAAmB;QACnB,cAAc;QACd,UAAU;KACX,CAAC;IACF,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACjD,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,cAAc,CAAC,GAAG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ACd,OAAO,GAMR;IACC,MAAM,kBAAkB,GACtB,kBAAkB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,mBAAmB,GACvB,kBAAkB,CAAC,yBAAyB,CAAC,cAAc,CAAC,CAAC;IAE/D,IAAI,CAAC,kBAAkB,IAAI,CAAC,mBAAmB,EAAE;QAC/C,OAAO,EAAE,CAAC;KACX;IAED,MAAM,yBAAyB,GAAG,MAAM,uBAAuB,CAG7D;QACA,MAAM,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,IAAI,EAAE;QAClC,SAAS,EAAE,uBAAuB;QAClC,SAAS,EAAE,KAAK,EAAE,4BAA4B,EAAE,KAAK,EAAE,EAAE;YACvD,MAAM,iCAAiC,GACrC,MAAM,kBAAkB,CAAC,gBAAgB,CAAC;gBACxC,cAAc,EAAE,KAAK;gBACrB,OAAO;gBACP,QAAQ,EAAE,cAAc;aACzB,CAAC,CAAC;YAEL,OAAO;gBACL,GAAG,4BAA4B;gBAC/B,GAAG,iCAAiC;aACrC,CAAC;QACJ,CAAC;QACD,aAAa,EAAE,EAAE;KAClB,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC,MAAM,CACrD,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,GAAG;YACN,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK;SACxD,CAAC;IACJ,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport {\n convertHexToDecimal,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport type { Nft, NftMetadata } from './NftController';\nimport type { AbstractTokenPricesService } from './token-prices-service';\nimport { type ContractExchangeRates } from './TokenRatesController';\n\n/**\n * The maximum number of token addresses that should be sent to the Price API in\n * a single request.\n */\nexport const TOKEN_PRICES_BATCH_SIZE = 30;\n\n/**\n * Compares nft metadata entries to any nft entry.\n * We need this method when comparing a new fetched nft metadata, in case a entry changed to a defined value,\n * there's a need to update the nft in state.\n *\n * @param newNftMetadata - Nft metadata object.\n * @param nft - Nft object to compare with.\n * @returns Whether there are differences.\n */\nexport function compareNftMetadata(newNftMetadata: NftMetadata, nft: Nft) {\n const keys: (keyof NftMetadata)[] = [\n 'image',\n 'backgroundColor',\n 'imagePreview',\n 'imageThumbnail',\n 'imageOriginal',\n 'animation',\n 'animationOriginal',\n 'externalLink',\n 'tokenURI',\n ];\n const differentValues = keys.reduce((value, key) => {\n if (newNftMetadata[key] && newNftMetadata[key] !== nft[key]) {\n return value + 1;\n }\n return value;\n }, 0);\n return differentValues > 0;\n}\n\n/**\n * Checks whether the existing nft object has all the keys of the new incoming nft metadata object\n * @param newNftMetadata - New nft metadata object\n * @param nft - Existing nft object to compare with\n * @returns Whether the existing nft object has all the new keys from the new Nft metadata object\n */\nexport function hasNewCollectionFields(\n newNftMetadata: NftMetadata,\n nft: Nft,\n): boolean {\n const keysNewNftMetadata = Object.keys(newNftMetadata.collection ?? {});\n const keysExistingNft = new Set(Object.keys(nft.collection ?? {}));\n\n return keysNewNftMetadata.some((key) => !keysExistingNft.has(key));\n}\n\nconst aggregatorNameByKey: Record<string, string> = {\n aave: 'Aave',\n bancor: 'Bancor',\n cmc: 'CMC',\n cryptocom: 'Crypto.com',\n coinGecko: 'CoinGecko',\n oneInch: '1inch',\n paraswap: 'Paraswap',\n pmm: 'PMM',\n zapper: 'Zapper',\n zerion: 'Zerion',\n zeroEx: '0x',\n synthetix: 'Synthetix',\n yearn: 'Yearn',\n apeswap: 'ApeSwap',\n binanceDex: 'BinanceDex',\n pancakeTop100: 'PancakeTop100',\n pancakeExtended: 'PancakeExtended',\n balancer: 'Balancer',\n quickswap: 'QuickSwap',\n matcha: 'Matcha',\n pangolinDex: 'PangolinDex',\n pangolinDexStableCoin: 'PangolinDexStableCoin',\n pangolinDexAvaxBridge: 'PangolinDexAvaxBridge',\n traderJoe: 'TraderJoe',\n airswapLight: 'AirswapLight',\n kleros: 'Kleros',\n};\n\n/**\n * Formats aggregator names to presentable format.\n *\n * @param aggregators - List of token list names in camelcase.\n * @returns Formatted aggregator names.\n */\nexport const formatAggregatorNames = (aggregators: string[]) => {\n return aggregators.map(\n (key) =>\n aggregatorNameByKey[key] ||\n `${key[0].toUpperCase()}${key.substring(1, key.length)}`,\n );\n};\n\n/**\n * Format token list assets to use image proxy from Codefi.\n *\n * @param params - Object that contains chainID and tokenAddress.\n * @param params.chainId - ChainID of network in 0x-prefixed hexadecimal format.\n * @param params.tokenAddress - Address of token in mixed or lowercase.\n * @returns Formatted image url\n */\nexport const formatIconUrlWithProxy = ({\n chainId,\n tokenAddress,\n}: {\n chainId: Hex;\n tokenAddress: string;\n}) => {\n const chainIdDecimal = convertHexToDecimal(chainId).toString();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `https://static.cx.metamask.io/api/v1/tokenIcons/${chainIdDecimal}/${tokenAddress.toLowerCase()}.png`;\n};\n\n/**\n * Networks where token detection is supported - Values are in hex format\n */\nexport enum SupportedTokenDetectionNetworks {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n mainnet = '0x1', // decimal: 1\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n bsc = '0x38', // decimal: 56\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n polygon = '0x89', // decimal: 137\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n avax = '0xa86a', // decimal: 43114\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n aurora = '0x4e454152', // decimal: 1313161554\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n linea_goerli = '0xe704', // decimal: 59140\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n linea_mainnet = '0xe708', // decimal: 59144\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n arbitrum = '0xa4b1', // decimal: 42161\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n optimism = '0xa', // decimal: 10\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n base = '0x2105', // decimal: 8453\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n zksync = '0x144', // decimal: 324\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n cronos = '0x19', // decimal: 25\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n celo = '0xa4ec', // decimal: 42220\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n gnosis = '0x64', // decimal: 100\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n fantom = '0xfa', // decimal: 250\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n polygon_zkevm = '0x44d', // decimal: 1101\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n moonbeam = '0x504', // decimal: 1284\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n moonriver = '0x505', // decimal: 1285\n}\n\n/**\n * Check if token detection is enabled for certain networks.\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports token detection\n */\nexport function isTokenDetectionSupportedForNetwork(chainId: Hex): boolean {\n return Object.values<Hex>(SupportedTokenDetectionNetworks).includes(chainId);\n}\n\n/**\n * Check if token list polling is enabled for a given network.\n * Currently this method is used to support e2e testing for consumers of this package.\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports tokenlists\n */\nexport function isTokenListSupportedForNetwork(chainId: Hex): boolean {\n return isTokenDetectionSupportedForNetwork(chainId);\n}\n\n/**\n * Removes IPFS protocol prefix from input string.\n *\n * @param ipfsUrl - An IPFS url (e.g. ipfs://{content id})\n * @returns IPFS content identifier and (possibly) path in a string\n * @throws Will throw if the url passed is not IPFS.\n */\nexport function removeIpfsProtocolPrefix(ipfsUrl: string) {\n if (ipfsUrl.startsWith('ipfs://ipfs/')) {\n return ipfsUrl.replace('ipfs://ipfs/', '');\n } else if (ipfsUrl.startsWith('ipfs://')) {\n return ipfsUrl.replace('ipfs://', '');\n }\n // this method should not be used with non-ipfs urls (i.e. startsWith('ipfs://') === true)\n throw new Error('this method should not be used with non ipfs urls');\n}\n\n/**\n * Extracts content identifier and path from an input string.\n *\n * @param ipfsUrl - An IPFS URL minus the IPFS protocol prefix\n * @returns IFPS content identifier (cid) and sub path as string.\n * @throws Will throw if the url passed is not ipfs.\n */\nexport async function getIpfsCIDv1AndPath(ipfsUrl: string): Promise<{\n cid: string;\n path?: string;\n}> {\n const url = removeIpfsProtocolPrefix(ipfsUrl);\n\n // check if there is a path\n // (CID is everything preceding first forward slash, path is everything after)\n const index = url.indexOf('/');\n const cid = index !== -1 ? url.substring(0, index) : url;\n const path = index !== -1 ? url.substring(index) : undefined;\n\n const { CID } = await import('multiformats');\n // We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)\n // because most cid v0s appear to be incompatible with IPFS subdomains\n return {\n cid: CID.parse(cid).toV1().toString(),\n path,\n };\n}\n\n/**\n * Formats URL correctly for use retrieving assets hosted on IPFS.\n *\n * @param ipfsGateway - The users preferred IPFS gateway (full URL or just host).\n * @param ipfsUrl - The IFPS URL pointed at the asset.\n * @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.\n * @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.\n */\nexport async function getFormattedIpfsUrl(\n ipfsGateway: string,\n ipfsUrl: string,\n subdomainSupported: boolean,\n): Promise<string> {\n const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));\n if (subdomainSupported) {\n const { cid, path } = await getIpfsCIDv1AndPath(ipfsUrl);\n return `${protocol}//${cid}.ipfs.${host}${path ?? ''}`;\n }\n const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);\n return `${origin}/ipfs/${cidAndPath}`;\n}\n\n/**\n * Adds URL protocol prefix to input URL string if missing.\n *\n * @param urlString - An IPFS URL.\n * @returns A URL with a https:// prepended.\n */\nexport function addUrlProtocolPrefix(urlString: string): string {\n if (!urlString.match(/(^http:\\/\\/)|(^https:\\/\\/)/u)) {\n return `https://${urlString}`;\n }\n return urlString;\n}\n\n/**\n * Converts an Ethers BigNumber to a BN.\n *\n * @param bigNumber - An Ethers BigNumber instance.\n * @returns A BN object.\n */\nexport function ethersBigNumberToBN(bigNumber: BigNumber): BN {\n return new BN(remove0x(bigNumber.toHexString()), 'hex');\n}\n\n/**\n * Partitions a list of values into groups that are at most `batchSize` in\n * length.\n *\n * @param values - The list of values.\n * @param args - The remaining arguments.\n * @param args.batchSize - The desired maximum number of values per batch.\n * @returns The list of batches.\n */\nexport function divideIntoBatches<Value>(\n values: Value[],\n { batchSize }: { batchSize: number },\n): Value[][] {\n const batches = [];\n for (let i = 0; i < values.length; i += batchSize) {\n batches.push(values.slice(i, i + batchSize));\n }\n return batches;\n}\n\n/**\n * Constructs an object from processing batches of the given values\n * sequentially.\n *\n * @param args - The arguments to this function.\n * @param args.values - A list of values to iterate over.\n * @param args.batchSize - The maximum number of values in each batch.\n * @param args.eachBatch - A function to call for each batch. This function is\n * similar to the function that `Array.prototype.reduce` takes, in that it\n * receives the object that is being built, each batch in the list of batches\n * and the index, and should return an updated version of the object.\n * @param args.initialResult - The initial value of the final data structure,\n * i.e., the value that will be fed into the first call of `eachBatch`.\n * @returns The built object.\n */\nexport async function reduceInBatchesSerially<\n Value,\n Result extends Record<PropertyKey, unknown>,\n>({\n values,\n batchSize,\n eachBatch,\n initialResult,\n}: {\n values: Value[];\n batchSize: number;\n eachBatch: (\n workingResult: Partial<Result>,\n batch: Value[],\n index: number,\n ) => Partial<Result> | Promise<Partial<Result>>;\n initialResult: Partial<Result>;\n}): Promise<Result> {\n const batches = divideIntoBatches(values, { batchSize });\n let workingResult = initialResult;\n for (const [index, batch] of batches.entries()) {\n workingResult = await eachBatch(workingResult, batch, index);\n }\n // There's no way around this — we have to assume that in the end, the result\n // matches the intended type.\n const finalResult = workingResult as Result;\n return finalResult;\n}\n\n/**\n * Retrieves token prices for a set of contract addresses in a specific currency and chainId.\n *\n * @param args - The arguments to function.\n * @param args.tokenPricesService - An object in charge of retrieving token prices.\n * @param args.nativeCurrency - The native currency to request price in.\n * @param args.tokenAddresses - The list of contract addresses.\n * @param args.chainId - The chainId of the tokens.\n * @returns The prices for the requested tokens.\n */\nexport async function fetchTokenContractExchangeRates({\n tokenPricesService,\n nativeCurrency,\n tokenAddresses,\n chainId,\n}: {\n tokenPricesService: AbstractTokenPricesService;\n nativeCurrency: string;\n tokenAddresses: Hex[];\n chainId: Hex;\n}): Promise<ContractExchangeRates> {\n const isChainIdSupported =\n tokenPricesService.validateChainIdSupported(chainId);\n const isCurrencySupported =\n tokenPricesService.validateCurrencySupported(nativeCurrency);\n\n if (!isChainIdSupported || !isCurrencySupported) {\n return {};\n }\n\n const tokenPricesByTokenAddress = await reduceInBatchesSerially<\n Hex,\n Awaited<ReturnType<AbstractTokenPricesService['fetchTokenPrices']>>\n >({\n values: [...tokenAddresses].sort(),\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n eachBatch: async (allTokenPricesByTokenAddress, batch) => {\n const tokenPricesByTokenAddressForBatch =\n await tokenPricesService.fetchTokenPrices({\n tokenAddresses: batch,\n chainId,\n currency: nativeCurrency,\n });\n\n return {\n ...allTokenPricesByTokenAddress,\n ...tokenPricesByTokenAddressForBatch,\n };\n },\n initialResult: {},\n });\n\n return Object.entries(tokenPricesByTokenAddress).reduce(\n (obj, [tokenAddress, tokenPrice]) => {\n return {\n ...obj,\n [toChecksumHexAddress(tokenAddress)]: tokenPrice?.price,\n };\n },\n {},\n );\n}\n"]}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Source = void 0;
4
+ var Source;
5
+ (function (Source) {
6
+ Source["Custom"] = "custom";
7
+ Source["Dapp"] = "dapp";
8
+ Source["Detected"] = "detected";
9
+ })(Source || (exports.Source = Source = {}));
10
+ //# sourceMappingURL=constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAIX;AAJD,WAAY,MAAM;IAChB,2BAAiB,CAAA;IACjB,uBAAa,CAAA;IACb,+BAAqB,CAAA;AACvB,CAAC,EAJW,MAAM,sBAAN,MAAM,QAIjB","sourcesContent":["export enum Source {\n Custom = 'custom',\n Dapp = 'dapp',\n Detected = 'detected',\n}\n"]}
@@ -3,4 +3,4 @@ export declare enum Source {
3
3
  Dapp = "dapp",
4
4
  Detected = "detected"
5
5
  }
6
- //# sourceMappingURL=constants.d.ts.map
6
+ //# sourceMappingURL=constants.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,MAAM;IAChB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,QAAQ,aAAa;CACtB"}
@@ -0,0 +1,6 @@
1
+ export declare enum Source {
2
+ Custom = "custom",
3
+ Dapp = "dapp",
4
+ Detected = "detected"
5
+ }
6
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,MAAM;IAChB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,QAAQ,aAAa;CACtB"}