@metamask/bridge-status-controller 68.1.0 → 70.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 +30 -1
- package/dist/bridge-status-controller.cjs +123 -221
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +1 -4
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +1 -4
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +9 -13
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +6 -8
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +6 -8
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +10 -14
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +125 -223
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/accounts.cjs +8 -0
- package/dist/utils/accounts.cjs.map +1 -0
- package/dist/utils/accounts.d.cts +36 -0
- package/dist/utils/accounts.d.cts.map +1 -0
- package/dist/utils/accounts.d.mts +36 -0
- package/dist/utils/accounts.d.mts.map +1 -0
- package/dist/utils/accounts.mjs +4 -0
- package/dist/utils/accounts.mjs.map +1 -0
- package/dist/utils/authentication.cjs +15 -0
- package/dist/utils/authentication.cjs.map +1 -0
- package/dist/utils/authentication.d.cts +3 -0
- package/dist/utils/authentication.d.cts.map +1 -0
- package/dist/utils/authentication.d.mts +3 -0
- package/dist/utils/authentication.d.mts.map +1 -0
- package/dist/utils/authentication.mjs +11 -0
- package/dist/utils/authentication.mjs.map +1 -0
- package/dist/utils/bridge-status.cjs +2 -4
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +2 -4
- package/dist/utils/bridge-status.mjs.map +1 -1
- package/dist/utils/bridge.cjs +16 -0
- package/dist/utils/bridge.cjs.map +1 -0
- package/dist/utils/bridge.d.cts +10 -0
- package/dist/utils/bridge.d.cts.map +1 -0
- package/dist/utils/bridge.d.mts +10 -0
- package/dist/utils/bridge.d.mts.map +1 -0
- package/dist/utils/bridge.mjs +11 -0
- package/dist/utils/bridge.mjs.map +1 -0
- package/dist/utils/gas.cjs +4 -7
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +1 -1
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +1 -1
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +4 -7
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/history.cjs +97 -0
- package/dist/utils/history.cjs.map +1 -0
- package/dist/utils/history.d.cts +21 -0
- package/dist/utils/history.d.cts.map +1 -0
- package/dist/utils/history.d.mts +21 -0
- package/dist/utils/history.d.mts.map +1 -0
- package/dist/utils/history.mjs +90 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/intent-api.cjs +18 -3
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +16 -7
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +16 -7
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +18 -4
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/keyring.cjs +12 -0
- package/dist/utils/keyring.cjs.map +1 -0
- package/dist/utils/keyring.d.cts +8 -0
- package/dist/utils/keyring.d.cts.map +1 -0
- package/dist/utils/keyring.d.mts +8 -0
- package/dist/utils/keyring.d.mts.map +1 -0
- package/dist/utils/keyring.mjs +8 -0
- package/dist/utils/keyring.mjs.map +1 -0
- package/dist/utils/network.cjs +17 -0
- package/dist/utils/network.cjs.map +1 -0
- package/dist/utils/network.d.cts +5 -0
- package/dist/utils/network.d.cts.map +1 -0
- package/dist/utils/network.d.mts +5 -0
- package/dist/utils/network.d.mts.map +1 -0
- package/dist/utils/network.mjs +12 -0
- package/dist/utils/network.mjs.map +1 -0
- package/dist/utils/snaps.cjs +146 -1
- package/dist/utils/snaps.cjs.map +1 -1
- package/dist/utils/snaps.d.cts +62 -0
- package/dist/utils/snaps.d.cts.map +1 -1
- package/dist/utils/snaps.d.mts +62 -0
- package/dist/utils/snaps.d.mts.map +1 -1
- package/dist/utils/snaps.mjs +141 -0
- package/dist/utils/snaps.mjs.map +1 -1
- package/dist/utils/trace.cjs +31 -0
- package/dist/utils/trace.cjs.map +1 -0
- package/dist/utils/trace.d.cts +17 -0
- package/dist/utils/trace.d.cts.map +1 -0
- package/dist/utils/trace.d.mts +17 -0
- package/dist/utils/trace.d.mts.map +1 -0
- package/dist/utils/trace.mjs +26 -0
- package/dist/utils/trace.mjs.map +1 -0
- package/dist/utils/transaction.cjs +31 -193
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +8 -79
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +8 -79
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +31 -187
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.cjs +5 -5
- package/dist/utils/validators.cjs.map +1 -1
- package/dist/utils/validators.d.cts +6 -11
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +6 -11
- package/dist/utils/validators.d.mts.map +1 -1
- package/dist/utils/validators.mjs +3 -3
- package/dist/utils/validators.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -10,22 +10,29 @@ 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
|
|
13
|
+
var _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_trace, _BridgeStatusController_markTxAsFailed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_rekeyHistoryItem, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_getSrcTxHash, _BridgeStatusController_updateSrcTxHash, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, _BridgeStatusController_waitForTxConfirmation, _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");
|
|
17
17
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
|
-
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
19
18
|
const polling_controller_1 = require("@metamask/polling-controller");
|
|
20
19
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
21
20
|
const utils_1 = require("@metamask/utils");
|
|
22
21
|
const bridge_status_controller_intent_1 = require("./bridge-status-controller.intent.cjs");
|
|
23
22
|
const constants_1 = require("./constants.cjs");
|
|
24
23
|
const types_1 = require("./types.cjs");
|
|
24
|
+
const accounts_1 = require("./utils/accounts.cjs");
|
|
25
|
+
const authentication_1 = require("./utils/authentication.cjs");
|
|
26
|
+
const bridge_1 = require("./utils/bridge.cjs");
|
|
25
27
|
const bridge_status_1 = require("./utils/bridge-status.cjs");
|
|
26
28
|
const gas_1 = require("./utils/gas.cjs");
|
|
29
|
+
const history_1 = require("./utils/history.cjs");
|
|
27
30
|
const intent_api_1 = require("./utils/intent-api.cjs");
|
|
31
|
+
const keyring_1 = require("./utils/keyring.cjs");
|
|
28
32
|
const metrics_1 = require("./utils/metrics.cjs");
|
|
33
|
+
const network_1 = require("./utils/network.cjs");
|
|
34
|
+
const snaps_1 = require("./utils/snaps.cjs");
|
|
35
|
+
const trace_1 = require("./utils/trace.cjs");
|
|
29
36
|
const transaction_1 = require("./utils/transaction.cjs");
|
|
30
37
|
const metadata = {
|
|
31
38
|
// We want to persist the bridge status state so that we can show the proper data for the Activity list
|
|
@@ -38,7 +45,7 @@ const metadata = {
|
|
|
38
45
|
},
|
|
39
46
|
};
|
|
40
47
|
class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPollingController)() {
|
|
41
|
-
constructor({ messenger, state, clientId, fetchFn,
|
|
48
|
+
constructor({ messenger, state, clientId, fetchFn, addTransactionBatchFn, config, traceFn, }) {
|
|
42
49
|
super({
|
|
43
50
|
name: constants_1.BRIDGE_STATUS_CONTROLLER_NAME,
|
|
44
51
|
metadata,
|
|
@@ -49,16 +56,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
49
56
|
...state,
|
|
50
57
|
},
|
|
51
58
|
});
|
|
52
|
-
_BridgeStatusController_instances.add(this);
|
|
53
59
|
_BridgeStatusController_pollingTokensByTxMetaId.set(this, {});
|
|
54
60
|
_BridgeStatusController_intentManager.set(this, void 0);
|
|
55
61
|
_BridgeStatusController_clientId.set(this, void 0);
|
|
56
62
|
_BridgeStatusController_fetchFn.set(this, void 0);
|
|
57
63
|
_BridgeStatusController_config.set(this, void 0);
|
|
58
|
-
_BridgeStatusController_addTransactionFn.set(this, void 0);
|
|
59
64
|
_BridgeStatusController_addTransactionBatchFn.set(this, void 0);
|
|
60
|
-
_BridgeStatusController_updateTransactionFn.set(this, void 0);
|
|
61
|
-
_BridgeStatusController_estimateGasFeeFn.set(this, void 0);
|
|
62
65
|
_BridgeStatusController_trace.set(this, void 0);
|
|
63
66
|
// Mark tx as failed in txHistory if either the approval or trade fails
|
|
64
67
|
_BridgeStatusController_markTxAsFailed.set(this, ({ id: txMetaId, actionId, }) => {
|
|
@@ -93,9 +96,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
else {
|
|
96
|
-
const
|
|
97
|
-
const selectedNetworkClient = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
98
|
-
const selectedChainId = selectedNetworkClient.configuration.chainId;
|
|
99
|
+
const selectedChainId = (0, network_1.getSelectedChainId)(this.messenger);
|
|
99
100
|
__classPrivateFieldGet(this, _BridgeStatusController_wipeBridgeStatusByChainId, "f").call(this, address, selectedChainId);
|
|
100
101
|
}
|
|
101
102
|
};
|
|
@@ -137,7 +138,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
137
138
|
}
|
|
138
139
|
});
|
|
139
140
|
// Restart polling if it was stopped and this tx still needs status updates
|
|
140
|
-
if (
|
|
141
|
+
if ((0, history_1.shouldPollHistoryItem)(historyItem)) {
|
|
141
142
|
// Check if polling was stopped (no active polling token)
|
|
142
143
|
const existingPollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[targetTxMetaId];
|
|
143
144
|
if (!existingPollingToken) {
|
|
@@ -145,7 +146,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
145
146
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, targetTxMetaId);
|
|
146
147
|
// Track polling manually restarted event
|
|
147
148
|
if (!historyItem.featureId) {
|
|
148
|
-
const selectedAccount = this.messenger
|
|
149
|
+
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
|
|
149
150
|
const requestParams = (0, metrics_1.getRequestParamFromHistory)(historyItem);
|
|
150
151
|
const requestMetadata = (0, metrics_1.getRequestMetadataFromHistory)(historyItem, selectedAccount);
|
|
151
152
|
const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
|
|
@@ -194,7 +195,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
194
195
|
})
|
|
195
196
|
// Only restart polling for items that still require status updates
|
|
196
197
|
.filter((historyItem) => {
|
|
197
|
-
return
|
|
198
|
+
return (0, history_1.shouldPollHistoryItem)(historyItem);
|
|
198
199
|
});
|
|
199
200
|
incompleteHistoryItems.forEach((historyItem) => {
|
|
200
201
|
const bridgeTxMetaId = historyItem.txMetaId;
|
|
@@ -207,51 +208,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
207
208
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeTxMetaId);
|
|
208
209
|
});
|
|
209
210
|
});
|
|
210
|
-
_BridgeStatusController_addTxToHistory.set(this, (
|
|
211
|
-
const {
|
|
212
|
-
// Determine the key for this history item:
|
|
213
|
-
// - For pre-submission (non-batch EVM): use actionId
|
|
214
|
-
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
215
|
-
const historyKey = (0, transaction_1.getHistoryKey)(actionId, bridgeTxMeta?.id);
|
|
216
|
-
// Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
|
|
217
|
-
// We know it's in progress but not the exact status yet
|
|
218
|
-
const txHistoryItem = {
|
|
219
|
-
txMetaId: bridgeTxMeta?.id,
|
|
220
|
-
actionId,
|
|
221
|
-
originalTransactionId: bridgeTxMeta
|
|
222
|
-
?.originalTransactionId || bridgeTxMeta?.id, // Keep original for intent transactions
|
|
223
|
-
batchId: bridgeTxMeta?.batchId,
|
|
224
|
-
quote: quoteResponse.quote,
|
|
225
|
-
startTime,
|
|
226
|
-
estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
|
|
227
|
-
slippagePercentage,
|
|
228
|
-
pricingData: {
|
|
229
|
-
amountSent: quoteResponse.sentAmount?.amount ?? '0',
|
|
230
|
-
amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,
|
|
231
|
-
quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,
|
|
232
|
-
quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,
|
|
233
|
-
quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,
|
|
234
|
-
},
|
|
235
|
-
initialDestAssetBalance,
|
|
236
|
-
targetContractAddress,
|
|
237
|
-
account: selectedAddress,
|
|
238
|
-
status: {
|
|
239
|
-
// We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that
|
|
240
|
-
// Also we know the bare minimum fields for status at this point in time
|
|
241
|
-
status: bridge_controller_1.StatusTypes.PENDING,
|
|
242
|
-
srcChain: {
|
|
243
|
-
chainId: statusRequest.srcChainId,
|
|
244
|
-
txHash: statusRequest.srcTxHash,
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
hasApprovalTx: Boolean(quoteResponse.approval),
|
|
248
|
-
approvalTxId,
|
|
249
|
-
isStxEnabled: isStxEnabled ?? false,
|
|
250
|
-
featureId: quoteResponse.featureId,
|
|
251
|
-
location,
|
|
252
|
-
...(abTests && { abTests }),
|
|
253
|
-
...(activeAbTests && { activeAbTests }),
|
|
254
|
-
};
|
|
211
|
+
_BridgeStatusController_addTxToHistory.set(this, (...args) => {
|
|
212
|
+
const { historyKey, txHistoryItem } = (0, history_1.getInitialHistoryItem)(...args);
|
|
255
213
|
this.update((state) => {
|
|
256
214
|
// Use actionId as key for pre-submission, or txMeta.id for post-submission
|
|
257
215
|
state.txHistory[historyKey] = txHistoryItem;
|
|
@@ -268,7 +226,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
268
226
|
*/
|
|
269
227
|
_BridgeStatusController_rekeyHistoryItem.set(this, (actionId, txMeta) => {
|
|
270
228
|
this.update((state) => {
|
|
271
|
-
(0,
|
|
229
|
+
(0, history_1.rekeyHistoryItemInState)(state, actionId, txMeta);
|
|
272
230
|
});
|
|
273
231
|
});
|
|
274
232
|
_BridgeStatusController_startPollingForTxId.set(this, (txId) => {
|
|
@@ -281,18 +239,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
281
239
|
if (!txHistoryItem) {
|
|
282
240
|
return;
|
|
283
241
|
}
|
|
284
|
-
if (
|
|
242
|
+
if ((0, history_1.shouldPollHistoryItem)(txHistoryItem)) {
|
|
285
243
|
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
|
286
244
|
bridgeTxMetaId: txId,
|
|
287
245
|
});
|
|
288
246
|
}
|
|
289
247
|
});
|
|
290
|
-
_BridgeStatusController_shouldPollHistoryItem.set(this, (historyItem) => {
|
|
291
|
-
const isIntent = Boolean(historyItem?.quote?.intent);
|
|
292
|
-
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
|
|
293
|
-
const isTronTx = (0, bridge_controller_1.isTronChainId)(historyItem.quote.srcChainId);
|
|
294
|
-
return [isBridgeTx, isIntent, isTronTx].some(Boolean);
|
|
295
|
-
});
|
|
296
248
|
/**
|
|
297
249
|
* @deprecated For EVM/Solana swap/bridge txs we add tx to history in submitTx()
|
|
298
250
|
* For Solana swap/bridge we start polling in submitTx()
|
|
@@ -344,7 +296,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
344
296
|
// Track max polling reached event
|
|
345
297
|
const historyItem = this.state.txHistory[bridgeTxMetaId];
|
|
346
298
|
if (historyItem && !historyItem.featureId) {
|
|
347
|
-
const selectedAccount = this.messenger
|
|
299
|
+
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
|
|
348
300
|
const requestParams = (0, metrics_1.getRequestParamFromHistory)(historyItem);
|
|
349
301
|
const requestMetadata = (0, metrics_1.getRequestMetadataFromHistory)(historyItem, selectedAccount);
|
|
350
302
|
const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
|
|
@@ -382,9 +334,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
382
334
|
try {
|
|
383
335
|
let status;
|
|
384
336
|
let validationFailures = [];
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const intentTxStatus = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").getIntentTransactionStatus(bridgeTxMetaId, historyItem, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
|
|
337
|
+
if (historyItem.quote.intent) {
|
|
338
|
+
const intentTxStatus = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").getIntentTransactionStatus(bridgeTxMetaId, historyItem.quote.srcChainId, historyItem.quote.intent.protocol, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), historyItem.status.srcChain.txHash);
|
|
388
339
|
if (intentTxStatus?.bridgeStatus === null ||
|
|
389
340
|
intentTxStatus?.bridgeStatus === undefined) {
|
|
390
341
|
return;
|
|
@@ -401,7 +352,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
401
352
|
}
|
|
402
353
|
__classPrivateFieldGet(this, _BridgeStatusController_updateSrcTxHash, "f").call(this, bridgeTxMetaId, srcTxHash);
|
|
403
354
|
const statusRequest = (0, bridge_status_1.getStatusRequestWithSrcTxHash)(historyItem.quote, srcTxHash);
|
|
404
|
-
const response = await (0, bridge_status_1.fetchBridgeTxStatus)(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), await
|
|
355
|
+
const response = await (0, bridge_status_1.fetchBridgeTxStatus)(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), await (0, authentication_1.getJwt)(this.messenger), __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl);
|
|
405
356
|
status = response.status;
|
|
406
357
|
validationFailures = response.validationFailures;
|
|
407
358
|
}
|
|
@@ -429,7 +380,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
429
380
|
this.update((state) => {
|
|
430
381
|
state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
|
|
431
382
|
});
|
|
432
|
-
if (
|
|
383
|
+
if (historyItem.quote.intent) {
|
|
433
384
|
__classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").syncTransactionFromIntentStatus(bridgeTxMetaId, historyItem);
|
|
434
385
|
}
|
|
435
386
|
// 5. After effects
|
|
@@ -457,16 +408,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
457
408
|
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
|
458
409
|
}
|
|
459
410
|
});
|
|
460
|
-
_BridgeStatusController_getJwt.set(this, async () => {
|
|
461
|
-
try {
|
|
462
|
-
const token = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
463
|
-
return token;
|
|
464
|
-
}
|
|
465
|
-
catch (error) {
|
|
466
|
-
console.error('Error getting JWT token for bridge-api request', error);
|
|
467
|
-
return undefined;
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
411
|
_BridgeStatusController_getSrcTxHash.set(this, (bridgeTxMetaId) => {
|
|
471
412
|
const { txHistory } = this.state;
|
|
472
413
|
// Prefer the srcTxHash from bridgeStatusState so we don't have to l ook up in TransactionController
|
|
@@ -516,34 +457,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
516
457
|
* TX SUBMISSION HANDLING
|
|
517
458
|
*******************************************************
|
|
518
459
|
*/
|
|
519
|
-
/**
|
|
520
|
-
* Submits the transaction to the snap using the new unified ClientRequest interface
|
|
521
|
-
* Works for all non-EVM chains (Solana, BTC, Tron)
|
|
522
|
-
* This adds an approval tx to the ApprovalsController in the background
|
|
523
|
-
* The client needs to handle the approval tx by redirecting to the confirmation page with the approvalTxId in the URL
|
|
524
|
-
*
|
|
525
|
-
* @param trade - The trade data (can be approval or main trade)
|
|
526
|
-
* @param quoteResponse - The quote response containing metadata
|
|
527
|
-
* @param selectedAccount - The account to submit the transaction for
|
|
528
|
-
* @returns The transaction meta
|
|
529
|
-
*/
|
|
530
|
-
_BridgeStatusController_handleNonEvmTx.set(this, async (trade, quoteResponse, selectedAccount) => {
|
|
531
|
-
if (!selectedAccount.metadata?.snap?.id) {
|
|
532
|
-
throw new Error('Failed to submit cross-chain swap transaction: undefined snap id');
|
|
533
|
-
}
|
|
534
|
-
const request = (0, transaction_1.getClientRequest)(trade, quoteResponse.quote.srcChainId, selectedAccount);
|
|
535
|
-
const requestResponse = (await this.messenger.call('SnapController:handleRequest', request));
|
|
536
|
-
// Create quote response with the specified trade
|
|
537
|
-
// This allows the same method to handle both approvals and main trades
|
|
538
|
-
const txQuoteResponse = {
|
|
539
|
-
...quoteResponse,
|
|
540
|
-
trade,
|
|
541
|
-
};
|
|
542
|
-
const txMeta = (0, transaction_1.handleNonEvmTxResponse)(requestResponse, txQuoteResponse, selectedAccount);
|
|
543
|
-
// TODO remove this eventually, just returning it now to match extension behavior
|
|
544
|
-
// OR if the snap can propagate the snapRequestId or keyringReqId to the ApprovalsController, this can return the approvalTxId instead and clients won't need to subscribe to the ApprovalsController state to redirect
|
|
545
|
-
return txMeta;
|
|
546
|
-
});
|
|
547
460
|
_BridgeStatusController_waitForHashAndReturnFinalTxMeta.set(this, async (hashPromise) => {
|
|
548
461
|
const transactionHash = await hashPromise;
|
|
549
462
|
const finalTransactionMeta = this.messenger
|
|
@@ -562,8 +475,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
562
475
|
pollMs,
|
|
563
476
|
});
|
|
564
477
|
});
|
|
565
|
-
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
566
|
-
if (approval) {
|
|
478
|
+
_BridgeStatusController_handleApprovalTx.set(this, async (quoteResponse, isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
479
|
+
if (approval && (0, bridge_controller_1.isEvmTxData)(approval)) {
|
|
567
480
|
const approveTx = async () => {
|
|
568
481
|
await __classPrivateFieldGet(this, _BridgeStatusController_handleUSDTAllowanceReset, "f").call(this, resetApproval);
|
|
569
482
|
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
@@ -576,15 +489,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
576
489
|
await (0, transaction_1.handleApprovalDelay)(srcChainId);
|
|
577
490
|
return approvalTxMeta;
|
|
578
491
|
};
|
|
579
|
-
return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this,
|
|
580
|
-
name: isBridgeTx
|
|
581
|
-
? constants_1.TraceName.BridgeTransactionApprovalCompleted
|
|
582
|
-
: constants_1.TraceName.SwapTransactionApprovalCompleted,
|
|
583
|
-
data: {
|
|
584
|
-
srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(srcChainId),
|
|
585
|
-
stxEnabled: false,
|
|
586
|
-
},
|
|
587
|
-
}, approveTx);
|
|
492
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getApprovalTraceParams)(quoteResponse, false), approveTx);
|
|
588
493
|
}
|
|
589
494
|
return undefined;
|
|
590
495
|
});
|
|
@@ -603,13 +508,13 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
603
508
|
*/
|
|
604
509
|
_BridgeStatusController_handleEvmTransaction.set(this, async ({ transactionType, trade, requireApproval = false, txFee, actionId: providedActionId, }) => {
|
|
605
510
|
// Use provided actionId (for pre-submission history) or generate one
|
|
606
|
-
const actionId = providedActionId ?? (0, transaction_1.generateActionId)()
|
|
607
|
-
const selectedAccount = this.messenger
|
|
511
|
+
const actionId = providedActionId ?? (0, transaction_1.generateActionId)();
|
|
512
|
+
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, trade.from);
|
|
608
513
|
if (!selectedAccount) {
|
|
609
514
|
throw new Error('Failed to submit cross-chain swap transaction: unknown account in trade data');
|
|
610
515
|
}
|
|
611
516
|
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(trade.chainId);
|
|
612
|
-
const networkClientId = this.messenger
|
|
517
|
+
const networkClientId = (0, network_1.getNetworkClientIdByChainId)(this.messenger, hexChainId);
|
|
613
518
|
const requestOptions = {
|
|
614
519
|
actionId,
|
|
615
520
|
networkClientId,
|
|
@@ -633,7 +538,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
633
538
|
...transactionParams,
|
|
634
539
|
...(await __classPrivateFieldGet(this, _BridgeStatusController_calculateGasFees, "f").call(this, transactionParams, networkClientId, hexChainId, txFee)),
|
|
635
540
|
};
|
|
636
|
-
const { result } = await
|
|
541
|
+
const { result } = await this.messenger.call('TransactionController:addTransaction', transactionParamsWithMaxGas, requestOptions);
|
|
637
542
|
return await __classPrivateFieldGet(this, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, "f").call(this, result);
|
|
638
543
|
});
|
|
639
544
|
_BridgeStatusController_handleUSDTAllowanceReset.set(this, async (resetApproval) => {
|
|
@@ -650,17 +555,13 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
650
555
|
// Convert to hex since txFee values from the quote are decimal strings
|
|
651
556
|
if (txFee) {
|
|
652
557
|
return {
|
|
653
|
-
maxFeePerGas: (0, controller_utils_1.toHex)(txFee.maxFeePerGas
|
|
654
|
-
maxPriorityFeePerGas: (0, controller_utils_1.toHex)(txFee.maxPriorityFeePerGas
|
|
558
|
+
maxFeePerGas: (0, controller_utils_1.toHex)(txFee.maxFeePerGas),
|
|
559
|
+
maxPriorityFeePerGas: (0, controller_utils_1.toHex)(txFee.maxPriorityFeePerGas),
|
|
655
560
|
gas: gas ? (0, controller_utils_1.toHex)(gas) : undefined,
|
|
656
561
|
};
|
|
657
562
|
}
|
|
658
563
|
const { gasFeeEstimates } = this.messenger.call('GasFeeController:getState');
|
|
659
|
-
const { estimates: txGasFeeEstimates } = await
|
|
660
|
-
transactionParams,
|
|
661
|
-
chainId,
|
|
662
|
-
networkClientId,
|
|
663
|
-
});
|
|
564
|
+
const { estimates: txGasFeeEstimates } = await this.messenger.call('TransactionController:estimateGasFee', { transactionParams, chainId, networkClientId });
|
|
664
565
|
const { maxFeePerGas, maxPriorityFeePerGas } = (0, gas_1.getTxGasEstimates)({
|
|
665
566
|
networkGasFeeEstimates: gasFeeEstimates,
|
|
666
567
|
txGasFeeEstimates,
|
|
@@ -686,7 +587,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
686
587
|
_BridgeStatusController_handleEvmTransactionBatch.set(this, async (args) => {
|
|
687
588
|
const transactionParams = await (0, transaction_1.getAddTransactionBatchParams)({
|
|
688
589
|
messenger: this.messenger,
|
|
689
|
-
estimateGasFeeFn: __classPrivateFieldGet(this, _BridgeStatusController_estimateGasFeeFn, "f"),
|
|
690
590
|
...args,
|
|
691
591
|
});
|
|
692
592
|
const txDataByType = {
|
|
@@ -698,7 +598,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
698
598
|
const { batchId } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f").call(this, transactionParams);
|
|
699
599
|
const { approvalMeta, tradeMeta } = (0, transaction_1.findAndUpdateTransactionsInBatch)({
|
|
700
600
|
messenger: this.messenger,
|
|
701
|
-
updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
|
|
702
601
|
batchId,
|
|
703
602
|
txDataByType,
|
|
704
603
|
});
|
|
@@ -720,11 +619,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
720
619
|
* @returns The transaction meta
|
|
721
620
|
*/
|
|
722
621
|
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests) => {
|
|
723
|
-
this.messenger
|
|
724
|
-
|
|
725
|
-
// If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
|
|
726
|
-
quoteResponse.featureId ? undefined : quotesReceivedContext);
|
|
727
|
-
const selectedAccount = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this, accountAddress);
|
|
622
|
+
(0, bridge_1.stopPollingForQuotes)(this.messenger, quoteResponse.featureId, quotesReceivedContext);
|
|
623
|
+
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
|
|
728
624
|
if (!selectedAccount) {
|
|
729
625
|
throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
|
|
730
626
|
}
|
|
@@ -735,6 +631,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
735
631
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
|
736
632
|
let txMeta;
|
|
737
633
|
let approvalTxId;
|
|
634
|
+
let isDelegatedAccount = false;
|
|
738
635
|
const startTime = Date.now();
|
|
739
636
|
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
740
637
|
const isTronTx = (0, bridge_controller_1.isTronChainId)(quoteResponse.quote.srcChainId);
|
|
@@ -742,20 +639,14 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
742
639
|
if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
|
|
743
640
|
// Handle non-EVM approval if present (e.g., Tron token approvals)
|
|
744
641
|
if (quoteResponse.approval && (0, bridge_controller_1.isTronTrade)(quoteResponse.approval)) {
|
|
745
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
746
|
-
name: isBridgeTx
|
|
747
|
-
? constants_1.TraceName.BridgeTransactionApprovalCompleted
|
|
748
|
-
: constants_1.TraceName.SwapTransactionApprovalCompleted,
|
|
749
|
-
data: {
|
|
750
|
-
srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(quoteResponse.quote.srcChainId),
|
|
751
|
-
stxEnabled: false,
|
|
752
|
-
},
|
|
753
|
-
}, async () => {
|
|
642
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getApprovalTraceParams)(quoteResponse, false), async () => {
|
|
754
643
|
try {
|
|
755
644
|
return quoteResponse.approval &&
|
|
756
645
|
(0, bridge_controller_1.isTronTrade)(quoteResponse.approval)
|
|
757
|
-
? await
|
|
758
|
-
:
|
|
646
|
+
? await (0, snaps_1.handleNonEvmTx)(this.messenger, quoteResponse.approval, quoteResponse, selectedAccount)
|
|
647
|
+
: /* c8 ignore start */
|
|
648
|
+
undefined;
|
|
649
|
+
/* c8 ignore end */
|
|
759
650
|
}
|
|
760
651
|
catch (error) {
|
|
761
652
|
!quoteResponse.featureId &&
|
|
@@ -770,26 +661,18 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
770
661
|
// Add delay after approval similar to EVM flow
|
|
771
662
|
await (0, transaction_1.handleApprovalDelay)(quoteResponse.quote.srcChainId);
|
|
772
663
|
}
|
|
773
|
-
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
774
|
-
name: isBridgeTx
|
|
775
|
-
? constants_1.TraceName.BridgeTransactionCompleted
|
|
776
|
-
: constants_1.TraceName.SwapTransactionCompleted,
|
|
777
|
-
data: {
|
|
778
|
-
srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(quoteResponse.quote.srcChainId),
|
|
779
|
-
stxEnabled: false,
|
|
780
|
-
},
|
|
781
|
-
}, async () => {
|
|
664
|
+
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, false), async () => {
|
|
782
665
|
try {
|
|
783
666
|
if (!((0, bridge_controller_1.isTronTrade)(quoteResponse.trade) ||
|
|
784
667
|
(0, bridge_controller_1.isBitcoinTrade)(quoteResponse.trade) ||
|
|
785
668
|
typeof quoteResponse.trade === 'string')) {
|
|
786
669
|
throw new Error('Failed to submit cross-chain swap transaction: trade is not a non-EVM transaction');
|
|
787
670
|
}
|
|
788
|
-
return await
|
|
671
|
+
return await (0, snaps_1.handleNonEvmTx)(this.messenger, quoteResponse.trade, quoteResponse, selectedAccount);
|
|
789
672
|
}
|
|
790
673
|
catch (error) {
|
|
791
674
|
!quoteResponse.featureId &&
|
|
792
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed,
|
|
675
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
793
676
|
error_message: error?.message,
|
|
794
677
|
...preConfirmationProperties,
|
|
795
678
|
});
|
|
@@ -803,19 +686,30 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
803
686
|
// Extension does not have this issue
|
|
804
687
|
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE && isHardwareAccount;
|
|
805
688
|
// Handle smart transactions if enabled
|
|
806
|
-
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
807
|
-
name: isBridgeTx
|
|
808
|
-
? constants_1.TraceName.BridgeTransactionCompleted
|
|
809
|
-
: constants_1.TraceName.SwapTransactionCompleted,
|
|
810
|
-
data: {
|
|
811
|
-
srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(quoteResponse.quote.srcChainId),
|
|
812
|
-
stxEnabled: isStxEnabledOnClient,
|
|
813
|
-
},
|
|
814
|
-
}, async () => {
|
|
689
|
+
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, isStxEnabledOnClient), async () => {
|
|
815
690
|
if (!(0, bridge_controller_1.isEvmTxData)(quoteResponse.trade)) {
|
|
816
691
|
throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
|
|
817
692
|
}
|
|
818
|
-
if
|
|
693
|
+
// Check if the account is an EIP-7702 delegated account
|
|
694
|
+
// Delegated accounts only allow 1 in-flight tx, so approve + swap
|
|
695
|
+
// must be batched into a single transaction
|
|
696
|
+
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId);
|
|
697
|
+
isDelegatedAccount = await (async () => {
|
|
698
|
+
try {
|
|
699
|
+
const atomicBatchSupport = await this.messenger.call('TransactionController:isAtomicBatchSupported', {
|
|
700
|
+
address: quoteResponse.trade
|
|
701
|
+
.from,
|
|
702
|
+
chainIds: [hexChainId],
|
|
703
|
+
});
|
|
704
|
+
return atomicBatchSupport.some((entry) => entry.isSupported && entry.delegationAddress);
|
|
705
|
+
}
|
|
706
|
+
catch {
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
})();
|
|
710
|
+
if (isStxEnabledOnClient ||
|
|
711
|
+
quoteResponse.quote.gasIncluded7702 ||
|
|
712
|
+
isDelegatedAccount) {
|
|
819
713
|
const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
|
|
820
714
|
isBridgeTx,
|
|
821
715
|
resetApproval: quoteResponse.resetApproval,
|
|
@@ -825,12 +719,13 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
825
719
|
trade: quoteResponse.trade,
|
|
826
720
|
quoteResponse,
|
|
827
721
|
requireApproval,
|
|
722
|
+
isDelegatedAccount,
|
|
828
723
|
});
|
|
829
724
|
approvalTxId = approvalMeta?.id;
|
|
830
725
|
return tradeMeta;
|
|
831
726
|
}
|
|
832
727
|
// Set approval time and id if an approval tx is needed
|
|
833
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
|
|
728
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
|
|
834
729
|
? quoteResponse.approval
|
|
835
730
|
: undefined, quoteResponse.resetApproval, requireApproval);
|
|
836
731
|
approvalTxId = approvalTxMeta?.id;
|
|
@@ -877,7 +772,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
877
772
|
// Only add history here for non-EVM and batch EVM transactions
|
|
878
773
|
const isNonBatchEvm = !(0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId) &&
|
|
879
774
|
!isStxEnabledOnClient &&
|
|
880
|
-
!quoteResponse.quote.gasIncluded7702
|
|
775
|
+
!quoteResponse.quote.gasIncluded7702 &&
|
|
776
|
+
!isDelegatedAccount;
|
|
881
777
|
if (!isNonBatchEvm) {
|
|
882
778
|
// Add swap or bridge tx to history
|
|
883
779
|
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
@@ -925,35 +821,32 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
925
821
|
*/
|
|
926
822
|
this.submitIntent = async (params) => {
|
|
927
823
|
const { quoteResponse, accountAddress, location, abTests, activeAbTests } = params;
|
|
928
|
-
|
|
824
|
+
// TODO add metrics context
|
|
825
|
+
(0, bridge_1.stopPollingForQuotes)(this.messenger);
|
|
929
826
|
// Build pre-confirmation properties for error tracking parity with submitTx
|
|
930
|
-
const account =
|
|
827
|
+
const account = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
|
|
931
828
|
const isHardwareAccount = Boolean(account) && (0, bridge_controller_1.isHardwareWallet)(account);
|
|
932
829
|
const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, false, isHardwareAccount, location, abTests, activeAbTests);
|
|
933
830
|
try {
|
|
934
|
-
const intent = (0,
|
|
831
|
+
const intent = (0, intent_api_1.getIntentFromQuote)(quoteResponse);
|
|
935
832
|
// If backend provided an approval tx for this intent quote, submit it first (on-chain),
|
|
936
833
|
// then proceed with off-chain intent submission.
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
/* requireApproval */ false);
|
|
945
|
-
approvalTxId = approvalTxMeta?.id;
|
|
946
|
-
if (approvalTxId) {
|
|
947
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
|
|
948
|
-
}
|
|
834
|
+
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
835
|
+
const requireApproval = isHardwareAccount && __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE;
|
|
836
|
+
// Handle approval silently for better UX in intent flows
|
|
837
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
|
|
838
|
+
const approvalTxId = approvalTxMeta?.id;
|
|
839
|
+
if (approvalTxId) {
|
|
840
|
+
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
|
|
949
841
|
}
|
|
950
|
-
const { srcChainId
|
|
951
|
-
const signature = await
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
842
|
+
const { srcChainId, requestId } = quoteResponse.quote;
|
|
843
|
+
const signature = await (0, keyring_1.signTypedMessage)({
|
|
844
|
+
messenger: this.messenger,
|
|
845
|
+
accountAddress,
|
|
846
|
+
typedData: intent.typedData,
|
|
847
|
+
});
|
|
955
848
|
const submissionParams = {
|
|
956
|
-
srcChainId
|
|
849
|
+
srcChainId,
|
|
957
850
|
quoteId: requestId,
|
|
958
851
|
signature,
|
|
959
852
|
order: intent.order,
|
|
@@ -963,16 +856,17 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
963
856
|
const intentOrder = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").submitIntent(submissionParams, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
|
|
964
857
|
const orderUid = intentOrder.id;
|
|
965
858
|
// Determine transaction type: swap for same-chain, bridge for cross-chain
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
:
|
|
859
|
+
const transactionType = isBridgeTx
|
|
860
|
+
? /* c8 ignore start */
|
|
861
|
+
transaction_controller_1.TransactionType.bridge
|
|
862
|
+
: /* c8 ignore end */
|
|
863
|
+
transaction_controller_1.TransactionType.swap;
|
|
970
864
|
// Create actual transaction in Transaction Controller first
|
|
971
|
-
const networkClientId =
|
|
865
|
+
const networkClientId = (0, network_1.getNetworkClientIdByChainId)(this.messenger, srcChainId);
|
|
972
866
|
// This is a synthetic transaction whose purpose is to be able
|
|
973
867
|
// to track the order status via the history
|
|
974
868
|
const intentTransactionParams = {
|
|
975
|
-
chainId: (0, bridge_controller_1.formatChainIdToHex)(
|
|
869
|
+
chainId: (0, bridge_controller_1.formatChainIdToHex)(srcChainId),
|
|
976
870
|
from: accountAddress,
|
|
977
871
|
to: intent.settlementContract ??
|
|
978
872
|
'0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract
|
|
@@ -981,7 +875,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
981
875
|
gas: '0x5208', // Minimal gas for display purposes
|
|
982
876
|
gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it
|
|
983
877
|
};
|
|
984
|
-
const { transactionMeta: txMetaPromise } = await
|
|
878
|
+
const { transactionMeta: txMetaPromise } = await this.messenger.call('TransactionController:addTransaction', intentTransactionParams, {
|
|
985
879
|
origin: 'metamask',
|
|
986
880
|
actionId: (0, transaction_1.generateActionId)(),
|
|
987
881
|
requireApproval: false,
|
|
@@ -1002,7 +896,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1002
896
|
...statusUpdatedTxMeta,
|
|
1003
897
|
isIntentTx: true,
|
|
1004
898
|
orderUid,
|
|
1005
|
-
intentType: isCrossChainTx ? 'bridge' : 'swap',
|
|
1006
899
|
};
|
|
1007
900
|
// Record in bridge history with actual transaction metadata
|
|
1008
901
|
try {
|
|
@@ -1082,24 +975,36 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1082
975
|
};
|
|
1083
976
|
// This will publish events for PERPS dropped tx failures as well
|
|
1084
977
|
if (!txMetaId) {
|
|
1085
|
-
|
|
978
|
+
(0, bridge_1.trackMetricsEvent)({
|
|
979
|
+
messenger: this.messenger,
|
|
980
|
+
eventName,
|
|
981
|
+
properties: baseProperties,
|
|
982
|
+
});
|
|
1086
983
|
return;
|
|
1087
984
|
}
|
|
1088
985
|
const historyItem = this.state.txHistory[txMetaId];
|
|
1089
986
|
if (!historyItem) {
|
|
1090
|
-
|
|
987
|
+
(0, bridge_1.trackMetricsEvent)({
|
|
988
|
+
messenger: this.messenger,
|
|
989
|
+
eventName,
|
|
990
|
+
properties: baseProperties,
|
|
991
|
+
});
|
|
1091
992
|
return;
|
|
1092
993
|
}
|
|
1093
994
|
const requestParamProperties = (0, metrics_1.getRequestParamFromHistory)(historyItem);
|
|
1094
995
|
// Always publish StatusValidationFailed event, regardless of featureId
|
|
1095
996
|
if (eventName === bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
997
|
+
(0, bridge_1.trackMetricsEvent)({
|
|
998
|
+
messenger: this.messenger,
|
|
999
|
+
eventName,
|
|
1000
|
+
properties: {
|
|
1001
|
+
...baseProperties,
|
|
1002
|
+
chain_id_source: requestParamProperties.chain_id_source,
|
|
1003
|
+
chain_id_destination: requestParamProperties.chain_id_destination,
|
|
1004
|
+
token_address_source: requestParamProperties.token_address_source,
|
|
1005
|
+
token_address_destination: requestParamProperties.token_address_destination,
|
|
1006
|
+
refresh_count: historyItem.attempts?.counter ?? 0,
|
|
1007
|
+
},
|
|
1103
1008
|
});
|
|
1104
1009
|
return;
|
|
1105
1010
|
}
|
|
@@ -1107,7 +1012,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1107
1012
|
if (historyItem.featureId) {
|
|
1108
1013
|
return;
|
|
1109
1014
|
}
|
|
1110
|
-
const selectedAccount = this.messenger
|
|
1015
|
+
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
|
|
1111
1016
|
const { transactions } = this.messenger.call('TransactionController:getState');
|
|
1112
1017
|
const txMeta = transactions?.find((tx) => tx.id === txMetaId);
|
|
1113
1018
|
const approvalTxMeta = transactions?.find((tx) => tx.id === historyItem.approvalTxId);
|
|
@@ -1120,24 +1025,23 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1120
1025
|
...(0, metrics_1.getFinalizedTxProperties)(historyItem, txMeta, approvalTxMeta),
|
|
1121
1026
|
...(0, metrics_1.getPriceImpactFromQuote)(historyItem.quote),
|
|
1122
1027
|
};
|
|
1123
|
-
|
|
1028
|
+
(0, bridge_1.trackMetricsEvent)({
|
|
1029
|
+
messenger: this.messenger,
|
|
1030
|
+
eventName,
|
|
1031
|
+
properties: requiredEventProperties,
|
|
1032
|
+
});
|
|
1124
1033
|
});
|
|
1125
1034
|
__classPrivateFieldSet(this, _BridgeStatusController_clientId, clientId, "f");
|
|
1126
1035
|
__classPrivateFieldSet(this, _BridgeStatusController_fetchFn, fetchFn, "f");
|
|
1127
|
-
__classPrivateFieldSet(this, _BridgeStatusController_addTransactionFn, addTransactionFn, "f");
|
|
1128
1036
|
__classPrivateFieldSet(this, _BridgeStatusController_addTransactionBatchFn, addTransactionBatchFn, "f");
|
|
1129
|
-
__classPrivateFieldSet(this, _BridgeStatusController_updateTransactionFn, updateTransactionFn, "f");
|
|
1130
|
-
__classPrivateFieldSet(this, _BridgeStatusController_estimateGasFeeFn, estimateGasFeeFn, "f");
|
|
1131
1037
|
__classPrivateFieldSet(this, _BridgeStatusController_config, {
|
|
1132
1038
|
customBridgeApiBaseUrl: config?.customBridgeApiBaseUrl ?? constants_1.BRIDGE_PROD_API_BASE_URL,
|
|
1133
1039
|
}, "f");
|
|
1134
1040
|
__classPrivateFieldSet(this, _BridgeStatusController_trace, traceFn ?? ((_request, fn) => fn?.()), "f");
|
|
1135
1041
|
__classPrivateFieldSet(this, _BridgeStatusController_intentManager, new bridge_status_controller_intent_1.IntentManager({
|
|
1136
1042
|
messenger: this.messenger,
|
|
1137
|
-
updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
|
|
1138
1043
|
customBridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
|
|
1139
1044
|
fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
|
|
1140
|
-
getJwt: __classPrivateFieldGet(this, _BridgeStatusController_getJwt, "f"),
|
|
1141
1045
|
}), "f");
|
|
1142
1046
|
// Register action handlers
|
|
1143
1047
|
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:startPollingForBridgeTxStatus`, this.startPollingForBridgeTxStatus.bind(this));
|
|
@@ -1195,7 +1099,5 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1195
1099
|
}
|
|
1196
1100
|
}
|
|
1197
1101
|
exports.BridgeStatusController = BridgeStatusController;
|
|
1198
|
-
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(),
|
|
1199
|
-
return this.messenger.call('AccountsController:getAccountByAddress', accountAddress);
|
|
1200
|
-
};
|
|
1102
|
+
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_markTxAsFailed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_rekeyHistoryItem = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_getSrcTxHash = new WeakMap(), _BridgeStatusController_updateSrcTxHash = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_waitForHashAndReturnFinalTxMeta = new WeakMap(), _BridgeStatusController_waitForTxConfirmation = 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();
|
|
1201
1103
|
//# sourceMappingURL=bridge-status-controller.cjs.map
|