@metamask/transaction-controller 24.0.0 → 25.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -1
- package/dist/TransactionController.js +38 -1816
- package/dist/TransactionController.js.map +1 -1
- package/dist/TransactionController.mjs +39 -0
- package/dist/TransactionController.mjs.map +1 -0
- package/dist/chunk-2K7J3EY3.mjs +170 -0
- package/dist/chunk-2K7J3EY3.mjs.map +1 -0
- package/dist/chunk-5XBULBP2.js +399 -0
- package/dist/chunk-5XBULBP2.js.map +1 -0
- package/dist/chunk-6MYNWYJK.mjs +158 -0
- package/dist/chunk-6MYNWYJK.mjs.map +1 -0
- package/dist/chunk-7APMBUKB.js +158 -0
- package/dist/chunk-7APMBUKB.js.map +1 -0
- package/dist/chunk-7LXE4KHV.js +40 -0
- package/dist/chunk-7LXE4KHV.js.map +1 -0
- package/dist/chunk-7MZ57ILQ.mjs +62 -0
- package/dist/chunk-7MZ57ILQ.mjs.map +1 -0
- package/dist/chunk-BJEESIBE.js +2313 -0
- package/dist/chunk-BJEESIBE.js.map +1 -0
- package/dist/chunk-C67QD5PV.mjs +320 -0
- package/dist/chunk-C67QD5PV.mjs.map +1 -0
- package/dist/chunk-DE3MZYVY.mjs +2313 -0
- package/dist/chunk-DE3MZYVY.mjs.map +1 -0
- package/dist/chunk-DEKM6PVG.mjs +46 -0
- package/dist/chunk-DEKM6PVG.mjs.map +1 -0
- package/dist/chunk-DQP6X25N.mjs +208 -0
- package/dist/chunk-DQP6X25N.mjs.map +1 -0
- package/dist/chunk-DTDTOMTB.js +238 -0
- package/dist/chunk-DTDTOMTB.js.map +1 -0
- package/dist/chunk-DTEDYRTL.js +242 -0
- package/dist/chunk-DTEDYRTL.js.map +1 -0
- package/dist/chunk-EQ3RRHB7.mjs +211 -0
- package/dist/chunk-EQ3RRHB7.mjs.map +1 -0
- package/dist/chunk-FDJPXQTF.js +46 -0
- package/dist/chunk-FDJPXQTF.js.map +1 -0
- package/dist/chunk-FRKQ3Z2L.mjs +40 -0
- package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
- package/dist/chunk-FS7FRO7B.mjs +90 -0
- package/dist/chunk-FS7FRO7B.mjs.map +1 -0
- package/dist/chunk-GKTIFXPN.js +170 -0
- package/dist/chunk-GKTIFXPN.js.map +1 -0
- package/dist/chunk-H4M66BA3.js +62 -0
- package/dist/chunk-H4M66BA3.js.map +1 -0
- package/dist/chunk-HPNXIKFY.js +76 -0
- package/dist/chunk-HPNXIKFY.js.map +1 -0
- package/dist/chunk-HS277C77.js +75 -0
- package/dist/chunk-HS277C77.js.map +1 -0
- package/dist/chunk-I5YZ7QUK.js +121 -0
- package/dist/chunk-I5YZ7QUK.js.map +1 -0
- package/dist/chunk-IC233ZQS.js +211 -0
- package/dist/chunk-IC233ZQS.js.map +1 -0
- package/dist/chunk-IUBAETUH.js +137 -0
- package/dist/chunk-IUBAETUH.js.map +1 -0
- package/dist/chunk-J56A7UCK.mjs +123 -0
- package/dist/chunk-J56A7UCK.mjs.map +1 -0
- package/dist/chunk-JR6HDRNV.mjs +242 -0
- package/dist/chunk-JR6HDRNV.mjs.map +1 -0
- package/dist/chunk-JRBREX22.mjs +75 -0
- package/dist/chunk-JRBREX22.mjs.map +1 -0
- package/dist/chunk-JRQHIBG5.mjs +399 -0
- package/dist/chunk-JRQHIBG5.mjs.map +1 -0
- package/dist/chunk-LM4NUNMT.mjs +76 -0
- package/dist/chunk-LM4NUNMT.mjs.map +1 -0
- package/dist/chunk-M7455RU7.js +320 -0
- package/dist/chunk-M7455RU7.js.map +1 -0
- package/dist/chunk-MHM5LRRF.mjs +122 -0
- package/dist/chunk-MHM5LRRF.mjs.map +1 -0
- package/dist/chunk-NHRBO3LU.mjs +50 -0
- package/dist/chunk-NHRBO3LU.mjs.map +1 -0
- package/dist/chunk-NM6OYEPP.mjs +182 -0
- package/dist/chunk-NM6OYEPP.mjs.map +1 -0
- package/dist/chunk-NUOBUW7C.js +85 -0
- package/dist/chunk-NUOBUW7C.js.map +1 -0
- package/dist/chunk-QP75SWIQ.js +53 -0
- package/dist/chunk-QP75SWIQ.js.map +1 -0
- package/dist/chunk-RI6MVJJN.js +122 -0
- package/dist/chunk-RI6MVJJN.js.map +1 -0
- package/dist/chunk-S6VGOPUY.js +14 -0
- package/dist/chunk-S6VGOPUY.js.map +1 -0
- package/dist/chunk-UGFBA4GV.js +123 -0
- package/dist/chunk-UGFBA4GV.js.map +1 -0
- package/dist/chunk-UKYY2RVS.mjs +137 -0
- package/dist/chunk-UKYY2RVS.mjs.map +1 -0
- package/dist/chunk-UM4ORJ5B.mjs +121 -0
- package/dist/chunk-UM4ORJ5B.mjs.map +1 -0
- package/dist/chunk-UQQWZT6C.mjs +14 -0
- package/dist/chunk-UQQWZT6C.mjs.map +1 -0
- package/dist/chunk-VH47Q6TS.js +182 -0
- package/dist/chunk-VH47Q6TS.js.map +1 -0
- package/dist/chunk-XGRAHX6T.mjs +53 -0
- package/dist/chunk-XGRAHX6T.mjs.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-Y734U4V6.mjs +85 -0
- package/dist/chunk-Y734U4V6.mjs.map +1 -0
- package/dist/chunk-Y7ENNK7L.mjs +238 -0
- package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/chunk-ZCQRDZ36.js +208 -0
- package/dist/chunk-ZCQRDZ36.js.map +1 -0
- package/dist/chunk-ZJLZSFOZ.js +90 -0
- package/dist/chunk-ZJLZSFOZ.js.map +1 -0
- package/dist/chunk-ZNZEJDOE.js +50 -0
- package/dist/chunk-ZNZEJDOE.js.map +1 -0
- package/dist/constants.js +15 -110
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +16 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
- package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
- package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
- package/dist/helpers/GasFeePoller.js +10 -143
- package/dist/helpers/GasFeePoller.js.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +11 -0
- package/dist/helpers/GasFeePoller.mjs.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.js +8 -205
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.js +12 -291
- package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
- package/dist/helpers/PendingTransactionTracker.js +9 -360
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +10 -0
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
- package/dist/index.js +56 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.js +11 -8
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +235 -46
- package/dist/types/TransactionController.d.ts.map +1 -0
- package/dist/{constants.d.ts → types/constants.d.ts} +5 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
- package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/{types.d.ts → types/types.d.ts} +63 -65
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/etherscan.d.ts.map +1 -0
- package/dist/types/utils/external-transactions.d.ts.map +1 -0
- package/dist/types/utils/gas-fees.d.ts.map +1 -0
- package/dist/types/utils/gas-flow.d.ts.map +1 -0
- package/dist/types/utils/gas.d.ts.map +1 -0
- package/dist/types/utils/history.d.ts +20 -0
- package/dist/types/utils/history.d.ts.map +1 -0
- package/dist/types/utils/nonce.d.ts.map +1 -0
- package/dist/types/utils/simulation-api.d.ts +99 -0
- package/dist/types/utils/simulation-api.d.ts.map +1 -0
- package/dist/types/utils/simulation.d.ts +21 -0
- package/dist/types/utils/simulation.d.ts.map +1 -0
- package/dist/{utils → types/utils}/swaps.d.ts +8 -5
- package/dist/types/utils/swaps.d.ts.map +1 -0
- package/dist/types/utils/transaction-type.d.ts.map +1 -0
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/dist/types.js +19 -170
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +20 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils/etherscan.js +13 -118
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/etherscan.mjs +14 -0
- package/dist/utils/etherscan.mjs.map +1 -0
- package/dist/utils/external-transactions.js +8 -35
- package/dist/utils/external-transactions.js.map +1 -1
- package/dist/utils/external-transactions.mjs +9 -0
- package/dist/utils/external-transactions.mjs.map +1 -0
- package/dist/utils/gas-fees.js +15 -200
- package/dist/utils/gas-fees.js.map +1 -1
- package/dist/utils/gas-fees.mjs +16 -0
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas-flow.js +10 -52
- package/dist/utils/gas-flow.js.map +1 -1
- package/dist/utils/gas-flow.mjs +11 -0
- package/dist/utils/gas-flow.mjs.map +1 -0
- package/dist/utils/gas.js +19 -133
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/gas.mjs +20 -0
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/history.js +9 -83
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/history.mjs +10 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/nonce.js +10 -76
- package/dist/utils/nonce.js.map +1 -1
- package/dist/utils/nonce.mjs +11 -0
- package/dist/utils/nonce.mjs.map +1 -0
- package/dist/utils/simulation-api.js +10 -0
- package/dist/utils/simulation-api.js.map +1 -0
- package/dist/utils/simulation-api.mjs +10 -0
- package/dist/utils/simulation-api.mjs.map +1 -0
- package/dist/utils/simulation.js +12 -0
- package/dist/utils/simulation.js.map +1 -0
- package/dist/utils/simulation.mjs +12 -0
- package/dist/utils/simulation.mjs.map +1 -0
- package/dist/utils/swaps.js +23 -256
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/swaps.mjs +24 -0
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/transaction-type.js +10 -120
- package/dist/utils/transaction-type.js.map +1 -1
- package/dist/utils/transaction-type.mjs +11 -0
- package/dist/utils/transaction-type.mjs.map +1 -0
- package/dist/utils/utils.js +32 -160
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +33 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/validation.js +11 -258
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/validation.mjs +12 -0
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +21 -9
- package/dist/TransactionController.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/etherscan.d.ts.map +0 -1
- package/dist/utils/external-transactions.d.ts.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-flow.d.ts.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/history.d.ts +0 -15
- package/dist/utils/history.d.ts.map +0 -1
- package/dist/utils/nonce.d.ts.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/transaction-type.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
- /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
- /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas.d.ts +0 -0
- /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
- /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/utils.d.ts +0 -0
- /package/dist/{utils → types/utils}/validation.d.ts +0 -0
package/dist/utils/history.js
CHANGED
|
@@ -1,84 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Add initial history snapshot to the provided transactionMeta history.
|
|
11
|
-
*
|
|
12
|
-
* @param transactionMeta - TransactionMeta to add initial history snapshot to.
|
|
13
|
-
*/
|
|
14
|
-
function addInitialHistorySnapshot(transactionMeta) {
|
|
15
|
-
const snapshot = snapshotFromTransactionMeta(transactionMeta);
|
|
16
|
-
transactionMeta.history = [snapshot];
|
|
17
|
-
}
|
|
18
|
-
exports.addInitialHistorySnapshot = addInitialHistorySnapshot;
|
|
19
|
-
/**
|
|
20
|
-
* Compares and adds history entry to the provided transactionMeta history.
|
|
21
|
-
*
|
|
22
|
-
* @param transactionMeta - TransactionMeta to add history entry to.
|
|
23
|
-
* @param note - Note to add to history entry.
|
|
24
|
-
*/
|
|
25
|
-
function updateTransactionHistory(transactionMeta, note) {
|
|
26
|
-
var _a;
|
|
27
|
-
if (!transactionMeta.history) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const currentState = snapshotFromTransactionMeta(transactionMeta);
|
|
31
|
-
const previousState = replayHistory(transactionMeta.history);
|
|
32
|
-
const historyEntry = generateHistoryEntry(previousState, currentState, note);
|
|
33
|
-
if (historyEntry.length) {
|
|
34
|
-
(_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.history) === null || _a === void 0 ? void 0 : _a.push(historyEntry);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.updateTransactionHistory = updateTransactionHistory;
|
|
38
|
-
/**
|
|
39
|
-
* Generates a history entry from the previous and new transaction metadata.
|
|
40
|
-
*
|
|
41
|
-
* @param previousState - The previous transaction metadata.
|
|
42
|
-
* @param currentState - The new transaction metadata.
|
|
43
|
-
* @param note - A note for the transaction metada update.
|
|
44
|
-
* @returns An array of history operation.
|
|
45
|
-
*/
|
|
46
|
-
function generateHistoryEntry(
|
|
47
|
-
// TODO: Replace `any` with type
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
-
previousState, currentState, note) {
|
|
50
|
-
const historyOperationsEntry = fast_json_patch_1.default.compare(previousState, currentState);
|
|
51
|
-
// Add a note to the first operation, since it breaks if we append it to the entry
|
|
52
|
-
if (historyOperationsEntry[0]) {
|
|
53
|
-
if (note) {
|
|
54
|
-
historyOperationsEntry[0].note = note;
|
|
55
|
-
}
|
|
56
|
-
historyOperationsEntry[0].timestamp = Date.now();
|
|
57
|
-
}
|
|
58
|
-
return historyOperationsEntry;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Recovers previous transactionMeta from passed history array.
|
|
62
|
-
*
|
|
63
|
-
* @param transactionHistory - The transaction metadata to replay.
|
|
64
|
-
* @returns The transaction metadata.
|
|
65
|
-
*/
|
|
66
|
-
function replayHistory(transactionHistory) {
|
|
67
|
-
const shortHistory = (0, lodash_1.cloneDeep)(transactionHistory);
|
|
68
|
-
return shortHistory.reduce(
|
|
69
|
-
// TODO: Replace `any` with type
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
(val, entry) => fast_json_patch_1.default.applyPatch(val, entry).newDocument);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Clone the transaction meta data without the history property.
|
|
75
|
-
*
|
|
76
|
-
* @param transactionMeta - The transaction metadata to snapshot.
|
|
77
|
-
* @returns A deep clone of transaction metadata without history property.
|
|
78
|
-
*/
|
|
79
|
-
function snapshotFromTransactionMeta(transactionMeta) {
|
|
80
|
-
const snapshot = Object.assign({}, transactionMeta);
|
|
81
|
-
delete snapshot.history;
|
|
82
|
-
return (0, lodash_1.cloneDeep)(snapshot);
|
|
83
|
-
}
|
|
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;
|
|
84
10
|
//# sourceMappingURL=history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/utils/nonce.js
CHANGED
|
@@ -1,77 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
package/dist/utils/nonce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 @@
|
|
|
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":[]}
|
package/dist/utils/swaps.js
CHANGED
|
@@ -1,257 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
exports.UPDATE_POST_TX_BALANCE_TIMEOUT =
|
|
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.controllerHubEmitter - Function to emit an event to the controller hub
|
|
93
|
-
*/
|
|
94
|
-
function updateSwapsTransaction(transactionMeta, transactionType, swaps, { isSwapsDisabled, cancelTransaction, controllerHubEmitter, }) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
if (isSwapsDisabled || !exports.SWAP_TRANSACTION_TYPES.includes(transactionType)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
// The simulationFails property is added if the estimateGas call fails. In cases
|
|
100
|
-
// when no swaps approval tx is required, this indicates that the swap will likely
|
|
101
|
-
// fail. There was an earlier estimateGas call made by the swaps controller,
|
|
102
|
-
// but it is possible that external conditions have change since then, and
|
|
103
|
-
// a previously succeeding estimate gas call could now fail. By checking for
|
|
104
|
-
// the `simulationFails` property here, we can reduce the number of swap
|
|
105
|
-
// transactions that get published to the blockchain only to fail and thereby
|
|
106
|
-
// waste the user's funds on gas.
|
|
107
|
-
if (transactionType === types_1.TransactionType.swap &&
|
|
108
|
-
(swaps === null || swaps === void 0 ? void 0 : swaps.hasApproveTx) === false &&
|
|
109
|
-
transactionMeta.simulationFails) {
|
|
110
|
-
yield cancelTransaction(transactionMeta.id);
|
|
111
|
-
throw new Error('Simulation failed');
|
|
112
|
-
}
|
|
113
|
-
const swapsMeta = swaps === null || swaps === void 0 ? void 0 : swaps.meta;
|
|
114
|
-
if (!swapsMeta) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (transactionType === types_1.TransactionType.swapApproval) {
|
|
118
|
-
updateSwapApprovalTransaction(transactionMeta, swapsMeta);
|
|
119
|
-
controllerHubEmitter('transaction-new-swap-approval', {
|
|
120
|
-
transactionMeta,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
if (transactionType === types_1.TransactionType.swap) {
|
|
124
|
-
updateSwapTransaction(transactionMeta, swapsMeta);
|
|
125
|
-
controllerHubEmitter('transaction-new-swap', {
|
|
126
|
-
transactionMeta,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
exports.updateSwapsTransaction = updateSwapsTransaction;
|
|
132
|
-
/**
|
|
133
|
-
* Attempts to update the post transaction balance of the provided transaction
|
|
134
|
-
*
|
|
135
|
-
* @param transactionMeta - Transaction meta object to update
|
|
136
|
-
* @param updatePostTransactionBalanceRequest - Dependency bag
|
|
137
|
-
* @param updatePostTransactionBalanceRequest.ethQuery - EthQuery object
|
|
138
|
-
* @param updatePostTransactionBalanceRequest.getTransaction - Reading function for the latest transaction state
|
|
139
|
-
* @param updatePostTransactionBalanceRequest.updateTransaction - Updating transaction function
|
|
140
|
-
*/
|
|
141
|
-
function updatePostTransactionBalance(transactionMeta, { ethQuery, getTransaction, updateTransaction, }) {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
log('Updating post transaction balance', transactionMeta.id);
|
|
144
|
-
const transactionId = transactionMeta.id;
|
|
145
|
-
let latestTransactionMeta, approvalTransactionMeta;
|
|
146
|
-
for (let i = 0; i < exports.UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {
|
|
147
|
-
log('Querying balance', { attempt: i });
|
|
148
|
-
const postTransactionBalance = yield (0, controller_utils_1.query)(ethQuery, 'getBalance', [
|
|
149
|
-
transactionMeta.txParams.from,
|
|
150
|
-
]);
|
|
151
|
-
latestTransactionMeta = getTransaction(transactionId);
|
|
152
|
-
approvalTransactionMeta = latestTransactionMeta.approvalTxId
|
|
153
|
-
? getTransaction(latestTransactionMeta.approvalTxId)
|
|
154
|
-
: undefined;
|
|
155
|
-
latestTransactionMeta.postTxBalance = postTransactionBalance.toString(16);
|
|
156
|
-
const isDefaultTokenAddress = isSwapsDefaultTokenAddress(transactionMeta.destinationTokenAddress, transactionMeta.chainId);
|
|
157
|
-
if (!isDefaultTokenAddress ||
|
|
158
|
-
transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance) {
|
|
159
|
-
log('Finishing post balance update', {
|
|
160
|
-
isDefaultTokenAddress,
|
|
161
|
-
preTxBalance: transactionMeta.preTxBalance,
|
|
162
|
-
postTxBalance: latestTransactionMeta.postTxBalance,
|
|
163
|
-
});
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
log('Waiting for balance to update', {
|
|
167
|
-
delay: exports.UPDATE_POST_TX_BALANCE_TIMEOUT,
|
|
168
|
-
});
|
|
169
|
-
yield sleep(exports.UPDATE_POST_TX_BALANCE_TIMEOUT);
|
|
170
|
-
}
|
|
171
|
-
updateTransaction(latestTransactionMeta, 'TransactionController#updatePostTransactionBalance - Add post transaction balance');
|
|
172
|
-
log('Completed post balance update', latestTransactionMeta === null || latestTransactionMeta === void 0 ? void 0 : latestTransactionMeta.postTxBalance);
|
|
173
|
-
return {
|
|
174
|
-
updatedTransactionMeta: latestTransactionMeta,
|
|
175
|
-
approvalTransactionMeta,
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
exports.updatePostTransactionBalance = updatePostTransactionBalance;
|
|
180
|
-
/**
|
|
181
|
-
* Updates the transaction meta object with the swap information
|
|
182
|
-
*
|
|
183
|
-
* @param transactionMeta - Transaction meta object to update
|
|
184
|
-
* @param propsToUpdate - Properties to update
|
|
185
|
-
* @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped
|
|
186
|
-
* @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received
|
|
187
|
-
* @param propsToUpdate.type - Type of the transaction
|
|
188
|
-
* @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received
|
|
189
|
-
* @param propsToUpdate.destinationTokenAddress - Address of the token to be received
|
|
190
|
-
* @param propsToUpdate.swapMetaData - Metadata of the swap
|
|
191
|
-
* @param propsToUpdate.swapTokenValue - Value of the token to be swapped
|
|
192
|
-
* @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction
|
|
193
|
-
* @param propsToUpdate.approvalTxId - Transaction id of the approval transaction
|
|
194
|
-
*/
|
|
195
|
-
function updateSwapTransaction(transactionMeta, { sourceTokenSymbol, destinationTokenSymbol, type, destinationTokenDecimals, destinationTokenAddress, swapMetaData, swapTokenValue, estimatedBaseFee, approvalTxId, }) {
|
|
196
|
-
(0, utils_1.validateIfTransactionUnapproved)(transactionMeta, 'updateSwapTransaction');
|
|
197
|
-
let swapTransaction = {
|
|
198
|
-
sourceTokenSymbol,
|
|
199
|
-
destinationTokenSymbol,
|
|
200
|
-
type,
|
|
201
|
-
destinationTokenDecimals,
|
|
202
|
-
destinationTokenAddress,
|
|
203
|
-
swapMetaData,
|
|
204
|
-
swapTokenValue,
|
|
205
|
-
estimatedBaseFee,
|
|
206
|
-
approvalTxId,
|
|
207
|
-
};
|
|
208
|
-
// TODO: Replace `any` with type
|
|
209
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
|
-
swapTransaction = (0, lodash_1.pickBy)(swapTransaction);
|
|
211
|
-
(0, lodash_1.merge)(transactionMeta, swapTransaction);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Updates the transaction meta object with the swap approval information
|
|
215
|
-
*
|
|
216
|
-
* @param transactionMeta - Transaction meta object to update
|
|
217
|
-
* @param propsToUpdate - Properties to update
|
|
218
|
-
* @param propsToUpdate.type - Type of the transaction
|
|
219
|
-
* @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped
|
|
220
|
-
*/
|
|
221
|
-
function updateSwapApprovalTransaction(transactionMeta, { type, sourceTokenSymbol }) {
|
|
222
|
-
(0, utils_1.validateIfTransactionUnapproved)(transactionMeta, 'updateSwapApprovalTransaction');
|
|
223
|
-
// TODO: Replace `any` with type
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
-
let swapApprovalTransaction = { type, sourceTokenSymbol };
|
|
226
|
-
swapApprovalTransaction = (0, lodash_1.pickBy)({
|
|
227
|
-
type,
|
|
228
|
-
sourceTokenSymbol,
|
|
229
|
-
});
|
|
230
|
-
(0, lodash_1.merge)(transactionMeta, swapApprovalTransaction);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Checks whether the provided address is strictly equal to the address for
|
|
234
|
-
* the default swaps token of the provided chain.
|
|
235
|
-
*
|
|
236
|
-
* @param address - The string to compare to the default token address
|
|
237
|
-
* @param chainId - The hex encoded chain ID of the default swaps token to check
|
|
238
|
-
* @returns Whether the address is the provided chain's default token address
|
|
239
|
-
*/
|
|
240
|
-
function isSwapsDefaultTokenAddress(address, chainId) {
|
|
241
|
-
var _a;
|
|
242
|
-
if (!address || !chainId) {
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
return (address ===
|
|
246
|
-
((_a = exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId]) === null || _a === void 0 ? void 0 : _a.address));
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Sleeps for the provided number of milliseconds
|
|
250
|
-
*
|
|
251
|
-
* @param ms - Number of milliseconds to sleep
|
|
252
|
-
* @returns Promise that resolves after the provided number of milliseconds
|
|
253
|
-
*/
|
|
254
|
-
function sleep(ms) {
|
|
255
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
256
|
-
}
|
|
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;
|
|
257
24
|
//# sourceMappingURL=swaps.js.map
|
package/dist/utils/swaps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swaps.js","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAmD;AAEnD,mCAAuC;AAEvC,4CAAyC;AACzC,sCAA8D;AAE9D,oCAA2C;AAC3C,mCAA0D;AAE1D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,OAAO,CAAC,CAAC;AAEvD;;GAEG;AACU,QAAA,8BAA8B,GAAG,IAAI,CAAC;AAEnD;;GAEG;AACU,QAAA,+BAA+B,GAAG,CAAC,CAAC;AAEjD,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC;;GAEG;AACU,QAAA,qBAAqB,GAChC,4CAA4C,CAAC;AAmB/C,MAAM,sBAAsB,GAAqB;IAC/C,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,6BAAqB;IAC9B,QAAQ,EAAE,EAAE;CACb,CAAC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D,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 { Events, 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.controllerHubEmitter - Function to emit an event to the controller hub\n */\nexport async function updateSwapsTransaction(\n transactionMeta: TransactionMeta,\n transactionType: TransactionType,\n swaps: {\n hasApproveTx?: boolean;\n meta?: Partial<TransactionMeta>;\n },\n {\n isSwapsDisabled,\n cancelTransaction,\n controllerHubEmitter,\n }: {\n isSwapsDisabled: boolean;\n cancelTransaction: (transactionId: string) => void;\n controllerHubEmitter: <T extends keyof Events>(\n eventName: T,\n ...args: Events[T]\n ) => boolean;\n },\n) {\n if (isSwapsDisabled || !SWAP_TRANSACTION_TYPES.includes(transactionType)) {\n return;\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 await 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;\n }\n\n if (transactionType === TransactionType.swapApproval) {\n updateSwapApprovalTransaction(transactionMeta, swapsMeta);\n controllerHubEmitter('transaction-new-swap-approval', {\n transactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swap) {\n updateSwapTransaction(transactionMeta, swapsMeta);\n controllerHubEmitter('transaction-new-swap', {\n transactionMeta,\n });\n }\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, 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 = getTransaction(transactionId) as TransactionMeta;\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 */\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) {\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 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 */\nfunction updateSwapApprovalTransaction(\n transactionMeta: TransactionMeta,\n { type, sourceTokenSymbol }: Partial<TransactionMeta>,\n) {\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 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":""}
|