@metamask/bridge-status-controller 70.0.1 → 70.0.3
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 +27 -1
- package/dist/bridge-status-controller.cjs +101 -110
- 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.mjs +101 -110
- package/dist/bridge-status-controller.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/transaction.d.cts +2 -0
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +2 -0
- package/dist/utils/transaction.d.mts.map +1 -1
- package/package.json +11 -11
|
@@ -516,140 +516,131 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
516
516
|
}
|
|
517
517
|
const isHardwareAccount = isHardwareWallet(selectedAccount);
|
|
518
518
|
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, isStxEnabledOnClient, isHardwareAccount, location, abTests, activeAbTests);
|
|
519
|
-
// Emit Submitted event after submit button is clicked
|
|
520
|
-
!quoteResponse.featureId &&
|
|
521
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
|
522
519
|
let txMeta;
|
|
523
520
|
let approvalTxId;
|
|
524
521
|
let isDelegatedAccount = false;
|
|
525
522
|
const startTime = Date.now();
|
|
526
523
|
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
527
524
|
const isTronTx = isTronChainId(quoteResponse.quote.srcChainId);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
525
|
+
try {
|
|
526
|
+
// Emit Submitted event after submit button is clicked
|
|
527
|
+
!quoteResponse.featureId &&
|
|
528
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
|
529
|
+
// Submit non-EVM tx (Solana, BTC, Tron)
|
|
530
|
+
if (isNonEvmChainId(quoteResponse.quote.srcChainId)) {
|
|
531
|
+
// Handle non-EVM approval if present (e.g., Tron token approvals)
|
|
532
|
+
if (quoteResponse.approval && isTronTrade(quoteResponse.approval)) {
|
|
533
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getApprovalTraceParams(quoteResponse, false), async () => {
|
|
534
534
|
return quoteResponse.approval &&
|
|
535
535
|
isTronTrade(quoteResponse.approval)
|
|
536
536
|
? await handleNonEvmTx(this.messenger, quoteResponse.approval, quoteResponse, selectedAccount)
|
|
537
537
|
: /* c8 ignore start */
|
|
538
538
|
undefined;
|
|
539
539
|
/* c8 ignore end */
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
});
|
|
547
|
-
throw error;
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
approvalTxId = approvalTxMeta?.id;
|
|
551
|
-
// Add delay after approval similar to EVM flow
|
|
552
|
-
await handleApprovalDelay(quoteResponse.quote.srcChainId);
|
|
553
|
-
}
|
|
554
|
-
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getTraceParams(quoteResponse, false), async () => {
|
|
555
|
-
try {
|
|
540
|
+
});
|
|
541
|
+
approvalTxId = approvalTxMeta?.id;
|
|
542
|
+
// Add delay after approval similar to EVM flow
|
|
543
|
+
await handleApprovalDelay(quoteResponse.quote.srcChainId);
|
|
544
|
+
}
|
|
545
|
+
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getTraceParams(quoteResponse, false), async () => {
|
|
556
546
|
if (!(isTronTrade(quoteResponse.trade) ||
|
|
557
547
|
isBitcoinTrade(quoteResponse.trade) ||
|
|
558
548
|
typeof quoteResponse.trade === 'string')) {
|
|
559
549
|
throw new Error('Failed to submit cross-chain swap transaction: trade is not a non-EVM transaction');
|
|
560
550
|
}
|
|
561
551
|
return await handleNonEvmTx(this.messenger, quoteResponse.trade, quoteResponse, selectedAccount);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
// Submit EVM tx
|
|
556
|
+
// For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval
|
|
557
|
+
// Extension does not have this issue
|
|
558
|
+
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === BridgeClientId.MOBILE && isHardwareAccount;
|
|
559
|
+
// Handle smart transactions if enabled
|
|
560
|
+
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, getTraceParams(quoteResponse, isStxEnabledOnClient), async () => {
|
|
561
|
+
if (!isEvmTxData(quoteResponse.trade)) {
|
|
562
|
+
throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
|
|
563
|
+
}
|
|
564
|
+
// Check if the account is an EIP-7702 delegated account
|
|
565
|
+
// Delegated accounts only allow 1 in-flight tx, so approve + swap
|
|
566
|
+
// must be batched into a single transaction
|
|
567
|
+
const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
|
568
|
+
isDelegatedAccount = await checkIsDelegatedAccount(this.messenger, quoteResponse.trade.from, [hexChainId]);
|
|
569
|
+
if (isStxEnabledOnClient ||
|
|
570
|
+
quoteResponse.quote.gasIncluded7702 ||
|
|
571
|
+
isDelegatedAccount) {
|
|
572
|
+
const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
|
|
573
|
+
isBridgeTx,
|
|
574
|
+
resetApproval: quoteResponse.resetApproval,
|
|
575
|
+
approval: quoteResponse.approval &&
|
|
576
|
+
isEvmTxData(quoteResponse.approval)
|
|
577
|
+
? quoteResponse.approval
|
|
578
|
+
: undefined,
|
|
579
|
+
trade: quoteResponse.trade,
|
|
580
|
+
quoteResponse,
|
|
581
|
+
requireApproval,
|
|
582
|
+
isDelegatedAccount,
|
|
568
583
|
});
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
isBridgeTx,
|
|
593
|
-
resetApproval: quoteResponse.resetApproval,
|
|
594
|
-
approval: quoteResponse.approval && isEvmTxData(quoteResponse.approval)
|
|
595
|
-
? quoteResponse.approval
|
|
596
|
-
: undefined,
|
|
597
|
-
trade: quoteResponse.trade,
|
|
584
|
+
approvalTxId = approvalMeta?.id;
|
|
585
|
+
return tradeMeta;
|
|
586
|
+
}
|
|
587
|
+
// Set approval time and id if an approval tx is needed
|
|
588
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && isEvmTxData(quoteResponse.approval)
|
|
589
|
+
? quoteResponse.approval
|
|
590
|
+
: undefined, quoteResponse.resetApproval, requireApproval);
|
|
591
|
+
approvalTxId = approvalTxMeta?.id;
|
|
592
|
+
// Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
|
|
593
|
+
// on-chain approval confirmation so swap gas estimation runs after allowance is set.
|
|
594
|
+
if (requireApproval && approvalTxMeta) {
|
|
595
|
+
await handleMobileHardwareWalletDelay(requireApproval);
|
|
596
|
+
await waitForTxConfirmation(this.messenger, approvalTxMeta.id);
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
await handleMobileHardwareWalletDelay(requireApproval);
|
|
600
|
+
}
|
|
601
|
+
// Generate actionId for pre-submission history (non-batch EVM only)
|
|
602
|
+
const actionId = generateActionId().toString();
|
|
603
|
+
// Add pre-submission history keyed by actionId
|
|
604
|
+
// This ensures we have quote data available if transaction fails during submission
|
|
605
|
+
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
606
|
+
accountAddress: selectedAccount.address,
|
|
598
607
|
quoteResponse,
|
|
608
|
+
slippagePercentage: 0,
|
|
609
|
+
isStxEnabled: isStxEnabledOnClient,
|
|
610
|
+
startTime,
|
|
611
|
+
approvalTxId,
|
|
612
|
+
location,
|
|
613
|
+
abTests,
|
|
614
|
+
activeAbTests,
|
|
615
|
+
actionId,
|
|
616
|
+
});
|
|
617
|
+
// Pass txFee when gasIncluded is true to use the quote's gas fees
|
|
618
|
+
// instead of re-estimating (which would fail for max native token swaps)
|
|
619
|
+
const tradeTxMeta = await submitEvmTransaction({
|
|
620
|
+
messenger: this.messenger,
|
|
621
|
+
transactionType: isBridgeTx
|
|
622
|
+
? TransactionType.bridge
|
|
623
|
+
: TransactionType.swap,
|
|
624
|
+
trade: quoteResponse.trade,
|
|
599
625
|
requireApproval,
|
|
600
|
-
|
|
626
|
+
txFee: quoteResponse.quote.gasIncluded
|
|
627
|
+
? quoteResponse.quote.feeData.txFee
|
|
628
|
+
: undefined,
|
|
629
|
+
actionId,
|
|
601
630
|
});
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
// Set approval time and id if an approval tx is needed
|
|
606
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && isEvmTxData(quoteResponse.approval)
|
|
607
|
-
? quoteResponse.approval
|
|
608
|
-
: undefined, quoteResponse.resetApproval, requireApproval);
|
|
609
|
-
approvalTxId = approvalTxMeta?.id;
|
|
610
|
-
// Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
|
|
611
|
-
// on-chain approval confirmation so swap gas estimation runs after allowance is set.
|
|
612
|
-
if (requireApproval && approvalTxMeta) {
|
|
613
|
-
await handleMobileHardwareWalletDelay(requireApproval);
|
|
614
|
-
await waitForTxConfirmation(this.messenger, approvalTxMeta.id);
|
|
615
|
-
}
|
|
616
|
-
else {
|
|
617
|
-
await handleMobileHardwareWalletDelay(requireApproval);
|
|
618
|
-
}
|
|
619
|
-
// Generate actionId for pre-submission history (non-batch EVM only)
|
|
620
|
-
const actionId = generateActionId().toString();
|
|
621
|
-
// Add pre-submission history keyed by actionId
|
|
622
|
-
// This ensures we have quote data available if transaction fails during submission
|
|
623
|
-
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
624
|
-
accountAddress: selectedAccount.address,
|
|
625
|
-
quoteResponse,
|
|
626
|
-
slippagePercentage: 0,
|
|
627
|
-
isStxEnabled: isStxEnabledOnClient,
|
|
628
|
-
startTime,
|
|
629
|
-
approvalTxId,
|
|
630
|
-
location,
|
|
631
|
-
abTests,
|
|
632
|
-
activeAbTests,
|
|
633
|
-
actionId,
|
|
631
|
+
// On success, rekey from actionId to txMeta.id and update srcTxHash
|
|
632
|
+
__classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this, actionId, tradeTxMeta);
|
|
633
|
+
return tradeTxMeta;
|
|
634
634
|
});
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
trade: quoteResponse.trade,
|
|
643
|
-
requireApproval,
|
|
644
|
-
txFee: quoteResponse.quote.gasIncluded
|
|
645
|
-
? quoteResponse.quote.feeData.txFee
|
|
646
|
-
: undefined,
|
|
647
|
-
actionId,
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
catch (error) {
|
|
638
|
+
!quoteResponse.featureId &&
|
|
639
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
640
|
+
error_message: error?.message,
|
|
641
|
+
...preConfirmationProperties,
|
|
648
642
|
});
|
|
649
|
-
|
|
650
|
-
__classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this, actionId, tradeTxMeta);
|
|
651
|
-
return tradeTxMeta;
|
|
652
|
-
});
|
|
643
|
+
throw error;
|
|
653
644
|
}
|
|
654
645
|
try {
|
|
655
646
|
// For non-batch EVM transactions, history was already added/rekeyed above
|