@metamask-previews/bridge-status-controller 69.0.0-preview-45f35b773 → 69.0.0-preview-e0f8f1907
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 +4 -0
- package/dist/bridge-status-controller.cjs +73 -175
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +3 -2
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +2 -3
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +2 -3
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +3 -2
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +75 -177
- 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/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.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/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 +16 -1
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +9 -1
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +9 -1
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +14 -0
- 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 +6 -177
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +2 -73
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +2 -73
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +6 -171
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.d.cts +2 -2
- package/dist/utils/validators.d.mts +2 -2
- package/package.json +1 -1
|
@@ -9,21 +9,28 @@ 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
|
|
13
|
-
import { formatChainIdToHex, isNonEvmChainId, StatusTypes, UnifiedSwapBridgeEventName,
|
|
12
|
+
var _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_updateTransactionFn, _BridgeStatusController_estimateGasFeeFn, _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;
|
|
13
|
+
import { formatChainIdToHex, isNonEvmChainId, StatusTypes, UnifiedSwapBridgeEventName, isCrossChain, isTronChainId, isEvmTxData, isHardwareWallet, MetricsActionType, MetaMetricsSwapsEventSource, isBitcoinTrade, isTronTrade, PollingStatus } from "@metamask/bridge-controller";
|
|
14
14
|
import { toHex } from "@metamask/controller-utils";
|
|
15
|
-
import { SignTypedDataVersion } from "@metamask/keyring-controller";
|
|
16
15
|
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
17
16
|
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
18
17
|
import { numberToHex } from "@metamask/utils";
|
|
19
18
|
import { IntentManager } from "./bridge-status-controller.intent.mjs";
|
|
20
|
-
import { BRIDGE_PROD_API_BASE_URL, BRIDGE_STATUS_CONTROLLER_NAME, DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE, MAX_ATTEMPTS, REFRESH_INTERVAL_MS
|
|
19
|
+
import { BRIDGE_PROD_API_BASE_URL, BRIDGE_STATUS_CONTROLLER_NAME, DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE, MAX_ATTEMPTS, REFRESH_INTERVAL_MS } from "./constants.mjs";
|
|
21
20
|
import { BridgeClientId } from "./types.mjs";
|
|
21
|
+
import { getAccountByAddress } from "./utils/accounts.mjs";
|
|
22
|
+
import { getJwt } from "./utils/authentication.mjs";
|
|
23
|
+
import { stopPollingForQuotes, trackMetricsEvent } from "./utils/bridge.mjs";
|
|
22
24
|
import { fetchBridgeTxStatus, getStatusRequestWithSrcTxHash, shouldSkipFetchDueToFetchFailures } from "./utils/bridge-status.mjs";
|
|
23
25
|
import { getTxGasEstimates } from "./utils/gas.mjs";
|
|
24
|
-
import {
|
|
26
|
+
import { getInitialHistoryItem, rekeyHistoryItemInState, shouldPollHistoryItem } from "./utils/history.mjs";
|
|
27
|
+
import { getIntentFromQuote, mapIntentOrderStatusToTransactionStatus } from "./utils/intent-api.mjs";
|
|
28
|
+
import { signTypedMessage } from "./utils/keyring.mjs";
|
|
25
29
|
import { getFinalizedTxProperties, getPriceImpactFromQuote, getRequestMetadataFromHistory, getRequestParamFromHistory, getTradeDataFromHistory, getEVMTxPropertiesFromTransactionMeta, getTxStatusesFromHistory, getPreConfirmationPropertiesFromQuote } from "./utils/metrics.mjs";
|
|
26
|
-
import {
|
|
30
|
+
import { getNetworkClientIdByChainId, getSelectedChainId } from "./utils/network.mjs";
|
|
31
|
+
import { handleNonEvmTx } from "./utils/snaps.mjs";
|
|
32
|
+
import { getApprovalTraceParams, getTraceParams } from "./utils/trace.mjs";
|
|
33
|
+
import { findAndUpdateTransactionsInBatch, getAddTransactionBatchParams, getStatusRequestParams, handleApprovalDelay, handleMobileHardwareWalletDelay, generateActionId, waitForTxConfirmation } from "./utils/transaction.mjs";
|
|
27
34
|
const metadata = {
|
|
28
35
|
// We want to persist the bridge status state so that we can show the proper data for the Activity list
|
|
29
36
|
// basically match the behavior of TransactionController
|
|
@@ -46,7 +53,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
46
53
|
...state,
|
|
47
54
|
},
|
|
48
55
|
});
|
|
49
|
-
_BridgeStatusController_instances.add(this);
|
|
50
56
|
_BridgeStatusController_pollingTokensByTxMetaId.set(this, {});
|
|
51
57
|
_BridgeStatusController_intentManager.set(this, void 0);
|
|
52
58
|
_BridgeStatusController_clientId.set(this, void 0);
|
|
@@ -90,9 +96,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
90
96
|
});
|
|
91
97
|
}
|
|
92
98
|
else {
|
|
93
|
-
const
|
|
94
|
-
const selectedNetworkClient = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
95
|
-
const selectedChainId = selectedNetworkClient.configuration.chainId;
|
|
99
|
+
const selectedChainId = getSelectedChainId(this.messenger);
|
|
96
100
|
__classPrivateFieldGet(this, _BridgeStatusController_wipeBridgeStatusByChainId, "f").call(this, address, selectedChainId);
|
|
97
101
|
}
|
|
98
102
|
};
|
|
@@ -134,7 +138,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
134
138
|
}
|
|
135
139
|
});
|
|
136
140
|
// Restart polling if it was stopped and this tx still needs status updates
|
|
137
|
-
if (
|
|
141
|
+
if (shouldPollHistoryItem(historyItem)) {
|
|
138
142
|
// Check if polling was stopped (no active polling token)
|
|
139
143
|
const existingPollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[targetTxMetaId];
|
|
140
144
|
if (!existingPollingToken) {
|
|
@@ -142,7 +146,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
142
146
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, targetTxMetaId);
|
|
143
147
|
// Track polling manually restarted event
|
|
144
148
|
if (!historyItem.featureId) {
|
|
145
|
-
const selectedAccount = this.messenger
|
|
149
|
+
const selectedAccount = getAccountByAddress(this.messenger, historyItem.account);
|
|
146
150
|
const requestParams = getRequestParamFromHistory(historyItem);
|
|
147
151
|
const requestMetadata = getRequestMetadataFromHistory(historyItem, selectedAccount);
|
|
148
152
|
const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
|
|
@@ -191,7 +195,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
191
195
|
})
|
|
192
196
|
// Only restart polling for items that still require status updates
|
|
193
197
|
.filter((historyItem) => {
|
|
194
|
-
return
|
|
198
|
+
return shouldPollHistoryItem(historyItem);
|
|
195
199
|
});
|
|
196
200
|
incompleteHistoryItems.forEach((historyItem) => {
|
|
197
201
|
const bridgeTxMetaId = historyItem.txMetaId;
|
|
@@ -204,51 +208,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
204
208
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeTxMetaId);
|
|
205
209
|
});
|
|
206
210
|
});
|
|
207
|
-
_BridgeStatusController_addTxToHistory.set(this, (
|
|
208
|
-
const {
|
|
209
|
-
// Determine the key for this history item:
|
|
210
|
-
// - For pre-submission (non-batch EVM): use actionId
|
|
211
|
-
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
212
|
-
const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id);
|
|
213
|
-
// Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
|
|
214
|
-
// We know it's in progress but not the exact status yet
|
|
215
|
-
const txHistoryItem = {
|
|
216
|
-
txMetaId: bridgeTxMeta?.id,
|
|
217
|
-
actionId,
|
|
218
|
-
originalTransactionId: bridgeTxMeta
|
|
219
|
-
?.originalTransactionId || bridgeTxMeta?.id, // Keep original for intent transactions
|
|
220
|
-
batchId: bridgeTxMeta?.batchId,
|
|
221
|
-
quote: quoteResponse.quote,
|
|
222
|
-
startTime,
|
|
223
|
-
estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
|
|
224
|
-
slippagePercentage,
|
|
225
|
-
pricingData: {
|
|
226
|
-
amountSent: quoteResponse.sentAmount?.amount ?? '0',
|
|
227
|
-
amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,
|
|
228
|
-
quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,
|
|
229
|
-
quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,
|
|
230
|
-
quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,
|
|
231
|
-
},
|
|
232
|
-
initialDestAssetBalance,
|
|
233
|
-
targetContractAddress,
|
|
234
|
-
account: selectedAddress,
|
|
235
|
-
status: {
|
|
236
|
-
// We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that
|
|
237
|
-
// Also we know the bare minimum fields for status at this point in time
|
|
238
|
-
status: StatusTypes.PENDING,
|
|
239
|
-
srcChain: {
|
|
240
|
-
chainId: statusRequest.srcChainId,
|
|
241
|
-
txHash: statusRequest.srcTxHash,
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
hasApprovalTx: Boolean(quoteResponse.approval),
|
|
245
|
-
approvalTxId,
|
|
246
|
-
isStxEnabled: Boolean(isStxEnabled),
|
|
247
|
-
featureId: quoteResponse.featureId,
|
|
248
|
-
location,
|
|
249
|
-
...(abTests && { abTests }),
|
|
250
|
-
...(activeAbTests && { activeAbTests }),
|
|
251
|
-
};
|
|
211
|
+
_BridgeStatusController_addTxToHistory.set(this, (...args) => {
|
|
212
|
+
const { historyKey, txHistoryItem } = getInitialHistoryItem(...args);
|
|
252
213
|
this.update((state) => {
|
|
253
214
|
// Use actionId as key for pre-submission, or txMeta.id for post-submission
|
|
254
215
|
state.txHistory[historyKey] = txHistoryItem;
|
|
@@ -278,18 +239,12 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
278
239
|
if (!txHistoryItem) {
|
|
279
240
|
return;
|
|
280
241
|
}
|
|
281
|
-
if (
|
|
242
|
+
if (shouldPollHistoryItem(txHistoryItem)) {
|
|
282
243
|
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
|
283
244
|
bridgeTxMetaId: txId,
|
|
284
245
|
});
|
|
285
246
|
}
|
|
286
247
|
});
|
|
287
|
-
_BridgeStatusController_shouldPollHistoryItem.set(this, (historyItem) => {
|
|
288
|
-
const isIntent = Boolean(historyItem?.quote?.intent);
|
|
289
|
-
const isBridgeTx = isCrossChain(historyItem.quote.srcChainId, historyItem.quote.destChainId);
|
|
290
|
-
const isTronTx = isTronChainId(historyItem.quote.srcChainId);
|
|
291
|
-
return [isBridgeTx, isIntent, isTronTx].some(Boolean);
|
|
292
|
-
});
|
|
293
248
|
/**
|
|
294
249
|
* @deprecated For EVM/Solana swap/bridge txs we add tx to history in submitTx()
|
|
295
250
|
* For Solana swap/bridge we start polling in submitTx()
|
|
@@ -341,7 +296,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
341
296
|
// Track max polling reached event
|
|
342
297
|
const historyItem = this.state.txHistory[bridgeTxMetaId];
|
|
343
298
|
if (historyItem && !historyItem.featureId) {
|
|
344
|
-
const selectedAccount = this.messenger
|
|
299
|
+
const selectedAccount = getAccountByAddress(this.messenger, historyItem.account);
|
|
345
300
|
const requestParams = getRequestParamFromHistory(historyItem);
|
|
346
301
|
const requestMetadata = getRequestMetadataFromHistory(historyItem, selectedAccount);
|
|
347
302
|
const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
|
|
@@ -397,7 +352,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
397
352
|
}
|
|
398
353
|
__classPrivateFieldGet(this, _BridgeStatusController_updateSrcTxHash, "f").call(this, bridgeTxMetaId, srcTxHash);
|
|
399
354
|
const statusRequest = getStatusRequestWithSrcTxHash(historyItem.quote, srcTxHash);
|
|
400
|
-
const response = await fetchBridgeTxStatus(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), await
|
|
355
|
+
const response = await fetchBridgeTxStatus(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), await getJwt(this.messenger), __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl);
|
|
401
356
|
status = response.status;
|
|
402
357
|
validationFailures = response.validationFailures;
|
|
403
358
|
}
|
|
@@ -453,16 +408,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
453
408
|
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
|
454
409
|
}
|
|
455
410
|
});
|
|
456
|
-
_BridgeStatusController_getJwt.set(this, async () => {
|
|
457
|
-
try {
|
|
458
|
-
const token = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
459
|
-
return token;
|
|
460
|
-
}
|
|
461
|
-
catch (error) {
|
|
462
|
-
console.error('Error getting JWT token for bridge-api request', error);
|
|
463
|
-
return undefined;
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
411
|
_BridgeStatusController_getSrcTxHash.set(this, (bridgeTxMetaId) => {
|
|
467
412
|
const { txHistory } = this.state;
|
|
468
413
|
// Prefer the srcTxHash from bridgeStatusState so we don't have to l ook up in TransactionController
|
|
@@ -512,34 +457,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
512
457
|
* TX SUBMISSION HANDLING
|
|
513
458
|
*******************************************************
|
|
514
459
|
*/
|
|
515
|
-
/**
|
|
516
|
-
* Submits the transaction to the snap using the new unified ClientRequest interface
|
|
517
|
-
* Works for all non-EVM chains (Solana, BTC, Tron)
|
|
518
|
-
* This adds an approval tx to the ApprovalsController in the background
|
|
519
|
-
* The client needs to handle the approval tx by redirecting to the confirmation page with the approvalTxId in the URL
|
|
520
|
-
*
|
|
521
|
-
* @param trade - The trade data (can be approval or main trade)
|
|
522
|
-
* @param quoteResponse - The quote response containing metadata
|
|
523
|
-
* @param selectedAccount - The account to submit the transaction for
|
|
524
|
-
* @returns The transaction meta
|
|
525
|
-
*/
|
|
526
|
-
_BridgeStatusController_handleNonEvmTx.set(this, async (trade, quoteResponse, selectedAccount) => {
|
|
527
|
-
if (!selectedAccount.metadata?.snap?.id) {
|
|
528
|
-
throw new Error('Failed to submit cross-chain swap transaction: undefined snap id');
|
|
529
|
-
}
|
|
530
|
-
const request = getClientRequest(trade, quoteResponse.quote.srcChainId, selectedAccount);
|
|
531
|
-
const requestResponse = (await this.messenger.call('SnapController:handleRequest', request));
|
|
532
|
-
// Create quote response with the specified trade
|
|
533
|
-
// This allows the same method to handle both approvals and main trades
|
|
534
|
-
const txQuoteResponse = {
|
|
535
|
-
...quoteResponse,
|
|
536
|
-
trade,
|
|
537
|
-
};
|
|
538
|
-
const txMeta = handleNonEvmTxResponse(requestResponse, txQuoteResponse, selectedAccount);
|
|
539
|
-
// TODO remove this eventually, just returning it now to match extension behavior
|
|
540
|
-
// 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
|
|
541
|
-
return txMeta;
|
|
542
|
-
});
|
|
543
460
|
_BridgeStatusController_waitForHashAndReturnFinalTxMeta.set(this, async (hashPromise) => {
|
|
544
461
|
const transactionHash = await hashPromise;
|
|
545
462
|
const finalTransactionMeta = this.messenger
|
|
@@ -558,7 +475,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
558
475
|
pollMs,
|
|
559
476
|
});
|
|
560
477
|
});
|
|
561
|
-
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
478
|
+
_BridgeStatusController_handleApprovalTx.set(this, async (quoteResponse, isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
562
479
|
if (approval && isEvmTxData(approval)) {
|
|
563
480
|
const approveTx = async () => {
|
|
564
481
|
await __classPrivateFieldGet(this, _BridgeStatusController_handleUSDTAllowanceReset, "f").call(this, resetApproval);
|
|
@@ -572,15 +489,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
572
489
|
await handleApprovalDelay(srcChainId);
|
|
573
490
|
return approvalTxMeta;
|
|
574
491
|
};
|
|
575
|
-
return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this,
|
|
576
|
-
name: isBridgeTx
|
|
577
|
-
? TraceName.BridgeTransactionApprovalCompleted
|
|
578
|
-
: TraceName.SwapTransactionApprovalCompleted,
|
|
579
|
-
data: {
|
|
580
|
-
srcChainId: formatChainIdToCaip(srcChainId),
|
|
581
|
-
stxEnabled: false,
|
|
582
|
-
},
|
|
583
|
-
}, approveTx);
|
|
492
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getApprovalTraceParams(quoteResponse, false), approveTx);
|
|
584
493
|
}
|
|
585
494
|
return undefined;
|
|
586
495
|
});
|
|
@@ -599,13 +508,13 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
599
508
|
*/
|
|
600
509
|
_BridgeStatusController_handleEvmTransaction.set(this, async ({ transactionType, trade, requireApproval = false, txFee, actionId: providedActionId, }) => {
|
|
601
510
|
// Use provided actionId (for pre-submission history) or generate one
|
|
602
|
-
const actionId = providedActionId ?? generateActionId()
|
|
603
|
-
const selectedAccount = this.messenger
|
|
511
|
+
const actionId = providedActionId ?? generateActionId();
|
|
512
|
+
const selectedAccount = getAccountByAddress(this.messenger, trade.from);
|
|
604
513
|
if (!selectedAccount) {
|
|
605
514
|
throw new Error('Failed to submit cross-chain swap transaction: unknown account in trade data');
|
|
606
515
|
}
|
|
607
516
|
const hexChainId = formatChainIdToHex(trade.chainId);
|
|
608
|
-
const networkClientId = this.messenger
|
|
517
|
+
const networkClientId = getNetworkClientIdByChainId(this.messenger, hexChainId);
|
|
609
518
|
const requestOptions = {
|
|
610
519
|
actionId,
|
|
611
520
|
networkClientId,
|
|
@@ -716,11 +625,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
716
625
|
* @returns The transaction meta
|
|
717
626
|
*/
|
|
718
627
|
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests) => {
|
|
719
|
-
this.messenger
|
|
720
|
-
|
|
721
|
-
// 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
|
|
722
|
-
quoteResponse.featureId ? undefined : quotesReceivedContext);
|
|
723
|
-
const selectedAccount = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this, accountAddress);
|
|
628
|
+
stopPollingForQuotes(this.messenger, quoteResponse.featureId, quotesReceivedContext);
|
|
629
|
+
const selectedAccount = getAccountByAddress(this.messenger, accountAddress);
|
|
724
630
|
if (!selectedAccount) {
|
|
725
631
|
throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
|
|
726
632
|
}
|
|
@@ -739,19 +645,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
739
645
|
if (isNonEvmChainId(quoteResponse.quote.srcChainId)) {
|
|
740
646
|
// Handle non-EVM approval if present (e.g., Tron token approvals)
|
|
741
647
|
if (quoteResponse.approval && isTronTrade(quoteResponse.approval)) {
|
|
742
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
743
|
-
name: isBridgeTx
|
|
744
|
-
? TraceName.BridgeTransactionApprovalCompleted
|
|
745
|
-
: TraceName.SwapTransactionApprovalCompleted,
|
|
746
|
-
data: {
|
|
747
|
-
srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),
|
|
748
|
-
stxEnabled: false,
|
|
749
|
-
},
|
|
750
|
-
}, async () => {
|
|
648
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getApprovalTraceParams(quoteResponse, false), async () => {
|
|
751
649
|
try {
|
|
752
650
|
return quoteResponse.approval &&
|
|
753
651
|
isTronTrade(quoteResponse.approval)
|
|
754
|
-
? await
|
|
652
|
+
? await handleNonEvmTx(this.messenger, quoteResponse.approval, quoteResponse, selectedAccount)
|
|
755
653
|
: /* c8 ignore start */
|
|
756
654
|
undefined;
|
|
757
655
|
/* c8 ignore end */
|
|
@@ -769,22 +667,14 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
769
667
|
// Add delay after approval similar to EVM flow
|
|
770
668
|
await handleApprovalDelay(quoteResponse.quote.srcChainId);
|
|
771
669
|
}
|
|
772
|
-
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
773
|
-
name: isBridgeTx
|
|
774
|
-
? TraceName.BridgeTransactionCompleted
|
|
775
|
-
: TraceName.SwapTransactionCompleted,
|
|
776
|
-
data: {
|
|
777
|
-
srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),
|
|
778
|
-
stxEnabled: false,
|
|
779
|
-
},
|
|
780
|
-
}, async () => {
|
|
670
|
+
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getTraceParams(quoteResponse, false), async () => {
|
|
781
671
|
try {
|
|
782
672
|
if (!(isTronTrade(quoteResponse.trade) ||
|
|
783
673
|
isBitcoinTrade(quoteResponse.trade) ||
|
|
784
674
|
typeof quoteResponse.trade === 'string')) {
|
|
785
675
|
throw new Error('Failed to submit cross-chain swap transaction: trade is not a non-EVM transaction');
|
|
786
676
|
}
|
|
787
|
-
return await
|
|
677
|
+
return await handleNonEvmTx(this.messenger, quoteResponse.trade, quoteResponse, selectedAccount);
|
|
788
678
|
}
|
|
789
679
|
catch (error) {
|
|
790
680
|
!quoteResponse.featureId &&
|
|
@@ -802,15 +692,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
802
692
|
// Extension does not have this issue
|
|
803
693
|
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === BridgeClientId.MOBILE && isHardwareAccount;
|
|
804
694
|
// Handle smart transactions if enabled
|
|
805
|
-
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
|
806
|
-
name: isBridgeTx
|
|
807
|
-
? TraceName.BridgeTransactionCompleted
|
|
808
|
-
: TraceName.SwapTransactionCompleted,
|
|
809
|
-
data: {
|
|
810
|
-
srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),
|
|
811
|
-
stxEnabled: isStxEnabledOnClient,
|
|
812
|
-
},
|
|
813
|
-
}, async () => {
|
|
695
|
+
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getTraceParams(quoteResponse, isStxEnabledOnClient), async () => {
|
|
814
696
|
if (!isEvmTxData(quoteResponse.trade)) {
|
|
815
697
|
throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
|
|
816
698
|
}
|
|
@@ -821,7 +703,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
821
703
|
isDelegatedAccount = await (async () => {
|
|
822
704
|
try {
|
|
823
705
|
const atomicBatchSupport = await this.messenger.call('TransactionController:isAtomicBatchSupported', {
|
|
824
|
-
address: quoteResponse.trade
|
|
706
|
+
address: quoteResponse.trade
|
|
707
|
+
.from,
|
|
825
708
|
chainIds: [hexChainId],
|
|
826
709
|
});
|
|
827
710
|
return atomicBatchSupport.some((entry) => entry.isSupported && entry.delegationAddress);
|
|
@@ -848,7 +731,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
848
731
|
return tradeMeta;
|
|
849
732
|
}
|
|
850
733
|
// Set approval time and id if an approval tx is needed
|
|
851
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && isEvmTxData(quoteResponse.approval)
|
|
734
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && isEvmTxData(quoteResponse.approval)
|
|
852
735
|
? quoteResponse.approval
|
|
853
736
|
: undefined, quoteResponse.resetApproval, requireApproval);
|
|
854
737
|
approvalTxId = approvalTxMeta?.id;
|
|
@@ -944,9 +827,10 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
944
827
|
*/
|
|
945
828
|
this.submitIntent = async (params) => {
|
|
946
829
|
const { quoteResponse, accountAddress, location, abTests, activeAbTests } = params;
|
|
947
|
-
|
|
830
|
+
// TODO add metrics context
|
|
831
|
+
stopPollingForQuotes(this.messenger);
|
|
948
832
|
// Build pre-confirmation properties for error tracking parity with submitTx
|
|
949
|
-
const account =
|
|
833
|
+
const account = getAccountByAddress(this.messenger, accountAddress);
|
|
950
834
|
const isHardwareAccount = Boolean(account) && isHardwareWallet(account);
|
|
951
835
|
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, false, isHardwareAccount, location, abTests, activeAbTests);
|
|
952
836
|
try {
|
|
@@ -956,16 +840,17 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
956
840
|
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
957
841
|
const requireApproval = isHardwareAccount && __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === BridgeClientId.MOBILE;
|
|
958
842
|
// Handle approval silently for better UX in intent flows
|
|
959
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
|
|
843
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
|
|
960
844
|
const approvalTxId = approvalTxMeta?.id;
|
|
961
845
|
if (approvalTxId) {
|
|
962
846
|
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
|
|
963
847
|
}
|
|
964
848
|
const { srcChainId, requestId } = quoteResponse.quote;
|
|
965
|
-
const signature = await
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
849
|
+
const signature = await signTypedMessage({
|
|
850
|
+
messenger: this.messenger,
|
|
851
|
+
accountAddress,
|
|
852
|
+
typedData: intent.typedData,
|
|
853
|
+
});
|
|
969
854
|
const submissionParams = {
|
|
970
855
|
srcChainId,
|
|
971
856
|
quoteId: requestId,
|
|
@@ -983,7 +868,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
983
868
|
: /* c8 ignore end */
|
|
984
869
|
TransactionType.swap;
|
|
985
870
|
// Create actual transaction in Transaction Controller first
|
|
986
|
-
const networkClientId = this.messenger
|
|
871
|
+
const networkClientId = getNetworkClientIdByChainId(this.messenger, srcChainId);
|
|
987
872
|
// This is a synthetic transaction whose purpose is to be able
|
|
988
873
|
// to track the order status via the history
|
|
989
874
|
const intentTransactionParams = {
|
|
@@ -1096,24 +981,36 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1096
981
|
};
|
|
1097
982
|
// This will publish events for PERPS dropped tx failures as well
|
|
1098
983
|
if (!txMetaId) {
|
|
1099
|
-
|
|
984
|
+
trackMetricsEvent({
|
|
985
|
+
messenger: this.messenger,
|
|
986
|
+
eventName,
|
|
987
|
+
properties: baseProperties,
|
|
988
|
+
});
|
|
1100
989
|
return;
|
|
1101
990
|
}
|
|
1102
991
|
const historyItem = this.state.txHistory[txMetaId];
|
|
1103
992
|
if (!historyItem) {
|
|
1104
|
-
|
|
993
|
+
trackMetricsEvent({
|
|
994
|
+
messenger: this.messenger,
|
|
995
|
+
eventName,
|
|
996
|
+
properties: baseProperties,
|
|
997
|
+
});
|
|
1105
998
|
return;
|
|
1106
999
|
}
|
|
1107
1000
|
const requestParamProperties = getRequestParamFromHistory(historyItem);
|
|
1108
1001
|
// Always publish StatusValidationFailed event, regardless of featureId
|
|
1109
1002
|
if (eventName === UnifiedSwapBridgeEventName.StatusValidationFailed) {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1003
|
+
trackMetricsEvent({
|
|
1004
|
+
messenger: this.messenger,
|
|
1005
|
+
eventName,
|
|
1006
|
+
properties: {
|
|
1007
|
+
...baseProperties,
|
|
1008
|
+
chain_id_source: requestParamProperties.chain_id_source,
|
|
1009
|
+
chain_id_destination: requestParamProperties.chain_id_destination,
|
|
1010
|
+
token_address_source: requestParamProperties.token_address_source,
|
|
1011
|
+
token_address_destination: requestParamProperties.token_address_destination,
|
|
1012
|
+
refresh_count: historyItem.attempts?.counter ?? 0,
|
|
1013
|
+
},
|
|
1117
1014
|
});
|
|
1118
1015
|
return;
|
|
1119
1016
|
}
|
|
@@ -1121,7 +1018,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1121
1018
|
if (historyItem.featureId) {
|
|
1122
1019
|
return;
|
|
1123
1020
|
}
|
|
1124
|
-
const selectedAccount = this.messenger
|
|
1021
|
+
const selectedAccount = getAccountByAddress(this.messenger, historyItem.account);
|
|
1125
1022
|
const { transactions } = this.messenger.call('TransactionController:getState');
|
|
1126
1023
|
const txMeta = transactions?.find((tx) => tx.id === txMetaId);
|
|
1127
1024
|
const approvalTxMeta = transactions?.find((tx) => tx.id === historyItem.approvalTxId);
|
|
@@ -1134,7 +1031,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1134
1031
|
...getFinalizedTxProperties(historyItem, txMeta, approvalTxMeta),
|
|
1135
1032
|
...getPriceImpactFromQuote(historyItem.quote),
|
|
1136
1033
|
};
|
|
1137
|
-
|
|
1034
|
+
trackMetricsEvent({
|
|
1035
|
+
messenger: this.messenger,
|
|
1036
|
+
eventName,
|
|
1037
|
+
properties: requiredEventProperties,
|
|
1038
|
+
});
|
|
1138
1039
|
});
|
|
1139
1040
|
__classPrivateFieldSet(this, _BridgeStatusController_clientId, clientId, "f");
|
|
1140
1041
|
__classPrivateFieldSet(this, _BridgeStatusController_fetchFn, fetchFn, "f");
|
|
@@ -1151,7 +1052,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1151
1052
|
updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
|
|
1152
1053
|
customBridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
|
|
1153
1054
|
fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
|
|
1154
|
-
getJwt: __classPrivateFieldGet(this, _BridgeStatusController_getJwt, "f"),
|
|
1155
1055
|
}), "f");
|
|
1156
1056
|
// Register action handlers
|
|
1157
1057
|
this.messenger.registerActionHandler(`${BRIDGE_STATUS_CONTROLLER_NAME}:startPollingForBridgeTxStatus`, this.startPollingForBridgeTxStatus.bind(this));
|
|
@@ -1208,7 +1108,5 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1208
1108
|
__classPrivateFieldGet(this, _BridgeStatusController_restartPollingForIncompleteHistoryItems, "f").call(this);
|
|
1209
1109
|
}
|
|
1210
1110
|
}
|
|
1211
|
-
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = 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_rekeyHistoryItem = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(),
|
|
1212
|
-
return this.messenger.call('AccountsController:getAccountByAddress', accountAddress);
|
|
1213
|
-
};
|
|
1111
|
+
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = 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_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();
|
|
1214
1112
|
//# sourceMappingURL=bridge-status-controller.mjs.map
|