@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
|
@@ -9,20 +9,19 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _BridgeStatusController_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn,
|
|
13
|
-
import { formatChainIdToHex,
|
|
12
|
+
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;
|
|
13
|
+
import { formatChainIdToHex, isSolanaChainId, StatusTypes, UnifiedSwapBridgeEventName, getActionType, formatChainIdToCaip, isCrossChain, getBridgeFeatureFlags, isHardwareWallet } from "@metamask/bridge-controller";
|
|
14
14
|
import { toHex } from "@metamask/controller-utils";
|
|
15
|
-
import {
|
|
15
|
+
import { SolScope } from "@metamask/keyring-api";
|
|
16
16
|
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
17
17
|
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
18
18
|
import { numberToHex } from "@metamask/utils";
|
|
19
|
-
import { BigNumber } from "bignumber.js";
|
|
20
19
|
import { BRIDGE_PROD_API_BASE_URL, BRIDGE_STATUS_CONTROLLER_NAME, DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE, REFRESH_INTERVAL_MS, TraceName } from "./constants.mjs";
|
|
21
20
|
import { BridgeClientId } from "./types.mjs";
|
|
22
21
|
import { fetchBridgeTxStatus, getStatusRequestWithSrcTxHash } from "./utils/bridge-status.mjs";
|
|
23
22
|
import { getTxGasEstimates } from "./utils/gas.mjs";
|
|
24
23
|
import { getFinalizedTxProperties, getPriceImpactFromQuote, getRequestMetadataFromHistory, getRequestParamFromHistory, getTradeDataFromHistory, getTradeDataFromQuote, getEVMTxPropertiesFromTransactionMeta, getTxStatusesFromHistory } from "./utils/metrics.mjs";
|
|
25
|
-
import { getClientRequest, getKeyringRequest, getStatusRequestParams,
|
|
24
|
+
import { findAndUpdateTransactionsInBatch, getAddTransactionBatchParams, getClientRequest, getKeyringRequest, getStatusRequestParams, getUSDTAllowanceResetTx, handleLineaDelay, handleSolanaTxResponse } from "./utils/transaction.mjs";
|
|
26
25
|
import { generateActionId } from "./utils/transaction.mjs";
|
|
27
26
|
const metadata = {
|
|
28
27
|
// We want to persist the bridge status state so that we can show the proper data for the Activity list
|
|
@@ -33,7 +32,7 @@ const metadata = {
|
|
|
33
32
|
},
|
|
34
33
|
};
|
|
35
34
|
export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
36
|
-
constructor({ messenger, state, clientId, fetchFn, addTransactionFn,
|
|
35
|
+
constructor({ messenger, state, clientId, fetchFn, addTransactionFn, addTransactionBatchFn, updateTransactionFn, estimateGasFeeFn, config, traceFn, }) {
|
|
37
36
|
super({
|
|
38
37
|
name: BRIDGE_STATUS_CONTROLLER_NAME,
|
|
39
38
|
metadata,
|
|
@@ -50,9 +49,22 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
50
49
|
_BridgeStatusController_fetchFn.set(this, void 0);
|
|
51
50
|
_BridgeStatusController_config.set(this, void 0);
|
|
52
51
|
_BridgeStatusController_addTransactionFn.set(this, void 0);
|
|
52
|
+
_BridgeStatusController_addTransactionBatchFn.set(this, void 0);
|
|
53
|
+
_BridgeStatusController_updateTransactionFn.set(this, void 0);
|
|
53
54
|
_BridgeStatusController_estimateGasFeeFn.set(this, void 0);
|
|
54
|
-
_BridgeStatusController_addUserOperationFromTransactionFn.set(this, void 0);
|
|
55
55
|
_BridgeStatusController_trace.set(this, void 0);
|
|
56
|
+
// Mark tx as failed in txHistory if either the approval or trade fails
|
|
57
|
+
_BridgeStatusController_markTxAsFailed.set(this, ({ id }) => {
|
|
58
|
+
const txHistoryKey = this.state.txHistory[id]
|
|
59
|
+
? id
|
|
60
|
+
: Object.keys(this.state.txHistory).find((key) => this.state.txHistory[key].approvalTxId === id);
|
|
61
|
+
if (!txHistoryKey) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.update((statusState) => {
|
|
65
|
+
statusState.txHistory[txHistoryKey].status.status = StatusTypes.FAILED;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
56
68
|
this.resetState = () => {
|
|
57
69
|
this.update((state) => {
|
|
58
70
|
state.txHistory = DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE.txHistory;
|
|
@@ -81,8 +93,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
81
93
|
historyItem.status.status === StatusTypes.UNKNOWN)
|
|
82
94
|
.filter((historyItem) => {
|
|
83
95
|
// Check if we are already polling this tx, if so, skip restarting polling for that
|
|
84
|
-
const
|
|
85
|
-
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[srcTxMetaId];
|
|
96
|
+
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[historyItem.txMetaId];
|
|
86
97
|
return !pollingToken;
|
|
87
98
|
})
|
|
88
99
|
// Swap txs don't need to have their statuses polled
|
|
@@ -94,9 +105,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
94
105
|
const bridgeTxMetaId = historyItem.txMetaId;
|
|
95
106
|
// We manually call startPolling() here rather than go through startPollingForBridgeTxStatus()
|
|
96
107
|
// because we don't want to overwrite the existing historyItem in state
|
|
97
|
-
__classPrivateFieldGet(this,
|
|
98
|
-
bridgeTxMetaId,
|
|
99
|
-
});
|
|
108
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeTxMetaId);
|
|
100
109
|
});
|
|
101
110
|
});
|
|
102
111
|
_BridgeStatusController_addTxToHistory.set(this, (startPollingForBridgeTxStatusArgs) => {
|
|
@@ -106,6 +115,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
106
115
|
// We know it's in progress but not the exact status yet
|
|
107
116
|
const txHistoryItem = {
|
|
108
117
|
txMetaId: bridgeTxMeta.id,
|
|
118
|
+
batchId: bridgeTxMeta.batchId,
|
|
109
119
|
quote: quoteResponse.quote,
|
|
110
120
|
startTime,
|
|
111
121
|
estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
|
|
@@ -137,20 +147,33 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
137
147
|
state.txHistory[bridgeTxMeta.id] = txHistoryItem;
|
|
138
148
|
});
|
|
139
149
|
});
|
|
150
|
+
_BridgeStatusController_startPollingForTxId.set(this, (txId) => {
|
|
151
|
+
// If we are already polling for this tx, stop polling for it before restarting
|
|
152
|
+
const existingPollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId];
|
|
153
|
+
if (existingPollingToken) {
|
|
154
|
+
this.stopPollingByPollingToken(existingPollingToken);
|
|
155
|
+
}
|
|
156
|
+
const txHistoryItem = this.state.txHistory[txId];
|
|
157
|
+
if (!txHistoryItem) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const { quote } = txHistoryItem;
|
|
161
|
+
const isBridgeTx = isCrossChain(quote.srcChainId, quote.destChainId);
|
|
162
|
+
if (isBridgeTx) {
|
|
163
|
+
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
|
164
|
+
bridgeTxMetaId: txId,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
140
168
|
/**
|
|
141
|
-
*
|
|
169
|
+
* Adds tx to history and starts polling for the bridge tx status
|
|
142
170
|
*
|
|
143
171
|
* @param txHistoryMeta - The parameters for creating the history item
|
|
144
172
|
*/
|
|
145
173
|
this.startPollingForBridgeTxStatus = (txHistoryMeta) => {
|
|
146
|
-
const {
|
|
174
|
+
const { bridgeTxMeta } = txHistoryMeta;
|
|
147
175
|
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, txHistoryMeta);
|
|
148
|
-
|
|
149
|
-
if (isBridgeTx) {
|
|
150
|
-
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMeta.id] = this.startPolling({
|
|
151
|
-
bridgeTxMetaId: bridgeTxMeta.id,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
176
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeTxMeta.id);
|
|
154
177
|
};
|
|
155
178
|
// This will be called after you call this.startPolling()
|
|
156
179
|
// The args passed in are the args you passed in to startPolling()
|
|
@@ -291,7 +314,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
291
314
|
}
|
|
292
315
|
return finalTransactionMeta;
|
|
293
316
|
});
|
|
294
|
-
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, quoteResponse
|
|
317
|
+
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, quoteResponse) => {
|
|
295
318
|
const { approval } = quoteResponse;
|
|
296
319
|
if (approval) {
|
|
297
320
|
const approveTx = async () => {
|
|
@@ -301,8 +324,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
301
324
|
? TransactionType.bridgeApproval
|
|
302
325
|
: TransactionType.swapApproval,
|
|
303
326
|
trade: approval,
|
|
304
|
-
quoteResponse,
|
|
305
|
-
requireApproval,
|
|
306
327
|
});
|
|
307
328
|
await handleLineaDelay(quoteResponse);
|
|
308
329
|
return approvalTxMeta;
|
|
@@ -319,31 +340,16 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
319
340
|
}
|
|
320
341
|
return undefined;
|
|
321
342
|
});
|
|
322
|
-
_BridgeStatusController_handleEvmSmartTransaction.set(this, async ({ isBridgeTx, trade, quoteResponse, approvalTxId, requireApproval = false, }) => {
|
|
323
|
-
return await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
324
|
-
transactionType: isBridgeTx
|
|
325
|
-
? TransactionType.bridge
|
|
326
|
-
: TransactionType.swap,
|
|
327
|
-
trade,
|
|
328
|
-
quoteResponse,
|
|
329
|
-
approvalTxId,
|
|
330
|
-
shouldWaitForHash: false,
|
|
331
|
-
requireApproval,
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
343
|
/**
|
|
335
344
|
* Submits an EVM transaction to the TransactionController
|
|
336
345
|
*
|
|
337
346
|
* @param params - The parameters for the transaction
|
|
338
347
|
* @param params.transactionType - The type of transaction to submit
|
|
339
348
|
* @param params.trade - The trade data to confirm
|
|
340
|
-
* @param params.quoteResponse - The quote response
|
|
341
|
-
* @param params.approvalTxId - The tx id of the approval tx
|
|
342
|
-
* @param params.shouldWaitForHash - Whether to wait for the hash of the transaction
|
|
343
349
|
* @param params.requireApproval - Whether to require approval for the transaction
|
|
344
350
|
* @returns The transaction meta
|
|
345
351
|
*/
|
|
346
|
-
_BridgeStatusController_handleEvmTransaction.set(this, async ({ transactionType, trade,
|
|
352
|
+
_BridgeStatusController_handleEvmTransaction.set(this, async ({ transactionType, trade, requireApproval = false, }) => {
|
|
347
353
|
const actionId = generateActionId().toString();
|
|
348
354
|
const selectedAccount = this.messagingSystem.call('AccountsController:getAccountByAddress', trade.from);
|
|
349
355
|
if (!selectedAccount) {
|
|
@@ -368,47 +374,16 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
368
374
|
...transactionParams,
|
|
369
375
|
...(await __classPrivateFieldGet(this, _BridgeStatusController_calculateGasFees, "f").call(this, transactionParams, networkClientId, hexChainId)),
|
|
370
376
|
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const isSmartContractAccount = selectedAccount.type === EthAccountType.Erc4337;
|
|
374
|
-
if (isSmartContractAccount && __classPrivateFieldGet(this, _BridgeStatusController_addUserOperationFromTransactionFn, "f")) {
|
|
375
|
-
const smartAccountTxResult = await __classPrivateFieldGet(this, _BridgeStatusController_addUserOperationFromTransactionFn, "f").call(this, transactionParamsWithMaxGas, requestOptions);
|
|
376
|
-
result = smartAccountTxResult.transactionHash;
|
|
377
|
-
transactionMeta = {
|
|
378
|
-
...requestOptions,
|
|
379
|
-
chainId: hexChainId,
|
|
380
|
-
txParams: transactionParamsWithMaxGas,
|
|
381
|
-
time: Date.now(),
|
|
382
|
-
id: smartAccountTxResult.id,
|
|
383
|
-
status: TransactionStatus.confirmed,
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
const addTransactionResult = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, transactionParamsWithMaxGas, requestOptions);
|
|
388
|
-
result = addTransactionResult.result;
|
|
389
|
-
transactionMeta = addTransactionResult.transactionMeta;
|
|
390
|
-
}
|
|
391
|
-
if (shouldWaitForHash) {
|
|
392
|
-
return await __classPrivateFieldGet(this, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, "f").call(this, result);
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
...getTxMetaFields(quoteResponse, approvalTxId),
|
|
396
|
-
...transactionMeta,
|
|
397
|
-
};
|
|
377
|
+
const { result } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, transactionParamsWithMaxGas, requestOptions);
|
|
378
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, "f").call(this, result);
|
|
398
379
|
});
|
|
399
380
|
_BridgeStatusController_handleUSDTAllowanceReset.set(this, async (quoteResponse) => {
|
|
400
|
-
const
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
407
|
-
transactionType: TransactionType.bridgeApproval,
|
|
408
|
-
trade: { ...quoteResponse.approval, data: getEthUsdtResetData() },
|
|
409
|
-
quoteResponse,
|
|
410
|
-
});
|
|
411
|
-
}
|
|
381
|
+
const resetApproval = await getUSDTAllowanceResetTx(this.messagingSystem, quoteResponse);
|
|
382
|
+
if (resetApproval) {
|
|
383
|
+
await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
384
|
+
transactionType: TransactionType.bridgeApproval,
|
|
385
|
+
trade: resetApproval,
|
|
386
|
+
});
|
|
412
387
|
}
|
|
413
388
|
});
|
|
414
389
|
_BridgeStatusController_calculateGasFees.set(this, async (transactionParams, networkClientId, chainId) => {
|
|
@@ -429,6 +404,42 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
429
404
|
gas: maxGasLimit,
|
|
430
405
|
};
|
|
431
406
|
});
|
|
407
|
+
/**
|
|
408
|
+
* Submits batched EVM transactions to the TransactionController
|
|
409
|
+
*
|
|
410
|
+
* @param args - The parameters for the transaction
|
|
411
|
+
* @param args.isBridgeTx - Whether the transaction is a bridge transaction
|
|
412
|
+
* @param args.trade - The trade data to confirm
|
|
413
|
+
* @param args.approval - The approval data to confirm
|
|
414
|
+
* @param args.resetApproval - The ethereum:USDT reset approval data to confirm
|
|
415
|
+
* @param args.quoteResponse - The quote response
|
|
416
|
+
* @param args.requireApproval - Whether to require approval for the transaction
|
|
417
|
+
* @returns The approvalMeta and tradeMeta for the batched transaction
|
|
418
|
+
*/
|
|
419
|
+
_BridgeStatusController_handleEvmTransactionBatch.set(this, async (args) => {
|
|
420
|
+
const transactionParams = await getAddTransactionBatchParams({
|
|
421
|
+
messagingSystem: this.messagingSystem,
|
|
422
|
+
estimateGasFeeFn: __classPrivateFieldGet(this, _BridgeStatusController_estimateGasFeeFn, "f"),
|
|
423
|
+
...args,
|
|
424
|
+
});
|
|
425
|
+
const txDataByType = {
|
|
426
|
+
[TransactionType.bridgeApproval]: transactionParams.transactions.find(({ type }) => type === TransactionType.bridgeApproval)?.params.data,
|
|
427
|
+
[TransactionType.swapApproval]: transactionParams.transactions.find(({ type }) => type === TransactionType.swapApproval)?.params.data,
|
|
428
|
+
[TransactionType.bridge]: transactionParams.transactions.find(({ type }) => type === TransactionType.bridge)?.params.data,
|
|
429
|
+
[TransactionType.swap]: transactionParams.transactions.find(({ type }) => type === TransactionType.swap)?.params.data,
|
|
430
|
+
};
|
|
431
|
+
const { batchId } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f").call(this, transactionParams);
|
|
432
|
+
const { approvalMeta, tradeMeta } = findAndUpdateTransactionsInBatch({
|
|
433
|
+
messagingSystem: this.messagingSystem,
|
|
434
|
+
updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
|
|
435
|
+
batchId,
|
|
436
|
+
txDataByType,
|
|
437
|
+
});
|
|
438
|
+
if (!tradeMeta) {
|
|
439
|
+
throw new Error('Failed to update cross-chain swap transaction batch: tradeMeta not found');
|
|
440
|
+
}
|
|
441
|
+
return { approvalMeta, tradeMeta };
|
|
442
|
+
});
|
|
432
443
|
/**
|
|
433
444
|
* Submits a cross-chain swap transaction
|
|
434
445
|
*
|
|
@@ -451,7 +462,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
451
462
|
// Emit Submitted event after submit button is clicked
|
|
452
463
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
|
453
464
|
let txMeta;
|
|
454
|
-
let
|
|
465
|
+
let approvalTxId;
|
|
466
|
+
const startTime = Date.now();
|
|
455
467
|
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
456
468
|
// Submit SOLANA tx
|
|
457
469
|
if (isSolanaChainId(quoteResponse.quote.srcChainId) &&
|
|
@@ -483,10 +495,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
483
495
|
// Extension does not have this issue
|
|
484
496
|
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === BridgeClientId.MOBILE &&
|
|
485
497
|
isHardwareWallet(__classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this));
|
|
486
|
-
// Set approval time and id if an approval tx is needed
|
|
487
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse, requireApproval);
|
|
488
|
-
approvalTime = approvalTxMeta?.time;
|
|
489
|
-
approvalTxId = approvalTxMeta?.id;
|
|
490
498
|
// Handle smart transactions if enabled
|
|
491
499
|
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
492
500
|
name: isBridgeTx
|
|
@@ -496,27 +504,34 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
496
504
|
srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),
|
|
497
505
|
stxEnabled: isStxEnabledOnClient,
|
|
498
506
|
},
|
|
499
|
-
}, async () =>
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
507
|
+
}, async () => {
|
|
508
|
+
if (isStxEnabledOnClient) {
|
|
509
|
+
const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
|
|
510
|
+
isBridgeTx,
|
|
511
|
+
resetApproval: await getUSDTAllowanceResetTx(this.messagingSystem, quoteResponse),
|
|
512
|
+
approval: quoteResponse.approval,
|
|
513
|
+
trade: quoteResponse.trade,
|
|
514
|
+
quoteResponse,
|
|
515
|
+
requireApproval,
|
|
516
|
+
});
|
|
517
|
+
approvalTxId = approvalMeta?.id;
|
|
518
|
+
return tradeMeta;
|
|
519
|
+
}
|
|
520
|
+
// Set approval time and id if an approval tx is needed
|
|
521
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse);
|
|
522
|
+
approvalTxId = approvalTxMeta?.id;
|
|
523
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
508
524
|
transactionType: isBridgeTx
|
|
509
525
|
? TransactionType.bridge
|
|
510
526
|
: TransactionType.swap,
|
|
511
527
|
trade: quoteResponse.trade,
|
|
512
|
-
quoteResponse,
|
|
513
|
-
approvalTxId,
|
|
514
528
|
requireApproval,
|
|
515
|
-
})
|
|
529
|
+
});
|
|
530
|
+
});
|
|
516
531
|
}
|
|
517
532
|
try {
|
|
518
|
-
//
|
|
519
|
-
this.
|
|
533
|
+
// Add swap or bridge tx to history
|
|
534
|
+
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
520
535
|
bridgeTxMeta: txMeta,
|
|
521
536
|
statusRequest: {
|
|
522
537
|
...getStatusRequestParams(quoteResponse),
|
|
@@ -525,12 +540,16 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
525
540
|
quoteResponse,
|
|
526
541
|
slippagePercentage: 0,
|
|
527
542
|
isStxEnabled: isStxEnabledOnClient,
|
|
528
|
-
startTime
|
|
543
|
+
startTime,
|
|
529
544
|
approvalTxId,
|
|
530
545
|
});
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
__classPrivateFieldGet(this,
|
|
546
|
+
if (isSolanaChainId(quoteResponse.quote.srcChainId)) {
|
|
547
|
+
// Start polling for bridge tx status
|
|
548
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, txMeta.id);
|
|
549
|
+
// Track Solana Swap completed event
|
|
550
|
+
if (!isBridgeTx) {
|
|
551
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Completed, txMeta.id);
|
|
552
|
+
}
|
|
534
553
|
}
|
|
535
554
|
}
|
|
536
555
|
catch {
|
|
@@ -571,7 +590,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
571
590
|
__classPrivateFieldSet(this, _BridgeStatusController_clientId, clientId, "f");
|
|
572
591
|
__classPrivateFieldSet(this, _BridgeStatusController_fetchFn, fetchFn, "f");
|
|
573
592
|
__classPrivateFieldSet(this, _BridgeStatusController_addTransactionFn, addTransactionFn, "f");
|
|
574
|
-
__classPrivateFieldSet(this,
|
|
593
|
+
__classPrivateFieldSet(this, _BridgeStatusController_addTransactionBatchFn, addTransactionBatchFn, "f");
|
|
594
|
+
__classPrivateFieldSet(this, _BridgeStatusController_updateTransactionFn, updateTransactionFn, "f");
|
|
575
595
|
__classPrivateFieldSet(this, _BridgeStatusController_estimateGasFeeFn, estimateGasFeeFn, "f");
|
|
576
596
|
__classPrivateFieldSet(this, _BridgeStatusController_config, {
|
|
577
597
|
customBridgeApiBaseUrl: config?.customBridgeApiBaseUrl ?? BRIDGE_PROD_API_BASE_URL,
|
|
@@ -587,16 +607,33 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
587
607
|
this.messagingSystem.subscribe('TransactionController:transactionFailed', ({ transactionMeta }) => {
|
|
588
608
|
const { type, status, id } = transactionMeta;
|
|
589
609
|
if (type &&
|
|
590
|
-
[
|
|
591
|
-
|
|
592
|
-
|
|
610
|
+
[
|
|
611
|
+
TransactionType.bridge,
|
|
612
|
+
TransactionType.swap,
|
|
613
|
+
TransactionType.bridgeApproval,
|
|
614
|
+
TransactionType.swapApproval,
|
|
615
|
+
].includes(type) &&
|
|
616
|
+
[
|
|
617
|
+
TransactionStatus.failed,
|
|
618
|
+
TransactionStatus.dropped,
|
|
619
|
+
TransactionStatus.rejected,
|
|
620
|
+
].includes(status)) {
|
|
621
|
+
// Mark tx as failed in txHistory
|
|
622
|
+
__classPrivateFieldGet(this, _BridgeStatusController_markTxAsFailed, "f").call(this, transactionMeta);
|
|
623
|
+
// Track failed event
|
|
624
|
+
if (status !== TransactionStatus.rejected) {
|
|
625
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, id, getEVMTxPropertiesFromTransactionMeta(transactionMeta));
|
|
626
|
+
}
|
|
593
627
|
}
|
|
594
628
|
});
|
|
595
629
|
this.messagingSystem.subscribe('TransactionController:transactionConfirmed', (transactionMeta) => {
|
|
596
|
-
const { type, id } = transactionMeta;
|
|
630
|
+
const { type, id, chainId } = transactionMeta;
|
|
597
631
|
if (type === TransactionType.swap) {
|
|
598
632
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Completed, id, getEVMTxPropertiesFromTransactionMeta(transactionMeta));
|
|
599
633
|
}
|
|
634
|
+
if (type === TransactionType.bridge && !isSolanaChainId(chainId)) {
|
|
635
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, id);
|
|
636
|
+
}
|
|
600
637
|
});
|
|
601
638
|
// If you close the extension, but keep the browser open, the polling continues
|
|
602
639
|
// If you close the browser, the polling stops
|
|
@@ -604,7 +641,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
604
641
|
__classPrivateFieldGet(this, _BridgeStatusController_restartPollingForIncompleteHistoryItems, "f").call(this);
|
|
605
642
|
}
|
|
606
643
|
}
|
|
607
|
-
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionFn = new WeakMap(),
|
|
644
|
+
_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() {
|
|
608
645
|
return this.messagingSystem.call('AccountsController:getSelectedMultichainAccount');
|
|
609
646
|
}, _BridgeStatusController_getMultichainSelectedAccountAddress = function _BridgeStatusController_getMultichainSelectedAccountAddress() {
|
|
610
647
|
return __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this)?.address ?? '';
|