@metamask/assets-controllers 37.0.0 → 38.0.1

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 +50 -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} +10 -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} +5 -5
  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 +369 -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 +366 -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} +9 -9
  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} +10 -10
  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 +24 -18
  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-54JUUBXY.mjs +0 -813
  248. package/dist/chunk-54JUUBXY.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-ADJ3IFJH.js +0 -813
  254. package/dist/chunk-ADJ3IFJH.js.map +0 -1
  255. package/dist/chunk-AX522TDL.mjs +0 -85
  256. package/dist/chunk-AX522TDL.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-CN53OZAM.mjs +0 -428
  264. package/dist/chunk-CN53OZAM.mjs.map +0 -1
  265. package/dist/chunk-CP3HC7AQ.mjs +0 -12
  266. package/dist/chunk-CP3HC7AQ.mjs.map +0 -1
  267. package/dist/chunk-CUFSPB7T.mjs +0 -530
  268. package/dist/chunk-CUFSPB7T.mjs.map +0 -1
  269. package/dist/chunk-F6L3DFOZ.js +0 -204
  270. package/dist/chunk-F6L3DFOZ.js.map +0 -1
  271. package/dist/chunk-GHG3DOUK.js +0 -428
  272. package/dist/chunk-GHG3DOUK.js.map +0 -1
  273. package/dist/chunk-HJ5GXVDT.mjs +0 -157
  274. package/dist/chunk-HJ5GXVDT.mjs.map +0 -1
  275. package/dist/chunk-HVOIBGYN.js +0 -282
  276. package/dist/chunk-HVOIBGYN.js.map +0 -1
  277. package/dist/chunk-ISK2VSBB.js +0 -178
  278. package/dist/chunk-ISK2VSBB.js.map +0 -1
  279. package/dist/chunk-JCR4H6YL.js +0 -115
  280. package/dist/chunk-JCR4H6YL.js.map +0 -1
  281. package/dist/chunk-JJX7TMH5.mjs +0 -135
  282. package/dist/chunk-JJX7TMH5.mjs.map +0 -1
  283. package/dist/chunk-JTXPJ6TK.mjs +0 -68
  284. package/dist/chunk-JTXPJ6TK.mjs.map +0 -1
  285. package/dist/chunk-JYHAAA6W.mjs +0 -1
  286. package/dist/chunk-JYHAAA6W.mjs.map +0 -1
  287. package/dist/chunk-K7A3EOIM.js +0 -85
  288. package/dist/chunk-K7A3EOIM.js.map +0 -1
  289. package/dist/chunk-KPBNX6GP.mjs +0 -215
  290. package/dist/chunk-KPBNX6GP.mjs.map +0 -1
  291. package/dist/chunk-MZI3SDQN.js +0 -215
  292. package/dist/chunk-MZI3SDQN.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-SBWPU4VT.mjs +0 -204
  300. package/dist/chunk-SBWPU4VT.mjs.map +0 -1
  301. package/dist/chunk-SK2B36Q4.mjs +0 -1405
  302. package/dist/chunk-SK2B36Q4.mjs.map +0 -1
  303. package/dist/chunk-T5ZX5BV7.js +0 -157
  304. package/dist/chunk-T5ZX5BV7.js.map +0 -1
  305. package/dist/chunk-TFLYM4PY.mjs +0 -291
  306. package/dist/chunk-TFLYM4PY.mjs.map +0 -1
  307. package/dist/chunk-TTH3ES66.mjs +0 -1
  308. package/dist/chunk-TTH3ES66.mjs.map +0 -1
  309. package/dist/chunk-V6DNVROD.js +0 -348
  310. package/dist/chunk-V6DNVROD.js.map +0 -1
  311. package/dist/chunk-X2HRAVDO.js +0 -530
  312. package/dist/chunk-X2HRAVDO.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-XQO3EG4J.mjs +0 -348
  316. package/dist/chunk-XQO3EG4J.mjs.map +0 -1
  317. package/dist/chunk-XUI43LEZ.mjs +0 -30
  318. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  319. package/dist/chunk-YGGUAMHV.js +0 -135
  320. package/dist/chunk-YGGUAMHV.js.map +0 -1
  321. package/dist/chunk-Z4BLTVTB.js +0 -30
  322. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  323. package/dist/chunk-Z7RMCHD4.mjs +0 -282
  324. package/dist/chunk-Z7RMCHD4.mjs.map +0 -1
  325. package/dist/chunk-ZAR4BIOC.js +0 -291
  326. package/dist/chunk-ZAR4BIOC.js.map +0 -1
  327. package/dist/chunk-ZG5MS2TO.js +0 -68
  328. package/dist/chunk-ZG5MS2TO.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":"CurrencyRateController.cjs","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":";;;AAKA,iEAGoC;AAKpC,qEAA+E;AAC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E;YACd,IACE,CAAC,CACC,KAAK,YAAY,KAAK;gBACtB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,0CAA0C,CAAC,CACnE,EACD;gBACA,sDAAsD;gBACtD,iBAAiB,GAAG,KAAK,CAAC;gBAC1B,MAAM,KAAK,CAAC;aACb;SACF;gBAAS;YACR,IAAI;gBACF,IAAI,iBAAiB,EAAE;oBACrB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;wBACf,OAAO;4BACL,aAAa,EAAE;gCACb,GAAG,aAAa;gCAChB,CAAC,cAAc,CAAC,EAAE;oCAChB,cAAc;oCACd,cAAc;oCACd,iBAAiB;iCAClB;6BACF;4BACD,eAAe;yBAChB,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACJ;aACF;oBAAS;gBACR,WAAW,EAAE,CAAC;aACf;SACF;IACH,CAAC;IAED;;;;OAIG;IACM,OAAO;QACd,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,eAAgC;QACjD,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,wCAAwC,EACxC,eAAe,CAChB,CAAC;QACF,MAAM,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;CACF;AArKD,wDAqKC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport { Mutex } from 'async-mutex';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare-service';\n\n/**\n * @type CurrencyRateState\n * @property currencyRates - Object keyed by native currency\n * @property currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n * @property currencyRates.conversionRate - Conversion rate from current base asset to the current currency\n * @property currentCurrency - Currently-active ISO 4217 currency code\n * @property usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n currentCurrency: string;\n currencyRates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'CurrencyRateController';\n\nexport type CurrencyRateStateChange = ControllerStateChangeEvent<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerEvents = CurrencyRateStateChange;\n\nexport type GetCurrencyRateState = ControllerGetStateAction<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerActions = GetCurrencyRateState;\n\ntype AllowedActions = NetworkControllerGetNetworkClientByIdAction;\n\ntype CurrencyRateMessenger = RestrictedControllerMessenger<\n typeof name,\n CurrencyRateControllerActions | AllowedActions,\n CurrencyRateControllerEvents,\n AllowedActions['type'],\n never\n>;\n\nconst metadata = {\n currentCurrency: { persist: true, anonymous: true },\n currencyRates: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n currentCurrency: 'usd',\n currencyRates: {\n ETH: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\nexport class CurrencyRateController extends StaticIntervalPollingController<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly fetchExchangeRate;\n\n private readonly includeUsdRate;\n\n /**\n * Creates a CurrencyRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n includeUsdRate = false,\n interval = 180000,\n messenger,\n state,\n fetchExchangeRate = defaultFetchExchangeRate,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: CurrencyRateMessenger;\n state?: Partial<CurrencyRateState>;\n fetchExchangeRate?: typeof defaultFetchExchangeRate;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.includeUsdRate = includeUsdRate;\n this.setIntervalLength(interval);\n this.fetchExchangeRate = fetchExchangeRate;\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string) {\n const releaseLock = await this.mutex.acquire();\n const nativeCurrencies = Object.keys(this.state.currencyRates);\n try {\n this.update(() => {\n return {\n ...defaultState,\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n nativeCurrencies.forEach(this.updateExchangeRate.bind(this));\n }\n\n /**\n * Updates the exchange rate for the current currency and native currency pair.\n *\n * @param nativeCurrency - The ticker symbol for the chain.\n */\n async updateExchangeRate(nativeCurrency: string): Promise<void> {\n const releaseLock = await this.mutex.acquire();\n const { currentCurrency, currencyRates } = this.state;\n\n let conversionDate: number | null = null;\n let conversionRate: number | null = null;\n let usdConversionRate: number | null = null;\n\n // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.\n const nativeCurrencyForExchangeRate = Object.values(\n TESTNET_TICKER_SYMBOLS,\n ).includes(nativeCurrency)\n ? FALL_BACK_VS_CURRENCY // ETH\n : nativeCurrency;\n\n let shouldUpdateState = true;\n try {\n if (\n currentCurrency &&\n nativeCurrency &&\n // if either currency is an empty string we can skip the comparison\n // because it will result in an error from the api and ultimately\n // a null conversionRate either way.\n currentCurrency !== '' &&\n nativeCurrency !== ''\n ) {\n const fetchExchangeRateResponse = await this.fetchExchangeRate(\n currentCurrency,\n nativeCurrencyForExchangeRate,\n this.includeUsdRate,\n );\n conversionRate = fetchExchangeRateResponse.conversionRate;\n usdConversionRate = fetchExchangeRateResponse.usdConversionRate;\n conversionDate = Date.now() / 1000;\n }\n } catch (error) {\n if (\n !(\n error instanceof Error &&\n error.message.includes('market does not exist for this coin pair')\n )\n ) {\n // Don't update state on transient / unexpected errors\n shouldUpdateState = false;\n throw error;\n }\n } finally {\n try {\n if (shouldUpdateState) {\n this.update(() => {\n return {\n currencyRates: {\n ...currencyRates,\n [nativeCurrency]: {\n conversionDate,\n conversionRate,\n usdConversionRate,\n },\n },\n currentCurrency,\n };\n });\n }\n } finally {\n releaseLock();\n }\n }\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopAllPolling();\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @param networkClientId - The network client ID used to get a ticker value.\n * @returns The controller state.\n */\n async _executePoll(networkClientId: NetworkClientId): Promise<void> {\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n await this.updateExchangeRate(networkClient.configuration.ticker);\n }\n}\n\nexport default CurrencyRateController;\n"]}
