@metamask-previews/transaction-controller 24.0.0-preview.d78968a2 → 24.0.0-preview.eb2135e

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 (275) hide show
  1. package/dist/TransactionController.js +38 -1908
  2. package/dist/TransactionController.js.map +1 -1
  3. package/dist/TransactionController.mjs +39 -0
  4. package/dist/TransactionController.mjs.map +1 -0
  5. package/dist/chunk-2K7J3EY3.mjs +170 -0
  6. package/dist/chunk-2K7J3EY3.mjs.map +1 -0
  7. package/dist/chunk-5XBULBP2.js +399 -0
  8. package/dist/chunk-5XBULBP2.js.map +1 -0
  9. package/dist/chunk-6MYNWYJK.mjs +158 -0
  10. package/dist/chunk-6MYNWYJK.mjs.map +1 -0
  11. package/dist/chunk-7APMBUKB.js +158 -0
  12. package/dist/chunk-7APMBUKB.js.map +1 -0
  13. package/dist/chunk-7LXE4KHV.js +40 -0
  14. package/dist/chunk-7LXE4KHV.js.map +1 -0
  15. package/dist/chunk-7MZ57ILQ.mjs +62 -0
  16. package/dist/chunk-7MZ57ILQ.mjs.map +1 -0
  17. package/dist/chunk-BJEESIBE.js +2313 -0
  18. package/dist/chunk-BJEESIBE.js.map +1 -0
  19. package/dist/chunk-C67QD5PV.mjs +320 -0
  20. package/dist/chunk-C67QD5PV.mjs.map +1 -0
  21. package/dist/chunk-DE3MZYVY.mjs +2313 -0
  22. package/dist/chunk-DE3MZYVY.mjs.map +1 -0
  23. package/dist/chunk-DEKM6PVG.mjs +46 -0
  24. package/dist/chunk-DEKM6PVG.mjs.map +1 -0
  25. package/dist/chunk-DQP6X25N.mjs +208 -0
  26. package/dist/chunk-DQP6X25N.mjs.map +1 -0
  27. package/dist/chunk-DTDTOMTB.js +238 -0
  28. package/dist/chunk-DTDTOMTB.js.map +1 -0
  29. package/dist/chunk-DTEDYRTL.js +242 -0
  30. package/dist/chunk-DTEDYRTL.js.map +1 -0
  31. package/dist/chunk-EQ3RRHB7.mjs +211 -0
  32. package/dist/chunk-EQ3RRHB7.mjs.map +1 -0
  33. package/dist/chunk-FDJPXQTF.js +46 -0
  34. package/dist/chunk-FDJPXQTF.js.map +1 -0
  35. package/dist/chunk-FRKQ3Z2L.mjs +40 -0
  36. package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
  37. package/dist/chunk-FS7FRO7B.mjs +90 -0
  38. package/dist/chunk-FS7FRO7B.mjs.map +1 -0
  39. package/dist/chunk-GKTIFXPN.js +170 -0
  40. package/dist/chunk-GKTIFXPN.js.map +1 -0
  41. package/dist/chunk-H4M66BA3.js +62 -0
  42. package/dist/chunk-H4M66BA3.js.map +1 -0
  43. package/dist/chunk-HPNXIKFY.js +76 -0
  44. package/dist/chunk-HPNXIKFY.js.map +1 -0
  45. package/dist/chunk-HS277C77.js +75 -0
  46. package/dist/chunk-HS277C77.js.map +1 -0
  47. package/dist/chunk-I5YZ7QUK.js +121 -0
  48. package/dist/chunk-I5YZ7QUK.js.map +1 -0
  49. package/dist/chunk-IC233ZQS.js +211 -0
  50. package/dist/chunk-IC233ZQS.js.map +1 -0
  51. package/dist/chunk-IUBAETUH.js +137 -0
  52. package/dist/chunk-IUBAETUH.js.map +1 -0
  53. package/dist/chunk-J56A7UCK.mjs +123 -0
  54. package/dist/chunk-J56A7UCK.mjs.map +1 -0
  55. package/dist/chunk-JR6HDRNV.mjs +242 -0
  56. package/dist/chunk-JR6HDRNV.mjs.map +1 -0
  57. package/dist/chunk-JRBREX22.mjs +75 -0
  58. package/dist/chunk-JRBREX22.mjs.map +1 -0
  59. package/dist/chunk-JRQHIBG5.mjs +399 -0
  60. package/dist/chunk-JRQHIBG5.mjs.map +1 -0
  61. package/dist/chunk-LM4NUNMT.mjs +76 -0
  62. package/dist/chunk-LM4NUNMT.mjs.map +1 -0
  63. package/dist/chunk-M7455RU7.js +320 -0
  64. package/dist/chunk-M7455RU7.js.map +1 -0
  65. package/dist/chunk-MHM5LRRF.mjs +122 -0
  66. package/dist/chunk-MHM5LRRF.mjs.map +1 -0
  67. package/dist/chunk-NHRBO3LU.mjs +50 -0
  68. package/dist/chunk-NHRBO3LU.mjs.map +1 -0
  69. package/dist/chunk-NM6OYEPP.mjs +182 -0
  70. package/dist/chunk-NM6OYEPP.mjs.map +1 -0
  71. package/dist/chunk-NUOBUW7C.js +85 -0
  72. package/dist/chunk-NUOBUW7C.js.map +1 -0
  73. package/dist/chunk-QP75SWIQ.js +53 -0
  74. package/dist/chunk-QP75SWIQ.js.map +1 -0
  75. package/dist/chunk-RI6MVJJN.js +122 -0
  76. package/dist/chunk-RI6MVJJN.js.map +1 -0
  77. package/dist/chunk-S6VGOPUY.js +14 -0
  78. package/dist/chunk-S6VGOPUY.js.map +1 -0
  79. package/dist/chunk-UGFBA4GV.js +123 -0
  80. package/dist/chunk-UGFBA4GV.js.map +1 -0
  81. package/dist/chunk-UKYY2RVS.mjs +137 -0
  82. package/dist/chunk-UKYY2RVS.mjs.map +1 -0
  83. package/dist/chunk-UM4ORJ5B.mjs +121 -0
  84. package/dist/chunk-UM4ORJ5B.mjs.map +1 -0
  85. package/dist/chunk-UQQWZT6C.mjs +14 -0
  86. package/dist/chunk-UQQWZT6C.mjs.map +1 -0
  87. package/dist/chunk-VH47Q6TS.js +182 -0
  88. package/dist/chunk-VH47Q6TS.js.map +1 -0
  89. package/dist/chunk-XGRAHX6T.mjs +53 -0
  90. package/dist/chunk-XGRAHX6T.mjs.map +1 -0
  91. package/dist/chunk-XUI43LEZ.mjs +30 -0
  92. package/dist/chunk-XUI43LEZ.mjs.map +1 -0
  93. package/dist/chunk-Y734U4V6.mjs +85 -0
  94. package/dist/chunk-Y734U4V6.mjs.map +1 -0
  95. package/dist/chunk-Y7ENNK7L.mjs +238 -0
  96. package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
  97. package/dist/chunk-Z4BLTVTB.js +30 -0
  98. package/dist/chunk-Z4BLTVTB.js.map +1 -0
  99. package/dist/chunk-ZCQRDZ36.js +208 -0
  100. package/dist/chunk-ZCQRDZ36.js.map +1 -0
  101. package/dist/chunk-ZJLZSFOZ.js +90 -0
  102. package/dist/chunk-ZJLZSFOZ.js.map +1 -0
  103. package/dist/chunk-ZNZEJDOE.js +50 -0
  104. package/dist/chunk-ZNZEJDOE.js.map +1 -0
  105. package/dist/constants.js +15 -110
  106. package/dist/constants.js.map +1 -1
  107. package/dist/constants.mjs +16 -0
  108. package/dist/constants.mjs.map +1 -0
  109. package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
  110. package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
  111. package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
  112. package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
  113. package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
  114. package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
  115. package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
  116. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
  117. package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
  118. package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
  119. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
  120. package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
  121. package/dist/helpers/GasFeePoller.js +10 -142
  122. package/dist/helpers/GasFeePoller.js.map +1 -1
  123. package/dist/helpers/GasFeePoller.mjs +11 -0
  124. package/dist/helpers/GasFeePoller.mjs.map +1 -0
  125. package/dist/helpers/IncomingTransactionHelper.js +8 -204
  126. package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
  127. package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
  128. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
  129. package/dist/helpers/MultichainTrackingHelper.js +12 -291
  130. package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
  131. package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
  132. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
  133. package/dist/helpers/PendingTransactionTracker.js +9 -357
  134. package/dist/helpers/PendingTransactionTracker.js.map +1 -1
  135. package/dist/helpers/PendingTransactionTracker.mjs +10 -0
  136. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
  137. package/dist/index.js +56 -20
  138. package/dist/index.js.map +1 -1
  139. package/dist/index.mjs +57 -0
  140. package/dist/index.mjs.map +1 -0
  141. package/dist/logger.js +11 -8
  142. package/dist/logger.js.map +1 -1
  143. package/dist/logger.mjs +12 -0
  144. package/dist/logger.mjs.map +1 -0
  145. package/dist/tsconfig.build.tsbuildinfo +1 -0
  146. package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +4 -1
  147. package/dist/types/TransactionController.d.ts.map +1 -0
  148. package/dist/{constants.d.ts → types/constants.d.ts} +5 -0
  149. package/dist/types/constants.d.ts.map +1 -0
  150. package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
  151. package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
  152. package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
  153. package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
  154. package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
  155. package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
  156. package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
  157. package/dist/types/index.d.ts.map +1 -0
  158. package/dist/types/logger.d.ts.map +1 -0
  159. package/dist/{types.d.ts → types/types.d.ts} +39 -0
  160. package/dist/types/types.d.ts.map +1 -0
  161. package/dist/types/utils/etherscan.d.ts.map +1 -0
  162. package/dist/types/utils/external-transactions.d.ts.map +1 -0
  163. package/dist/types/utils/gas-fees.d.ts.map +1 -0
  164. package/dist/types/utils/gas-flow.d.ts.map +1 -0
  165. package/dist/types/utils/gas.d.ts.map +1 -0
  166. package/dist/types/utils/history.d.ts.map +1 -0
  167. package/dist/types/utils/nonce.d.ts.map +1 -0
  168. package/dist/types/utils/simulation-api.d.ts +99 -0
  169. package/dist/types/utils/simulation-api.d.ts.map +1 -0
  170. package/dist/types/utils/simulation.d.ts +21 -0
  171. package/dist/types/utils/simulation.d.ts.map +1 -0
  172. package/dist/types/utils/swaps.d.ts.map +1 -0
  173. package/dist/types/utils/transaction-type.d.ts.map +1 -0
  174. package/dist/types/utils/utils.d.ts.map +1 -0
  175. package/dist/types/utils/validation.d.ts.map +1 -0
  176. package/dist/types.js +19 -170
  177. package/dist/types.js.map +1 -1
  178. package/dist/types.mjs +20 -0
  179. package/dist/types.mjs.map +1 -0
  180. package/dist/utils/etherscan.js +13 -118
  181. package/dist/utils/etherscan.js.map +1 -1
  182. package/dist/utils/etherscan.mjs +14 -0
  183. package/dist/utils/etherscan.mjs.map +1 -0
  184. package/dist/utils/external-transactions.js +8 -35
  185. package/dist/utils/external-transactions.js.map +1 -1
  186. package/dist/utils/external-transactions.mjs +9 -0
  187. package/dist/utils/external-transactions.mjs.map +1 -0
  188. package/dist/utils/gas-fees.js +15 -200
  189. package/dist/utils/gas-fees.js.map +1 -1
  190. package/dist/utils/gas-fees.mjs +16 -0
  191. package/dist/utils/gas-fees.mjs.map +1 -0
  192. package/dist/utils/gas-flow.js +10 -52
  193. package/dist/utils/gas-flow.js.map +1 -1
  194. package/dist/utils/gas-flow.mjs +11 -0
  195. package/dist/utils/gas-flow.mjs.map +1 -0
  196. package/dist/utils/gas.js +19 -133
  197. package/dist/utils/gas.js.map +1 -1
  198. package/dist/utils/gas.mjs +20 -0
  199. package/dist/utils/gas.mjs.map +1 -0
  200. package/dist/utils/history.js +9 -90
  201. package/dist/utils/history.js.map +1 -1
  202. package/dist/utils/history.mjs +10 -0
  203. package/dist/utils/history.mjs.map +1 -0
  204. package/dist/utils/nonce.js +10 -76
  205. package/dist/utils/nonce.js.map +1 -1
  206. package/dist/utils/nonce.mjs +11 -0
  207. package/dist/utils/nonce.mjs.map +1 -0
  208. package/dist/utils/simulation-api.js +10 -0
  209. package/dist/utils/simulation-api.js.map +1 -0
  210. package/dist/utils/simulation-api.mjs +10 -0
  211. package/dist/utils/simulation-api.mjs.map +1 -0
  212. package/dist/utils/simulation.js +12 -0
  213. package/dist/utils/simulation.js.map +1 -0
  214. package/dist/utils/simulation.mjs +12 -0
  215. package/dist/utils/simulation.mjs.map +1 -0
  216. package/dist/utils/swaps.js +23 -262
  217. package/dist/utils/swaps.js.map +1 -1
  218. package/dist/utils/swaps.mjs +24 -0
  219. package/dist/utils/swaps.mjs.map +1 -0
  220. package/dist/utils/transaction-type.js +10 -120
  221. package/dist/utils/transaction-type.js.map +1 -1
  222. package/dist/utils/transaction-type.mjs +11 -0
  223. package/dist/utils/transaction-type.mjs.map +1 -0
  224. package/dist/utils/utils.js +32 -175
  225. package/dist/utils/utils.js.map +1 -1
  226. package/dist/utils/utils.mjs +33 -0
  227. package/dist/utils/utils.mjs.map +1 -0
  228. package/dist/utils/validation.js +11 -258
  229. package/dist/utils/validation.js.map +1 -1
  230. package/dist/utils/validation.mjs +12 -0
  231. package/dist/utils/validation.mjs.map +1 -0
  232. package/package.json +12 -1
  233. package/dist/TransactionController.d.ts.map +0 -1
  234. package/dist/constants.d.ts.map +0 -1
  235. package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
  236. package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
  237. package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
  238. package/dist/helpers/GasFeePoller.d.ts.map +0 -1
  239. package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
  240. package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
  241. package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
  242. package/dist/index.d.ts.map +0 -1
  243. package/dist/logger.d.ts.map +0 -1
  244. package/dist/types.d.ts.map +0 -1
  245. package/dist/utils/etherscan.d.ts.map +0 -1
  246. package/dist/utils/external-transactions.d.ts.map +0 -1
  247. package/dist/utils/gas-fees.d.ts.map +0 -1
  248. package/dist/utils/gas-flow.d.ts.map +0 -1
  249. package/dist/utils/gas.d.ts.map +0 -1
  250. package/dist/utils/history.d.ts.map +0 -1
  251. package/dist/utils/nonce.d.ts.map +0 -1
  252. package/dist/utils/swaps.d.ts.map +0 -1
  253. package/dist/utils/transaction-type.d.ts.map +0 -1
  254. package/dist/utils/utils.d.ts.map +0 -1
  255. package/dist/utils/validation.d.ts.map +0 -1
  256. /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
  257. /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
  258. /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
  259. /package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +0 -0
  260. /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
  261. /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
  262. /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
  263. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  264. /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
  265. /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
  266. /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
  267. /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
  268. /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
  269. /package/dist/{utils → types/utils}/gas.d.ts +0 -0
  270. /package/dist/{utils → types/utils}/history.d.ts +0 -0
  271. /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
  272. /package/dist/{utils → types/utils}/swaps.d.ts +0 -0
  273. /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
  274. /package/dist/{utils → types/utils}/utils.d.ts +0 -0
  275. /package/dist/{utils → types/utils}/validation.d.ts +0 -0
