@metamask/transaction-controller 24.0.0 → 25.0.0

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