@metamask/transaction-controller 24.0.0 → 25.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 (288) hide show
  1. package/CHANGELOG.md +129 -1
  2. package/dist/TransactionController.js +39 -1816
  3. package/dist/TransactionController.js.map +1 -1
  4. package/dist/TransactionController.mjs +40 -0
  5. package/dist/TransactionController.mjs.map +1 -0
  6. package/dist/chunk-2YXA3K67.mjs +62 -0
  7. package/dist/chunk-2YXA3K67.mjs.map +1 -0
  8. package/dist/chunk-3D3SA6PY.mjs +211 -0
  9. package/dist/chunk-3D3SA6PY.mjs.map +1 -0
  10. package/dist/chunk-4S25HUCL.js +46 -0
  11. package/dist/chunk-4S25HUCL.js.map +1 -0
  12. package/dist/chunk-5OQ373JS.js +211 -0
  13. package/dist/chunk-5OQ373JS.js.map +1 -0
  14. package/dist/chunk-5XBULBP2.js +399 -0
  15. package/dist/chunk-5XBULBP2.js.map +1 -0
  16. package/dist/chunk-72OTU5ZW.mjs +2332 -0
  17. package/dist/chunk-72OTU5ZW.mjs.map +1 -0
  18. package/dist/chunk-7LXE4KHV.js +40 -0
  19. package/dist/chunk-7LXE4KHV.js.map +1 -0
  20. package/dist/chunk-7XPI7KU5.mjs +46 -0
  21. package/dist/chunk-7XPI7KU5.mjs.map +1 -0
  22. package/dist/chunk-BILEZLAT.js +182 -0
  23. package/dist/chunk-BILEZLAT.js.map +1 -0
  24. package/dist/chunk-CQBXHAYR.js +121 -0
  25. package/dist/chunk-CQBXHAYR.js.map +1 -0
  26. package/dist/chunk-CXXGL43K.js +85 -0
  27. package/dist/chunk-CXXGL43K.js.map +1 -0
  28. package/dist/chunk-DTDTOMTB.js +238 -0
  29. package/dist/chunk-DTDTOMTB.js.map +1 -0
  30. package/dist/chunk-DTONMSFW.mjs +208 -0
  31. package/dist/chunk-DTONMSFW.mjs.map +1 -0
  32. package/dist/chunk-EEMJC7S7.mjs +182 -0
  33. package/dist/chunk-EEMJC7S7.mjs.map +1 -0
  34. package/dist/chunk-F3CMU2DM.js +170 -0
  35. package/dist/chunk-F3CMU2DM.js.map +1 -0
  36. package/dist/chunk-FRKQ3Z2L.mjs +40 -0
  37. package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
  38. package/dist/chunk-HS277C77.js +75 -0
  39. package/dist/chunk-HS277C77.js.map +1 -0
  40. package/dist/chunk-ITDY6AIZ.js +127 -0
  41. package/dist/chunk-ITDY6AIZ.js.map +1 -0
  42. package/dist/chunk-IZI7FQIN.mjs +170 -0
  43. package/dist/chunk-IZI7FQIN.mjs.map +1 -0
  44. package/dist/chunk-J56A7UCK.mjs +123 -0
  45. package/dist/chunk-J56A7UCK.mjs.map +1 -0
  46. package/dist/chunk-JRBREX22.mjs +75 -0
  47. package/dist/chunk-JRBREX22.mjs.map +1 -0
  48. package/dist/chunk-JRQHIBG5.mjs +399 -0
  49. package/dist/chunk-JRQHIBG5.mjs.map +1 -0
  50. package/dist/chunk-K26EBMGI.mjs +121 -0
  51. package/dist/chunk-K26EBMGI.mjs.map +1 -0
  52. package/dist/chunk-KFL2GGZC.mjs +48 -0
  53. package/dist/chunk-KFL2GGZC.mjs.map +1 -0
  54. package/dist/chunk-NHRBO3LU.mjs +50 -0
  55. package/dist/chunk-NHRBO3LU.mjs.map +1 -0
  56. package/dist/chunk-NM4LTWRU.mjs +76 -0
  57. package/dist/chunk-NM4LTWRU.mjs.map +1 -0
  58. package/dist/chunk-NM6OYEPP.mjs +182 -0
  59. package/dist/chunk-NM6OYEPP.mjs.map +1 -0
  60. package/dist/chunk-NRWEI43Q.js +320 -0
  61. package/dist/chunk-NRWEI43Q.js.map +1 -0
  62. package/dist/chunk-O7H2MC7R.js +62 -0
  63. package/dist/chunk-O7H2MC7R.js.map +1 -0
  64. package/dist/chunk-OF6NSLXF.mjs +90 -0
  65. package/dist/chunk-OF6NSLXF.mjs.map +1 -0
  66. package/dist/chunk-QDIYZX5V.js +2332 -0
  67. package/dist/chunk-QDIYZX5V.js.map +1 -0
  68. package/dist/chunk-QP75SWIQ.js +53 -0
  69. package/dist/chunk-QP75SWIQ.js.map +1 -0
  70. package/dist/chunk-QPNEFZB3.js +208 -0
  71. package/dist/chunk-QPNEFZB3.js.map +1 -0
  72. package/dist/chunk-QSBIXUMB.mjs +242 -0
  73. package/dist/chunk-QSBIXUMB.mjs.map +1 -0
  74. package/dist/chunk-R7NJVDWN.js +48 -0
  75. package/dist/chunk-R7NJVDWN.js.map +1 -0
  76. package/dist/chunk-RQKICZYP.js +137 -0
  77. package/dist/chunk-RQKICZYP.js.map +1 -0
  78. package/dist/chunk-S6VGOPUY.js +14 -0
  79. package/dist/chunk-S6VGOPUY.js.map +1 -0
  80. package/dist/chunk-TXVH44HM.js +90 -0
  81. package/dist/chunk-TXVH44HM.js.map +1 -0
  82. package/dist/chunk-UGFBA4GV.js +123 -0
  83. package/dist/chunk-UGFBA4GV.js.map +1 -0
  84. package/dist/chunk-UQQWZT6C.mjs +14 -0
  85. package/dist/chunk-UQQWZT6C.mjs.map +1 -0
  86. package/dist/chunk-VEREDMI2.mjs +85 -0
  87. package/dist/chunk-VEREDMI2.mjs.map +1 -0
  88. package/dist/chunk-VH47Q6TS.js +182 -0
  89. package/dist/chunk-VH47Q6TS.js.map +1 -0
  90. package/dist/chunk-W3GAOR7Y.js +76 -0
  91. package/dist/chunk-W3GAOR7Y.js.map +1 -0
  92. package/dist/chunk-WXQZIUNW.js +242 -0
  93. package/dist/chunk-WXQZIUNW.js.map +1 -0
  94. package/dist/chunk-XGRAHX6T.mjs +53 -0
  95. package/dist/chunk-XGRAHX6T.mjs.map +1 -0
  96. package/dist/chunk-XKNFL657.mjs +137 -0
  97. package/dist/chunk-XKNFL657.mjs.map +1 -0
  98. package/dist/chunk-XUI43LEZ.mjs +30 -0
  99. package/dist/chunk-XUI43LEZ.mjs.map +1 -0
  100. package/dist/chunk-Y7ENNK7L.mjs +238 -0
  101. package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
  102. package/dist/chunk-Z3HHSD5I.mjs +127 -0
  103. package/dist/chunk-Z3HHSD5I.mjs.map +1 -0
  104. package/dist/chunk-Z4BLTVTB.js +30 -0
  105. package/dist/chunk-Z4BLTVTB.js.map +1 -0
  106. package/dist/chunk-ZNZEJDOE.js +50 -0
  107. package/dist/chunk-ZNZEJDOE.js.map +1 -0
  108. package/dist/chunk-ZQFMTLZJ.mjs +320 -0
  109. package/dist/chunk-ZQFMTLZJ.mjs.map +1 -0
  110. package/dist/constants.js +15 -110
  111. package/dist/constants.js.map +1 -1
  112. package/dist/constants.mjs +16 -0
  113. package/dist/constants.mjs.map +1 -0
  114. package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
  115. package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
  116. package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
  117. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
  118. package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
  119. package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
  120. package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
  121. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
  122. package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
  123. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
  124. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
  125. package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
  126. package/dist/helpers/GasFeePoller.js +11 -143
  127. package/dist/helpers/GasFeePoller.js.map +1 -1
  128. package/dist/helpers/GasFeePoller.mjs +12 -0
  129. package/dist/helpers/GasFeePoller.mjs.map +1 -0
  130. package/dist/helpers/IncomingTransactionHelper.js +8 -205
  131. package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
  132. package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
  133. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
  134. package/dist/helpers/MultichainTrackingHelper.js +12 -291
  135. package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
  136. package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
  137. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
  138. package/dist/helpers/PendingTransactionTracker.js +9 -360
  139. package/dist/helpers/PendingTransactionTracker.js.map +1 -1
  140. package/dist/helpers/PendingTransactionTracker.mjs +10 -0
  141. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
  142. package/dist/index.js +57 -26
  143. package/dist/index.js.map +1 -1
  144. package/dist/index.mjs +58 -0
  145. package/dist/index.mjs.map +1 -0
  146. package/dist/logger.js +11 -8
  147. package/dist/logger.js.map +1 -1
  148. package/dist/logger.mjs +12 -0
  149. package/dist/logger.mjs.map +1 -0
  150. package/dist/tsconfig.build.tsbuildinfo +1 -0
  151. package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +236 -46
  152. package/dist/types/TransactionController.d.ts.map +1 -0
  153. package/dist/{constants.d.ts → types/constants.d.ts} +10 -0
  154. package/dist/types/constants.d.ts.map +1 -0
  155. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
  156. package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
  157. package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
  158. package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +5 -3
  159. package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
  160. package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
  161. package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
  162. package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
  163. package/dist/types/index.d.ts +9 -0
  164. package/dist/types/index.d.ts.map +1 -0
  165. package/dist/types/logger.d.ts.map +1 -0
  166. package/dist/{types.d.ts → types/types.d.ts} +94 -65
  167. package/dist/types/types.d.ts.map +1 -0
  168. package/dist/types/utils/etherscan.d.ts.map +1 -0
  169. package/dist/types/utils/external-transactions.d.ts.map +1 -0
  170. package/dist/types/utils/gas-fees.d.ts.map +1 -0
  171. package/dist/types/utils/gas-flow.d.ts.map +1 -0
  172. package/dist/types/utils/gas.d.ts.map +1 -0
  173. package/dist/types/utils/history.d.ts +20 -0
  174. package/dist/types/utils/history.d.ts.map +1 -0
  175. package/dist/types/utils/layer1-gas-fee-flow.d.ts +16 -0
  176. package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +1 -0
  177. package/dist/types/utils/nonce.d.ts.map +1 -0
  178. package/dist/types/utils/simulation-api.d.ts +99 -0
  179. package/dist/types/utils/simulation-api.d.ts.map +1 -0
  180. package/dist/types/utils/simulation.d.ts +21 -0
  181. package/dist/types/utils/simulation.d.ts.map +1 -0
  182. package/dist/{utils → types/utils}/swaps.d.ts +8 -5
  183. package/dist/types/utils/swaps.d.ts.map +1 -0
  184. package/dist/types/utils/transaction-type.d.ts.map +1 -0
  185. package/dist/types/utils/utils.d.ts.map +1 -0
  186. package/dist/types/utils/validation.d.ts.map +1 -0
  187. package/dist/types.js +19 -170
  188. package/dist/types.js.map +1 -1
  189. package/dist/types.mjs +20 -0
  190. package/dist/types.mjs.map +1 -0
  191. package/dist/utils/etherscan.js +13 -118
  192. package/dist/utils/etherscan.js.map +1 -1
  193. package/dist/utils/etherscan.mjs +14 -0
  194. package/dist/utils/etherscan.mjs.map +1 -0
  195. package/dist/utils/external-transactions.js +8 -35
  196. package/dist/utils/external-transactions.js.map +1 -1
  197. package/dist/utils/external-transactions.mjs +9 -0
  198. package/dist/utils/external-transactions.mjs.map +1 -0
  199. package/dist/utils/gas-fees.js +15 -200
  200. package/dist/utils/gas-fees.js.map +1 -1
  201. package/dist/utils/gas-fees.mjs +16 -0
  202. package/dist/utils/gas-fees.mjs.map +1 -0
  203. package/dist/utils/gas-flow.js +10 -52
  204. package/dist/utils/gas-flow.js.map +1 -1
  205. package/dist/utils/gas-flow.mjs +11 -0
  206. package/dist/utils/gas-flow.mjs.map +1 -0
  207. package/dist/utils/gas.js +19 -133
  208. package/dist/utils/gas.js.map +1 -1
  209. package/dist/utils/gas.mjs +20 -0
  210. package/dist/utils/gas.mjs.map +1 -0
  211. package/dist/utils/history.js +9 -83
  212. package/dist/utils/history.js.map +1 -1
  213. package/dist/utils/history.mjs +10 -0
  214. package/dist/utils/history.mjs.map +1 -0
  215. package/dist/utils/layer1-gas-fee-flow.js +9 -0
  216. package/dist/utils/layer1-gas-fee-flow.js.map +1 -0
  217. package/dist/utils/layer1-gas-fee-flow.mjs +9 -0
  218. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -0
  219. package/dist/utils/nonce.js +10 -76
  220. package/dist/utils/nonce.js.map +1 -1
  221. package/dist/utils/nonce.mjs +11 -0
  222. package/dist/utils/nonce.mjs.map +1 -0
  223. package/dist/utils/simulation-api.js +10 -0
  224. package/dist/utils/simulation-api.js.map +1 -0
  225. package/dist/utils/simulation-api.mjs +10 -0
  226. package/dist/utils/simulation-api.mjs.map +1 -0
  227. package/dist/utils/simulation.js +12 -0
  228. package/dist/utils/simulation.js.map +1 -0
  229. package/dist/utils/simulation.mjs +12 -0
  230. package/dist/utils/simulation.mjs.map +1 -0
  231. package/dist/utils/swaps.js +23 -256
  232. package/dist/utils/swaps.js.map +1 -1
  233. package/dist/utils/swaps.mjs +24 -0
  234. package/dist/utils/swaps.mjs.map +1 -0
  235. package/dist/utils/transaction-type.js +10 -120
  236. package/dist/utils/transaction-type.js.map +1 -1
  237. package/dist/utils/transaction-type.mjs +11 -0
  238. package/dist/utils/transaction-type.mjs.map +1 -0
  239. package/dist/utils/utils.js +32 -160
  240. package/dist/utils/utils.js.map +1 -1
  241. package/dist/utils/utils.mjs +33 -0
  242. package/dist/utils/utils.mjs.map +1 -0
  243. package/dist/utils/validation.js +11 -258
  244. package/dist/utils/validation.js.map +1 -1
  245. package/dist/utils/validation.mjs +12 -0
  246. package/dist/utils/validation.mjs.map +1 -0
  247. package/package.json +22 -10
  248. package/dist/TransactionController.d.ts.map +0 -1
  249. package/dist/constants.d.ts.map +0 -1
  250. package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  251. package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  252. package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
  253. package/dist/helpers/GasFeePoller.d.ts.map +0 -1
  254. package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
  255. package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  256. package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
  257. package/dist/index.d.ts +0 -7
  258. package/dist/index.d.ts.map +0 -1
  259. package/dist/logger.d.ts.map +0 -1
  260. package/dist/types.d.ts.map +0 -1
  261. package/dist/utils/etherscan.d.ts.map +0 -1
  262. package/dist/utils/external-transactions.d.ts.map +0 -1
  263. package/dist/utils/gas-fees.d.ts.map +0 -1
  264. package/dist/utils/gas-flow.d.ts.map +0 -1
  265. package/dist/utils/gas.d.ts.map +0 -1
  266. package/dist/utils/history.d.ts +0 -15
  267. package/dist/utils/history.d.ts.map +0 -1
  268. package/dist/utils/nonce.d.ts.map +0 -1
  269. package/dist/utils/swaps.d.ts.map +0 -1
  270. package/dist/utils/transaction-type.d.ts.map +0 -1
  271. package/dist/utils/utils.d.ts.map +0 -1
  272. package/dist/utils/validation.d.ts.map +0 -1
  273. /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
  274. /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
  275. /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
  276. /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
  277. /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
  278. /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
  279. /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
  280. /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
  282. /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
  283. /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
  284. /package/dist/{utils → types/utils}/gas.d.ts +0 -0
  285. /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
  286. /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
  287. /package/dist/{utils → types/utils}/utils.d.ts +0 -0
  288. /package/dist/{utils → types/utils}/validation.d.ts +0 -0