@@ -1,91 +1,10 @@
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.updateTransactionHistory = exports.addInitialHistorySnapshot = void 0;
7
- const fast_json_patch_1 = __importDefault(require("fast-json-patch"));
8
- const lodash_1 = require("lodash");
9
- /**
10
- * Build a new version of the provided transaction with an initial history
11
- * entry, which is just a snapshot of the transaction.
12
- *
13
- * @param transactionMeta - TransactionMeta to add initial history snapshot to.
14
- * @returns A copy of `transactionMeta` with a new `history` property.
15
- */
16
- function addInitialHistorySnapshot(transactionMeta) {
17
- const snapshot = snapshotFromTransactionMeta(transactionMeta);
18
- return (0, lodash_1.merge)({}, transactionMeta, { history: [snapshot] });
19
- }
20
- exports.addInitialHistorySnapshot = addInitialHistorySnapshot;
21
- /**
22
- * Builds a new version of the transaction with a new history entry if
23
- * it has a `history` property, or just returns the transaction.
24
- *
25
- * @param transactionMeta - TransactionMeta to add history entry to.
26
- * @param note - Note to add to history entry.
27
- * @returns A copy of `transactionMeta` with a new `history` entry if it has an
28
- * existing non-empty `history` array.
29
- */
30
- function updateTransactionHistory(transactionMeta, note) {
31
- if (!transactionMeta.history) {
32
- return transactionMeta;
33
- }
34
- const currentState = snapshotFromTransactionMeta(transactionMeta);
35
- const previousState = replayHistory(transactionMeta.history);
36
- const historyEntry = generateHistoryEntry(previousState, currentState, note);
37
- if (historyEntry.length > 0) {
38
- return (0, lodash_1.merge)({}, transactionMeta, {
39
- history: [...transactionMeta.history, historyEntry],
40
- });
41
- }
42
- return transactionMeta;
43
- }
44
- exports.updateTransactionHistory = updateTransactionHistory;
45
- /**
46
- * Generates a history entry from the previous and new transaction metadata.
47
- *
48
- * @param previousState - The previous transaction metadata.
49
- * @param currentState - The new transaction metadata.
50
- * @param note - A note for the transaction metada update.
51
- * @returns An array of history operation.
52
- */
53
- function generateHistoryEntry(
54
- // TODO: Replace `any` with type
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- previousState, currentState, note) {
57
- const historyOperationsEntry = fast_json_patch_1.default.compare(previousState, currentState);
58
- // Add a note to the first operation, since it breaks if we append it to the entry
59
- if (historyOperationsEntry[0]) {
60
- if (note) {
61
- historyOperationsEntry[0].note = note;
62
- }
63
- historyOperationsEntry[0].timestamp = Date.now();
64
- }
65
- return historyOperationsEntry;
66
- }
67
- /**
68
- * Recovers previous transactionMeta from passed history array.
69
- *
70
- * @param transactionHistory - The transaction metadata to replay.
71
- * @returns The transaction metadata.
72
- */
73
- function replayHistory(transactionHistory) {
74
- const shortHistory = (0, lodash_1.cloneDeep)(transactionHistory);
75
- return shortHistory.reduce(
76
- // TODO: Replace `any` with type
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- (val, entry) => fast_json_patch_1.default.applyPatch(val, entry).newDocument);
79
- }
80
- /**
81
- * Clone the transaction meta data without the history property.
82
- *
83
- * @param transactionMeta - The transaction metadata to snapshot.
84
- * @returns A deep clone of transaction metadata without history property.
85
- */
86
- function snapshotFromTransactionMeta(transactionMeta) {
87
- const snapshot = Object.assign({}, transactionMeta);
88
- delete snapshot.history;
89
- return (0, lodash_1.cloneDeep)(snapshot);
90
- }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkQP75SWIQjs = require('../chunk-QP75SWIQ.js');
5
+ require('../chunk-Z4BLTVTB.js');
6
+
7
+
8
+
9
+ exports.addInitialHistorySnapshot = _chunkQP75SWIQjs.addInitialHistorySnapshot; exports.updateTransactionHistory = _chunkQP75SWIQjs.updateTransactionHistory;
91
10
  //# sourceMappingURL=history.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAyC;AACzC,mCAA0C;AAQ1C;;;;;;GAMG;AACH,SAAgB,yBAAyB,CACvC,eAAgC;IAEhC,MAAM,QAAQ,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;IAC9D,OAAO,IAAA,cAAK,EAAC,EA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A,kBAAS,EAAC,kBAAkB,CAAC,CAAC;IACnD,OAAO,YAAY,CAAC,MAAM;IACxB,gCAAgC;IAChC,8DAA8D;IAC9D,CAAC,GAAG,EAAE,KAAU,EAAE,EAAE,CAAC,yBAAU,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,WAAW,CAChD,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,eAAgC;IAEhC,MAAM,QAAQ,qBAAQ,eAAe,CAAE,CAAC;IACxC,OAAO,QAAQ,CAAC,OAAO,CAAC;IACxB,OAAO,IAAA,kBAAS,EAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import jsonDiffer from 'fast-json-patch';\nimport { cloneDeep, merge } from 'lodash';\n\nimport type {\n TransactionHistory,\n TransactionHistoryEntry,\n TransactionMeta,\n} from '../types';\n\n/**\n * Build a new version of the provided transaction with an initial history\n * entry, which is just a snapshot of the transaction.\n *\n * @param transactionMeta - TransactionMeta to add initial history snapshot to.\n * @returns A copy of `transactionMeta` with a new `history` property.\n */\nexport function addInitialHistorySnapshot(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = snapshotFromTransactionMeta(transactionMeta);\n return merge({}, transactionMeta, { history: [snapshot] });\n}\n\n/**\n * Builds a new version of the transaction with a new history entry if\n * it has a `history` property, or just returns the transaction.\n *\n * @param transactionMeta - TransactionMeta to add history entry to.\n * @param note - Note to add to history entry.\n * @returns A copy of `transactionMeta` with a new `history` entry if it has an\n * existing non-empty `history` array.\n */\nexport function updateTransactionHistory(\n transactionMeta: TransactionMeta,\n note: string,\n): TransactionMeta {\n if (!transactionMeta.history) {\n return transactionMeta;\n }\n\n const currentState = snapshotFromTransactionMeta(transactionMeta);\n const previousState = replayHistory(transactionMeta.history);\n const historyEntry = generateHistoryEntry(previousState, currentState, note);\n\n if (historyEntry.length > 0) {\n return merge({}, transactionMeta, {\n history: [...transactionMeta.history, historyEntry],\n });\n }\n return transactionMeta;\n}\n\n/**\n * Generates a history entry from the previous and new transaction metadata.\n *\n * @param previousState - The previous transaction metadata.\n * @param currentState - The new transaction metadata.\n * @param note - A note for the transaction metada update.\n * @returns An array of history operation.\n */\nfunction generateHistoryEntry(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n previousState: any,\n currentState: TransactionMeta,\n note: string,\n): TransactionHistoryEntry {\n const historyOperationsEntry = jsonDiffer.compare(\n previousState,\n currentState,\n ) as TransactionHistoryEntry;\n // Add a note to the first operation, since it breaks if we append it to the entry\n if (historyOperationsEntry[0]) {\n if (note) {\n historyOperationsEntry[0].note = note;\n }\n historyOperationsEntry[0].timestamp = Date.now();\n }\n return historyOperationsEntry;\n}\n\n/**\n * Recovers previous transactionMeta from passed history array.\n *\n * @param transactionHistory - The transaction metadata to replay.\n * @returns The transaction metadata.\n */\nfunction replayHistory(\n transactionHistory: TransactionHistory,\n): TransactionMeta {\n const shortHistory = cloneDeep(transactionHistory);\n return shortHistory.reduce(\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (val, entry: any) => jsonDiffer.applyPatch(val, entry).newDocument,\n ) as TransactionMeta;\n}\n\n/**\n * Clone the transaction meta data without the history property.\n *\n * @param transactionMeta - The transaction metadata to snapshot.\n * @returns A deep clone of transaction metadata without history property.\n */\nfunction snapshotFromTransactionMeta(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = { ...transactionMeta };\n delete snapshot.history;\n return cloneDeep(snapshot);\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import {
