@metamask-previews/transaction-controller 36.1.0-preview-367cb1da → 36.1.0-preview-cf09c0a

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 (479) hide show
  1. package/dist/TransactionController.cjs +2026 -0
  2. package/dist/TransactionController.cjs.map +1 -0
  3. package/dist/{types/TransactionController.d.ts → TransactionController.d.cts} +15 -15
  4. package/dist/TransactionController.d.cts.map +1 -0
  5. package/dist/TransactionController.d.mts +827 -0
  6. package/dist/TransactionController.d.mts.map +1 -0
  7. package/dist/TransactionController.mjs +2027 -44
  8. package/dist/TransactionController.mjs.map +1 -1
  9. package/dist/constants.cjs +170 -0
  10. package/dist/constants.cjs.map +1 -0
  11. package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
  12. package/dist/constants.d.cts.map +1 -0
  13. package/dist/constants.d.mts +143 -0
  14. package/dist/constants.d.mts.map +1 -0
  15. package/dist/constants.mjs +165 -18
  16. package/dist/constants.mjs.map +1 -1
  17. package/dist/errors.cjs +30 -0
  18. package/dist/{chunk-HMOSP33F.js.map → errors.cjs.map} +1 -1
  19. package/dist/{types/errors.d.ts → errors.d.cts} +2 -2
  20. package/dist/errors.d.cts.map +1 -0
  21. package/dist/errors.d.mts +15 -0
  22. package/dist/errors.d.mts.map +1 -0
  23. package/dist/errors.mjs +22 -14
  24. package/dist/errors.mjs.map +1 -1
  25. package/dist/gas-flows/DefaultGasFeeFlow.cjs +87 -0
  26. package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -0
  27. package/dist/{types/gas-flows/DefaultGasFeeFlow.d.ts → gas-flows/DefaultGasFeeFlow.d.cts} +2 -2
  28. package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -0
  29. package/dist/gas-flows/DefaultGasFeeFlow.d.mts +10 -0
  30. package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -0
  31. package/dist/gas-flows/DefaultGasFeeFlow.mjs +81 -13
  32. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
  33. package/dist/gas-flows/LineaGasFeeFlow.cjs +102 -0
  34. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -0
  35. package/dist/{types/gas-flows/LineaGasFeeFlow.d.ts → gas-flows/LineaGasFeeFlow.d.cts} +2 -2
  36. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -0
  37. package/dist/gas-flows/LineaGasFeeFlow.d.mts +12 -0
  38. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -0
  39. package/dist/gas-flows/LineaGasFeeFlow.mjs +96 -14
  40. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  41. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +29 -0
  42. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -0
  43. package/dist/{types/gas-flows/OptimismLayer1GasFeeFlow.d.ts → gas-flows/OptimismLayer1GasFeeFlow.d.cts} +3 -3
  44. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -0
  45. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +10 -0
  46. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -0
  47. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +24 -10
  48. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
  49. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +92 -0
  50. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -0
  51. package/dist/{types/gas-flows/OracleLayer1GasFeeFlow.d.ts → gas-flows/OracleLayer1GasFeeFlow.d.cts} +3 -3
  52. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -0
  53. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +12 -0
  54. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -0
  55. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs +88 -7
  56. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
  57. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +21 -0
  58. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -0
  59. package/dist/{types/gas-flows/ScrollLayer1GasFeeFlow.d.ts → gas-flows/ScrollLayer1GasFeeFlow.d.cts} +3 -3
  60. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -0
  61. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +10 -0
  62. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -0
  63. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +16 -10
  64. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
  65. package/dist/gas-flows/TestGasFeeFlow.cjs +73 -0
  66. package/dist/{chunk-FMRLPVFZ.mjs.map → gas-flows/TestGasFeeFlow.cjs.map} +1 -1
  67. package/dist/{types/gas-flows/TestGasFeeFlow.d.ts → gas-flows/TestGasFeeFlow.d.cts} +2 -2
  68. package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -0
  69. package/dist/gas-flows/TestGasFeeFlow.d.mts +12 -0
  70. package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -0
  71. package/dist/gas-flows/TestGasFeeFlow.mjs +67 -7
  72. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
  73. package/dist/helpers/EtherscanRemoteTransactionSource.cjs +149 -0
  74. package/dist/helpers/EtherscanRemoteTransactionSource.cjs.map +1 -0
  75. package/dist/{types/helpers/EtherscanRemoteTransactionSource.d.ts → helpers/EtherscanRemoteTransactionSource.d.cts} +3 -3
  76. package/dist/helpers/EtherscanRemoteTransactionSource.d.cts.map +1 -0
  77. package/dist/helpers/EtherscanRemoteTransactionSource.d.mts +15 -0
  78. package/dist/helpers/EtherscanRemoteTransactionSource.d.mts.map +1 -0
  79. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +147 -10
  80. package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -1
  81. package/dist/helpers/GasFeePoller.cjs +185 -0
  82. package/dist/helpers/GasFeePoller.cjs.map +1 -0
  83. package/dist/{types/helpers/GasFeePoller.d.ts → helpers/GasFeePoller.d.cts} +7 -7
  84. package/dist/helpers/GasFeePoller.d.cts.map +1 -0
  85. package/dist/helpers/GasFeePoller.d.mts +35 -0
  86. package/dist/helpers/GasFeePoller.d.mts.map +1 -0
  87. package/dist/helpers/GasFeePoller.mjs +183 -10
  88. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  89. package/dist/helpers/IncomingTransactionHelper.cjs +199 -0
  90. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -0
  91. package/dist/{types/helpers/IncomingTransactionHelper.d.ts → helpers/IncomingTransactionHelper.d.cts} +6 -6
  92. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -0
  93. package/dist/helpers/IncomingTransactionHelper.d.mts +40 -0
  94. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -0
  95. package/dist/helpers/IncomingTransactionHelper.mjs +190 -7
  96. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  97. package/dist/helpers/MultichainTrackingHelper.cjs +284 -0
  98. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -0
  99. package/dist/{types/helpers/MultichainTrackingHelper.d.ts → helpers/MultichainTrackingHelper.d.cts} +8 -8
  100. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -0
  101. package/dist/helpers/MultichainTrackingHelper.d.mts +76 -0
  102. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -0
  103. package/dist/helpers/MultichainTrackingHelper.mjs +282 -11
  104. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  105. package/dist/helpers/PendingTransactionTracker.cjs +328 -0
  106. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
  107. package/dist/{types/helpers/PendingTransactionTracker.d.ts → helpers/PendingTransactionTracker.d.cts} +5 -5
  108. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -0
  109. package/dist/helpers/PendingTransactionTracker.d.mts +42 -0
  110. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -0
  111. package/dist/helpers/PendingTransactionTracker.mjs +320 -8
  112. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  113. package/dist/index.cjs +28 -0
  114. package/dist/index.cjs.map +1 -0
  115. package/dist/{types/index.d.ts → index.d.cts} +10 -10
  116. package/dist/index.d.cts.map +1 -0
  117. package/dist/index.d.mts +10 -0
  118. package/dist/index.d.mts.map +1 -0
  119. package/dist/index.mjs +6 -76
  120. package/dist/index.mjs.map +1 -1
  121. package/dist/logger.cjs +9 -0
  122. package/dist/logger.cjs.map +1 -0
  123. package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
  124. package/dist/logger.d.cts.map +1 -0
  125. package/dist/logger.d.mts +6 -0
  126. package/dist/logger.d.mts.map +1 -0
  127. package/dist/logger.mjs +5 -11
  128. package/dist/logger.mjs.map +1 -1
  129. package/dist/types.cjs +308 -0
  130. package/dist/types.cjs.map +1 -0
  131. package/dist/{types/types.d.ts → types.d.cts} +7 -7
  132. package/dist/types.d.cts.map +1 -0
  133. package/dist/types.d.mts +999 -0
  134. package/dist/types.d.mts.map +1 -0
  135. package/dist/types.mjs +304 -23
  136. package/dist/types.mjs.map +1 -1
  137. package/dist/utils/etherscan.cjs +111 -0
  138. package/dist/utils/etherscan.cjs.map +1 -0
  139. package/dist/{types/utils/etherscan.d.ts → utils/etherscan.d.cts} +2 -2
  140. package/dist/utils/etherscan.d.cts.map +1 -0
  141. package/dist/utils/etherscan.d.mts +71 -0
  142. package/dist/utils/etherscan.d.mts.map +1 -0
  143. package/dist/utils/etherscan.mjs +104 -13
  144. package/dist/utils/etherscan.mjs.map +1 -1
  145. package/dist/utils/external-transactions.cjs +36 -0
  146. package/dist/utils/external-transactions.cjs.map +1 -0
  147. package/dist/{types/utils/external-transactions.d.ts → utils/external-transactions.d.cts} +2 -2
  148. package/dist/utils/external-transactions.d.cts.map +1 -0
  149. package/dist/utils/external-transactions.d.mts +10 -0
  150. package/dist/utils/external-transactions.d.mts.map +1 -0
  151. package/dist/utils/external-transactions.mjs +31 -8
  152. package/dist/utils/external-transactions.mjs.map +1 -1
  153. package/dist/utils/gas-fees.cjs +208 -0
  154. package/dist/utils/gas-fees.cjs.map +1 -0
  155. package/dist/{types/utils/gas-fees.d.ts → utils/gas-fees.d.cts} +5 -5
  156. package/dist/utils/gas-fees.d.cts.map +1 -0
  157. package/dist/utils/gas-fees.d.mts +26 -0
  158. package/dist/utils/gas-fees.d.mts.map +1 -0
  159. package/dist/utils/gas-fees.mjs +202 -15
  160. package/dist/utils/gas-fees.mjs.map +1 -1
  161. package/dist/utils/gas-flow.cjs +76 -0
  162. package/dist/utils/gas-flow.cjs.map +1 -0
  163. package/dist/{types/utils/gas-flow.d.ts → utils/gas-flow.d.cts} +5 -5
  164. package/dist/utils/gas-flow.d.cts.map +1 -0
  165. package/dist/utils/gas-flow.d.mts +26 -0
  166. package/dist/utils/gas-flow.d.mts.map +1 -0
  167. package/dist/utils/gas-flow.mjs +70 -10
  168. package/dist/utils/gas-flow.mjs.map +1 -1
  169. package/dist/utils/gas.cjs +112 -0
  170. package/dist/utils/gas.cjs.map +1 -0
  171. package/dist/{types/utils/gas.d.ts → utils/gas.d.cts} +4 -4
  172. package/dist/utils/gas.d.cts.map +1 -0
  173. package/dist/utils/gas.d.mts +28 -0
  174. package/dist/utils/gas.d.mts.map +1 -0
  175. package/dist/utils/gas.mjs +105 -19
  176. package/dist/utils/gas.mjs.map +1 -1
  177. package/dist/utils/history.cjs +164 -0
  178. package/dist/utils/history.cjs.map +1 -0
  179. package/dist/{types/utils/history.d.ts → utils/history.d.cts} +2 -2
  180. package/dist/utils/history.d.cts.map +1 -0
  181. package/dist/utils/history.d.mts +29 -0
  182. package/dist/utils/history.d.mts.map +1 -0
  183. package/dist/utils/history.mjs +163 -13
  184. package/dist/utils/history.mjs.map +1 -1
  185. package/dist/utils/layer1-gas-fee-flow.cjs +59 -0
  186. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -0
  187. package/dist/{types/utils/layer1-gas-fee-flow.d.ts → utils/layer1-gas-fee-flow.d.cts} +4 -4
  188. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -0
  189. package/dist/utils/layer1-gas-fee-flow.d.mts +25 -0
  190. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -0
  191. package/dist/utils/layer1-gas-fee-flow.mjs +53 -10
  192. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  193. package/dist/utils/nonce.cjs +66 -0
  194. package/dist/utils/nonce.cjs.map +1 -0
  195. package/dist/{types/utils/nonce.d.ts → utils/nonce.d.cts} +3 -3
  196. package/dist/utils/nonce.d.cts.map +1 -0
  197. package/dist/utils/nonce.d.mts +21 -0
  198. package/dist/utils/nonce.d.mts.map +1 -0
  199. package/dist/utils/nonce.mjs +60 -10
  200. package/dist/utils/nonce.mjs.map +1 -1
  201. package/dist/utils/retry.cjs +89 -0
  202. package/dist/utils/retry.cjs.map +1 -0
  203. package/dist/{types/utils/retry.d.ts → utils/retry.d.cts} +3 -3
  204. package/dist/utils/retry.d.cts.map +1 -0
  205. package/dist/utils/retry.d.mts +11 -0
  206. package/dist/utils/retry.d.mts.map +1 -0
  207. package/dist/utils/retry.mjs +84 -7
  208. package/dist/utils/retry.mjs.map +1 -1
  209. package/dist/utils/simulation-api.cjs +72 -0
  210. package/dist/utils/simulation-api.cjs.map +1 -0
  211. package/dist/{types/utils/simulation-api.d.ts → utils/simulation-api.d.cts} +2 -2
  212. package/dist/utils/simulation-api.d.cts.map +1 -0
  213. package/dist/utils/simulation-api.d.mts +107 -0
  214. package/dist/utils/simulation-api.d.mts.map +1 -0
  215. package/dist/utils/simulation-api.mjs +67 -10
  216. package/dist/utils/simulation-api.mjs.map +1 -1
  217. package/dist/utils/simulation.cjs +443 -0
  218. package/dist/utils/simulation.cjs.map +1 -0
  219. package/dist/{types/utils/simulation.d.ts → utils/simulation.d.cts} +6 -6
  220. package/dist/utils/simulation.d.cts.map +1 -0
  221. package/dist/utils/simulation.d.mts +46 -0
  222. package/dist/utils/simulation.d.mts.map +1 -0
  223. package/dist/utils/simulation.mjs +436 -15
  224. package/dist/utils/simulation.mjs.map +1 -1
  225. package/dist/utils/swaps.cjs +309 -0
  226. package/dist/utils/swaps.cjs.map +1 -0
  227. package/dist/{types/utils/swaps.d.ts → utils/swaps.d.cts} +5 -5
  228. package/dist/utils/swaps.d.cts.map +1 -0
  229. package/dist/utils/swaps.d.mts +84 -0
  230. package/dist/utils/swaps.d.mts.map +1 -0
  231. package/dist/utils/swaps.mjs +303 -22
  232. package/dist/utils/swaps.mjs.map +1 -1
  233. package/dist/utils/transaction-type.cjs +115 -0
  234. package/dist/utils/transaction-type.cjs.map +1 -0
  235. package/dist/{types/utils/transaction-type.d.ts → utils/transaction-type.d.cts} +3 -3
  236. package/dist/utils/transaction-type.d.cts.map +1 -0
  237. package/dist/utils/transaction-type.d.mts +14 -0
  238. package/dist/utils/transaction-type.d.mts.map +1 -0
  239. package/dist/utils/transaction-type.mjs +110 -10
  240. package/dist/utils/transaction-type.mjs.map +1 -1
  241. package/dist/utils/utils.cjs +151 -0
  242. package/dist/utils/utils.cjs.map +1 -0
  243. package/dist/{types/utils/utils.d.ts → utils/utils.d.cts} +2 -2
  244. package/dist/utils/utils.d.cts.map +1 -0
  245. package/dist/utils/utils.d.mts +52 -0
  246. package/dist/utils/utils.d.mts.map +1 -0
  247. package/dist/utils/utils.mjs +139 -21
  248. package/dist/utils/utils.mjs.map +1 -1
  249. package/dist/utils/validation.cjs +267 -0
  250. package/dist/{chunk-DIPBZJ5G.js.map → utils/validation.cjs.map} +1 -1
  251. package/dist/{types/utils/validation.d.ts → utils/validation.d.cts} +2 -2
  252. package/dist/utils/validation.d.cts.map +1 -0
  253. package/dist/utils/validation.d.mts +20 -0
  254. package/dist/utils/validation.d.mts.map +1 -0
  255. package/dist/utils/validation.mjs +261 -11
  256. package/dist/utils/validation.mjs.map +1 -1
  257. package/package.json +12 -7
  258. package/dist/TransactionController.js +0 -46
  259. package/dist/TransactionController.js.map +0 -1
  260. package/dist/chunk-2XKEAKQG.js +0 -55
  261. package/dist/chunk-2XKEAKQG.js.map +0 -1
  262. package/dist/chunk-3AVRGHUO.mjs +0 -360
  263. package/dist/chunk-3AVRGHUO.mjs.map +0 -1
  264. package/dist/chunk-3ZV5YEUV.mjs +0 -239
  265. package/dist/chunk-3ZV5YEUV.mjs.map +0 -1
  266. package/dist/chunk-4SYKJQLR.js +0 -228
  267. package/dist/chunk-4SYKJQLR.js.map +0 -1
  268. package/dist/chunk-4V4XIPCI.mjs +0 -338
  269. package/dist/chunk-4V4XIPCI.mjs.map +0 -1
  270. package/dist/chunk-4ZOE2ACZ.js +0 -67
  271. package/dist/chunk-4ZOE2ACZ.js.map +0 -1
  272. package/dist/chunk-5G6OHAXI.mjs +0 -137
  273. package/dist/chunk-5G6OHAXI.mjs.map +0 -1
  274. package/dist/chunk-5QVDIVJH.js +0 -68
  275. package/dist/chunk-5QVDIVJH.js.map +0 -1
  276. package/dist/chunk-6DDVVUJC.mjs +0 -50
  277. package/dist/chunk-6DDVVUJC.mjs.map +0 -1
  278. package/dist/chunk-6DODV6OV.js +0 -390
  279. package/dist/chunk-6DODV6OV.js.map +0 -1
  280. package/dist/chunk-6JO6EU6Z.mjs +0 -67
  281. package/dist/chunk-6JO6EU6Z.mjs.map +0 -1
  282. package/dist/chunk-6OLJWLKK.js +0 -338
  283. package/dist/chunk-6OLJWLKK.js.map +0 -1
  284. package/dist/chunk-7LXE4KHV.js +0 -40
  285. package/dist/chunk-7LXE4KHV.js.map +0 -1
  286. package/dist/chunk-7M2R5AHC.mjs +0 -390
  287. package/dist/chunk-7M2R5AHC.mjs.map +0 -1
  288. package/dist/chunk-7NMV2NPM.js +0 -172
  289. package/dist/chunk-7NMV2NPM.js.map +0 -1
  290. package/dist/chunk-ASTXVFGJ.mjs +0 -92
  291. package/dist/chunk-ASTXVFGJ.mjs.map +0 -1
  292. package/dist/chunk-CKRPGICI.js +0 -2499
  293. package/dist/chunk-CKRPGICI.js.map +0 -1
  294. package/dist/chunk-DIPBZJ5G.js +0 -201
  295. package/dist/chunk-EGQCE3FK.mjs +0 -85
  296. package/dist/chunk-EGQCE3FK.mjs.map +0 -1
  297. package/dist/chunk-EHIRNR33.mjs +0 -228
  298. package/dist/chunk-EHIRNR33.mjs.map +0 -1
  299. package/dist/chunk-EKJXGERC.mjs +0 -172
  300. package/dist/chunk-EKJXGERC.mjs.map +0 -1
  301. package/dist/chunk-FG74Z3F5.mjs +0 -102
  302. package/dist/chunk-FG74Z3F5.mjs.map +0 -1
  303. package/dist/chunk-FMRLPVFZ.mjs +0 -66
  304. package/dist/chunk-FRKQ3Z2L.mjs +0 -40
  305. package/dist/chunk-FRKQ3Z2L.mjs.map +0 -1
  306. package/dist/chunk-H5MYUJHR.js +0 -92
  307. package/dist/chunk-H5MYUJHR.js.map +0 -1
  308. package/dist/chunk-HAW3IWCX.mjs +0 -201
  309. package/dist/chunk-HAW3IWCX.mjs.map +0 -1
  310. package/dist/chunk-HMOSP33F.js +0 -36
  311. package/dist/chunk-HQSNKCXI.mjs +0 -36
  312. package/dist/chunk-HQSNKCXI.mjs.map +0 -1
  313. package/dist/chunk-JIFPK37W.mjs +0 -257
  314. package/dist/chunk-JIFPK37W.mjs.map +0 -1
  315. package/dist/chunk-JOQK7A5G.mjs +0 -68
  316. package/dist/chunk-JOQK7A5G.mjs.map +0 -1
  317. package/dist/chunk-K4KOSAGM.mjs +0 -61
  318. package/dist/chunk-K4KOSAGM.mjs.map +0 -1
  319. package/dist/chunk-KG4UW4K4.mjs +0 -88
  320. package/dist/chunk-KG4UW4K4.mjs.map +0 -1
  321. package/dist/chunk-KT6UAKBB.js +0 -61
  322. package/dist/chunk-KT6UAKBB.js.map +0 -1
  323. package/dist/chunk-KTGMNUTQ.js +0 -106
  324. package/dist/chunk-KTGMNUTQ.js.map +0 -1
  325. package/dist/chunk-NNCUD3QF.js +0 -360
  326. package/dist/chunk-NNCUD3QF.js.map +0 -1
  327. package/dist/chunk-NOHEXQ7Y.mjs +0 -55
  328. package/dist/chunk-NOHEXQ7Y.mjs.map +0 -1
  329. package/dist/chunk-NYKRCWBG.js +0 -31
  330. package/dist/chunk-NYKRCWBG.js.map +0 -1
  331. package/dist/chunk-O6ZZVIFH.mjs +0 -176
  332. package/dist/chunk-O6ZZVIFH.mjs.map +0 -1
  333. package/dist/chunk-ORWR5LSG.js +0 -112
  334. package/dist/chunk-ORWR5LSG.js.map +0 -1
  335. package/dist/chunk-PRUNMTRD.js +0 -50
  336. package/dist/chunk-PRUNMTRD.js.map +0 -1
  337. package/dist/chunk-Q44JQKVP.mjs +0 -112
  338. package/dist/chunk-Q44JQKVP.mjs.map +0 -1
  339. package/dist/chunk-QKV7E5BO.js +0 -257
  340. package/dist/chunk-QKV7E5BO.js.map +0 -1
  341. package/dist/chunk-REFVF44I.mjs +0 -2499
  342. package/dist/chunk-REFVF44I.mjs.map +0 -1
  343. package/dist/chunk-RGWMNCTE.mjs +0 -121
  344. package/dist/chunk-RGWMNCTE.mjs.map +0 -1
  345. package/dist/chunk-RHDPOIS4.js +0 -239
  346. package/dist/chunk-RHDPOIS4.js.map +0 -1
  347. package/dist/chunk-S6VGOPUY.js +0 -14
  348. package/dist/chunk-S6VGOPUY.js.map +0 -1
  349. package/dist/chunk-SD6CWFDF.js +0 -88
  350. package/dist/chunk-SD6CWFDF.js.map +0 -1
  351. package/dist/chunk-SMC5Q6ZH.mjs +0 -120
  352. package/dist/chunk-SMC5Q6ZH.mjs.map +0 -1
  353. package/dist/chunk-TIE3CPF7.js +0 -120
  354. package/dist/chunk-TIE3CPF7.js.map +0 -1
  355. package/dist/chunk-TJMQEH57.js +0 -66
  356. package/dist/chunk-TJMQEH57.js.map +0 -1
  357. package/dist/chunk-UGN7PBON.js +0 -176
  358. package/dist/chunk-UGN7PBON.js.map +0 -1
  359. package/dist/chunk-UHSRHP55.mjs +0 -106
  360. package/dist/chunk-UHSRHP55.mjs.map +0 -1
  361. package/dist/chunk-UQQWZT6C.mjs +0 -14
  362. package/dist/chunk-UQQWZT6C.mjs.map +0 -1
  363. package/dist/chunk-V2OWJ7RY.mjs +0 -226
  364. package/dist/chunk-V2OWJ7RY.mjs.map +0 -1
  365. package/dist/chunk-V72C4MCR.js +0 -137
  366. package/dist/chunk-V72C4MCR.js.map +0 -1
  367. package/dist/chunk-VEVVBHP3.mjs +0 -31
  368. package/dist/chunk-VEVVBHP3.mjs.map +0 -1
  369. package/dist/chunk-WFRHYZIO.js +0 -226
  370. package/dist/chunk-WFRHYZIO.js.map +0 -1
  371. package/dist/chunk-WR5F34OW.js +0 -23
  372. package/dist/chunk-WR5F34OW.js.map +0 -1
  373. package/dist/chunk-XUI43LEZ.mjs +0 -30
  374. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  375. package/dist/chunk-XVYXRCRL.js +0 -85
  376. package/dist/chunk-XVYXRCRL.js.map +0 -1
  377. package/dist/chunk-YAFENU6Y.js +0 -121
  378. package/dist/chunk-YAFENU6Y.js.map +0 -1
  379. package/dist/chunk-YVCX6Z75.js +0 -102
  380. package/dist/chunk-YVCX6Z75.js.map +0 -1
  381. package/dist/chunk-Z4BLTVTB.js +0 -30
  382. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  383. package/dist/chunk-Z4GV3YQQ.mjs +0 -23
  384. package/dist/chunk-Z4GV3YQQ.mjs.map +0 -1
  385. package/dist/constants.js +0 -20
  386. package/dist/constants.js.map +0 -1
  387. package/dist/errors.js +0 -15
  388. package/dist/errors.js.map +0 -1
  389. package/dist/gas-flows/DefaultGasFeeFlow.js +0 -15
  390. package/dist/gas-flows/DefaultGasFeeFlow.js.map +0 -1
  391. package/dist/gas-flows/LineaGasFeeFlow.js +0 -16
  392. package/dist/gas-flows/LineaGasFeeFlow.js.map +0 -1
  393. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js +0 -11
  394. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
  395. package/dist/gas-flows/OracleLayer1GasFeeFlow.js +0 -9
  396. package/dist/gas-flows/OracleLayer1GasFeeFlow.js.map +0 -1
  397. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js +0 -11
  398. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js.map +0 -1
  399. package/dist/gas-flows/TestGasFeeFlow.js +0 -9
  400. package/dist/gas-flows/TestGasFeeFlow.js.map +0 -1
  401. package/dist/helpers/EtherscanRemoteTransactionSource.js +0 -12
  402. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +0 -1
  403. package/dist/helpers/GasFeePoller.js +0 -12
  404. package/dist/helpers/GasFeePoller.js.map +0 -1
  405. package/dist/helpers/IncomingTransactionHelper.js +0 -9
  406. package/dist/helpers/IncomingTransactionHelper.js.map +0 -1
  407. package/dist/helpers/MultichainTrackingHelper.js +0 -13
  408. package/dist/helpers/MultichainTrackingHelper.js.map +0 -1
  409. package/dist/helpers/PendingTransactionTracker.js +0 -10
  410. package/dist/helpers/PendingTransactionTracker.js.map +0 -1
  411. package/dist/index.js +0 -77
  412. package/dist/index.js.map +0 -1
  413. package/dist/logger.js +0 -12
  414. package/dist/logger.js.map +0 -1
  415. package/dist/tsconfig.build.tsbuildinfo +0 -1
  416. package/dist/types/TransactionController.d.ts.map +0 -1
  417. package/dist/types/constants.d.ts.map +0 -1
  418. package/dist/types/errors.d.ts.map +0 -1
  419. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  420. package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  421. package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
  422. package/dist/types/gas-flows/OracleLayer1GasFeeFlow.d.ts.map +0 -1
  423. package/dist/types/gas-flows/ScrollLayer1GasFeeFlow.d.ts.map +0 -1
  424. package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +0 -1
  425. package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
  426. package/dist/types/helpers/GasFeePoller.d.ts.map +0 -1
  427. package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +0 -1
  428. package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  429. package/dist/types/helpers/PendingTransactionTracker.d.ts.map +0 -1
  430. package/dist/types/index.d.ts.map +0 -1
  431. package/dist/types/logger.d.ts.map +0 -1
  432. package/dist/types/types.d.ts.map +0 -1
  433. package/dist/types/utils/etherscan.d.ts.map +0 -1
  434. package/dist/types/utils/external-transactions.d.ts.map +0 -1
  435. package/dist/types/utils/gas-fees.d.ts.map +0 -1
  436. package/dist/types/utils/gas-flow.d.ts.map +0 -1
  437. package/dist/types/utils/gas.d.ts.map +0 -1
  438. package/dist/types/utils/history.d.ts.map +0 -1
  439. package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +0 -1
  440. package/dist/types/utils/nonce.d.ts.map +0 -1
  441. package/dist/types/utils/retry.d.ts.map +0 -1
  442. package/dist/types/utils/simulation-api.d.ts.map +0 -1
  443. package/dist/types/utils/simulation.d.ts.map +0 -1
  444. package/dist/types/utils/swaps.d.ts.map +0 -1
  445. package/dist/types/utils/transaction-type.d.ts.map +0 -1
  446. package/dist/types/utils/utils.d.ts.map +0 -1
  447. package/dist/types/utils/validation.d.ts.map +0 -1
  448. package/dist/types.js +0 -24
  449. package/dist/types.js.map +0 -1
  450. package/dist/utils/etherscan.js +0 -14
  451. package/dist/utils/etherscan.js.map +0 -1
  452. package/dist/utils/external-transactions.js +0 -9
  453. package/dist/utils/external-transactions.js.map +0 -1
  454. package/dist/utils/gas-fees.js +0 -16
  455. package/dist/utils/gas-fees.js.map +0 -1
  456. package/dist/utils/gas-flow.js +0 -11
  457. package/dist/utils/gas-flow.js.map +0 -1
  458. package/dist/utils/gas.js +0 -20
  459. package/dist/utils/gas.js.map +0 -1
  460. package/dist/utils/history.js +0 -14
  461. package/dist/utils/history.js.map +0 -1
  462. package/dist/utils/layer1-gas-fee-flow.js +0 -11
  463. package/dist/utils/layer1-gas-fee-flow.js.map +0 -1
  464. package/dist/utils/nonce.js +0 -11
  465. package/dist/utils/nonce.js.map +0 -1
  466. package/dist/utils/retry.js +0 -8
  467. package/dist/utils/retry.js.map +0 -1
  468. package/dist/utils/simulation-api.js +0 -11
  469. package/dist/utils/simulation-api.js.map +0 -1
  470. package/dist/utils/simulation.js +0 -17
  471. package/dist/utils/simulation.js.map +0 -1
  472. package/dist/utils/swaps.js +0 -24
  473. package/dist/utils/swaps.js.map +0 -1
  474. package/dist/utils/transaction-type.js +0 -11
  475. package/dist/utils/transaction-type.js.map +0 -1
  476. package/dist/utils/utils.js +0 -23
  477. package/dist/utils/utils.js.map +0 -1
  478. package/dist/utils/validation.js +0 -12
  479. package/dist/utils/validation.js.map +0 -1
