@metamask-previews/transaction-controller 69.6.1-preview-4f4c98e → 69.6.1-preview-eb263b0ee

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 (492) hide show
  1. package/CHANGELOG.md +0 -5
  2. package/dist/TransactionController-method-action-types.cjs +7 -0
  3. package/dist/TransactionController-method-action-types.cjs.map +1 -0
  4. package/dist/{TransactionController-method-action-types.d.ts → TransactionController-method-action-types.d.cts} +2 -2
  5. package/dist/TransactionController-method-action-types.d.cts.map +1 -0
  6. package/dist/TransactionController-method-action-types.d.mts +413 -0
  7. package/dist/TransactionController-method-action-types.d.mts.map +1 -0
  8. package/dist/{TransactionController-method-action-types.js → TransactionController-method-action-types.mjs} +1 -1
  9. package/dist/TransactionController-method-action-types.mjs.map +1 -0
  10. package/dist/TransactionController.cjs +2444 -0
  11. package/dist/TransactionController.cjs.map +1 -0
  12. package/dist/{TransactionController.d.ts → TransactionController.d.cts} +18 -18
  13. package/dist/TransactionController.d.cts.map +1 -0
  14. package/dist/TransactionController.d.mts +751 -0
  15. package/dist/TransactionController.d.mts.map +1 -0
  16. package/dist/{TransactionController.js → TransactionController.mjs} +50 -49
  17. package/dist/TransactionController.mjs.map +1 -0
  18. package/dist/api/accounts-api.cjs +57 -0
  19. package/dist/api/accounts-api.cjs.map +1 -0
  20. package/dist/api/{accounts-api.d.ts → accounts-api.d.cts} +1 -1
  21. package/dist/api/accounts-api.d.cts.map +1 -0
  22. package/dist/api/accounts-api.d.mts +44 -0
  23. package/dist/api/accounts-api.d.mts.map +1 -0
  24. package/dist/api/{accounts-api.js → accounts-api.mjs} +5 -5
  25. package/dist/api/accounts-api.mjs.map +1 -0
  26. package/dist/api/simulation-api.cjs +116 -0
  27. package/dist/api/simulation-api.cjs.map +1 -0
  28. package/dist/api/{simulation-api.d.ts → simulation-api.d.cts} +3 -3
  29. package/dist/api/simulation-api.d.cts.map +1 -0
  30. package/dist/api/simulation-api.d.mts +196 -0
  31. package/dist/api/simulation-api.d.mts.map +1 -0
  32. package/dist/api/{simulation-api.js → simulation-api.mjs} +8 -7
  33. package/dist/api/simulation-api.mjs.map +1 -0
  34. package/dist/constants.cjs +111 -0
  35. package/dist/constants.cjs.map +1 -0
  36. package/dist/{constants.d.ts → constants.d.cts} +37 -37
  37. package/dist/constants.d.cts.map +1 -0
  38. package/dist/constants.d.mts +78 -0
  39. package/dist/constants.d.mts.map +1 -0
  40. package/dist/{constants.js → constants.mjs} +1 -1
  41. package/dist/constants.mjs.map +1 -0
  42. package/dist/errors.cjs +37 -0
  43. package/dist/errors.cjs.map +1 -0
  44. package/dist/{errors.d.ts → errors.d.cts} +2 -2
  45. package/dist/errors.d.cts.map +1 -0
  46. package/dist/errors.d.mts +19 -0
  47. package/dist/errors.d.mts.map +1 -0
  48. package/dist/{errors.js → errors.mjs} +2 -2
  49. package/dist/errors.mjs.map +1 -0
  50. package/dist/gas-flows/DefaultGasFeeFlow.cjs +85 -0
  51. package/dist/gas-flows/{DefaultGasFeeFlow.js.map → DefaultGasFeeFlow.cjs.map} +1 -1
  52. package/dist/gas-flows/{DefaultGasFeeFlow.d.ts → DefaultGasFeeFlow.d.cts} +2 -2
  53. package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -0
  54. package/dist/gas-flows/DefaultGasFeeFlow.d.mts +10 -0
  55. package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -0
  56. package/dist/gas-flows/{DefaultGasFeeFlow.js → DefaultGasFeeFlow.mjs} +6 -6
  57. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
  58. package/dist/gas-flows/LineaGasFeeFlow.cjs +111 -0
  59. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -0
  60. package/dist/gas-flows/{LineaGasFeeFlow.d.ts → LineaGasFeeFlow.d.cts} +3 -3
  61. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -0
  62. package/dist/gas-flows/LineaGasFeeFlow.d.mts +16 -0
  63. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -0
  64. package/dist/gas-flows/{LineaGasFeeFlow.js → LineaGasFeeFlow.mjs} +7 -7
  65. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
  66. package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs +66 -0
  67. package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs.map +1 -0
  68. package/dist/gas-flows/{MantleLayer1GasFeeFlow.d.ts → MantleLayer1GasFeeFlow.d.cts} +5 -5
  69. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.cts.map +1 -0
  70. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts +21 -0
  71. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts.map +1 -0
  72. package/dist/gas-flows/{MantleLayer1GasFeeFlow.js → MantleLayer1GasFeeFlow.mjs} +6 -6
  73. package/dist/gas-flows/MantleLayer1GasFeeFlow.mjs.map +1 -0
  74. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +59 -0
  75. package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -0
  76. package/dist/gas-flows/{OptimismLayer1GasFeeFlow.d.ts → OptimismLayer1GasFeeFlow.d.cts} +4 -4
  77. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -0
  78. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +14 -0
  79. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -0
  80. package/dist/gas-flows/{OptimismLayer1GasFeeFlow.js → OptimismLayer1GasFeeFlow.mjs} +5 -5
  81. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -0
  82. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +201 -0
  83. package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -0
  84. package/dist/gas-flows/{OracleLayer1GasFeeFlow.d.ts → OracleLayer1GasFeeFlow.d.cts} +5 -5
  85. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -0
  86. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +57 -0
  87. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -0
  88. package/dist/gas-flows/{OracleLayer1GasFeeFlow.js → OracleLayer1GasFeeFlow.mjs} +15 -8
  89. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -0
  90. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs +123 -0
  91. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs.map +1 -0
  92. package/dist/gas-flows/{RandomisedEstimationsGasFeeFlow.d.ts → RandomisedEstimationsGasFeeFlow.d.cts} +4 -4
  93. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts.map +1 -0
  94. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts +28 -0
  95. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts.map +1 -0
  96. package/dist/gas-flows/{RandomisedEstimationsGasFeeFlow.js → RandomisedEstimationsGasFeeFlow.mjs} +8 -8
  97. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs.map +1 -0
  98. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +24 -0
  99. package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -0
  100. package/dist/gas-flows/{ScrollLayer1GasFeeFlow.d.ts → ScrollLayer1GasFeeFlow.d.cts} +5 -5
  101. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -0
  102. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +16 -0
  103. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -0
  104. package/dist/gas-flows/{ScrollLayer1GasFeeFlow.js → ScrollLayer1GasFeeFlow.mjs} +3 -3
  105. package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -0
  106. package/dist/gas-flows/TestGasFeeFlow.cjs +73 -0
  107. package/dist/gas-flows/TestGasFeeFlow.cjs.map +1 -0
  108. package/dist/gas-flows/{TestGasFeeFlow.d.ts → TestGasFeeFlow.d.cts} +2 -2
  109. package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -0
  110. package/dist/gas-flows/TestGasFeeFlow.d.mts +12 -0
  111. package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -0
  112. package/dist/gas-flows/{TestGasFeeFlow.js → TestGasFeeFlow.mjs} +3 -3
  113. package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -0
  114. package/dist/helpers/GasFeePoller.cjs +334 -0
  115. package/dist/helpers/GasFeePoller.cjs.map +1 -0
  116. package/dist/helpers/{GasFeePoller.d.ts → GasFeePoller.d.cts} +10 -7
  117. package/dist/helpers/GasFeePoller.d.cts.map +1 -0
  118. package/dist/helpers/GasFeePoller.d.mts +66 -0
  119. package/dist/helpers/GasFeePoller.d.mts.map +1 -0
  120. package/dist/helpers/{GasFeePoller.js → GasFeePoller.mjs} +9 -9
  121. package/dist/helpers/GasFeePoller.mjs.map +1 -0
  122. package/dist/helpers/MethodDataHelper.cjs +84 -0
  123. package/dist/helpers/MethodDataHelper.cjs.map +1 -0
  124. package/dist/helpers/{MethodDataHelper.d.ts → MethodDataHelper.d.cts} +7 -4
  125. package/dist/helpers/MethodDataHelper.d.cts.map +1 -0
  126. package/dist/helpers/MethodDataHelper.d.mts +16 -0
  127. package/dist/helpers/MethodDataHelper.d.mts.map +1 -0
  128. package/dist/helpers/{MethodDataHelper.js → MethodDataHelper.mjs} +7 -7
  129. package/dist/helpers/MethodDataHelper.mjs.map +1 -0
  130. package/dist/helpers/MultichainTrackingHelper.cjs +231 -0
  131. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -0
  132. package/dist/helpers/{MultichainTrackingHelper.d.ts → MultichainTrackingHelper.d.cts} +5 -5
  133. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -0
  134. package/dist/helpers/MultichainTrackingHelper.d.mts +56 -0
  135. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -0
  136. package/dist/helpers/{MultichainTrackingHelper.js → MultichainTrackingHelper.mjs} +8 -8
  137. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
  138. package/dist/helpers/PendingTransactionTracker.cjs +407 -0
  139. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
  140. package/dist/helpers/{PendingTransactionTracker.d.ts → PendingTransactionTracker.d.cts} +8 -5
  141. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -0
  142. package/dist/helpers/PendingTransactionTracker.d.mts +54 -0
  143. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -0
  144. package/dist/helpers/{PendingTransactionTracker.js → PendingTransactionTracker.mjs} +15 -14
  145. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
  146. package/dist/helpers/ResimulateHelper.cjs +274 -0
  147. package/dist/helpers/ResimulateHelper.cjs.map +1 -0
  148. package/dist/helpers/{ResimulateHelper.d.ts → ResimulateHelper.d.cts} +3 -3
  149. package/dist/helpers/ResimulateHelper.d.cts.map +1 -0
  150. package/dist/helpers/ResimulateHelper.d.mts +36 -0
  151. package/dist/helpers/ResimulateHelper.d.mts.map +1 -0
  152. package/dist/helpers/{ResimulateHelper.js → ResimulateHelper.mjs} +8 -7
  153. package/dist/helpers/ResimulateHelper.mjs.map +1 -0
  154. package/dist/helpers/TransactionPoller.cjs +175 -0
  155. package/dist/helpers/TransactionPoller.cjs.map +1 -0
  156. package/dist/helpers/{TransactionPoller.d.ts → TransactionPoller.d.cts} +5 -5
  157. package/dist/helpers/TransactionPoller.d.cts.map +1 -0
  158. package/dist/helpers/TransactionPoller.d.mts +37 -0
  159. package/dist/helpers/TransactionPoller.d.mts.map +1 -0
  160. package/dist/helpers/{TransactionPoller.js → TransactionPoller.mjs} +11 -10
  161. package/dist/helpers/TransactionPoller.mjs.map +1 -0
  162. package/dist/hooks/CollectPublishHook.cjs +94 -0
  163. package/dist/hooks/CollectPublishHook.cjs.map +1 -0
  164. package/dist/hooks/{CollectPublishHook.d.ts → CollectPublishHook.d.cts} +3 -3
  165. package/dist/hooks/CollectPublishHook.d.cts.map +1 -0
  166. package/dist/hooks/CollectPublishHook.d.mts +29 -0
  167. package/dist/hooks/CollectPublishHook.d.mts.map +1 -0
  168. package/dist/hooks/{CollectPublishHook.js → CollectPublishHook.mjs} +5 -4
  169. package/dist/hooks/CollectPublishHook.mjs.map +1 -0
  170. package/dist/hooks/ExtraTransactionsPublishHook.cjs +126 -0
  171. package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -0
  172. package/dist/hooks/{ExtraTransactionsPublishHook.d.ts → ExtraTransactionsPublishHook.d.cts} +3 -3
  173. package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -0
  174. package/dist/hooks/ExtraTransactionsPublishHook.d.mts +19 -0
  175. package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -0
  176. package/dist/hooks/{ExtraTransactionsPublishHook.js → ExtraTransactionsPublishHook.mjs} +3 -3
  177. package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -0
  178. package/dist/hooks/SequentialPublishBatchHook.cjs +112 -0
  179. package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -0
  180. package/dist/hooks/{SequentialPublishBatchHook.d.ts → SequentialPublishBatchHook.d.cts} +4 -4
  181. package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -0
  182. package/dist/hooks/SequentialPublishBatchHook.d.mts +22 -0
  183. package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -0
  184. package/dist/hooks/{SequentialPublishBatchHook.js → SequentialPublishBatchHook.mjs} +4 -4
  185. package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -0
  186. package/dist/index.cjs +40 -0
  187. package/dist/index.cjs.map +1 -0
  188. package/dist/{index.d.ts → index.d.cts} +16 -16
  189. package/dist/index.d.cts.map +1 -0
  190. package/dist/index.d.mts +16 -0
  191. package/dist/index.d.mts.map +1 -0
  192. package/dist/index.mjs +12 -0
  193. package/dist/index.mjs.map +1 -0
  194. package/dist/logger.cjs +9 -0
  195. package/dist/logger.cjs.map +1 -0
  196. package/dist/{logger.d.ts → logger.d.cts} +3 -2
  197. package/dist/logger.d.cts.map +1 -0
  198. package/dist/logger.d.mts +6 -0
  199. package/dist/logger.d.mts.map +1 -0
  200. package/dist/{logger.js → logger.mjs} +2 -2
  201. package/dist/logger.mjs.map +1 -0
  202. package/dist/types.cjs +382 -0
  203. package/dist/types.cjs.map +1 -0
  204. package/dist/{types.d.ts → types.d.cts} +8 -8
  205. package/dist/types.d.cts.map +1 -0
  206. package/dist/types.d.mts +1887 -0
  207. package/dist/types.d.mts.map +1 -0
  208. package/dist/{types.js → types.mjs} +1 -1
  209. package/dist/types.mjs.map +1 -0
  210. package/dist/utils/balance-changes.cjs +592 -0
  211. package/dist/utils/balance-changes.cjs.map +1 -0
  212. package/dist/utils/{balance-changes.d.ts → balance-changes.d.cts} +5 -5
  213. package/dist/utils/balance-changes.d.cts.map +1 -0
  214. package/dist/utils/balance-changes.d.mts +38 -0
  215. package/dist/utils/balance-changes.d.mts.map +1 -0
  216. package/dist/utils/{balance-changes.js → balance-changes.mjs} +20 -13
  217. package/dist/utils/balance-changes.mjs.map +1 -0
  218. package/dist/utils/balance.cjs +44 -0
  219. package/dist/utils/balance.cjs.map +1 -0
  220. package/dist/utils/{balance.d.ts → balance.d.cts} +5 -5
  221. package/dist/utils/balance.d.cts.map +1 -0
  222. package/dist/utils/balance.d.mts +26 -0
  223. package/dist/utils/balance.d.mts.map +1 -0
  224. package/dist/utils/{balance.js → balance.mjs} +3 -3
  225. package/dist/utils/balance.mjs.map +1 -0
  226. package/dist/utils/batch.cjs +712 -0
  227. package/dist/utils/batch.cjs.map +1 -0
  228. package/dist/utils/{batch.d.ts → batch.d.cts} +8 -8
  229. package/dist/utils/batch.d.cts.map +1 -0
  230. package/dist/utils/batch.d.mts +58 -0
  231. package/dist/utils/batch.d.mts.map +1 -0
  232. package/dist/utils/{batch.js → batch.mjs} +18 -18
  233. package/dist/utils/batch.mjs.map +1 -0
  234. package/dist/utils/eip7702.cjs +354 -0
  235. package/dist/utils/eip7702.cjs.map +1 -0
  236. package/dist/utils/{eip7702.d.ts → eip7702.d.cts} +5 -5
  237. package/dist/utils/eip7702.d.cts.map +1 -0
  238. package/dist/utils/eip7702.d.mts +137 -0
  239. package/dist/utils/eip7702.d.mts.map +1 -0
  240. package/dist/utils/{eip7702.js → eip7702.mjs} +12 -12
  241. package/dist/utils/eip7702.mjs.map +1 -0
  242. package/dist/utils/external-transactions.cjs +36 -0
  243. package/dist/utils/external-transactions.cjs.map +1 -0
  244. package/dist/utils/{external-transactions.d.ts → external-transactions.d.cts} +2 -2
  245. package/dist/utils/external-transactions.d.cts.map +1 -0
  246. package/dist/utils/external-transactions.d.mts +10 -0
  247. package/dist/utils/external-transactions.d.mts.map +1 -0
  248. package/dist/utils/{external-transactions.js → external-transactions.mjs} +3 -3
  249. package/dist/utils/external-transactions.mjs.map +1 -0
  250. package/dist/utils/feature-flags.cjs +255 -0
  251. package/dist/utils/feature-flags.cjs.map +1 -0
  252. package/dist/utils/{feature-flags.d.ts → feature-flags.d.cts} +3 -3
  253. package/dist/utils/feature-flags.d.cts.map +1 -0
  254. package/dist/utils/feature-flags.d.mts +313 -0
  255. package/dist/utils/feature-flags.d.mts.map +1 -0
  256. package/dist/utils/{feature-flags.js → feature-flags.mjs} +5 -5
  257. package/dist/utils/feature-flags.mjs.map +1 -0
  258. package/dist/utils/first-time-interaction.cjs +69 -0
  259. package/dist/utils/first-time-interaction.cjs.map +1 -0
  260. package/dist/utils/{first-time-interaction.d.ts → first-time-interaction.d.cts} +3 -3
  261. package/dist/utils/first-time-interaction.d.cts.map +1 -0
  262. package/dist/utils/first-time-interaction.d.mts +30 -0
  263. package/dist/utils/first-time-interaction.d.mts.map +1 -0
  264. package/dist/utils/{first-time-interaction.js → first-time-interaction.mjs} +6 -6
  265. package/dist/utils/first-time-interaction.mjs.map +1 -0
  266. package/dist/utils/gas-fee-tokens.cjs +174 -0
  267. package/dist/utils/gas-fee-tokens.cjs.map +1 -0
  268. package/dist/utils/{gas-fee-tokens.d.ts → gas-fee-tokens.d.cts} +5 -5
  269. package/dist/utils/gas-fee-tokens.d.cts.map +1 -0
  270. package/dist/utils/gas-fee-tokens.d.mts +46 -0
  271. package/dist/utils/gas-fee-tokens.d.mts.map +1 -0
  272. package/dist/utils/{gas-fee-tokens.js → gas-fee-tokens.mjs} +9 -9
  273. package/dist/utils/gas-fee-tokens.mjs.map +1 -0
  274. package/dist/utils/gas-fees.cjs +424 -0
  275. package/dist/utils/gas-fees.cjs.map +1 -0
  276. package/dist/utils/{gas-fees.d.ts → gas-fees.d.cts} +5 -5
  277. package/dist/utils/gas-fees.d.cts.map +1 -0
  278. package/dist/utils/gas-fees.d.mts +57 -0
  279. package/dist/utils/gas-fees.d.mts.map +1 -0
  280. package/dist/utils/{gas-fees.js → gas-fees.mjs} +9 -9
  281. package/dist/utils/gas-fees.mjs.map +1 -0
  282. package/dist/utils/gas-flow.cjs +81 -0
  283. package/dist/utils/gas-flow.cjs.map +1 -0
  284. package/dist/utils/{gas-flow.d.ts → gas-flow.d.cts} +6 -6
  285. package/dist/utils/gas-flow.d.cts.map +1 -0
  286. package/dist/utils/gas-flow.d.mts +29 -0
  287. package/dist/utils/gas-flow.d.mts.map +1 -0
  288. package/dist/utils/{gas-flow.js → gas-flow.mjs} +3 -3
  289. package/dist/utils/gas-flow.mjs.map +1 -0
  290. package/dist/utils/gas.cjs +545 -0
  291. package/dist/utils/gas.cjs.map +1 -0
  292. package/dist/utils/{gas.d.ts → gas.d.cts} +6 -5
  293. package/dist/utils/gas.d.cts.map +1 -0
  294. package/dist/utils/gas.d.mts +116 -0
  295. package/dist/utils/gas.d.mts.map +1 -0
  296. package/dist/utils/{gas.js → gas.mjs} +11 -11
  297. package/dist/utils/gas.mjs.map +1 -0
  298. package/dist/utils/layer1-gas-fee-flow.cjs +73 -0
  299. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -0
  300. package/dist/utils/{layer1-gas-fee-flow.d.ts → layer1-gas-fee-flow.d.cts} +4 -4
  301. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -0
  302. package/dist/utils/layer1-gas-fee-flow.d.mts +28 -0
  303. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -0
  304. package/dist/utils/{layer1-gas-fee-flow.js → layer1-gas-fee-flow.mjs} +3 -3
  305. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -0
  306. package/dist/utils/nonce.cjs +93 -0
  307. package/dist/utils/nonce.cjs.map +1 -0
  308. package/dist/utils/{nonce.d.ts → nonce.d.cts} +3 -3
  309. package/dist/utils/nonce.d.cts.map +1 -0
  310. package/dist/utils/nonce.d.mts +26 -0
  311. package/dist/utils/nonce.d.mts.map +1 -0
  312. package/dist/utils/{nonce.js → nonce.mjs} +4 -4
  313. package/dist/utils/nonce.mjs.map +1 -0
  314. package/dist/utils/prepare.cjs +97 -0
  315. package/dist/utils/prepare.cjs.map +1 -0
  316. package/dist/utils/{prepare.d.ts → prepare.d.cts} +5 -5
  317. package/dist/utils/prepare.d.cts.map +1 -0
  318. package/dist/utils/prepare.d.mts +22 -0
  319. package/dist/utils/prepare.d.mts.map +1 -0
  320. package/dist/utils/{prepare.js → prepare.mjs} +6 -5
  321. package/dist/utils/prepare.mjs.map +1 -0
  322. package/dist/utils/provider.cjs +106 -0
  323. package/dist/utils/provider.cjs.map +1 -0
  324. package/dist/utils/{provider.d.ts → provider.d.cts} +4 -4
  325. package/dist/utils/provider.d.cts.map +1 -0
  326. package/dist/utils/provider.d.mts +65 -0
  327. package/dist/utils/provider.d.mts.map +1 -0
  328. package/dist/utils/{provider.js → provider.mjs} +3 -3
  329. package/dist/utils/provider.mjs.map +1 -0
  330. package/dist/utils/recipient.cjs +31 -0
  331. package/dist/utils/recipient.cjs.map +1 -0
  332. package/dist/utils/{recipient.d.ts → recipient.d.cts} +2 -2
  333. package/dist/utils/recipient.d.cts.map +1 -0
  334. package/dist/utils/recipient.d.mts +13 -0
  335. package/dist/utils/recipient.d.mts.map +1 -0
  336. package/dist/utils/{recipient.js → recipient.mjs} +3 -3
  337. package/dist/utils/recipient.mjs.map +1 -0
  338. package/dist/utils/retry.cjs +93 -0
  339. package/dist/utils/retry.cjs.map +1 -0
  340. package/dist/utils/{retry.d.ts → retry.d.cts} +2 -2
  341. package/dist/utils/retry.d.cts.map +1 -0
  342. package/dist/utils/retry.d.mts +11 -0
  343. package/dist/utils/retry.d.mts.map +1 -0
  344. package/dist/utils/{retry.js → retry.mjs} +3 -3
  345. package/dist/utils/retry.mjs.map +1 -0
  346. package/dist/utils/revert-reason.cjs +192 -0
  347. package/dist/utils/revert-reason.cjs.map +1 -0
  348. package/dist/utils/{revert-reason.d.ts → revert-reason.d.cts} +5 -5
  349. package/dist/utils/revert-reason.d.cts.map +1 -0
  350. package/dist/utils/revert-reason.d.mts +57 -0
  351. package/dist/utils/revert-reason.d.mts.map +1 -0
  352. package/dist/utils/{revert-reason.js → revert-reason.mjs} +4 -4
  353. package/dist/utils/revert-reason.mjs.map +1 -0
  354. package/dist/utils/signature.cjs +26 -0
  355. package/dist/utils/signature.cjs.map +1 -0
  356. package/dist/utils/{signature.d.ts → signature.d.cts} +2 -2
  357. package/dist/utils/signature.d.cts.map +1 -0
  358. package/dist/utils/signature.d.mts +11 -0
  359. package/dist/utils/signature.d.mts.map +1 -0
  360. package/dist/utils/{signature.js → signature.mjs} +3 -3
  361. package/dist/utils/signature.mjs.map +1 -0
  362. package/dist/utils/swaps.cjs +332 -0
  363. package/dist/utils/swaps.cjs.map +1 -0
  364. package/dist/utils/{swaps.d.ts → swaps.d.cts} +5 -5
  365. package/dist/utils/swaps.d.cts.map +1 -0
  366. package/dist/utils/swaps.d.mts +90 -0
  367. package/dist/utils/swaps.d.mts.map +1 -0
  368. package/dist/utils/{swaps.js → swaps.mjs} +8 -7
  369. package/dist/utils/swaps.mjs.map +1 -0
  370. package/dist/utils/transaction-type.cjs +159 -0
  371. package/dist/utils/transaction-type.cjs.map +1 -0
  372. package/dist/utils/{transaction-type.d.ts → transaction-type.d.cts} +6 -6
  373. package/dist/utils/transaction-type.d.cts.map +1 -0
  374. package/dist/utils/transaction-type.d.mts +44 -0
  375. package/dist/utils/transaction-type.d.mts.map +1 -0
  376. package/dist/utils/{transaction-type.js → transaction-type.mjs} +6 -6
  377. package/dist/utils/transaction-type.mjs.map +1 -0
  378. package/dist/utils/utils.cjs +287 -0
  379. package/dist/utils/utils.cjs.map +1 -0
  380. package/dist/utils/{utils.d.ts → utils.d.cts} +4 -4
  381. package/dist/utils/utils.d.cts.map +1 -0
  382. package/dist/utils/utils.d.mts +101 -0
  383. package/dist/utils/utils.d.mts.map +1 -0
  384. package/dist/utils/{utils.js → utils.mjs} +12 -5
  385. package/dist/utils/utils.mjs.map +1 -0
  386. package/dist/utils/validation.cjs +389 -0
  387. package/dist/utils/validation.cjs.map +1 -0
  388. package/dist/utils/{validation.d.ts → validation.d.cts} +4 -4
  389. package/dist/utils/validation.d.cts.map +1 -0
  390. package/dist/utils/validation.d.mts +66 -0
  391. package/dist/utils/validation.d.mts.map +1 -0
  392. package/dist/utils/{validation.js → validation.mjs} +8 -8
  393. package/dist/utils/validation.mjs.map +1 -0
  394. package/package.json +19 -15
  395. package/dist/TransactionController-method-action-types.d.ts.map +0 -1
  396. package/dist/TransactionController-method-action-types.js.map +0 -1
  397. package/dist/TransactionController.d.ts.map +0 -1
  398. package/dist/TransactionController.js.map +0 -1
  399. package/dist/api/accounts-api.d.ts.map +0 -1
  400. package/dist/api/accounts-api.js.map +0 -1
  401. package/dist/api/simulation-api.d.ts.map +0 -1
  402. package/dist/api/simulation-api.js.map +0 -1
  403. package/dist/constants.d.ts.map +0 -1
  404. package/dist/constants.js.map +0 -1
  405. package/dist/errors.d.ts.map +0 -1
  406. package/dist/errors.js.map +0 -1
  407. package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  408. package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  409. package/dist/gas-flows/LineaGasFeeFlow.js.map +0 -1
  410. package/dist/gas-flows/MantleLayer1GasFeeFlow.d.ts.map +0 -1
  411. package/dist/gas-flows/MantleLayer1GasFeeFlow.js.map +0 -1
  412. package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
  413. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
  414. package/dist/gas-flows/OracleLayer1GasFeeFlow.d.ts.map +0 -1
  415. package/dist/gas-flows/OracleLayer1GasFeeFlow.js.map +0 -1
  416. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.ts.map +0 -1
  417. package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.js.map +0 -1
  418. package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.ts.map +0 -1
  419. package/dist/gas-flows/ScrollLayer1GasFeeFlow.js.map +0 -1
  420. package/dist/gas-flows/TestGasFeeFlow.d.ts.map +0 -1
  421. package/dist/gas-flows/TestGasFeeFlow.js.map +0 -1
  422. package/dist/helpers/GasFeePoller.d.ts.map +0 -1
  423. package/dist/helpers/GasFeePoller.js.map +0 -1
  424. package/dist/helpers/MethodDataHelper.d.ts.map +0 -1
  425. package/dist/helpers/MethodDataHelper.js.map +0 -1
  426. package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  427. package/dist/helpers/MultichainTrackingHelper.js.map +0 -1
  428. package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
  429. package/dist/helpers/PendingTransactionTracker.js.map +0 -1
  430. package/dist/helpers/ResimulateHelper.d.ts.map +0 -1
  431. package/dist/helpers/ResimulateHelper.js.map +0 -1
  432. package/dist/helpers/TransactionPoller.d.ts.map +0 -1
  433. package/dist/helpers/TransactionPoller.js.map +0 -1
  434. package/dist/hooks/CollectPublishHook.d.ts.map +0 -1
  435. package/dist/hooks/CollectPublishHook.js.map +0 -1
  436. package/dist/hooks/ExtraTransactionsPublishHook.d.ts.map +0 -1
  437. package/dist/hooks/ExtraTransactionsPublishHook.js.map +0 -1
  438. package/dist/hooks/SequentialPublishBatchHook.d.ts.map +0 -1
  439. package/dist/hooks/SequentialPublishBatchHook.js.map +0 -1
  440. package/dist/index.d.ts.map +0 -1
  441. package/dist/index.js +0 -12
  442. package/dist/index.js.map +0 -1
  443. package/dist/logger.d.ts.map +0 -1
  444. package/dist/logger.js.map +0 -1
  445. package/dist/types.d.ts.map +0 -1
  446. package/dist/types.js.map +0 -1
  447. package/dist/utils/balance-changes.d.ts.map +0 -1
  448. package/dist/utils/balance-changes.js.map +0 -1
  449. package/dist/utils/balance.d.ts.map +0 -1
  450. package/dist/utils/balance.js.map +0 -1
  451. package/dist/utils/batch.d.ts.map +0 -1
  452. package/dist/utils/batch.js.map +0 -1
  453. package/dist/utils/eip7702.d.ts.map +0 -1
  454. package/dist/utils/eip7702.js.map +0 -1
  455. package/dist/utils/external-transactions.d.ts.map +0 -1
  456. package/dist/utils/external-transactions.js.map +0 -1
  457. package/dist/utils/feature-flags.d.ts.map +0 -1
  458. package/dist/utils/feature-flags.js.map +0 -1
  459. package/dist/utils/first-time-interaction.d.ts.map +0 -1
  460. package/dist/utils/first-time-interaction.js.map +0 -1
  461. package/dist/utils/gas-fee-tokens.d.ts.map +0 -1
  462. package/dist/utils/gas-fee-tokens.js.map +0 -1
  463. package/dist/utils/gas-fees.d.ts.map +0 -1
  464. package/dist/utils/gas-fees.js.map +0 -1
  465. package/dist/utils/gas-flow.d.ts.map +0 -1
  466. package/dist/utils/gas-flow.js.map +0 -1
  467. package/dist/utils/gas.d.ts.map +0 -1
  468. package/dist/utils/gas.js.map +0 -1
  469. package/dist/utils/layer1-gas-fee-flow.d.ts.map +0 -1
  470. package/dist/utils/layer1-gas-fee-flow.js.map +0 -1
  471. package/dist/utils/nonce.d.ts.map +0 -1
  472. package/dist/utils/nonce.js.map +0 -1
  473. package/dist/utils/prepare.d.ts.map +0 -1
  474. package/dist/utils/prepare.js.map +0 -1
  475. package/dist/utils/provider.d.ts.map +0 -1
  476. package/dist/utils/provider.js.map +0 -1
  477. package/dist/utils/recipient.d.ts.map +0 -1
  478. package/dist/utils/recipient.js.map +0 -1
  479. package/dist/utils/retry.d.ts.map +0 -1
  480. package/dist/utils/retry.js.map +0 -1
  481. package/dist/utils/revert-reason.d.ts.map +0 -1
  482. package/dist/utils/revert-reason.js.map +0 -1
  483. package/dist/utils/signature.d.ts.map +0 -1
  484. package/dist/utils/signature.js.map +0 -1
  485. package/dist/utils/swaps.d.ts.map +0 -1
  486. package/dist/utils/swaps.js.map +0 -1
  487. package/dist/utils/transaction-type.d.ts.map +0 -1
  488. package/dist/utils/transaction-type.js.map +0 -1
  489. package/dist/utils/utils.d.ts.map +0 -1
  490. package/dist/utils/utils.js.map +0 -1
  491. package/dist/utils/validation.d.ts.map +0 -1
  492. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1,592 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getBalanceChanges = exports.SupportedToken = void 0;