2
+ addInitialHistorySnapshot,
3
+ updateTransactionHistory
4
+ } from "../chunk-XGRAHX6T.mjs";
5
+ import "../chunk-XUI43LEZ.mjs";
6
+ export {
7
+ addInitialHistorySnapshot,
8
+ updateTransactionHistory
9
+ };
10
+ //# sourceMappingURL=history.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,77 +1,11 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getAndFormatTransactionsForNonceTracker = exports.getNextNonce = void 0;
13
- const controller_utils_1 = require("@metamask/controller-utils");
14
- const logger_1 = require("../logger");
15
- const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'nonce');
16
- /**
17
- * Determine the next nonce to be used for a transaction.
18
- *
19
- * @param txMeta - The transaction metadata.
20
- * @param getNonceLock - An anonymous function that acquires the nonce lock for an address
21
- * @returns The next hexadecimal nonce to be used for the given transaction, and optionally a function to release the nonce lock.
22
- */
23
- function getNextNonce(txMeta, getNonceLock) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const { customNonceValue, txParams: { from, nonce: existingNonce }, } = txMeta;
26
- const customNonce = customNonceValue ? (0, controller_utils_1.toHex)(customNonceValue) : undefined;
27
- if (customNonce) {
28
- log('Using custom nonce', customNonce);
29
- return [customNonce, undefined];
30
- }
31
- if (existingNonce) {
32
- log('Using existing nonce', existingNonce);
33
- return [existingNonce, undefined];
34
- }
35
- const nonceLock = yield getNonceLock(from);
36
- const nonce = (0, controller_utils_1.toHex)(nonceLock.nextNonce);
37
- const releaseLock = nonceLock.releaseLock.bind(nonceLock);
38
- log('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);
39
- return [nonce, releaseLock];
40
- });
41
- }
42
- exports.getNextNonce = getNextNonce;
43
- /**
44
- * Filter and format transactions for the nonce tracker.
45
- *
46
- * @param currentChainId - Chain ID of the current network.
47
- * @param fromAddress - Address of the account from which the transactions to filter from are sent.
48
- * @param transactionStatus - Status of the transactions for which to filter.
49
- * @param transactions - Array of transactionMeta objects that have been prefiltered.
50
- * @returns Array of transactions formatted for the nonce tracker.
51
- */
52
- function getAndFormatTransactionsForNonceTracker(currentChainId, fromAddress, transactionStatus, transactions) {
53
- return transactions
54
- .filter(({ chainId, isTransfer, isUserOperation, status, txParams: { from } }) => !isTransfer &&
55
- !isUserOperation &&
56
- chainId === currentChainId &&
57
- status === transactionStatus &&
58
- from.toLowerCase() === fromAddress.toLowerCase())
59
- .map(({ status, txParams: { from, gas, value, nonce } }) => {
60
- // the only value we care about is the nonce
61
- // but we need to return the other values to satisfy the type
62
- // TODO: refactor nonceTracker to not require this
63
- /* istanbul ignore next */
64
- return {
65
- status,
66
- history: [{}],
67
- txParams: {
68
- from: from !== null && from !== void 0 ? from : '',
69
- gas: gas !== null && gas !== void 0 ? gas : '',
70
- value: value !== null && value !== void 0 ? value : '',
71
- nonce: nonce !== null && nonce !== void 0 ? nonce : '',
72
- },
73
- };
74
- });
75
- }
76
- exports.getAndFormatTransactionsForNonceTracker = getAndFormatTransactionsForNonceTracker;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkZNZEJDOEjs = require('../chunk-ZNZEJDOE.js');
5
+ require('../chunk-S6VGOPUY.js');
6
+ require('../chunk-Z4BLTVTB.js');
7
+
8
+
9
+
10
+ exports.getAndFormatTransactionsForNonceTracker = _chunkZNZEJDOEjs.getAndFormatTransactionsForNonceTracker; exports.getNextNonce = _chunkZNZEJDOEjs.getNextNonce;
77
11
  //# sourceMappingURL=nonce.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nonce.js","sourceRoot":"","sources":["../../src/utils/nonce.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAmD;AAMnD,sC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AE,EAAE,CACvE,CAAC,UAAU;QACX,CAAC,eAAe;QAChB,OAAO,KAAK,cAAc;QAC1B,MAAM,KAAK,iBAAiB;QAC5B,IAAI,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CACnD;SACA,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;QACzD,4CAA4C;QAC5C,6DAA6D;QAC7D,kDAAkD;QAClD,0BAA0B;QAC1B,OAAO;YACL,MAAM;YACN,OAAO,EAAE,CAAC,EAAE,CAAC;YACb,QAAQ,EAAE;gBACR,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE;gBAChB,GAAG,EAAE,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,EAAE;gBACd,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE;gBAClB,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE;aACnB;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC;AA/BD,0FA+BC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type {\n NonceLock,\n Transaction as NonceTrackerTransaction,\n} from 'nonce-tracker';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionMeta, TransactionStatus } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'nonce');\n\n/**\n * Determine the next nonce to be used for a transaction.\n *\n * @param txMeta - The transaction metadata.\n * @param getNonceLock - An anonymous function that acquires the nonce lock for an address\n * @returns The next hexadecimal nonce to be used for the given transaction, and optionally a function to release the nonce lock.\n */\nexport async function getNextNonce(\n txMeta: TransactionMeta,\n getNonceLock: (address: string) => Promise<NonceLock>,\n): Promise<[string, (() => void) | undefined]> {\n const {\n customNonceValue,\n txParams: { from, nonce: existingNonce },\n } = txMeta;\n\n const customNonce = customNonceValue ? toHex(customNonceValue) : undefined;\n\n if (customNonce) {\n log('Using custom nonce', customNonce);\n return [customNonce, undefined];\n }\n\n if (existingNonce) {\n log('Using existing nonce', existingNonce);\n return [existingNonce, undefined];\n }\n\n const nonceLock = await getNonceLock(from);\n const nonce = toHex(nonceLock.nextNonce);\n const releaseLock = nonceLock.releaseLock.bind(nonceLock);\n\n log('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);\n\n return [nonce, releaseLock];\n}\n\n/**\n * Filter and format transactions for the nonce tracker.\n *\n * @param currentChainId - Chain ID of the current network.\n * @param fromAddress - Address of the account from which the transactions to filter from are sent.\n * @param transactionStatus - Status of the transactions for which to filter.\n * @param transactions - Array of transactionMeta objects that have been prefiltered.\n * @returns Array of transactions formatted for the nonce tracker.\n */\nexport function getAndFormatTransactionsForNonceTracker(\n currentChainId: string,\n fromAddress: string,\n transactionStatus: TransactionStatus,\n transactions: TransactionMeta[],\n): NonceTrackerTransaction[] {\n return transactions\n .filter(\n ({ chainId, isTransfer, isUserOperation, status, txParams: { from } }) =>\n !isTransfer &&\n !isUserOperation &&\n chainId === currentChainId &&\n status === transactionStatus &&\n from.toLowerCase() === fromAddress.toLowerCase(),\n )\n .map(({ status, txParams: { from, gas, value, nonce } }) => {\n // the only value we care about is the nonce\n // but we need to return the other values to satisfy the type\n // TODO: refactor nonceTracker to not require this\n /* istanbul ignore next */\n return {\n status,\n history: [{}],\n txParams: {\n from: from ?? '',\n gas: gas ?? '',\n value: value ?? '',\n nonce: nonce ?? '',\n },\n };\n });\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import {