@@ -1,2499 +0,0 @@
1
- import {
2
- getAndFormatTransactionsForNonceTracker,
3
- getNextNonce
4
- } from "./chunk-6DDVVUJC.mjs";
5
- import {
6
- getTransactionParamsWithIncreasedGasFee
7
- } from "./chunk-JOQK7A5G.mjs";
8
- import {
9
- getSimulationData
10
- } from "./chunk-3AVRGHUO.mjs";
11
- import {
12
- determineTransactionType
13
- } from "./chunk-KG4UW4K4.mjs";
14
- import {
15
- validateTransactionOrigin,
16
- validateTxParams
17
- } from "./chunk-HAW3IWCX.mjs";
18
- import {
19
- TestGasFeeFlow
20
- } from "./chunk-FMRLPVFZ.mjs";
21
- import {
22
- validateConfirmedExternalTransaction
23
- } from "./chunk-FRKQ3Z2L.mjs";
24
- import {
25
- addGasBuffer,
26
- estimateGas,
27
- updateGas
28
- } from "./chunk-5G6OHAXI.mjs";
29
- import {
30
- addInitialHistorySnapshot,
31
- updateTransactionHistory
32
- } from "./chunk-SMC5Q6ZH.mjs";
33
- import {
34
- IncomingTransactionHelper
35
- } from "./chunk-3ZV5YEUV.mjs";
36
- import {
37
- MultichainTrackingHelper
38
- } from "./chunk-4V4XIPCI.mjs";
39
- import {
40
- PendingTransactionTracker
41
- } from "./chunk-7M2R5AHC.mjs";
42
- import {
43
- LineaGasFeeFlow
44
- } from "./chunk-RGWMNCTE.mjs";
45
- import {
46
- DefaultGasFeeFlow
47
- } from "./chunk-Q44JQKVP.mjs";
48
- import {
49
- updateGasFees
50
- } from "./chunk-V2OWJ7RY.mjs";
51
- import {
52
- updatePostTransactionBalance,
53
- updateSwapsTransaction
54
- } from "./chunk-JIFPK37W.mjs";
55
- import {
56
- isEIP1559Transaction,
57
- normalizeGasFeeValues,
58
- normalizeTransactionParams,
59
- normalizeTxError,
60
- validateGasValues,
61
- validateIfTransactionUnapproved
62
- } from "./chunk-UHSRHP55.mjs";
63
- import {
64
- OptimismLayer1GasFeeFlow
65
- } from "./chunk-VEVVBHP3.mjs";
66
- import {
67
- ScrollLayer1GasFeeFlow
68
- } from "./chunk-Z4GV3YQQ.mjs";
69
- import {
70
- EtherscanRemoteTransactionSource
71
- } from "./chunk-EKJXGERC.mjs";
72
- import {
73
- GasFeePoller
74
- } from "./chunk-EHIRNR33.mjs";
75
- import {
76
- getTransactionLayer1GasFee,
77
- updateTransactionLayer1GasFee
78
- } from "./chunk-NOHEXQ7Y.mjs";
79
- import {
80
- getGasFeeFlow
81
- } from "./chunk-6JO6EU6Z.mjs";
82
- import {
83
- projectLogger
84
- } from "./chunk-UQQWZT6C.mjs";
85
- import {
86
- __privateAdd,
87
- __privateGet,
88
- __privateMethod,
89
- __privateSet
90
- } from "./chunk-XUI43LEZ.mjs";
91
-
92
- // src/TransactionController.ts
93
- import { Hardfork, Common } from "@ethereumjs/common";
94
- import { TransactionFactory } from "@ethereumjs/tx";
95
- import { bufferToHex } from "@ethereumjs/util";
96
- import { BaseController } from "@metamask/base-controller";
97
- import {
98
- query,
99
- ApprovalType,
100
- ORIGIN_METAMASK,
101
- convertHexToDecimal,
102
- isInfuraNetworkType
103
- } from "@metamask/controller-utils";
104
- import EthQuery from "@metamask/eth-query";
105
- import { NetworkClientType } from "@metamask/network-controller";
106
- import { NonceTracker } from "@metamask/nonce-tracker";
107
- import { errorCodes, rpcErrors, providerErrors } from "@metamask/rpc-errors";
108
- import { add0x } from "@metamask/utils";
109
- import { Mutex } from "async-mutex";
110
- import { MethodRegistry } from "eth-method-registry";
111
- import { EventEmitter } from "events";
112
- import { cloneDeep, mapValues, merge, pickBy, sortBy, isEqual } from "lodash";
113
- import { v1 as random } from "uuid";
114
- var metadata = {
115
- transactions: {
116
- persist: true,
117
- anonymous: false
118
- },
119
- methodData: {
120
- persist: true,
121
- anonymous: false
122
- },
123
- lastFetchedBlockNumbers: {
124
- persist: true,
125
- anonymous: false
126
- }
127
- };
128
- var HARDFORK = Hardfork.London;
129
- var CANCEL_RATE = 1.1;
130
- var SPEED_UP_RATE = 1.1;
131
- var controllerName = "TransactionController";
132
- var ApprovalState = /* @__PURE__ */ ((ApprovalState2) => {
133
- ApprovalState2["Approved"] = "approved";
134
- ApprovalState2["NotApproved"] = "not-approved";
135
- ApprovalState2["SkippedViaBeforePublishHook"] = "skipped-via-before-publish-hook";
136
- return ApprovalState2;
137
- })(ApprovalState || {});
138
- function getDefaultTransactionControllerState() {
139
- return {
140
- methodData: {},
141
- transactions: [],
142
- lastFetchedBlockNumbers: {}
143
- };
144
- }
145
- var _internalEvents, _incomingTransactionOptions, _pendingTransactionOptions, _trace, _transactionHistoryLimit, _isSimulationEnabled, _testGasFeeFlows, _multichainTrackingHelper, _retryTransaction, retryTransaction_fn, _createNonceTracker, createNonceTracker_fn, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn, _createPendingTransactionTracker, createPendingTransactionTracker_fn, _checkForPendingTransactionAndStartPolling, _stopAllTracking, stopAllTracking_fn, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn, _addIncomingTransactionHelperListeners, addIncomingTransactionHelperListeners_fn, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn, _addPendingTransactionTrackerListeners, addPendingTransactionTrackerListeners_fn, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn, _getGasFeeFlows, getGasFeeFlows_fn, _getLayer1GasFeeFlows, getLayer1GasFeeFlows_fn, _updateTransactionInternal, updateTransactionInternal_fn, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn, _onTransactionParamsUpdated, onTransactionParamsUpdated_fn, _updateSimulationData, updateSimulationData_fn, _onGasFeePollerTransactionUpdate, onGasFeePollerTransactionUpdate_fn, _getNetworkClientId, getNetworkClientId_fn, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn, _getGlobalChainId, getGlobalChainId_fn, _isCustomNetwork, isCustomNetwork_fn, _getSelectedAccount, getSelectedAccount_fn;
146
- var TransactionController = class extends BaseController {
147
- /**
148
- * Constructs a TransactionController.
149
- *
150
- * @param options - The controller options.
151
- * @param options.blockTracker - The block tracker used to poll for new blocks data.
152
- * @param options.disableHistory - Whether to disable storing history in transaction metadata.
153
- * @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
154
- * @param options.disableSwaps - Whether to disable additional processing on swaps transactions.
155
- * @param options.getCurrentAccountEIP1559Compatibility - Whether or not the account supports EIP-1559.
156
- * @param options.getCurrentNetworkEIP1559Compatibility - Whether or not the network supports EIP-1559.
157
- * @param options.getExternalPendingTransactions - Callback to retrieve pending transactions from external sources.
158
- * @param options.getGasFeeEstimates - Callback to retrieve gas fee estimates.
159
- * @param options.getNetworkClientRegistry - Gets the network client registry.
160
- * @param options.getNetworkState - Gets the state of the network controller.
161
- * @param options.getPermittedAccounts - Get accounts that a given origin has permissions for.
162
- * @param options.getSavedGasFees - Gets the saved gas fee config.
163
- * @param options.incomingTransactions - Configuration options for incoming transaction support.
164
- * @param options.isMultichainEnabled - Enable multichain support.
165
- * @param options.isSimulationEnabled - Whether new transactions will be automatically simulated.
166
- * @param options.messenger - The controller messenger.
167
- * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
168
- * @param options.pendingTransactions - Configuration options for pending transaction support.
169
- * @param options.provider - The provider used to create the underlying EthQuery instance.
170
- * @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
171
- * @param options.sign - Function used to sign transactions.
172
- * @param options.state - Initial state to set on this controller.
173
- * @param options.testGasFeeFlows - Whether to use the test gas fee flow.
174
- * @param options.trace - Callback to generate trace information.
175
- * @param options.transactionHistoryLimit - Transaction history limit.
176
- * @param options.hooks - The controller hooks.
177
- */
178
- constructor({
179
- blockTracker,
180
- disableHistory,
181
- disableSendFlowHistory,
182
- disableSwaps,
183
- getCurrentAccountEIP1559Compatibility,
184
- getCurrentNetworkEIP1559Compatibility,
185
- getExternalPendingTransactions,
186
- getGasFeeEstimates,
187
- getNetworkClientRegistry,
188
- getNetworkState,
189
- getPermittedAccounts,
190
- getSavedGasFees,
191
- incomingTransactions = {},
192
- isMultichainEnabled = false,
193
- isSimulationEnabled,
194
- messenger,
195
- onNetworkStateChange,
196
- pendingTransactions = {},
197
- provider,
198
- securityProviderRequest,
199
- sign,
200
- state,
201
- testGasFeeFlows,
202
- trace,
203
- transactionHistoryLimit = 40,
204
- hooks
205
- }) {
206
- super({
207
- name: controllerName,
208
- metadata,
209
- messenger,
210
- state: {
211
- ...getDefaultTransactionControllerState(),
212
- ...state
213
- }
214
- });
215
- __privateAdd(this, _retryTransaction);
216
- __privateAdd(this, _createNonceTracker);
217
- __privateAdd(this, _createIncomingTransactionHelper);
218
- __privateAdd(this, _createPendingTransactionTracker);
219
- __privateAdd(this, _stopAllTracking);
220
- __privateAdd(this, _removeIncomingTransactionHelperListeners);
221
- __privateAdd(this, _addIncomingTransactionHelperListeners);
222
- __privateAdd(this, _removePendingTransactionTrackerListeners);
223
- __privateAdd(this, _addPendingTransactionTrackerListeners);
224
- __privateAdd(this, _getNonceTrackerPendingTransactions);
225
- __privateAdd(this, _getGasFeeFlows);
226
- __privateAdd(this, _getLayer1GasFeeFlows);
227
- __privateAdd(this, _updateTransactionInternal);
228
- __privateAdd(this, _checkIfTransactionParamsUpdated);
229
- __privateAdd(this, _onTransactionParamsUpdated);
230
- __privateAdd(this, _updateSimulationData);
231
- __privateAdd(this, _onGasFeePollerTransactionUpdate);
232
- __privateAdd(this, _getNetworkClientId);
233
- __privateAdd(this, _getGlobalNetworkClientId);
234
- __privateAdd(this, _getGlobalChainId);
235
- __privateAdd(this, _isCustomNetwork);
236
- __privateAdd(this, _getSelectedAccount);
237
- __privateAdd(this, _internalEvents, new EventEmitter());
238
- this.approvingTransactionIds = /* @__PURE__ */ new Set();
239
- this.mutex = new Mutex();
240
- __privateAdd(this, _incomingTransactionOptions, void 0);
241
- __privateAdd(this, _pendingTransactionOptions, void 0);
242
- this.signAbortCallbacks = /* @__PURE__ */ new Map();
243
- __privateAdd(this, _trace, void 0);
244
- __privateAdd(this, _transactionHistoryLimit, void 0);
245
- __privateAdd(this, _isSimulationEnabled, void 0);
246
- __privateAdd(this, _testGasFeeFlows, void 0);
247
- __privateAdd(this, _multichainTrackingHelper, void 0);
248
- __privateAdd(this, _checkForPendingTransactionAndStartPolling, () => {
249
- this.pendingTransactionTracker.startIfPendingTransactions();
250
- __privateGet(this, _multichainTrackingHelper).checkForPendingTransactionAndStartPolling();
251
- });
252
- this.messagingSystem = messenger;
253
- this.getNetworkState = getNetworkState;
254
- this.isSendFlowHistoryDisabled = disableSendFlowHistory ?? false;
255
- this.isHistoryDisabled = disableHistory ?? false;
256
- this.isSwapsDisabled = disableSwaps ?? false;
257
- __privateSet(this, _isSimulationEnabled, isSimulationEnabled ?? (() => true));
258
- this.registry = new MethodRegistry({ provider });
259
- this.getSavedGasFees = getSavedGasFees ?? ((_chainId) => void 0);
260
- this.getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility ?? (() => Promise.resolve(true));
261
- this.getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
262
- this.getGasFeeEstimates = getGasFeeEstimates || (() => Promise.resolve({}));
263
- this.getPermittedAccounts = getPermittedAccounts;
264
- this.getExternalPendingTransactions = getExternalPendingTransactions ?? (() => []);
265
- this.securityProviderRequest = securityProviderRequest;
266
- __privateSet(this, _incomingTransactionOptions, incomingTransactions);
267
- __privateSet(this, _pendingTransactionOptions, pendingTransactions);
268
- __privateSet(this, _transactionHistoryLimit, transactionHistoryLimit);
269
- this.sign = sign;
270
- __privateSet(this, _testGasFeeFlows, testGasFeeFlows === true);
271
- __privateSet(this, _trace, trace ?? ((_request, fn) => fn?.()));
272
- this.afterSign = hooks?.afterSign ?? (() => true);
273
- this.beforeCheckPendingTransaction = hooks?.beforeCheckPendingTransaction ?? /* istanbul ignore next */
274
- (() => true);
275
- this.beforePublish = hooks?.beforePublish ?? (() => true);
276
- this.getAdditionalSignArguments = hooks?.getAdditionalSignArguments ?? (() => []);
277
- this.publish = hooks?.publish ?? (() => Promise.resolve({ transactionHash: void 0 }));
278
- this.nonceTracker = __privateMethod(this, _createNonceTracker, createNonceTracker_fn).call(this, {
279
- provider,
280
- blockTracker
281
- });
282
- const findNetworkClientIdByChainId = (chainId) => {
283
- return this.messagingSystem.call(
284
- `NetworkController:findNetworkClientIdByChainId`,
285
- chainId
286
- );
287
- };
288
- __privateSet(this, _multichainTrackingHelper, new MultichainTrackingHelper({
289
- isMultichainEnabled,
290
- provider,
291
- nonceTracker: this.nonceTracker,
292
- incomingTransactionOptions: incomingTransactions,
293
- findNetworkClientIdByChainId,
294
- getNetworkClientById: (networkClientId) => {
295
- return this.messagingSystem.call(
296
- `NetworkController:getNetworkClientById`,
297
- networkClientId
298
- );
299
- },
300
- getNetworkClientRegistry,
301
- removeIncomingTransactionHelperListeners: __privateMethod(this, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn).bind(this),
302
- removePendingTransactionTrackerListeners: __privateMethod(this, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn).bind(this),
303
- createNonceTracker: __privateMethod(this, _createNonceTracker, createNonceTracker_fn).bind(this),
304
- createIncomingTransactionHelper: __privateMethod(this, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn).bind(this),
305
- createPendingTransactionTracker: __privateMethod(this, _createPendingTransactionTracker, createPendingTransactionTracker_fn).bind(this),
306
- onNetworkStateChange: (listener) => {
307
- this.messagingSystem.subscribe(
308
- "NetworkController:stateChange",
309
- listener
310
- );
311
- }
312
- }));
313
- __privateGet(this, _multichainTrackingHelper).initialize();
314
- const etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource({
315
- includeTokenTransfers: incomingTransactions.includeTokenTransfers
316
- });
317
- this.incomingTransactionHelper = __privateMethod(this, _createIncomingTransactionHelper, createIncomingTransactionHelper_fn).call(this, {
318
- blockTracker,
319
- etherscanRemoteTransactionSource
320
- });
321
- this.pendingTransactionTracker = __privateMethod(this, _createPendingTransactionTracker, createPendingTransactionTracker_fn).call(this, {
322
- provider,
323
- blockTracker
324
- });
325
- this.gasFeeFlows = __privateMethod(this, _getGasFeeFlows, getGasFeeFlows_fn).call(this);
326
- this.layer1GasFeeFlows = __privateMethod(this, _getLayer1GasFeeFlows, getLayer1GasFeeFlows_fn).call(this);
327
- const gasFeePoller = new GasFeePoller({
328
- findNetworkClientIdByChainId,
329
- gasFeeFlows: this.gasFeeFlows,
330
- getGasFeeControllerEstimates: this.getGasFeeEstimates,
331
- getProvider: (chainId, networkClientId) => __privateGet(this, _multichainTrackingHelper).getProvider({
332
- networkClientId,
333
- chainId
334
- }),
335
- getTransactions: () => this.state.transactions,
336
- layer1GasFeeFlows: this.layer1GasFeeFlows,
337
- onStateChange: (listener) => {
338
- this.messagingSystem.subscribe(
339
- "TransactionController:stateChange",
340
- listener
341
- );
342
- }
343
- });
344
- gasFeePoller.hub.on(
345
- "transaction-updated",
346
- __privateMethod(this, _onGasFeePollerTransactionUpdate, onGasFeePollerTransactionUpdate_fn).bind(this)
347
- );
348
- this.messagingSystem.subscribe(
349
- "TransactionController:stateChange",
350
- __privateGet(this, _checkForPendingTransactionAndStartPolling)
351
- );
352
- onNetworkStateChange(() => {
353
- projectLogger("Detected network change", this.getChainId());
354
- this.pendingTransactionTracker.startIfPendingTransactions();
355
- this.onBootCleanup();
356
- });
357
- this.onBootCleanup();
358
- __privateGet(this, _checkForPendingTransactionAndStartPolling).call(this);
359
- }
360
- failTransaction(transactionMeta, error, actionId) {
361
- let newTransactionMeta;
362
- try {
363
- newTransactionMeta = __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
364
- transactionId: transactionMeta.id,
365
- note: "TransactionController#failTransaction - Add error message and set status to failed",
366
- skipValidation: true
367
- }, (draftTransactionMeta) => {
368
- draftTransactionMeta.status = "failed" /* failed */;
369
- draftTransactionMeta.error = normalizeTxError(error);
370
- });
371
- } catch (err) {
372
- projectLogger("Failed to mark transaction as failed", err);
373
- newTransactionMeta = {
374
- ...transactionMeta,
375
- status: "failed" /* failed */,
376
- error: normalizeTxError(error)
377
- };
378
- }
379
- this.messagingSystem.publish(`${controllerName}:transactionFailed`, {
380
- actionId,
381
- error: error.message,
382
- transactionMeta: newTransactionMeta
383
- });
384
- this.onTransactionStatusChange(newTransactionMeta);
385
- this.messagingSystem.publish(
386
- `${controllerName}:transactionFinished`,
387
- newTransactionMeta
388
- );
389
- __privateGet(this, _internalEvents).emit(
390
- `${transactionMeta.id}:finished`,
391
- newTransactionMeta
392
- );
393
- }
394
- async registryLookup(fourBytePrefix) {
395
- const registryMethod = await this.registry.lookup(fourBytePrefix);
396
- if (!registryMethod) {
397
- return {
398
- registryMethod: "",
399
- parsedRegistryMethod: { name: void 0, args: void 0 }
400
- };
401
- }
402
- const parsedRegistryMethod = this.registry.parse(registryMethod);
403
- return { registryMethod, parsedRegistryMethod };
404
- }
405
- /**
406
- * Stops polling and removes listeners to prepare the controller for garbage collection.
407
- */
408
- destroy() {
409
- __privateMethod(this, _stopAllTracking, stopAllTracking_fn).call(this);
410
- }
411
- /**
412
- * Handle new method data request.
413
- *
414
- * @param fourBytePrefix - The method prefix.
415
- * @returns The method data object corresponding to the given signature prefix.
416
- */
417
- async handleMethodData(fourBytePrefix) {
418
- const releaseLock = await this.mutex.acquire();
419
- try {
420
- const { methodData } = this.state;
421
- const knownMethod = Object.keys(methodData).find(
422
- (knownFourBytePrefix) => fourBytePrefix === knownFourBytePrefix
423
- );
424
- if (knownMethod) {
425
- return methodData[fourBytePrefix];
426
- }
427
- const registry = await this.registryLookup(fourBytePrefix);
428
- this.update((state) => {
429
- state.methodData[fourBytePrefix] = registry;
430
- });
431
- return registry;
432
- } finally {
433
- releaseLock();
434
- }
435
- }
436
- /**
437
- * Add a new unapproved transaction to state. Parameters will be validated, a
438
- * unique transaction id will be generated, and gas and gasPrice will be calculated
439
- * if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
440
- *
441
- * @param txParams - Standard parameters for an Ethereum transaction.
442
- * @param opts - Additional options to control how the transaction is added.
443
- * @param opts.actionId - Unique ID to prevent duplicate requests.
444
- * @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
445
- * @param opts.method - RPC method that requested the transaction.
446
- * @param opts.origin - The origin of the transaction request, such as a dApp hostname.
447
- * @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
448
- * @param opts.securityAlertResponse - Response from security validator.
449
- * @param opts.sendFlowHistory - The sendFlowHistory entries to add.
450
- * @param opts.type - Type of transaction to add, such as 'cancel' or 'swap'.
451
- * @param opts.swaps - Options for swaps transactions.
452
- * @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
453
- * @param opts.swaps.meta - Metadata for swap transaction.
454
- * @param opts.networkClientId - The id of the network client for this transaction.
455
- * @param opts.traceContext - The parent context for any new traces.
456
- * @returns Object containing a promise resolving to the transaction hash if approved.
457
- */
458
- async addTransaction(txParams, {
459
- actionId,
460
- deviceConfirmedOn,
461
- method,
462
- origin,
463
- requireApproval,
464
- securityAlertResponse,
465
- sendFlowHistory,
466
- swaps = {},
467
- traceContext,
468
- type,
469
- networkClientId: requestNetworkClientId
470
- } = {}) {
471
- projectLogger("Adding transaction", txParams);
472
- txParams = normalizeTransactionParams(txParams);
473
- if (requestNetworkClientId && !__privateGet(this, _multichainTrackingHelper).has(requestNetworkClientId)) {
474
- throw new Error(
475
- "The networkClientId for this transaction could not be found"
476
- );
477
- }
478
- const networkClientId = requestNetworkClientId ?? __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
479
- const isEIP1559Compatible = await this.getEIP1559Compatibility(
480
- networkClientId
481
- );
482
- validateTxParams(txParams, isEIP1559Compatible);
483
- if (origin) {
484
- await validateTransactionOrigin(
485
- await this.getPermittedAccounts(origin),
486
- __privateMethod(this, _getSelectedAccount, getSelectedAccount_fn).call(this).address,
487
- txParams.from,
488
- origin
489
- );
490
- }
491
- const dappSuggestedGasFees = this.generateDappSuggestedGasFees(
492
- txParams,
493
- origin
494
- );
495
- const chainId = this.getChainId(networkClientId);
496
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
497
- networkClientId,
498
- chainId
499
- });
500
- const transactionType = type ?? (await determineTransactionType(txParams, ethQuery)).type;
501
- const existingTransactionMeta = this.getTransactionWithActionId(actionId);
502
- let addedTransactionMeta = existingTransactionMeta ? cloneDeep(existingTransactionMeta) : {
503
- // Add actionId to txMeta to check if same actionId is seen again
504
- actionId,
505
- chainId,
506
- dappSuggestedGasFees,
507
- deviceConfirmedOn,
508
- id: random(),
509
- origin,
510
- securityAlertResponse,
511
- status: "unapproved" /* unapproved */,
512
- time: Date.now(),
513
- txParams,
514
- userEditedGasLimit: false,
515
- verifiedOnBlockchain: false,
516
- type: transactionType,
517
- networkClientId
518
- };
519
- await __privateGet(this, _trace).call(this, { name: "Estimate Gas Properties", parentContext: traceContext }, (context) => this.updateGasProperties(addedTransactionMeta, {
520
- traceContext: context
521
- }));
522
- if (!existingTransactionMeta) {
523
- if (method && this.securityProviderRequest) {
524
- const securityProviderResponse = await this.securityProviderRequest(
525
- addedTransactionMeta,
526
- method
527
- );
528
- addedTransactionMeta.securityProviderResponse = securityProviderResponse;
529
- }
530
- if (!this.isSendFlowHistoryDisabled) {
531
- addedTransactionMeta.sendFlowHistory = sendFlowHistory ?? [];
532
- }
533
- if (!this.isHistoryDisabled) {
534
- addedTransactionMeta = addInitialHistorySnapshot(addedTransactionMeta);
535
- }
536
- addedTransactionMeta = updateSwapsTransaction(
537
- addedTransactionMeta,
538
- transactionType,
539
- swaps,
540
- {
541
- isSwapsDisabled: this.isSwapsDisabled,
542
- cancelTransaction: this.cancelTransaction.bind(this),
543
- messenger: this.messagingSystem
544
- }
545
- );
546
- this.addMetadata(addedTransactionMeta);
547
- if (requireApproval !== false) {
548
- __privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta, {
549
- traceContext
550
- }).catch((error) => {
551
- projectLogger("Error while updating simulation data", error);
552
- throw error;
553
- });
554
- } else {
555
- projectLogger("Skipping simulation as approval not required");
556
- }
557
- this.messagingSystem.publish(
558
- `${controllerName}:unapprovedTransactionAdded`,
559
- addedTransactionMeta
560
- );
561
- }
562
- return {
563
- result: this.processApproval(addedTransactionMeta, {
564
- isExisting: Boolean(existingTransactionMeta),
565
- requireApproval,
566
- actionId,
567
- traceContext
568
- }),
569
- transactionMeta: addedTransactionMeta
570
- };
571
- }
572
- startIncomingTransactionPolling(networkClientIds = []) {
573
- if (networkClientIds.length === 0) {
574
- this.incomingTransactionHelper.start();
575
- return;
576
- }
577
- __privateGet(this, _multichainTrackingHelper).startIncomingTransactionPolling(
578
- networkClientIds
579
- );
580
- }
581
- stopIncomingTransactionPolling(networkClientIds = []) {
582
- if (networkClientIds.length === 0) {
583
- this.incomingTransactionHelper.stop();
584
- return;
585
- }
586
- __privateGet(this, _multichainTrackingHelper).stopIncomingTransactionPolling(
587
- networkClientIds
588
- );
589
- }
590
- stopAllIncomingTransactionPolling() {
591
- this.incomingTransactionHelper.stop();
592
- __privateGet(this, _multichainTrackingHelper).stopAllIncomingTransactionPolling();
593
- }
594
- async updateIncomingTransactions(networkClientIds = []) {
595
- if (networkClientIds.length === 0) {
596
- await this.incomingTransactionHelper.update();
597
- return;
598
- }
599
- await __privateGet(this, _multichainTrackingHelper).updateIncomingTransactions(
600
- networkClientIds
601
- );
602
- }
603
- /**
604
- * Attempts to cancel a transaction based on its ID by setting its status to "rejected"
605
- * and emitting a `<tx.id>:finished` hub event.
606
- *
607
- * @param transactionId - The ID of the transaction to cancel.
608
- * @param gasValues - The gas values to use for the cancellation transaction.
609
- * @param options - The options for the cancellation transaction.
610
- * @param options.actionId - Unique ID to prevent duplicate requests.
611
- * @param options.estimatedBaseFee - The estimated base fee of the transaction.
612
- */
613
- async stopTransaction(transactionId, gasValues, {
614
- estimatedBaseFee,
615
- actionId
616
- } = {}) {
617
- return await __privateMethod(this, _retryTransaction, retryTransaction_fn).call(this, {
618
- actionId,
619
- estimatedBaseFee,
620
- gasValues,
621
- label: "cancel",
622
- rate: CANCEL_RATE,
623
- transactionId,
624
- transactionType: "cancel" /* cancel */,
625
- prepareTransactionParams: (txParams) => {
626
- delete txParams.data;
627
- txParams.to = txParams.from;
628
- txParams.value = "0x0";
629
- },
630
- afterSubmit: (newTransactionMeta) => {
631
- this.messagingSystem.publish(
632
- `${controllerName}:transactionFinished`,
633
- newTransactionMeta
634
- );
635
- __privateGet(this, _internalEvents).emit(
636
- `${newTransactionMeta.id}:finished`,
637
- newTransactionMeta
638
- );
639
- }
640
- });
641
- }
642
- /**
643
- * Attempts to speed up a transaction increasing transaction gasPrice by ten percent.
644
- *
645
- * @param transactionId - The ID of the transaction to speed up.
646
- * @param gasValues - The gas values to use for the speed up transaction.
647
- * @param options - The options for the speed up transaction.
648
- * @param options.actionId - Unique ID to prevent duplicate requests
649
- * @param options.estimatedBaseFee - The estimated base fee of the transaction.
650
- */
651
- async speedUpTransaction(transactionId, gasValues, {
652
- actionId,
653
- estimatedBaseFee
654
- } = {}) {
655
- return await __privateMethod(this, _retryTransaction, retryTransaction_fn).call(this, {
656
- actionId,
657
- estimatedBaseFee,
658
- gasValues,
659
- label: "speed up",
660
- rate: SPEED_UP_RATE,
661
- transactionId,
662
- transactionType: "retry" /* retry */,
663
- afterSubmit: (newTransactionMeta) => {
664
- this.messagingSystem.publish(
665
- `${controllerName}:speedupTransactionAdded`,
666
- newTransactionMeta
667
- );
668
- }
669
- });
670
- }
671
- /**
672
- * Estimates required gas for a given transaction.
673
- *
674
- * @param transaction - The transaction to estimate gas for.
675
- * @param networkClientId - The network client id to use for the estimate.
676
- * @returns The gas and gas price.
677
- */
678
- async estimateGas(transaction, networkClientId) {
679
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
680
- networkClientId
681
- });
682
- const { estimatedGas, simulationFails } = await estimateGas(
683
- transaction,
684
- ethQuery
685
- );
686
- return { gas: estimatedGas, simulationFails };
687
- }
688
- /**
689
- * Estimates required gas for a given transaction and add additional gas buffer with the given multiplier.
690
- *
691
- * @param transaction - The transaction params to estimate gas for.
692
- * @param multiplier - The multiplier to use for the gas buffer.
693
- * @param networkClientId - The network client id to use for the estimate.
694
- */
695
- async estimateGasBuffered(transaction, multiplier, networkClientId) {
696
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
697
- networkClientId
698
- });
699
- const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(
700
- transaction,
701
- ethQuery
702
- );
703
- const gas = addGasBuffer(estimatedGas, blockGasLimit, multiplier);
704
- return {
705
- gas,
706
- simulationFails
707
- };
708
- }
709
- /**
710
- * Updates an existing transaction in state.
711
- *
712
- * @param transactionMeta - The new transaction to store in state.
713
- * @param note - A note or update reason to include in the transaction history.
714
- */
715
- updateTransaction(transactionMeta, note) {
716
- const { id: transactionId } = transactionMeta;
717
- __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { transactionId, note }, () => ({
718
- ...transactionMeta
719
- }));
720
- }
721
- /**
722
- * Update the security alert response for a transaction.
723
- *
724
- * @param transactionId - ID of the transaction.
725
- * @param securityAlertResponse - The new security alert response for the transaction.
726
- */
727
- updateSecurityAlertResponse(transactionId, securityAlertResponse) {
728
- if (!securityAlertResponse) {
729
- throw new Error(
730
- "updateSecurityAlertResponse: securityAlertResponse should not be null"
731
- );
732
- }
733
- const transactionMeta = this.getTransaction(transactionId);
734
- if (!transactionMeta) {
735
- throw new Error(
736
- `Cannot update security alert response as no transaction metadata found`
737
- );
738
- }
739
- const updatedTransactionMeta = {
740
- ...transactionMeta,
741
- securityAlertResponse
742
- };
743
- this.updateTransaction(
744
- updatedTransactionMeta,
745
- `${controllerName}:updatesecurityAlertResponse - securityAlertResponse updated`
746
- );
747
- }
748
- /**
749
- * Removes all transactions from state, optionally based on the current network.
750
- *
751
- * @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
752
- * current network. If `true`, all transactions are wiped.
753
- * @param address - If specified, only transactions originating from this address will be
754
- * wiped on current network.
755
- */
756
- wipeTransactions(ignoreNetwork, address) {
757
- if (ignoreNetwork && !address) {
758
- this.update((state) => {
759
- state.transactions = [];
760
- });
761
- return;
762
- }
763
- const currentChainId = this.getChainId();
764
- const newTransactions = this.state.transactions.filter(
765
- ({ chainId, txParams }) => {
766
- const isMatchingNetwork = ignoreNetwork || chainId === currentChainId;
767
- if (!isMatchingNetwork) {
768
- return true;
769
- }
770
- const isMatchingAddress = !address || txParams.from?.toLowerCase() === address.toLowerCase();
771
- return !isMatchingAddress;
772
- }
773
- );
774
- this.update((state) => {
775
- state.transactions = this.trimTransactionsForState(newTransactions);
776
- });
777
- }
778
- /**
779
- * Adds external provided transaction to state as confirmed transaction.
780
- *
781
- * @param transactionMeta - TransactionMeta to add transactions.
782
- * @param transactionReceipt - TransactionReceipt of the external transaction.
783
- * @param baseFeePerGas - Base fee per gas of the external transaction.
784
- */
785
- async confirmExternalTransaction(transactionMeta, transactionReceipt, baseFeePerGas) {
786
- const newTransactionMeta = this.addExternalTransaction(transactionMeta);
787
- try {
788
- const transactionId = newTransactionMeta.id;
789
- const updatedTransactionMeta = {
790
- ...newTransactionMeta,
791
- status: "confirmed" /* confirmed */,
792
- txReceipt: transactionReceipt
793
- };
794
- if (baseFeePerGas) {
795
- updatedTransactionMeta.baseFeePerGas = baseFeePerGas;
796
- }
797
- this.markNonceDuplicatesDropped(transactionId);
798
- this.updateTransaction(
799
- updatedTransactionMeta,
800
- `${controllerName}:confirmExternalTransaction - Add external transaction`
801
- );
802
- this.onTransactionStatusChange(updatedTransactionMeta);
803
- this.updatePostBalance(updatedTransactionMeta).catch((error) => {
804
- projectLogger("Error while updating post balance", error);
805
- throw error;
806
- });
807
- this.messagingSystem.publish(
808
- `${controllerName}:transactionConfirmed`,
809
- updatedTransactionMeta
810
- );
811
- } catch (error) {
812
- console.error("Failed to confirm external transaction", error);
813
- }
814
- }
815
- /**
816
- * Append new send flow history to a transaction.
817
- *
818
- * @param transactionID - The ID of the transaction to update.
819
- * @param currentSendFlowHistoryLength - The length of the current sendFlowHistory array.
820
- * @param sendFlowHistoryToAdd - The sendFlowHistory entries to add.
821
- * @returns The updated transactionMeta.
822
- */
823
- updateTransactionSendFlowHistory(transactionID, currentSendFlowHistoryLength, sendFlowHistoryToAdd) {
824
- if (this.isSendFlowHistoryDisabled) {
825
- throw new Error(
826
- "Send flow history is disabled for the current transaction controller"
827
- );
828
- }
829
- const transactionMeta = this.getTransaction(transactionID);
830
- if (!transactionMeta) {
831
- throw new Error(
832
- `Cannot update send flow history as no transaction metadata found`
833
- );
834
- }
835
- validateIfTransactionUnapproved(
836
- transactionMeta,
837
- "updateTransactionSendFlowHistory"
838
- );
839
- const sendFlowHistory = transactionMeta.sendFlowHistory ?? [];
840
- if (currentSendFlowHistoryLength === sendFlowHistory.length) {
841
- const updatedTransactionMeta = {
842
- ...transactionMeta,
843
- sendFlowHistory: [...sendFlowHistory, ...sendFlowHistoryToAdd]
844
- };
845
- this.updateTransaction(
846
- updatedTransactionMeta,
847
- `${controllerName}:updateTransactionSendFlowHistory - sendFlowHistory updated`
848
- );
849
- }
850
- return this.getTransaction(transactionID);
851
- }
852
- /**
853
- * Update the gas values of a transaction.
854
- *
855
- * @param transactionId - The ID of the transaction to update.
856
- * @param gasValues - Gas values to update.
857
- * @param gasValues.gas - Same as transaction.gasLimit.
858
- * @param gasValues.gasLimit - Maxmimum number of units of gas to use for this transaction.
859
- * @param gasValues.gasPrice - Price per gas for legacy transactions.
860
- * @param gasValues.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.
861
- * @param gasValues.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.
862
- * @param gasValues.estimateUsed - Which estimate level was used.
863
- * @param gasValues.estimateSuggested - Which estimate level that the API suggested.
864
- * @param gasValues.defaultGasEstimates - The default estimate for gas.
865
- * @param gasValues.originalGasEstimate - Original estimate for gas.
866
- * @param gasValues.userEditedGasLimit - The gas limit supplied by user.
867
- * @param gasValues.userFeeLevel - Estimate level user selected.
868
- * @returns The updated transactionMeta.
869
- */
870
- updateTransactionGasFees(transactionId, {
871
- defaultGasEstimates,
872
- estimateUsed,
873
- estimateSuggested,
874
- gas,
875
- gasLimit,
876
- gasPrice,
877
- maxPriorityFeePerGas,
878
- maxFeePerGas,
879
- originalGasEstimate,
880
- userEditedGasLimit,
881
- userFeeLevel
882
- }) {
883
- const transactionMeta = this.getTransaction(transactionId);
884
- if (!transactionMeta) {
885
- throw new Error(
886
- `Cannot update transaction as no transaction metadata found`
887
- );
888
- }
889
- validateIfTransactionUnapproved(
890
- transactionMeta,
891
- "updateTransactionGasFees"
892
- );
893
- let transactionGasFees = {
894
- txParams: {
895
- gas,
896
- gasLimit,
897
- gasPrice,
898
- maxPriorityFeePerGas,
899
- maxFeePerGas
900
- },
901
- defaultGasEstimates,
902
- estimateUsed,
903
- estimateSuggested,
904
- originalGasEstimate,
905
- userEditedGasLimit,
906
- userFeeLevel
907
- // TODO: Replace `any` with type
908
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
909
- };
910
- transactionGasFees.txParams = pickBy(transactionGasFees.txParams);
911
- transactionGasFees = pickBy(transactionGasFees);
912
- const updatedMeta = merge({}, transactionMeta, transactionGasFees);
913
- this.updateTransaction(
914
- updatedMeta,
915
- `${controllerName}:updateTransactionGasFees - gas values updated`
916
- );
917
- return this.getTransaction(transactionId);
918
- }
919
- /**
920
- * Update the previous gas values of a transaction.
921
- *
922
- * @param transactionId - The ID of the transaction to update.
923
- * @param previousGas - Previous gas values to update.
924
- * @param previousGas.gasLimit - Maxmimum number of units of gas to use for this transaction.
925
- * @param previousGas.maxFeePerGas - Maximum amount per gas to pay for the transaction, including the priority fee.
926
- * @param previousGas.maxPriorityFeePerGas - Maximum amount per gas to give to validator as incentive.
927
- * @returns The updated transactionMeta.
928
- */
929
- updatePreviousGasParams(transactionId, {
930
- gasLimit,
931
- maxFeePerGas,
932
- maxPriorityFeePerGas
933
- }) {
934
- const transactionMeta = this.getTransaction(transactionId);
935
- if (!transactionMeta) {
936
- throw new Error(
937
- `Cannot update transaction as no transaction metadata found`
938
- );
939
- }
940
- validateIfTransactionUnapproved(transactionMeta, "updatePreviousGasParams");
941
- const transactionPreviousGas = {
942
- previousGas: {
943
- gasLimit,
944
- maxFeePerGas,
945
- maxPriorityFeePerGas
946
- }
947
- // TODO: Replace `any` with type
948
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
949
- };
950
- transactionPreviousGas.previousGas = pickBy(
951
- transactionPreviousGas.previousGas
952
- );
953
- const updatedMeta = merge({}, transactionMeta, transactionPreviousGas);
954
- this.updateTransaction(
955
- updatedMeta,
956
- `${controllerName}:updatePreviousGasParams - Previous gas values updated`
957
- );
958
- return this.getTransaction(transactionId);
959
- }
960
- async getNonceLock(address, networkClientId) {
961
- return __privateGet(this, _multichainTrackingHelper).getNonceLock(
962
- address,
963
- networkClientId
964
- );
965
- }
966
- /**
967
- * Updates the editable parameters of a transaction.
968
- *
969
- * @param txId - The ID of the transaction to update.
970
- * @param params - The editable parameters to update.
971
- * @param params.data - Data to pass with the transaction.
972
- * @param params.gas - Maximum number of units of gas to use for the transaction.
973
- * @param params.gasPrice - Price per gas for legacy transactions.
974
- * @param params.from - Address to send the transaction from.
975
- * @param params.to - Address to send the transaction to.
976
- * @param params.value - Value associated with the transaction.
977
- * @returns The updated transaction metadata.
978
- */
979
- async updateEditableParams(txId, {
980
- data,
981
- gas,
982
- gasPrice,
983
- from,
984
- to,
985
- value
986
- }) {
987
- const transactionMeta = this.getTransaction(txId);
988
- if (!transactionMeta) {
989
- throw new Error(
990
- `Cannot update editable params as no transaction metadata found`
991
- );
992
- }
993
- validateIfTransactionUnapproved(transactionMeta, "updateEditableParams");
994
- const editableParams = {
995
- txParams: {
996
- data,
997
- from,
998
- to,
999
- value,
1000
- gas,
1001
- gasPrice
1002
- }
1003
- };
1004
- editableParams.txParams = pickBy(
1005
- editableParams.txParams
1006
- );
1007
- const updatedTransaction = merge({}, transactionMeta, editableParams);
1008
- const provider = __privateGet(this, _multichainTrackingHelper).getProvider({
1009
- chainId: transactionMeta.chainId,
1010
- networkClientId: transactionMeta.networkClientId
1011
- });
1012
- const ethQuery = new EthQuery(provider);
1013
- const { type } = await determineTransactionType(
1014
- updatedTransaction.txParams,
1015
- ethQuery
1016
- );
1017
- updatedTransaction.type = type;
1018
- await updateTransactionLayer1GasFee({
1019
- layer1GasFeeFlows: this.layer1GasFeeFlows,
1020
- provider,
1021
- transactionMeta: updatedTransaction
1022
- });
1023
- this.updateTransaction(
1024
- updatedTransaction,
1025
- `Update Editable Params for ${txId}`
1026
- );
1027
- return this.getTransaction(txId);
1028
- }
1029
- /**
1030
- * Signs and returns the raw transaction data for provided transaction params list.
1031
- *
1032
- * @param listOfTxParams - The list of transaction params to approve.
1033
- * @param opts - Options bag.
1034
- * @param opts.hasNonce - Whether the transactions already have a nonce.
1035
- * @returns The raw transactions.
1036
- */
1037
- async approveTransactionsWithSameNonce(listOfTxParams = [], { hasNonce } = {}) {
1038
- projectLogger("Approving transactions with same nonce", {
1039
- transactions: listOfTxParams
1040
- });
1041
- if (listOfTxParams.length === 0) {
1042
- return "";
1043
- }
1044
- const initialTx = listOfTxParams[0];
1045
- const common = this.getCommonConfiguration(initialTx.chainId);
1046
- let networkClientId;
1047
- try {
1048
- networkClientId = this.messagingSystem.call(
1049
- `NetworkController:findNetworkClientIdByChainId`,
1050
- initialTx.chainId
1051
- );
1052
- } catch (err) {
1053
- projectLogger("failed to find networkClientId from chainId", err);
1054
- }
1055
- const initialTxAsEthTx = TransactionFactory.fromTxData(initialTx, {
1056
- common
1057
- });
1058
- const initialTxAsSerializedHex = bufferToHex(initialTxAsEthTx.serialize());
1059
- if (this.approvingTransactionIds.has(initialTxAsSerializedHex)) {
1060
- return "";
1061
- }
1062
- this.approvingTransactionIds.add(initialTxAsSerializedHex);
1063
- let rawTransactions, nonceLock;
1064
- try {
1065
- const fromAddress = initialTx.from;
1066
- const requiresNonce = hasNonce !== true;
1067
- nonceLock = requiresNonce ? await this.getNonceLock(fromAddress, networkClientId) : void 0;
1068
- const nonce = nonceLock ? add0x(nonceLock.nextNonce.toString(16)) : initialTx.nonce;
1069
- if (nonceLock) {
1070
- projectLogger("Using nonce from nonce tracker", nonce, nonceLock.nonceDetails);
1071
- }
1072
- rawTransactions = await Promise.all(
1073
- listOfTxParams.map((txParams) => {
1074
- txParams.nonce = nonce;
1075
- return this.signExternalTransaction(txParams.chainId, txParams);
1076
- })
1077
- );
1078
- } catch (err) {
1079
- projectLogger("Error while signing transactions with same nonce", err);
1080
- throw err;
1081
- } finally {
1082
- nonceLock?.releaseLock();
1083
- this.approvingTransactionIds.delete(initialTxAsSerializedHex);
1084
- }
1085
- return rawTransactions;
1086
- }
1087
- /**
1088
- * Update a custodial transaction.
1089
- *
1090
- * @param transactionId - The ID of the transaction to update.
1091
- * @param options - The custodial transaction options to update.
1092
- * @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
1093
- * @param options.hash - The new hash value to be assigned.
1094
- * @param options.status - The new status value to be assigned.
1095
- */
1096
- updateCustodialTransaction(transactionId, {
1097
- errorMessage,
1098
- hash,
1099
- status
1100
- }) {
1101
- const transactionMeta = this.getTransaction(transactionId);
1102
- if (!transactionMeta) {
1103
- throw new Error(
1104
- `Cannot update custodial transaction as no transaction metadata found`
1105
- );
1106
- }
1107
- if (!transactionMeta.custodyId) {
1108
- throw new Error("Transaction must be a custodian transaction");
1109
- }
1110
- if (status && ![
1111
- "submitted" /* submitted */,
1112
- "signed" /* signed */,
1113
- "failed" /* failed */
1114
- ].includes(status)) {
1115
- throw new Error(
1116
- `Cannot update custodial transaction with status: ${status}`
1117
- );
1118
- }
1119
- const updatedTransactionMeta = merge(
1120
- {},
1121
- transactionMeta,
1122
- pickBy({ hash, status })
1123
- );
1124
- if (updatedTransactionMeta.status === "submitted" /* submitted */) {
1125
- updatedTransactionMeta.submittedTime = (/* @__PURE__ */ new Date()).getTime();
1126
- }
1127
- if (updatedTransactionMeta.status === "failed" /* failed */) {
1128
- updatedTransactionMeta.error = normalizeTxError(new Error(errorMessage));
1129
- }
1130
- this.updateTransaction(
1131
- updatedTransactionMeta,
1132
- `${controllerName}:updateCustodialTransaction - Custodial transaction updated`
1133
- );
1134
- if (["submitted" /* submitted */, "failed" /* failed */].includes(
1135
- status
1136
- )) {
1137
- this.messagingSystem.publish(
1138
- `${controllerName}:transactionFinished`,
1139
- updatedTransactionMeta
1140
- );
1141
- __privateGet(this, _internalEvents).emit(
1142
- `${updatedTransactionMeta.id}:finished`,
1143
- updatedTransactionMeta
1144
- );
1145
- }
1146
- }
1147
- /**
1148
- * Search transaction metadata for matching entries.
1149
- *
1150
- * @param opts - Options bag.
1151
- * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.
1152
- * @param opts.initialList - The transactions to search. Defaults to the current state.
1153
- * @param opts.filterToCurrentNetwork - Whether to filter the results to the current network. Defaults to true.
1154
- * @param opts.limit - The maximum number of transactions to return. No limit by default.
1155
- * @returns An array of transactions matching the provided options.
1156
- */
1157
- getTransactions({
1158
- searchCriteria = {},
1159
- initialList,
1160
- filterToCurrentNetwork = true,
1161
- limit
1162
- } = {}) {
1163
- const chainId = this.getChainId();
1164
- const predicateMethods = mapValues(searchCriteria, (predicate) => {
1165
- return typeof predicate === "function" ? predicate : (
1166
- // TODO: Replace `any` with type
1167
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1168
- (v) => v === predicate
1169
- );
1170
- });
1171
- const transactionsToFilter = initialList ?? this.state.transactions;
1172
- const filteredTransactions = sortBy(
1173
- pickBy(transactionsToFilter, (transaction) => {
1174
- if (filterToCurrentNetwork && transaction.chainId !== chainId) {
1175
- return false;
1176
- }
1177
- for (const [key, predicate] of Object.entries(predicateMethods)) {
1178
- if (key in transaction.txParams) {
1179
- if (predicate(transaction.txParams[key]) === false) {
1180
- return false;
1181
- }
1182
- } else if (predicate(transaction[key]) === false) {
1183
- return false;
1184
- }
1185
- }
1186
- return true;
1187
- }),
1188
- "time"
1189
- );
1190
- if (limit !== void 0) {
1191
- const nonces = /* @__PURE__ */ new Set();
1192
- const txs = [];
1193
- for (let i = filteredTransactions.length - 1; i > -1; i--) {
1194
- const txMeta = filteredTransactions[i];
1195
- const { nonce } = txMeta.txParams;
1196
- if (!nonces.has(nonce)) {
1197
- if (nonces.size < limit) {
1198
- nonces.add(nonce);
1199
- } else {
1200
- continue;
1201
- }
1202
- }
1203
- txs.unshift(txMeta);
1204
- }
1205
- return txs;
1206
- }
1207
- return filteredTransactions;
1208
- }
1209
- async estimateGasFee({
1210
- transactionParams,
1211
- chainId,
1212
- networkClientId: requestNetworkClientId
1213
- }) {
1214
- const networkClientId = __privateMethod(this, _getNetworkClientId, getNetworkClientId_fn).call(this, {
1215
- networkClientId: requestNetworkClientId,
1216
- chainId
1217
- });
1218
- const transactionMeta = {
1219
- txParams: transactionParams,
1220
- chainId,
1221
- networkClientId
1222
- };
1223
- const gasFeeFlow = getGasFeeFlow(
1224
- transactionMeta,
1225
- this.gasFeeFlows
1226
- );
1227
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
1228
- networkClientId,
1229
- chainId
1230
- });
1231
- const gasFeeControllerData = await this.getGasFeeEstimates({
1232
- networkClientId
1233
- });
1234
- return gasFeeFlow.getGasFees({
1235
- ethQuery,
1236
- gasFeeControllerData,
1237
- transactionMeta
1238
- });
1239
- }
1240
- /**
1241
- * Determine the layer 1 gas fee for the given transaction parameters.
1242
- *
1243
- * @param request - The request object.
1244
- * @param request.transactionParams - The transaction parameters to estimate the layer 1 gas fee for.
1245
- * @param request.chainId - The ID of the chain where the transaction will be executed.
1246
- * @param request.networkClientId - The ID of a specific network client to process the transaction.
1247
- */
1248
- async getLayer1GasFee({
1249
- transactionParams,
1250
- chainId,
1251
- networkClientId
1252
- }) {
1253
- const provider = __privateGet(this, _multichainTrackingHelper).getProvider({
1254
- networkClientId,
1255
- chainId
1256
- });
1257
- return await getTransactionLayer1GasFee({
1258
- layer1GasFeeFlows: this.layer1GasFeeFlows,
1259
- provider,
1260
- transactionMeta: {
1261
- txParams: transactionParams,
1262
- chainId
1263
- }
1264
- });
1265
- }
1266
- async signExternalTransaction(chainId, transactionParams) {
1267
- if (!this.sign) {
1268
- throw new Error("No sign method defined.");
1269
- }
1270
- const normalizedTransactionParams = normalizeTransactionParams(transactionParams);
1271
- const type = isEIP1559Transaction(normalizedTransactionParams) ? "0x2" /* feeMarket */ : "0x0" /* legacy */;
1272
- const updatedTransactionParams = {
1273
- ...normalizedTransactionParams,
1274
- type,
1275
- gasLimit: normalizedTransactionParams.gas,
1276
- chainId
1277
- };
1278
- const { from } = updatedTransactionParams;
1279
- const common = this.getCommonConfiguration(chainId);
1280
- const unsignedTransaction = TransactionFactory.fromTxData(
1281
- updatedTransactionParams,
1282
- { common }
1283
- );
1284
- const signedTransaction = await this.sign(unsignedTransaction, from);
1285
- const rawTransaction = bufferToHex(signedTransaction.serialize());
1286
- return rawTransaction;
1287
- }
1288
- /**
1289
- * Removes unapproved transactions from state.
1290
- */
1291
- clearUnapprovedTransactions() {
1292
- const transactions = this.state.transactions.filter(
1293
- ({ status }) => status !== "unapproved" /* unapproved */
1294
- );
1295
- this.update((state) => {
1296
- state.transactions = this.trimTransactionsForState(transactions);
1297
- });
1298
- }
1299
- /**
1300
- * Stop the signing process for a specific transaction.
1301
- * Throws an error causing the transaction status to be set to failed.
1302
- * @param transactionId - The ID of the transaction to stop signing.
1303
- */
1304
- abortTransactionSigning(transactionId) {
1305
- const transactionMeta = this.getTransaction(transactionId);
1306
- if (!transactionMeta) {
1307
- throw new Error(`Cannot abort signing as no transaction metadata found`);
1308
- }
1309
- const abortCallback = this.signAbortCallbacks.get(transactionId);
1310
- if (!abortCallback) {
1311
- throw new Error(
1312
- `Cannot abort signing as transaction is not waiting for signing`
1313
- );
1314
- }
1315
- abortCallback();
1316
- this.signAbortCallbacks.delete(transactionId);
1317
- }
1318
- addMetadata(transactionMeta) {
1319
- validateTxParams(transactionMeta.txParams);
1320
- this.update((state) => {
1321
- state.transactions = this.trimTransactionsForState([
1322
- ...state.transactions,
1323
- transactionMeta
1324
- ]);
1325
- });
1326
- }
1327
- async updateGasProperties(transactionMeta, { traceContext } = {}) {
1328
- const isEIP1559Compatible = transactionMeta.txParams.type !== "0x0" /* legacy */ && await this.getEIP1559Compatibility(transactionMeta.networkClientId);
1329
- const { networkClientId, chainId } = transactionMeta;
1330
- const isCustomNetwork = __privateMethod(this, _isCustomNetwork, isCustomNetwork_fn).call(this, networkClientId);
1331
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
1332
- networkClientId,
1333
- chainId
1334
- });
1335
- const provider = __privateGet(this, _multichainTrackingHelper).getProvider({
1336
- networkClientId,
1337
- chainId
1338
- });
1339
- await __privateGet(this, _trace).call(this, { name: "Update Gas", parentContext: traceContext }, async () => {
1340
- await updateGas({
1341
- ethQuery,
1342
- chainId,
1343
- isCustomNetwork,
1344
- txMeta: transactionMeta
1345
- });
1346
- });
1347
- await __privateGet(this, _trace).call(this, { name: "Update Gas Fees", parentContext: traceContext }, async () => await updateGasFees({
1348
- eip1559: isEIP1559Compatible,
1349
- ethQuery,
1350
- gasFeeFlows: this.gasFeeFlows,
1351
- getGasFeeEstimates: this.getGasFeeEstimates,
1352
- getSavedGasFees: this.getSavedGasFees.bind(this),
1353
- txMeta: transactionMeta
1354
- }));
1355
- await __privateGet(this, _trace).call(this, { name: "Update Layer 1 Gas Fees", parentContext: traceContext }, async () => await updateTransactionLayer1GasFee({
1356
- layer1GasFeeFlows: this.layer1GasFeeFlows,
1357
- provider,
1358
- transactionMeta
1359
- }));
1360
- }
1361
- onBootCleanup() {
1362
- this.clearUnapprovedTransactions();
1363
- this.failIncompleteTransactions();
1364
- }
1365
- failIncompleteTransactions() {
1366
- const incompleteTransactions = this.state.transactions.filter(
1367
- (transaction) => ["approved" /* approved */, "signed" /* signed */].includes(
1368
- transaction.status
1369
- )
1370
- );
1371
- for (const transactionMeta of incompleteTransactions) {
1372
- this.failTransaction(
1373
- transactionMeta,
1374
- new Error("Transaction incomplete at startup")
1375
- );
1376
- }
1377
- }
1378
- async processApproval(transactionMeta, {
1379
- isExisting = false,
1380
- requireApproval,
1381
- shouldShowRequest = true,
1382
- actionId,
1383
- traceContext
1384
- }) {
1385
- const transactionId = transactionMeta.id;
1386
- let resultCallbacks;
1387
- const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
1388
- const finishedPromise = isCompleted ? Promise.resolve(meta) : this.waitForTransactionFinished(transactionId);
1389
- if (meta && !isExisting && !isCompleted) {
1390
- try {
1391
- if (requireApproval !== false) {
1392
- const acceptResult = await __privateGet(this, _trace).call(this, { name: "Await Approval", parentContext: traceContext }, (context) => this.requestApproval(transactionMeta, {
1393
- shouldShowRequest,
1394
- traceContext: context
1395
- }));
1396
- resultCallbacks = acceptResult.resultCallbacks;
1397
- const approvalValue = acceptResult.value;
1398
- const updatedTransaction = approvalValue?.txMeta;
1399
- if (updatedTransaction) {
1400
- projectLogger("Updating transaction with approval data", {
1401
- customNonce: updatedTransaction.customNonceValue,
1402
- params: updatedTransaction.txParams
1403
- });
1404
- this.updateTransaction(
1405
- updatedTransaction,
1406
- "TransactionController#processApproval - Updated with approval data"
1407
- );
1408
- }
1409
- }
1410
- const { isCompleted: isTxCompleted } = this.isTransactionCompleted(transactionId);
1411
- if (!isTxCompleted) {
1412
- const approvalResult = await this.approveTransaction(
1413
- transactionId,
1414
- traceContext
1415
- );
1416
- if (approvalResult === "skipped-via-before-publish-hook" /* SkippedViaBeforePublishHook */ && resultCallbacks) {
1417
- resultCallbacks.success();
1418
- }
1419
- const updatedTransactionMeta = this.getTransaction(
1420
- transactionId
1421
- );
1422
- this.messagingSystem.publish(
1423
- `${controllerName}:transactionApproved`,
1424
- {
1425
- transactionMeta: updatedTransactionMeta,
1426
- actionId
1427
- }
1428
- );
1429
- }
1430
- } catch (error) {
1431
- const { isCompleted: isTxCompleted } = this.isTransactionCompleted(transactionId);
1432
- if (!isTxCompleted) {
1433
- if (error?.code === errorCodes.provider.userRejectedRequest) {
1434
- this.cancelTransaction(transactionId, actionId);
1435
- throw providerErrors.userRejectedRequest(
1436
- "MetaMask Tx Signature: User denied transaction signature."
1437
- );
1438
- } else {
1439
- this.failTransaction(meta, error, actionId);
1440
- }
1441
- }
1442
- }
1443
- }
1444
- const finalMeta = await finishedPromise;
1445
- switch (finalMeta?.status) {
1446
- case "failed" /* failed */:
1447
- resultCallbacks?.error(finalMeta.error);
1448
- throw rpcErrors.internal(finalMeta.error.message);
1449
- case "submitted" /* submitted */:
1450
- resultCallbacks?.success();
1451
- return finalMeta.hash;
1452
- default:
1453
- const internalError = rpcErrors.internal(
1454
- `MetaMask Tx Signature: Unknown problem: ${JSON.stringify(
1455
- finalMeta || transactionId
1456
- )}`
1457
- );
1458
- resultCallbacks?.error(internalError);
1459
- throw internalError;
1460
- }
1461
- }
1462
- /**
1463
- * Approves a transaction and updates it's status in state. If this is not a
1464
- * retry transaction, a nonce will be generated. The transaction is signed
1465
- * using the sign configuration property, then published to the blockchain.
1466
- * A `<tx.id>:finished` hub event is fired after success or failure.
1467
- *
1468
- * @param transactionId - The ID of the transaction to approve.
1469
- * @param traceContext - The parent context for any new traces.
1470
- */
1471
- async approveTransaction(transactionId, traceContext) {
1472
- const cleanupTasks = new Array();
1473
- cleanupTasks.push(await this.mutex.acquire());
1474
- let transactionMeta = this.getTransactionOrThrow(transactionId);
1475
- try {
1476
- if (!this.sign) {
1477
- this.failTransaction(
1478
- transactionMeta,
1479
- new Error("No sign method defined.")
1480
- );
1481
- return "not-approved" /* NotApproved */;
1482
- } else if (!transactionMeta.chainId) {
1483
- this.failTransaction(transactionMeta, new Error("No chainId defined."));
1484
- return "not-approved" /* NotApproved */;
1485
- }
1486
- if (this.approvingTransactionIds.has(transactionId)) {
1487
- projectLogger("Skipping approval as signing in progress", transactionId);
1488
- return "not-approved" /* NotApproved */;
1489
- }
1490
- this.approvingTransactionIds.add(transactionId);
1491
- cleanupTasks.push(
1492
- () => this.approvingTransactionIds.delete(transactionId)
1493
- );
1494
- const [nonce, releaseNonce] = await getNextNonce(
1495
- transactionMeta,
1496
- (address) => __privateGet(this, _multichainTrackingHelper).getNonceLock(
1497
- address,
1498
- transactionMeta.networkClientId
1499
- )
1500
- );
1501
- releaseNonce && cleanupTasks.push(releaseNonce);
1502
- transactionMeta = __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
1503
- transactionId,
1504
- note: "TransactionController#approveTransaction - Transaction approved"
1505
- }, (draftTxMeta) => {
1506
- const { txParams, chainId } = draftTxMeta;
1507
- draftTxMeta.status = "approved" /* approved */;
1508
- draftTxMeta.txParams = {
1509
- ...txParams,
1510
- nonce,
1511
- chainId,
1512
- gasLimit: txParams.gas,
1513
- ...isEIP1559Transaction(txParams) && {
1514
- type: "0x2" /* feeMarket */
1515
- }
1516
- };
1517
- });
1518
- this.onTransactionStatusChange(transactionMeta);
1519
- const rawTx = await __privateGet(this, _trace).call(this, { name: "Sign", parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
1520
- if (!this.beforePublish(transactionMeta)) {
1521
- projectLogger("Skipping publishing transaction based on hook");
1522
- this.messagingSystem.publish(
1523
- `${controllerName}:transactionPublishingSkipped`,
1524
- transactionMeta
1525
- );
1526
- return "skipped-via-before-publish-hook" /* SkippedViaBeforePublishHook */;
1527
- }
1528
- if (!rawTx) {
1529
- return "not-approved" /* NotApproved */;
1530
- }
1531
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
1532
- networkClientId: transactionMeta.networkClientId,
1533
- chainId: transactionMeta.chainId
1534
- });
1535
- let preTxBalance;
1536
- const shouldUpdatePreTxBalance = transactionMeta.type === "swap" /* swap */;
1537
- if (shouldUpdatePreTxBalance) {
1538
- projectLogger("Determining pre-transaction balance");
1539
- preTxBalance = await query(ethQuery, "getBalance", [
1540
- transactionMeta.txParams.from
1541
- ]);
1542
- }
1543
- projectLogger("Publishing transaction", transactionMeta.txParams);
1544
- let hash;
1545
- await __privateGet(this, _trace).call(this, { name: "Publish", parentContext: traceContext }, async () => {
1546
- ({ transactionHash: hash } = await this.publish(
1547
- transactionMeta,
1548
- rawTx
1549
- ));
1550
- if (hash === void 0) {
1551
- hash = await this.publishTransaction(ethQuery, rawTx);
1552
- }
1553
- });
1554
- projectLogger("Publish successful", hash);
1555
- transactionMeta = __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
1556
- transactionId,
1557
- note: "TransactionController#approveTransaction - Transaction submitted"
1558
- }, (draftTxMeta) => {
1559
- draftTxMeta.hash = hash;
1560
- draftTxMeta.status = "submitted" /* submitted */;
1561
- draftTxMeta.submittedTime = (/* @__PURE__ */ new Date()).getTime();
1562
- if (shouldUpdatePreTxBalance) {
1563
- draftTxMeta.preTxBalance = preTxBalance;
1564
- projectLogger("Updated pre-transaction balance", preTxBalance);
1565
- }
1566
- });
1567
- this.messagingSystem.publish(`${controllerName}:transactionSubmitted`, {
1568
- transactionMeta
1569
- });
1570
- this.messagingSystem.publish(
1571
- `${controllerName}:transactionFinished`,
1572
- transactionMeta
1573
- );
1574
- __privateGet(this, _internalEvents).emit(`${transactionId}:finished`, transactionMeta);
1575
- this.onTransactionStatusChange(transactionMeta);
1576
- return "approved" /* Approved */;
1577
- } catch (error) {
1578
- this.failTransaction(transactionMeta, error);
1579
- return "not-approved" /* NotApproved */;
1580
- } finally {
1581
- cleanupTasks.forEach((task) => task());
1582
- }
1583
- }
1584
- async publishTransaction(ethQuery, rawTransaction) {
1585
- return await query(ethQuery, "sendRawTransaction", [rawTransaction]);
1586
- }
1587
- /**
1588
- * Cancels a transaction based on its ID by setting its status to "rejected"
1589
- * and emitting a `<tx.id>:finished` hub event.
1590
- *
1591
- * @param transactionId - The ID of the transaction to cancel.
1592
- * @param actionId - The actionId passed from UI
1593
- */
1594
- cancelTransaction(transactionId, actionId) {
1595
- const transactionMeta = this.state.transactions.find(
1596
- ({ id }) => id === transactionId
1597
- );
1598
- if (!transactionMeta) {
1599
- return;
1600
- }
1601
- this.update((state) => {
1602
- const transactions = state.transactions.filter(
1603
- ({ id }) => id !== transactionId
1604
- );
1605
- state.transactions = this.trimTransactionsForState(transactions);
1606
- });
1607
- const updatedTransactionMeta = {
1608
- ...transactionMeta,
1609
- status: "rejected" /* rejected */
1610
- };
1611
- this.messagingSystem.publish(
1612
- `${controllerName}:transactionFinished`,
1613
- updatedTransactionMeta
1614
- );
1615
- __privateGet(this, _internalEvents).emit(
1616
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1617
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1618
- `${transactionMeta.id}:finished`,
1619
- updatedTransactionMeta
1620
- );
1621
- this.messagingSystem.publish(`${controllerName}:transactionRejected`, {
1622
- transactionMeta: updatedTransactionMeta,
1623
- actionId
1624
- });
1625
- this.onTransactionStatusChange(updatedTransactionMeta);
1626
- }
1627
- /**
1628
- * Trim the amount of transactions that are set on the state. Checks
1629
- * if the length of the tx history is longer then desired persistence
1630
- * limit and then if it is removes the oldest confirmed or rejected tx.
1631
- * Pending or unapproved transactions will not be removed by this
1632
- * operation. For safety of presenting a fully functional transaction UI
1633
- * representation, this function will not break apart transactions with the
1634
- * same nonce, created on the same day, per network. Not accounting for
1635
- * transactions of the same nonce, same day and network combo can result in
1636
- * confusing or broken experiences in the UI.
1637
- *
1638
- * @param transactions - The transactions to be applied to the state.
1639
- * @returns The trimmed list of transactions.
1640
- */
1641
- trimTransactionsForState(transactions) {
1642
- const nonceNetworkSet = /* @__PURE__ */ new Set();
1643
- const txsToKeep = [...transactions].sort((a, b) => a.time > b.time ? -1 : 1).filter((tx) => {
1644
- const { chainId, status, txParams, time } = tx;
1645
- if (txParams) {
1646
- const key = `${String(txParams.nonce)}-${convertHexToDecimal(
1647
- chainId
1648
- )}-${new Date(time).toDateString()}`;
1649
- if (nonceNetworkSet.has(key)) {
1650
- return true;
1651
- } else if (nonceNetworkSet.size < __privateGet(this, _transactionHistoryLimit) || !this.isFinalState(status)) {
1652
- nonceNetworkSet.add(key);
1653
- return true;
1654
- }
1655
- }
1656
- return false;
1657
- });
1658
- txsToKeep.reverse();
1659
- return txsToKeep;
1660
- }
1661
- /**
1662
- * Determines if the transaction is in a final state.
1663
- *
1664
- * @param status - The transaction status.
1665
- * @returns Whether the transaction is in a final state.
1666
- */
1667
- isFinalState(status) {
1668
- return status === "rejected" /* rejected */ || status === "confirmed" /* confirmed */ || status === "failed" /* failed */;
1669
- }
1670
- /**
1671
- * Whether the transaction has at least completed all local processing.
1672
- *
1673
- * @param status - The transaction status.
1674
- * @returns Whether the transaction is in a final state.
1675
- */
1676
- isLocalFinalState(status) {
1677
- return [
1678
- "confirmed" /* confirmed */,
1679
- "failed" /* failed */,
1680
- "rejected" /* rejected */,
1681
- "submitted" /* submitted */
1682
- ].includes(status);
1683
- }
1684
- async requestApproval(txMeta, {
1685
- shouldShowRequest,
1686
- traceContext
1687
- }) {
1688
- const id = this.getApprovalId(txMeta);
1689
- const { origin } = txMeta;
1690
- const type = ApprovalType.Transaction;
1691
- const requestData = { txId: txMeta.id };
1692
- await __privateGet(this, _trace).call(this, {
1693
- name: "Notification Display",
1694
- id,
1695
- parentContext: traceContext
1696
- });
1697
- return await this.messagingSystem.call(
1698
- "ApprovalController:addRequest",
1699
- {
1700
- id,
1701
- origin: origin || ORIGIN_METAMASK,
1702
- type,
1703
- requestData,
1704
- expectsResult: true
1705
- },
1706
- shouldShowRequest
1707
- );
1708
- }
1709
- getTransaction(transactionId) {
1710
- const { transactions } = this.state;
1711
- return transactions.find(({ id }) => id === transactionId);
1712
- }
1713
- getTransactionOrThrow(transactionId, errorMessagePrefix = "TransactionController") {
1714
- const txMeta = this.getTransaction(transactionId);
1715
- if (!txMeta) {
1716
- throw new Error(
1717
- `${errorMessagePrefix}: No transaction found with id ${transactionId}`
1718
- );
1719
- }
1720
- return txMeta;
1721
- }
1722
- getApprovalId(txMeta) {
1723
- return String(txMeta.id);
1724
- }
1725
- isTransactionCompleted(transactionId) {
1726
- const transaction = this.getTransaction(transactionId);
1727
- if (!transaction) {
1728
- return { meta: void 0, isCompleted: false };
1729
- }
1730
- const isCompleted = this.isLocalFinalState(transaction.status);
1731
- return { meta: transaction, isCompleted };
1732
- }
1733
- getChainId(networkClientId) {
1734
- const globalChainId = __privateMethod(this, _getGlobalChainId, getGlobalChainId_fn).call(this);
1735
- const globalNetworkClientId = __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
1736
- if (!networkClientId || networkClientId === globalNetworkClientId) {
1737
- return globalChainId;
1738
- }
1739
- return this.messagingSystem.call(
1740
- `NetworkController:getNetworkClientById`,
1741
- networkClientId
1742
- ).configuration.chainId;
1743
- }
1744
- prepareUnsignedEthTx(chainId, txParams) {
1745
- return TransactionFactory.fromTxData(txParams, {
1746
- freeze: false,
1747
- common: this.getCommonConfiguration(chainId)
1748
- });
1749
- }
1750
- /**
1751
- * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
1752
- * specifying which chain, network, hardfork and EIPs to support for
1753
- * a transaction. By referencing this configuration, and analyzing the fields
1754
- * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
1755
- * transaction type to use.
1756
- *
1757
- * @param chainId - The chainId to use for the configuration.
1758
- * @returns common configuration object
1759
- */
1760
- getCommonConfiguration(chainId) {
1761
- const customChainParams = {
1762
- chainId: parseInt(chainId, 16),
1763
- defaultHardfork: HARDFORK
1764
- };
1765
- return Common.custom(customChainParams);
1766
- }
1767
- onIncomingTransactions({
1768
- added,
1769
- updated
1770
- }) {
1771
- this.update((state) => {
1772
- const { transactions: currentTransactions } = state;
1773
- const updatedTransactions = [
1774
- ...added,
1775
- ...currentTransactions.map((originalTransaction) => {
1776
- const updatedTransaction = updated.find(
1777
- ({ hash }) => hash === originalTransaction.hash
1778
- );
1779
- return updatedTransaction ?? originalTransaction;
1780
- })
1781
- ];
1782
- state.transactions = this.trimTransactionsForState(updatedTransactions);
1783
- });
1784
- }
1785
- onUpdatedLastFetchedBlockNumbers({
1786
- lastFetchedBlockNumbers,
1787
- blockNumber
1788
- }) {
1789
- this.update((state) => {
1790
- state.lastFetchedBlockNumbers = lastFetchedBlockNumbers;
1791
- });
1792
- this.messagingSystem.publish(
1793
- `${controllerName}:incomingTransactionBlockReceived`,
1794
- blockNumber
1795
- );
1796
- }
1797
- generateDappSuggestedGasFees(txParams, origin) {
1798
- if (!origin || origin === ORIGIN_METAMASK) {
1799
- return void 0;
1800
- }
1801
- const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } = txParams;
1802
- if (gasPrice === void 0 && maxFeePerGas === void 0 && maxPriorityFeePerGas === void 0 && gas === void 0) {
1803
- return void 0;
1804
- }
1805
- const dappSuggestedGasFees = {};
1806
- if (gasPrice !== void 0) {
1807
- dappSuggestedGasFees.gasPrice = gasPrice;
1808
- } else if (maxFeePerGas !== void 0 || maxPriorityFeePerGas !== void 0) {
1809
- dappSuggestedGasFees.maxFeePerGas = maxFeePerGas;
1810
- dappSuggestedGasFees.maxPriorityFeePerGas = maxPriorityFeePerGas;
1811
- }
1812
- if (gas !== void 0) {
1813
- dappSuggestedGasFees.gas = gas;
1814
- }
1815
- return dappSuggestedGasFees;
1816
- }
1817
- /**
1818
- * Validates and adds external provided transaction to state.
1819
- *
1820
- * @param transactionMeta - Nominated external transaction to be added to state.
1821
- * @returns The new transaction.
1822
- */
1823
- addExternalTransaction(transactionMeta) {
1824
- const { chainId } = transactionMeta;
1825
- const { transactions } = this.state;
1826
- const fromAddress = transactionMeta?.txParams?.from;
1827
- const sameFromAndNetworkTransactions = transactions.filter(
1828
- (transaction) => transaction.txParams.from === fromAddress && transaction.chainId === chainId
1829
- );
1830
- const confirmedTxs = sameFromAndNetworkTransactions.filter(
1831
- (transaction) => transaction.status === "confirmed" /* confirmed */
1832
- );
1833
- const pendingTxs = sameFromAndNetworkTransactions.filter(
1834
- (transaction) => transaction.status === "submitted" /* submitted */
1835
- );
1836
- validateConfirmedExternalTransaction(
1837
- transactionMeta,
1838
- confirmedTxs,
1839
- pendingTxs
1840
- );
1841
- const newTransactionMeta = (transactionMeta.history ?? []).length === 0 && !this.isHistoryDisabled ? addInitialHistorySnapshot(transactionMeta) : transactionMeta;
1842
- this.update((state) => {
1843
- state.transactions = this.trimTransactionsForState([
1844
- ...state.transactions,
1845
- newTransactionMeta
1846
- ]);
1847
- });
1848
- return newTransactionMeta;
1849
- }
1850
- /**
1851
- * Sets other txMeta statuses to dropped if the txMeta that has been confirmed has other transactions
1852
- * in the transactions have the same nonce.
1853
- *
1854
- * @param transactionId - Used to identify original transaction.
1855
- */
1856
- markNonceDuplicatesDropped(transactionId) {
1857
- const transactionMeta = this.getTransaction(transactionId);
1858
- if (!transactionMeta) {
1859
- return;
1860
- }
1861
- const nonce = transactionMeta.txParams?.nonce;
1862
- const from = transactionMeta.txParams?.from;
1863
- const { chainId } = transactionMeta;
1864
- const sameNonceTransactions = this.state.transactions.filter(
1865
- (transaction) => transaction.id !== transactionId && transaction.txParams.from === from && transaction.txParams.nonce === nonce && transaction.chainId === chainId && transaction.type !== "incoming" /* incoming */
1866
- );
1867
- const sameNonceTransactionIds = sameNonceTransactions.map(
1868
- (transaction) => transaction.id
1869
- );
1870
- if (sameNonceTransactions.length === 0) {
1871
- return;
1872
- }
1873
- this.update((state) => {
1874
- for (const transaction of state.transactions) {
1875
- if (sameNonceTransactionIds.includes(transaction.id)) {
1876
- transaction.replacedBy = transactionMeta?.hash;
1877
- transaction.replacedById = transactionMeta?.id;
1878
- }
1879
- }
1880
- });
1881
- for (const transaction of this.state.transactions) {
1882
- if (sameNonceTransactionIds.includes(transaction.id) && transaction.status !== "failed" /* failed */) {
1883
- this.setTransactionStatusDropped(transaction);
1884
- }
1885
- }
1886
- }
1887
- /**
1888
- * Method to set transaction status to dropped.
1889
- *
1890
- * @param transactionMeta - TransactionMeta of transaction to be marked as dropped.
1891
- */
1892
- setTransactionStatusDropped(transactionMeta) {
1893
- const updatedTransactionMeta = {
1894
- ...transactionMeta,
1895
- status: "dropped" /* dropped */
1896
- };
1897
- this.messagingSystem.publish(`${controllerName}:transactionDropped`, {
1898
- transactionMeta: updatedTransactionMeta
1899
- });
1900
- this.updateTransaction(
1901
- updatedTransactionMeta,
1902
- "TransactionController#setTransactionStatusDropped - Transaction dropped"
1903
- );
1904
- this.onTransactionStatusChange(updatedTransactionMeta);
1905
- }
1906
- /**
1907
- * Get transaction with provided actionId.
1908
- *
1909
- * @param actionId - Unique ID to prevent duplicate requests
1910
- * @returns the filtered transaction
1911
- */
1912
- getTransactionWithActionId(actionId) {
1913
- return this.state.transactions.find(
1914
- (transaction) => actionId && transaction.actionId === actionId
1915
- );
1916
- }
1917
- async waitForTransactionFinished(transactionId) {
1918
- return new Promise((resolve) => {
1919
- __privateGet(this, _internalEvents).once(`${transactionId}:finished`, (txMeta) => {
1920
- resolve(txMeta);
1921
- });
1922
- });
1923
- }
1924
- /**
1925
- * Updates the r, s, and v properties of a TransactionMeta object
1926
- * with values from a signed transaction.
1927
- *
1928
- * @param transactionMeta - The TransactionMeta object to update.
1929
- * @param signedTx - The encompassing type for all transaction types containing r, s, and v values.
1930
- * @returns The updated TransactionMeta object.
1931
- */
1932
- updateTransactionMetaRSV(transactionMeta, signedTx) {
1933
- const transactionMetaWithRsv = cloneDeep(transactionMeta);
1934
- for (const key of ["r", "s", "v"]) {
1935
- const value = signedTx[key];
1936
- if (value === void 0 || value === null) {
1937
- continue;
1938
- }
1939
- transactionMetaWithRsv[key] = add0x(value.toString(16));
1940
- }
1941
- return transactionMetaWithRsv;
1942
- }
1943
- async getEIP1559Compatibility(networkClientId) {
1944
- const currentNetworkIsEIP1559Compatible = await this.getCurrentNetworkEIP1559Compatibility(networkClientId);
1945
- const currentAccountIsEIP1559Compatible = await this.getCurrentAccountEIP1559Compatibility();
1946
- return currentNetworkIsEIP1559Compatible && currentAccountIsEIP1559Compatible;
1947
- }
1948
- async signTransaction(transactionMeta, txParams) {
1949
- projectLogger("Signing transaction", txParams);
1950
- const unsignedEthTx = this.prepareUnsignedEthTx(
1951
- transactionMeta.chainId,
1952
- txParams
1953
- );
1954
- this.approvingTransactionIds.add(transactionMeta.id);
1955
- const signedTx = await new Promise((resolve, reject) => {
1956
- this.sign?.(
1957
- unsignedEthTx,
1958
- txParams.from,
1959
- ...this.getAdditionalSignArguments(transactionMeta)
1960
- ).then(resolve, reject);
1961
- this.signAbortCallbacks.set(
1962
- transactionMeta.id,
1963
- () => reject(new Error("Signing aborted by user"))
1964
- );
1965
- });
1966
- this.signAbortCallbacks.delete(transactionMeta.id);
1967
- if (!signedTx) {
1968
- projectLogger("Skipping signed status as no signed transaction");
1969
- return void 0;
1970
- }
1971
- const transactionMetaFromHook = cloneDeep(transactionMeta);
1972
- if (!this.afterSign(transactionMetaFromHook, signedTx)) {
1973
- this.updateTransaction(
1974
- transactionMetaFromHook,
1975
- "TransactionController#signTransaction - Update after sign"
1976
- );
1977
- projectLogger("Skipping signed status based on hook");
1978
- return void 0;
1979
- }
1980
- const transactionMetaWithRsv = {
1981
- ...this.updateTransactionMetaRSV(transactionMetaFromHook, signedTx),
1982
- status: "signed" /* signed */
1983
- };
1984
- this.updateTransaction(
1985
- transactionMetaWithRsv,
1986
- "TransactionController#approveTransaction - Transaction signed"
1987
- );
1988
- this.onTransactionStatusChange(transactionMetaWithRsv);
1989
- const rawTx = bufferToHex(signedTx.serialize());
1990
- const transactionMetaWithRawTx = merge({}, transactionMetaWithRsv, {
1991
- rawTx
1992
- });
1993
- this.updateTransaction(
1994
- transactionMetaWithRawTx,
1995
- "TransactionController#approveTransaction - RawTransaction added"
1996
- );
1997
- return rawTx;
1998
- }
1999
- onTransactionStatusChange(transactionMeta) {
2000
- this.messagingSystem.publish(`${controllerName}:transactionStatusUpdated`, {
2001
- transactionMeta
2002
- });
2003
- }
2004
- getNonceTrackerTransactions(status, address, chainId = this.getChainId()) {
2005
- return getAndFormatTransactionsForNonceTracker(
2006
- chainId,
2007
- address,
2008
- status,
2009
- this.state.transactions
2010
- );
2011
- }
2012
- onConfirmedTransaction(transactionMeta) {
2013
- projectLogger("Processing confirmed transaction", transactionMeta.id);
2014
- this.markNonceDuplicatesDropped(transactionMeta.id);
2015
- this.messagingSystem.publish(
2016
- `${controllerName}:transactionConfirmed`,
2017
- transactionMeta
2018
- );
2019
- this.onTransactionStatusChange(transactionMeta);
2020
- this.updatePostBalance(transactionMeta).catch((error) => {
2021
- projectLogger("Error while updating post balance", error);
2022
- throw error;
2023
- });
2024
- }
2025
- async updatePostBalance(transactionMeta) {
2026
- try {
2027
- if (transactionMeta.type !== "swap" /* swap */) {
2028
- return;
2029
- }
2030
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
2031
- networkClientId: transactionMeta.networkClientId,
2032
- chainId: transactionMeta.chainId
2033
- });
2034
- const { updatedTransactionMeta, approvalTransactionMeta } = await updatePostTransactionBalance(transactionMeta, {
2035
- ethQuery,
2036
- getTransaction: this.getTransaction.bind(this),
2037
- updateTransaction: this.updateTransaction.bind(this)
2038
- });
2039
- this.messagingSystem.publish(
2040
- `${controllerName}:postTransactionBalanceUpdated`,
2041
- {
2042
- transactionMeta: updatedTransactionMeta,
2043
- approvalTransactionMeta
2044
- }
2045
- );
2046
- } catch (error) {
2047
- projectLogger("Error while updating post transaction balance", error);
2048
- }
2049
- }
2050
- async publishTransactionForRetry(ethQuery, rawTx, transactionMeta) {
2051
- try {
2052
- const hash = await this.publishTransaction(ethQuery, rawTx);
2053
- return hash;
2054
- } catch (error) {
2055
- if (this.isTransactionAlreadyConfirmedError(error)) {
2056
- await this.pendingTransactionTracker.forceCheckTransaction(
2057
- transactionMeta
2058
- );
2059
- throw new Error("Previous transaction is already confirmed");
2060
- }
2061
- throw error;
2062
- }
2063
- }
2064
- /**
2065
- * Ensures that error is a nonce issue
2066
- *
2067
- * @param error - The error to check
2068
- * @returns Whether or not the error is a nonce issue
2069
- */
2070
- // TODO: Replace `any` with type
2071
- // Some networks are returning original error in the data field
2072
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2073
- isTransactionAlreadyConfirmedError(error) {
2074
- return error?.message?.includes("nonce too low") || error?.data?.message?.includes("nonce too low");
2075
- }
2076
- };
2077
- _internalEvents = new WeakMap();
2078
- _incomingTransactionOptions = new WeakMap();
2079
- _pendingTransactionOptions = new WeakMap();
2080
- _trace = new WeakMap();
2081
- _transactionHistoryLimit = new WeakMap();
2082
- _isSimulationEnabled = new WeakMap();
2083
- _testGasFeeFlows = new WeakMap();
2084
- _multichainTrackingHelper = new WeakMap();
2085
- _retryTransaction = new WeakSet();
2086
- retryTransaction_fn = async function({
2087
- actionId,
2088
- afterSubmit,
2089
- estimatedBaseFee,
2090
- gasValues,
2091
- label,
2092
- prepareTransactionParams,
2093
- rate,
2094
- transactionId,
2095
- transactionType
2096
- }) {
2097
- if (this.getTransactionWithActionId(actionId)) {
2098
- return;
2099
- }
2100
- if (gasValues) {
2101
- gasValues = normalizeGasFeeValues(gasValues);
2102
- validateGasValues(gasValues);
2103
- }
2104
- projectLogger(`Creating ${label} transaction`, transactionId, gasValues);
2105
- const transactionMeta = this.getTransaction(transactionId);
2106
- if (!transactionMeta) {
2107
- return;
2108
- }
2109
- if (!this.sign) {
2110
- throw new Error("No sign method defined.");
2111
- }
2112
- const newTxParams = getTransactionParamsWithIncreasedGasFee(
2113
- transactionMeta.txParams,
2114
- rate,
2115
- gasValues
2116
- );
2117
- prepareTransactionParams?.(newTxParams);
2118
- const unsignedEthTx = this.prepareUnsignedEthTx(
2119
- transactionMeta.chainId,
2120
- newTxParams
2121
- );
2122
- const signedTx = await this.sign(
2123
- unsignedEthTx,
2124
- transactionMeta.txParams.from
2125
- );
2126
- const transactionMetaWithRsv = this.updateTransactionMetaRSV(
2127
- transactionMeta,
2128
- signedTx
2129
- );
2130
- const rawTx = bufferToHex(signedTx.serialize());
2131
- const newFee = newTxParams.maxFeePerGas ?? newTxParams.gasPrice;
2132
- const oldFee = newTxParams.maxFeePerGas ? transactionMetaWithRsv.txParams.maxFeePerGas : transactionMetaWithRsv.txParams.gasPrice;
2133
- projectLogger(`Submitting ${label} transaction`, {
2134
- oldFee,
2135
- newFee,
2136
- txParams: newTxParams
2137
- });
2138
- const ethQuery = __privateGet(this, _multichainTrackingHelper).getEthQuery({
2139
- networkClientId: transactionMeta.networkClientId,
2140
- chainId: transactionMeta.chainId
2141
- });
2142
- const hash = await this.publishTransactionForRetry(
2143
- ethQuery,
2144
- rawTx,
2145
- transactionMeta
2146
- );
2147
- const newTransactionMeta = {
2148
- ...transactionMetaWithRsv,
2149
- actionId,
2150
- estimatedBaseFee,
2151
- hash,
2152
- id: random(),
2153
- originalGasEstimate: transactionMeta.txParams.gas,
2154
- originalType: transactionMeta.type,
2155
- rawTx,
2156
- time: Date.now(),
2157
- txParams: newTxParams,
2158
- type: transactionType
2159
- };
2160
- this.addMetadata(newTransactionMeta);
2161
- this.messagingSystem.publish(`${controllerName}:transactionApproved`, {
2162
- transactionMeta: newTransactionMeta,
2163
- actionId
2164
- });
2165
- this.messagingSystem.publish(`${controllerName}:transactionSubmitted`, {
2166
- transactionMeta: newTransactionMeta,
2167
- actionId
2168
- });
2169
- afterSubmit?.(newTransactionMeta);
2170
- };
2171
- _createNonceTracker = new WeakSet();
2172
- createNonceTracker_fn = function({
2173
- provider,
2174
- blockTracker,
2175
- chainId
2176
- }) {
2177
- return new NonceTracker({
2178
- // TODO: Fix types
2179
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2180
- provider,
2181
- // TODO: Fix types
2182
- blockTracker,
2183
- getPendingTransactions: __privateMethod(this, _getNonceTrackerPendingTransactions, getNonceTrackerPendingTransactions_fn).bind(
2184
- this,
2185
- chainId
2186
- ),
2187
- getConfirmedTransactions: this.getNonceTrackerTransactions.bind(
2188
- this,
2189
- "confirmed" /* confirmed */
2190
- )
2191
- });
2192
- };
2193
- _createIncomingTransactionHelper = new WeakSet();
2194
- createIncomingTransactionHelper_fn = function({
2195
- blockTracker,
2196
- etherscanRemoteTransactionSource,
2197
- chainId
2198
- }) {
2199
- const incomingTransactionHelper = new IncomingTransactionHelper({
2200
- blockTracker,
2201
- getCurrentAccount: () => __privateMethod(this, _getSelectedAccount, getSelectedAccount_fn).call(this),
2202
- getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
2203
- getChainId: chainId ? () => chainId : this.getChainId.bind(this),
2204
- isEnabled: __privateGet(this, _incomingTransactionOptions).isEnabled,
2205
- queryEntireHistory: __privateGet(this, _incomingTransactionOptions).queryEntireHistory,
2206
- remoteTransactionSource: etherscanRemoteTransactionSource,
2207
- transactionLimit: __privateGet(this, _transactionHistoryLimit),
2208
- updateTransactions: __privateGet(this, _incomingTransactionOptions).updateTransactions
2209
- });
2210
- __privateMethod(this, _addIncomingTransactionHelperListeners, addIncomingTransactionHelperListeners_fn).call(this, incomingTransactionHelper);
2211
- return incomingTransactionHelper;
2212
- };
2213
- _createPendingTransactionTracker = new WeakSet();
2214
- createPendingTransactionTracker_fn = function({
2215
- provider,
2216
- blockTracker,
2217
- chainId
2218
- }) {
2219
- const ethQuery = new EthQuery(provider);
2220
- const getChainId = chainId ? () => chainId : this.getChainId.bind(this);
2221
- const pendingTransactionTracker = new PendingTransactionTracker({
2222
- blockTracker,
2223
- getChainId,
2224
- getEthQuery: () => ethQuery,
2225
- getTransactions: () => this.state.transactions,
2226
- isResubmitEnabled: __privateGet(this, _pendingTransactionOptions).isResubmitEnabled,
2227
- getGlobalLock: () => __privateGet(this, _multichainTrackingHelper).acquireNonceLockForChainIdKey({
2228
- chainId: getChainId()
2229
- }),
2230
- publishTransaction: this.publishTransaction.bind(this),
2231
- hooks: {
2232
- beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
2233
- beforePublish: this.beforePublish.bind(this)
2234
- }
2235
- });
2236
- __privateMethod(this, _addPendingTransactionTrackerListeners, addPendingTransactionTrackerListeners_fn).call(this, pendingTransactionTracker);
2237
- return pendingTransactionTracker;
2238
- };
2239
- _checkForPendingTransactionAndStartPolling = new WeakMap();
2240
- _stopAllTracking = new WeakSet();
2241
- stopAllTracking_fn = function() {
2242
- this.pendingTransactionTracker.stop();
2243
- __privateMethod(this, _removePendingTransactionTrackerListeners, removePendingTransactionTrackerListeners_fn).call(this, this.pendingTransactionTracker);
2244
- this.incomingTransactionHelper.stop();
2245
- __privateMethod(this, _removeIncomingTransactionHelperListeners, removeIncomingTransactionHelperListeners_fn).call(this, this.incomingTransactionHelper);
2246
- __privateGet(this, _multichainTrackingHelper).stopAllTracking();
2247
- };
2248
- _removeIncomingTransactionHelperListeners = new WeakSet();
2249
- removeIncomingTransactionHelperListeners_fn = function(incomingTransactionHelper) {
2250
- incomingTransactionHelper.hub.removeAllListeners("transactions");
2251
- incomingTransactionHelper.hub.removeAllListeners(
2252
- "updatedLastFetchedBlockNumbers"
2253
- );
2254
- };
2255
- _addIncomingTransactionHelperListeners = new WeakSet();
2256
- addIncomingTransactionHelperListeners_fn = function(incomingTransactionHelper) {
2257
- incomingTransactionHelper.hub.on(
2258
- "transactions",
2259
- this.onIncomingTransactions.bind(this)
2260
- );
2261
- incomingTransactionHelper.hub.on(
2262
- "updatedLastFetchedBlockNumbers",
2263
- this.onUpdatedLastFetchedBlockNumbers.bind(this)
2264
- );
2265
- };
2266
- _removePendingTransactionTrackerListeners = new WeakSet();
2267
- removePendingTransactionTrackerListeners_fn = function(pendingTransactionTracker) {
2268
- pendingTransactionTracker.hub.removeAllListeners("transaction-confirmed");
2269
- pendingTransactionTracker.hub.removeAllListeners("transaction-dropped");
2270
- pendingTransactionTracker.hub.removeAllListeners("transaction-failed");
2271
- pendingTransactionTracker.hub.removeAllListeners("transaction-updated");
2272
- };
2273
- _addPendingTransactionTrackerListeners = new WeakSet();
2274
- addPendingTransactionTrackerListeners_fn = function(pendingTransactionTracker) {
2275
- pendingTransactionTracker.hub.on(
2276
- "transaction-confirmed",
2277
- this.onConfirmedTransaction.bind(this)
2278
- );
2279
- pendingTransactionTracker.hub.on(
2280
- "transaction-dropped",
2281
- this.setTransactionStatusDropped.bind(this)
2282
- );
2283
- pendingTransactionTracker.hub.on(
2284
- "transaction-failed",
2285
- this.failTransaction.bind(this)
2286
- );
2287
- pendingTransactionTracker.hub.on(
2288
- "transaction-updated",
2289
- this.updateTransaction.bind(this)
2290
- );
2291
- };
2292
- _getNonceTrackerPendingTransactions = new WeakSet();
2293
- getNonceTrackerPendingTransactions_fn = function(chainId, address) {
2294
- const standardPendingTransactions = this.getNonceTrackerTransactions(
2295
- "submitted" /* submitted */,
2296
- address,
2297
- chainId
2298
- );
2299
- const externalPendingTransactions = this.getExternalPendingTransactions(
2300
- address,
2301
- chainId
2302
- );
2303
- return [...standardPendingTransactions, ...externalPendingTransactions];
2304
- };
2305
- _getGasFeeFlows = new WeakSet();
2306
- getGasFeeFlows_fn = function() {
2307
- if (__privateGet(this, _testGasFeeFlows)) {
2308
- return [new TestGasFeeFlow()];
2309
- }
2310
- return [new LineaGasFeeFlow(), new DefaultGasFeeFlow()];
2311
- };
2312
- _getLayer1GasFeeFlows = new WeakSet();
2313
- getLayer1GasFeeFlows_fn = function() {
2314
- return [new OptimismLayer1GasFeeFlow(), new ScrollLayer1GasFeeFlow()];
2315
- };
2316
- _updateTransactionInternal = new WeakSet();
2317
- updateTransactionInternal_fn = function({
2318
- transactionId,
2319
- note,
2320
- skipHistory,
2321
- skipValidation
2322
- }, callback) {
2323
- let updatedTransactionParams = [];
2324
- this.update((state) => {
2325
- const index = state.transactions.findIndex(
2326
- ({ id }) => id === transactionId
2327
- );
2328
- let transactionMeta2 = state.transactions[index];
2329
- transactionMeta2 = callback(transactionMeta2) ?? transactionMeta2;
2330
- if (skipValidation !== true) {
2331
- transactionMeta2.txParams = normalizeTransactionParams(
2332
- transactionMeta2.txParams
2333
- );
2334
- validateTxParams(transactionMeta2.txParams);
2335
- }
2336
- updatedTransactionParams = __privateMethod(this, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn).call(this, transactionMeta2);
2337
- const shouldSkipHistory = this.isHistoryDisabled || skipHistory;
2338
- if (!shouldSkipHistory) {
2339
- transactionMeta2 = updateTransactionHistory(
2340
- transactionMeta2,
2341
- note ?? "Transaction updated"
2342
- );
2343
- }
2344
- state.transactions[index] = transactionMeta2;
2345
- });
2346
- const transactionMeta = this.getTransaction(
2347
- transactionId
2348
- );
2349
- if (updatedTransactionParams.length > 0) {
2350
- __privateMethod(this, _onTransactionParamsUpdated, onTransactionParamsUpdated_fn).call(this, transactionMeta, updatedTransactionParams);
2351
- }
2352
- return transactionMeta;
2353
- };
2354
- _checkIfTransactionParamsUpdated = new WeakSet();
2355
- checkIfTransactionParamsUpdated_fn = function(newTransactionMeta) {
2356
- const { id: transactionId, txParams: newParams } = newTransactionMeta;
2357
- const originalParams = this.getTransaction(transactionId)?.txParams;
2358
- if (!originalParams || isEqual(originalParams, newParams)) {
2359
- return [];
2360
- }
2361
- const params = Object.keys(newParams);
2362
- const updatedProperties = params.filter(
2363
- (param) => newParams[param] !== originalParams[param]
2364
- );
2365
- projectLogger(
2366
- "Transaction parameters have been updated",
2367
- transactionId,
2368
- updatedProperties,
2369
- originalParams,
2370
- newParams
2371
- );
2372
- return updatedProperties;
2373
- };
2374
- _onTransactionParamsUpdated = new WeakSet();
2375
- onTransactionParamsUpdated_fn = function(transactionMeta, updatedParams) {
2376
- if (["to", "value", "data"].some(
2377
- (param) => updatedParams.includes(param)
2378
- )) {
2379
- projectLogger("Updating simulation data due to transaction parameter update");
2380
- __privateMethod(this, _updateSimulationData, updateSimulationData_fn).call(this, transactionMeta).catch((error) => {
2381
- projectLogger("Error updating simulation data", error);
2382
- throw error;
2383
- });
2384
- }
2385
- };
2386
- _updateSimulationData = new WeakSet();
2387
- updateSimulationData_fn = async function(transactionMeta, { traceContext } = {}) {
2388
- const { id: transactionId, chainId, txParams } = transactionMeta;
2389
- const { from, to, value, data } = txParams;
2390
- let simulationData = {
2391
- error: {
2392
- code: "disabled" /* Disabled */,
2393
- message: "Simulation disabled"
2394
- },
2395
- tokenBalanceChanges: []
2396
- };
2397
- if (__privateGet(this, _isSimulationEnabled).call(this)) {
2398
- __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { transactionId, skipHistory: true }, (txMeta) => {
2399
- txMeta.simulationData = void 0;
2400
- });
2401
- simulationData = await __privateGet(this, _trace).call(this, { name: "Simulate", parentContext: traceContext }, () => getSimulationData({
2402
- chainId,
2403
- from,
2404
- to,
2405
- value,
2406
- data
2407
- }));
2408
- }
2409
- const finalTransactionMeta = this.getTransaction(transactionId);
2410
- if (!finalTransactionMeta) {
2411
- projectLogger(
2412
- "Cannot update simulation data as transaction not found",
2413
- transactionId,
2414
- simulationData
2415
- );
2416
- return;
2417
- }
2418
- __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, {
2419
- transactionId,
2420
- note: "TransactionController#updateSimulationData - Update simulation data"
2421
- }, (txMeta) => {
2422
- txMeta.simulationData = simulationData;
2423
- });
2424
- projectLogger("Updated simulation data", transactionId, simulationData);
2425
- };
2426
- _onGasFeePollerTransactionUpdate = new WeakSet();
2427
- onGasFeePollerTransactionUpdate_fn = function({
2428
- transactionId,
2429
- gasFeeEstimates,
2430
- gasFeeEstimatesLoaded,
2431
- layer1GasFee
2432
- }) {
2433
- __privateMethod(this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { transactionId, skipHistory: true }, (txMeta) => {
2434
- if (gasFeeEstimates) {
2435
- txMeta.gasFeeEstimates = gasFeeEstimates;
2436
- }
2437
- if (gasFeeEstimatesLoaded !== void 0) {
2438
- txMeta.gasFeeEstimatesLoaded = gasFeeEstimatesLoaded;
2439
- }
2440
- if (layer1GasFee) {
2441
- txMeta.layer1GasFee = layer1GasFee;
2442
- }
2443
- });
2444
- };
2445
- _getNetworkClientId = new WeakSet();
2446
- getNetworkClientId_fn = function({
2447
- networkClientId: requestNetworkClientId,
2448
- chainId
2449
- }) {
2450
- const globalChainId = __privateMethod(this, _getGlobalChainId, getGlobalChainId_fn).call(this);
2451
- const globalNetworkClientId = __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
2452
- if (requestNetworkClientId) {
2453
- return requestNetworkClientId;
2454
- }
2455
- if (!chainId || chainId === globalChainId) {
2456
- return globalNetworkClientId;
2457
- }
2458
- return this.messagingSystem.call(
2459
- `NetworkController:findNetworkClientIdByChainId`,
2460
- chainId
2461
- );
2462
- };
2463
- _getGlobalNetworkClientId = new WeakSet();
2464
- getGlobalNetworkClientId_fn = function() {
2465
- return this.getNetworkState().selectedNetworkClientId;
2466
- };
2467
- _getGlobalChainId = new WeakSet();
2468
- getGlobalChainId_fn = function() {
2469
- return this.messagingSystem.call(
2470
- `NetworkController:getNetworkClientById`,
2471
- this.getNetworkState().selectedNetworkClientId
2472
- ).configuration.chainId;
2473
- };
2474
- _isCustomNetwork = new WeakSet();
2475
- isCustomNetwork_fn = function(networkClientId) {
2476
- const globalNetworkClientId = __privateMethod(this, _getGlobalNetworkClientId, getGlobalNetworkClientId_fn).call(this);
2477
- if (!networkClientId || networkClientId === globalNetworkClientId) {
2478
- return !isInfuraNetworkType(
2479
- this.getNetworkState().selectedNetworkClientId
2480
- );
2481
- }
2482
- return this.messagingSystem.call(
2483
- `NetworkController:getNetworkClientById`,
2484
- networkClientId
2485
- ).configuration.type === NetworkClientType.Custom;
2486
- };
2487
- _getSelectedAccount = new WeakSet();
2488
- getSelectedAccount_fn = function() {
2489
- return this.messagingSystem.call("AccountsController:getSelectedAccount");
2490
- };
2491
-
2492
- export {
2493
- HARDFORK,
2494
- CANCEL_RATE,
2495
- SPEED_UP_RATE,
2496
- ApprovalState,
2497
- TransactionController
2498
- };
2499
- //# sourceMappingURL=chunk-REFVF44I.mjs.map