7
+ const abi_1 = require("@ethersproject/abi");
8
+ const controller_utils_1 = require("@metamask/controller-utils");
9
+ const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
10
+ const utils_1 = require("@metamask/utils");
11
+ const bn_js_1 = __importDefault(require("bn.js"));
12
+ const simulation_api_js_1 = require("../api/simulation-api.cjs");
13
+ const constants_js_1 = require("../constants.cjs");
14
+ const errors_js_1 = require("../errors.cjs");
15
+ const logger_js_1 = require("../logger.cjs");
16
+ const types_js_1 = require("../types.cjs");
17
+ const balance_js_1 = require("./balance.cjs");
18
+ const revert_reason_js_1 = require("./revert-reason.cjs");
19
+ var SupportedToken;
20
+ (function (SupportedToken) {
21
+ SupportedToken["ERC20"] = "erc20";
22
+ SupportedToken["ERC721"] = "erc721";
23
+ SupportedToken["ERC1155"] = "erc1155";
24
+ // eslint-disable-next-line @typescript-eslint/naming-convention
25
+ SupportedToken["ERC20_WRAPPED"] = "erc20Wrapped";
26
+ // eslint-disable-next-line @typescript-eslint/naming-convention
27
+ SupportedToken["ERC721_LEGACY"] = "erc721Legacy";
28
+ })(SupportedToken || (exports.SupportedToken = SupportedToken = {}));
29
+ const log = (0, utils_1.createModuleLogger)(logger_js_1.projectLogger, 'balance-changes');
30
+ const SUPPORTED_EVENTS = [
31
+ 'Transfer',
32
+ 'TransferSingle',
33
+ 'TransferBatch',
34
+ 'Deposit',
35
+ 'Withdrawal',
36
+ ];
37
+ const SUPPORTED_TOKEN_ABIS = {
38
+ [SupportedToken.ERC20]: {
39
+ abi: metamask_eth_abis_1.abiERC20,
40
+ standard: types_js_1.SimulationTokenStandard.erc20,
41
+ },
42
+ [SupportedToken.ERC721]: {
43
+ abi: metamask_eth_abis_1.abiERC721,
44
+ standard: types_js_1.SimulationTokenStandard.erc721,
45
+ },
46
+ [SupportedToken.ERC1155]: {
47
+ abi: metamask_eth_abis_1.abiERC1155,
48
+ standard: types_js_1.SimulationTokenStandard.erc1155,
49
+ },
50
+ [SupportedToken.ERC20_WRAPPED]: {
51
+ abi: constants_js_1.ABI_SIMULATION_ERC20_WRAPPED,
52
+ standard: types_js_1.SimulationTokenStandard.erc20,
53
+ },
54
+ [SupportedToken.ERC721_LEGACY]: {
55
+ abi: constants_js_1.ABI_SIMULATION_ERC721_LEGACY,
56
+ standard: types_js_1.SimulationTokenStandard.erc721,
57
+ },
58
+ };
59
+ const REVERTED_ERRORS = ['execution reverted', 'insufficient funds for gas'];
60
+ /**
61
+ * Generate simulation data for a transaction.
62
+ *
63
+ * @param request - The transaction to simulate.
64
+ * @param request.chainId - The chain ID of the transaction.
65
+ * @param request.from - The sender of the transaction.
66
+ * @param request.to - The recipient of the transaction.
67
+ * @param request.value - The value of the transaction.
68
+ * @param request.data - The data of the transaction.
69
+ * @param request.getSimulationConfig - Optional transaction simulation parameters.
70
+ * @returns The simulation data.
71
+ */
72
+ async function getBalanceChanges(request) {
73
+ log('Request', request);
74
+ let callTraceErrors;
75
+ let simulationRevert;
76
+ try {
77
+ const response = await baseRequest({
78
+ request,
79
+ params: {
80
+ withCallTrace: true,
81
+ withLogs: true,
82
+ },
83
+ });
84
+ const transactionResponse = response.transactions?.[0];
85
+ callTraceErrors = extractCallTraceErrors(transactionResponse?.callTrace);
86
+ simulationRevert = extractRootRevert(transactionResponse?.callTrace);
87
+ const transactionError = transactionResponse?.error;
88
+ if (transactionError) {
89
+ throw new errors_js_1.SimulationError(transactionError);
90
+ }
91
+ const nativeBalanceChange = getNativeBalanceChange(request, response);
92
+ const events = getEvents(response);
93
+ log('Parsed events', events);
94
+ const tokenBalanceChanges = await getTokenBalanceChanges(request, events);
95
+ const gasUsed = transactionResponse?.gasUsed;
96
+ const simulationData = {
97
+ callTraceErrors,
98
+ nativeBalanceChange,
99
+ tokenBalanceChanges,
100
+ };
101
+ return { simulationData, gasUsed, simulationRevert };
102
+ }
103
+ catch (error) {
104
+ log('Failed to get balance changes', error, request);
105
+ let simulationError = error;
106
+ if (REVERTED_ERRORS.some((revertErrorMessage) => simulationError.message?.includes(revertErrorMessage))) {
107
+ simulationError = new errors_js_1.SimulationRevertedError();
108
+ }
109
+ const { code, message } = simulationError;
110
+ return {
111
+ simulationData: {
112
+ callTraceErrors,
113
+ tokenBalanceChanges: [],
114
+ error: {
115
+ code,
116
+ message,
117
+ },
118
+ },
119
+ gasUsed: undefined,
120
+ simulationRevert,
121
+ };
122
+ }
123
+ }
124
+ exports.getBalanceChanges = getBalanceChanges;
125
+ /**
126
+ * Extract the native balance change from a simulation response.
127
+ *
128
+ * @param request - Simulation request.
129
+ * @param response - Simulation response.
130
+ * @returns Native balance change or undefined if unchanged.
131
+ */
132
+ function getNativeBalanceChange(request, response) {
133
+ const transactionResponse = response.transactions[0];
134
+ /* istanbul ignore next */
135
+ if (!transactionResponse) {
136
+ return undefined;
137
+ }
138
+ const { txParams } = request;
139
+ const userAddress = txParams.from;
140
+ const { stateDiff } = transactionResponse;
141
+ const previousBalance = stateDiff?.pre?.[userAddress]?.balance;
142
+ const newBalance = stateDiff?.post?.[userAddress]?.balance;
143
+ if (!previousBalance || !newBalance) {
144
+ return undefined;
145
+ }
146
+ return getSimulationBalanceChange(previousBalance, newBalance, transactionResponse.gasCost);
147
+ }
148
+ /**
149
+ * Extract events from a simulation response.
150
+ *
151
+ * @param response - The simulation response.
152
+ * @returns The parsed events.
153
+ */
154
+ function getEvents(response) {
155
+ /* istanbul ignore next */
156
+ const logs = extractLogs(response.transactions[0]?.callTrace ?? {});
157
+ log('Extracted logs', logs);
158
+ const interfaces = getContractInterfaces();
159
+ return logs
160
+ .map((currentLog) => {
161
+ const event = parseLog(currentLog, interfaces);
162
+ if (!event) {
163
+ log('Failed to parse log', currentLog);
164
+ return undefined;
165
+ }
166
+ /* istanbul ignore next */
167
+ const inputs = event.abi.find((eventAbi) => eventAbi.name === event.name)?.inputs;
168
+ /* istanbul ignore if */
169
+ if (!inputs) {
170
+ log('Failed to find inputs for event', event);
171
+ return undefined;
172
+ }
173
+ if (!SUPPORTED_EVENTS.includes(event.name)) {
174
+ log('Ignoring unsupported event', event.name, event);
175
+ return undefined;
176
+ }
177
+ log('Normalizing event args', event.name, event);
178
+ const args = normalizeEventArgs(event.args, inputs);
179
+ return {
180
+ contractAddress: currentLog.address,
181
+ tokenStandard: event.standard,
182
+ name: event.name,
183
+ args,
184
+ abi: event.abi,
185
+ };
186
+ })
187
+ .filter((parsedEvent) => parsedEvent !== undefined);
188
+ }
189
+ /**
190
+ * Normalize event arguments using ABI input definitions.
191
+ *
192
+ * @param args - The raw event arguments.
193
+ * @param abiInputs - The ABI input definitions.
194
+ * @returns The normalized event arguments.
195
+ */
196
+ function normalizeEventArgs(args, abiInputs) {
197
+ return args.reduce((result, arg, index) => {
198
+ const name = abiInputs[index].name.replace('_', '');
199
+ const value = normalizeEventArgValue(arg);
200
+ result[name] = value;
201
+ return result;
202
+ }, {});
203
+ }
204
+ /**
205
+ * Normalize an event argument value.
206
+ *
207
+ * @param value - The event argument value.
208
+ * @returns The normalized event argument value.
209
+ */
210
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
211
+ function normalizeEventArgValue(value) {
212
+ if (Array.isArray(value)) {
213
+ return value.map(normalizeEventArgValue);
214
+ }
215
+ let normalizedValue = value;
216
+ normalizedValue = normalizedValue.toHexString?.() ?? normalizedValue;
217
+ normalizedValue = normalizedValue.toLowerCase?.() ?? normalizedValue;
218
+ return normalizedValue;
219
+ }
220
+ /**
221
+ * Generate token balance changes from parsed events.
222
+ *
223
+ * @param request - The transaction that was simulated.
224
+ * @param events - The parsed events.
225
+ * @returns An array of token balance changes.
226
+ */
227
+ async function getTokenBalanceChanges(request, events) {
228
+ const { txParams } = request;
229
+ const from = txParams.from;
230
+ const balanceTxs = getTokenBalanceTransactions(request, events);
231
+ log('Generated balance transactions', [...balanceTxs.after.values()]);
232
+ const transactionCount = balanceTxs.before.size + balanceTxs.after.size + 1;
233
+ if (transactionCount === 1) {
234
+ return [];
235
+ }
236
+ const response = await baseRequest({
237
+ request,
238
+ before: [...balanceTxs.before.values()],
239
+ after: [...balanceTxs.after.values()],
240
+ });
241
+ log('Balance simulation response', response);
242
+ if (response.transactions.length !== transactionCount) {
243
+ throw new errors_js_1.SimulationInvalidResponseError();
244
+ }
245
+ let prevBalanceTxIndex = 0;
246
+ return [...balanceTxs.after.keys()]
247
+ .map((token, index) => {
248
+ const previousBalanceCheckSkipped = !balanceTxs.before.get(token);
249
+ const previousBalance = previousBalanceCheckSkipped
250
+ ? '0x0'
251
+ : getAmountFromBalanceTransactionResult(from, token,
252
+ // eslint-disable-next-line no-plusplus
253
+ response.transactions[prevBalanceTxIndex++]);
254
+ const newBalance = getAmountFromBalanceTransactionResult(from, token, response.transactions[index + balanceTxs.before.size + 1]);
255
+ const balanceChange = getSimulationBalanceChange(previousBalance, newBalance);
256
+ if (!balanceChange) {
257
+ return undefined;
258
+ }
259
+ return {
260
+ ...token,
261
+ ...balanceChange,
262
+ };
263
+ })
264
+ .filter((change) => change !== undefined);
265
+ }
266
+ /**
267
+ * Generate transactions to check token balances.
268
+ *
269
+ * @param request - The transaction that was simulated.
270
+ * @param events - The parsed events.
271
+ * @returns A map of token balance transactions keyed by token.
272
+ */
273
+ function getTokenBalanceTransactions(request, events) {
274
+ const tokenKeys = new Set();
275
+ const before = new Map();
276
+ const after = new Map();
277
+ const from = request.txParams.from;
278
+ const userEvents = events.filter((event) => [event.args.from, event.args.to].includes(from));
279
+ log('Filtered user events', userEvents);
280
+ for (const event of userEvents) {
281
+ const tokenIds = getEventTokenIds(event);
282
+ log('Extracted token IDs', tokenIds);
283
+ for (const tokenId of tokenIds) {
284
+ const simulationToken = {
285
+ address: event.contractAddress,
286
+ standard: event.tokenStandard,
287
+ id: tokenId,
288
+ };
289
+ const tokenKey = JSON.stringify(simulationToken);
290
+ if (tokenKeys.has(tokenKey)) {
291
+ log('Ignoring additional event with same contract and token ID', simulationToken);
292
+ continue;
293
+ }
294
+ tokenKeys.add(tokenKey);
295
+ const data = getBalanceTransactionData(event.tokenStandard, from, tokenId);
296
+ const transaction = {
297
+ from,
298
+ to: event.contractAddress,
299
+ data,
300
+ };
301
+ if (skipPriorBalanceCheck(event)) {
302
+ after.set(simulationToken, transaction);
303
+ }
304
+ else {
305
+ before.set(simulationToken, transaction);
306
+ after.set(simulationToken, transaction);
307
+ }
308
+ }
309
+ }
310
+ return { before, after };
311
+ }
312
+ /**
313
+ * Check if an event needs to check the previous balance.
314
+ *
315
+ * @param event - The parsed event.
316
+ * @returns True if the prior balance check should be skipped.
317
+ */
318
+ function skipPriorBalanceCheck(event) {
319
+ // In the case of an NFT mint, we cannot check the NFT owner before the mint
320
+ // as the balance check transaction would revert.
321
+ return (event.name === 'Transfer' &&
322
+ event.tokenStandard === types_js_1.SimulationTokenStandard.erc721 &&
323
+ parseInt(event.args.from, 16) === 0);
324
+ }
325
+ /**
326
+ * Extract token IDs from a parsed event.
327
+ *
328
+ * @param event - The parsed event.
329
+ * @returns An array of token IDs.
330
+ */
331
+ function getEventTokenIds(event) {
332
+ if (event.tokenStandard === types_js_1.SimulationTokenStandard.erc721) {
333
+ return [event.args.tokenId];
334
+ }
335
+ if (event.tokenStandard === types_js_1.SimulationTokenStandard.erc1155 &&
336
+ event.name === 'TransferSingle') {
337
+ return [event.args.id];
338
+ }
339
+ if (event.tokenStandard === types_js_1.SimulationTokenStandard.erc1155 &&
340
+ event.name === 'TransferBatch') {
341
+ return event.args.ids;
342
+ }
343
+ // ERC-20 does not have a token ID so default to undefined.
344
+ return [undefined];
345
+ }
346
+ /**
347
+ * Get the interface for a token standard.
348
+ *
349
+ * @param tokenStandard - The token standard.
350
+ * @returns The interface for the token standard.
351
+ */
352
+ function getContractInterface(tokenStandard) {
353
+ switch (tokenStandard) {
354
+ case types_js_1.SimulationTokenStandard.erc721:
355
+ return new abi_1.Interface(metamask_eth_abis_1.abiERC721);
356
+ case types_js_1.SimulationTokenStandard.erc1155:
357
+ return new abi_1.Interface(metamask_eth_abis_1.abiERC1155);
358
+ default:
359
+ return new abi_1.Interface(metamask_eth_abis_1.abiERC20);
360
+ }
361
+ }
362
+ /**
363
+ * Extract the value from a balance transaction response using the correct ABI.
364
+ *
365
+ * @param from - The address to check the balance of.
366
+ * @param token - The token to check the balance of.
367
+ * @param response - The balance transaction response.
368
+ * @returns The value of the balance transaction as Hex.
369
+ */
370
+ function getAmountFromBalanceTransactionResult(from, token, response) {
371
+ const contract = getContractInterface(token.standard);
372
+ try {
373
+ if (token.standard === types_js_1.SimulationTokenStandard.erc721) {
374
+ const result = contract.decodeFunctionResult('ownerOf', response.return);
375
+ const owner = result[0];
376
+ return owner.toLowerCase() === from.toLowerCase() ? '0x1' : '0x0';
377
+ }
378
+ const result = contract.decodeFunctionResult('balanceOf', response.return);
379
+ return (0, controller_utils_1.toHex)(result[0]);
380
+ }
381
+ catch (error) {
382
+ log('Failed to decode balance transaction', error, { token, response });
383
+ throw new errors_js_1.SimulationError(`Failed to decode balance transaction for token ${token.address}: ${String(error)}`);
384
+ }
385
+ }
386
+ /**
387
+ * Generate the balance transaction data for a token.
388
+ *
389
+ * @param tokenStandard - The token standard.
390
+ * @param from - The address to check the balance of.
391
+ * @param tokenId - The token ID to check the balance of.
392
+ * @returns The balance transaction data.
393
+ */
394
+ function getBalanceTransactionData(tokenStandard, from, tokenId) {
395
+ const contract = getContractInterface(tokenStandard);
396
+ switch (tokenStandard) {
397
+ case types_js_1.SimulationTokenStandard.erc721:
398
+ return contract.encodeFunctionData('ownerOf', [tokenId]);
399
+ case types_js_1.SimulationTokenStandard.erc1155:
400
+ return contract.encodeFunctionData('balanceOf', [from, tokenId]);
401
+ default:
402
+ return contract.encodeFunctionData('balanceOf', [from]);
403
+ }
404
+ }
405
+ /**
406
+ * Parse a raw event log using known ABIs.
407
+ *
408
+ * @param eventLog - The raw event log.
409
+ * @param interfaces - The contract interfaces.
410
+ * @returns The parsed event log or undefined if it could not be parsed.
411
+ */
412
+ function parseLog(eventLog, interfaces) {
413
+ const supportedTokens = Object.values(SupportedToken);
414
+ for (const token of supportedTokens) {
415
+ try {
416
+ const contractInterface = interfaces.get(token);
417
+ const { abi, standard } = SUPPORTED_TOKEN_ABIS[token];
418
+ return {
419
+ ...contractInterface.parseLog(eventLog),
420
+ abi,
421
+ standard,
422
+ };
423
+ }
424
+ catch {
425
+ continue;
426
+ }
427
+ }
428
+ return undefined;
429
+ }
430
+ /**
431
+ * Extract all logs from a call trace tree.
432
+ *
433
+ * @param call - The root call trace.
434
+ * @returns An array of logs.
435
+ */
436
+ function extractLogs(call) {
437
+ /* istanbul ignore next */
438
+ const logs = call.logs ?? [];
439
+ /* istanbul ignore next */
440
+ const nestedCalls = call.calls ?? [];
441
+ return [
442
+ ...logs,
443
+ ...nestedCalls.map((nestedCall) => extractLogs(nestedCall)).flat(),
444
+ ];
445
+ }
446
+ /**
447
+ * Extract all error messages from a call trace tree.
448
+ *
449
+ * @param call - The root call trace.
450
+ * @returns An array of error messages.
451
+ */
452
+ function extractCallTraceErrors(call) {
453
+ if (!call) {
454
+ return [];
455
+ }
456
+ const errors = call.error ? [call.error] : [];
457
+ const nestedCalls = call.calls ?? [];
458
+ const nestedErrors = nestedCalls.flatMap((nestedCall) => extractCallTraceErrors(nestedCall));
459
+ return [...errors, ...nestedErrors];
460
+ }
461
+ /**
462
+ * Build a `Revert` from the root call trace frame. Reads only the raw
463
+ * `output` hex and decodes it locally; the upstream `error` message string
464
+ * is never parsed. Only the root frame's output is considered, since
465
+ * nested frame errors may have been caught and recovered by their callers.
466
+ *
467
+ * @param call - The root call trace frame.
468
+ * @returns A `Revert` if the root frame reverted with output data,
469
+ * otherwise `undefined`.
470
+ */
471
+ function extractRootRevert(call) {
472
+ if (!call?.error) {
473
+ return undefined;
474
+ }
475
+ return (0, revert_reason_js_1.decodeRevert)(call.output, 'simulation');
476
+ }
477
+ /**
478
+ * Generate balance change data from previous and new balances.
479
+ *
480
+ * @param previousBalance - The previous balance.
481
+ * @param newBalance - The new balance.
482
+ * @param offset - Optional offset to apply to the new balance.
483
+ * @returns The balance change data or undefined if unchanged.
484
+ */
485
+ function getSimulationBalanceChange(previousBalance, newBalance, offset = 0) {
486
+ const newBalanceBN = (0, controller_utils_1.hexToBN)(newBalance).add(new bn_js_1.default(offset));
487
+ const previousBalanceBN = (0, controller_utils_1.hexToBN)(previousBalance);
488
+ const differenceBN = newBalanceBN.sub(previousBalanceBN);
489
+ const isDecrease = differenceBN.isNeg();
490
+ const difference = (0, controller_utils_1.toHex)(differenceBN.abs());
491
+ if (differenceBN.isZero()) {
492
+ log('Balance change is zero');
493
+ return undefined;
494
+ }
495
+ return {
496
+ previousBalance,
497
+ newBalance: (0, controller_utils_1.toHex)(newBalanceBN),
498
+ difference,
499
+ isDecrease,
500
+ };
501
+ }
502
+ /**
503
+ * Get the contract interfaces for all supported tokens.
504
+ *
505
+ * @returns A map of supported tokens to their contract interfaces.
506
+ */
507
+ function getContractInterfaces() {
508
+ const supportedTokens = Object.values(SupportedToken);
509
+ return new Map(supportedTokens.map((tokenType) => {
510
+ const { abi } = SUPPORTED_TOKEN_ABIS[tokenType];
511
+ const contractInterface = new abi_1.Interface(abi);
512
+ return [tokenType, contractInterface];
513
+ }));
514
+ }
515
+ /**
516
+ * Base request to simulation API.
517
+ *
518
+ * @param options - Options bag.
519
+ * @param options.after - Transactions to simulate after user's transaction.
520
+ * @param options.before - Transactions to simulate before user's transaction.
521
+ * @param options.params - Additional parameters for the request.
522
+ * @param options.request - Original request object.
523
+ * @returns The simulation response.
524
+ */
525
+ async function baseRequest({ request, params, before = [], after = [], }) {
526
+ const { blockTime, chainId, messenger, networkClientId, getSimulationConfig, txParams, } = request;
527
+ const { authorizationList } = txParams;
528
+ const from = txParams.from;
529
+ const authorizationListFinal = authorizationList?.map((authorization) => ({
530
+ address: authorization.address,
531
+ from,
532
+ }));
533
+ const userTransaction = {
534
+ authorizationList: authorizationListFinal,
535
+ data: txParams.data,
536
+ from: txParams.from,
537
+ gas: txParams.gas,
538
+ maxFeePerGas: (txParams.maxFeePerGas ?? txParams.gasPrice),
539
+ maxPriorityFeePerGas: (txParams.maxPriorityFeePerGas ??
540
+ txParams.gasPrice),
541
+ to: txParams.to,
542
+ value: txParams.value,
543
+ };
544
+ const transactions = [...before, userTransaction, ...after];
545
+ const requiredBalanceBN = getRequiredBalance(request);
546
+ const requiredBalanceHex = (0, controller_utils_1.toHex)(requiredBalanceBN);
547
+ log('Required balance', requiredBalanceHex);
548
+ const { balanceRaw } = await (0, balance_js_1.getNativeBalance)(from, messenger, networkClientId);
549
+ const currentBalanceHex = (0, controller_utils_1.toHex)(balanceRaw);
550
+ const currentBalanceBN = (0, controller_utils_1.hexToBN)(currentBalanceHex);
551
+ log('Current balance', currentBalanceHex);
552
+ const isInsufficientBalance = currentBalanceBN.lt(requiredBalanceBN);
553
+ return await (0, simulation_api_js_1.simulateTransactions)(chainId, {
554
+ ...params,
555
+ getSimulationConfig,
556
+ transactions,
557
+ withGas: true,
558
+ withDefaultBlockOverrides: true,
559
+ ...(blockTime && {
560
+ blockOverrides: {
561
+ ...params?.blockOverrides,
562
+ time: (0, controller_utils_1.toHex)(blockTime),
563
+ },
564
+ }),
565
+ ...(isInsufficientBalance && {
566
+ overrides: {
567
+ ...params?.overrides,
568
+ [from]: {
569
+ ...params?.overrides?.[from],
570
+ balance: requiredBalanceHex,
571
+ },
572
+ },
573
+ }),
574
+ });
575
+ }
576
+ /**
577
+ * Calculate the required minimum balance for a transaction.
578
+ *
579
+ * @param request - The transaction request.
580
+ * @returns The minimal balance as a BN.
581
+ */
582
+ function getRequiredBalance(request) {
583
+ const { txParams } = request;
584
+ const gasLimit = (0, controller_utils_1.hexToBN)(txParams.gas ?? '0x0');
585
+ const gasPrice = (0, controller_utils_1.hexToBN)(txParams.maxFeePerGas ?? txParams.gasPrice ?? '0x0');
586
+ const value = (0, controller_utils_1.hexToBN)(txParams.value ?? '0x0');
587
+ const nestedValue = (request.nestedTransactions ?? [])
588
+ .map((tx) => (0, controller_utils_1.hexToBN)(tx.value ?? '0x0'))
589
+ .reduce((acc, val) => acc.add(val), new bn_js_1.default(0));
590
+ return gasLimit.mul(gasPrice).add(value).add(nestedValue);
591
+ }
592
+ //# sourceMappingURL=balance-changes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance-changes.cjs","sourceRoot":"","sources":["../../src/utils/balance-changes.ts"],"names":[],"mappings":";;;;;;AACA,4CAA+C;AAC/C,iEAA4D;AAC5D,mEAA8E;AAE9E,2CAAqD;AAErD,kDAAuB;AAEvB,iEAAgE;AAShE,mDAGyB;AACzB,6CAIsB;AACtB,6CAA6C;AAY7C,2CAAsD;AACtD,8CAAgD;AAChD,0DAAkD;AAElD,IAAY,cAQX;AARD,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;IACnB,g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AC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjD,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC5D,CAAC","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 type { NetworkClientId } from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { simulateTransactions } from '../api/simulation-api.js';\nimport type {\n SimulationResponseLog,\n SimulationRequestTransaction,\n SimulationResponse,\n SimulationResponseCallTrace,\n SimulationResponseTransaction,\n SimulationRequest,\n} from '../api/simulation-api.js';\nimport {\n ABI_SIMULATION_ERC20_WRAPPED,\n ABI_SIMULATION_ERC721_LEGACY,\n} from '../constants.js';\nimport {\n SimulationError,\n SimulationInvalidResponseError,\n SimulationRevertedError,\n} from '../errors.js';\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n Revert,\n SimulationBalanceChange,\n SimulationData,\n SimulationTokenBalanceChange,\n SimulationToken,\n TransactionParams,\n NestedTransactionMetadata,\n GetSimulationConfig,\n} from '../types.js';\nimport { SimulationTokenStandard } from '../types.js';\nimport { getNativeBalance } from './balance.js';\nimport { decodeRevert } from './revert-reason.js';\n\nexport enum SupportedToken {\n ERC20 = 'erc20',\n ERC721 = 'erc721',\n ERC1155 = 'erc1155',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ERC20_WRAPPED = 'erc20Wrapped',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ERC721_LEGACY = 'erc721Legacy',\n}\n\ntype ABI = Fragment[];\n\nexport type GetBalanceChangesRequest = {\n blockTime?: number;\n chainId: Hex;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n getSimulationConfig: GetSimulationConfig;\n nestedTransactions?: NestedTransactionMetadata[];\n txParams: TransactionParams;\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, 'balance-changes');\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 *\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 * @param request.getSimulationConfig - Optional transaction simulation parameters.\n * @returns The simulation data.\n */\nexport async function getBalanceChanges(\n request: GetBalanceChangesRequest,\n): Promise<{\n simulationData: SimulationData;\n gasUsed?: Hex;\n simulationRevert?: Revert;\n}> {\n log('Request', request);\n\n let callTraceErrors: string[] | undefined;\n let simulationRevert: Revert | undefined;\n\n try {\n const response = await baseRequest({\n request,\n params: {\n withCallTrace: true,\n withLogs: true,\n },\n });\n\n const transactionResponse = response.transactions?.[0];\n callTraceErrors = extractCallTraceErrors(transactionResponse?.callTrace);\n simulationRevert = extractRootRevert(transactionResponse?.callTrace);\n const transactionError = transactionResponse?.error;\n\n if (transactionError) {\n throw new SimulationError(transactionError);\n }\n\n const nativeBalanceChange = getNativeBalanceChange(request, response);\n const events = getEvents(response);\n\n log('Parsed events', events);\n\n const tokenBalanceChanges = await getTokenBalanceChanges(request, events);\n\n const gasUsed = transactionResponse?.gasUsed;\n const simulationData = {\n callTraceErrors,\n nativeBalanceChange,\n tokenBalanceChanges,\n };\n\n return { simulationData, gasUsed, simulationRevert };\n } catch (error) {\n log('Failed to get balance changes', 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 simulationData: {\n callTraceErrors,\n tokenBalanceChanges: [],\n error: {\n code,\n message,\n },\n },\n gasUsed: undefined,\n simulationRevert,\n };\n }\n}\n\n/**\n * Extract the native balance change from a simulation response.\n *\n * @param request - Simulation request.\n * @param response - Simulation response.\n * @returns Native balance change or undefined if unchanged.\n */\nfunction getNativeBalanceChange(\n request: GetBalanceChangesRequest,\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 { txParams } = request;\n const userAddress = txParams.from as Hex;\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(\n previousBalance,\n newBalance,\n transactionResponse.gasCost,\n );\n}\n\n/**\n * Extract events from a simulation response.\n *\n * @param response - The simulation response.\n * @returns The parsed events.\n */\nfunction 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(\n (eventAbi) => eventAbi.name === event.name,\n )?.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((parsedEvent) => parsedEvent !== undefined) as ParsedEvent[];\n}\n\n/**\n * Normalize event arguments using ABI input definitions.\n *\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 *\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 *\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: GetBalanceChangesRequest,\n events: ParsedEvent[],\n): Promise<SimulationTokenBalanceChange[]> {\n const { txParams } = request;\n const from = txParams.from as Hex;\n const balanceTxs = getTokenBalanceTransactions(request, events);\n\n log('Generated balance transactions', [...balanceTxs.after.values()]);\n\n const transactionCount = balanceTxs.before.size + balanceTxs.after.size + 1;\n\n if (transactionCount === 1) {\n return [];\n }\n\n const response = await baseRequest({\n request,\n before: [...balanceTxs.before.values()],\n after: [...balanceTxs.after.values()],\n });\n\n log('Balance simulation response', response);\n\n if (response.transactions.length !== transactionCount) {\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 : getAmountFromBalanceTransactionResult(\n from,\n token,\n // eslint-disable-next-line no-plusplus\n response.transactions[prevBalanceTxIndex++],\n );\n\n const newBalance = getAmountFromBalanceTransactionResult(\n 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 *\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: GetBalanceChangesRequest,\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 const from = request.txParams.from as Hex;\n\n const userEvents = events.filter((event) =>\n [event.args.from, event.args.to].includes(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 from,\n tokenId,\n );\n\n const transaction: SimulationRequestTransaction = {\n 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 *\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 *\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 * Get the interface for a token standard.\n *\n * @param tokenStandard - The token standard.\n * @returns The interface for the token standard.\n */\nfunction getContractInterface(\n tokenStandard: SimulationTokenStandard,\n): Interface {\n switch (tokenStandard) {\n case SimulationTokenStandard.erc721:\n return new Interface(abiERC721);\n case SimulationTokenStandard.erc1155:\n return new Interface(abiERC1155);\n default:\n return new Interface(abiERC20);\n }\n}\n\n/**\n * Extract the value from a balance transaction response using the correct ABI.\n *\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 as Hex.\n */\nfunction getAmountFromBalanceTransactionResult(\n from: Hex,\n token: SimulationToken,\n response: SimulationResponseTransaction,\n): Hex {\n const contract = getContractInterface(token.standard);\n\n try {\n if (token.standard === SimulationTokenStandard.erc721) {\n const result = contract.decodeFunctionResult('ownerOf', response.return);\n const owner = result[0];\n return owner.toLowerCase() === from.toLowerCase() ? '0x1' : '0x0';\n }\n\n const result = contract.decodeFunctionResult('balanceOf', response.return);\n return toHex(result[0]);\n } catch (error) {\n log('Failed to decode balance transaction', error, { token, response });\n throw new SimulationError(\n `Failed to decode balance transaction for token ${\n token.address\n }: ${String(error)}`,\n );\n }\n}\n\n/**\n * Generate the balance transaction data for a token.\n *\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 const contract = getContractInterface(tokenStandard);\n switch (tokenStandard) {\n case SimulationTokenStandard.erc721:\n return contract.encodeFunctionData('ownerOf', [tokenId]) as Hex;\n\n case SimulationTokenStandard.erc1155:\n return contract.encodeFunctionData('balanceOf', [from, tokenId]) as Hex;\n\n default:\n return contract.encodeFunctionData('balanceOf', [from]) as Hex;\n }\n}\n\n/**\n * Parse a raw event log using known ABIs.\n *\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 {\n continue;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extract all logs from a call trace tree.\n *\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 * Extract all error messages from a call trace tree.\n *\n * @param call - The root call trace.\n * @returns An array of error messages.\n */\nfunction extractCallTraceErrors(call?: SimulationResponseCallTrace): string[] {\n if (!call) {\n return [];\n }\n\n const errors = call.error ? [call.error] : [];\n const nestedCalls = call.calls ?? [];\n const nestedErrors = nestedCalls.flatMap((nestedCall) =>\n extractCallTraceErrors(nestedCall),\n );\n\n return [...errors, ...nestedErrors];\n}\n\n/**\n * Build a `Revert` from the root call trace frame. Reads only the raw\n * `output` hex and decodes it locally; the upstream `error` message string\n * is never parsed. Only the root frame's output is considered, since\n * nested frame errors may have been caught and recovered by their callers.\n *\n * @param call - The root call trace frame.\n * @returns A `Revert` if the root frame reverted with output data,\n * otherwise `undefined`.\n */\nfunction extractRootRevert(\n call?: SimulationResponseCallTrace,\n): Revert | undefined {\n if (!call?.error) {\n return undefined;\n }\n return decodeRevert(call.output, 'simulation');\n}\n\n/**\n * Generate balance change data from previous and new balances.\n *\n * @param previousBalance - The previous balance.\n * @param newBalance - The new balance.\n * @param offset - Optional offset to apply to the new balance.\n * @returns The balance change data or undefined if unchanged.\n */\nfunction getSimulationBalanceChange(\n previousBalance: Hex,\n newBalance: Hex,\n offset: number = 0,\n): SimulationBalanceChange | undefined {\n const newBalanceBN = hexToBN(newBalance).add(new BN(offset));\n const previousBalanceBN = hexToBN(previousBalance);\n const differenceBN = newBalanceBN.sub(previousBalanceBN);\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: toHex(newBalanceBN),\n difference,\n isDecrease,\n };\n}\n\n/**\n * Get the contract interfaces for all supported tokens.\n *\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\n/**\n * Base request to simulation API.\n *\n * @param options - Options bag.\n * @param options.after - Transactions to simulate after user's transaction.\n * @param options.before - Transactions to simulate before user's transaction.\n * @param options.params - Additional parameters for the request.\n * @param options.request - Original request object.\n * @returns The simulation response.\n */\nasync function baseRequest({\n request,\n params,\n before = [],\n after = [],\n}: {\n request: GetBalanceChangesRequest;\n params?: Partial<SimulationRequest>;\n before?: SimulationRequestTransaction[];\n after?: SimulationRequestTransaction[];\n}): Promise<SimulationResponse> {\n const {\n blockTime,\n chainId,\n messenger,\n networkClientId,\n getSimulationConfig,\n txParams,\n } = request;\n const { authorizationList } = txParams;\n const from = txParams.from as Hex;\n\n const authorizationListFinal = authorizationList?.map((authorization) => ({\n address: authorization.address,\n from,\n }));\n\n const userTransaction: SimulationRequestTransaction = {\n authorizationList: authorizationListFinal,\n data: txParams.data as Hex,\n from: txParams.from as Hex,\n gas: txParams.gas as Hex,\n maxFeePerGas: (txParams.maxFeePerGas ?? txParams.gasPrice) as Hex,\n maxPriorityFeePerGas: (txParams.maxPriorityFeePerGas ??\n txParams.gasPrice) as Hex,\n to: txParams.to as Hex,\n value: txParams.value as Hex,\n };\n\n const transactions = [...before, userTransaction, ...after];\n const requiredBalanceBN = getRequiredBalance(request);\n const requiredBalanceHex = toHex(requiredBalanceBN);\n\n log('Required balance', requiredBalanceHex);\n\n const { balanceRaw } = await getNativeBalance(\n from,\n messenger,\n networkClientId,\n );\n const currentBalanceHex = toHex(balanceRaw);\n const currentBalanceBN = hexToBN(currentBalanceHex);\n\n log('Current balance', currentBalanceHex);\n\n const isInsufficientBalance = currentBalanceBN.lt(requiredBalanceBN);\n\n return await simulateTransactions(chainId, {\n ...params,\n getSimulationConfig,\n transactions,\n withGas: true,\n withDefaultBlockOverrides: true,\n ...(blockTime && {\n blockOverrides: {\n ...params?.blockOverrides,\n time: toHex(blockTime),\n },\n }),\n ...(isInsufficientBalance && {\n overrides: {\n ...params?.overrides,\n [from]: {\n ...params?.overrides?.[from],\n balance: requiredBalanceHex,\n },\n },\n }),\n });\n}\n\n/**\n * Calculate the required minimum balance for a transaction.\n *\n * @param request - The transaction request.\n * @returns The minimal balance as a BN.\n */\nfunction getRequiredBalance(request: GetBalanceChangesRequest): BN {\n const { txParams } = request;\n const gasLimit = hexToBN(txParams.gas ?? '0x0');\n const gasPrice = hexToBN(txParams.maxFeePerGas ?? txParams.gasPrice ?? '0x0');\n const value = hexToBN(txParams.value ?? '0x0');\n\n const nestedValue = (request.nestedTransactions ?? [])\n .map((tx) => hexToBN(tx.value ?? '0x0'))\n .reduce((acc, val) => acc.add(val), new BN(0));\n\n return gasLimit.mul(gasPrice).add(value).add(nestedValue);\n}\n"]}