@metamask/transaction-controller 36.1.0 → 37.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (480) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/dist/TransactionController.cjs +2071 -0
  3. package/dist/TransactionController.cjs.map +1 -0
  4. package/dist/{types/TransactionController.d.ts → TransactionController.d.cts} +19 -26
  5. package/dist/TransactionController.d.cts.map +1 -0
  6. package/dist/TransactionController.d.mts +828 -0
  7. package/dist/TransactionController.d.mts.map +1 -0
  8. package/dist/TransactionController.mjs +2072 -44
  9. package/dist/TransactionController.mjs.map +1 -1
  10. package/dist/constants.cjs +170 -0
  11. package/dist/constants.cjs.map +1 -0
  12. package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
  13. package/dist/constants.d.cts.map +1 -0
  14. package/dist/constants.d.mts +143 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.mjs +165 -18
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/errors.cjs +30 -0
  19. package/dist/{chunk-HMOSP33F.js.map → errors.cjs.map} +1 -1
  20. package/dist/{types/errors.d.ts → errors.d.cts} +2 -2
  21. package/dist/errors.d.cts.map +1 -0
  22. package/dist/errors.d.mts +15 -0
  23. package/dist/errors.d.mts.map +1 -0
  24. package/dist/errors.mjs +22 -14
  25. package/dist/errors.mjs.map +1 -1
  26. package/dist/gas-flows/DefaultGasFeeFlow.cjs +87 -0
  27. package/dist/gas-flows/DefaultGasFeeFlow.cjs.map +1 -0
  28. package/dist/{types/gas-flows/DefaultGasFeeFlow.d.ts → gas-flows/DefaultGasFeeFlow.d.cts} +2 -2
  29. package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -0
  30. package/dist/gas-flows/DefaultGasFeeFlow.d.mts +10 -0
  31. package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -0
  32. package/dist/gas-flows/DefaultGasFeeFlow.mjs +81 -13
  33. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -1
  34. package/dist/gas-flows/LineaGasFeeFlow.cjs +102 -0
  35. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -0
  36. package/dist/{types/gas-flows/LineaGasFeeFlow.d.ts → gas-flows/LineaGasFeeFlow.d.cts} +2 -2
  37. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -0
  38. package/dist/gas-flows/LineaGasFeeFlow.d.mts +12 -0
  39. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -0
  40. package/dist/gas-flows/LineaGasFeeFlow.mjs +96 -14
  41. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  42. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +29 -0
  43. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -0
  44. package/dist/{types/gas-flows/OptimismLayer1GasFeeFlow.d.ts → gas-flows/OptimismLayer1GasFeeFlow.d.cts} +3 -3
  45. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -0
  46. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +10 -0
  47. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -0
  48. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +24 -10
  49. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -1
  50. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +92 -0
  51. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -0
  52. package/dist/{types/gas-flows/OracleLayer1GasFeeFlow.d.ts → gas-flows/OracleLayer1GasFeeFlow.d.cts} +3 -3
  53. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -0
  54. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +12 -0
  55. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -0
  56. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs +88 -7
  57. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
  58. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +21 -0
  59. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -0
  60. package/dist/{types/gas-flows/ScrollLayer1GasFeeFlow.d.ts → gas-flows/ScrollLayer1GasFeeFlow.d.cts} +3 -3
  61. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -0
  62. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +10 -0
  63. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -0
  64. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs +16 -10
  65. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -1
  66. package/dist/gas-flows/TestGasFeeFlow.cjs +73 -0
  67. package/dist/{chunk-FMRLPVFZ.mjs.map → gas-flows/TestGasFeeFlow.cjs.map} +1 -1
  68. package/dist/{types/gas-flows/TestGasFeeFlow.d.ts → gas-flows/TestGasFeeFlow.d.cts} +2 -2
  69. package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -0
  70. package/dist/gas-flows/TestGasFeeFlow.d.mts +12 -0
  71. package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -0
  72. package/dist/gas-flows/TestGasFeeFlow.mjs +67 -7
  73. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -1
  74. package/dist/helpers/EtherscanRemoteTransactionSource.cjs +149 -0
  75. package/dist/helpers/EtherscanRemoteTransactionSource.cjs.map +1 -0
  76. package/dist/{types/helpers/EtherscanRemoteTransactionSource.d.ts → helpers/EtherscanRemoteTransactionSource.d.cts} +3 -3
  77. package/dist/helpers/EtherscanRemoteTransactionSource.d.cts.map +1 -0
  78. package/dist/helpers/EtherscanRemoteTransactionSource.d.mts +15 -0
  79. package/dist/helpers/EtherscanRemoteTransactionSource.d.mts.map +1 -0
  80. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +147 -10
  81. package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -1
  82. package/dist/helpers/GasFeePoller.cjs +185 -0
  83. package/dist/helpers/GasFeePoller.cjs.map +1 -0
  84. package/dist/{types/helpers/GasFeePoller.d.ts → helpers/GasFeePoller.d.cts} +7 -7
  85. package/dist/helpers/GasFeePoller.d.cts.map +1 -0
  86. package/dist/helpers/GasFeePoller.d.mts +35 -0
  87. package/dist/helpers/GasFeePoller.d.mts.map +1 -0
  88. package/dist/helpers/GasFeePoller.mjs +183 -10
  89. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  90. package/dist/helpers/IncomingTransactionHelper.cjs +199 -0
  91. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -0
  92. package/dist/{types/helpers/IncomingTransactionHelper.d.ts → helpers/IncomingTransactionHelper.d.cts} +6 -6
  93. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -0
  94. package/dist/helpers/IncomingTransactionHelper.d.mts +40 -0
  95. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -0
  96. package/dist/helpers/IncomingTransactionHelper.mjs +190 -7
  97. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  98. package/dist/helpers/MultichainTrackingHelper.cjs +284 -0
  99. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -0
  100. package/dist/{types/helpers/MultichainTrackingHelper.d.ts → helpers/MultichainTrackingHelper.d.cts} +8 -8
  101. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -0
  102. package/dist/helpers/MultichainTrackingHelper.d.mts +76 -0
  103. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -0
  104. package/dist/helpers/MultichainTrackingHelper.mjs +282 -11
  105. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  106. package/dist/helpers/PendingTransactionTracker.cjs +327 -0
  107. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
  108. package/dist/{types/helpers/PendingTransactionTracker.d.ts → helpers/PendingTransactionTracker.d.cts} +7 -8
  109. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -0
  110. package/dist/helpers/PendingTransactionTracker.d.mts +42 -0
  111. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -0
  112. package/dist/helpers/PendingTransactionTracker.mjs +319 -8
  113. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  114. package/dist/index.cjs +32 -0
  115. package/dist/index.cjs.map +1 -0
  116. package/dist/{types/index.d.ts → index.d.cts} +11 -10
  117. package/dist/index.d.cts.map +1 -0
  118. package/dist/index.d.mts +11 -0
  119. package/dist/index.d.mts.map +1 -0
  120. package/dist/index.mjs +7 -76
  121. package/dist/index.mjs.map +1 -1
  122. package/dist/logger.cjs +9 -0
  123. package/dist/logger.cjs.map +1 -0
  124. package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
  125. package/dist/logger.d.cts.map +1 -0
  126. package/dist/logger.d.mts +6 -0
  127. package/dist/logger.d.mts.map +1 -0
  128. package/dist/logger.mjs +5 -11
  129. package/dist/logger.mjs.map +1 -1
  130. package/dist/types.cjs +308 -0
  131. package/dist/types.cjs.map +1 -0
  132. package/dist/{types/types.d.ts → types.d.cts} +35 -35
  133. package/dist/types.d.cts.map +1 -0
  134. package/dist/types.d.mts +1027 -0
  135. package/dist/types.d.mts.map +1 -0
  136. package/dist/types.mjs +304 -23
  137. package/dist/types.mjs.map +1 -1
  138. package/dist/utils/etherscan.cjs +111 -0
  139. package/dist/utils/etherscan.cjs.map +1 -0
  140. package/dist/{types/utils/etherscan.d.ts → utils/etherscan.d.cts} +2 -2
  141. package/dist/utils/etherscan.d.cts.map +1 -0
  142. package/dist/utils/etherscan.d.mts +71 -0
  143. package/dist/utils/etherscan.d.mts.map +1 -0
  144. package/dist/utils/etherscan.mjs +104 -13
  145. package/dist/utils/etherscan.mjs.map +1 -1
  146. package/dist/utils/external-transactions.cjs +36 -0
  147. package/dist/utils/external-transactions.cjs.map +1 -0
  148. package/dist/{types/utils/external-transactions.d.ts → utils/external-transactions.d.cts} +2 -2
  149. package/dist/utils/external-transactions.d.cts.map +1 -0
  150. package/dist/utils/external-transactions.d.mts +10 -0
  151. package/dist/utils/external-transactions.d.mts.map +1 -0
  152. package/dist/utils/external-transactions.mjs +31 -8
  153. package/dist/utils/external-transactions.mjs.map +1 -1
  154. package/dist/utils/gas-fees.cjs +208 -0
  155. package/dist/utils/gas-fees.cjs.map +1 -0
  156. package/dist/{types/utils/gas-fees.d.ts → utils/gas-fees.d.cts} +5 -5
  157. package/dist/utils/gas-fees.d.cts.map +1 -0
  158. package/dist/utils/gas-fees.d.mts +26 -0
  159. package/dist/utils/gas-fees.d.mts.map +1 -0
  160. package/dist/utils/gas-fees.mjs +202 -15
  161. package/dist/utils/gas-fees.mjs.map +1 -1
  162. package/dist/utils/gas-flow.cjs +76 -0
  163. package/dist/utils/gas-flow.cjs.map +1 -0
  164. package/dist/{types/utils/gas-flow.d.ts → utils/gas-flow.d.cts} +5 -5
  165. package/dist/utils/gas-flow.d.cts.map +1 -0
  166. package/dist/utils/gas-flow.d.mts +26 -0
  167. package/dist/utils/gas-flow.d.mts.map +1 -0
  168. package/dist/utils/gas-flow.mjs +70 -10
  169. package/dist/utils/gas-flow.mjs.map +1 -1
  170. package/dist/utils/gas.cjs +112 -0
  171. package/dist/utils/gas.cjs.map +1 -0
  172. package/dist/{types/utils/gas.d.ts → utils/gas.d.cts} +4 -4
  173. package/dist/utils/gas.d.cts.map +1 -0
  174. package/dist/utils/gas.d.mts +28 -0
  175. package/dist/utils/gas.d.mts.map +1 -0
  176. package/dist/utils/gas.mjs +105 -19
  177. package/dist/utils/gas.mjs.map +1 -1
  178. package/dist/utils/history.cjs +164 -0
  179. package/dist/utils/history.cjs.map +1 -0
  180. package/dist/{types/utils/history.d.ts → utils/history.d.cts} +2 -2
  181. package/dist/utils/history.d.cts.map +1 -0
  182. package/dist/utils/history.d.mts +29 -0
  183. package/dist/utils/history.d.mts.map +1 -0
  184. package/dist/utils/history.mjs +163 -13
  185. package/dist/utils/history.mjs.map +1 -1
  186. package/dist/utils/layer1-gas-fee-flow.cjs +59 -0
  187. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -0
  188. package/dist/{types/utils/layer1-gas-fee-flow.d.ts → utils/layer1-gas-fee-flow.d.cts} +4 -4
  189. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -0
  190. package/dist/utils/layer1-gas-fee-flow.d.mts +25 -0
  191. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -0
  192. package/dist/utils/layer1-gas-fee-flow.mjs +53 -10
  193. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  194. package/dist/utils/nonce.cjs +66 -0
  195. package/dist/utils/nonce.cjs.map +1 -0
  196. package/dist/{types/utils/nonce.d.ts → utils/nonce.d.cts} +3 -3
  197. package/dist/utils/nonce.d.cts.map +1 -0
  198. package/dist/utils/nonce.d.mts +21 -0
  199. package/dist/utils/nonce.d.mts.map +1 -0
  200. package/dist/utils/nonce.mjs +60 -10
  201. package/dist/utils/nonce.mjs.map +1 -1
  202. package/dist/utils/retry.cjs +89 -0
  203. package/dist/utils/retry.cjs.map +1 -0
  204. package/dist/{types/utils/retry.d.ts → utils/retry.d.cts} +3 -3
  205. package/dist/utils/retry.d.cts.map +1 -0
  206. package/dist/utils/retry.d.mts +11 -0
  207. package/dist/utils/retry.d.mts.map +1 -0
  208. package/dist/utils/retry.mjs +84 -7
  209. package/dist/utils/retry.mjs.map +1 -1
  210. package/dist/utils/simulation-api.cjs +72 -0
  211. package/dist/utils/simulation-api.cjs.map +1 -0
  212. package/dist/{types/utils/simulation-api.d.ts → utils/simulation-api.d.cts} +2 -2
  213. package/dist/utils/simulation-api.d.cts.map +1 -0
  214. package/dist/utils/simulation-api.d.mts +107 -0
  215. package/dist/utils/simulation-api.d.mts.map +1 -0
  216. package/dist/utils/simulation-api.mjs +67 -10
  217. package/dist/utils/simulation-api.mjs.map +1 -1
  218. package/dist/utils/simulation.cjs +443 -0
  219. package/dist/utils/simulation.cjs.map +1 -0
  220. package/dist/{types/utils/simulation.d.ts → utils/simulation.d.cts} +6 -6
  221. package/dist/utils/simulation.d.cts.map +1 -0
  222. package/dist/utils/simulation.d.mts +46 -0
  223. package/dist/utils/simulation.d.mts.map +1 -0
  224. package/dist/utils/simulation.mjs +436 -15
  225. package/dist/utils/simulation.mjs.map +1 -1
  226. package/dist/utils/swaps.cjs +309 -0
  227. package/dist/utils/swaps.cjs.map +1 -0
  228. package/dist/{types/utils/swaps.d.ts → utils/swaps.d.cts} +5 -5
  229. package/dist/utils/swaps.d.cts.map +1 -0
  230. package/dist/utils/swaps.d.mts +84 -0
  231. package/dist/utils/swaps.d.mts.map +1 -0
  232. package/dist/utils/swaps.mjs +303 -22
  233. package/dist/utils/swaps.mjs.map +1 -1
  234. package/dist/utils/transaction-type.cjs +115 -0
  235. package/dist/utils/transaction-type.cjs.map +1 -0
  236. package/dist/{types/utils/transaction-type.d.ts → utils/transaction-type.d.cts} +3 -3
  237. package/dist/utils/transaction-type.d.cts.map +1 -0
  238. package/dist/utils/transaction-type.d.mts +14 -0
  239. package/dist/utils/transaction-type.d.mts.map +1 -0
  240. package/dist/utils/transaction-type.mjs +110 -10
  241. package/dist/utils/transaction-type.mjs.map +1 -1
  242. package/dist/utils/utils.cjs +151 -0
  243. package/dist/utils/utils.cjs.map +1 -0
  244. package/dist/{types/utils/utils.d.ts → utils/utils.d.cts} +2 -2
  245. package/dist/utils/utils.d.cts.map +1 -0
  246. package/dist/utils/utils.d.mts +52 -0
  247. package/dist/utils/utils.d.mts.map +1 -0
  248. package/dist/utils/utils.mjs +139 -21
  249. package/dist/utils/utils.mjs.map +1 -1
  250. package/dist/utils/validation.cjs +267 -0
  251. package/dist/{chunk-4OYPDGHO.js.map → utils/validation.cjs.map} +1 -1
  252. package/dist/{types/utils/validation.d.ts → utils/validation.d.cts} +2 -2
  253. package/dist/utils/validation.d.cts.map +1 -0
  254. package/dist/utils/validation.d.mts +20 -0
  255. package/dist/utils/validation.d.mts.map +1 -0
  256. package/dist/utils/validation.mjs +261 -11
  257. package/dist/utils/validation.mjs.map +1 -1
  258. package/package.json +20 -15
  259. package/dist/TransactionController.js +0 -46
  260. package/dist/TransactionController.js.map +0 -1
  261. package/dist/chunk-2XKEAKQG.js +0 -55
  262. package/dist/chunk-2XKEAKQG.js.map +0 -1
  263. package/dist/chunk-3AVRGHUO.mjs +0 -360
  264. package/dist/chunk-3AVRGHUO.mjs.map +0 -1
  265. package/dist/chunk-3ZV5YEUV.mjs +0 -239
  266. package/dist/chunk-3ZV5YEUV.mjs.map +0 -1
  267. package/dist/chunk-4OYPDGHO.js +0 -201
  268. package/dist/chunk-4V4XIPCI.mjs +0 -338
  269. package/dist/chunk-4V4XIPCI.mjs.map +0 -1
  270. package/dist/chunk-5G6OHAXI.mjs +0 -137
  271. package/dist/chunk-5G6OHAXI.mjs.map +0 -1
  272. package/dist/chunk-5HYWLTVQ.js +0 -228
  273. package/dist/chunk-5HYWLTVQ.js.map +0 -1
  274. package/dist/chunk-5QVDIVJH.js +0 -68
  275. package/dist/chunk-5QVDIVJH.js.map +0 -1
  276. package/dist/chunk-6B5BEO3R.mjs +0 -399
  277. package/dist/chunk-6B5BEO3R.mjs.map +0 -1
  278. package/dist/chunk-6DDVVUJC.mjs +0 -50
  279. package/dist/chunk-6DDVVUJC.mjs.map +0 -1
  280. package/dist/chunk-6OLJWLKK.js +0 -338
  281. package/dist/chunk-6OLJWLKK.js.map +0 -1
  282. package/dist/chunk-7LXE4KHV.js +0 -40
  283. package/dist/chunk-7LXE4KHV.js.map +0 -1
  284. package/dist/chunk-7NMV2NPM.js +0 -172
  285. package/dist/chunk-7NMV2NPM.js.map +0 -1
  286. package/dist/chunk-AWIJZAW3.mjs +0 -112
  287. package/dist/chunk-AWIJZAW3.mjs.map +0 -1
  288. package/dist/chunk-BZV72SCF.js +0 -226
  289. package/dist/chunk-BZV72SCF.js.map +0 -1
  290. package/dist/chunk-EGQCE3FK.mjs +0 -85
  291. package/dist/chunk-EGQCE3FK.mjs.map +0 -1
  292. package/dist/chunk-EHWAY6XU.js +0 -112
  293. package/dist/chunk-EHWAY6XU.js.map +0 -1
  294. package/dist/chunk-EKJXGERC.mjs +0 -172
  295. package/dist/chunk-EKJXGERC.mjs.map +0 -1
  296. package/dist/chunk-FG74Z3F5.mjs +0 -102
  297. package/dist/chunk-FG74Z3F5.mjs.map +0 -1
  298. package/dist/chunk-FMRLPVFZ.mjs +0 -66
  299. package/dist/chunk-FRKQ3Z2L.mjs +0 -40
  300. package/dist/chunk-FRKQ3Z2L.mjs.map +0 -1
  301. package/dist/chunk-HMOSP33F.js +0 -36
  302. package/dist/chunk-HQSNKCXI.mjs +0 -36
  303. package/dist/chunk-HQSNKCXI.mjs.map +0 -1
  304. package/dist/chunk-JIFPK37W.mjs +0 -257
  305. package/dist/chunk-JIFPK37W.mjs.map +0 -1
  306. package/dist/chunk-JOQK7A5G.mjs +0 -68
  307. package/dist/chunk-JOQK7A5G.mjs.map +0 -1
  308. package/dist/chunk-K4KOSAGM.mjs +0 -61
  309. package/dist/chunk-K4KOSAGM.mjs.map +0 -1
  310. package/dist/chunk-KG4UW4K4.mjs +0 -88
  311. package/dist/chunk-KG4UW4K4.mjs.map +0 -1
  312. package/dist/chunk-KT6UAKBB.js +0 -61
  313. package/dist/chunk-KT6UAKBB.js.map +0 -1
  314. package/dist/chunk-KTGMNUTQ.js +0 -106
  315. package/dist/chunk-KTGMNUTQ.js.map +0 -1
  316. package/dist/chunk-KYRW4BLA.mjs +0 -121
  317. package/dist/chunk-KYRW4BLA.mjs.map +0 -1
  318. package/dist/chunk-LFFYCDHB.mjs +0 -92
  319. package/dist/chunk-LFFYCDHB.mjs.map +0 -1
  320. package/dist/chunk-NNCUD3QF.js +0 -360
  321. package/dist/chunk-NNCUD3QF.js.map +0 -1
  322. package/dist/chunk-NNHSNPT2.mjs +0 -67
  323. package/dist/chunk-NNHSNPT2.mjs.map +0 -1
  324. package/dist/chunk-NOHEXQ7Y.mjs +0 -55
  325. package/dist/chunk-NOHEXQ7Y.mjs.map +0 -1
  326. package/dist/chunk-NYKRCWBG.js +0 -31
  327. package/dist/chunk-NYKRCWBG.js.map +0 -1
  328. package/dist/chunk-O6ZZVIFH.mjs +0 -176
  329. package/dist/chunk-O6ZZVIFH.mjs.map +0 -1
  330. package/dist/chunk-PRUNMTRD.js +0 -50
  331. package/dist/chunk-PRUNMTRD.js.map +0 -1
  332. package/dist/chunk-PSZ34BI5.js +0 -92
  333. package/dist/chunk-PSZ34BI5.js.map +0 -1
  334. package/dist/chunk-QKV7E5BO.js +0 -257
  335. package/dist/chunk-QKV7E5BO.js.map +0 -1
  336. package/dist/chunk-RHDPOIS4.js +0 -239
  337. package/dist/chunk-RHDPOIS4.js.map +0 -1
  338. package/dist/chunk-S6VGOPUY.js +0 -14
  339. package/dist/chunk-S6VGOPUY.js.map +0 -1
  340. package/dist/chunk-SD6CWFDF.js +0 -88
  341. package/dist/chunk-SD6CWFDF.js.map +0 -1
  342. package/dist/chunk-SFFOC25Q.mjs +0 -226
  343. package/dist/chunk-SFFOC25Q.mjs.map +0 -1
  344. package/dist/chunk-SMC5Q6ZH.mjs +0 -120
  345. package/dist/chunk-SMC5Q6ZH.mjs.map +0 -1
  346. package/dist/chunk-TIE3CPF7.js +0 -120
  347. package/dist/chunk-TIE3CPF7.js.map +0 -1
  348. package/dist/chunk-TJMQEH57.js +0 -66
  349. package/dist/chunk-TJMQEH57.js.map +0 -1
  350. package/dist/chunk-UGN7PBON.js +0 -176
  351. package/dist/chunk-UGN7PBON.js.map +0 -1
  352. package/dist/chunk-UHAFIPSL.js +0 -121
  353. package/dist/chunk-UHAFIPSL.js.map +0 -1
  354. package/dist/chunk-UHSRHP55.mjs +0 -106
  355. package/dist/chunk-UHSRHP55.mjs.map +0 -1
  356. package/dist/chunk-ULD4JC3Q.js +0 -399
  357. package/dist/chunk-ULD4JC3Q.js.map +0 -1
  358. package/dist/chunk-UQQWZT6C.mjs +0 -14
  359. package/dist/chunk-UQQWZT6C.mjs.map +0 -1
  360. package/dist/chunk-V72C4MCR.js +0 -137
  361. package/dist/chunk-V72C4MCR.js.map +0 -1
  362. package/dist/chunk-VEVVBHP3.mjs +0 -31
  363. package/dist/chunk-VEVVBHP3.mjs.map +0 -1
  364. package/dist/chunk-VGFPVAKX.mjs +0 -228
  365. package/dist/chunk-VGFPVAKX.mjs.map +0 -1
  366. package/dist/chunk-VKWOHNDO.js +0 -2509
  367. package/dist/chunk-VKWOHNDO.js.map +0 -1
  368. package/dist/chunk-WR5F34OW.js +0 -23
  369. package/dist/chunk-WR5F34OW.js.map +0 -1
  370. package/dist/chunk-X4XSEYPL.mjs +0 -201
  371. package/dist/chunk-X4XSEYPL.mjs.map +0 -1
  372. package/dist/chunk-XTMJ25EF.mjs +0 -2509
  373. package/dist/chunk-XTMJ25EF.mjs.map +0 -1
  374. package/dist/chunk-XUI43LEZ.mjs +0 -30
  375. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  376. package/dist/chunk-XVYXRCRL.js +0 -85
  377. package/dist/chunk-XVYXRCRL.js.map +0 -1
  378. package/dist/chunk-YVCX6Z75.js +0 -102
  379. package/dist/chunk-YVCX6Z75.js.map +0 -1
  380. package/dist/chunk-YWLMT7XH.js +0 -67
  381. package/dist/chunk-YWLMT7XH.js.map +0 -1
  382. package/dist/chunk-Z4BLTVTB.js +0 -30
  383. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  384. package/dist/chunk-Z4GV3YQQ.mjs +0 -23
  385. package/dist/chunk-Z4GV3YQQ.mjs.map +0 -1
  386. package/dist/constants.js +0 -20
  387. package/dist/constants.js.map +0 -1
  388. package/dist/errors.js +0 -15
  389. package/dist/errors.js.map +0 -1
  390. package/dist/gas-flows/DefaultGasFeeFlow.js +0 -15
  391. package/dist/gas-flows/DefaultGasFeeFlow.js.map +0 -1
  392. package/dist/gas-flows/LineaGasFeeFlow.js +0 -16
  393. package/dist/gas-flows/LineaGasFeeFlow.js.map +0 -1
  394. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js +0 -11
  395. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
  396. package/dist/gas-flows/OracleLayer1GasFeeFlow.js +0 -9
  397. package/dist/gas-flows/OracleLayer1GasFeeFlow.js.map +0 -1
  398. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js +0 -11
  399. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js.map +0 -1
  400. package/dist/gas-flows/TestGasFeeFlow.js +0 -9
  401. package/dist/gas-flows/TestGasFeeFlow.js.map +0 -1
  402. package/dist/helpers/EtherscanRemoteTransactionSource.js +0 -12
  403. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +0 -1
  404. package/dist/helpers/GasFeePoller.js +0 -12
  405. package/dist/helpers/GasFeePoller.js.map +0 -1
  406. package/dist/helpers/IncomingTransactionHelper.js +0 -9
  407. package/dist/helpers/IncomingTransactionHelper.js.map +0 -1
  408. package/dist/helpers/MultichainTrackingHelper.js +0 -13
  409. package/dist/helpers/MultichainTrackingHelper.js.map +0 -1
  410. package/dist/helpers/PendingTransactionTracker.js +0 -10
  411. package/dist/helpers/PendingTransactionTracker.js.map +0 -1
  412. package/dist/index.js +0 -77
  413. package/dist/index.js.map +0 -1
  414. package/dist/logger.js +0 -12
  415. package/dist/logger.js.map +0 -1
  416. package/dist/tsconfig.build.tsbuildinfo +0 -1
  417. package/dist/types/TransactionController.d.ts.map +0 -1
  418. package/dist/types/constants.d.ts.map +0 -1
  419. package/dist/types/errors.d.ts.map +0 -1
  420. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  421. package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  422. package/dist/types/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
  423. package/dist/types/gas-flows/OracleLayer1GasFeeFlow.d.ts.map +0 -1
  424. package/dist/types/gas-flows/ScrollLayer1GasFeeFlow.d.ts.map +0 -1
  425. package/dist/types/gas-flows/TestGasFeeFlow.d.ts.map +0 -1
  426. package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
  427. package/dist/types/helpers/GasFeePoller.d.ts.map +0 -1
  428. package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +0 -1
  429. package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  430. package/dist/types/helpers/PendingTransactionTracker.d.ts.map +0 -1
  431. package/dist/types/index.d.ts.map +0 -1
  432. package/dist/types/logger.d.ts.map +0 -1
  433. package/dist/types/types.d.ts.map +0 -1
  434. package/dist/types/utils/etherscan.d.ts.map +0 -1
  435. package/dist/types/utils/external-transactions.d.ts.map +0 -1
  436. package/dist/types/utils/gas-fees.d.ts.map +0 -1
  437. package/dist/types/utils/gas-flow.d.ts.map +0 -1
  438. package/dist/types/utils/gas.d.ts.map +0 -1
  439. package/dist/types/utils/history.d.ts.map +0 -1
  440. package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +0 -1
  441. package/dist/types/utils/nonce.d.ts.map +0 -1
  442. package/dist/types/utils/retry.d.ts.map +0 -1
  443. package/dist/types/utils/simulation-api.d.ts.map +0 -1
  444. package/dist/types/utils/simulation.d.ts.map +0 -1
  445. package/dist/types/utils/swaps.d.ts.map +0 -1
  446. package/dist/types/utils/transaction-type.d.ts.map +0 -1
  447. package/dist/types/utils/utils.d.ts.map +0 -1
  448. package/dist/types/utils/validation.d.ts.map +0 -1
  449. package/dist/types.js +0 -24
  450. package/dist/types.js.map +0 -1
  451. package/dist/utils/etherscan.js +0 -14
  452. package/dist/utils/etherscan.js.map +0 -1
  453. package/dist/utils/external-transactions.js +0 -9
  454. package/dist/utils/external-transactions.js.map +0 -1
  455. package/dist/utils/gas-fees.js +0 -16
  456. package/dist/utils/gas-fees.js.map +0 -1
  457. package/dist/utils/gas-flow.js +0 -11
  458. package/dist/utils/gas-flow.js.map +0 -1
  459. package/dist/utils/gas.js +0 -20
  460. package/dist/utils/gas.js.map +0 -1
  461. package/dist/utils/history.js +0 -14
  462. package/dist/utils/history.js.map +0 -1
  463. package/dist/utils/layer1-gas-fee-flow.js +0 -11
  464. package/dist/utils/layer1-gas-fee-flow.js.map +0 -1
  465. package/dist/utils/nonce.js +0 -11
  466. package/dist/utils/nonce.js.map +0 -1
  467. package/dist/utils/retry.js +0 -8
  468. package/dist/utils/retry.js.map +0 -1
  469. package/dist/utils/simulation-api.js +0 -11
  470. package/dist/utils/simulation-api.js.map +0 -1
  471. package/dist/utils/simulation.js +0 -17
  472. package/dist/utils/simulation.js.map +0 -1
  473. package/dist/utils/swaps.js +0 -24
  474. package/dist/utils/swaps.js.map +0 -1
  475. package/dist/utils/transaction-type.js +0 -11
  476. package/dist/utils/transaction-type.js.map +0 -1
  477. package/dist/utils/utils.js +0 -23
  478. package/dist/utils/utils.js.map +0 -1
  479. package/dist/utils/validation.js +0 -12
  480. package/dist/utils/validation.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAC/C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,mCAAmC;AAChF,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AACvD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAEjE,OAAO,EAAE,uBAAuB,EAA0B,qBAAiB;AAC3E,OAAO,EAAE,oBAAoB,EAAE,oBAAgB;AAI/C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,kBAA4B,EAC5B,eAAuB,EACvB,IAAY,EACZ,MAAc;IAEd,IAAI,MAAM,KAAK,eAAe,EAAE;QAC9B,mEAAmE;QACnE,IAAI,IAAI,KAAK,eAAe,EAAE;YAC5B,MAAM,SAAS,CAAC,QAAQ,CAAC;gBACvB,OAAO,EAAE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B,EAC3B,mBAAwC,EACxC,sBAA2C;IAE3C,IAAI,OAAO,QAAQ,CAAC,sBAAsB,CAAC,KAAK,WAAW,EAAE;QAC3D,MAAM,SAAS,CAAC,aAAa,CAC3B,yCAAyC,mBAAmB,sBAAsB,sBAAsB,yBAAyB,CAClI,CAAC;KACH;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,mBAAmB,CAC1B,QAA2B,EAC3B,KAA0B;IAE1B,IAAI,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE;QACvC,MAAM,SAAS,CAAC,aAAa;QAC3B,gFAAgF;QAChF,4EAA4E;QAC5E,+BAA+B,KAAK,2BAA2B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAClF,CAAC;KACH;AACH,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { ORIGIN_METAMASK, isValidHexAddress } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { TransactionEnvelopeType, type TransactionParams } from '../types';\nimport { isEIP1559Transaction } from './utils';\n\ntype GasFieldsToValidate = 'gasPrice' | 'maxFeePerGas' | 'maxPriorityFeePerGas';\n\n/**\n * Validates whether a transaction initiated by a specific 'from' address is permitted by the origin.\n *\n * @param permittedAddresses - The permitted accounts for the given origin.\n * @param selectedAddress - The currently selected Ethereum address in the wallet.\n * @param from - The address from which the transaction is initiated.\n * @param origin - The origin or source of the transaction.\n * @throws Throws an error if the transaction is not permitted.\n */\nexport async function validateTransactionOrigin(\n permittedAddresses: string[],\n selectedAddress: string,\n from: string,\n origin: string,\n) {\n if (origin === ORIGIN_METAMASK) {\n // Ensure the 'from' address matches the currently selected address\n if (from !== selectedAddress) {\n throw rpcErrors.internal({\n message: `Internally initiated transaction is using invalid account.`,\n data: {\n origin,\n fromAddress: from,\n selectedAddress,\n },\n });\n }\n return;\n }\n\n // Check if the origin has permissions to initiate transactions from the specified address\n if (!permittedAddresses.includes(from)) {\n throw providerErrors.unauthorized({ data: { origin } });\n }\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.\n */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\n) {\n validateEnvelopeType(txParams.type);\n validateEIP1559Compatibility(txParams, isEIP1559Compatible);\n validateParamFrom(txParams.from);\n validateParamRecipient(txParams);\n validateParamValue(txParams.value);\n validateParamData(txParams.data);\n validateParamChainId(txParams.chainId);\n validateGasFeeParams(txParams);\n}\n\n/**\n * Validates the `type` property, ensuring that if it is specified, it is a valid transaction envelope type.\n *\n * @param type - The transaction envelope type to validate.\n * @throws Throws invalid params if the type is not a valid transaction envelope type.\n */\nfunction validateEnvelopeType(type: string | undefined) {\n if (\n type &&\n !Object.values(TransactionEnvelopeType).includes(\n type as TransactionEnvelopeType,\n )\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: \"${type}\". Must be one of: ${Object.values(\n TransactionEnvelopeType,\n ).join(', ')}`,\n );\n }\n}\n\n/**\n * Validates EIP-1559 compatibility for transaction creation.\n *\n * @param txParams - The transaction parameters to validate.\n * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.\n * @throws Throws invalid params if the transaction specifies EIP-1559 but the network does not support it.\n */\nfunction validateEIP1559Compatibility(\n txParams: TransactionParams,\n isEIP1559Compatible: boolean,\n) {\n if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',\n );\n }\n}\n\n/**\n * Validates value property, ensuring it is a valid positive integer number\n * denominated in wei.\n *\n * @param value - The value to validate, expressed as a string.\n * @throws Throws an error if the value is not a valid positive integer\n * number denominated in wei.\n * - If the value contains a hyphen (-), it is considered invalid.\n * - If the value contains a decimal point (.), it is considered invalid.\n * - If the value is not a finite number, is NaN, or is not a safe integer, it is considered invalid.\n */\nfunction validateParamValue(value?: string) {\n if (value !== undefined) {\n if (value.includes('-')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": not a positive number.`,\n );\n }\n\n if (value.includes('.')) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value \"${value}\": number must be in wei.`,\n );\n }\n const intValue = parseInt(value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw rpcErrors.invalidParams(\n `Invalid transaction value ${value}: number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param txParams - The transaction parameters object to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamRecipient(txParams: TransactionParams) {\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw rpcErrors.invalidParams(`Invalid \"to\" address.`);\n }\n}\n\n/**\n * Validates the recipient address in a transaction's parameters.\n *\n * @param from - The from property to validate.\n * @throws Throws an error if the recipient address is invalid:\n * - If the recipient address is an empty string ('0x') or undefined and the transaction contains data,\n * the \"to\" field is removed from the transaction parameters.\n * - If the recipient address is not a valid hexadecimal Ethereum address, an error is thrown.\n */\nfunction validateParamFrom(from: string) {\n if (!from || typeof from !== 'string') {\n throw rpcErrors.invalidParams(\n `Invalid \"from\" address ${from}: not a string.`,\n );\n }\n if (!isValidHexAddress(from)) {\n throw rpcErrors.invalidParams('Invalid \"from\" address.');\n }\n}\n\n/**\n * Validates input data for transactions.\n *\n * @param value - The input data to validate.\n * @throws Throws invalid params if the input data is invalid.\n */\nfunction validateParamData(value?: string) {\n if (value) {\n const ERC20Interface = new Interface(abiERC20);\n try {\n ERC20Interface.parseTransaction({ data: value });\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n if (error.message.match(/BUFFER_OVERRUN/u)) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: data out-of-bounds, BUFFER_OVERRUN.',\n );\n }\n }\n }\n}\n\n/**\n * Validates chainId type.\n *\n * @param chainId - The chainId to validate.\n */\nfunction validateParamChainId(chainId: number | string | undefined) {\n if (\n chainId !== undefined &&\n typeof chainId !== 'number' &&\n typeof chainId !== 'string'\n ) {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: chainId is not a Number or hex string. got: (${chainId})`,\n );\n }\n}\n\n/**\n * Validates gas values.\n *\n * @param txParams - The transaction parameters to validate.\n */\nfunction validateGasFeeParams(txParams: TransactionParams) {\n if (txParams.gasPrice) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'gasPrice');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'gasPrice',\n 'maxPriorityFeePerGas',\n );\n ensureFieldIsString(txParams, 'gasPrice');\n }\n\n if (txParams.maxFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(txParams, 'maxFeePerGas');\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsString(txParams, 'maxFeePerGas');\n }\n\n if (txParams.maxPriorityFeePerGas) {\n ensureProperTransactionEnvelopeTypeProvided(\n txParams,\n 'maxPriorityFeePerGas',\n );\n ensureMutuallyExclusiveFieldsNotProvided(\n txParams,\n 'maxPriorityFeePerGas',\n 'gasPrice',\n );\n ensureFieldIsString(txParams, 'maxPriorityFeePerGas');\n }\n}\n\n/**\n * Ensures that the provided txParams has the proper 'type' specified for the\n * given field, if it is provided. If types do not match throws an\n * invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {ethErrors.rpc.invalidParams} Throws if type does not match the\n * expectations for provided field.\n */\nfunction ensureProperTransactionEnvelopeTypeProvided(\n txParams: TransactionParams,\n field: GasFieldsToValidate,\n) {\n switch (field) {\n case 'maxFeePerGas':\n case 'maxPriorityFeePerGas':\n if (\n txParams.type &&\n txParams.type !== TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.type}\" but including maxFeePerGas and maxPriorityFeePerGas requires type: \"${TransactionEnvelopeType.feeMarket}\"`,\n );\n }\n break;\n case 'gasPrice':\n default:\n if (\n txParams.type &&\n txParams.type === TransactionEnvelopeType.feeMarket\n ) {\n throw rpcErrors.invalidParams(\n `Invalid transaction envelope type: specified type \"${txParams.type}\" but included a gasPrice instead of maxFeePerGas and maxPriorityFeePerGas`,\n );\n }\n }\n}\n\n/**\n * Given two fields, ensure that the second field is not included in txParams,\n * and if it is throw an invalidParams error.\n *\n * @param txParams - The transaction parameters object\n * @param fieldBeingValidated - The current field being validated\n * @param mutuallyExclusiveField - The field to ensure is not provided\n * @throws {ethErrors.rpc.invalidParams} Throws if mutuallyExclusiveField is\n * present in txParams.\n */\nfunction ensureMutuallyExclusiveFieldsNotProvided(\n txParams: TransactionParams,\n fieldBeingValidated: GasFieldsToValidate,\n mutuallyExclusiveField: GasFieldsToValidate,\n) {\n if (typeof txParams[mutuallyExclusiveField] !== 'undefined') {\n throw rpcErrors.invalidParams(\n `Invalid transaction params: specified ${fieldBeingValidated} but also included ${mutuallyExclusiveField}, these cannot be mixed`,\n );\n }\n}\n\n/**\n * Ensures that the provided value for field is a string, throws an\n * invalidParams error if field is not a string.\n *\n * @param txParams - The transaction parameters object\n * @param field - The current field being validated\n * @throws {rpcErrors.invalidParams} Throws if field is not a string\n */\nfunction ensureFieldIsString(\n txParams: TransactionParams,\n field: GasFieldsToValidate,\n) {\n if (typeof txParams[field] !== 'string') {\n throw rpcErrors.invalidParams(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Invalid transaction params: ${field} is not a string. got: (${txParams[field]})`,\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/transaction-controller",
3
- "version": "36.1.0",
3
+ "version": "37.1.0",
4
4
  "description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -18,19 +18,24 @@
18
18
  "sideEffects": false,
19
19
  "exports": {
20
20
  ".": {
21
- "import": "./dist/index.mjs",
22
- "require": "./dist/index.js",
23
- "types": "./dist/types/index.d.ts"
21
+ "import": {
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
24
29
  },
25
30
  "./package.json": "./package.json"
26
31
  },
27
- "main": "./dist/index.js",
28
- "types": "./dist/types/index.d.ts",
32
+ "main": "./dist/index.cjs",
33
+ "types": "./dist/index.d.cts",
29
34
  "files": [
30
35
  "dist/"
31
36
  ],
32
37
  "scripts": {
33
- "build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
38
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
34
39
  "build:docs": "typedoc",
35
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/transaction-controller",
36
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/transaction-controller",
@@ -48,8 +53,8 @@
48
53
  "@ethersproject/abi": "^5.7.0",
49
54
  "@ethersproject/contracts": "^5.7.0",
50
55
  "@ethersproject/providers": "^5.7.0",
51
- "@metamask/base-controller": "^7.0.0",
52
- "@metamask/controller-utils": "^11.2.0",
56
+ "@metamask/base-controller": "^7.0.1",
57
+ "@metamask/controller-utils": "^11.3.0",
53
58
  "@metamask/eth-query": "^4.0.0",
54
59
  "@metamask/metamask-eth-abis": "^3.1.1",
55
60
  "@metamask/nonce-tracker": "^6.0.0",
@@ -64,14 +69,14 @@
64
69
  },
65
70
  "devDependencies": {
66
71
  "@babel/runtime": "^7.23.9",
67
- "@metamask/accounts-controller": "^18.2.0",
68
- "@metamask/approval-controller": "^7.0.3",
72
+ "@metamask/accounts-controller": "^18.2.2",
73
+ "@metamask/approval-controller": "^7.1.0",
69
74
  "@metamask/auto-changelog": "^3.4.4",
70
- "@metamask/eth-json-rpc-provider": "^4.1.3",
75
+ "@metamask/eth-json-rpc-provider": "^4.1.4",
71
76
  "@metamask/ethjs-provider-http": "^0.3.0",
72
- "@metamask/gas-fee-controller": "^20.0.0",
73
- "@metamask/keyring-api": "^8.1.0",
74
- "@metamask/network-controller": "^21.0.0",
77
+ "@metamask/gas-fee-controller": "^20.0.1",
78
+ "@metamask/keyring-api": "^8.1.3",
79
+ "@metamask/network-controller": "^21.0.1",
75
80
  "@types/bn.js": "^5.1.5",
76
81
  "@types/jest": "^27.4.1",
77
82
  "@types/node": "^16.18.54",
@@ -1,46 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
-
6
-
7
- var _chunkVKWOHNDOjs = require('./chunk-VKWOHNDO.js');
8
- require('./chunk-PRUNMTRD.js');
9
- require('./chunk-5QVDIVJH.js');
10
- require('./chunk-NNCUD3QF.js');
11
- require('./chunk-KT6UAKBB.js');
12
- require('./chunk-SD6CWFDF.js');
13
- require('./chunk-4OYPDGHO.js');
14
- require('./chunk-ULD4JC3Q.js');
15
- require('./chunk-7LXE4KHV.js');
16
- require('./chunk-V72C4MCR.js');
17
- require('./chunk-TIE3CPF7.js');
18
- require('./chunk-NYKRCWBG.js');
19
- require('./chunk-WR5F34OW.js');
20
- require('./chunk-YVCX6Z75.js');
21
- require('./chunk-TJMQEH57.js');
22
- require('./chunk-5HYWLTVQ.js');
23
- require('./chunk-2XKEAKQG.js');
24
- require('./chunk-RHDPOIS4.js');
25
- require('./chunk-6OLJWLKK.js');
26
- require('./chunk-7NMV2NPM.js');
27
- require('./chunk-XVYXRCRL.js');
28
- require('./chunk-HMOSP33F.js');
29
- require('./chunk-UHAFIPSL.js');
30
- require('./chunk-EHWAY6XU.js');
31
- require('./chunk-BZV72SCF.js');
32
- require('./chunk-QKV7E5BO.js');
33
- require('./chunk-KTGMNUTQ.js');
34
- require('./chunk-YWLMT7XH.js');
35
- require('./chunk-UGN7PBON.js');
36
- require('./chunk-S6VGOPUY.js');
37
- require('./chunk-PSZ34BI5.js');
38
- require('./chunk-Z4BLTVTB.js');
39
-
40
-
41
-
42
-
43
-
44
-
45
- exports.ApprovalState = _chunkVKWOHNDOjs.ApprovalState; exports.CANCEL_RATE = _chunkVKWOHNDOjs.CANCEL_RATE; exports.HARDFORK = _chunkVKWOHNDOjs.HARDFORK; exports.SPEED_UP_RATE = _chunkVKWOHNDOjs.SPEED_UP_RATE; exports.TransactionController = _chunkVKWOHNDOjs.TransactionController;
46
- //# sourceMappingURL=TransactionController.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,55 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
4
-
5
- // src/utils/layer1-gas-fee-flow.ts
6
- var _utils = require('@metamask/utils');
7
- var log = _utils.createModuleLogger.call(void 0, _chunkS6VGOPUYjs.projectLogger, "layer-1-gas-fee-flow");
8
- async function updateTransactionLayer1GasFee(request) {
9
- const layer1GasFee = await getTransactionLayer1GasFee(request);
10
- if (!layer1GasFee) {
11
- return;
12
- }
13
- const { transactionMeta } = request;
14
- transactionMeta.layer1GasFee = layer1GasFee;
15
- log("Updated layer 1 gas fee", layer1GasFee, transactionMeta.id);
16
- }
17
- function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows) {
18
- return layer1GasFeeFlows.find(
19
- (layer1GasFeeFlow) => layer1GasFeeFlow.matchesTransaction(transactionMeta)
20
- );
21
- }
22
- async function getTransactionLayer1GasFee({
23
- layer1GasFeeFlows,
24
- provider,
25
- transactionMeta
26
- }) {
27
- const layer1GasFeeFlow = getLayer1GasFeeFlow(
28
- transactionMeta,
29
- layer1GasFeeFlows
30
- );
31
- if (!layer1GasFeeFlow) {
32
- return void 0;
33
- }
34
- log(
35
- "Found layer 1 gas fee flow",
36
- layer1GasFeeFlow.constructor.name,
37
- transactionMeta.id
38
- );
39
- try {
40
- const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({
41
- provider,
42
- transactionMeta
43
- });
44
- return layer1Fee;
45
- } catch (error) {
46
- log("Failed to get layer 1 gas fee", transactionMeta.id, error);
47
- return void 0;
48
- }
49
- }
50
-
51
-
52
-
53
-
54
- exports.updateTransactionLayer1GasFee = updateTransactionLayer1GasFee; exports.getTransactionLayer1GasFee = getTransactionLayer1GasFee;
55
- //# sourceMappingURL=chunk-2XKEAKQG.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":";;;;;AACA,SAAS,0BAAoC;AAK7C,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAepE,eAAsB,8BACpB,SACA;AACA,QAAM,eAAe,MAAM,2BAA2B,OAAO;AAE7D,MAAI,CAAC,cAAc;AACjB;AAAA,EACF;AAEA,QAAM,EAAE,gBAAgB,IAAI;AAE5B,kBAAgB,eAAe;AAE/B,MAAI,2BAA2B,cAAc,gBAAgB,EAAE;AACjE;AAQA,SAAS,oBACP,iBACA,mBAC8B;AAC9B,SAAO,kBAAkB;AAAA,IAAK,CAAC,qBAC7B,iBAAiB,mBAAmB,eAAe;AAAA,EACrD;AACF;AASA,eAAsB,2BAA2B;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,kBAAkB;AACrB,WAAO;AAAA,EACT;AAEA;AAAA,IACE;AAAA,IACA,iBAAiB,YAAY;AAAA,IAC7B,gBAAgB;AAAA,EAClB;AAEA,MAAI;AACF,UAAM,EAAE,UAAU,IAAI,MAAM,iBAAiB,aAAa;AAAA,MACxD;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iCAAiC,gBAAgB,IAAI,KAAK;AAC9D,WAAO;AAAA,EACT;AACF","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (!layer1GasFee) {\n return;\n }\n\n const { transactionMeta } = request;\n\n transactionMeta.layer1GasFee = layer1GasFee;\n\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction and return the layer1Fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n\n if (!layer1GasFeeFlow) {\n return undefined;\n }\n\n log(\n 'Found layer 1 gas fee flow',\n layer1GasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
@@ -1,360 +0,0 @@
1
- import {
2
- simulateTransactions
3
- } from "./chunk-K4KOSAGM.mjs";
4
- import {
5
- SimulationError,
6
- SimulationInvalidResponseError,
7
- SimulationRevertedError
8
- } from "./chunk-HQSNKCXI.mjs";
9
- import {
10
- ABI_SIMULATION_ERC20_WRAPPED,
11
- ABI_SIMULATION_ERC721_LEGACY
12
- } from "./chunk-O6ZZVIFH.mjs";
13
- import {
14
- projectLogger
15
- } from "./chunk-UQQWZT6C.mjs";
16
-
17
- // src/utils/simulation.ts
18
- import { Interface } from "@ethersproject/abi";
19
- import { hexToBN, toHex } from "@metamask/controller-utils";
20
- import { abiERC20, abiERC721, abiERC1155 } from "@metamask/metamask-eth-abis";
21
- import { createModuleLogger } from "@metamask/utils";
22
- var SupportedToken = /* @__PURE__ */ ((SupportedToken2) => {
23
- SupportedToken2["ERC20"] = "erc20";
24
- SupportedToken2["ERC721"] = "erc721";
25
- SupportedToken2["ERC1155"] = "erc1155";
26
- SupportedToken2["ERC20_WRAPPED"] = "erc20Wrapped";
27
- SupportedToken2["ERC721_LEGACY"] = "erc721Legacy";
28
- return SupportedToken2;
29
- })(SupportedToken || {});
30
- var log = createModuleLogger(projectLogger, "simulation");
31
- var SUPPORTED_EVENTS = [
32
- "Transfer",
33
- "TransferSingle",
34
- "TransferBatch",
35
- "Deposit",
36
- "Withdrawal"
37
- ];
38
- var SUPPORTED_TOKEN_ABIS = {
39
- ["erc20" /* ERC20 */]: {
40
- abi: abiERC20,
41
- standard: "erc20" /* erc20 */
42
- },
43
- ["erc721" /* ERC721 */]: {
44
- abi: abiERC721,
45
- standard: "erc721" /* erc721 */
46
- },
47
- ["erc1155" /* ERC1155 */]: {
48
- abi: abiERC1155,
49
- standard: "erc1155" /* erc1155 */
50
- },
51
- ["erc20Wrapped" /* ERC20_WRAPPED */]: {
52
- abi: ABI_SIMULATION_ERC20_WRAPPED,
53
- standard: "erc20" /* erc20 */
54
- },
55
- ["erc721Legacy" /* ERC721_LEGACY */]: {
56
- abi: ABI_SIMULATION_ERC721_LEGACY,
57
- standard: "erc721" /* erc721 */
58
- }
59
- };
60
- var REVERTED_ERRORS = ["execution reverted", "insufficient funds for gas"];
61
- async function getSimulationData(request) {
62
- const { chainId, from, to, value, data } = request;
63
- log("Getting simulation data", request);
64
- try {
65
- const response = await simulateTransactions(chainId, {
66
- transactions: [
67
- {
68
- data,
69
- from,
70
- maxFeePerGas: "0x0",
71
- maxPriorityFeePerGas: "0x0",
72
- to,
73
- value
74
- }
75
- ],
76
- withCallTrace: true,
77
- withLogs: true
78
- });
79
- const transactionError = response.transactions?.[0]?.error;
80
- if (transactionError) {
81
- throw new SimulationError(transactionError);
82
- }
83
- const nativeBalanceChange = getNativeBalanceChange(request.from, response);
84
- const events = getEvents(response);
85
- log("Parsed events", events);
86
- const tokenBalanceChanges = await getTokenBalanceChanges(request, events);
87
- return {
88
- nativeBalanceChange,
89
- tokenBalanceChanges
90
- };
91
- } catch (error) {
92
- log("Failed to get simulation data", error, request);
93
- let simulationError = error;
94
- if (REVERTED_ERRORS.some(
95
- (revertErrorMessage) => simulationError.message?.includes(revertErrorMessage)
96
- )) {
97
- simulationError = new SimulationRevertedError();
98
- }
99
- const { code, message } = simulationError;
100
- return {
101
- tokenBalanceChanges: [],
102
- error: {
103
- code,
104
- message
105
- }
106
- };
107
- }
108
- }
109
- function getNativeBalanceChange(userAddress, response) {
110
- const transactionResponse = response.transactions[0];
111
- if (!transactionResponse) {
112
- return void 0;
113
- }
114
- const { stateDiff } = transactionResponse;
115
- const previousBalance = stateDiff?.pre?.[userAddress]?.balance;
116
- const newBalance = stateDiff?.post?.[userAddress]?.balance;
117
- if (!previousBalance || !newBalance) {
118
- return void 0;
119
- }
120
- return getSimulationBalanceChange(previousBalance, newBalance);
121
- }
122
- function getEvents(response) {
123
- const logs = extractLogs(
124
- response.transactions[0]?.callTrace ?? {}
125
- );
126
- log("Extracted logs", logs);
127
- const interfaces = getContractInterfaces();
128
- return logs.map((currentLog) => {
129
- const event = parseLog(currentLog, interfaces);
130
- if (!event) {
131
- log("Failed to parse log", currentLog);
132
- return void 0;
133
- }
134
- const inputs = event.abi.find((e) => e.name === event.name)?.inputs;
135
- if (!inputs) {
136
- log("Failed to find inputs for event", event);
137
- return void 0;
138
- }
139
- if (!SUPPORTED_EVENTS.includes(event.name)) {
140
- log("Ignoring unsupported event", event.name, event);
141
- return void 0;
142
- }
143
- log("Normalizing event args", event.name, event);
144
- const args = normalizeEventArgs(event.args, inputs);
145
- return {
146
- contractAddress: currentLog.address,
147
- tokenStandard: event.standard,
148
- name: event.name,
149
- args,
150
- abi: event.abi
151
- };
152
- }).filter((e) => e !== void 0);
153
- }
154
- function normalizeEventArgs(args, abiInputs) {
155
- return args.reduce((result, arg, index) => {
156
- const name = abiInputs[index].name.replace("_", "");
157
- const value = normalizeEventArgValue(arg);
158
- result[name] = value;
159
- return result;
160
- }, {});
161
- }
162
- function normalizeEventArgValue(value) {
163
- if (Array.isArray(value)) {
164
- return value.map(normalizeEventArgValue);
165
- }
166
- let normalizedValue = value;
167
- normalizedValue = normalizedValue.toHexString?.() ?? normalizedValue;
168
- normalizedValue = normalizedValue.toLowerCase?.() ?? normalizedValue;
169
- return normalizedValue;
170
- }
171
- async function getTokenBalanceChanges(request, events) {
172
- const balanceTxs = getTokenBalanceTransactions(request, events);
173
- log("Generated balance transactions", [...balanceTxs.after.values()]);
174
- const transactions = [
175
- ...balanceTxs.before.values(),
176
- request,
177
- ...balanceTxs.after.values()
178
- ];
179
- if (transactions.length === 1) {
180
- return [];
181
- }
182
- const response = await simulateTransactions(request.chainId, {
183
- transactions
184
- });
185
- log("Balance simulation response", response);
186
- if (response.transactions.length !== transactions.length) {
187
- throw new SimulationInvalidResponseError();
188
- }
189
- let prevBalanceTxIndex = 0;
190
- return [...balanceTxs.after.keys()].map((token, index) => {
191
- const previousBalanceCheckSkipped = !balanceTxs.before.get(token);
192
- const previousBalance = previousBalanceCheckSkipped ? "0x0" : getValueFromBalanceTransaction(
193
- request.from,
194
- token,
195
- // eslint-disable-next-line no-plusplus
196
- response.transactions[prevBalanceTxIndex++]
197
- );
198
- const newBalance = getValueFromBalanceTransaction(
199
- request.from,
200
- token,
201
- response.transactions[index + balanceTxs.before.size + 1]
202
- );
203
- const balanceChange = getSimulationBalanceChange(
204
- previousBalance,
205
- newBalance
206
- );
207
- if (!balanceChange) {
208
- return void 0;
209
- }
210
- return {
211
- ...token,
212
- ...balanceChange
213
- };
214
- }).filter((change) => change !== void 0);
215
- }
216
- function getTokenBalanceTransactions(request, events) {
217
- const tokenKeys = /* @__PURE__ */ new Set();
218
- const before = /* @__PURE__ */ new Map();
219
- const after = /* @__PURE__ */ new Map();
220
- const userEvents = events.filter(
221
- (event) => [event.args.from, event.args.to].includes(request.from)
222
- );
223
- log("Filtered user events", userEvents);
224
- for (const event of userEvents) {
225
- const tokenIds = getEventTokenIds(event);
226
- log("Extracted token IDs", tokenIds);
227
- for (const tokenId of tokenIds) {
228
- const simulationToken = {
229
- address: event.contractAddress,
230
- standard: event.tokenStandard,
231
- id: tokenId
232
- };
233
- const tokenKey = JSON.stringify(simulationToken);
234
- if (tokenKeys.has(tokenKey)) {
235
- log(
236
- "Ignoring additional event with same contract and token ID",
237
- simulationToken
238
- );
239
- continue;
240
- }
241
- tokenKeys.add(tokenKey);
242
- const data = getBalanceTransactionData(
243
- event.tokenStandard,
244
- request.from,
245
- tokenId
246
- );
247
- const transaction = {
248
- from: request.from,
249
- to: event.contractAddress,
250
- data
251
- };
252
- if (skipPriorBalanceCheck(event)) {
253
- after.set(simulationToken, transaction);
254
- } else {
255
- before.set(simulationToken, transaction);
256
- after.set(simulationToken, transaction);
257
- }
258
- }
259
- }
260
- return { before, after };
261
- }
262
- function skipPriorBalanceCheck(event) {
263
- return event.name === "Transfer" && event.tokenStandard === "erc721" /* erc721 */ && parseInt(event.args.from, 16) === 0;
264
- }
265
- function getEventTokenIds(event) {
266
- if (event.tokenStandard === "erc721" /* erc721 */) {
267
- return [event.args.tokenId];
268
- }
269
- if (event.tokenStandard === "erc1155" /* erc1155 */ && event.name === "TransferSingle") {
270
- return [event.args.id];
271
- }
272
- if (event.tokenStandard === "erc1155" /* erc1155 */ && event.name === "TransferBatch") {
273
- return event.args.ids;
274
- }
275
- return [void 0];
276
- }
277
- function getValueFromBalanceTransaction(from, token, response) {
278
- const normalizedReturn = normalizeReturnValue(response.return);
279
- if (token.standard === "erc721" /* erc721 */) {
280
- return normalizedReturn === from ? "0x1" : "0x0";
281
- }
282
- return normalizedReturn;
283
- }
284
- function getBalanceTransactionData(tokenStandard, from, tokenId) {
285
- switch (tokenStandard) {
286
- case "erc721" /* erc721 */:
287
- return new Interface(abiERC721).encodeFunctionData("ownerOf", [
288
- tokenId
289
- ]);
290
- case "erc1155" /* erc1155 */:
291
- return new Interface(abiERC1155).encodeFunctionData("balanceOf", [
292
- from,
293
- tokenId
294
- ]);
295
- default:
296
- return new Interface(abiERC20).encodeFunctionData("balanceOf", [
297
- from
298
- ]);
299
- }
300
- }
301
- function parseLog(eventLog, interfaces) {
302
- const supportedTokens = Object.values(SupportedToken);
303
- for (const token of supportedTokens) {
304
- try {
305
- const contractInterface = interfaces.get(token);
306
- const { abi, standard } = SUPPORTED_TOKEN_ABIS[token];
307
- return {
308
- ...contractInterface.parseLog(eventLog),
309
- abi,
310
- standard
311
- };
312
- } catch (e) {
313
- continue;
314
- }
315
- }
316
- return void 0;
317
- }
318
- function extractLogs(call) {
319
- const logs = call.logs ?? [];
320
- const nestedCalls = call.calls ?? [];
321
- return [
322
- ...logs,
323
- ...nestedCalls.map((nestedCall) => extractLogs(nestedCall)).flat()
324
- ];
325
- }
326
- function getSimulationBalanceChange(previousBalance, newBalance) {
327
- const differenceBN = hexToBN(newBalance).sub(hexToBN(previousBalance));
328
- const isDecrease = differenceBN.isNeg();
329
- const difference = toHex(differenceBN.abs());
330
- if (differenceBN.isZero()) {
331
- log("Balance change is zero");
332
- return void 0;
333
- }
334
- return {
335
- previousBalance,
336
- newBalance,
337
- difference,
338
- isDecrease
339
- };
340
- }
341
- function normalizeReturnValue(value) {
342
- return toHex(hexToBN(value));
343
- }
344
- function getContractInterfaces() {
345
- const supportedTokens = Object.values(SupportedToken);
346
- return new Map(
347
- supportedTokens.map((tokenType) => {
348
- const { abi } = SUPPORTED_TOKEN_ABIS[tokenType];
349
- const contractInterface = new Interface(abi);
350
- return [tokenType, contractInterface];
351
- })
352
- );
353
- }
354
-
355
- export {
356
- SupportedToken,
357
- getSimulationData,
358
- getEvents
359
- };
360
- //# sourceMappingURL=chunk-3AVRGHUO.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/simulation.ts"],"sourcesContent":["import type { Fragment, LogDescription, Result } from '@ethersproject/abi';\nimport { Interface } from '@ethersproject/abi';\nimport { hexToBN, toHex } from '@metamask/controller-utils';\nimport { abiERC20, abiERC721, abiERC1155 } from '@metamask/metamask-eth-abis';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport {\n ABI_SIMULATION_ERC20_WRAPPED,\n ABI_SIMULATION_ERC721_LEGACY,\n} from '../constants';\nimport {\n SimulationError,\n SimulationInvalidResponseError,\n SimulationRevertedError,\n} from '../errors';\nimport { projectLogger } from '../logger';\nimport type {\n SimulationBalanceChange,\n SimulationData,\n SimulationTokenBalanceChange,\n SimulationToken,\n} from '../types';\nimport { SimulationTokenStandard } from '../types';\nimport { simulateTransactions } from './simulation-api';\nimport type {\n SimulationResponseLog,\n SimulationRequestTransaction,\n SimulationResponse,\n SimulationResponseCallTrace,\n SimulationResponseTransaction,\n} from './simulation-api';\n\nexport enum SupportedToken {\n ERC20 = 'erc20',\n ERC721 = 'erc721',\n ERC1155 = 'erc1155',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ERC20_WRAPPED = 'erc20Wrapped',\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ERC721_LEGACY = 'erc721Legacy',\n}\n\ntype ABI = Fragment[];\n\nexport type GetSimulationDataRequest = {\n chainId: Hex;\n from: Hex;\n to?: Hex;\n value?: Hex;\n data?: Hex;\n};\n\ntype ParsedEvent = {\n contractAddress: Hex;\n tokenStandard: SimulationTokenStandard;\n name: string;\n args: Record<string, Hex | Hex[]>;\n abi: ABI;\n};\n\nconst log = createModuleLogger(projectLogger, 'simulation');\n\nconst SUPPORTED_EVENTS = [\n 'Transfer',\n 'TransferSingle',\n 'TransferBatch',\n 'Deposit',\n 'Withdrawal',\n];\n\nconst SUPPORTED_TOKEN_ABIS = {\n [SupportedToken.ERC20]: {\n abi: abiERC20,\n standard: SimulationTokenStandard.erc20,\n },\n [SupportedToken.ERC721]: {\n abi: abiERC721,\n standard: SimulationTokenStandard.erc721,\n },\n [SupportedToken.ERC1155]: {\n abi: abiERC1155,\n standard: SimulationTokenStandard.erc1155,\n },\n [SupportedToken.ERC20_WRAPPED]: {\n abi: ABI_SIMULATION_ERC20_WRAPPED,\n standard: SimulationTokenStandard.erc20,\n },\n [SupportedToken.ERC721_LEGACY]: {\n abi: ABI_SIMULATION_ERC721_LEGACY,\n standard: SimulationTokenStandard.erc721,\n },\n};\n\nconst REVERTED_ERRORS = ['execution reverted', 'insufficient funds for gas'];\n\ntype BalanceTransactionMap = Map<SimulationToken, SimulationRequestTransaction>;\n\n/**\n * Generate simulation data for a transaction.\n * @param request - The transaction to simulate.\n * @param request.chainId - The chain ID of the transaction.\n * @param request.from - The sender of the transaction.\n * @param request.to - The recipient of the transaction.\n * @param request.value - The value of the transaction.\n * @param request.data - The data of the transaction.\n * @returns The simulation data.\n */\nexport async function getSimulationData(\n request: GetSimulationDataRequest,\n): Promise<SimulationData> {\n const { chainId, from, to, value, data } = request;\n\n log('Getting simulation data', request);\n\n try {\n const response = await simulateTransactions(chainId, {\n transactions: [\n {\n data,\n from,\n maxFeePerGas: '0x0',\n maxPriorityFeePerGas: '0x0',\n to,\n value,\n },\n ],\n withCallTrace: true,\n withLogs: true,\n });\n\n const transactionError = response.transactions?.[0]?.error;\n\n if (transactionError) {\n throw new SimulationError(transactionError);\n }\n\n const nativeBalanceChange = getNativeBalanceChange(request.from, response);\n const events = getEvents(response);\n\n log('Parsed events', events);\n\n const tokenBalanceChanges = await getTokenBalanceChanges(request, events);\n\n return {\n nativeBalanceChange,\n tokenBalanceChanges,\n };\n } catch (error) {\n log('Failed to get simulation data', error, request);\n\n let simulationError = error as SimulationError;\n\n if (\n REVERTED_ERRORS.some((revertErrorMessage) =>\n simulationError.message?.includes(revertErrorMessage),\n )\n ) {\n simulationError = new SimulationRevertedError();\n }\n\n const { code, message } = simulationError;\n\n return {\n tokenBalanceChanges: [],\n error: {\n code,\n message,\n },\n };\n }\n}\n\n/**\n * Extract the native balance change from a simulation response.\n * @param userAddress - The user's account address.\n * @param response - The simulation response.\n * @returns The native balance change or undefined if unchanged.\n */\nfunction getNativeBalanceChange(\n userAddress: Hex,\n response: SimulationResponse,\n): SimulationBalanceChange | undefined {\n const transactionResponse = response.transactions[0];\n\n /* istanbul ignore next */\n if (!transactionResponse) {\n return undefined;\n }\n\n const { stateDiff } = transactionResponse;\n const previousBalance = stateDiff?.pre?.[userAddress]?.balance;\n const newBalance = stateDiff?.post?.[userAddress]?.balance;\n\n if (!previousBalance || !newBalance) {\n return undefined;\n }\n\n return getSimulationBalanceChange(previousBalance, newBalance);\n}\n\n/**\n * Extract events from a simulation response.\n * @param response - The simulation response.\n * @returns The parsed events.\n */\nexport function getEvents(response: SimulationResponse): ParsedEvent[] {\n /* istanbul ignore next */\n const logs = extractLogs(\n response.transactions[0]?.callTrace ?? ({} as SimulationResponseCallTrace),\n );\n\n log('Extracted logs', logs);\n\n const interfaces = getContractInterfaces();\n\n return logs\n .map((currentLog) => {\n const event = parseLog(currentLog, interfaces);\n\n if (!event) {\n log('Failed to parse log', currentLog);\n return undefined;\n }\n\n /* istanbul ignore next */\n const inputs = event.abi.find((e) => e.name === event.name)?.inputs;\n\n /* istanbul ignore if */\n if (!inputs) {\n log('Failed to find inputs for event', event);\n return undefined;\n }\n\n if (!SUPPORTED_EVENTS.includes(event.name)) {\n log('Ignoring unsupported event', event.name, event);\n return undefined;\n }\n\n log('Normalizing event args', event.name, event);\n\n const args = normalizeEventArgs(event.args, inputs);\n\n return {\n contractAddress: currentLog.address,\n tokenStandard: event.standard,\n name: event.name,\n args,\n abi: event.abi,\n };\n })\n .filter((e) => e !== undefined) as ParsedEvent[];\n}\n\n/**\n * Normalize event arguments using ABI input definitions.\n * @param args - The raw event arguments.\n * @param abiInputs - The ABI input definitions.\n * @returns The normalized event arguments.\n */\nfunction normalizeEventArgs(\n args: Result,\n abiInputs: { name: string }[],\n): Record<string, Hex | Hex[]> {\n return args.reduce((result, arg, index) => {\n const name = abiInputs[index].name.replace('_', '');\n const value = normalizeEventArgValue(arg);\n\n result[name] = value;\n\n return result;\n }, {});\n}\n\n/**\n * Normalize an event argument value.\n * @param value - The event argument value.\n * @returns The normalized event argument value.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction normalizeEventArgValue(value: any): any {\n if (Array.isArray(value)) {\n return value.map(normalizeEventArgValue);\n }\n\n let normalizedValue = value;\n\n normalizedValue = normalizedValue.toHexString?.() ?? normalizedValue;\n normalizedValue = normalizedValue.toLowerCase?.() ?? normalizedValue;\n\n return normalizedValue;\n}\n\n/**\n * Generate token balance changes from parsed events.\n * @param request - The transaction that was simulated.\n * @param events - The parsed events.\n * @returns An array of token balance changes.\n */\nasync function getTokenBalanceChanges(\n request: GetSimulationDataRequest,\n events: ParsedEvent[],\n): Promise<SimulationTokenBalanceChange[]> {\n const balanceTxs = getTokenBalanceTransactions(request, events);\n\n log('Generated balance transactions', [...balanceTxs.after.values()]);\n\n const transactions = [\n ...balanceTxs.before.values(),\n request,\n ...balanceTxs.after.values(),\n ];\n\n if (transactions.length === 1) {\n return [];\n }\n\n const response = await simulateTransactions(request.chainId as Hex, {\n transactions,\n });\n\n log('Balance simulation response', response);\n\n if (response.transactions.length !== transactions.length) {\n throw new SimulationInvalidResponseError();\n }\n\n let prevBalanceTxIndex = 0;\n return [...balanceTxs.after.keys()]\n .map((token, index) => {\n const previousBalanceCheckSkipped = !balanceTxs.before.get(token);\n const previousBalance = previousBalanceCheckSkipped\n ? '0x0'\n : getValueFromBalanceTransaction(\n request.from,\n token,\n // eslint-disable-next-line no-plusplus\n response.transactions[prevBalanceTxIndex++],\n );\n\n const newBalance = getValueFromBalanceTransaction(\n request.from,\n token,\n response.transactions[index + balanceTxs.before.size + 1],\n );\n\n const balanceChange = getSimulationBalanceChange(\n previousBalance,\n newBalance,\n );\n\n if (!balanceChange) {\n return undefined;\n }\n\n return {\n ...token,\n ...balanceChange,\n };\n })\n .filter((change) => change !== undefined) as SimulationTokenBalanceChange[];\n}\n\n/**\n * Generate transactions to check token balances.\n * @param request - The transaction that was simulated.\n * @param events - The parsed events.\n * @returns A map of token balance transactions keyed by token.\n */\nfunction getTokenBalanceTransactions(\n request: GetSimulationDataRequest,\n events: ParsedEvent[],\n): {\n before: BalanceTransactionMap;\n after: BalanceTransactionMap;\n} {\n const tokenKeys = new Set();\n const before = new Map();\n const after = new Map();\n\n const userEvents = events.filter((event) =>\n [event.args.from, event.args.to].includes(request.from),\n );\n\n log('Filtered user events', userEvents);\n\n for (const event of userEvents) {\n const tokenIds = getEventTokenIds(event);\n\n log('Extracted token IDs', tokenIds);\n\n for (const tokenId of tokenIds) {\n const simulationToken: SimulationToken = {\n address: event.contractAddress,\n standard: event.tokenStandard,\n id: tokenId,\n };\n\n const tokenKey = JSON.stringify(simulationToken);\n\n if (tokenKeys.has(tokenKey)) {\n log(\n 'Ignoring additional event with same contract and token ID',\n simulationToken,\n );\n continue;\n }\n\n tokenKeys.add(tokenKey);\n\n const data = getBalanceTransactionData(\n event.tokenStandard,\n request.from,\n tokenId,\n );\n\n const transaction: SimulationRequestTransaction = {\n from: request.from,\n to: event.contractAddress,\n data,\n };\n\n if (skipPriorBalanceCheck(event)) {\n after.set(simulationToken, transaction);\n } else {\n before.set(simulationToken, transaction);\n after.set(simulationToken, transaction);\n }\n }\n }\n\n return { before, after };\n}\n\n/**\n * Check if an event needs to check the previous balance.\n * @param event - The parsed event.\n * @returns True if the prior balance check should be skipped.\n */\nfunction skipPriorBalanceCheck(event: ParsedEvent): boolean {\n // In the case of an NFT mint, we cannot check the NFT owner before the mint\n // as the balance check transaction would revert.\n return (\n event.name === 'Transfer' &&\n event.tokenStandard === SimulationTokenStandard.erc721 &&\n parseInt(event.args.from as string, 16) === 0\n );\n}\n\n/**\n * Extract token IDs from a parsed event.\n * @param event - The parsed event.\n * @returns An array of token IDs.\n */\nfunction getEventTokenIds(event: ParsedEvent): (Hex | undefined)[] {\n if (event.tokenStandard === SimulationTokenStandard.erc721) {\n return [event.args.tokenId as Hex];\n }\n\n if (\n event.tokenStandard === SimulationTokenStandard.erc1155 &&\n event.name === 'TransferSingle'\n ) {\n return [event.args.id as Hex];\n }\n\n if (\n event.tokenStandard === SimulationTokenStandard.erc1155 &&\n event.name === 'TransferBatch'\n ) {\n return event.args.ids as Hex[];\n }\n\n // ERC-20 does not have a token ID so default to undefined.\n return [undefined];\n}\n\n/**\n * Extract the value from a balance transaction response.\n * @param from - The address to check the balance of.\n * @param token - The token to check the balance of.\n * @param response - The balance transaction response.\n * @returns The value of the balance transaction.\n */\nfunction getValueFromBalanceTransaction(\n from: Hex,\n token: SimulationToken,\n response: SimulationResponseTransaction,\n): Hex {\n const normalizedReturn = normalizeReturnValue(response.return);\n\n if (token.standard === SimulationTokenStandard.erc721) {\n return normalizedReturn === from ? '0x1' : '0x0';\n }\n\n return normalizedReturn;\n}\n\n/**\n * Generate the balance transaction data for a token.\n * @param tokenStandard - The token standard.\n * @param from - The address to check the balance of.\n * @param tokenId - The token ID to check the balance of.\n * @returns The balance transaction data.\n */\nfunction getBalanceTransactionData(\n tokenStandard: SimulationTokenStandard,\n from: Hex,\n tokenId?: Hex,\n): Hex {\n switch (tokenStandard) {\n case SimulationTokenStandard.erc721:\n return new Interface(abiERC721).encodeFunctionData('ownerOf', [\n tokenId,\n ]) as Hex;\n\n case SimulationTokenStandard.erc1155:\n return new Interface(abiERC1155).encodeFunctionData('balanceOf', [\n from,\n tokenId,\n ]) as Hex;\n\n default:\n return new Interface(abiERC20).encodeFunctionData('balanceOf', [\n from,\n ]) as Hex;\n }\n}\n\n/**\n * Parse a raw event log using known ABIs.\n * @param eventLog - The raw event log.\n * @param interfaces - The contract interfaces.\n * @returns The parsed event log or undefined if it could not be parsed.\n */\nfunction parseLog(\n eventLog: SimulationResponseLog,\n interfaces: Map<SupportedToken, Interface>,\n):\n | (LogDescription & { abi: ABI; standard: SimulationTokenStandard })\n | undefined {\n const supportedTokens = Object.values(SupportedToken);\n\n for (const token of supportedTokens) {\n try {\n const contractInterface = interfaces.get(token) as Interface;\n const { abi, standard } = SUPPORTED_TOKEN_ABIS[token];\n\n return {\n ...contractInterface.parseLog(eventLog),\n abi,\n standard,\n };\n } catch (e) {\n continue;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extract all logs from a call trace tree.\n * @param call - The root call trace.\n * @returns An array of logs.\n */\nfunction extractLogs(\n call: SimulationResponseCallTrace,\n): SimulationResponseLog[] {\n /* istanbul ignore next */\n const logs = call.logs ?? [];\n\n /* istanbul ignore next */\n const nestedCalls = call.calls ?? [];\n\n return [\n ...logs,\n ...nestedCalls.map((nestedCall) => extractLogs(nestedCall)).flat(),\n ];\n}\n\n/**\n * Generate balance change data from previous and new balances.\n * @param previousBalance - The previous balance.\n * @param newBalance - The new balance.\n * @returns The balance change data or undefined if unchanged.\n */\nfunction getSimulationBalanceChange(\n previousBalance: Hex,\n newBalance: Hex,\n): SimulationBalanceChange | undefined {\n const differenceBN = hexToBN(newBalance).sub(hexToBN(previousBalance));\n const isDecrease = differenceBN.isNeg();\n const difference = toHex(differenceBN.abs());\n\n if (differenceBN.isZero()) {\n log('Balance change is zero');\n return undefined;\n }\n\n return {\n previousBalance,\n newBalance,\n difference,\n isDecrease,\n };\n}\n\n/**\n * Normalize a return value.\n * @param value - The return value to normalize.\n * @returns The normalized return value.\n */\nfunction normalizeReturnValue(value: Hex): Hex {\n return toHex(hexToBN(value));\n}\n\n/**\n * Get the contract interfaces for all supported tokens.\n * @returns A map of supported tokens to their contract interfaces.\n */\nfunction getContractInterfaces(): Map<SupportedToken, Interface> {\n const supportedTokens = Object.values(SupportedToken);\n\n return new Map(\n supportedTokens.map((tokenType) => {\n const { abi } = SUPPORTED_TOKEN_ABIS[tokenType];\n const contractInterface = new Interface(abi);\n return [tokenType, contractInterface];\n }),\n );\n}\n"],"mappings":";;;;;;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