@metamask/bridge-status-controller 33.0.0 → 34.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 +21 -1
- package/dist/bridge-status-controller.cjs +141 -104
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +4 -4
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +4 -4
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +144 -107
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/gas.cjs +34 -1
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +7 -0
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +7 -0
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +32 -0
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/metrics.cjs +9 -4
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +1 -1
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +1 -1
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +9 -4
- package/dist/utils/metrics.mjs.map +1 -1
- package/dist/utils/transaction.cjs +100 -1
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +80 -2
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +80 -2
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +96 -1
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +3 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [34.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `batchId` to BridgeHistoryItem to enable querying history by batchId ([#6058](https://github.com/MetaMask/core/pull/6058))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **BREAKING** Add tx batching functionality, which requires an `addTransactionBatchFn` handler to be passed to the BridgeStatusController's constructor ([#6058](https://github.com/MetaMask/core/pull/6058))
|
|
19
|
+
- **BREAKING** Update batched txs after signing with correct tx types, which requires an `updateTransactionFn` handler to be passed to the BridgeStatusController's constructor ([#6058](https://github.com/MetaMask/core/pull/6058))
|
|
20
|
+
- Add approvalTxId to txHistoryItem after signing batched transaction ([#6058](https://github.com/MetaMask/core/pull/6058))
|
|
21
|
+
- Remove `addUserOperationFromTransaction` tx submission code and constructor arg since it is unsupported ([#6057](https://github.com/MetaMask/core/pull/6057))
|
|
22
|
+
- Remove @metamask/user-operation-controller dependency ([#6057](https://github.com/MetaMask/core/pull/6057))
|
|
23
|
+
- **BREAKING:** Bump peer dependency `@metamask/snaps-controllers` from `^12.0.0` to `^14.0.0` ([#6035](https://github.com/MetaMask/core/pull/6035))
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- Wait until a bridge transaction is confirmed before polling for its status. This reduces (or fully removes) premature `getTxStatus` calls, and enables adding batched bridge txs to history before its transaction Id is available ([#6052](https://github.com/MetaMask/core/pull/6052))
|
|
28
|
+
|
|
10
29
|
## [33.0.0]
|
|
11
30
|
|
|
12
31
|
### Changed
|
|
@@ -377,7 +396,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
377
396
|
|
|
378
397
|
- Initial release ([#5317](https://github.com/MetaMask/core/pull/5317))
|
|
379
398
|
|
|
380
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@
|
|
399
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@34.0.0...HEAD
|
|
400
|
+
[34.0.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@33.0.0...@metamask/bridge-status-controller@34.0.0
|
|
381
401
|
[33.0.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@32.0.0...@metamask/bridge-status-controller@33.0.0
|
|
382
402
|
[32.0.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@31.0.0...@metamask/bridge-status-controller@32.0.0
|
|
383
403
|
[31.0.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@30.0.0...@metamask/bridge-status-controller@31.0.0
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _BridgeStatusController_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn,
|
|
13
|
+
var _BridgeStatusController_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_updateTransactionFn, _BridgeStatusController_estimateGasFeeFn, _BridgeStatusController_trace, _BridgeStatusController_markTxAsFailed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_getMultichainSelectedAccount, _BridgeStatusController_getMultichainSelectedAccountAddress, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_getSrcTxHash, _BridgeStatusController_updateSrcTxHash, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleSolanaTx, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransaction, _BridgeStatusController_handleUSDTAllowanceReset, _BridgeStatusController_calculateGasFees, _BridgeStatusController_handleEvmTransactionBatch, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.BridgeStatusController = void 0;
|
|
16
16
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
@@ -19,7 +19,6 @@ const keyring_api_1 = require("@metamask/keyring-api");
|
|
|
19
19
|
const polling_controller_1 = require("@metamask/polling-controller");
|
|
20
20
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
21
21
|
const utils_1 = require("@metamask/utils");
|
|
22
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
23
22
|
const constants_1 = require("./constants.cjs");
|
|
24
23
|
const types_1 = require("./types.cjs");
|
|
25
24
|
const bridge_status_1 = require("./utils/bridge-status.cjs");
|
|
@@ -36,7 +35,7 @@ const metadata = {
|
|
|
36
35
|
},
|
|
37
36
|
};
|
|
38
37
|
class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPollingController)() {
|
|
39
|
-
constructor({ messenger, state, clientId, fetchFn, addTransactionFn,
|
|
38
|
+
constructor({ messenger, state, clientId, fetchFn, addTransactionFn, addTransactionBatchFn, updateTransactionFn, estimateGasFeeFn, config, traceFn, }) {
|
|
40
39
|
super({
|
|
41
40
|
name: constants_1.BRIDGE_STATUS_CONTROLLER_NAME,
|
|
42
41
|
metadata,
|
|
@@ -53,9 +52,22 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
53
52
|
_BridgeStatusController_fetchFn.set(this, void 0);
|
|
54
53
|
_BridgeStatusController_config.set(this, void 0);
|
|
55
54
|
_BridgeStatusController_addTransactionFn.set(this, void 0);
|
|
55
|
+
_BridgeStatusController_addTransactionBatchFn.set(this, void 0);
|
|
56
|
+
_BridgeStatusController_updateTransactionFn.set(this, void 0);
|
|
56
57
|
_BridgeStatusController_estimateGasFeeFn.set(this, void 0);
|
|
57
|
-
_BridgeStatusController_addUserOperationFromTransactionFn.set(this, void 0);
|
|
58
58
|
_BridgeStatusController_trace.set(this, void 0);
|
|
59
|
+
// Mark tx as failed in txHistory if either the approval or trade fails
|
|
60
|
+
_BridgeStatusController_markTxAsFailed.set(this, ({ id }) => {
|
|
61
|
+
const txHistoryKey = this.state.txHistory[id]
|
|
62
|
+
? id
|
|
63
|
+
: Object.keys(this.state.txHistory).find((key) => this.state.txHistory[key].approvalTxId === id);
|
|
64
|
+
if (!txHistoryKey) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.update((statusState) => {
|
|
68
|
+
statusState.txHistory[txHistoryKey].status.status = bridge_controller_1.StatusTypes.FAILED;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
59
71
|
this.resetState = () => {
|
|
60
72
|
this.update((state) => {
|
|
61
73
|
state.txHistory = constants_1.DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE.txHistory;
|
|
@@ -84,8 +96,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
84
96
|
historyItem.status.status === bridge_controller_1.StatusTypes.UNKNOWN)
|
|
85
97
|
.filter((historyItem) => {
|
|
86
98
|
// Check if we are already polling this tx, if so, skip restarting polling for that
|
|
87
|
-
const
|
|
88
|
-
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[srcTxMetaId];
|
|
99
|
+
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[historyItem.txMetaId];
|
|
89
100
|
return !pollingToken;
|
|
90
101
|
})
|
|
91
102
|
// Swap txs don't need to have their statuses polled
|
|
@@ -97,9 +108,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
97
108
|
const bridgeTxMetaId = historyItem.txMetaId;
|
|
98
109
|
// We manually call startPolling() here rather than go through startPollingForBridgeTxStatus()
|
|
99
110
|
// because we don't want to overwrite the existing historyItem in state
|
|
100
|
-
__classPrivateFieldGet(this,
|
|
101
|
-
bridgeTxMetaId,
|
|
102
|
-
});
|
|
111
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeTxMetaId);
|
|
103
112
|
});
|
|
104
113
|
});
|
|
105
114
|
_BridgeStatusController_addTxToHistory.set(this, (startPollingForBridgeTxStatusArgs) => {
|
|
@@ -109,6 +118,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
109
118
|
// We know it's in progress but not the exact status yet
|
|
110
119
|
const txHistoryItem = {
|
|
111
120
|
txMetaId: bridgeTxMeta.id,
|
|
121
|
+
batchId: bridgeTxMeta.batchId,
|
|
112
122
|
quote: quoteResponse.quote,
|
|
113
123
|
startTime,
|
|
114
124
|
estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
|
|
@@ -140,20 +150,33 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
140
150
|
state.txHistory[bridgeTxMeta.id] = txHistoryItem;
|
|
141
151
|
});
|
|
142
152
|
});
|
|
153
|
+
_BridgeStatusController_startPollingForTxId.set(this, (txId) => {
|
|
154
|
+
// If we are already polling for this tx, stop polling for it before restarting
|
|
155
|
+
const existingPollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId];
|
|
156
|
+
if (existingPollingToken) {
|
|
157
|
+
this.stopPollingByPollingToken(existingPollingToken);
|
|
158
|
+
}
|
|
159
|
+
const txHistoryItem = this.state.txHistory[txId];
|
|
160
|
+
if (!txHistoryItem) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const { quote } = txHistoryItem;
|
|
164
|
+
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quote.srcChainId, quote.destChainId);
|
|
165
|
+
if (isBridgeTx) {
|
|
166
|
+
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
|
167
|
+
bridgeTxMetaId: txId,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
143
171
|
/**
|
|
144
|
-
*
|
|
172
|
+
* Adds tx to history and starts polling for the bridge tx status
|
|
145
173
|
*
|
|
146
174
|
* @param txHistoryMeta - The parameters for creating the history item
|
|
147
175
|
*/
|
|
148
176
|
this.startPollingForBridgeTxStatus = (txHistoryMeta) => {
|
|
149
|
-
const {
|
|
177
|
+
const { bridgeTxMeta } = txHistoryMeta;
|
|
150
178
|
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, txHistoryMeta);
|
|
151
|
-
|
|
152
|
-
if (isBridgeTx) {
|
|
153
|
-
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMeta.id] = this.startPolling({
|
|
154
|
-
bridgeTxMetaId: bridgeTxMeta.id,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
179
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeTxMeta.id);
|
|
157
180
|
};
|
|
158
181
|
// This will be called after you call this.startPolling()
|
|
159
182
|
// The args passed in are the args you passed in to startPolling()
|
|
@@ -294,7 +317,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
294
317
|
}
|
|
295
318
|
return finalTransactionMeta;
|
|
296
319
|
});
|
|
297
|
-
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, quoteResponse
|
|
320
|
+
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, quoteResponse) => {
|
|
298
321
|
const { approval } = quoteResponse;
|
|
299
322
|
if (approval) {
|
|
300
323
|
const approveTx = async () => {
|
|
@@ -304,8 +327,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
304
327
|
? transaction_controller_1.TransactionType.bridgeApproval
|
|
305
328
|
: transaction_controller_1.TransactionType.swapApproval,
|
|
306
329
|
trade: approval,
|
|
307
|
-
quoteResponse,
|
|
308
|
-
requireApproval,
|
|
309
330
|
});
|
|
310
331
|
await (0, transaction_1.handleLineaDelay)(quoteResponse);
|
|
311
332
|
return approvalTxMeta;
|
|
@@ -322,31 +343,16 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
322
343
|
}
|
|
323
344
|
return undefined;
|
|
324
345
|
});
|
|
325
|
-
_BridgeStatusController_handleEvmSmartTransaction.set(this, async ({ isBridgeTx, trade, quoteResponse, approvalTxId, requireApproval = false, }) => {
|
|
326
|
-
return await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
327
|
-
transactionType: isBridgeTx
|
|
328
|
-
? transaction_controller_1.TransactionType.bridge
|
|
329
|
-
: transaction_controller_1.TransactionType.swap,
|
|
330
|
-
trade,
|
|
331
|
-
quoteResponse,
|
|
332
|
-
approvalTxId,
|
|
333
|
-
shouldWaitForHash: false,
|
|
334
|
-
requireApproval,
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
346
|
/**
|
|
338
347
|
* Submits an EVM transaction to the TransactionController
|
|
339
348
|
*
|
|
340
349
|
* @param params - The parameters for the transaction
|
|
341
350
|
* @param params.transactionType - The type of transaction to submit
|
|
342
351
|
* @param params.trade - The trade data to confirm
|
|
343
|
-
* @param params.quoteResponse - The quote response
|
|
344
|
-
* @param params.approvalTxId - The tx id of the approval tx
|
|
345
|
-
* @param params.shouldWaitForHash - Whether to wait for the hash of the transaction
|
|
346
352
|
* @param params.requireApproval - Whether to require approval for the transaction
|
|
347
353
|
* @returns The transaction meta
|
|
348
354
|
*/
|
|
349
|
-
_BridgeStatusController_handleEvmTransaction.set(this, async ({ transactionType, trade,
|
|
355
|
+
_BridgeStatusController_handleEvmTransaction.set(this, async ({ transactionType, trade, requireApproval = false, }) => {
|
|
350
356
|
const actionId = (0, transaction_2.generateActionId)().toString();
|
|
351
357
|
const selectedAccount = this.messagingSystem.call('AccountsController:getAccountByAddress', trade.from);
|
|
352
358
|
if (!selectedAccount) {
|
|
@@ -371,47 +377,16 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
371
377
|
...transactionParams,
|
|
372
378
|
...(await __classPrivateFieldGet(this, _BridgeStatusController_calculateGasFees, "f").call(this, transactionParams, networkClientId, hexChainId)),
|
|
373
379
|
};
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const isSmartContractAccount = selectedAccount.type === keyring_api_1.EthAccountType.Erc4337;
|
|
377
|
-
if (isSmartContractAccount && __classPrivateFieldGet(this, _BridgeStatusController_addUserOperationFromTransactionFn, "f")) {
|
|
378
|
-
const smartAccountTxResult = await __classPrivateFieldGet(this, _BridgeStatusController_addUserOperationFromTransactionFn, "f").call(this, transactionParamsWithMaxGas, requestOptions);
|
|
379
|
-
result = smartAccountTxResult.transactionHash;
|
|
380
|
-
transactionMeta = {
|
|
381
|
-
...requestOptions,
|
|
382
|
-
chainId: hexChainId,
|
|
383
|
-
txParams: transactionParamsWithMaxGas,
|
|
384
|
-
time: Date.now(),
|
|
385
|
-
id: smartAccountTxResult.id,
|
|
386
|
-
status: transaction_controller_1.TransactionStatus.confirmed,
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
const addTransactionResult = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, transactionParamsWithMaxGas, requestOptions);
|
|
391
|
-
result = addTransactionResult.result;
|
|
392
|
-
transactionMeta = addTransactionResult.transactionMeta;
|
|
393
|
-
}
|
|
394
|
-
if (shouldWaitForHash) {
|
|
395
|
-
return await __classPrivateFieldGet(this, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, "f").call(this, result);
|
|
396
|
-
}
|
|
397
|
-
return {
|
|
398
|
-
...(0, transaction_1.getTxMetaFields)(quoteResponse, approvalTxId),
|
|
399
|
-
...transactionMeta,
|
|
400
|
-
};
|
|
380
|
+
const { result } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, transactionParamsWithMaxGas, requestOptions);
|
|
381
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, "f").call(this, result);
|
|
401
382
|
});
|
|
402
383
|
_BridgeStatusController_handleUSDTAllowanceReset.set(this, async (quoteResponse) => {
|
|
403
|
-
const
|
|
404
|
-
if (
|
|
405
|
-
(
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
410
|
-
transactionType: transaction_controller_1.TransactionType.bridgeApproval,
|
|
411
|
-
trade: { ...quoteResponse.approval, data: (0, bridge_controller_1.getEthUsdtResetData)() },
|
|
412
|
-
quoteResponse,
|
|
413
|
-
});
|
|
414
|
-
}
|
|
384
|
+
const resetApproval = await (0, transaction_1.getUSDTAllowanceResetTx)(this.messagingSystem, quoteResponse);
|
|
385
|
+
if (resetApproval) {
|
|
386
|
+
await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
387
|
+
transactionType: transaction_controller_1.TransactionType.bridgeApproval,
|
|
388
|
+
trade: resetApproval,
|
|
389
|
+
});
|
|
415
390
|
}
|
|
416
391
|
});
|
|
417
392
|
_BridgeStatusController_calculateGasFees.set(this, async (transactionParams, networkClientId, chainId) => {
|
|
@@ -432,6 +407,42 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
432
407
|
gas: maxGasLimit,
|
|
433
408
|
};
|
|
434
409
|
});
|
|
410
|
+
/**
|
|
411
|
+
* Submits batched EVM transactions to the TransactionController
|
|
412
|
+
*
|
|
413
|
+
* @param args - The parameters for the transaction
|
|
414
|
+
* @param args.isBridgeTx - Whether the transaction is a bridge transaction
|
|
415
|
+
* @param args.trade - The trade data to confirm
|
|
416
|
+
* @param args.approval - The approval data to confirm
|
|
417
|
+
* @param args.resetApproval - The ethereum:USDT reset approval data to confirm
|
|
418
|
+
* @param args.quoteResponse - The quote response
|
|
419
|
+
* @param args.requireApproval - Whether to require approval for the transaction
|
|
420
|
+
* @returns The approvalMeta and tradeMeta for the batched transaction
|
|
421
|
+
*/
|
|
422
|
+
_BridgeStatusController_handleEvmTransactionBatch.set(this, async (args) => {
|
|
423
|
+
const transactionParams = await (0, transaction_1.getAddTransactionBatchParams)({
|
|
424
|
+
messagingSystem: this.messagingSystem,
|
|
425
|
+
estimateGasFeeFn: __classPrivateFieldGet(this, _BridgeStatusController_estimateGasFeeFn, "f"),
|
|
426
|
+
...args,
|
|
427
|
+
});
|
|
428
|
+
const txDataByType = {
|
|
429
|
+
[transaction_controller_1.TransactionType.bridgeApproval]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.bridgeApproval)?.params.data,
|
|
430
|
+
[transaction_controller_1.TransactionType.swapApproval]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.swapApproval)?.params.data,
|
|
431
|
+
[transaction_controller_1.TransactionType.bridge]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.bridge)?.params.data,
|
|
432
|
+
[transaction_controller_1.TransactionType.swap]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.swap)?.params.data,
|
|
433
|
+
};
|
|
434
|
+
const { batchId } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f").call(this, transactionParams);
|
|
435
|
+
const { approvalMeta, tradeMeta } = (0, transaction_1.findAndUpdateTransactionsInBatch)({
|
|
436
|
+
messagingSystem: this.messagingSystem,
|
|
437
|
+
updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
|
|
438
|
+
batchId,
|
|
439
|
+
txDataByType,
|
|
440
|
+
});
|
|
441
|
+
if (!tradeMeta) {
|
|
442
|
+
throw new Error('Failed to update cross-chain swap transaction batch: tradeMeta not found');
|
|
443
|
+
}
|
|
444
|
+
return { approvalMeta, tradeMeta };
|
|
445
|
+
});
|
|
435
446
|
/**
|
|
436
447
|
* Submits a cross-chain swap transaction
|
|
437
448
|
*
|
|
@@ -454,7 +465,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
454
465
|
// Emit Submitted event after submit button is clicked
|
|
455
466
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
|
456
467
|
let txMeta;
|
|
457
|
-
let
|
|
468
|
+
let approvalTxId;
|
|
469
|
+
const startTime = Date.now();
|
|
458
470
|
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
459
471
|
// Submit SOLANA tx
|
|
460
472
|
if ((0, bridge_controller_1.isSolanaChainId)(quoteResponse.quote.srcChainId) &&
|
|
@@ -486,10 +498,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
486
498
|
// Extension does not have this issue
|
|
487
499
|
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
|
|
488
500
|
(0, bridge_controller_1.isHardwareWallet)(__classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this));
|
|
489
|
-
// Set approval time and id if an approval tx is needed
|
|
490
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse, requireApproval);
|
|
491
|
-
approvalTime = approvalTxMeta?.time;
|
|
492
|
-
approvalTxId = approvalTxMeta?.id;
|
|
493
501
|
// Handle smart transactions if enabled
|
|
494
502
|
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
495
503
|
name: isBridgeTx
|
|
@@ -499,27 +507,34 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
499
507
|
srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(quoteResponse.quote.srcChainId),
|
|
500
508
|
stxEnabled: isStxEnabledOnClient,
|
|
501
509
|
},
|
|
502
|
-
}, async () =>
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
510
|
+
}, async () => {
|
|
511
|
+
if (isStxEnabledOnClient) {
|
|
512
|
+
const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
|
|
513
|
+
isBridgeTx,
|
|
514
|
+
resetApproval: await (0, transaction_1.getUSDTAllowanceResetTx)(this.messagingSystem, quoteResponse),
|
|
515
|
+
approval: quoteResponse.approval,
|
|
516
|
+
trade: quoteResponse.trade,
|
|
517
|
+
quoteResponse,
|
|
518
|
+
requireApproval,
|
|
519
|
+
});
|
|
520
|
+
approvalTxId = approvalMeta?.id;
|
|
521
|
+
return tradeMeta;
|
|
522
|
+
}
|
|
523
|
+
// Set approval time and id if an approval tx is needed
|
|
524
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse);
|
|
525
|
+
approvalTxId = approvalTxMeta?.id;
|
|
526
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
511
527
|
transactionType: isBridgeTx
|
|
512
528
|
? transaction_controller_1.TransactionType.bridge
|
|
513
529
|
: transaction_controller_1.TransactionType.swap,
|
|
514
530
|
trade: quoteResponse.trade,
|
|
515
|
-
quoteResponse,
|
|
516
|
-
approvalTxId,
|
|
517
531
|
requireApproval,
|
|
518
|
-
})
|
|
532
|
+
});
|
|
533
|
+
});
|
|
519
534
|
}
|
|
520
535
|
try {
|
|
521
|
-
//
|
|
522
|
-
this.
|
|
536
|
+
// Add swap or bridge tx to history
|
|
537
|
+
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
523
538
|
bridgeTxMeta: txMeta,
|
|
524
539
|
statusRequest: {
|
|
525
540
|
...(0, transaction_1.getStatusRequestParams)(quoteResponse),
|
|
@@ -528,12 +543,16 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
528
543
|
quoteResponse,
|
|
529
544
|
slippagePercentage: 0,
|
|
530
545
|
isStxEnabled: isStxEnabledOnClient,
|
|
531
|
-
startTime
|
|
546
|
+
startTime,
|
|
532
547
|
approvalTxId,
|
|
533
548
|
});
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
__classPrivateFieldGet(this,
|
|
549
|
+
if ((0, bridge_controller_1.isSolanaChainId)(quoteResponse.quote.srcChainId)) {
|
|
550
|
+
// Start polling for bridge tx status
|
|
551
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, txMeta.id);
|
|
552
|
+
// Track Solana Swap completed event
|
|
553
|
+
if (!isBridgeTx) {
|
|
554
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, txMeta.id);
|
|
555
|
+
}
|
|
537
556
|
}
|
|
538
557
|
}
|
|
539
558
|
catch {
|
|
@@ -574,7 +593,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
574
593
|
__classPrivateFieldSet(this, _BridgeStatusController_clientId, clientId, "f");
|
|
575
594
|
__classPrivateFieldSet(this, _BridgeStatusController_fetchFn, fetchFn, "f");
|
|
576
595
|
__classPrivateFieldSet(this, _BridgeStatusController_addTransactionFn, addTransactionFn, "f");
|
|
577
|
-
__classPrivateFieldSet(this,
|
|
596
|
+
__classPrivateFieldSet(this, _BridgeStatusController_addTransactionBatchFn, addTransactionBatchFn, "f");
|
|
597
|
+
__classPrivateFieldSet(this, _BridgeStatusController_updateTransactionFn, updateTransactionFn, "f");
|
|
578
598
|
__classPrivateFieldSet(this, _BridgeStatusController_estimateGasFeeFn, estimateGasFeeFn, "f");
|
|
579
599
|
__classPrivateFieldSet(this, _BridgeStatusController_config, {
|
|
580
600
|
customBridgeApiBaseUrl: config?.customBridgeApiBaseUrl ?? constants_1.BRIDGE_PROD_API_BASE_URL,
|
|
@@ -590,16 +610,33 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
590
610
|
this.messagingSystem.subscribe('TransactionController:transactionFailed', ({ transactionMeta }) => {
|
|
591
611
|
const { type, status, id } = transactionMeta;
|
|
592
612
|
if (type &&
|
|
593
|
-
[
|
|
594
|
-
|
|
595
|
-
|
|
613
|
+
[
|
|
614
|
+
transaction_controller_1.TransactionType.bridge,
|
|
615
|
+
transaction_controller_1.TransactionType.swap,
|
|
616
|
+
transaction_controller_1.TransactionType.bridgeApproval,
|
|
617
|
+
transaction_controller_1.TransactionType.swapApproval,
|
|
618
|
+
].includes(type) &&
|
|
619
|
+
[
|
|
620
|
+
transaction_controller_1.TransactionStatus.failed,
|
|
621
|
+
transaction_controller_1.TransactionStatus.dropped,
|
|
622
|
+
transaction_controller_1.TransactionStatus.rejected,
|
|
623
|
+
].includes(status)) {
|
|
624
|
+
// Mark tx as failed in txHistory
|
|
625
|
+
__classPrivateFieldGet(this, _BridgeStatusController_markTxAsFailed, "f").call(this, transactionMeta);
|
|
626
|
+
// Track failed event
|
|
627
|
+
if (status !== transaction_controller_1.TransactionStatus.rejected) {
|
|
628
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, id, (0, metrics_1.getEVMTxPropertiesFromTransactionMeta)(transactionMeta));
|
|
629
|
+
}
|
|
596
630
|
}
|
|
597
631
|
});
|
|
598
632
|
this.messagingSystem.subscribe('TransactionController:transactionConfirmed', (transactionMeta) => {
|
|
599
|
-
const { type, id } = transactionMeta;
|
|
633
|
+
const { type, id, chainId } = transactionMeta;
|
|
600
634
|
if (type === transaction_controller_1.TransactionType.swap) {
|
|
601
635
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, id, (0, metrics_1.getEVMTxPropertiesFromTransactionMeta)(transactionMeta));
|
|
602
636
|
}
|
|
637
|
+
if (type === transaction_controller_1.TransactionType.bridge && !(0, bridge_controller_1.isSolanaChainId)(chainId)) {
|
|
638
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, id);
|
|
639
|
+
}
|
|
603
640
|
});
|
|
604
641
|
// If you close the extension, but keep the browser open, the polling continues
|
|
605
642
|
// If you close the browser, the polling stops
|
|
@@ -608,7 +645,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
608
645
|
}
|
|
609
646
|
}
|
|
610
647
|
exports.BridgeStatusController = BridgeStatusController;
|
|
611
|
-
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionFn = new WeakMap(),
|
|
648
|
+
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionFn = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_updateTransactionFn = new WeakMap(), _BridgeStatusController_estimateGasFeeFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_markTxAsFailed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_getSrcTxHash = new WeakMap(), _BridgeStatusController_updateSrcTxHash = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_handleSolanaTx = new WeakMap(), _BridgeStatusController_waitForHashAndReturnFinalTxMeta = new WeakMap(), _BridgeStatusController_handleApprovalTx = new WeakMap(), _BridgeStatusController_handleEvmTransaction = new WeakMap(), _BridgeStatusController_handleUSDTAllowanceReset = new WeakMap(), _BridgeStatusController_calculateGasFees = new WeakMap(), _BridgeStatusController_handleEvmTransactionBatch = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap(), _BridgeStatusController_instances = new WeakSet(), _BridgeStatusController_getMultichainSelectedAccount = function _BridgeStatusController_getMultichainSelectedAccount() {
|
|
612
649
|
return this.messagingSystem.call('AccountsController:getSelectedMultichainAccount');
|
|
613
650
|
}, _BridgeStatusController_getMultichainSelectedAccountAddress = function _BridgeStatusController_getMultichainSelectedAccountAddress() {
|
|
614
651
|
return __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this)?.address ?? '';
|