@metamask-previews/bridge-status-controller 42.0.0-preview-331bec5d → 42.0.0-preview-5feaf905
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/dist/bridge-status-controller.cjs +11 -451
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +0 -15
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +0 -15
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +11 -451
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs +0 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -12
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -12
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/transaction.d.cts +0 -20
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +0 -20
- package/dist/utils/transaction.d.mts.map +1 -1
- package/package.json +1 -1
@@ -10,7 +10,7 @@ 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 _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,
|
13
|
+
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_handleSolanaTx, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, _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");
|
@@ -25,20 +25,6 @@ const gas_1 = require("./utils/gas.cjs");
|
|
25
25
|
const metrics_1 = require("./utils/metrics.cjs");
|
26
26
|
const transaction_1 = require("./utils/transaction.cjs");
|
27
27
|
const transaction_2 = require("./utils/transaction.cjs");
|
28
|
-
// CoW intent: API base and network path mapping (adjust as needed)
|
29
|
-
const COW_API_BASE = 'https://api.cow.fi';
|
30
|
-
const COW_NETWORK_PATHS = {
|
31
|
-
// Ethereum Mainnet
|
32
|
-
1: 'mainnet',
|
33
|
-
// Arbitrum One
|
34
|
-
42161: 'arbitrum_one',
|
35
|
-
// Base
|
36
|
-
8453: 'base',
|
37
|
-
// Avalanche C-Chain
|
38
|
-
43114: 'avalanche',
|
39
|
-
// Polygon PoS
|
40
|
-
137: 'polygon',
|
41
|
-
};
|
42
28
|
const metadata = {
|
43
29
|
// We want to persist the bridge status state so that we can show the proper data for the Activity list
|
44
30
|
// basically match the behavior of TransactionController
|
@@ -193,8 +179,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
193
179
|
// We know it's in progress but not the exact status yet
|
194
180
|
const txHistoryItem = {
|
195
181
|
txMetaId: bridgeTxMeta.id,
|
196
|
-
originalTransactionId: bridgeTxMeta
|
197
|
-
.originalTransactionId || bridgeTxMeta.id,
|
198
182
|
batchId: bridgeTxMeta.batchId,
|
199
183
|
quote: quoteResponse.quote,
|
200
184
|
startTime,
|
@@ -239,9 +223,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
239
223
|
return;
|
240
224
|
}
|
241
225
|
const { quote } = txHistoryItem;
|
242
|
-
const isIntent = txId.startsWith('intent:');
|
243
226
|
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quote.srcChainId, quote.destChainId);
|
244
|
-
if (isBridgeTx
|
227
|
+
if (isBridgeTx) {
|
245
228
|
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
246
229
|
bridgeTxMetaId: txId,
|
247
230
|
});
|
@@ -300,11 +283,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
300
283
|
});
|
301
284
|
_BridgeStatusController_fetchBridgeTxStatus.set(this, async ({ bridgeTxMetaId, }) => {
|
302
285
|
const { txHistory } = this.state;
|
303
|
-
// Intent-based items: poll CoW API instead of Bridge API
|
304
|
-
if (bridgeTxMetaId.startsWith('intent:')) {
|
305
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_fetchCowOrderStatus, "f").call(this, { bridgeTxMetaId });
|
306
|
-
return;
|
307
|
-
}
|
308
286
|
if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(txHistory[bridgeTxMetaId]?.attempts)) {
|
309
287
|
return;
|
310
288
|
}
|
@@ -356,174 +334,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
356
334
|
}
|
357
335
|
}
|
358
336
|
}
|
359
|
-
catch (
|
360
|
-
console.warn('Failed to fetch bridge tx status',
|
361
|
-
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
362
|
-
}
|
363
|
-
});
|
364
|
-
_BridgeStatusController_fetchCowOrderStatus.set(this, async ({ bridgeTxMetaId, }) => {
|
365
|
-
const { txHistory } = this.state;
|
366
|
-
const historyItem = txHistory[bridgeTxMetaId];
|
367
|
-
if (!historyItem) {
|
368
|
-
return;
|
369
|
-
}
|
370
|
-
// Backoff handling
|
371
|
-
if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(historyItem.attempts)) {
|
372
|
-
return;
|
373
|
-
}
|
374
|
-
const orderUid = bridgeTxMetaId.replace(/^intent:/u, '');
|
375
|
-
const { srcChainId } = historyItem.quote;
|
376
|
-
const networkPath = COW_NETWORK_PATHS[srcChainId];
|
377
|
-
if (!networkPath) {
|
378
|
-
// Unsupported mapping: stop polling with failure
|
379
|
-
this.update((state) => {
|
380
|
-
state.txHistory[bridgeTxMetaId].status = {
|
381
|
-
status: bridge_controller_1.StatusTypes.FAILED,
|
382
|
-
srcChain: {
|
383
|
-
chainId: srcChainId,
|
384
|
-
txHash: '',
|
385
|
-
},
|
386
|
-
};
|
387
|
-
});
|
388
|
-
return;
|
389
|
-
}
|
390
|
-
try {
|
391
|
-
const url = `${COW_API_BASE}/${networkPath}/api/v1/orders/${orderUid}`;
|
392
|
-
const res = await __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f").call(this, url, { method: 'GET' });
|
393
|
-
// CoW API status enum mapping
|
394
|
-
const rawStatus = typeof res === 'object' && res !== null && 'status' in res
|
395
|
-
? (res.status ?? '')
|
396
|
-
: '';
|
397
|
-
const isComplete = rawStatus === 'fulfilled';
|
398
|
-
const isFailed = ['cancelled', 'expired'].includes(rawStatus);
|
399
|
-
const isPending = ['presignaturePending', 'open'].includes(rawStatus);
|
400
|
-
// Try to find a tx hash in common fields
|
401
|
-
let txHash = '';
|
402
|
-
let allHashes = [];
|
403
|
-
if (isComplete) {
|
404
|
-
// Prefer authoritative trades endpoint for one or multiple fills
|
405
|
-
const tradesUrl = `${COW_API_BASE}/${networkPath}/api/v1/trades?orderUid=${orderUid}`;
|
406
|
-
const trades = (await __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f").call(this, tradesUrl, { method: 'GET' })) ?? [];
|
407
|
-
allHashes = Array.isArray(trades)
|
408
|
-
? trades
|
409
|
-
.map((t) => t?.txHash || t?.transactionHash)
|
410
|
-
.filter((h) => typeof h === 'string' && h.length > 0)
|
411
|
-
: [];
|
412
|
-
// Fallback to any hash on order if trades missing
|
413
|
-
if (allHashes.length === 0) {
|
414
|
-
const possible = [
|
415
|
-
res.txHash,
|
416
|
-
res.transactionHash,
|
417
|
-
res.executedTransaction,
|
418
|
-
res
|
419
|
-
.executedTransactionHash,
|
420
|
-
].filter((h) => typeof h === 'string' && h.length > 0);
|
421
|
-
allHashes = possible;
|
422
|
-
}
|
423
|
-
txHash = allHashes[allHashes.length - 1] || '';
|
424
|
-
}
|
425
|
-
let statusType;
|
426
|
-
if (isComplete) {
|
427
|
-
statusType = bridge_controller_1.StatusTypes.COMPLETE;
|
428
|
-
}
|
429
|
-
else if (isFailed) {
|
430
|
-
statusType = bridge_controller_1.StatusTypes.FAILED;
|
431
|
-
}
|
432
|
-
else if (isPending) {
|
433
|
-
statusType = bridge_controller_1.StatusTypes.PENDING;
|
434
|
-
}
|
435
|
-
else {
|
436
|
-
statusType = bridge_controller_1.StatusTypes.PENDING; // Default to pending for unknown statuses
|
437
|
-
}
|
438
|
-
const newStatus = {
|
439
|
-
status: statusType,
|
440
|
-
srcChain: {
|
441
|
-
chainId: srcChainId,
|
442
|
-
txHash: txHash || historyItem.status.srcChain.txHash || '',
|
443
|
-
},
|
444
|
-
};
|
445
|
-
const newBridgeHistoryItem = {
|
446
|
-
...historyItem,
|
447
|
-
status: newStatus,
|
448
|
-
completionTime: newStatus.status === bridge_controller_1.StatusTypes.COMPLETE ||
|
449
|
-
newStatus.status === bridge_controller_1.StatusTypes.FAILED
|
450
|
-
? Date.now()
|
451
|
-
: undefined,
|
452
|
-
attempts: undefined,
|
453
|
-
srcTxHashes: allHashes.length > 0
|
454
|
-
? Array.from(new Set([...(historyItem.srcTxHashes ?? []), ...allHashes]))
|
455
|
-
: historyItem.srcTxHashes,
|
456
|
-
};
|
457
|
-
this.update((state) => {
|
458
|
-
state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
|
459
|
-
});
|
460
|
-
// Update the actual transaction in TransactionController to sync with CoW status
|
461
|
-
// Use the original transaction ID (not the intent: prefixed bridge history key)
|
462
|
-
const originalTxId = historyItem
|
463
|
-
.originalTransactionId || historyItem.txMetaId;
|
464
|
-
if (originalTxId && !originalTxId.startsWith('intent:')) {
|
465
|
-
try {
|
466
|
-
let transactionStatus;
|
467
|
-
if (isComplete) {
|
468
|
-
transactionStatus = transaction_controller_1.TransactionStatus.confirmed;
|
469
|
-
}
|
470
|
-
else if (isFailed) {
|
471
|
-
transactionStatus = transaction_controller_1.TransactionStatus.failed;
|
472
|
-
}
|
473
|
-
else if (isPending) {
|
474
|
-
transactionStatus = transaction_controller_1.TransactionStatus.submitted;
|
475
|
-
}
|
476
|
-
else {
|
477
|
-
transactionStatus = transaction_controller_1.TransactionStatus.submitted; // Default to submitted for unknown statuses
|
478
|
-
}
|
479
|
-
// Merge with existing TransactionMeta to avoid wiping required fields
|
480
|
-
const { transactions } = this.messagingSystem.call('TransactionController:getState');
|
481
|
-
const existingTxMeta = transactions.find((t) => t.id === originalTxId);
|
482
|
-
if (!existingTxMeta) {
|
483
|
-
console.warn('📝 [fetchCowOrderStatus] Skipping update; transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
484
|
-
}
|
485
|
-
else {
|
486
|
-
const updatedTxMeta = {
|
487
|
-
...existingTxMeta,
|
488
|
-
status: transactionStatus,
|
489
|
-
...(txHash ? { hash: txHash } : {}),
|
490
|
-
...(txHash
|
491
|
-
? {
|
492
|
-
txReceipt: {
|
493
|
-
...existingTxMeta.txReceipt,
|
494
|
-
transactionHash: txHash,
|
495
|
-
status: (isComplete ? '0x1' : '0x0'),
|
496
|
-
},
|
497
|
-
}
|
498
|
-
: {}),
|
499
|
-
};
|
500
|
-
__classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - CoW order status updated: ${rawStatus}`);
|
501
|
-
}
|
502
|
-
}
|
503
|
-
catch (error) {
|
504
|
-
console.error('📝 [fetchCowOrderStatus] Failed to update transaction status', {
|
505
|
-
originalTxId,
|
506
|
-
bridgeHistoryKey: bridgeTxMetaId,
|
507
|
-
error,
|
508
|
-
});
|
509
|
-
}
|
510
|
-
}
|
511
|
-
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
|
512
|
-
const isFinal = newStatus.status === bridge_controller_1.StatusTypes.COMPLETE ||
|
513
|
-
newStatus.status === bridge_controller_1.StatusTypes.FAILED;
|
514
|
-
if (isFinal && pollingToken) {
|
515
|
-
this.stopPollingByPollingToken(pollingToken);
|
516
|
-
delete __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
|
517
|
-
if (newStatus.status === bridge_controller_1.StatusTypes.COMPLETE) {
|
518
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
|
519
|
-
}
|
520
|
-
else if (newStatus.status === bridge_controller_1.StatusTypes.FAILED) {
|
521
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, bridgeTxMetaId);
|
522
|
-
}
|
523
|
-
}
|
524
|
-
}
|
525
|
-
catch {
|
526
|
-
// Network or API error: apply backoff
|
337
|
+
catch (e) {
|
338
|
+
console.warn('Failed to fetch bridge tx status', e);
|
527
339
|
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
528
340
|
}
|
529
341
|
});
|
@@ -608,36 +420,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
608
420
|
}
|
609
421
|
return finalTransactionMeta;
|
610
422
|
});
|
611
|
-
// Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.
|
612
|
-
_BridgeStatusController_waitForTxConfirmation.set(this, async (txId, { timeoutMs = 5 * 60000, // 5 minutes default
|
613
|
-
pollMs = 2000, } = {}) => {
|
614
|
-
const start = Date.now();
|
615
|
-
// Poll the TransactionController state for status changes
|
616
|
-
// We intentionally keep this simple to avoid extra wiring/subscriptions in this controller
|
617
|
-
// and because we only need it for the rare intent+approval path.
|
618
|
-
while (true) {
|
619
|
-
const { transactions } = this.messagingSystem.call('TransactionController:getState');
|
620
|
-
const meta = transactions.find((t) => t.id === txId);
|
621
|
-
if (meta) {
|
622
|
-
// Treat both 'confirmed' and 'finalized' as success to match TC lifecycle
|
623
|
-
if (meta.status === transaction_controller_1.TransactionStatus.confirmed ||
|
624
|
-
// Some environments move directly to finalized
|
625
|
-
transaction_controller_1.TransactionStatus.finalized ===
|
626
|
-
meta.status) {
|
627
|
-
return meta;
|
628
|
-
}
|
629
|
-
if (meta.status === transaction_controller_1.TransactionStatus.failed ||
|
630
|
-
meta.status === transaction_controller_1.TransactionStatus.dropped ||
|
631
|
-
meta.status === transaction_controller_1.TransactionStatus.rejected) {
|
632
|
-
throw new Error('Approval transaction did not confirm');
|
633
|
-
}
|
634
|
-
}
|
635
|
-
if (Date.now() - start > timeoutMs) {
|
636
|
-
throw new Error('Timed out waiting for approval confirmation');
|
637
|
-
}
|
638
|
-
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
639
|
-
}
|
640
|
-
});
|
641
423
|
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, quoteResponse, requireApproval) => {
|
642
424
|
const { approval } = quoteResponse;
|
643
425
|
if (approval) {
|
@@ -689,17 +471,11 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
689
471
|
type: transactionType,
|
690
472
|
origin: 'metamask',
|
691
473
|
};
|
692
|
-
// Exclude gasLimit from trade to avoid type issues (it can be null)
|
693
|
-
const { gasLimit: tradeGasLimit, ...tradeWithoutGasLimit } = trade;
|
694
474
|
const transactionParams = {
|
695
|
-
...
|
475
|
+
...trade,
|
696
476
|
chainId: hexChainId,
|
697
|
-
|
698
|
-
|
699
|
-
tradeGasLimit !== 0 && {
|
700
|
-
gasLimit: tradeGasLimit.toString(),
|
701
|
-
gas: tradeGasLimit.toString(),
|
702
|
-
}),
|
477
|
+
gasLimit: trade.gasLimit?.toString(),
|
478
|
+
gas: trade.gasLimit?.toString(),
|
703
479
|
};
|
704
480
|
const transactionParamsWithMaxGas = {
|
705
481
|
...transactionParams,
|
@@ -728,11 +504,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
728
504
|
networkGasFeeEstimates: gasFeeEstimates,
|
729
505
|
txGasFeeEstimates,
|
730
506
|
});
|
731
|
-
|
732
|
-
// This fixes the issue where approval transactions had zero gas
|
733
|
-
const maxGasLimit = transactionParams.gas
|
734
|
-
? (0, controller_utils_1.toHex)(transactionParams.gas)
|
735
|
-
: undefined;
|
507
|
+
const maxGasLimit = (0, controller_utils_1.toHex)(transactionParams.gas ?? 0);
|
736
508
|
return {
|
737
509
|
maxFeePerGas,
|
738
510
|
maxPriorityFeePerGas,
|
@@ -889,211 +661,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
889
661
|
}
|
890
662
|
return txMeta;
|
891
663
|
};
|
892
|
-
/**
|
893
|
-
* UI-signed intent submission (fast path): the UI generates the EIP-712 signature and calls this with the raw signature.
|
894
|
-
* Here we POST the order to the intent backend (e.g., CoW) and create a synthetic history entry for UX.
|
895
|
-
*
|
896
|
-
* @param params - Object containing intent submission parameters
|
897
|
-
* @param params.quoteResponse - Quote carrying intent data
|
898
|
-
* @param params.signature - Hex signature produced by eth_signTypedData_v4
|
899
|
-
* @param params.accountAddress - The EOA submitting the order
|
900
|
-
* @returns A lightweight TransactionMeta-like object for history linking
|
901
|
-
*/
|
902
|
-
this.submitIntent = async (params) => {
|
903
|
-
const { quoteResponse, signature, accountAddress } = params;
|
904
|
-
// Build pre-confirmation properties for error tracking parity with submitTx
|
905
|
-
const account = this.messagingSystem.call('AccountsController:getAccountByAddress', accountAddress);
|
906
|
-
const isHardwareAccount = Boolean(account) && (0, bridge_controller_1.isHardwareWallet)(account);
|
907
|
-
const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, false, isHardwareAccount);
|
908
|
-
try {
|
909
|
-
const { intent } = quoteResponse
|
910
|
-
.quote;
|
911
|
-
if (!intent || intent.protocol !== 'cowswap') {
|
912
|
-
throw new Error('submitIntent: missing or unsupported intent');
|
913
|
-
}
|
914
|
-
// If backend provided an approval tx for this intent quote, submit it first (on-chain),
|
915
|
-
// then proceed with off-chain intent submission.
|
916
|
-
let approvalTxId;
|
917
|
-
if (quoteResponse.approval) {
|
918
|
-
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
919
|
-
// Handle approval silently for better UX in intent flows
|
920
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse,
|
921
|
-
/* requireApproval */ false);
|
922
|
-
approvalTxId = approvalTxMeta?.id;
|
923
|
-
// Optionally wait for approval confirmation with timeout and graceful fallback
|
924
|
-
// CoW order can be created before allowance is mined, but waiting helps avoid MEV issues
|
925
|
-
if (approvalTxId) {
|
926
|
-
try {
|
927
|
-
// Wait with a shorter timeout and continue if it fails
|
928
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId, {
|
929
|
-
timeoutMs: 30000,
|
930
|
-
pollMs: 3000, // Poll less frequently to avoid rate limits
|
931
|
-
});
|
932
|
-
}
|
933
|
-
catch (error) {
|
934
|
-
// Log but don't throw - continue with CoW order submission
|
935
|
-
console.warn('Approval confirmation failed, continuing with intent submission:', error);
|
936
|
-
}
|
937
|
-
}
|
938
|
-
}
|
939
|
-
// Map chainId to CoW API server path (prod)
|
940
|
-
const chainId = quoteResponse.quote.srcChainId;
|
941
|
-
const serverPath = COW_NETWORK_PATHS[chainId];
|
942
|
-
if (!serverPath) {
|
943
|
-
throw new Error(`submitIntent: unsupported chainId for CoW intents: ${chainId}`);
|
944
|
-
}
|
945
|
-
// Build OrderCreation payload (simplified)
|
946
|
-
const orderBody = {
|
947
|
-
...intent.order,
|
948
|
-
feeAmount: '0',
|
949
|
-
from: accountAddress,
|
950
|
-
signature,
|
951
|
-
signingScheme: 'eip712',
|
952
|
-
};
|
953
|
-
// POST to CoW prod
|
954
|
-
const url = `https://api.cow.fi/${serverPath}/api/v1/orders`;
|
955
|
-
const res = await __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f").call(this, url, {
|
956
|
-
method: 'POST',
|
957
|
-
headers: { 'Content-Type': 'application/json' },
|
958
|
-
body: JSON.stringify(orderBody),
|
959
|
-
});
|
960
|
-
const orderUid = typeof res === 'string'
|
961
|
-
? res
|
962
|
-
: (res?.uid ??
|
963
|
-
res
|
964
|
-
?.orderUid ??
|
965
|
-
res?.id);
|
966
|
-
if (!orderUid) {
|
967
|
-
throw new Error('submitIntent: failed to submit order');
|
968
|
-
}
|
969
|
-
// Get initial order status from CoW API
|
970
|
-
let initialOrderStatus = 'open'; // Default status
|
971
|
-
try {
|
972
|
-
const orderStatusUrl = `${COW_API_BASE}/${serverPath}/api/v1/orders/${orderUid}`;
|
973
|
-
const orderStatusRes = await __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f").call(this, orderStatusUrl, {
|
974
|
-
method: 'GET',
|
975
|
-
});
|
976
|
-
initialOrderStatus =
|
977
|
-
orderStatusRes?.status ?? 'open';
|
978
|
-
}
|
979
|
-
catch (error) {
|
980
|
-
console.warn('📝 [submitIntent] Failed to get initial order status, using default:', error);
|
981
|
-
}
|
982
|
-
// Determine transaction type: swap for same-chain, bridge for cross-chain
|
983
|
-
const isCrossChainTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
984
|
-
const transactionType = isCrossChainTx
|
985
|
-
? transaction_controller_1.TransactionType.bridge
|
986
|
-
: transaction_controller_1.TransactionType.swap;
|
987
|
-
// Create actual transaction in Transaction Controller first
|
988
|
-
const networkClientId = this.messagingSystem.call('NetworkController:findNetworkClientIdByChainId', (0, bridge_controller_1.formatChainIdToHex)(chainId));
|
989
|
-
const intentTransactionParams = {
|
990
|
-
chainId: (0, bridge_controller_1.formatChainIdToHex)(chainId),
|
991
|
-
from: accountAddress,
|
992
|
-
to: intent.settlementContract ||
|
993
|
-
'0x9008D19f58AAbd9eD0D60971565AA8510560ab41',
|
994
|
-
data: `0x${orderUid.slice(-8)}`,
|
995
|
-
value: '0x0',
|
996
|
-
gas: '0x5208',
|
997
|
-
gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it
|
998
|
-
};
|
999
|
-
const { transactionMeta: txMetaPromise } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, intentTransactionParams, {
|
1000
|
-
origin: 'metamask',
|
1001
|
-
actionId: (0, transaction_2.generateActionId)(),
|
1002
|
-
requireApproval: false,
|
1003
|
-
networkClientId,
|
1004
|
-
type: transactionType,
|
1005
|
-
swaps: {
|
1006
|
-
meta: {
|
1007
|
-
// Add token symbols from quoteResponse for proper display
|
1008
|
-
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
1009
|
-
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
1010
|
-
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
1011
|
-
destinationTokenAmount: quoteResponse.quote.destTokenAmount,
|
1012
|
-
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
1013
|
-
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
1014
|
-
sourceTokenAddress: quoteResponse.quote.srcAsset.address,
|
1015
|
-
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
1016
|
-
swapTokenValue: quoteResponse.sentAmount.amount,
|
1017
|
-
approvalTxId,
|
1018
|
-
swapMetaData: {
|
1019
|
-
isIntentTx: true,
|
1020
|
-
orderUid,
|
1021
|
-
intentType: isCrossChainTx ? 'bridge' : 'swap',
|
1022
|
-
},
|
1023
|
-
},
|
1024
|
-
},
|
1025
|
-
});
|
1026
|
-
const intentTxMeta = txMetaPromise;
|
1027
|
-
// Map initial CoW order status to TransactionController status
|
1028
|
-
const isComplete = initialOrderStatus === 'fulfilled';
|
1029
|
-
const isFailed = ['cancelled', 'expired'].includes(initialOrderStatus);
|
1030
|
-
const isPending = ['presignaturePending', 'open'].includes(initialOrderStatus);
|
1031
|
-
let initialTransactionStatus;
|
1032
|
-
if (isComplete) {
|
1033
|
-
initialTransactionStatus = transaction_controller_1.TransactionStatus.confirmed;
|
1034
|
-
}
|
1035
|
-
else if (isFailed) {
|
1036
|
-
initialTransactionStatus = transaction_controller_1.TransactionStatus.failed;
|
1037
|
-
}
|
1038
|
-
else if (isPending) {
|
1039
|
-
initialTransactionStatus = transaction_controller_1.TransactionStatus.submitted;
|
1040
|
-
}
|
1041
|
-
else {
|
1042
|
-
initialTransactionStatus = transaction_controller_1.TransactionStatus.submitted;
|
1043
|
-
}
|
1044
|
-
// Update transaction with proper initial status based on CoW order
|
1045
|
-
const statusUpdatedTxMeta = {
|
1046
|
-
...intentTxMeta,
|
1047
|
-
status: initialTransactionStatus,
|
1048
|
-
};
|
1049
|
-
__classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f").call(this, statusUpdatedTxMeta, `BridgeStatusController - Initial CoW order status: ${initialOrderStatus}`);
|
1050
|
-
// Update with actual transaction metadata
|
1051
|
-
const syntheticMeta = {
|
1052
|
-
...statusUpdatedTxMeta,
|
1053
|
-
isIntentTx: true,
|
1054
|
-
orderUid,
|
1055
|
-
intentType: isCrossChainTx ? 'bridge' : 'swap',
|
1056
|
-
};
|
1057
|
-
// Record in bridge history with actual transaction metadata
|
1058
|
-
try {
|
1059
|
-
// Use intent: prefix for CoW transactions to route to CoW API
|
1060
|
-
const bridgeHistoryKey = `intent:${orderUid}`;
|
1061
|
-
// Create a bridge transaction metadata that includes the original txId
|
1062
|
-
const bridgeTxMetaForHistory = {
|
1063
|
-
...syntheticMeta,
|
1064
|
-
id: bridgeHistoryKey,
|
1065
|
-
originalTransactionId: syntheticMeta.id, // Keep original txId for TransactionController updates
|
1066
|
-
};
|
1067
|
-
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
1068
|
-
accountAddress,
|
1069
|
-
bridgeTxMeta: bridgeTxMetaForHistory,
|
1070
|
-
statusRequest: {
|
1071
|
-
...(0, transaction_1.getStatusRequestParams)(quoteResponse),
|
1072
|
-
srcTxHash: syntheticMeta.hash || '',
|
1073
|
-
},
|
1074
|
-
quoteResponse,
|
1075
|
-
slippagePercentage: 0,
|
1076
|
-
isStxEnabled: false,
|
1077
|
-
approvalTxId,
|
1078
|
-
});
|
1079
|
-
// Debug: Check if the bridge history was added
|
1080
|
-
// Start polling using the intent: prefixed key to route to CoW API
|
1081
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeHistoryKey);
|
1082
|
-
}
|
1083
|
-
catch (error) {
|
1084
|
-
console.error('📝 [submitIntent] Failed to add to bridge history', error);
|
1085
|
-
// non-fatal but log the error
|
1086
|
-
}
|
1087
|
-
return syntheticMeta;
|
1088
|
-
}
|
1089
|
-
catch (error) {
|
1090
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
|
1091
|
-
error_message: error?.message,
|
1092
|
-
...preConfirmationProperties,
|
1093
|
-
});
|
1094
|
-
throw error;
|
1095
|
-
}
|
1096
|
-
};
|
1097
664
|
/**
|
1098
665
|
* Tracks post-submission events for a cross-chain swap based on the history item
|
1099
666
|
*
|
@@ -1117,8 +684,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
1117
684
|
}
|
1118
685
|
const selectedAccount = this.messagingSystem.call('AccountsController:getAccountByAddress', historyItem.account);
|
1119
686
|
const { transactions } = this.messagingSystem.call('TransactionController:getState');
|
1120
|
-
const txMeta = transactions?.find((
|
1121
|
-
const approvalTxMeta = transactions?.find((
|
687
|
+
const txMeta = transactions?.find(({ id }) => id === txMetaId);
|
688
|
+
const approvalTxMeta = transactions?.find(({ id }) => id === historyItem.approvalTxId);
|
1122
689
|
const requestParamProperties = (0, metrics_1.getRequestParamFromHistory)(historyItem);
|
1123
690
|
if (eventName === bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed) {
|
1124
691
|
const { chain_id_source, chain_id_destination, token_address_source, token_address_destination, } = requestParamProperties;
|
@@ -1158,19 +725,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
1158
725
|
this.messagingSystem.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:wipeBridgeStatus`, this.wipeBridgeStatus.bind(this));
|
1159
726
|
this.messagingSystem.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:resetState`, this.resetState.bind(this));
|
1160
727
|
this.messagingSystem.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:submitTx`, this.submitTx.bind(this));
|
1161
|
-
this.messagingSystem.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:submitIntent`, this.submitIntent.bind(this));
|
1162
728
|
this.messagingSystem.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:restartPollingForFailedAttempts`, this.restartPollingForFailedAttempts.bind(this));
|
1163
729
|
this.messagingSystem.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:getBridgeHistoryItemByTxMetaId`, this.getBridgeHistoryItemByTxMetaId.bind(this));
|
1164
730
|
// Set interval
|
1165
731
|
this.setIntervalLength(constants_1.REFRESH_INTERVAL_MS);
|
1166
732
|
this.messagingSystem.subscribe('TransactionController:transactionFailed', ({ transactionMeta }) => {
|
1167
733
|
const { type, status, id } = transactionMeta;
|
1168
|
-
// Skip intent transactions - they have their own tracking via CoW API
|
1169
|
-
// Skip intent transactions - they have their own tracking via CoW API
|
1170
|
-
if (transactionMeta
|
1171
|
-
.swapMetaData?.isIntentTx) {
|
1172
|
-
return;
|
1173
|
-
}
|
1174
734
|
if (type &&
|
1175
735
|
[
|
1176
736
|
transaction_controller_1.TransactionType.bridge,
|
@@ -1207,7 +767,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
1207
767
|
}
|
1208
768
|
}
|
1209
769
|
exports.BridgeStatusController = BridgeStatusController;
|
1210
|
-
_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(),
|
770
|
+
_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_handleSolanaTx = new WeakMap(), _BridgeStatusController_waitForHashAndReturnFinalTxMeta = new WeakMap(), _BridgeStatusController_handleApprovalTx = new WeakMap(), _BridgeStatusController_handleEvmTransaction = new WeakMap(), _BridgeStatusController_handleUSDTAllowanceReset = new WeakMap(), _BridgeStatusController_calculateGasFees = new WeakMap(), _BridgeStatusController_handleEvmTransactionBatch = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap(), _BridgeStatusController_instances = new WeakSet(), _BridgeStatusController_getMultichainSelectedAccount = function _BridgeStatusController_getMultichainSelectedAccount() {
|
1211
771
|
return this.messagingSystem.call('AccountsController:getSelectedMultichainAccount');
|
1212
772
|
};
|
1213
773
|
//# sourceMappingURL=bridge-status-controller.cjs.map
|