@metamask-previews/bridge-status-controller 64.1.0-preview-8cfea65a → 64.2.0-preview-d24ded2
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 +5 -2
- package/dist/bridge-status-controller.cjs +15 -405
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +1 -16
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +1 -16
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +15 -405
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs +7 -9
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +16 -26
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +16 -26
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +7 -9
- package/dist/types.mjs.map +1 -1
- package/dist/utils/transaction.d.cts +2 -21
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +2 -21
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/validators.d.cts +0 -1
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +0 -1
- package/dist/utils/validators.d.mts.map +1 -1
- package/package.json +2 -2
- package/dist/intent-api.cjs +0 -58
- package/dist/intent-api.cjs.map +0 -1
- package/dist/intent-api.d.cts +0 -19
- package/dist/intent-api.d.cts.map +0 -1
- package/dist/intent-api.d.mts +0 -19
- package/dist/intent-api.d.mts.map +0 -1
- package/dist/intent-api.mjs +0 -54
- package/dist/intent-api.mjs.map +0 -1
- package/dist/intent-order-status.cjs +0 -14
- package/dist/intent-order-status.cjs.map +0 -1
- package/dist/intent-order-status.d.cts +0 -10
- package/dist/intent-order-status.d.cts.map +0 -1
- package/dist/intent-order-status.d.mts +0 -10
- package/dist/intent-order-status.d.mts.map +0 -1
- package/dist/intent-order-status.mjs +0 -11
- package/dist/intent-order-status.mjs.map +0 -1
- package/dist/intent-order.cjs +0 -4
- package/dist/intent-order.cjs.map +0 -1
- package/dist/intent-order.d.cts +0 -10
- package/dist/intent-order.d.cts.map +0 -1
- package/dist/intent-order.d.mts +0 -10
- package/dist/intent-order.d.mts.map +0 -1
- package/dist/intent-order.mjs +0 -2
- package/dist/intent-order.mjs.map +0 -1
|
@@ -9,15 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _BridgeStatusController_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_updateTransactionFn, _BridgeStatusController_estimateGasFeeFn, _BridgeStatusController_trace, _BridgeStatusController_markTxAsFailed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_getMultichainSelectedAccount, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_fetchBridgeTxStatus,
|
|
12
|
+
var _BridgeStatusController_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_updateTransactionFn, _BridgeStatusController_estimateGasFeeFn, _BridgeStatusController_trace, _BridgeStatusController_markTxAsFailed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_getMultichainSelectedAccount, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_getSrcTxHash, _BridgeStatusController_updateSrcTxHash, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleNonEvmTx, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransaction, _BridgeStatusController_handleUSDTAllowanceReset, _BridgeStatusController_calculateGasFees, _BridgeStatusController_handleEvmTransactionBatch, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
|
|
13
13
|
import { formatChainIdToHex, isNonEvmChainId, StatusTypes, UnifiedSwapBridgeEventName, formatChainIdToCaip, isCrossChain, isEvmTxData, isHardwareWallet, MetricsActionType, isBitcoinTrade, isTronTrade, AbortReason } from "@metamask/bridge-controller";
|
|
14
14
|
import { toHex } from "@metamask/controller-utils";
|
|
15
15
|
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
16
16
|
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
17
17
|
import { numberToHex } from "@metamask/utils";
|
|
18
18
|
import { BRIDGE_PROD_API_BASE_URL, BRIDGE_STATUS_CONTROLLER_NAME, DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE, MAX_ATTEMPTS, REFRESH_INTERVAL_MS, TraceName } from "./constants.mjs";
|
|
19
|
-
import { IntentApiImpl } from "./intent-api.mjs";
|
|
20
|
-
import { IntentOrderStatus } from "./intent-order-status.mjs";
|
|
21
19
|
import { BridgeClientId } from "./types.mjs";
|
|
22
20
|
import { fetchBridgeTxStatus, getStatusRequestWithSrcTxHash, shouldSkipFetchDueToFetchFailures } from "./utils/bridge-status.mjs";
|
|
23
21
|
import { getTxGasEstimates } from "./utils/gas.mjs";
|
|
@@ -179,8 +177,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
179
177
|
// We know it's in progress but not the exact status yet
|
|
180
178
|
const txHistoryItem = {
|
|
181
179
|
txMetaId: bridgeTxMeta.id,
|
|
182
|
-
originalTransactionId: bridgeTxMeta
|
|
183
|
-
.originalTransactionId || bridgeTxMeta.id, // Keep original for intent transactions
|
|
184
180
|
batchId: bridgeTxMeta.batchId,
|
|
185
181
|
quote: quoteResponse.quote,
|
|
186
182
|
startTime,
|
|
@@ -226,9 +222,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
226
222
|
return;
|
|
227
223
|
}
|
|
228
224
|
const { quote } = txHistoryItem;
|
|
229
|
-
const isIntent = txId.startsWith('intent:');
|
|
230
225
|
const isBridgeTx = isCrossChain(quote.srcChainId, quote.destChainId);
|
|
231
|
-
if (isBridgeTx
|
|
226
|
+
if (isBridgeTx) {
|
|
232
227
|
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
|
233
228
|
bridgeTxMetaId: txId,
|
|
234
229
|
});
|
|
@@ -287,11 +282,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
287
282
|
});
|
|
288
283
|
_BridgeStatusController_fetchBridgeTxStatus.set(this, async ({ bridgeTxMetaId, }) => {
|
|
289
284
|
const { txHistory } = this.state;
|
|
290
|
-
// Intent-based items: poll intent provider instead of Bridge API
|
|
291
|
-
if (bridgeTxMetaId.startsWith('intent:')) {
|
|
292
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_fetchIntentOrderStatus, "f").call(this, { bridgeTxMetaId });
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
285
|
if (shouldSkipFetchDueToFetchFailures(txHistory[bridgeTxMetaId]?.attempts)) {
|
|
296
286
|
return;
|
|
297
287
|
}
|
|
@@ -348,33 +338,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
348
338
|
}
|
|
349
339
|
}
|
|
350
340
|
}
|
|
351
|
-
catch (
|
|
352
|
-
console.warn('Failed to fetch bridge tx status',
|
|
353
|
-
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
_BridgeStatusController_fetchIntentOrderStatus.set(this, async ({ bridgeTxMetaId, }) => {
|
|
357
|
-
const { txHistory } = this.state;
|
|
358
|
-
const historyItem = txHistory[bridgeTxMetaId];
|
|
359
|
-
if (!historyItem) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
// Backoff handling
|
|
363
|
-
if (shouldSkipFetchDueToFetchFailures(historyItem.attempts)) {
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
try {
|
|
367
|
-
const orderId = bridgeTxMetaId.replace(/^intent:/u, '');
|
|
368
|
-
const { srcChainId } = historyItem.quote;
|
|
369
|
-
// Extract provider name from order metadata or default to empty
|
|
370
|
-
const providerName = historyItem.quote.intent?.protocol ?? '';
|
|
371
|
-
const intentApi = new IntentApiImpl(__classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl, __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"));
|
|
372
|
-
const intentOrder = (await intentApi.getOrderStatus(orderId, providerName, srcChainId.toString()));
|
|
373
|
-
// Update bridge history with intent order status
|
|
374
|
-
__classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_updateBridgeHistoryFromIntentOrder).call(this, bridgeTxMetaId, intentOrder, historyItem);
|
|
375
|
-
}
|
|
376
|
-
catch (error) {
|
|
377
|
-
console.error('Failed to fetch intent order status:', error);
|
|
341
|
+
catch (e) {
|
|
342
|
+
console.warn('Failed to fetch bridge tx status', e);
|
|
378
343
|
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
|
379
344
|
}
|
|
380
345
|
});
|
|
@@ -465,36 +430,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
465
430
|
}
|
|
466
431
|
return finalTransactionMeta;
|
|
467
432
|
});
|
|
468
|
-
// Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.
|
|
469
|
-
_BridgeStatusController_waitForTxConfirmation.set(this, async (txId, { timeoutMs = 5 * 60000, // 5 minutes default
|
|
470
|
-
pollMs = 2000, } = {}) => {
|
|
471
|
-
const start = Date.now();
|
|
472
|
-
// Poll the TransactionController state for status changes
|
|
473
|
-
// We intentionally keep this simple to avoid extra wiring/subscriptions in this controller
|
|
474
|
-
// and because we only need it for the rare intent+approval path.
|
|
475
|
-
while (true) {
|
|
476
|
-
const { transactions } = this.messenger.call('TransactionController:getState');
|
|
477
|
-
const meta = transactions.find((tx) => tx.id === txId);
|
|
478
|
-
if (meta) {
|
|
479
|
-
// Treat both 'confirmed' and 'finalized' as success to match TC lifecycle
|
|
480
|
-
if (meta.status === TransactionStatus.confirmed ||
|
|
481
|
-
// Some environments move directly to finalized
|
|
482
|
-
TransactionStatus.finalized ===
|
|
483
|
-
meta.status) {
|
|
484
|
-
return meta;
|
|
485
|
-
}
|
|
486
|
-
if (meta.status === TransactionStatus.failed ||
|
|
487
|
-
meta.status === TransactionStatus.dropped ||
|
|
488
|
-
meta.status === TransactionStatus.rejected) {
|
|
489
|
-
throw new Error('Approval transaction did not confirm');
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
if (Date.now() - start > timeoutMs) {
|
|
493
|
-
throw new Error('Timed out waiting for approval confirmation');
|
|
494
|
-
}
|
|
495
|
-
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
433
|
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
499
434
|
if (approval) {
|
|
500
435
|
const approveTx = async () => {
|
|
@@ -548,17 +483,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
548
483
|
type: transactionType,
|
|
549
484
|
origin: 'metamask',
|
|
550
485
|
};
|
|
551
|
-
// Exclude gasLimit from trade to avoid type issues (it can be null)
|
|
552
|
-
const { gasLimit: tradeGasLimit, ...tradeWithoutGasLimit } = trade;
|
|
553
486
|
const transactionParams = {
|
|
554
|
-
...
|
|
487
|
+
...trade,
|
|
555
488
|
chainId: hexChainId,
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
tradeGasLimit !== 0 && {
|
|
559
|
-
gasLimit: tradeGasLimit.toString(),
|
|
560
|
-
gas: tradeGasLimit.toString(),
|
|
561
|
-
}),
|
|
489
|
+
gasLimit: trade.gasLimit?.toString(),
|
|
490
|
+
gas: trade.gasLimit?.toString(),
|
|
562
491
|
};
|
|
563
492
|
const transactionParamsWithMaxGas = {
|
|
564
493
|
...transactionParams,
|
|
@@ -805,169 +734,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
805
734
|
}
|
|
806
735
|
return txMeta;
|
|
807
736
|
};
|
|
808
|
-
/**
|
|
809
|
-
* UI-signed intent submission (fast path): the UI generates the EIP-712 signature and calls this with the raw signature.
|
|
810
|
-
* Here we submit the order to the intent provider and create a synthetic history entry for UX.
|
|
811
|
-
*
|
|
812
|
-
* @param params - Object containing intent submission parameters
|
|
813
|
-
* @param params.quoteResponse - Quote carrying intent data
|
|
814
|
-
* @param params.signature - Hex signature produced by eth_signTypedData_v4
|
|
815
|
-
* @param params.accountAddress - The EOA submitting the order
|
|
816
|
-
* @returns A lightweight TransactionMeta-like object for history linking
|
|
817
|
-
*/
|
|
818
|
-
this.submitIntent = async (params) => {
|
|
819
|
-
const { quoteResponse, signature, accountAddress } = params;
|
|
820
|
-
// Build pre-confirmation properties for error tracking parity with submitTx
|
|
821
|
-
const account = this.messenger.call('AccountsController:getAccountByAddress', accountAddress);
|
|
822
|
-
const isHardwareAccount = Boolean(account) && isHardwareWallet(account);
|
|
823
|
-
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, false, isHardwareAccount);
|
|
824
|
-
try {
|
|
825
|
-
const { intent } = quoteResponse
|
|
826
|
-
.quote;
|
|
827
|
-
if (!intent) {
|
|
828
|
-
throw new Error('submitIntent: missing intent data');
|
|
829
|
-
}
|
|
830
|
-
// If backend provided an approval tx for this intent quote, submit it first (on-chain),
|
|
831
|
-
// then proceed with off-chain intent submission.
|
|
832
|
-
let approvalTxId;
|
|
833
|
-
if (quoteResponse.approval) {
|
|
834
|
-
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
835
|
-
// Handle approval silently for better UX in intent flows
|
|
836
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && isEvmTxData(quoteResponse.approval)
|
|
837
|
-
? quoteResponse.approval
|
|
838
|
-
: undefined, quoteResponse.resetApproval,
|
|
839
|
-
/* requireApproval */ false);
|
|
840
|
-
approvalTxId = approvalTxMeta?.id;
|
|
841
|
-
// Optionally wait for approval confirmation with timeout and graceful fallback
|
|
842
|
-
// Intent order can be created before allowance is mined, but waiting helps avoid MEV issues
|
|
843
|
-
if (approvalTxId) {
|
|
844
|
-
try {
|
|
845
|
-
// Wait with a shorter timeout and continue if it fails
|
|
846
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId, {
|
|
847
|
-
timeoutMs: 30000, // 30 seconds instead of 5 minutes
|
|
848
|
-
pollMs: 3000, // Poll less frequently to avoid rate limits
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
catch (error) {
|
|
852
|
-
// Log but don't throw - continue with intent order submission
|
|
853
|
-
console.warn('Approval confirmation failed, continuing with intent submission:', error);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
// Create intent quote from bridge quote response
|
|
858
|
-
const intentQuote = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_convertBridgeQuoteToIntentQuote).call(this, quoteResponse, intent);
|
|
859
|
-
const chainId = quoteResponse.quote.srcChainId;
|
|
860
|
-
const submissionParams = {
|
|
861
|
-
srcChainId: chainId.toString(),
|
|
862
|
-
quoteId: intentQuote.id,
|
|
863
|
-
signature,
|
|
864
|
-
order: intentQuote.metadata.order,
|
|
865
|
-
userAddress: accountAddress,
|
|
866
|
-
aggregatorId: 'cowswap',
|
|
867
|
-
};
|
|
868
|
-
const intentApi = new IntentApiImpl(__classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl, __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"));
|
|
869
|
-
const intentOrder = (await intentApi.submitIntent(submissionParams));
|
|
870
|
-
const orderUid = intentOrder.id;
|
|
871
|
-
// Determine transaction type: swap for same-chain, bridge for cross-chain
|
|
872
|
-
const isCrossChainTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
873
|
-
const transactionType = isCrossChainTx
|
|
874
|
-
? TransactionType.bridge
|
|
875
|
-
: TransactionType.swap;
|
|
876
|
-
// Create actual transaction in Transaction Controller first
|
|
877
|
-
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', formatChainIdToHex(chainId));
|
|
878
|
-
const intentTransactionParams = {
|
|
879
|
-
chainId: formatChainIdToHex(chainId),
|
|
880
|
-
from: accountAddress,
|
|
881
|
-
to: intent.settlementContract ??
|
|
882
|
-
'0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract
|
|
883
|
-
data: `0x${orderUid.slice(-8)}`, // Use last 8 chars of orderUid to make each transaction unique
|
|
884
|
-
value: '0x0',
|
|
885
|
-
gas: '0x5208', // Minimal gas for display purposes
|
|
886
|
-
gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it
|
|
887
|
-
skipInitialGasEstimate: true,
|
|
888
|
-
};
|
|
889
|
-
const { transactionMeta: txMetaPromise } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, intentTransactionParams, {
|
|
890
|
-
origin: 'metamask',
|
|
891
|
-
actionId: generateActionId(),
|
|
892
|
-
requireApproval: false,
|
|
893
|
-
networkClientId,
|
|
894
|
-
type: transactionType,
|
|
895
|
-
swaps: {
|
|
896
|
-
meta: {
|
|
897
|
-
// Add token symbols from quoteResponse for proper display
|
|
898
|
-
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
|
899
|
-
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
|
900
|
-
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
|
901
|
-
destinationTokenAmount: quoteResponse.quote.destTokenAmount,
|
|
902
|
-
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
|
903
|
-
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
|
904
|
-
sourceTokenAddress: quoteResponse.quote.srcAsset.address,
|
|
905
|
-
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
|
906
|
-
swapTokenValue: quoteResponse.sentAmount.amount,
|
|
907
|
-
approvalTxId,
|
|
908
|
-
swapMetaData: {
|
|
909
|
-
isIntentTx: true,
|
|
910
|
-
orderUid,
|
|
911
|
-
intentType: isCrossChainTx ? 'bridge' : 'swap',
|
|
912
|
-
},
|
|
913
|
-
},
|
|
914
|
-
},
|
|
915
|
-
});
|
|
916
|
-
const intentTxMeta = txMetaPromise;
|
|
917
|
-
// Map intent order status to TransactionController status
|
|
918
|
-
const initialTransactionStatus = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_mapIntentOrderStatusToTransactionStatus).call(this, intentOrder.status);
|
|
919
|
-
// Update transaction with proper initial status based on intent order
|
|
920
|
-
const statusUpdatedTxMeta = {
|
|
921
|
-
...intentTxMeta,
|
|
922
|
-
status: initialTransactionStatus,
|
|
923
|
-
};
|
|
924
|
-
__classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f").call(this, statusUpdatedTxMeta, `BridgeStatusController - Initial intent order status: ${intentOrder.status}`);
|
|
925
|
-
// Update with actual transaction metadata
|
|
926
|
-
const syntheticMeta = {
|
|
927
|
-
...statusUpdatedTxMeta,
|
|
928
|
-
isIntentTx: true,
|
|
929
|
-
orderUid,
|
|
930
|
-
intentType: isCrossChainTx ? 'bridge' : 'swap',
|
|
931
|
-
};
|
|
932
|
-
// Record in bridge history with actual transaction metadata
|
|
933
|
-
try {
|
|
934
|
-
// Use 'intent:' prefix for intent transactions
|
|
935
|
-
const bridgeHistoryKey = `intent:${orderUid}`;
|
|
936
|
-
// Create a bridge transaction metadata that includes the original txId
|
|
937
|
-
const bridgeTxMetaForHistory = {
|
|
938
|
-
...syntheticMeta,
|
|
939
|
-
id: bridgeHistoryKey, // Use intent: prefix for bridge history key
|
|
940
|
-
originalTransactionId: syntheticMeta.id, // Keep original txId for TransactionController updates
|
|
941
|
-
};
|
|
942
|
-
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
943
|
-
accountAddress,
|
|
944
|
-
bridgeTxMeta: bridgeTxMetaForHistory,
|
|
945
|
-
statusRequest: {
|
|
946
|
-
...getStatusRequestParams(quoteResponse),
|
|
947
|
-
srcTxHash: syntheticMeta.hash ?? '',
|
|
948
|
-
},
|
|
949
|
-
quoteResponse,
|
|
950
|
-
slippagePercentage: 0,
|
|
951
|
-
isStxEnabled: false,
|
|
952
|
-
approvalTxId,
|
|
953
|
-
});
|
|
954
|
-
// Start polling using the intent: prefixed key to route to intent manager
|
|
955
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeHistoryKey);
|
|
956
|
-
}
|
|
957
|
-
catch (error) {
|
|
958
|
-
console.error('📝 [submitIntent] Failed to add to bridge history', error);
|
|
959
|
-
// non-fatal but log the error
|
|
960
|
-
}
|
|
961
|
-
return syntheticMeta;
|
|
962
|
-
}
|
|
963
|
-
catch (error) {
|
|
964
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
965
|
-
error_message: error?.message,
|
|
966
|
-
...preConfirmationProperties,
|
|
967
|
-
});
|
|
968
|
-
throw error;
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
737
|
/**
|
|
972
738
|
* Tracks post-submission events for a cross-chain swap based on the history item
|
|
973
739
|
*
|
|
@@ -993,12 +759,13 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
993
759
|
const requestParamProperties = getRequestParamFromHistory(historyItem);
|
|
994
760
|
// Always publish StatusValidationFailed event, regardless of featureId
|
|
995
761
|
if (eventName === UnifiedSwapBridgeEventName.StatusValidationFailed) {
|
|
762
|
+
const { chain_id_source, chain_id_destination, token_address_source, token_address_destination, } = requestParamProperties;
|
|
996
763
|
this.messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, {
|
|
997
764
|
...baseProperties,
|
|
998
|
-
chain_id_source
|
|
999
|
-
chain_id_destination
|
|
1000
|
-
token_address_source
|
|
1001
|
-
token_address_destination
|
|
765
|
+
chain_id_source,
|
|
766
|
+
chain_id_destination,
|
|
767
|
+
token_address_source,
|
|
768
|
+
token_address_destination,
|
|
1002
769
|
refresh_count: historyItem.attempts?.counter ?? 0,
|
|
1003
770
|
});
|
|
1004
771
|
return;
|
|
@@ -1009,8 +776,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1009
776
|
}
|
|
1010
777
|
const selectedAccount = this.messenger.call('AccountsController:getAccountByAddress', historyItem.account);
|
|
1011
778
|
const { transactions } = this.messenger.call('TransactionController:getState');
|
|
1012
|
-
const txMeta = transactions?.find((
|
|
1013
|
-
const approvalTxMeta = transactions?.find((
|
|
779
|
+
const txMeta = transactions?.find(({ id }) => id === txMetaId);
|
|
780
|
+
const approvalTxMeta = transactions?.find(({ id }) => id === historyItem.approvalTxId);
|
|
1014
781
|
const requiredEventProperties = {
|
|
1015
782
|
...baseProperties,
|
|
1016
783
|
...requestParamProperties,
|
|
@@ -1037,19 +804,12 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1037
804
|
this.messenger.registerActionHandler(`${BRIDGE_STATUS_CONTROLLER_NAME}:wipeBridgeStatus`, this.wipeBridgeStatus.bind(this));
|
|
1038
805
|
this.messenger.registerActionHandler(`${BRIDGE_STATUS_CONTROLLER_NAME}:resetState`, this.resetState.bind(this));
|
|
1039
806
|
this.messenger.registerActionHandler(`${BRIDGE_STATUS_CONTROLLER_NAME}:submitTx`, this.submitTx.bind(this));
|
|
1040
|
-
this.messenger.registerActionHandler(`${BRIDGE_STATUS_CONTROLLER_NAME}:submitIntent`, this.submitIntent.bind(this));
|
|
1041
807
|
this.messenger.registerActionHandler(`${BRIDGE_STATUS_CONTROLLER_NAME}:restartPollingForFailedAttempts`, this.restartPollingForFailedAttempts.bind(this));
|
|
1042
808
|
this.messenger.registerActionHandler(`${BRIDGE_STATUS_CONTROLLER_NAME}:getBridgeHistoryItemByTxMetaId`, this.getBridgeHistoryItemByTxMetaId.bind(this));
|
|
1043
809
|
// Set interval
|
|
1044
810
|
this.setIntervalLength(REFRESH_INTERVAL_MS);
|
|
1045
811
|
this.messenger.subscribe('TransactionController:transactionFailed', ({ transactionMeta }) => {
|
|
1046
812
|
const { type, status, id } = transactionMeta;
|
|
1047
|
-
// Skip intent transactions - they have their own tracking via CoW API
|
|
1048
|
-
// Skip intent transactions - they have their own tracking via CoW API
|
|
1049
|
-
if (transactionMeta
|
|
1050
|
-
.swapMetaData?.isIntentTx) {
|
|
1051
|
-
return;
|
|
1052
|
-
}
|
|
1053
813
|
if (type &&
|
|
1054
814
|
[
|
|
1055
815
|
TransactionType.bridge,
|
|
@@ -1085,157 +845,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1085
845
|
__classPrivateFieldGet(this, _BridgeStatusController_restartPollingForIncompleteHistoryItems, "f").call(this);
|
|
1086
846
|
}
|
|
1087
847
|
}
|
|
1088
|
-
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionFn = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_updateTransactionFn = new WeakMap(), _BridgeStatusController_estimateGasFeeFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_markTxAsFailed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(),
|
|
848
|
+
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionFn = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_updateTransactionFn = new WeakMap(), _BridgeStatusController_estimateGasFeeFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_markTxAsFailed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_getSrcTxHash = new WeakMap(), _BridgeStatusController_updateSrcTxHash = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_handleNonEvmTx = new WeakMap(), _BridgeStatusController_waitForHashAndReturnFinalTxMeta = new WeakMap(), _BridgeStatusController_handleApprovalTx = new WeakMap(), _BridgeStatusController_handleEvmTransaction = new WeakMap(), _BridgeStatusController_handleUSDTAllowanceReset = new WeakMap(), _BridgeStatusController_calculateGasFees = new WeakMap(), _BridgeStatusController_handleEvmTransactionBatch = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap(), _BridgeStatusController_instances = new WeakSet(), _BridgeStatusController_getMultichainSelectedAccount = function _BridgeStatusController_getMultichainSelectedAccount(accountAddress) {
|
|
1089
849
|
return this.messenger.call('AccountsController:getAccountByAddress', accountAddress);
|
|
1090
|
-
}, _BridgeStatusController_updateBridgeHistoryFromIntentOrder = function _BridgeStatusController_updateBridgeHistoryFromIntentOrder(bridgeTxMetaId, intentOrder, historyItem) {
|
|
1091
|
-
const { srcChainId } = historyItem.quote;
|
|
1092
|
-
// Map intent order status to bridge status using enum values
|
|
1093
|
-
let statusType;
|
|
1094
|
-
const isComplete = [
|
|
1095
|
-
IntentOrderStatus.CONFIRMED,
|
|
1096
|
-
IntentOrderStatus.COMPLETED,
|
|
1097
|
-
].includes(intentOrder.status);
|
|
1098
|
-
const isFailed = [
|
|
1099
|
-
IntentOrderStatus.FAILED,
|
|
1100
|
-
IntentOrderStatus.EXPIRED,
|
|
1101
|
-
].includes(intentOrder.status);
|
|
1102
|
-
const isPending = [IntentOrderStatus.PENDING].includes(intentOrder.status);
|
|
1103
|
-
const isSubmitted = [IntentOrderStatus.SUBMITTED].includes(intentOrder.status);
|
|
1104
|
-
if (isComplete) {
|
|
1105
|
-
statusType = StatusTypes.COMPLETE;
|
|
1106
|
-
}
|
|
1107
|
-
else if (isFailed) {
|
|
1108
|
-
statusType = StatusTypes.FAILED;
|
|
1109
|
-
}
|
|
1110
|
-
else if (isPending) {
|
|
1111
|
-
statusType = StatusTypes.PENDING;
|
|
1112
|
-
}
|
|
1113
|
-
else if (isSubmitted) {
|
|
1114
|
-
statusType = StatusTypes.SUBMITTED;
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
statusType = StatusTypes.UNKNOWN;
|
|
1118
|
-
}
|
|
1119
|
-
// Extract transaction hashes from intent order
|
|
1120
|
-
const txHash = intentOrder.txHash ?? '';
|
|
1121
|
-
// Check metadata for additional transaction hashes
|
|
1122
|
-
const metadataTxHashes = Array.isArray(intentOrder.metadata.txHashes)
|
|
1123
|
-
? intentOrder.metadata.txHashes
|
|
1124
|
-
: [];
|
|
1125
|
-
let allHashes;
|
|
1126
|
-
if (metadataTxHashes.length > 0) {
|
|
1127
|
-
allHashes = metadataTxHashes;
|
|
1128
|
-
}
|
|
1129
|
-
else if (txHash) {
|
|
1130
|
-
allHashes = [txHash];
|
|
1131
|
-
}
|
|
1132
|
-
else {
|
|
1133
|
-
allHashes = [];
|
|
1134
|
-
}
|
|
1135
|
-
const newStatus = {
|
|
1136
|
-
status: statusType,
|
|
1137
|
-
srcChain: {
|
|
1138
|
-
chainId: srcChainId,
|
|
1139
|
-
txHash: txHash ?? historyItem.status.srcChain.txHash ?? '',
|
|
1140
|
-
},
|
|
1141
|
-
};
|
|
1142
|
-
const newBridgeHistoryItem = {
|
|
1143
|
-
...historyItem,
|
|
1144
|
-
status: newStatus,
|
|
1145
|
-
completionTime: newStatus.status === StatusTypes.COMPLETE ||
|
|
1146
|
-
newStatus.status === StatusTypes.FAILED
|
|
1147
|
-
? Date.now()
|
|
1148
|
-
: undefined,
|
|
1149
|
-
attempts: undefined,
|
|
1150
|
-
srcTxHashes: allHashes.length > 0
|
|
1151
|
-
? Array.from(new Set([...(historyItem.srcTxHashes ?? []), ...allHashes]))
|
|
1152
|
-
: historyItem.srcTxHashes,
|
|
1153
|
-
};
|
|
1154
|
-
this.update((state) => {
|
|
1155
|
-
state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
|
|
1156
|
-
});
|
|
1157
|
-
// Update the actual transaction in TransactionController to sync with intent status
|
|
1158
|
-
// Use the original transaction ID (not the intent: prefixed bridge history key)
|
|
1159
|
-
const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
|
|
1160
|
-
if (originalTxId && !originalTxId.startsWith('intent:')) {
|
|
1161
|
-
try {
|
|
1162
|
-
const transactionStatus = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_mapIntentOrderStatusToTransactionStatus).call(this, intentOrder.status);
|
|
1163
|
-
// Merge with existing TransactionMeta to avoid wiping required fields
|
|
1164
|
-
const { transactions } = this.messenger.call('TransactionController:getState');
|
|
1165
|
-
const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
|
|
1166
|
-
if (existingTxMeta) {
|
|
1167
|
-
const updatedTxMeta = {
|
|
1168
|
-
...existingTxMeta,
|
|
1169
|
-
status: transactionStatus,
|
|
1170
|
-
...(txHash ? { hash: txHash } : {}),
|
|
1171
|
-
...(txHash
|
|
1172
|
-
? {
|
|
1173
|
-
txReceipt: {
|
|
1174
|
-
...existingTxMeta.txReceipt,
|
|
1175
|
-
transactionHash: txHash,
|
|
1176
|
-
status: (isComplete ? '0x1' : '0x0'),
|
|
1177
|
-
},
|
|
1178
|
-
}
|
|
1179
|
-
: {}),
|
|
1180
|
-
};
|
|
1181
|
-
__classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${intentOrder.status}`);
|
|
1182
|
-
}
|
|
1183
|
-
else {
|
|
1184
|
-
console.warn('📝 [fetchIntentOrderStatus] Skipping update; transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
catch (error) {
|
|
1188
|
-
console.error('📝 [fetchIntentOrderStatus] Failed to update transaction status', {
|
|
1189
|
-
originalTxId,
|
|
1190
|
-
bridgeHistoryKey: bridgeTxMetaId,
|
|
1191
|
-
error,
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
|
|
1196
|
-
const isFinal = newStatus.status === StatusTypes.COMPLETE ||
|
|
1197
|
-
newStatus.status === StatusTypes.FAILED;
|
|
1198
|
-
if (isFinal && pollingToken) {
|
|
1199
|
-
this.stopPollingByPollingToken(pollingToken);
|
|
1200
|
-
delete __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
|
|
1201
|
-
if (newStatus.status === StatusTypes.COMPLETE) {
|
|
1202
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
|
|
1203
|
-
}
|
|
1204
|
-
else if (newStatus.status === StatusTypes.FAILED) {
|
|
1205
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, bridgeTxMetaId);
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
}, _BridgeStatusController_convertBridgeQuoteToIntentQuote = function _BridgeStatusController_convertBridgeQuoteToIntentQuote(quoteResponse, intent) {
|
|
1209
|
-
return {
|
|
1210
|
-
id: `bridge-${Date.now()}`,
|
|
1211
|
-
provider: intent.protocol,
|
|
1212
|
-
srcAmount: quoteResponse.quote.srcTokenAmount,
|
|
1213
|
-
destAmount: quoteResponse.quote.destTokenAmount,
|
|
1214
|
-
estimatedGas: '21000',
|
|
1215
|
-
estimatedTime: 300, // 5 minutes
|
|
1216
|
-
priceImpact: 0,
|
|
1217
|
-
fees: [],
|
|
1218
|
-
validUntil: Date.now() + 300000, // 5 minutes from now
|
|
1219
|
-
metadata: {
|
|
1220
|
-
order: intent.order,
|
|
1221
|
-
settlementContract: intent.settlementContract ?? '',
|
|
1222
|
-
chainId: quoteResponse.quote.srcChainId,
|
|
1223
|
-
bridgeQuote: quoteResponse,
|
|
1224
|
-
},
|
|
1225
|
-
};
|
|
1226
|
-
}, _BridgeStatusController_mapIntentOrderStatusToTransactionStatus = function _BridgeStatusController_mapIntentOrderStatusToTransactionStatus(intentStatus) {
|
|
1227
|
-
switch (intentStatus) {
|
|
1228
|
-
case IntentOrderStatus.PENDING:
|
|
1229
|
-
case IntentOrderStatus.SUBMITTED:
|
|
1230
|
-
return TransactionStatus.submitted;
|
|
1231
|
-
case IntentOrderStatus.CONFIRMED:
|
|
1232
|
-
case IntentOrderStatus.COMPLETED:
|
|
1233
|
-
return TransactionStatus.confirmed;
|
|
1234
|
-
case IntentOrderStatus.FAILED:
|
|
1235
|
-
case IntentOrderStatus.EXPIRED:
|
|
1236
|
-
return TransactionStatus.failed;
|
|
1237
|
-
default:
|
|
1238
|
-
return TransactionStatus.submitted;
|
|
1239
|
-
}
|
|
1240
850
|
};
|
|
1241
851
|
//# sourceMappingURL=bridge-status-controller.mjs.map
|