2
+ getAndFormatTransactionsForNonceTracker,
3
+ getNextNonce
4
+ } from "../chunk-NHRBO3LU.mjs";
5
+ import "../chunk-UQQWZT6C.mjs";
6
+ import "../chunk-XUI43LEZ.mjs";
7
+ export {
8
+ getAndFormatTransactionsForNonceTracker,
9
+ getNextNonce
10
+ };
11
+ //# sourceMappingURL=nonce.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkFDJPXQTFjs = require('../chunk-FDJPXQTF.js');
4
+ require('../chunk-RI6MVJJN.js');
5
+ require('../chunk-S6VGOPUY.js');
6
+ require('../chunk-Z4BLTVTB.js');
7
+
8
+
9
+ exports.simulateTransactions = _chunkFDJPXQTFjs.simulateTransactions;
10
+ //# sourceMappingURL=simulation-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import {
2
+ simulateTransactions
3
+ } from "../chunk-DEKM6PVG.mjs";
4
+ import "../chunk-MHM5LRRF.mjs";
5
+ import "../chunk-UQQWZT6C.mjs";
6
+ import "../chunk-XUI43LEZ.mjs";
7
+ export {
8
+ simulateTransactions
9
+ };
10
+ //# sourceMappingURL=simulation-api.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkDTEDYRTLjs = require('../chunk-DTEDYRTL.js');
4
+ require('../chunk-FDJPXQTF.js');
5
+ require('../chunk-RI6MVJJN.js');
6
+ require('../chunk-S6VGOPUY.js');
7
+ require('../chunk-HPNXIKFY.js');
8
+ require('../chunk-Z4BLTVTB.js');
9
+
10
+
11
+ exports.getSimulationData = _chunkDTEDYRTLjs.getSimulationData;
12
+ //# sourceMappingURL=simulation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import {
2
+ getSimulationData
3
+ } from "../chunk-JR6HDRNV.mjs";
4
+ import "../chunk-DEKM6PVG.mjs";
5
+ import "../chunk-MHM5LRRF.mjs";
6
+ import "../chunk-UQQWZT6C.mjs";
7
+ import "../chunk-LM4NUNMT.mjs";
8
+ import "../chunk-XUI43LEZ.mjs";
9
+ export {
10
+ getSimulationData
11
+ };
12
+ //# sourceMappingURL=simulation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,263 +1,24 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.updatePostTransactionBalance = exports.updateSwapsTransaction = exports.SWAP_TRANSACTION_TYPES = exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP = exports.DEFAULT_TOKEN_ADDRESS = exports.UPDATE_POST_TX_BALANCE_ATTEMPTS = exports.UPDATE_POST_TX_BALANCE_TIMEOUT = void 0;
13
- const controller_utils_1 = require("@metamask/controller-utils");
14
- const lodash_1 = require("lodash");
15
- const constants_1 = require("../constants");
16
- const logger_1 = require("../logger");
17
- const types_1 = require("../types");
18
- const utils_1 = require("./utils");
19
- const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'swaps');
20
- /**
21
- * Interval in milliseconds between checks of post transaction balance
22
- */
23
- exports.UPDATE_POST_TX_BALANCE_TIMEOUT = 5000;
24
- /**
25
- * Retry attempts for checking post transaction balance
26
- */
27
- exports.UPDATE_POST_TX_BALANCE_ATTEMPTS = 6;
28
- const SWAPS_TESTNET_CHAIN_ID = '0x539';
29
- /**
30
- * An address that the metaswap-api recognizes as the default token for the current network, in place of the token address that ERC-20 tokens have
31
- */
32
- exports.DEFAULT_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000000';
33
- const ETH_SWAPS_TOKEN_OBJECT = {
34
- name: 'Ether',
35
- address: exports.DEFAULT_TOKEN_ADDRESS,
36
- decimals: 18,
37
- };
38
- const BNB_SWAPS_TOKEN_OBJECT = {
39
- name: 'Binance Coin',
40
- address: exports.DEFAULT_TOKEN_ADDRESS,
41
- decimals: 18,
42
- };
43
- const MATIC_SWAPS_TOKEN_OBJECT = {
44
- name: 'Matic',
45
- address: exports.DEFAULT_TOKEN_ADDRESS,
46
- decimals: 18,
47
- };
48
- const AVAX_SWAPS_TOKEN_OBJECT = {
49
- name: 'Avalanche',
50
- address: exports.DEFAULT_TOKEN_ADDRESS,
51
- decimals: 18,
52
- };
53
- const TEST_ETH_SWAPS_TOKEN_OBJECT = {
54
- name: 'Test Ether',
55
- address: exports.DEFAULT_TOKEN_ADDRESS,
56
- decimals: 18,
57
- };
58
- const GOERLI_SWAPS_TOKEN_OBJECT = {
59
- name: 'Ether',
60
- address: exports.DEFAULT_TOKEN_ADDRESS,
61
- decimals: 18,
62
- };
63
- const ARBITRUM_SWAPS_TOKEN_OBJECT = Object.assign({}, ETH_SWAPS_TOKEN_OBJECT);
64
- const OPTIMISM_SWAPS_TOKEN_OBJECT = Object.assign({}, ETH_SWAPS_TOKEN_OBJECT);
65
- const ZKSYNC_ERA_SWAPS_TOKEN_OBJECT = Object.assign({}, ETH_SWAPS_TOKEN_OBJECT);
66
- exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {
67
- [constants_1.CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,
68
- [SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,
69
- [constants_1.CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,
70
- [constants_1.CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,
71
- [constants_1.CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,
72
- [constants_1.CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,
73
- [constants_1.CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,
74
- [constants_1.CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,
75
- [constants_1.CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT,
76
- };
77
- exports.SWAP_TRANSACTION_TYPES = [
78
- types_1.TransactionType.swap,
79
- types_1.TransactionType.swapApproval,
80
- ];
81
- /**
82
- * Updates the transaction meta object with the swap information
83
- *
84
- * @param transactionMeta - The transaction meta object to update
85
- * @param transactionType - The type of the transaction
86
- * @param swaps - The swaps object
87
- * @param swaps.hasApproveTx - Whether the swap has an approval transaction
88
- * @param swaps.meta - The swap meta object
89
- * @param updateSwapsTransactionRequest - Dependency bag
90
- * @param updateSwapsTransactionRequest.isSwapsDisabled - Whether swaps are disabled
91
- * @param updateSwapsTransactionRequest.cancelTransaction - Function to cancel a transaction
92
- * @param updateSwapsTransactionRequest.messenger - TransactionController messenger
93
- * @returns A copy of the transaction meta object with updates, or the same
94
- * transaction meta object if no updates were made.
95
- */
96
- function updateSwapsTransaction(transactionMeta, transactionType, swaps, { isSwapsDisabled, cancelTransaction, messenger, }) {
97
- if (isSwapsDisabled || !exports.SWAP_TRANSACTION_TYPES.includes(transactionType)) {
98
- return transactionMeta;
99
- }
100
- // The simulationFails property is added if the estimateGas call fails. In cases
101
- // when no swaps approval tx is required, this indicates that the swap will likely
102
- // fail. There was an earlier estimateGas call made by the swaps controller,
103
- // but it is possible that external conditions have change since then, and
104
- // a previously succeeding estimate gas call could now fail. By checking for
105
- // the `simulationFails` property here, we can reduce the number of swap
106
- // transactions that get published to the blockchain only to fail and thereby
107
- // waste the user's funds on gas.
108
- if (transactionType === types_1.TransactionType.swap &&
109
- (swaps === null || swaps === void 0 ? void 0 : swaps.hasApproveTx) === false &&
110
- transactionMeta.simulationFails) {
111
- cancelTransaction(transactionMeta.id);
112
- throw new Error('Simulation failed');
113
- }
114
- const swapsMeta = swaps === null || swaps === void 0 ? void 0 : swaps.meta;
115
- if (!swapsMeta) {
116
- return transactionMeta;
117
- }
118
- let updatedTransactionMeta = transactionMeta;
119
- if (transactionType === types_1.TransactionType.swapApproval) {
120
- updatedTransactionMeta = updateSwapApprovalTransaction(transactionMeta, swapsMeta);
121
- messenger.publish('TransactionController:transactionNewSwapApproval', {
122
- transactionMeta: updatedTransactionMeta,
123
- });
124
- }
125
- if (transactionType === types_1.TransactionType.swap) {
126
- updatedTransactionMeta = updateSwapTransaction(transactionMeta, swapsMeta);
127
- messenger.publish('TransactionController:transactionNewSwap', {
128
- transactionMeta: updatedTransactionMeta,
129
- });
130
- }
131
- return updatedTransactionMeta;
132
- }
133
- exports.updateSwapsTransaction = updateSwapsTransaction;
134
- /**
135
- * Attempts to update the post transaction balance of the provided transaction
136
- *
137
- * @param transactionMeta - Transaction meta object to update
138
- * @param updatePostTransactionBalanceRequest - Dependency bag
139
- * @param updatePostTransactionBalanceRequest.ethQuery - EthQuery object
140
- * @param updatePostTransactionBalanceRequest.getTransaction - Reading function for the latest transaction state
141
- * @param updatePostTransactionBalanceRequest.updateTransaction - Updating transaction function
142
- */
143
- function updatePostTransactionBalance(transactionMeta, { ethQuery, getTransaction, updateTransaction, }) {
144
- var _a;
145
- return __awaiter(this, void 0, void 0, function* () {
146
- log('Updating post transaction balance', transactionMeta.id);
147
- const transactionId = transactionMeta.id;
148
- let latestTransactionMeta;
149
- let approvalTransactionMeta;
150
- for (let i = 0; i < exports.UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {
151
- log('Querying balance', { attempt: i });
152
- const postTransactionBalance = yield (0, controller_utils_1.query)(ethQuery, 'getBalance', [
153
- transactionMeta.txParams.from,
154
- ]);
155
- latestTransactionMeta = Object.assign({}, ((_a = getTransaction(transactionId)) !== null && _a !== void 0 ? _a : {}));
156
- approvalTransactionMeta = latestTransactionMeta.approvalTxId
157
- ? getTransaction(latestTransactionMeta.approvalTxId)
158
- : undefined;
159
- latestTransactionMeta.postTxBalance = postTransactionBalance.toString(16);
160
- const isDefaultTokenAddress = isSwapsDefaultTokenAddress(transactionMeta.destinationTokenAddress, transactionMeta.chainId);
161
- if (!isDefaultTokenAddress ||
162
- transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance) {
163
- log('Finishing post balance update', {
164
- isDefaultTokenAddress,
165
- preTxBalance: transactionMeta.preTxBalance,
166
- postTxBalance: latestTransactionMeta.postTxBalance,
167
- });
168
- break;
169
- }
170
- log('Waiting for balance to update', {
171
- delay: exports.UPDATE_POST_TX_BALANCE_TIMEOUT,
172
- });
173
- yield sleep(exports.UPDATE_POST_TX_BALANCE_TIMEOUT);
174
- }
175
- updateTransaction(latestTransactionMeta, 'TransactionController#updatePostTransactionBalance - Add post transaction balance');
176
- log('Completed post balance update', latestTransactionMeta === null || latestTransactionMeta === void 0 ? void 0 : latestTransactionMeta.postTxBalance);
177
- return {
178
- updatedTransactionMeta: latestTransactionMeta,
179
- approvalTransactionMeta,
180
- };
181
- });
182
- }
183
- exports.updatePostTransactionBalance = updatePostTransactionBalance;
184
- /**
185
- * Updates the transaction meta object with the swap information
186
- *
187
- * @param transactionMeta - Transaction meta object to update
188
- * @param propsToUpdate - Properties to update
189
- * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped
190
- * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received
191
- * @param propsToUpdate.type - Type of the transaction
192
- * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received
193
- * @param propsToUpdate.destinationTokenAddress - Address of the token to be received
194
- * @param propsToUpdate.swapMetaData - Metadata of the swap
195
- * @param propsToUpdate.swapTokenValue - Value of the token to be swapped
196
- * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction
197
- * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction
198
- * @returns The updated transaction meta object.
199
- */
200
- function updateSwapTransaction(transactionMeta, { sourceTokenSymbol, destinationTokenSymbol, type, destinationTokenDecimals, destinationTokenAddress, swapMetaData, swapTokenValue, estimatedBaseFee, approvalTxId, }) {
201
- (0, utils_1.validateIfTransactionUnapproved)(transactionMeta, 'updateSwapTransaction');
202
- let swapTransaction = {
203
- sourceTokenSymbol,
204
- destinationTokenSymbol,
205
- type,
206
- destinationTokenDecimals,
207
- destinationTokenAddress,
208
- swapMetaData,
209
- swapTokenValue,
210
- estimatedBaseFee,
211
- approvalTxId,
212
- };
213
- // TODO: Replace `any` with type
214
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
- swapTransaction = (0, lodash_1.pickBy)(swapTransaction);
216
- return (0, lodash_1.merge)({}, transactionMeta, swapTransaction);
217
- }
218
- /**
219
- * Updates the transaction meta object with the swap approval information
220
- *
221
- * @param transactionMeta - Transaction meta object to update
222
- * @param propsToUpdate - Properties to update
223
- * @param propsToUpdate.type - Type of the transaction
224
- * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped
225
- * @returns The updated transaction meta object.
226
- */
227
- function updateSwapApprovalTransaction(transactionMeta, { type, sourceTokenSymbol }) {
228
- (0, utils_1.validateIfTransactionUnapproved)(transactionMeta, 'updateSwapApprovalTransaction');
229
- // TODO: Replace `any` with type
230
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
- let swapApprovalTransaction = { type, sourceTokenSymbol };
232
- swapApprovalTransaction = (0, lodash_1.pickBy)({
233
- type,
234
- sourceTokenSymbol,
235
- });
236
- return (0, lodash_1.merge)({}, transactionMeta, swapApprovalTransaction);
237
- }
238
- /**
239
- * Checks whether the provided address is strictly equal to the address for
240
- * the default swaps token of the provided chain.
241
- *
242
- * @param address - The string to compare to the default token address
243
- * @param chainId - The hex encoded chain ID of the default swaps token to check
244
- * @returns Whether the address is the provided chain's default token address
245
- */
246
- function isSwapsDefaultTokenAddress(address, chainId) {
247
- var _a;
248
- if (!address || !chainId) {
249
- return false;
250
- }
251
- return (address ===
252
- ((_a = exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId]) === null || _a === void 0 ? void 0 : _a.address));
253
- }
254
- /**
255
- * Sleeps for the provided number of milliseconds
256
- *
257
- * @param ms - Number of milliseconds to sleep
258
- * @returns Promise that resolves after the provided number of milliseconds
259
- */
260
- function sleep(ms) {
261
- return new Promise((resolve) => setTimeout(resolve, ms));
262
- }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkIC233ZQSjs = require('../chunk-IC233ZQS.js');
10
+ require('../chunk-UGFBA4GV.js');
11
+ require('../chunk-RI6MVJJN.js');
12
+ require('../chunk-S6VGOPUY.js');
13
+ require('../chunk-HPNXIKFY.js');
14
+ require('../chunk-Z4BLTVTB.js');
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+ exports.DEFAULT_TOKEN_ADDRESS = _chunkIC233ZQSjs.DEFAULT_TOKEN_ADDRESS; exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP = _chunkIC233ZQSjs.SWAPS_CHAINID_DEFAULT_TOKEN_MAP; exports.SWAP_TRANSACTION_TYPES = _chunkIC233ZQSjs.SWAP_TRANSACTION_TYPES; exports.UPDATE_POST_TX_BALANCE_ATTEMPTS = _chunkIC233ZQSjs.UPDATE_POST_TX_BALANCE_ATTEMPTS; exports.UPDATE_POST_TX_BALANCE_TIMEOUT = _chunkIC233ZQSjs.UPDATE_POST_TX_BALANCE_TIMEOUT; exports.updatePostTransactionBalance = _chunkIC233ZQSjs.updatePostTransactionBalance; exports.updateSwapsTransaction = _chunkIC233ZQSjs.updateSwapsTransaction;
263
24
  //# sourceMappingURL=swaps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"swaps.js","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAmD;AAEnD,m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sB;QACtB,IAAI;QACJ,wBAAwB;QACxB,uBAAuB;QACvB,YAAY;QACZ,cAAc;QACd,gBAAgB;QAChB,YAAY;KACb,CAAC;IACF,gCAAgC;IAChC,8DAA8D;IAC9D,eAAe,GAAG,IAAA,eAAM,EAAC,eAAe,CAAQ,CAAC;IAEjD,OAAO,IAAA,cAAK,EAAC,EAAE,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,6BAA6B,CACpC,eAAgC,EAChC,EAAE,IAAI,EAAE,iBAAiB,EAA4B;IAErD,IAAA,uCAA+B,EAC7B,eAAe,EACf,+BAA+B,CAChC,CAAC;IAEF,gCAAgC;IAChC,8DAA8D;IAC9D,IAAI,uBAAuB,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAS,CAAC;IACjE,uBAAuB,GAAG,IAAA,eAAM,EAAC;QAC/B,IAAI;QACJ,iBAAiB;KAClB,CAA6B,CAAC;IAE/B,OAAO,IAAA,cAAK,EAAC,EAAE,EAAE,eAAe,EAAE,uBAAuB,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,0BAA0B,CAAC,OAAe,EAAE,OAAe;;IAClE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CACL,OAAO;SACP,MAAA,uCAA+B,CAC7B,OAAuD,CACxD,0CAAE,OAAO,CAAA,CACX,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { merge, pickBy } from 'lodash';\n\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\nimport { TransactionType } from '../types';\nimport { validateIfTransactionUnapproved } from './utils';\n\nconst log = createModuleLogger(projectLogger, 'swaps');\n\n/**\n * Interval in milliseconds between checks of post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_TIMEOUT = 5000;\n\n/**\n * Retry attempts for checking post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_ATTEMPTS = 6;\n\nconst SWAPS_TESTNET_CHAIN_ID = '0x539';\n\n/**\n * An address that the metaswap-api recognizes as the default token for the current network, in place of the token address that ERC-20 tokens have\n */\nexport const DEFAULT_TOKEN_ADDRESS =\n '0x0000000000000000000000000000000000000000';\n\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface SwapsTokenObject {\n /**\n * The name for the network\n */\n name: string;\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string;\n /**\n * Number of digits after decimal point\n */\n decimals: number;\n}\n\nconst ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n};\n\nconst BNB_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Binance Coin',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst MATIC_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Matic',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst AVAX_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Avalanche',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst TEST_ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Test Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst GOERLI_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst ARBITRUM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst OPTIMISM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst ZKSYNC_ERA_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {\n [CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,\n [SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAP_TRANSACTION_TYPES = [\n TransactionType.swap,\n TransactionType.swapApproval,\n];\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - The transaction meta object to update\n * @param transactionType - The type of the transaction\n * @param swaps - The swaps object\n * @param swaps.hasApproveTx - Whether the swap has an approval transaction\n * @param swaps.meta - The swap meta object\n * @param updateSwapsTransactionRequest - Dependency bag\n * @param updateSwapsTransactionRequest.isSwapsDisabled - Whether swaps are disabled\n * @param updateSwapsTransactionRequest.cancelTransaction - Function to cancel a transaction\n * @param updateSwapsTransactionRequest.messenger - TransactionController messenger\n * @returns A copy of the transaction meta object with updates, or the same\n * transaction meta object if no updates were made.\n */\nexport function updateSwapsTransaction(\n transactionMeta: TransactionMeta,\n transactionType: TransactionType,\n swaps: {\n hasApproveTx?: boolean;\n meta?: Partial<TransactionMeta>;\n },\n {\n isSwapsDisabled,\n cancelTransaction,\n messenger,\n }: {\n isSwapsDisabled: boolean;\n cancelTransaction: (transactionId: string) => void;\n messenger: TransactionControllerMessenger;\n },\n): TransactionMeta {\n if (isSwapsDisabled || !SWAP_TRANSACTION_TYPES.includes(transactionType)) {\n return transactionMeta;\n }\n\n // The simulationFails property is added if the estimateGas call fails. In cases\n // when no swaps approval tx is required, this indicates that the swap will likely\n // fail. There was an earlier estimateGas call made by the swaps controller,\n // but it is possible that external conditions have change since then, and\n // a previously succeeding estimate gas call could now fail. By checking for\n // the `simulationFails` property here, we can reduce the number of swap\n // transactions that get published to the blockchain only to fail and thereby\n // waste the user's funds on gas.\n if (\n transactionType === TransactionType.swap &&\n swaps?.hasApproveTx === false &&\n transactionMeta.simulationFails\n ) {\n cancelTransaction(transactionMeta.id);\n throw new Error('Simulation failed');\n }\n\n const swapsMeta = swaps?.meta as Partial<TransactionMeta>;\n\n if (!swapsMeta) {\n return transactionMeta;\n }\n\n let updatedTransactionMeta = transactionMeta;\n\n if (transactionType === TransactionType.swapApproval) {\n updatedTransactionMeta = updateSwapApprovalTransaction(\n transactionMeta,\n swapsMeta,\n );\n messenger.publish('TransactionController:transactionNewSwapApproval', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swap) {\n updatedTransactionMeta = updateSwapTransaction(transactionMeta, swapsMeta);\n messenger.publish('TransactionController:transactionNewSwap', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n return updatedTransactionMeta;\n}\n\n/**\n * Attempts to update the post transaction balance of the provided transaction\n *\n * @param transactionMeta - Transaction meta object to update\n * @param updatePostTransactionBalanceRequest - Dependency bag\n * @param updatePostTransactionBalanceRequest.ethQuery - EthQuery object\n * @param updatePostTransactionBalanceRequest.getTransaction - Reading function for the latest transaction state\n * @param updatePostTransactionBalanceRequest.updateTransaction - Updating transaction function\n */\nexport async function updatePostTransactionBalance(\n transactionMeta: TransactionMeta,\n {\n ethQuery,\n getTransaction,\n updateTransaction,\n }: {\n ethQuery: EthQuery;\n getTransaction: (transactionId: string) => TransactionMeta | undefined;\n updateTransaction: (transactionMeta: TransactionMeta, note: string) => void;\n },\n): Promise<{\n updatedTransactionMeta: TransactionMeta;\n approvalTransactionMeta?: TransactionMeta;\n}> {\n log('Updating post transaction balance', transactionMeta.id);\n\n const transactionId = transactionMeta.id;\n let latestTransactionMeta: TransactionMeta | undefined;\n let approvalTransactionMeta;\n\n for (let i = 0; i < UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {\n log('Querying balance', { attempt: i });\n\n const postTransactionBalance = await query(ethQuery, 'getBalance', [\n transactionMeta.txParams.from,\n ]);\n\n latestTransactionMeta = {\n ...(getTransaction(transactionId) ?? ({} as TransactionMeta)),\n };\n\n approvalTransactionMeta = latestTransactionMeta.approvalTxId\n ? getTransaction(latestTransactionMeta.approvalTxId)\n : undefined;\n\n latestTransactionMeta.postTxBalance = postTransactionBalance.toString(16);\n\n const isDefaultTokenAddress = isSwapsDefaultTokenAddress(\n transactionMeta.destinationTokenAddress as string,\n transactionMeta.chainId,\n );\n\n if (\n !isDefaultTokenAddress ||\n transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance\n ) {\n log('Finishing post balance update', {\n isDefaultTokenAddress,\n preTxBalance: transactionMeta.preTxBalance,\n postTxBalance: latestTransactionMeta.postTxBalance,\n });\n\n break;\n }\n\n log('Waiting for balance to update', {\n delay: UPDATE_POST_TX_BALANCE_TIMEOUT,\n });\n\n await sleep(UPDATE_POST_TX_BALANCE_TIMEOUT);\n }\n\n updateTransaction(\n latestTransactionMeta as TransactionMeta,\n 'TransactionController#updatePostTransactionBalance - Add post transaction balance',\n );\n\n log('Completed post balance update', latestTransactionMeta?.postTxBalance);\n\n return {\n updatedTransactionMeta: latestTransactionMeta as TransactionMeta,\n approvalTransactionMeta,\n };\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n * @returns The updated transaction meta object.\n */\nfunction updateSwapTransaction(\n transactionMeta: TransactionMeta,\n {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n\n return merge({}, transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap approval information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @returns The updated transaction meta object.\n */\nfunction updateSwapApprovalTransaction(\n transactionMeta: TransactionMeta,\n { type, sourceTokenSymbol }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(\n transactionMeta,\n 'updateSwapApprovalTransaction',\n );\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let swapApprovalTransaction = { type, sourceTokenSymbol } as any;\n swapApprovalTransaction = pickBy({\n type,\n sourceTokenSymbol,\n }) as Partial<TransactionMeta>;\n\n return merge({}, transactionMeta, swapApprovalTransaction);\n}\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nfunction isSwapsDefaultTokenAddress(address: string, chainId: string) {\n if (!address || !chainId) {\n return false;\n }\n\n return (\n address ===\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ]?.address\n );\n}\n\n/**\n * Sleeps for the provided number of milliseconds\n *\n * @param ms - Number of milliseconds to sleep\n * @returns Promise that resolves after the provided number of milliseconds\n */\nfunction sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}