@@ -0,0 +1,320 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+
3
+ var _chunkF3CMU2DMjs = require('./chunk-F3CMU2DM.js');
4
+
5
+
6
+ var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
7
+
8
+
9
+
10
+
11
+
12
+ var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
13
+
14
+ // src/helpers/MultichainTrackingHelper.ts
15
+ var _ethquery = require('@metamask/eth-query'); var _ethquery2 = _interopRequireDefault(_ethquery);
16
+ var _asyncmutex = require('async-mutex');
17
+ var _isMultichainEnabled, _provider, _nonceTracker, _incomingTransactionOptions, _findNetworkClientIdByChainId, _getNetworkClientById, _getNetworkClientRegistry, _removeIncomingTransactionHelperListeners, _removePendingTransactionTrackerListeners, _createNonceTracker, _createIncomingTransactionHelper, _createPendingTransactionTracker, _nonceMutexesByChainId, _trackingMap, _etherscanRemoteTransactionSourcesMap, _refreshTrackingMap, _stopTrackingByNetworkClientId, stopTrackingByNetworkClientId_fn, _startTrackingByNetworkClientId, startTrackingByNetworkClientId_fn, _refreshEtherscanRemoteTransactionSources;
18
+ var MultichainTrackingHelper = class {
19
+ constructor({
20
+ isMultichainEnabled,
21
+ provider,
22
+ nonceTracker,
23
+ incomingTransactionOptions,
24
+ findNetworkClientIdByChainId,
25
+ getNetworkClientById,
26
+ getNetworkClientRegistry,
27
+ removeIncomingTransactionHelperListeners,
28
+ removePendingTransactionTrackerListeners,
29
+ createNonceTracker,
30
+ createIncomingTransactionHelper,
31
+ createPendingTransactionTracker,
32
+ onNetworkStateChange
33
+ }) {
34
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _stopTrackingByNetworkClientId);
35
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _startTrackingByNetworkClientId);
36
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _isMultichainEnabled, void 0);
37
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _provider, void 0);
38
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _nonceTracker, void 0);
39
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _incomingTransactionOptions, void 0);
40
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _findNetworkClientIdByChainId, void 0);
41
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getNetworkClientById, void 0);
42
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getNetworkClientRegistry, void 0);
43
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _removeIncomingTransactionHelperListeners, void 0);
44
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _removePendingTransactionTrackerListeners, void 0);
45
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _createNonceTracker, void 0);
46
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _createIncomingTransactionHelper, void 0);
47
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _createPendingTransactionTracker, void 0);
48
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _nonceMutexesByChainId, /* @__PURE__ */ new Map());
49
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _trackingMap, /* @__PURE__ */ new Map());
50
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _etherscanRemoteTransactionSourcesMap, /* @__PURE__ */ new Map());
51
+ this.checkForPendingTransactionAndStartPolling = () => {
52
+ for (const [, trackers] of _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap)) {
53
+ trackers.pendingTransactionTracker.startIfPendingTransactions();
54
+ }
55
+ };
56
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _refreshTrackingMap, (networkClients) => {
57
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _refreshEtherscanRemoteTransactionSources).call(this, networkClients);
58
+ const networkClientIds = Object.keys(networkClients);
59
+ const existingNetworkClientIds = Array.from(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).keys());
60
+ const networkClientIdsToRemove = existingNetworkClientIds.filter(
61
+ (id) => !networkClientIds.includes(id)
62
+ );
63
+ networkClientIdsToRemove.forEach((id) => {
64
+ _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _stopTrackingByNetworkClientId, stopTrackingByNetworkClientId_fn).call(this, id);
65
+ });
66
+ const networkClientIdsToAdd = networkClientIds.filter(
67
+ (id) => !existingNetworkClientIds.includes(id)
68
+ );
69
+ networkClientIdsToAdd.forEach((id) => {
70
+ _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _startTrackingByNetworkClientId, startTrackingByNetworkClientId_fn).call(this, id);
71
+ });
72
+ });
73
+ _chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _refreshEtherscanRemoteTransactionSources, (networkClients) => {
74
+ const chainIdsInRegistry = /* @__PURE__ */ new Set();
75
+ Object.values(networkClients).forEach(
76
+ (networkClient) => chainIdsInRegistry.add(networkClient.configuration.chainId)
77
+ );
78
+ const existingChainIds = Array.from(
79
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _etherscanRemoteTransactionSourcesMap).keys()
80
+ );
81
+ const chainIdsToRemove = existingChainIds.filter(
82
+ (chainId) => !chainIdsInRegistry.has(chainId)
83
+ );
84
+ chainIdsToRemove.forEach((chainId) => {
85
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _etherscanRemoteTransactionSourcesMap).delete(chainId);
86
+ });
87
+ });
88
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _isMultichainEnabled, isMultichainEnabled);
89
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _provider, provider);
90
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _nonceTracker, nonceTracker);
91
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _incomingTransactionOptions, incomingTransactionOptions);
92
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _findNetworkClientIdByChainId, findNetworkClientIdByChainId);
93
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getNetworkClientById, getNetworkClientById);
94
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _getNetworkClientRegistry, getNetworkClientRegistry);
95
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners);
96
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners);
97
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _createNonceTracker, createNonceTracker);
98
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _createIncomingTransactionHelper, createIncomingTransactionHelper);
99
+ _chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _createPendingTransactionTracker, createPendingTransactionTracker);
100
+ onNetworkStateChange((_, patches) => {
101
+ if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isMultichainEnabled)) {
102
+ const networkClients = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNetworkClientRegistry).call(this);
103
+ patches.forEach(({ op, path }) => {
104
+ if (op === "remove" && path[0] === "networkConfigurations") {
105
+ const networkClientId = path[1];
106
+ delete networkClients[networkClientId];
107
+ }
108
+ });
109
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _refreshTrackingMap).call(this, networkClients);
110
+ }
111
+ });
112
+ }
113
+ initialize() {
114
+ if (!_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isMultichainEnabled)) {
115
+ return;
116
+ }
117
+ const networkClients = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNetworkClientRegistry).call(this);
118
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _refreshTrackingMap).call(this, networkClients);
119
+ }
120
+ has(networkClientId) {
121
+ return _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).has(networkClientId);
122
+ }
123
+ getEthQuery({
124
+ networkClientId,
125
+ chainId
126
+ } = {}) {
127
+ if (!_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isMultichainEnabled)) {
128
+ return new (0, _ethquery2.default)(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _provider));
129
+ }
130
+ let networkClient;
131
+ if (networkClientId) {
132
+ try {
133
+ networkClient = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNetworkClientById).call(this, networkClientId);
134
+ } catch (err) {
135
+ _chunkS6VGOPUYjs.incomingTransactionsLogger.call(void 0, "failed to get network client by networkClientId");
136
+ }
137
+ }
138
+ if (!networkClient && chainId) {
139
+ try {
140
+ networkClientId = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _findNetworkClientIdByChainId).call(this, chainId);
141
+ networkClient = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNetworkClientById).call(this, networkClientId);
142
+ } catch (err) {
143
+ _chunkS6VGOPUYjs.incomingTransactionsLogger.call(void 0, "failed to get network client by chainId");
144
+ }
145
+ }
146
+ if (networkClient) {
147
+ return new (0, _ethquery2.default)(networkClient.provider);
148
+ }
149
+ return new (0, _ethquery2.default)(_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _provider));
150
+ }
151
+ /**
152
+ * Gets the mutex intended to guard the nonceTracker for a particular chainId and key .
153
+ *
154
+ * @param opts - The options object.
155
+ * @param opts.chainId - The hex chainId.
156
+ * @param opts.key - The hex address (or constant) pertaining to the chainId
157
+ * @returns Mutex instance for the given chainId and key pair
158
+ */
159
+ async acquireNonceLockForChainIdKey({
160
+ chainId,
161
+ key = "global"
162
+ }) {
163
+ let nonceMutexesForChainId = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _nonceMutexesByChainId).get(chainId);
164
+ if (!nonceMutexesForChainId) {
165
+ nonceMutexesForChainId = /* @__PURE__ */ new Map();
166
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _nonceMutexesByChainId).set(chainId, nonceMutexesForChainId);
167
+ }
168
+ let nonceMutexForKey = nonceMutexesForChainId.get(key);
169
+ if (!nonceMutexForKey) {
170
+ nonceMutexForKey = new (0, _asyncmutex.Mutex)();
171
+ nonceMutexesForChainId.set(key, nonceMutexForKey);
172
+ }
173
+ return await nonceMutexForKey.acquire();
174
+ }
175
+ /**
176
+ * Gets the next nonce according to the nonce-tracker.
177
+ * Ensure `releaseLock` is called once processing of the `nonce` value is complete.
178
+ *
179
+ * @param address - The hex string address for the transaction.
180
+ * @param networkClientId - The network client ID for the transaction, used to fetch the correct nonce tracker.
181
+ * @returns object with the `nextNonce` `nonceDetails`, and the releaseLock.
182
+ */
183
+ async getNonceLock(address, networkClientId) {
184
+ let releaseLockForChainIdKey;
185
+ let nonceTracker = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _nonceTracker);
186
+ if (networkClientId && _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isMultichainEnabled)) {
187
+ const networkClient = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNetworkClientById).call(this, networkClientId);
188
+ releaseLockForChainIdKey = await this.acquireNonceLockForChainIdKey({
189
+ chainId: networkClient.configuration.chainId,
190
+ key: address
191
+ });
192
+ const trackers = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).get(networkClientId);
193
+ if (!trackers) {
194
+ throw new Error("missing nonceTracker for networkClientId");
195
+ }
196
+ nonceTracker = trackers.nonceTracker;
197
+ }
198
+ try {
199
+ const nonceLock = await nonceTracker.getNonceLock(address);
200
+ return {
201
+ ...nonceLock,
202
+ releaseLock: () => {
203
+ nonceLock.releaseLock();
204
+ releaseLockForChainIdKey?.();
205
+ }
206
+ };
207
+ } catch (err) {
208
+ releaseLockForChainIdKey?.();
209
+ throw err;
210
+ }
211
+ }
212
+ startIncomingTransactionPolling(networkClientIds = []) {
213
+ networkClientIds.forEach((networkClientId) => {
214
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).get(networkClientId)?.incomingTransactionHelper.start();
215
+ });
216
+ }
217
+ stopIncomingTransactionPolling(networkClientIds = []) {
218
+ networkClientIds.forEach((networkClientId) => {
219
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).get(networkClientId)?.incomingTransactionHelper.stop();
220
+ });
221
+ }
222
+ stopAllIncomingTransactionPolling() {
223
+ for (const [, trackers] of _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap)) {
224
+ trackers.incomingTransactionHelper.stop();
225
+ }
226
+ }
227
+ async updateIncomingTransactions(networkClientIds = []) {
228
+ const promises = await Promise.allSettled(
229
+ networkClientIds.map(async (networkClientId) => {
230
+ return await _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).get(networkClientId)?.incomingTransactionHelper.update();
231
+ })
232
+ );
233
+ promises.filter((result) => result.status === "rejected").forEach((result) => {
234
+ _chunkS6VGOPUYjs.incomingTransactionsLogger.call(void 0,
235
+ "failed to update incoming transactions",
236
+ result.reason
237
+ );
238
+ });
239
+ }
240
+ stopAllTracking() {
241
+ for (const [networkClientId] of _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap)) {
242
+ _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _stopTrackingByNetworkClientId, stopTrackingByNetworkClientId_fn).call(this, networkClientId);
243
+ }
244
+ }
245
+ };
246
+ _isMultichainEnabled = new WeakMap();
247
+ _provider = new WeakMap();
248
+ _nonceTracker = new WeakMap();
249
+ _incomingTransactionOptions = new WeakMap();
250
+ _findNetworkClientIdByChainId = new WeakMap();
251
+ _getNetworkClientById = new WeakMap();
252
+ _getNetworkClientRegistry = new WeakMap();
253
+ _removeIncomingTransactionHelperListeners = new WeakMap();
254
+ _removePendingTransactionTrackerListeners = new WeakMap();
255
+ _createNonceTracker = new WeakMap();
256
+ _createIncomingTransactionHelper = new WeakMap();
257
+ _createPendingTransactionTracker = new WeakMap();
258
+ _nonceMutexesByChainId = new WeakMap();
259
+ _trackingMap = new WeakMap();
260
+ _etherscanRemoteTransactionSourcesMap = new WeakMap();
261
+ _refreshTrackingMap = new WeakMap();
262
+ _stopTrackingByNetworkClientId = new WeakSet();
263
+ stopTrackingByNetworkClientId_fn = function(networkClientId) {
264
+ const trackers = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).get(networkClientId);
265
+ if (trackers) {
266
+ trackers.pendingTransactionTracker.stop();
267
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _removePendingTransactionTrackerListeners).call(this, trackers.pendingTransactionTracker);
268
+ trackers.incomingTransactionHelper.stop();
269
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _removeIncomingTransactionHelperListeners).call(this, trackers.incomingTransactionHelper);
270
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).delete(networkClientId);
271
+ }
272
+ };
273
+ _startTrackingByNetworkClientId = new WeakSet();
274
+ startTrackingByNetworkClientId_fn = function(networkClientId) {
275
+ const trackers = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).get(networkClientId);
276
+ if (trackers) {
277
+ return;
278
+ }
279
+ const {
280
+ provider,
281
+ blockTracker,
282
+ configuration: { chainId }
283
+ } = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getNetworkClientById).call(this, networkClientId);
284
+ let etherscanRemoteTransactionSource = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _etherscanRemoteTransactionSourcesMap).get(chainId);
285
+ if (!etherscanRemoteTransactionSource) {
286
+ etherscanRemoteTransactionSource = new (0, _chunkF3CMU2DMjs.EtherscanRemoteTransactionSource)({
287
+ includeTokenTransfers: _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _incomingTransactionOptions).includeTokenTransfers
288
+ });
289
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _etherscanRemoteTransactionSourcesMap).set(
290
+ chainId,
291
+ etherscanRemoteTransactionSource
292
+ );
293
+ }
294
+ const nonceTracker = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _createNonceTracker).call(this, {
295
+ provider,
296
+ blockTracker,
297
+ chainId
298
+ });
299
+ const incomingTransactionHelper = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _createIncomingTransactionHelper).call(this, {
300
+ blockTracker,
301
+ etherscanRemoteTransactionSource,
302
+ chainId
303
+ });
304
+ const pendingTransactionTracker = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _createPendingTransactionTracker).call(this, {
305
+ provider,
306
+ blockTracker,
307
+ chainId
308
+ });
309
+ _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _trackingMap).set(networkClientId, {
310
+ nonceTracker,
311
+ incomingTransactionHelper,
312
+ pendingTransactionTracker
313
+ });
314
+ };
315
+ _refreshEtherscanRemoteTransactionSources = new WeakMap();
316
+
317
+
318
+
319
+ exports.MultichainTrackingHelper = MultichainTrackingHelper;
320
+ //# sourceMappingURL=chunk-NRWEI43Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/helpers/MultichainTrackingHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,OAAO,cAAc;AAUrB,SAAS,aAAa;AAVtB;AAkEO,IAAM,2BAAN,MAA+B;AAAA,EAyDpC,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAA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amask/eth-query';\nimport type {\n NetworkClientId,\n NetworkController,\n NetworkClient,\n BlockTracker,\n Provider,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport type { NonceLock, NonceTracker } from 'nonce-tracker';\n\nimport { incomingTransactionsLogger as log } from '../logger';\nimport { EtherscanRemoteTransactionSource } from './EtherscanRemoteTransactionSource';\nimport type {\n IncomingTransactionHelper,\n IncomingTransactionOptions,\n} from './IncomingTransactionHelper';\nimport type { PendingTransactionTracker } from './PendingTransactionTracker';\n\n/**\n * Registry of network clients provided by the NetworkController\n */\ntype NetworkClientRegistry = ReturnType<\n NetworkController['getNetworkClientRegistry']\n>;\n\nexport type MultichainTrackingHelperOptions = {\n isMultichainEnabled: boolean;\n provider: Provider;\n nonceTracker: NonceTracker;\n incomingTransactionOptions: IncomingTransactionOptions;\n\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n getNetworkClientById: NetworkController['getNetworkClientById'];\n getNetworkClientRegistry: NetworkController['getNetworkClientRegistry'];\n\n removeIncomingTransactionHelperListeners: (\n IncomingTransactionHelper: IncomingTransactionHelper,\n ) => void;\n removePendingTransactionTrackerListeners: (\n pendingTransactionTracker: PendingTransactionTracker,\n ) => void;\n createNonceTracker: (opts: {\n provider: Provider;\n blockTracker: BlockTracker;\n chainId?: Hex;\n }) => NonceTracker;\n createIncomingTransactionHelper: (opts: {\n blockTracker: BlockTracker;\n etherscanRemoteTransactionSource: EtherscanRemoteTransactionSource;\n chainId?: Hex;\n }) => IncomingTransactionHelper;\n createPendingTransactionTracker: (opts: {\n provider: Provider;\n blockTracker: BlockTracker;\n chainId?: Hex;\n }) => PendingTransactionTracker;\n onNetworkStateChange: (\n listener: (\n ...payload: NetworkControllerStateChangeEvent['payload']\n ) => void,\n ) => void;\n};\n\nexport class MultichainTrackingHelper {\n #isMultichainEnabled: boolean;\n\n readonly #provider: Provider;\n\n readonly #nonceTracker: NonceTracker;\n\n readonly #incomingTransactionOptions: IncomingTransactionOptions;\n\n readonly #findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n\n readonly #getNetworkClientById: NetworkController['getNetworkClientById'];\n\n readonly #getNetworkClientRegistry: NetworkController['getNetworkClientRegistry'];\n\n readonly #removeIncomingTransactionHelperListeners: (\n IncomingTransactionHelper: IncomingTransactionHelper,\n ) => void;\n\n readonly #removePendingTransactionTrackerListeners: (\n pendingTransactionTracker: PendingTransactionTracker,\n ) => void;\n\n readonly #createNonceTracker: (opts: {\n provider: Provider;\n blockTracker: BlockTracker;\n chainId?: Hex;\n }) => NonceTracker;\n\n readonly #createIncomingTransactionHelper: (opts: {\n blockTracker: BlockTracker;\n chainId?: Hex;\n etherscanRemoteTransactionSource: EtherscanRemoteTransactionSource;\n }) => IncomingTransactionHelper;\n\n readonly #createPendingTransactionTracker: (opts: {\n provider: Provider;\n blockTracker: BlockTracker;\n chainId?: Hex;\n }) => PendingTransactionTracker;\n\n readonly #nonceMutexesByChainId = new Map<Hex, Map<string, Mutex>>();\n\n readonly #trackingMap: Map<\n NetworkClientId,\n {\n nonceTracker: NonceTracker;\n pendingTransactionTracker: PendingTransactionTracker;\n incomingTransactionHelper: IncomingTransactionHelper;\n }\n > = new Map();\n\n readonly #etherscanRemoteTransactionSourcesMap: Map<\n Hex,\n EtherscanRemoteTransactionSource\n > = new Map();\n\n constructor({\n isMultichainEnabled,\n provider,\n nonceTracker,\n incomingTransactionOptions,\n findNetworkClientIdByChainId,\n getNetworkClientById,\n getNetworkClientRegistry,\n removeIncomingTransactionHelperListeners,\n removePendingTransactionTrackerListeners,\n createNonceTracker,\n createIncomingTransactionHelper,\n createPendingTransactionTracker,\n onNetworkStateChange,\n }: MultichainTrackingHelperOptions) {\n this.#isMultichainEnabled = isMultichainEnabled;\n this.#provider = provider;\n this.#nonceTracker = nonceTracker;\n this.#incomingTransactionOptions = incomingTransactionOptions;\n\n this.#findNetworkClientIdByChainId = findNetworkClientIdByChainId;\n this.#getNetworkClientById = getNetworkClientById;\n this.#getNetworkClientRegistry = getNetworkClientRegistry;\n\n this.#removeIncomingTransactionHelperListeners =\n removeIncomingTransactionHelperListeners;\n this.#removePendingTransactionTrackerListeners =\n removePendingTransactionTrackerListeners;\n this.#createNonceTracker = createNonceTracker;\n this.#createIncomingTransactionHelper = createIncomingTransactionHelper;\n this.#createPendingTransactionTracker = createPendingTransactionTracker;\n\n onNetworkStateChange((_, patches) => {\n if (this.#isMultichainEnabled) {\n const networkClients = this.#getNetworkClientRegistry();\n patches.forEach(({ op, path }) => {\n if (op === 'remove' && path[0] === 'networkConfigurations') {\n const networkClientId = path[1] as NetworkClientId;\n delete networkClients[networkClientId];\n }\n });\n\n this.#refreshTrackingMap(networkClients);\n }\n });\n }\n\n initialize() {\n if (!this.#isMultichainEnabled) {\n return;\n }\n const networkClients = this.#getNetworkClientRegistry();\n this.#refreshTrackingMap(networkClients);\n }\n\n has(networkClientId: NetworkClientId) {\n return this.#trackingMap.has(networkClientId);\n }\n\n getEthQuery({\n networkClientId,\n chainId,\n }: {\n networkClientId?: NetworkClientId;\n chainId?: Hex;\n } = {}): EthQuery {\n if (!this.#isMultichainEnabled) {\n return new EthQuery(this.#provider);\n }\n let networkClient: NetworkClient | undefined;\n\n if (networkClientId) {\n try {\n networkClient = this.#getNetworkClientById(networkClientId);\n } catch (err) {\n log('failed to get network client by networkClientId');\n }\n }\n if (!networkClient && chainId) {\n try {\n networkClientId = this.#findNetworkClientIdByChainId(chainId);\n networkClient = this.#getNetworkClientById(networkClientId);\n } catch (err) {\n log('failed to get network client by chainId');\n }\n }\n\n if (networkClient) {\n return new EthQuery(networkClient.provider);\n }\n\n // NOTE(JL): we're not ready to drop globally selected ethQuery yet.\n // Some calls to getEthQuery only have access to optional networkClientId\n // throw new Error('failed to get eth query instance');\n return new EthQuery(this.#provider);\n }\n\n /**\n * Gets the mutex intended to guard the nonceTracker for a particular chainId and key .\n *\n * @param opts - The options object.\n * @param opts.chainId - The hex chainId.\n * @param opts.key - The hex address (or constant) pertaining to the chainId\n * @returns Mutex instance for the given chainId and key pair\n */\n async acquireNonceLockForChainIdKey({\n chainId,\n key = 'global',\n }: {\n chainId: Hex;\n key?: string;\n }): Promise<() => void> {\n let nonceMutexesForChainId = this.#nonceMutexesByChainId.get(chainId);\n if (!nonceMutexesForChainId) {\n nonceMutexesForChainId = new Map<string, Mutex>();\n this.#nonceMutexesByChainId.set(chainId, nonceMutexesForChainId);\n }\n let nonceMutexForKey = nonceMutexesForChainId.get(key);\n if (!nonceMutexForKey) {\n nonceMutexForKey = new Mutex();\n nonceMutexesForChainId.set(key, nonceMutexForKey);\n }\n\n return await nonceMutexForKey.acquire();\n }\n\n /**\n * Gets the next nonce according to the nonce-tracker.\n * Ensure `releaseLock` is called once processing of the `nonce` value is complete.\n *\n * @param address - The hex string address for the transaction.\n * @param networkClientId - The network client ID for the transaction, used to fetch the correct nonce tracker.\n * @returns object with the `nextNonce` `nonceDetails`, and the releaseLock.\n */\n async getNonceLock(\n address: string,\n networkClientId?: NetworkClientId,\n ): Promise<NonceLock> {\n let releaseLockForChainIdKey: (() => void) | undefined;\n let nonceTracker = this.#nonceTracker;\n if (networkClientId && this.#isMultichainEnabled) {\n const networkClient = this.#getNetworkClientById(networkClientId);\n releaseLockForChainIdKey = await this.acquireNonceLockForChainIdKey({\n chainId: networkClient.configuration.chainId,\n key: address,\n });\n const trackers = this.#trackingMap.get(networkClientId);\n if (!trackers) {\n throw new Error('missing nonceTracker for networkClientId');\n }\n nonceTracker = trackers.nonceTracker;\n }\n\n // Acquires the lock for the chainId + address and the nonceLock from the nonceTracker, then\n // couples them together by replacing the nonceLock's releaseLock method with\n // an anonymous function that calls releases both the original nonceLock and the\n // lock for the chainId.\n try {\n const nonceLock = await nonceTracker.getNonceLock(address);\n return {\n ...nonceLock,\n releaseLock: () => {\n nonceLock.releaseLock();\n releaseLockForChainIdKey?.();\n },\n };\n } catch (err) {\n releaseLockForChainIdKey?.();\n throw err;\n }\n }\n\n startIncomingTransactionPolling(networkClientIds: NetworkClientId[] = []) {\n networkClientIds.forEach((networkClientId) => {\n this.#trackingMap.get(networkClientId)?.incomingTransactionHelper.start();\n });\n }\n\n stopIncomingTransactionPolling(networkClientIds: NetworkClientId[] = []) {\n networkClientIds.forEach((networkClientId) => {\n this.#trackingMap.get(networkClientId)?.incomingTransactionHelper.stop();\n });\n }\n\n stopAllIncomingTransactionPolling() {\n for (const [, trackers] of this.#trackingMap) {\n trackers.incomingTransactionHelper.stop();\n }\n }\n\n async updateIncomingTransactions(networkClientIds: NetworkClientId[] = []) {\n const promises = await Promise.allSettled(\n networkClientIds.map(async (networkClientId) => {\n return await this.#trackingMap\n .get(networkClientId)\n ?.incomingTransactionHelper.update();\n }),\n );\n\n promises\n .filter((result) => result.status === 'rejected')\n .forEach((result) => {\n log(\n 'failed to update incoming transactions',\n (result as PromiseRejectedResult).reason,\n );\n });\n }\n\n checkForPendingTransactionAndStartPolling = () => {\n for (const [, trackers] of this.#trackingMap) {\n trackers.pendingTransactionTracker.startIfPendingTransactions();\n }\n };\n\n stopAllTracking() {\n for (const [networkClientId] of this.#trackingMap) {\n this.#stopTrackingByNetworkClientId(networkClientId);\n }\n }\n\n #refreshTrackingMap = (networkClients: NetworkClientRegistry) => {\n this.#refreshEtherscanRemoteTransactionSources(networkClients);\n\n const networkClientIds = Object.keys(networkClients);\n const existingNetworkClientIds = Array.from(this.#trackingMap.keys());\n\n // Remove tracking for NetworkClientIds that no longer exist\n const networkClientIdsToRemove = existingNetworkClientIds.filter(\n (id) => !networkClientIds.includes(id),\n );\n networkClientIdsToRemove.forEach((id) => {\n this.#stopTrackingByNetworkClientId(id);\n });\n\n // Start tracking new NetworkClientIds from the registry\n const networkClientIdsToAdd = networkClientIds.filter(\n (id) => !existingNetworkClientIds.includes(id),\n );\n networkClientIdsToAdd.forEach((id) => {\n this.#startTrackingByNetworkClientId(id);\n });\n };\n\n #stopTrackingByNetworkClientId(networkClientId: NetworkClientId) {\n const trackers = this.#trackingMap.get(networkClientId);\n if (trackers) {\n trackers.pendingTransactionTracker.stop();\n this.#removePendingTransactionTrackerListeners(\n trackers.pendingTransactionTracker,\n );\n trackers.incomingTransactionHelper.stop();\n this.#removeIncomingTransactionHelperListeners(\n trackers.incomingTransactionHelper,\n );\n this.#trackingMap.delete(networkClientId);\n }\n }\n\n #startTrackingByNetworkClientId(networkClientId: NetworkClientId) {\n const trackers = this.#trackingMap.get(networkClientId);\n if (trackers) {\n return;\n }\n\n const {\n provider,\n blockTracker,\n configuration: { chainId },\n } = this.#getNetworkClientById(networkClientId);\n\n let etherscanRemoteTransactionSource =\n this.#etherscanRemoteTransactionSourcesMap.get(chainId);\n if (!etherscanRemoteTransactionSource) {\n etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource({\n includeTokenTransfers:\n this.#incomingTransactionOptions.includeTokenTransfers,\n });\n this.#etherscanRemoteTransactionSourcesMap.set(\n chainId,\n etherscanRemoteTransactionSource,\n );\n }\n\n const nonceTracker = this.#createNonceTracker({\n provider,\n blockTracker,\n chainId,\n });\n\n const incomingTransactionHelper = this.#createIncomingTransactionHelper({\n blockTracker,\n etherscanRemoteTransactionSource,\n chainId,\n });\n\n const pendingTransactionTracker = this.#createPendingTransactionTracker({\n provider,\n blockTracker,\n chainId,\n });\n\n this.#trackingMap.set(networkClientId, {\n nonceTracker,\n incomingTransactionHelper,\n pendingTransactionTracker,\n });\n }\n\n #refreshEtherscanRemoteTransactionSources = (\n networkClients: NetworkClientRegistry,\n ) => {\n // this will be prettier when we have consolidated network clients with a single chainId:\n // check if there are still other network clients using the same chainId\n // if not remove the etherscanRemoteTransaction source from the map\n const chainIdsInRegistry = new Set();\n Object.values(networkClients).forEach((networkClient) =>\n chainIdsInRegistry.add(networkClient.configuration.chainId),\n );\n const existingChainIds = Array.from(\n this.#etherscanRemoteTransactionSourcesMap.keys(),\n );\n const chainIdsToRemove = existingChainIds.filter(\n (chainId) => !chainIdsInRegistry.has(chainId),\n );\n\n chainIdsToRemove.forEach((chainId) => {\n this.#etherscanRemoteTransactionSourcesMap.delete(chainId);\n });\n };\n}\n"]}
@@ -0,0 +1,62 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkW3GAOR7Yjs = require('./chunk-W3GAOR7Y.js');
4
+
5
+ // src/utils/gas-flow.ts
6
+ var _controllerutils = require('@metamask/controller-utils');
7
+
8
+
9
+ var _gasfeecontroller = require('@metamask/gas-fee-controller');
10
+ function getGasFeeFlow(transactionMeta, gasFeeFlows) {
11
+ return gasFeeFlows.find(
12
+ (gasFeeFlow) => gasFeeFlow.matchesTransaction(transactionMeta)
13
+ );
14
+ }
15
+ function mergeGasFeeEstimates({
16
+ gasFeeControllerEstimateType,
17
+ gasFeeControllerEstimates,
18
+ transactionGasFeeEstimates
19
+ }) {
20
+ if (gasFeeControllerEstimateType === _gasfeecontroller.GAS_ESTIMATE_TYPES.FEE_MARKET) {
21
+ return Object.values(_chunkW3GAOR7Yjs.GasFeeEstimateLevel).reduce(
22
+ (result, level) => ({
23
+ ...result,
24
+ [level]: mergeFeeMarketEstimate(
25
+ gasFeeControllerEstimates[level],
26
+ transactionGasFeeEstimates[level]
27
+ )
28
+ }),
29
+ { ...gasFeeControllerEstimates }
30
+ );
31
+ }
32
+ if (gasFeeControllerEstimateType === _gasfeecontroller.GAS_ESTIMATE_TYPES.LEGACY) {
33
+ return Object.values(_chunkW3GAOR7Yjs.GasFeeEstimateLevel).reduce(
34
+ (result, level) => ({
35
+ ...result,
36
+ [level]: getLegacyEstimate(transactionGasFeeEstimates[level])
37
+ }),
38
+ {}
39
+ );
40
+ }
41
+ return gasFeeControllerEstimates;
42
+ }
43
+ function mergeFeeMarketEstimate(gasFeeControllerEstimate, transactionGasFeeEstimate) {
44
+ return {
45
+ ...gasFeeControllerEstimate,
46
+ suggestedMaxFeePerGas: _controllerutils.weiHexToGweiDec.call(void 0,
47
+ transactionGasFeeEstimate.maxFeePerGas
48
+ ),
49
+ suggestedMaxPriorityFeePerGas: _controllerutils.weiHexToGweiDec.call(void 0,
50
+ transactionGasFeeEstimate.maxPriorityFeePerGas
51
+ )
52
+ };
53
+ }
54
+ function getLegacyEstimate(transactionGasFeeEstimate) {
55
+ return _controllerutils.weiHexToGweiDec.call(void 0, transactionGasFeeEstimate.maxFeePerGas);
56
+ }
57
+
58
+
59
+
60
+
61
+ exports.getGasFeeFlow = getGasFeeFlow; exports.mergeGasFeeEstimates = mergeGasFeeEstimates;
62
+ //# sourceMappingURL=chunk-O7H2MC7R.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/gas-flow.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAMhC;AAAA,EACE;AAAA,OAEK;AAiBA,SAAS,cACd,iBACA,aACwB;AACxB,SAAO,YAAY;AAAA,IAAK,CAAC,eACvB,WAAW,mBAAmB,eAAe;AAAA,EAC/C;AACF;AAsBO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAEuE;AACrE,MAAI,iCAAiC,mBAAmB,YAAY;AAClE,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG;AAAA,UACP,0BAA0B,KAAK;AAAA,UAC/B,2BAA2B,KAAK;AAAA,QAClC;AAAA,MACF;AAAA,MACA,EAAE,GAAG,0BAA0B;AAAA,IACjC;AAAA,EACF;AAEA,MAAI,iCAAiC,mBAAmB,QAAQ;AAC9D,WAAO,OAAO,OAAO,mBAAmB,EAAE;AAAA,MACxC,CAAC,QAAQ,WAAW;AAAA,QAClB,GAAG;AAAA,QACH,CAAC,KAAK,GAAG,kBAAkB,2BAA2B,KAAK,CAAC;AAAA,MAC9D;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAQA,SAAS,uBACP,0BACA,2BACe;AACf,SAAO;AAAA,IACL,GAAG;AAAA,IACH,uBAAuB;AAAA,MACrB,0BAA0B;AAAA,IAC5B;AAAA,IACA,+BAA+B;AAAA,MAC7B,0BAA0B;AAAA,IAC5B;AAAA,EACF;AACF;AAOA,SAAS,kBACP,2BACQ;AACR,SAAO,gBAAgB,0BAA0B,YAAY;AAC/D","sourcesContent":["import { weiHexToGweiDec } from '@metamask/controller-utils';\nimport type {\n Eip1559GasFee,\n GasFeeEstimates,\n LegacyGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\n\nimport {\n type GasFeeEstimates as TransactionGasFeeEstimates,\n type GasFeeFlow,\n type TransactionMeta,\n type GasFeeEstimatesForLevel,\n GasFeeEstimateLevel,\n} from '../types';\n\n/**\n * Returns the first gas fee flow that matches the transaction.\n *\n * @param transactionMeta - The transaction metadata to find a gas fee flow for.\n * @param gasFeeFlows - The gas fee flows to search.\n * @returns The first gas fee flow that matches the transaction, or undefined if none match.\n */\nexport function getGasFeeFlow(\n transactionMeta: TransactionMeta,\n gasFeeFlows: GasFeeFlow[],\n): GasFeeFlow | undefined {\n return gasFeeFlows.find((gasFeeFlow) =>\n gasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\ntype FeeMarketMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'fee-market';\n gasFeeControllerEstimates: GasFeeEstimates;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\ntype LegacyMergeGasFeeEstimatesRequest = {\n gasFeeControllerEstimateType: 'legacy';\n gasFeeControllerEstimates: LegacyGasPriceEstimate;\n transactionGasFeeEstimates: TransactionGasFeeEstimates;\n};\n\n/**\n * Merge the gas fee estimates from the gas fee controller with the gas fee estimates from a transaction.\n * @param request - Data required to merge gas fee estimates.\n * @param request.gasFeeControllerEstimateType - Gas fee estimate type from the gas fee controller.\n * @param request.gasFeeControllerEstimates - Gas fee estimates from the GasFeeController.\n * @param request.transactionGasFeeEstimates - Gas fee estimates from the transaction.\n * @returns The merged gas fee estimates.\n */\nexport function mergeGasFeeEstimates({\n gasFeeControllerEstimateType,\n gasFeeControllerEstimates,\n transactionGasFeeEstimates,\n}:\n | FeeMarketMergeGasFeeEstimatesRequest\n | LegacyMergeGasFeeEstimatesRequest): GasFeeState['gasFeeEstimates'] {\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: mergeFeeMarketEstimate(\n gasFeeControllerEstimates[level],\n transactionGasFeeEstimates[level],\n ),\n }),\n { ...gasFeeControllerEstimates } as GasFeeEstimates,\n );\n }\n\n if (gasFeeControllerEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n return Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: getLegacyEstimate(transactionGasFeeEstimates[level]),\n }),\n {} as LegacyGasPriceEstimate,\n );\n }\n\n return gasFeeControllerEstimates;\n}\n\n/**\n * Merge a specific priority level of EIP-1559 gas fee estimates.\n * @param gasFeeControllerEstimate - The gas fee estimate from the gas fee controller.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The merged gas fee estimate.\n */\nfunction mergeFeeMarketEstimate(\n gasFeeControllerEstimate: Eip1559GasFee,\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): Eip1559GasFee {\n return {\n ...gasFeeControllerEstimate,\n suggestedMaxFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxFeePerGas,\n ),\n suggestedMaxPriorityFeePerGas: weiHexToGweiDec(\n transactionGasFeeEstimate.maxPriorityFeePerGas,\n ),\n };\n}\n\n/**\n * Generate a specific priority level for a legacy gas fee estimate.\n * @param transactionGasFeeEstimate - The gas fee estimate from the transaction.\n * @returns The legacy gas fee estimate.\n */\nfunction getLegacyEstimate(\n transactionGasFeeEstimate: GasFeeEstimatesForLevel,\n): string {\n return weiHexToGweiDec(transactionGasFeeEstimate.maxFeePerGas);\n}\n"]}
@@ -0,0 +1,90 @@
1
+ import {
2
+ gweiDecimalToWeiHex
3
+ } from "./chunk-DTONMSFW.mjs";
4
+ import {
5
+ projectLogger
6
+ } from "./chunk-UQQWZT6C.mjs";
7
+ import {
8
+ GasFeeEstimateLevel
9
+ } from "./chunk-NM4LTWRU.mjs";
10
+ import {
11
+ __privateAdd,
12
+ __privateMethod
13
+ } from "./chunk-XUI43LEZ.mjs";
14
+
15
+ // src/gas-flows/DefaultGasFeeFlow.ts
16
+ import { GAS_ESTIMATE_TYPES } from "@metamask/gas-fee-controller";
17
+ import { createModuleLogger } from "@metamask/utils";
18
+ var log = createModuleLogger(projectLogger, "default-gas-fee-flow");
19
+ var _getEstimateLevel, getEstimateLevel_fn, _getFeeMarketLevel, getFeeMarketLevel_fn, _getLegacyLevel, getLegacyLevel_fn;
20
+ var DefaultGasFeeFlow = class {
21
+ constructor() {
22
+ __privateAdd(this, _getEstimateLevel);
23
+ __privateAdd(this, _getFeeMarketLevel);
24
+ __privateAdd(this, _getLegacyLevel);
25
+ }
26
+ matchesTransaction(_transactionMeta) {
27
+ return true;
28
+ }
29
+ async getGasFees(request) {
30
+ const { getGasFeeControllerEstimates, transactionMeta } = request;
31
+ const { networkClientId } = transactionMeta;
32
+ const { gasEstimateType, gasFeeEstimates } = await getGasFeeControllerEstimates({ networkClientId });
33
+ if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
34
+ log("Using fee market estimates", gasFeeEstimates);
35
+ } else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {
36
+ log("Using legacy estimates", gasFeeEstimates);
37
+ } else {
38
+ throw new Error(`'No gas fee estimates available`);
39
+ }
40
+ const estimates = Object.values(GasFeeEstimateLevel).reduce(
41
+ (result, level) => ({
42
+ ...result,
43
+ [level]: __privateMethod(this, _getEstimateLevel, getEstimateLevel_fn).call(this, {
44
+ gasEstimateType,
45
+ gasFeeEstimates,
46
+ level
47
+ })
48
+ }),
49
+ {}
50
+ );
51
+ return { estimates };
52
+ }
53
+ };
54
+ _getEstimateLevel = new WeakSet();
55
+ getEstimateLevel_fn = function({
56
+ gasEstimateType,
57
+ gasFeeEstimates,
58
+ level
59
+ }) {
60
+ if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {
61
+ return __privateMethod(this, _getFeeMarketLevel, getFeeMarketLevel_fn).call(this, gasFeeEstimates, level);
62
+ }
63
+ return __privateMethod(this, _getLegacyLevel, getLegacyLevel_fn).call(this, gasFeeEstimates, level);
64
+ };
65
+ _getFeeMarketLevel = new WeakSet();
66
+ getFeeMarketLevel_fn = function(gasFeeEstimates, level) {
67
+ const maxFeePerGas = gweiDecimalToWeiHex(
68
+ gasFeeEstimates[level].suggestedMaxFeePerGas
69
+ );
70
+ const maxPriorityFeePerGas = gweiDecimalToWeiHex(
71
+ gasFeeEstimates[level].suggestedMaxPriorityFeePerGas
72
+ );
73
+ return {
74
+ maxFeePerGas,
75
+ maxPriorityFeePerGas
76
+ };
77
+ };
78
+ _getLegacyLevel = new WeakSet();
79
+ getLegacyLevel_fn = function(gasFeeEstimates, level) {
80
+ const gasPrice = gweiDecimalToWeiHex(gasFeeEstimates[level]);
81
+ return {
82
+ maxFeePerGas: gasPrice,
83
+ maxPriorityFeePerGas: gasPrice
84
+ };
85
+ };
86
+
87
+ export {
88
+ DefaultGasFeeFlow
89
+ };
90
+ //# sourceMappingURL=chunk-OF6NSLXF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/DefaultGasFeeFlow.ts"],"sourcesContent":["import type {\n LegacyGasPriceEstimate,\n GasFeeEstimates as FeeMarketGasPriceEstimate,\n} from '@metamask/gas-fee-controller';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type {\n GasFeeEstimates,\n GasFeeEstimatesForLevel,\n GasFeeFlow,\n GasFeeFlowRequest,\n GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { GasFeeEstimateLevel } from '../types';\nimport { gweiDecimalToWeiHex } from '../utils/gas-fees';\n\nconst log = createModuleLogger(projectLogger, 'default-gas-fee-flow');\n\ntype FeeMarketGetEstimateLevelRequest = {\n gasEstimateType: 'fee-market';\n gasFeeEstimates: FeeMarketGasPriceEstimate;\n level: GasFeeEstimateLevel;\n};\n\ntype LegacyGetEstimateLevelRequest = {\n gasEstimateType: 'legacy';\n gasFeeEstimates: LegacyGasPriceEstimate;\n level: GasFeeEstimateLevel;\n};\n\n/**\n * The standard implementation of a gas fee flow that obtains gas fee estimates using only the GasFeeController.\n */\nexport class DefaultGasFeeFlow implements GasFeeFlow {\n matchesTransaction(_transactionMeta: TransactionMeta): boolean {\n return true;\n }\n\n async getGasFees(request: GasFeeFlowRequest): Promise<GasFeeFlowResponse> {\n const { getGasFeeControllerEstimates, transactionMeta } = request;\n const { networkClientId } = transactionMeta;\n\n const { gasEstimateType, gasFeeEstimates } =\n await getGasFeeControllerEstimates({ networkClientId });\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n log('Using fee market estimates', gasFeeEstimates);\n } else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n log('Using legacy estimates', gasFeeEstimates);\n } else {\n throw new Error(`'No gas fee estimates available`);\n }\n\n const estimates = Object.values(GasFeeEstimateLevel).reduce(\n (result, level) => ({\n ...result,\n [level]: this.#getEstimateLevel({\n gasEstimateType,\n gasFeeEstimates,\n level,\n } as FeeMarketGetEstimateLevelRequest | LegacyGetEstimateLevelRequest),\n }),\n {} as GasFeeEstimates,\n );\n\n return { estimates };\n }\n\n #getEstimateLevel({\n gasEstimateType,\n gasFeeEstimates,\n level,\n }:\n | FeeMarketGetEstimateLevelRequest\n | LegacyGetEstimateLevelRequest): GasFeeEstimatesForLevel {\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n return this.#getFeeMarketLevel(gasFeeEstimates, level);\n }\n\n return this.#getLegacyLevel(gasFeeEstimates, level);\n }\n\n #getFeeMarketLevel(\n gasFeeEstimates: FeeMarketGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): GasFeeEstimatesForLevel {\n const maxFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxFeePerGas,\n );\n\n const maxPriorityFeePerGas = gweiDecimalToWeiHex(\n gasFeeEstimates[level].suggestedMaxPriorityFeePerGas,\n );\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n }\n\n #getLegacyLevel(\n gasFeeEstimates: LegacyGasPriceEstimate,\n level: GasFeeEstimateLevel,\n ): GasFeeEstimatesForLevel {\n const gasPrice = gweiDecimalToWeiHex(gasFeeEstimates[level]);\n\n return {\n maxFeePerGas: gasPrice,\n maxPriorityFeePerGas: gasPrice,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAIA,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAcnC,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAnBpE;AAoCO,IAAM,oBAAN,MAA8C;AAAA,EAA9C;AAmCL;AAcA;AAkBA;AAAA;AAAA,EAlEA,mBAAmB,kBAA4C;AAC7D,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,SAAyD;AACxE,UAAM,EAAE,8BAA8B,gBAAgB,IAAI;AAC1D,UAAM,EAAE,gBAAgB,IAAI;AAE5B,UAAM,EAAE,iBAAiB,gBAAgB,IACvC,MAAM,6BAA6B,EAAE,gBAAgB,CAAC;AAExD,QAAI,oBAAoB,mBAAmB,YAAY;AACrD,UAAI,8BAA8B,eAAe;AAAA,IACnD,WAAW,oBAAoB,mBAAmB,QAAQ;AACxD,UAAI,0BAA0B,eAAe;AAAA,IAC/C,OAAO;AACL,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AAEA,UAAM,YAAY,OAAO,OAAO,m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