@@ -1,7 +1,7 @@
1
- import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
2
- import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';
3
- import { StaticIntervalPollingController } from '@metamask/polling-controller';
4
- import { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare-service';
1
+ import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
3
+ import { StaticIntervalPollingController } from "@metamask/polling-controller";
4
+ import { fetchExchangeRate as defaultFetchExchangeRate } from "./crypto-compare-service/index.cjs";
5
5
  /**
6
6
  * @type CurrencyRateState
7
7
  * @property currencyRates - Object keyed by native currency
@@ -77,4 +77,4 @@ export declare class CurrencyRateController extends StaticIntervalPollingControl
77
77
  _executePoll(networkClientId: NetworkClientId): Promise<void>;
78
78
  }
79
79
  export default CurrencyRateController;
80
- //# sourceMappingURL=CurrencyRateController.d.ts.map
80
+ //# sourceMappingURL=CurrencyRateController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrencyRateController.d.cts","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAKnC,OAAO,KAAK,EACV,eAAe,EACf,2CAA2C,EAC5C,qCAAqC;AACtC,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAG/E,OAAO,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,2CAAiC;AAEzF;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CACnB,MAAM,EACN;QACE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;KAClC,CACF,CAAC;CACH,CAAC;AAEF,QAAA,MAAM,IAAI,2BAA2B,CAAC;AAEtC,MAAM,MAAM,uBAAuB,GAAG,0BAA0B,CAC9D,OAAO,IAAI,EACX,iBAAiB,CAClB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,uBAAuB,CAAC;AAEnE,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,CACzD,OAAO,IAAI,EACX,iBAAiB,CAClB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,oBAAoB,CAAC;AAEjE,KAAK,cAAc,GAAG,2CAA2C,CAAC;AAElE,KAAK,qBAAqB,GAAG,6BAA6B,CACxD,OAAO,IAAI,EACX,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,EAC5B,cAAc,CAAC,MAAM,CAAC,EACtB,KAAK,CACN,CAAC;AAkBF;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,+BAA+B,CACzE,OAAO,IAAI,EACX,iBAAiB,EACjB,qBAAqB,CACtB;IACC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IAErC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC;IAEnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAEhC;;;;;;;;;OASG;gBACS,EACV,cAAsB,EACtB,QAAiB,EACjB,SAAS,EACT,KAAK,EACL,iBAA4C,GAC7C,EAAE;QACD,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,qBAAqB,CAAC;QACjC,KAAK,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACnC,iBAAiB,CAAC,EAAE,OAAO,wBAAwB,CAAC;KACrD;IAYD;;;;OAIG;IACG,kBAAkB,CAAC,eAAe,EAAE,MAAM;IAkBhD;;;;OAIG;IACG,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqE/D;;;;OAIG;IACM,OAAO;IAKhB;;;;;OAKG;IACG,YAAY,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAOpE;AAED,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,80 @@
1
+ import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
3
+ import { StaticIntervalPollingController } from "@metamask/polling-controller";
4
+ import { fetchExchangeRate as defaultFetchExchangeRate } from "./crypto-compare-service/index.mjs";
5
+ /**
6
+ * @type CurrencyRateState
7
+ * @property currencyRates - Object keyed by native currency
8
+ * @property currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch
9
+ * @property currencyRates.conversionRate - Conversion rate from current base asset to the current currency
10
+ * @property currentCurrency - Currently-active ISO 4217 currency code
11
+ * @property usdConversionRate - Conversion rate from usd to the current currency
12
+ */
13
+ export type CurrencyRateState = {
14
+ currentCurrency: string;
15
+ currencyRates: Record<string, {
16
+ conversionDate: number | null;
17
+ conversionRate: number | null;
18
+ usdConversionRate: number | null;
19
+ }>;
20
+ };
21
+ declare const name = "CurrencyRateController";
22
+ export type CurrencyRateStateChange = ControllerStateChangeEvent<typeof name, CurrencyRateState>;
23
+ export type CurrencyRateControllerEvents = CurrencyRateStateChange;
24
+ export type GetCurrencyRateState = ControllerGetStateAction<typeof name, CurrencyRateState>;
25
+ export type CurrencyRateControllerActions = GetCurrencyRateState;
26
+ type AllowedActions = NetworkControllerGetNetworkClientByIdAction;
27
+ type CurrencyRateMessenger = RestrictedControllerMessenger<typeof name, CurrencyRateControllerActions | AllowedActions, CurrencyRateControllerEvents, AllowedActions['type'], never>;
28
+ /**
29
+ * Controller that passively polls on a set interval for an exchange rate from the current network
30
+ * asset to the user's preferred currency.
31
+ */
32
+ export declare class CurrencyRateController extends StaticIntervalPollingController<typeof name, CurrencyRateState, CurrencyRateMessenger> {
33
+ private readonly mutex;
34
+ private readonly fetchExchangeRate;
35
+ private readonly includeUsdRate;
36
+ /**
37
+ * Creates a CurrencyRateController instance.
38
+ *
39
+ * @param options - Constructor options.
40
+ * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.
41
+ * @param options.interval - The polling interval, in milliseconds.
42
+ * @param options.messenger - A reference to the messaging system.
43
+ * @param options.state - Initial state to set on this controller.
44
+ * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.
45
+ */
46
+ constructor({ includeUsdRate, interval, messenger, state, fetchExchangeRate, }: {
47
+ includeUsdRate?: boolean;
48
+ interval?: number;
49
+ messenger: CurrencyRateMessenger;
50
+ state?: Partial<CurrencyRateState>;
51
+ fetchExchangeRate?: typeof defaultFetchExchangeRate;
52
+ });
53
+ /**
54
+ * Sets a currency to track.
55
+ *
56
+ * @param currentCurrency - ISO 4217 currency code.
57
+ */
58
+ setCurrentCurrency(currentCurrency: string): Promise<void>;
59
+ /**
60
+ * Updates the exchange rate for the current currency and native currency pair.
61
+ *
62
+ * @param nativeCurrency - The ticker symbol for the chain.
63
+ */
64
+ updateExchangeRate(nativeCurrency: string): Promise<void>;
65
+ /**
66
+ * Prepare to discard this controller.
67
+ *
68
+ * This stops any active polling.
69
+ */
70
+ destroy(): void;
71
+ /**
72
+ * Updates exchange rate for the current currency.
73
+ *
74
+ * @param networkClientId - The network client ID used to get a ticker value.
75
+ * @returns The controller state.
76
+ */
77
+ _executePoll(networkClientId: NetworkClientId): Promise<void>;
78
+ }
79
+ export default CurrencyRateController;
80
+ //# sourceMappingURL=CurrencyRateController.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CurrencyRateController.d.mts","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAKnC,OAAO,KAAK,EACV,eAAe,EACf,2CAA2C,EAC5C,qCAAqC;AACtC,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAG/E,OAAO,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,2CAAiC;AAEzF;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CACnB,MAAM,EACN;QACE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAA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ACM,OAAO;IAKhB;;;;;OAKG;IACG,YAAY,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAOpE;AAED,eAAe,sBAAsB,CAAC"}
@@ -1,12 +1,152 @@
1
- import {
2
- CurrencyRateController,
3
- CurrencyRateController_default
4
- } from "./chunk-HJ5GXVDT.mjs";
5
- import "./chunk-TTH3ES66.mjs";
6
- import "./chunk-JTXPJ6TK.mjs";
7
- import "./chunk-XUI43LEZ.mjs";
8
- export {
9
- CurrencyRateController,
10
- CurrencyRateController_default as default
1
+ import { TESTNET_TICKER_SYMBOLS, FALL_BACK_VS_CURRENCY } from "@metamask/controller-utils";
2
+ import { StaticIntervalPollingController } from "@metamask/polling-controller";
3
+ import { Mutex } from "async-mutex";
4
+ import { fetchExchangeRate as defaultFetchExchangeRate } from "./crypto-compare-service/index.mjs";
5
+ const name = 'CurrencyRateController';
6
+ const metadata = {
7
+ currentCurrency: { persist: true, anonymous: true },
8
+ currencyRates: { persist: true, anonymous: true },
11
9
  };
10
+ const defaultState = {
11
+ currentCurrency: 'usd',
12
+ currencyRates: {
13
+ ETH: {
14
+ conversionDate: 0,
15
+ conversionRate: 0,
16
+ usdConversionRate: null,
17
+ },
18
+ },
19
+ };
20
+ /**
21
+ * Controller that passively polls on a set interval for an exchange rate from the current network
22
+ * asset to the user's preferred currency.
23
+ */
24
+ export class CurrencyRateController extends StaticIntervalPollingController {
25
+ /**
26
+ * Creates a CurrencyRateController instance.
27
+ *
28
+ * @param options - Constructor options.
29
+ * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.
30
+ * @param options.interval - The polling interval, in milliseconds.
31
+ * @param options.messenger - A reference to the messaging system.
32
+ * @param options.state - Initial state to set on this controller.
33
+ * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.
34
+ */
35
+ constructor({ includeUsdRate = false, interval = 180000, messenger, state, fetchExchangeRate = defaultFetchExchangeRate, }) {
36
+ super({
37
+ name,
38
+ metadata,
39
+ messenger,
40
+ state: { ...defaultState, ...state },
41
+ });
42
+ this.mutex = new Mutex();
43
+ this.includeUsdRate = includeUsdRate;
44
+ this.setIntervalLength(interval);
45
+ this.fetchExchangeRate = fetchExchangeRate;
46
+ }
47
+ /**
48
+ * Sets a currency to track.
49
+ *
50
+ * @param currentCurrency - ISO 4217 currency code.
51
+ */
52
+ async setCurrentCurrency(currentCurrency) {
53
+ const releaseLock = await this.mutex.acquire();
54
+ const nativeCurrencies = Object.keys(this.state.currencyRates);
55
+ try {
56
+ this.update(() => {
57
+ return {
58
+ ...defaultState,
59
+ currentCurrency,
60
+ };
61
+ });
62
+ }
63
+ finally {
64
+ releaseLock();
65
+ }
66
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
67
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
68
+ nativeCurrencies.forEach(this.updateExchangeRate.bind(this));
69
+ }
70
+ /**
71
+ * Updates the exchange rate for the current currency and native currency pair.
72
+ *
73
+ * @param nativeCurrency - The ticker symbol for the chain.
74
+ */
75
+ async updateExchangeRate(nativeCurrency) {
76
+ const releaseLock = await this.mutex.acquire();
77
+ const { currentCurrency, currencyRates } = this.state;
78
+ let conversionDate = null;
79
+ let conversionRate = null;
80
+ let usdConversionRate = null;
81
+ // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.
82
+ const nativeCurrencyForExchangeRate = Object.values(TESTNET_TICKER_SYMBOLS).includes(nativeCurrency)
83
+ ? FALL_BACK_VS_CURRENCY // ETH
84
+ : nativeCurrency;
85
+ let shouldUpdateState = true;
86
+ try {
87
+ if (currentCurrency &&
88
+ nativeCurrency &&
89
+ // if either currency is an empty string we can skip the comparison
90
+ // because it will result in an error from the api and ultimately
91
+ // a null conversionRate either way.
92
+ currentCurrency !== '' &&
93
+ nativeCurrency !== '') {
94
+ const fetchExchangeRateResponse = await this.fetchExchangeRate(currentCurrency, nativeCurrencyForExchangeRate, this.includeUsdRate);
95
+ conversionRate = fetchExchangeRateResponse.conversionRate;
96
+ usdConversionRate = fetchExchangeRateResponse.usdConversionRate;
97
+ conversionDate = Date.now() / 1000;
98
+ }
99
+ }
100
+ catch (error) {
101
+ if (!(error instanceof Error &&
102
+ error.message.includes('market does not exist for this coin pair'))) {
103
+ // Don't update state on transient / unexpected errors
104
+ shouldUpdateState = false;
105
+ throw error;
106
+ }
107
+ }
108
+ finally {
109
+ try {
110
+ if (shouldUpdateState) {
111
+ this.update(() => {
112
+ return {
113
+ currencyRates: {
114
+ ...currencyRates,
115
+ [nativeCurrency]: {
116
+ conversionDate,
117
+ conversionRate,
118
+ usdConversionRate,
119
+ },
120
+ },
121
+ currentCurrency,
122
+ };
123
+ });
124
+ }
125
+ }
126
+ finally {
127
+ releaseLock();
128
+ }
129
+ }
130
+ }
131
+ /**
132
+ * Prepare to discard this controller.
133
+ *
134
+ * This stops any active polling.
135
+ */
136
+ destroy() {
137
+ super.destroy();
138
+ this.stopAllPolling();
139
+ }
140
+ /**
141
+ * Updates exchange rate for the current currency.
142
+ *
143
+ * @param networkClientId - The network client ID used to get a ticker value.
144
+ * @returns The controller state.
145
+ */
146
+ async _executePoll(networkClientId) {
147
+ const networkClient = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId);
148
+ await this.updateExchangeRate(networkClient.configuration.ticker);
149
+ }
150
+ }
151
+ export default CurrencyRateController;
12
152
  //# sourceMappingURL=CurrencyRateController.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"CurrencyRateController.mjs","sourceRoot":"","sources":["../src/CurrencyRateController.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACtB,mCAAmC;AAKpC,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAC/E,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAEpC,OAAO,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,2CAAiC;AAsBzF,MA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,KAAK;gBACtB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,0CAA0C,CAAC,CACnE,EACD;gBACA,sDAAsD;gBACtD,iBAAiB,GAAG,KAAK,CAAC;gBAC1B,MAAM,KAAK,CAAC;aACb;SACF;gBAAS;YACR,IAAI;gBACF,IAAI,iBAAiB,EAAE;oBACrB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;wBACf,OAAO;4BACL,aAAa,EAAE;gCACb,GAAG,aAAa;gCAChB,CAAC,cAAc,CAAC,EAAE;oCAChB,cAAc;oCACd,cAAc;oCACd,iBAAiB;iCAClB;6BACF;4BACD,eAAe;yBAChB,CAAC;oBACJ,CAAC,CAAC,CAAC;iBACJ;aACF;oBAAS;gBACR,WAAW,EAAE,CAAC;aACf;SACF;IACH,CAAC;IAED;;;;OAIG;IACM,OAAO;QACd,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,eAAgC;QACjD,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,wCAAwC,EACxC,eAAe,CAChB,CAAC;QACF,MAAM,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport {\n TESTNET_TICKER_SYMBOLS,\n FALL_BACK_VS_CURRENCY,\n} from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport { Mutex } from 'async-mutex';\n\nimport { fetchExchangeRate as defaultFetchExchangeRate } from './crypto-compare-service';\n\n/**\n * @type CurrencyRateState\n * @property currencyRates - Object keyed by native currency\n * @property currencyRates.conversionDate - Timestamp of conversion rate expressed in ms since UNIX epoch\n * @property currencyRates.conversionRate - Conversion rate from current base asset to the current currency\n * @property currentCurrency - Currently-active ISO 4217 currency code\n * @property usdConversionRate - Conversion rate from usd to the current currency\n */\nexport type CurrencyRateState = {\n currentCurrency: string;\n currencyRates: Record<\n string,\n {\n conversionDate: number | null;\n conversionRate: number | null;\n usdConversionRate: number | null;\n }\n >;\n};\n\nconst name = 'CurrencyRateController';\n\nexport type CurrencyRateStateChange = ControllerStateChangeEvent<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerEvents = CurrencyRateStateChange;\n\nexport type GetCurrencyRateState = ControllerGetStateAction<\n typeof name,\n CurrencyRateState\n>;\n\nexport type CurrencyRateControllerActions = GetCurrencyRateState;\n\ntype AllowedActions = NetworkControllerGetNetworkClientByIdAction;\n\ntype CurrencyRateMessenger = RestrictedControllerMessenger<\n typeof name,\n CurrencyRateControllerActions | AllowedActions,\n CurrencyRateControllerEvents,\n AllowedActions['type'],\n never\n>;\n\nconst metadata = {\n currentCurrency: { persist: true, anonymous: true },\n currencyRates: { persist: true, anonymous: true },\n};\n\nconst defaultState = {\n currentCurrency: 'usd',\n currencyRates: {\n ETH: {\n conversionDate: 0,\n conversionRate: 0,\n usdConversionRate: null,\n },\n },\n};\n\n/**\n * Controller that passively polls on a set interval for an exchange rate from the current network\n * asset to the user's preferred currency.\n */\nexport class CurrencyRateController extends StaticIntervalPollingController<\n typeof name,\n CurrencyRateState,\n CurrencyRateMessenger\n> {\n private readonly mutex = new Mutex();\n\n private readonly fetchExchangeRate;\n\n private readonly includeUsdRate;\n\n /**\n * Creates a CurrencyRateController instance.\n *\n * @param options - Constructor options.\n * @param options.includeUsdRate - Keep track of the USD rate in addition to the current currency rate.\n * @param options.interval - The polling interval, in milliseconds.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.fetchExchangeRate - Fetches the exchange rate from an external API. This option is primarily meant for use in unit tests.\n */\n constructor({\n includeUsdRate = false,\n interval = 180000,\n messenger,\n state,\n fetchExchangeRate = defaultFetchExchangeRate,\n }: {\n includeUsdRate?: boolean;\n interval?: number;\n messenger: CurrencyRateMessenger;\n state?: Partial<CurrencyRateState>;\n fetchExchangeRate?: typeof defaultFetchExchangeRate;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: { ...defaultState, ...state },\n });\n this.includeUsdRate = includeUsdRate;\n this.setIntervalLength(interval);\n this.fetchExchangeRate = fetchExchangeRate;\n }\n\n /**\n * Sets a currency to track.\n *\n * @param currentCurrency - ISO 4217 currency code.\n */\n async setCurrentCurrency(currentCurrency: string) {\n const releaseLock = await this.mutex.acquire();\n const nativeCurrencies = Object.keys(this.state.currencyRates);\n try {\n this.update(() => {\n return {\n ...defaultState,\n currentCurrency,\n };\n });\n } finally {\n releaseLock();\n }\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n nativeCurrencies.forEach(this.updateExchangeRate.bind(this));\n }\n\n /**\n * Updates the exchange rate for the current currency and native currency pair.\n *\n * @param nativeCurrency - The ticker symbol for the chain.\n */\n async updateExchangeRate(nativeCurrency: string): Promise<void> {\n const releaseLock = await this.mutex.acquire();\n const { currentCurrency, currencyRates } = this.state;\n\n let conversionDate: number | null = null;\n let conversionRate: number | null = null;\n let usdConversionRate: number | null = null;\n\n // For preloaded testnets (Goerli, Sepolia) we want to fetch exchange rate for real ETH.\n const nativeCurrencyForExchangeRate = Object.values(\n TESTNET_TICKER_SYMBOLS,\n ).includes(nativeCurrency)\n ? FALL_BACK_VS_CURRENCY // ETH\n : nativeCurrency;\n\n let shouldUpdateState = true;\n try {\n if (\n currentCurrency &&\n nativeCurrency &&\n // if either currency is an empty string we can skip the comparison\n // because it will result in an error from the api and ultimately\n // a null conversionRate either way.\n currentCurrency !== '' &&\n nativeCurrency !== ''\n ) {\n const fetchExchangeRateResponse = await this.fetchExchangeRate(\n currentCurrency,\n nativeCurrencyForExchangeRate,\n this.includeUsdRate,\n );\n conversionRate = fetchExchangeRateResponse.conversionRate;\n usdConversionRate = fetchExchangeRateResponse.usdConversionRate;\n conversionDate = Date.now() / 1000;\n }\n } catch (error) {\n if (\n !(\n error instanceof Error &&\n error.message.includes('market does not exist for this coin pair')\n )\n ) {\n // Don't update state on transient / unexpected errors\n shouldUpdateState = false;\n throw error;\n }\n } finally {\n try {\n if (shouldUpdateState) {\n this.update(() => {\n return {\n currencyRates: {\n ...currencyRates,\n [nativeCurrency]: {\n conversionDate,\n conversionRate,\n usdConversionRate,\n },\n },\n currentCurrency,\n };\n });\n }\n } finally {\n releaseLock();\n }\n }\n }\n\n /**\n * Prepare to discard this controller.\n *\n * This stops any active polling.\n */\n override destroy() {\n super.destroy();\n this.stopAllPolling();\n }\n\n /**\n * Updates exchange rate for the current currency.\n *\n * @param networkClientId - The network client ID used to get a ticker value.\n * @returns The controller state.\n */\n async _executePoll(networkClientId: NetworkClientId): Promise<void> {\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n await this.updateExchangeRate(networkClient.configuration.ticker);\n }\n}\n\nexport default CurrencyRateController;\n"]}