@metamask-previews/bridge-status-controller 31.0.0-preview-08a4995 → 32.0.0-preview-c6e5eb7
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 +18 -1
- package/dist/bridge-status-controller.cjs +68 -64
- 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 +69 -65
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/metrics.cjs +59 -1
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +40 -1
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +40 -1
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +56 -1
- package/dist/utils/metrics.mjs.map +1 -1
- package/package.json +2 -4
@@ -21,7 +21,7 @@ import { BRIDGE_PROD_API_BASE_URL, BRIDGE_STATUS_CONTROLLER_NAME, DEFAULT_BRIDGE
|
|
21
21
|
import { BridgeClientId } from "./types.mjs";
|
22
22
|
import { fetchBridgeTxStatus, getStatusRequestWithSrcTxHash } from "./utils/bridge-status.mjs";
|
23
23
|
import { getTxGasEstimates } from "./utils/gas.mjs";
|
24
|
-
import { getFinalizedTxProperties, getRequestMetadataFromHistory, getRequestParamFromHistory, getTradeDataFromHistory, getTxStatusesFromHistory } from "./utils/metrics.mjs";
|
24
|
+
import { getFinalizedTxProperties, getPriceImpactFromQuote, getRequestMetadataFromHistory, getRequestParamFromHistory, getTradeDataFromHistory, getTradeDataFromQuote, getEVMTxPropertiesFromTransactionMeta, getTxStatusesFromHistory } from "./utils/metrics.mjs";
|
25
25
|
import { getClientRequest, getKeyringRequest, getStatusRequestParams, getTxMetaFields, handleLineaDelay, handleSolanaTxResponse } from "./utils/transaction.mjs";
|
26
26
|
import { generateActionId } from "./utils/transaction.mjs";
|
27
27
|
const metadata = {
|
@@ -286,6 +286,9 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
286
286
|
const finalTransactionMeta = this.messagingSystem
|
287
287
|
.call('TransactionController:getState')
|
288
288
|
.transactions.find((tx) => tx.hash === transactionHash);
|
289
|
+
if (!finalTransactionMeta) {
|
290
|
+
throw new Error('Failed to submit cross-chain swap tx: txMeta for txHash was not found');
|
291
|
+
}
|
289
292
|
return finalTransactionMeta;
|
290
293
|
});
|
291
294
|
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, quoteResponse, requireApproval = false) => {
|
@@ -301,9 +304,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
301
304
|
quoteResponse,
|
302
305
|
requireApproval,
|
303
306
|
});
|
304
|
-
if (!approvalTxMeta) {
|
305
|
-
throw new Error('Failed to submit bridge tx: approval txMeta is undefined');
|
306
|
-
}
|
307
307
|
await handleLineaDelay(quoteResponse);
|
308
308
|
return approvalTxMeta;
|
309
309
|
};
|
@@ -438,7 +438,20 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
438
438
|
*/
|
439
439
|
this.submitTx = async (quoteResponse, isStxEnabledOnClient) => {
|
440
440
|
this.messagingSystem.call('BridgeController:stopPollingForQuotes');
|
441
|
+
// Before the tx is confirmed, its data is not available in txHistory
|
442
|
+
// The quote is used to populate event properties before confirmation
|
443
|
+
const preConfirmationProperties = {
|
444
|
+
...getPriceImpactFromQuote(quoteResponse.quote),
|
445
|
+
...getTradeDataFromQuote(quoteResponse),
|
446
|
+
token_symbol_source: quoteResponse.quote.srcAsset.symbol,
|
447
|
+
token_symbol_destination: quoteResponse.quote.destAsset.symbol,
|
448
|
+
usd_amount_source: Number(quoteResponse.sentAmount?.usd ?? 0),
|
449
|
+
stx_enabled: isStxEnabledOnClient,
|
450
|
+
};
|
451
|
+
// Emit Submitted event after submit button is clicked
|
452
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
441
453
|
let txMeta;
|
454
|
+
let approvalTime, approvalTxId;
|
442
455
|
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
443
456
|
// Submit SOLANA tx
|
444
457
|
if (isSolanaChainId(quoteResponse.quote.srcChainId) &&
|
@@ -451,13 +464,21 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
451
464
|
srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),
|
452
465
|
stxEnabled: false,
|
453
466
|
},
|
454
|
-
}, async () =>
|
455
|
-
|
467
|
+
}, async () => {
|
468
|
+
try {
|
469
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_handleSolanaTx, "f").call(this, quoteResponse);
|
470
|
+
}
|
471
|
+
catch (error) {
|
472
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, txMeta?.id, {
|
473
|
+
error_message: error?.message,
|
474
|
+
...preConfirmationProperties,
|
475
|
+
});
|
476
|
+
throw error;
|
477
|
+
}
|
478
|
+
});
|
456
479
|
}
|
457
|
-
|
458
|
-
|
459
|
-
if (!isSolanaChainId(quoteResponse.quote.srcChainId) &&
|
460
|
-
typeof quoteResponse.trade !== 'string') {
|
480
|
+
else {
|
481
|
+
// Submit EVM tx
|
461
482
|
// For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval
|
462
483
|
// Extension does not have this issue
|
463
484
|
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === BridgeClientId.MOBILE &&
|
@@ -467,43 +488,31 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
467
488
|
approvalTime = approvalTxMeta?.time;
|
468
489
|
approvalTxId = approvalTxMeta?.id;
|
469
490
|
// Handle smart transactions if enabled
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
491
|
+
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
|
492
|
+
name: isBridgeTx
|
493
|
+
? TraceName.BridgeTransactionCompleted
|
494
|
+
: TraceName.SwapTransactionCompleted,
|
495
|
+
data: {
|
496
|
+
srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),
|
497
|
+
stxEnabled: isStxEnabledOnClient,
|
498
|
+
},
|
499
|
+
}, async () => isStxEnabledOnClient
|
500
|
+
? await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmSmartTransaction, "f").call(this, {
|
480
501
|
isBridgeTx,
|
481
502
|
trade: quoteResponse.trade,
|
482
503
|
quoteResponse,
|
483
504
|
approvalTxId,
|
484
505
|
requireApproval,
|
485
|
-
})
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
? TraceName.BridgeTransactionCompleted
|
491
|
-
: TraceName.SwapTransactionCompleted,
|
492
|
-
data: {
|
493
|
-
srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),
|
494
|
-
stxEnabled: false,
|
495
|
-
},
|
496
|
-
}, async () => await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
497
|
-
transactionType: TransactionType.bridge,
|
506
|
+
})
|
507
|
+
: await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
508
|
+
transactionType: isBridgeTx
|
509
|
+
? TransactionType.bridge
|
510
|
+
: TransactionType.swap,
|
498
511
|
trade: quoteResponse.trade,
|
499
512
|
quoteResponse,
|
500
513
|
approvalTxId,
|
501
514
|
requireApproval,
|
502
515
|
}));
|
503
|
-
}
|
504
|
-
}
|
505
|
-
if (!txMeta) {
|
506
|
-
throw new Error('Failed to submit bridge tx: txMeta is undefined');
|
507
516
|
}
|
508
517
|
try {
|
509
518
|
// Start polling for bridge tx status
|
@@ -519,7 +528,10 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
519
528
|
startTime: approvalTime ?? Date.now(),
|
520
529
|
approvalTxId,
|
521
530
|
});
|
522
|
-
|
531
|
+
// Track Solana Swap completed event
|
532
|
+
if (isSolanaChainId(quoteResponse.quote.srcChainId) && !isBridgeTx) {
|
533
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Completed, txMeta.id);
|
534
|
+
}
|
523
535
|
}
|
524
536
|
catch {
|
525
537
|
// Ignore errors here, we don't want to crash the app if this fails and tx submission succeeds
|
@@ -531,31 +543,29 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
531
543
|
*
|
532
544
|
* @param eventName - The name of the event to track
|
533
545
|
* @param txMetaId - The txMetaId of the history item to track the event for
|
546
|
+
* @param eventProperties - The properties for the event
|
534
547
|
*/
|
535
|
-
_BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId) => {
|
548
|
+
_BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId, eventProperties) => {
|
549
|
+
if (!txMetaId) {
|
550
|
+
this.messagingSystem.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, eventProperties ?? {});
|
551
|
+
return;
|
552
|
+
}
|
536
553
|
const historyItem = this.state.txHistory[txMetaId];
|
537
554
|
if (!historyItem) {
|
538
|
-
this.messagingSystem.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, {});
|
555
|
+
this.messagingSystem.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, eventProperties ?? {});
|
539
556
|
return;
|
540
557
|
}
|
541
|
-
let requiredEventProperties;
|
542
558
|
const selectedAccount = this.messagingSystem.call('AccountsController:getAccountByAddress', historyItem.account);
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
...getTxStatusesFromHistory(historyItem),
|
554
|
-
...getFinalizedTxProperties(historyItem),
|
555
|
-
error_message: 'error_message',
|
556
|
-
price_impact: Number(historyItem.quote.priceData?.priceImpact ?? '0'),
|
557
|
-
};
|
558
|
-
}
|
559
|
+
const requiredEventProperties = {
|
560
|
+
action_type: getActionType(historyItem.quote.srcChainId, historyItem.quote.destChainId),
|
561
|
+
...(eventProperties ?? {}),
|
562
|
+
...getRequestParamFromHistory(historyItem),
|
563
|
+
...getRequestMetadataFromHistory(historyItem, selectedAccount),
|
564
|
+
...getTradeDataFromHistory(historyItem),
|
565
|
+
...getTxStatusesFromHistory(historyItem),
|
566
|
+
...getFinalizedTxProperties(historyItem),
|
567
|
+
...getPriceImpactFromQuote(historyItem.quote),
|
568
|
+
};
|
559
569
|
this.messagingSystem.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, requiredEventProperties);
|
560
570
|
});
|
561
571
|
__classPrivateFieldSet(this, _BridgeStatusController_clientId, clientId, "f");
|
@@ -579,19 +589,13 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
579
589
|
if (type &&
|
580
590
|
[TransactionType.bridge, TransactionType.swap].includes(type) &&
|
581
591
|
![TransactionStatus.signed, TransactionStatus.approved].includes(status)) {
|
582
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, id);
|
592
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, id, getEVMTxPropertiesFromTransactionMeta(transactionMeta));
|
583
593
|
}
|
584
594
|
});
|
585
595
|
this.messagingSystem.subscribe('TransactionController:transactionConfirmed', (transactionMeta) => {
|
586
596
|
const { type, id } = transactionMeta;
|
587
597
|
if (type === TransactionType.swap) {
|
588
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Completed, id);
|
589
|
-
}
|
590
|
-
});
|
591
|
-
this.messagingSystem.subscribe('MultichainTransactionsController:transactionConfirmed', (transactionMeta) => {
|
592
|
-
const { type, id } = transactionMeta;
|
593
|
-
if (type === TransactionType.swap) {
|
594
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Completed, id);
|
598
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Completed, id, getEVMTxPropertiesFromTransactionMeta(transactionMeta));
|
595
599
|
}
|
596
600
|
});
|
597
601
|
// If you close the extension, but keep the browser open, the polling continues
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,WAAW,EACX,0BAA0B,EAC1B,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EACjB,oCAAoC;AAErC,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,8BAA8B;AACjE,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAK/E,OAAO,EACL,iBAAiB,EACjB,eAAe,EAEhB,yCAAyC;AAE1C,OAAO,EAAE,WAAW,EAAY,wBAAwB;AACxD,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,EACL,wBAAwB,EACxB,6BAA6B,EAC7B,sCAAsC,EACtC,mBAAmB,EACnB,SAAS,EACV,wBAAoB;AASrB,OAAO,EAAE,cAAc,EAAE,oBAAgB;AACz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AAe,CAAC,IAAI,EAAE;gBACjC,uBAAA,IAAI,2DAA6B,MAAjC,IAAI,EACF,0BAA0B,CAAC,SAAS,EACpC,EAAE,CACH,CAAC;aACH;QACH,CAAC,CACF,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,SAAS,CAC5B,uDAAuD,EACvD,CAAC,eAAe,EAAE,EAAE;YAClB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;YACrC,IAAI,IAAI,KAAK,eAAe,CAAC,IAAI,EAAE;gBACjC,uBAAA,IAAI,2DAA6B,MAAjC,IAAI,EACF,0BAA0B,CAAC,SAAS,EACpC,EAAE,CACH,CAAC;aACH;QACH,CAAC,CACF,CAAC;QAEF,+EAA+E;QAC/E,8CAA8C;QAC9C,mFAAmF;QACnF,uBAAA,IAAI,uEAAyC,MAA7C,IAAI,CAA2C,CAAC;IAClD,CAAC;CAwyBF;;IAhpBG,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAC9B,iDAAiD,CAClD,CAAC;AACJ,CAAC;IAGC,OAAO,uBAAA,IAAI,+FAA8B,MAAlC,IAAI,CAAgC,EAAE,OAAO,IAAI,EAAE,CAAC;AAC7D,CAAC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport type {\n QuoteMetadata,\n RequiredEventContextFromClient,\n TxData,\n QuoteResponse,\n} from '@metamask/bridge-controller';\nimport {\n formatChainIdToHex,\n getEthUsdtResetData,\n isEthUsdt,\n isSolanaChainId,\n StatusTypes,\n UnifiedSwapBridgeEventName,\n getActionType,\n formatChainIdToCaip,\n isCrossChain,\n getBridgeFeatureFlags,\n isHardwareWallet,\n} from '@metamask/bridge-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport { toHex } from '@metamask/controller-utils';\nimport { EthAccountType, SolScope } from '@metamask/keyring-api';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type {\n TransactionController,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { UserOperationController } from '@metamask/user-operation-controller';\nimport { numberToHex, type Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n BRIDGE_PROD_API_BASE_URL,\n BRIDGE_STATUS_CONTROLLER_NAME,\n DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE,\n REFRESH_INTERVAL_MS,\n TraceName,\n} from './constants';\nimport type {\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n FetchFunction,\n SolanaTransactionMeta,\n BridgeHistoryItem,\n} from './types';\nimport { type BridgeStatusControllerMessenger } from './types';\nimport { BridgeClientId } from './types';\nimport {\n fetchBridgeTxStatus,\n getStatusRequestWithSrcTxHash,\n} from './utils/bridge-status';\nimport { getTxGasEstimates } from './utils/gas';\nimport {\n getFinalizedTxProperties,\n getRequestMetadataFromHistory,\n getRequestParamFromHistory,\n getTradeDataFromHistory,\n getTxStatusesFromHistory,\n} from './utils/metrics';\nimport {\n getClientRequest,\n getKeyringRequest,\n getStatusRequestParams,\n getTxMetaFields,\n handleLineaDelay,\n handleSolanaTxResponse,\n} from './utils/transaction';\nimport { generateActionId } from './utils/transaction';\n\nconst metadata: StateMetadata<BridgeStatusControllerState> = {\n // We want to persist the bridge status state so that we can show the proper data for the Activity list\n // basically match the behavior of TransactionController\n txHistory: {\n persist: true,\n anonymous: false,\n },\n};\n\n/** The input to start polling for the {@link BridgeStatusController} */\ntype BridgeStatusPollingInput = FetchBridgeTxStatusArgs;\n\ntype SrcTxMetaId = string;\nexport type FetchBridgeTxStatusArgs = {\n bridgeTxMetaId: string;\n};\nexport class BridgeStatusController extends StaticIntervalPollingController<BridgeStatusPollingInput>()<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState,\n BridgeStatusControllerMessenger\n> {\n #pollingTokensByTxMetaId: Record<SrcTxMetaId, string> = {};\n\n readonly #clientId: BridgeClientId;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #config: {\n customBridgeApiBaseUrl: string;\n };\n\n readonly #addTransactionFn: typeof TransactionController.prototype.addTransaction;\n\n readonly #estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n\n readonly #addUserOperationFromTransactionFn?: typeof UserOperationController.prototype.addUserOperationFromTransaction;\n\n readonly #trace: TraceCallback;\n\n constructor({\n messenger,\n state,\n clientId,\n fetchFn,\n addTransactionFn,\n addUserOperationFromTransactionFn,\n estimateGasFeeFn,\n config,\n traceFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n state?: Partial<BridgeStatusControllerState>;\n clientId: BridgeClientId;\n fetchFn: FetchFunction;\n addTransactionFn: typeof TransactionController.prototype.addTransaction;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n addUserOperationFromTransactionFn?: typeof UserOperationController.prototype.addUserOperationFromTransaction;\n config?: {\n customBridgeApiBaseUrl?: string;\n };\n traceFn?: TraceCallback;\n }) {\n super({\n name: BRIDGE_STATUS_CONTROLLER_NAME,\n metadata,\n messenger,\n // Restore the persisted state\n state: {\n ...DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE,\n ...state,\n },\n });\n\n this.#clientId = clientId;\n this.#fetchFn = fetchFn;\n this.#addTransactionFn = addTransactionFn;\n this.#addUserOperationFromTransactionFn = addUserOperationFromTransactionFn;\n this.#estimateGasFeeFn = estimateGasFeeFn;\n this.#config = {\n customBridgeApiBaseUrl:\n config?.customBridgeApiBaseUrl ?? BRIDGE_PROD_API_BASE_URL,\n };\n this.#trace = traceFn ?? (((_request, fn) => fn?.()) as TraceCallback);\n\n // Register action handlers\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:startPollingForBridgeTxStatus`,\n this.startPollingForBridgeTxStatus.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:wipeBridgeStatus`,\n this.wipeBridgeStatus.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:resetState`,\n this.resetState.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:submitTx`,\n this.submitTx.bind(this),\n );\n\n // Set interval\n this.setIntervalLength(REFRESH_INTERVAL_MS);\n\n this.messagingSystem.subscribe(\n 'TransactionController:transactionFailed',\n ({ transactionMeta }) => {\n const { type, status, id } = transactionMeta;\n if (\n type &&\n [TransactionType.bridge, TransactionType.swap].includes(type) &&\n ![TransactionStatus.signed, TransactionStatus.approved].includes(\n status,\n )\n ) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Failed,\n id,\n );\n }\n },\n );\n\n this.messagingSystem.subscribe(\n 'TransactionController:transactionConfirmed',\n (transactionMeta) => {\n const { type, id } = transactionMeta;\n if (type === TransactionType.swap) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Completed,\n id,\n );\n }\n },\n );\n\n this.messagingSystem.subscribe(\n 'MultichainTransactionsController:transactionConfirmed',\n (transactionMeta) => {\n const { type, id } = transactionMeta;\n if (type === TransactionType.swap) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Completed,\n id,\n );\n }\n },\n );\n\n // If you close the extension, but keep the browser open, the polling continues\n // If you close the browser, the polling stops\n // Check for historyItems that do not have a status of complete and restart polling\n this.#restartPollingForIncompleteHistoryItems();\n }\n\n resetState = () => {\n this.update((state) => {\n state.txHistory = DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE.txHistory;\n });\n };\n\n wipeBridgeStatus = ({\n address,\n ignoreNetwork,\n }: {\n address: string;\n ignoreNetwork: boolean;\n }) => {\n // Wipe all networks for this address\n if (ignoreNetwork) {\n this.update((state) => {\n state.txHistory = DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE.txHistory;\n });\n } else {\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const selectedNetworkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n const selectedChainId = selectedNetworkClient.configuration.chainId;\n\n this.#wipeBridgeStatusByChainId(address, selectedChainId);\n }\n };\n\n readonly #restartPollingForIncompleteHistoryItems = () => {\n // Check for historyItems that do not have a status of complete and restart polling\n const { txHistory } = this.state;\n const historyItems = Object.values(txHistory);\n const incompleteHistoryItems = historyItems\n .filter(\n (historyItem) =>\n historyItem.status.status === StatusTypes.PENDING ||\n historyItem.status.status === StatusTypes.UNKNOWN,\n )\n .filter((historyItem) => {\n // Check if we are already polling this tx, if so, skip restarting polling for that\n const srcTxMetaId = historyItem.txMetaId;\n const pollingToken = this.#pollingTokensByTxMetaId[srcTxMetaId];\n return !pollingToken;\n })\n // Swap txs don't need to have their statuses polled\n .filter((historyItem) => {\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n return isBridgeTx;\n });\n\n incompleteHistoryItems.forEach((historyItem) => {\n const bridgeTxMetaId = historyItem.txMetaId;\n\n // We manually call startPolling() here rather than go through startPollingForBridgeTxStatus()\n // because we don't want to overwrite the existing historyItem in state\n this.#pollingTokensByTxMetaId[bridgeTxMetaId] = this.startPolling({\n bridgeTxMetaId,\n });\n });\n };\n\n readonly #addTxToHistory = (\n startPollingForBridgeTxStatusArgs: StartPollingForBridgeTxStatusArgsSerialized,\n ) => {\n const {\n bridgeTxMeta,\n statusRequest,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n } = startPollingForBridgeTxStatusArgs;\n const accountAddress = this.#getMultichainSelectedAccountAddress();\n // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API\n // We know it's in progress but not the exact status yet\n const txHistoryItem = {\n txMetaId: bridgeTxMeta.id,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount.amount,\n amountSentInUsd: quoteResponse.sentAmount.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount.usd ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: accountAddress,\n status: {\n // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that\n // Also we know the bare minimum fields for status at this point in time\n status: StatusTypes.PENDING,\n srcChain: {\n chainId: statusRequest.srcChainId,\n txHash: statusRequest.srcTxHash,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: isStxEnabled ?? false,\n };\n this.update((state) => {\n // Use the txMeta.id as the key so we can reference the txMeta in TransactionController\n state.txHistory[bridgeTxMeta.id] = txHistoryItem;\n });\n };\n\n /**\n * Starts polling for the bridge tx status\n *\n * @param txHistoryMeta - The parameters for creating the history item\n */\n startPollingForBridgeTxStatus = (\n txHistoryMeta: StartPollingForBridgeTxStatusArgsSerialized,\n ) => {\n const { quoteResponse, bridgeTxMeta } = txHistoryMeta;\n\n this.#addTxToHistory(txHistoryMeta);\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n if (isBridgeTx) {\n this.#pollingTokensByTxMetaId[bridgeTxMeta.id] = this.startPolling({\n bridgeTxMetaId: bridgeTxMeta.id,\n });\n }\n };\n\n // This will be called after you call this.startPolling()\n // The args passed in are the args you passed in to startPolling()\n _executePoll = async (pollingInput: BridgeStatusPollingInput) => {\n await this.#fetchBridgeTxStatus(pollingInput);\n };\n\n #getMultichainSelectedAccount() {\n return this.messagingSystem.call(\n 'AccountsController:getSelectedMultichainAccount',\n );\n }\n\n #getMultichainSelectedAccountAddress() {\n return this.#getMultichainSelectedAccount()?.address ?? '';\n }\n\n readonly #fetchBridgeTxStatus = async ({\n bridgeTxMetaId,\n }: FetchBridgeTxStatusArgs) => {\n const { txHistory } = this.state;\n\n try {\n // We try here because we receive 500 errors from Bridge API if we try to fetch immediately after submitting the source tx\n // Oddly mostly happens on Optimism, never on Arbitrum. By the 2nd fetch, the Bridge API responds properly.\n // Also srcTxHash may not be available immediately for STX, so we don't want to fetch in those cases\n const historyItem = txHistory[bridgeTxMetaId];\n const srcTxHash = this.#getSrcTxHash(bridgeTxMetaId);\n if (!srcTxHash) {\n return;\n }\n\n this.#updateSrcTxHash(bridgeTxMetaId, srcTxHash);\n\n const statusRequest = getStatusRequestWithSrcTxHash(\n historyItem.quote,\n srcTxHash,\n );\n const status = await fetchBridgeTxStatus(\n statusRequest,\n this.#clientId,\n this.#fetchFn,\n this.#config.customBridgeApiBaseUrl,\n );\n const newBridgeHistoryItem = {\n ...historyItem,\n status,\n completionTime:\n status.status === StatusTypes.COMPLETE ||\n status.status === StatusTypes.FAILED\n ? Date.now()\n : undefined, // TODO make this more accurate by looking up dest txHash block time\n };\n\n // No need to purge these on network change or account change, TransactionController does not purge either.\n // TODO In theory we can skip checking status if it's not the current account/network\n // we need to keep track of the account that this is associated with as well so that we don't show it in Activity list for other accounts\n // First stab at this will not stop polling when you are on a different account\n this.update((state) => {\n state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;\n });\n\n const pollingToken = this.#pollingTokensByTxMetaId[bridgeTxMetaId];\n\n if (\n (status.status === StatusTypes.COMPLETE ||\n status.status === StatusTypes.FAILED) &&\n pollingToken\n ) {\n this.stopPollingByPollingToken(pollingToken);\n\n if (status.status === StatusTypes.COMPLETE) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Completed,\n bridgeTxMetaId,\n );\n }\n if (status.status === StatusTypes.FAILED) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Failed,\n bridgeTxMetaId,\n );\n }\n }\n } catch (e) {\n console.log('Failed to fetch bridge tx status', e);\n }\n };\n\n readonly #getSrcTxHash = (bridgeTxMetaId: string): string | undefined => {\n const { txHistory } = this.state;\n // Prefer the srcTxHash from bridgeStatusState so we don't have to l ook up in TransactionController\n // But it is possible to have bridgeHistoryItem in state without the srcTxHash yet when it is an STX\n const srcTxHash = txHistory[bridgeTxMetaId].status.srcChain.txHash;\n\n if (srcTxHash) {\n return srcTxHash;\n }\n\n // Look up in TransactionController if txMeta has been updated with the srcTxHash\n const txControllerState = this.messagingSystem.call(\n 'TransactionController:getState',\n );\n const txMeta = txControllerState.transactions.find(\n (tx: TransactionMeta) => tx.id === bridgeTxMetaId,\n );\n return txMeta?.hash;\n };\n\n readonly #updateSrcTxHash = (bridgeTxMetaId: string, srcTxHash: string) => {\n const { txHistory } = this.state;\n if (txHistory[bridgeTxMetaId].status.srcChain.txHash) {\n return;\n }\n\n this.update((state) => {\n state.txHistory[bridgeTxMetaId].status.srcChain.txHash = srcTxHash;\n });\n };\n\n // Wipes the bridge status for the given address and chainId\n // Will match only source chainId to the selectedChainId\n readonly #wipeBridgeStatusByChainId = (\n address: string,\n selectedChainId: Hex,\n ) => {\n const sourceTxMetaIdsToDelete = Object.keys(this.state.txHistory).filter(\n (txMetaId) => {\n const bridgeHistoryItem = this.state.txHistory[txMetaId];\n\n const hexSourceChainId = numberToHex(\n bridgeHistoryItem.quote.srcChainId,\n );\n\n return (\n bridgeHistoryItem.account === address &&\n hexSourceChainId === selectedChainId\n );\n },\n );\n\n sourceTxMetaIdsToDelete.forEach((sourceTxMetaId) => {\n const pollingToken = this.#pollingTokensByTxMetaId[sourceTxMetaId];\n\n if (pollingToken) {\n this.stopPollingByPollingToken(\n this.#pollingTokensByTxMetaId[sourceTxMetaId],\n );\n }\n });\n\n this.update((state) => {\n state.txHistory = sourceTxMetaIdsToDelete.reduce(\n (acc, sourceTxMetaId) => {\n delete acc[sourceTxMetaId];\n return acc;\n },\n state.txHistory,\n );\n });\n };\n\n /**\n * ******************************************************\n * TX SUBMISSION HANDLING\n *******************************************************\n */\n\n /**\n * Submits the transaction to the snap using the keyring rpc method\n * This adds an approval tx to the ApprovalsController in the background\n * The client needs to handle the approval tx by redirecting to the confirmation page with the approvalTxId in the URL\n *\n * @param quoteResponse - The quote response\n * @param quoteResponse.quote - The quote\n * @returns The transaction meta\n */\n readonly #handleSolanaTx = async (\n quoteResponse: QuoteResponse<string> & QuoteMetadata,\n ) => {\n const selectedAccount = this.#getMultichainSelectedAccount();\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: undefined multichain account',\n );\n }\n if (!selectedAccount?.metadata?.snap?.id) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: undefined snap id',\n );\n }\n\n const bridgeFeatureFlags = getBridgeFeatureFlags(this.messagingSystem);\n const request = bridgeFeatureFlags?.chains?.[SolScope.Mainnet]\n ?.isSnapConfirmationEnabled\n ? getKeyringRequest(quoteResponse, selectedAccount)\n : getClientRequest(quoteResponse, selectedAccount);\n const requestResponse = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n request,\n )) as string | { result: Record<string, string> };\n\n // The extension client actually redirects before it can do anytyhing with this meta\n const txMeta = handleSolanaTxResponse(\n requestResponse,\n quoteResponse,\n selectedAccount,\n );\n\n // TODO remove this eventually, just returning it now to match extension behavior\n // 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\n return txMeta;\n };\n\n readonly #waitForHashAndReturnFinalTxMeta = async (\n hashPromise?:\n | Awaited<ReturnType<TransactionController['addTransaction']>>['result']\n | Awaited<\n ReturnType<UserOperationController['addUserOperationFromTransaction']>\n >['hash'],\n ): Promise<TransactionMeta | undefined> => {\n const transactionHash = await hashPromise;\n const finalTransactionMeta: TransactionMeta | undefined =\n this.messagingSystem\n .call('TransactionController:getState')\n .transactions.find(\n (tx: TransactionMeta) => tx.hash === transactionHash,\n );\n return finalTransactionMeta;\n };\n\n readonly #handleApprovalTx = async (\n isBridgeTx: boolean,\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata,\n requireApproval = false,\n ): Promise<TransactionMeta | undefined> => {\n const { approval } = quoteResponse;\n\n if (approval) {\n const approveTx = async () => {\n await this.#handleUSDTAllowanceReset(quoteResponse);\n\n const approvalTxMeta = await this.#handleEvmTransaction({\n transactionType: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n trade: approval,\n quoteResponse,\n requireApproval,\n });\n if (!approvalTxMeta) {\n throw new Error(\n 'Failed to submit bridge tx: approval txMeta is undefined',\n );\n }\n\n await handleLineaDelay(quoteResponse);\n return approvalTxMeta;\n };\n\n return await this.#trace(\n {\n name: isBridgeTx\n ? TraceName.BridgeTransactionApprovalCompleted\n : TraceName.SwapTransactionApprovalCompleted,\n data: {\n srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),\n stxEnabled: false,\n },\n },\n approveTx,\n );\n }\n\n return undefined;\n };\n\n readonly #handleEvmSmartTransaction = async ({\n isBridgeTx,\n trade,\n quoteResponse,\n approvalTxId,\n requireApproval = false,\n }: {\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n approvalTxId?: string;\n requireApproval?: boolean;\n }) => {\n return await this.#handleEvmTransaction({\n transactionType: isBridgeTx\n ? TransactionType.bridge\n : TransactionType.swap,\n trade,\n quoteResponse,\n approvalTxId,\n shouldWaitForHash: false, // Set to false to indicate we don't want to wait for hash\n requireApproval,\n });\n };\n\n /**\n * Submits an EVM transaction to the TransactionController\n *\n * @param params - The parameters for the transaction\n * @param params.transactionType - The type of transaction to submit\n * @param params.trade - The trade data to confirm\n * @param params.quoteResponse - The quote response\n * @param params.approvalTxId - The tx id of the approval tx\n * @param params.shouldWaitForHash - Whether to wait for the hash of the transaction\n * @param params.requireApproval - Whether to require approval for the transaction\n * @returns The transaction meta\n */\n readonly #handleEvmTransaction = async ({\n transactionType,\n trade,\n quoteResponse,\n approvalTxId,\n shouldWaitForHash = true,\n requireApproval = false,\n }: {\n transactionType: TransactionType;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n approvalTxId?: string;\n shouldWaitForHash?: boolean;\n requireApproval?: boolean;\n }): Promise<TransactionMeta | undefined> => {\n const actionId = generateActionId().toString();\n\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = this.messagingSystem.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n const requestOptions = {\n actionId,\n networkClientId,\n requireApproval,\n type: transactionType,\n origin: 'metamask',\n };\n const transactionParams: Parameters<\n TransactionController['addTransaction']\n >[0] = {\n ...trade,\n chainId: hexChainId,\n gasLimit: trade.gasLimit?.toString(),\n gas: trade.gasLimit?.toString(),\n };\n const transactionParamsWithMaxGas: TransactionParams = {\n ...transactionParams,\n ...(await this.#calculateGasFees(\n transactionParams,\n networkClientId,\n hexChainId,\n )),\n };\n\n let result:\n | Awaited<ReturnType<TransactionController['addTransaction']>>['result']\n | Awaited<\n ReturnType<UserOperationController['addUserOperationFromTransaction']>\n >['hash']\n | undefined;\n let transactionMeta: TransactionMeta | undefined;\n\n const isSmartContractAccount =\n selectedAccount.type === EthAccountType.Erc4337;\n if (isSmartContractAccount && this.#addUserOperationFromTransactionFn) {\n const smartAccountTxResult =\n await this.#addUserOperationFromTransactionFn(\n transactionParamsWithMaxGas,\n requestOptions,\n );\n result = smartAccountTxResult.transactionHash;\n transactionMeta = {\n ...requestOptions,\n chainId: hexChainId,\n txParams: transactionParamsWithMaxGas,\n time: Date.now(),\n id: smartAccountTxResult.id,\n status: TransactionStatus.confirmed,\n };\n } else {\n const addTransactionResult = await this.#addTransactionFn(\n transactionParamsWithMaxGas,\n requestOptions,\n );\n result = addTransactionResult.result;\n transactionMeta = addTransactionResult.transactionMeta;\n }\n\n if (shouldWaitForHash) {\n return await this.#waitForHashAndReturnFinalTxMeta(result);\n }\n\n return {\n ...getTxMetaFields(quoteResponse, approvalTxId),\n ...transactionMeta,\n };\n };\n\n readonly #handleUSDTAllowanceReset = async (\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n ) => {\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n if (\n quoteResponse.approval &&\n isEthUsdt(hexChainId, quoteResponse.quote.srcAsset.address)\n ) {\n const allowance = new BigNumber(\n await this.messagingSystem.call(\n 'BridgeController:getBridgeERC20Allowance',\n quoteResponse.quote.srcAsset.address,\n hexChainId,\n ),\n );\n const shouldResetApproval =\n allowance.lt(quoteResponse.sentAmount.amount) && allowance.gt(0);\n if (shouldResetApproval) {\n await this.#handleEvmTransaction({\n transactionType: TransactionType.bridgeApproval,\n trade: { ...quoteResponse.approval, data: getEthUsdtResetData() },\n quoteResponse,\n });\n }\n }\n };\n\n readonly #calculateGasFees = async (\n transactionParams: TransactionParams,\n networkClientId: string,\n chainId: Hex,\n ) => {\n const { gasFeeEstimates } = this.messagingSystem.call(\n 'GasFeeController:getState',\n );\n const { estimates: txGasFeeEstimates } = await this.#estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n };\n\n /**\n * Submits a cross-chain swap transaction\n *\n * @param quoteResponse - The quote response\n * @param isStxEnabledOnClient - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension\n * @returns The transaction meta\n */\n submitTx = async (\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n isStxEnabledOnClient: boolean,\n ): Promise<TransactionMeta & Partial<SolanaTransactionMeta>> => {\n this.messagingSystem.call('BridgeController:stopPollingForQuotes');\n\n let txMeta: (TransactionMeta & Partial<SolanaTransactionMeta>) | undefined;\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n // Submit SOLANA tx\n if (\n isSolanaChainId(quoteResponse.quote.srcChainId) &&\n typeof quoteResponse.trade === 'string'\n ) {\n txMeta = await this.#trace(\n {\n name: isBridgeTx\n ? TraceName.BridgeTransactionCompleted\n : TraceName.SwapTransactionCompleted,\n data: {\n srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),\n stxEnabled: false,\n },\n },\n async () =>\n await this.#handleSolanaTx(\n quoteResponse as QuoteResponse<string> & QuoteMetadata,\n ),\n );\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.SnapConfirmationViewed,\n txMeta.id,\n );\n }\n // Submit EVM tx\n let approvalTime: number | undefined, approvalTxId: string | undefined;\n if (\n !isSolanaChainId(quoteResponse.quote.srcChainId) &&\n typeof quoteResponse.trade !== 'string'\n ) {\n // For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval\n // Extension does not have this issue\n const requireApproval =\n this.#clientId === BridgeClientId.MOBILE &&\n isHardwareWallet(this.#getMultichainSelectedAccount());\n\n // Set approval time and id if an approval tx is needed\n const approvalTxMeta = await this.#handleApprovalTx(\n isBridgeTx,\n quoteResponse,\n requireApproval,\n );\n approvalTime = approvalTxMeta?.time;\n approvalTxId = approvalTxMeta?.id;\n // Handle smart transactions if enabled\n if (isStxEnabledOnClient) {\n txMeta = await this.#trace(\n {\n name: isBridgeTx\n ? TraceName.BridgeTransactionCompleted\n : TraceName.SwapTransactionCompleted,\n data: {\n srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),\n stxEnabled: true,\n },\n },\n async () =>\n await this.#handleEvmSmartTransaction({\n isBridgeTx,\n trade: quoteResponse.trade as TxData,\n quoteResponse,\n approvalTxId,\n requireApproval,\n }),\n );\n } else {\n txMeta = await this.#trace(\n {\n name: isBridgeTx\n ? TraceName.BridgeTransactionCompleted\n : TraceName.SwapTransactionCompleted,\n data: {\n srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),\n stxEnabled: false,\n },\n },\n async () =>\n await this.#handleEvmTransaction({\n transactionType: TransactionType.bridge,\n trade: quoteResponse.trade as TxData,\n quoteResponse,\n approvalTxId,\n requireApproval,\n }),\n );\n }\n }\n\n if (!txMeta) {\n throw new Error('Failed to submit bridge tx: txMeta is undefined');\n }\n\n try {\n // Start polling for bridge tx status\n this.startPollingForBridgeTxStatus({\n bridgeTxMeta: txMeta, // Only the id field is used by the BridgeStatusController\n statusRequest: {\n ...getStatusRequestParams(quoteResponse),\n srcTxHash: txMeta.hash,\n },\n quoteResponse,\n slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request\n isStxEnabled: isStxEnabledOnClient,\n startTime: approvalTime ?? Date.now(),\n approvalTxId,\n });\n\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Submitted,\n txMeta.id,\n );\n } catch {\n // Ignore errors here, we don't want to crash the app if this fails and tx submission succeeds\n }\n return txMeta;\n };\n\n /**\n * Tracks post-submission events for a cross-chain swap based on the history item\n *\n * @param eventName - The name of the event to track\n * @param txMetaId - The txMetaId of the history item to track the event for\n */\n readonly #trackUnifiedSwapBridgeEvent = <\n T extends\n | typeof UnifiedSwapBridgeEventName.Submitted\n | typeof UnifiedSwapBridgeEventName.Failed\n | typeof UnifiedSwapBridgeEventName.SnapConfirmationViewed\n | typeof UnifiedSwapBridgeEventName.Completed,\n >(\n eventName: T,\n txMetaId: string,\n ) => {\n const historyItem: BridgeHistoryItem | undefined =\n this.state.txHistory[txMetaId];\n if (!historyItem) {\n this.messagingSystem.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n {},\n );\n return;\n }\n\n let requiredEventProperties: Pick<RequiredEventContextFromClient, T>[T];\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getAccountByAddress',\n historyItem.account,\n );\n\n switch (eventName) {\n case UnifiedSwapBridgeEventName.Submitted:\n case UnifiedSwapBridgeEventName.Completed:\n case UnifiedSwapBridgeEventName.Failed:\n default:\n requiredEventProperties = {\n action_type: getActionType(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n ),\n ...getRequestParamFromHistory(historyItem),\n ...getRequestMetadataFromHistory(historyItem, selectedAccount),\n ...getTradeDataFromHistory(historyItem),\n ...getTxStatusesFromHistory(historyItem),\n ...getFinalizedTxProperties(historyItem),\n error_message: 'error_message',\n price_impact: Number(historyItem.quote.priceData?.priceImpact ?? '0'),\n };\n }\n\n this.messagingSystem.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n requiredEventProperties,\n );\n };\n}\n"]}
|
1
|
+
{"version":3,"file":"bridge-status-controller.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,WAAW,EACX,0BAA0B,EAC1B,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EACjB,oCAAoC;AAErC,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,8BAA8B;AACjE,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAK/E,OAAO,EACL,iBAAiB,EACjB,eAAe,EAEhB,yCAAyC;AAE1C,OAAO,EAAE,WAAW,EAAY,wBAAwB;AACxD,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,EACL,wBAAwB,EACxB,6BAA6B,EAC7B,sCAAsC,EACtC,mBAAmB,EACnB,SAAS,EACV,wBAAoB;AASrB,OAAO,EAAE,cAAc,EAAE,oBAAgB;AACzC,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC9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QAAQ,CAC9D,MAAM,CACP,EACD;gBACA,uBAAA,IAAI,2DAA6B,MAAjC,IAAI,EACF,0BAA0B,CAAC,MAAM,EACjC,EAAE,EACF,qCAAqC,CAAC,eAAe,CAAC,CACvD,CAAC;aACH;QACH,CAAC,CACF,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,SAAS,CAC5B,4CAA4C,EAC5C,CAAC,eAAe,EAAE,EAAE;YAClB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;YACrC,IAAI,IAAI,KAAK,eAAe,CAAC,IAAI,EAAE;gBACjC,uBAAA,IAAI,2DAA6B,MAAjC,IAAI,EACF,0BAA0B,CAAC,SAAS,EACpC,EAAE,EACF,qCAAqC,CAAC,eAAe,CAAC,CACvD,CAAC;aACH;QACH,CAAC,CACF,CAAC;QAEF,+EAA+E;QAC/E,8CAA8C;QAC9C,mFAAmF;QACnF,uBAAA,IAAI,uEAAyC,MAA7C,IAAI,CAA2C,CAAC;IAClD,CAAC;CAozBF;;IA5pBG,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAC9B,iDAAiD,CAClD,CAAC;AACJ,CAAC;IAGC,OAAO,uBAAA,IAAI,+FAA8B,MAAlC,IAAI,CAAgC,EAAE,OAAO,IAAI,EAAE,CAAC;AAC7D,CAAC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport type {\n QuoteMetadata,\n RequiredEventContextFromClient,\n TxData,\n QuoteResponse,\n} from '@metamask/bridge-controller';\nimport {\n formatChainIdToHex,\n getEthUsdtResetData,\n isEthUsdt,\n isSolanaChainId,\n StatusTypes,\n UnifiedSwapBridgeEventName,\n getActionType,\n formatChainIdToCaip,\n isCrossChain,\n getBridgeFeatureFlags,\n isHardwareWallet,\n} from '@metamask/bridge-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport { toHex } from '@metamask/controller-utils';\nimport { EthAccountType, SolScope } from '@metamask/keyring-api';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type {\n TransactionController,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { UserOperationController } from '@metamask/user-operation-controller';\nimport { numberToHex, type Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n BRIDGE_PROD_API_BASE_URL,\n BRIDGE_STATUS_CONTROLLER_NAME,\n DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE,\n REFRESH_INTERVAL_MS,\n TraceName,\n} from './constants';\nimport type {\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n FetchFunction,\n SolanaTransactionMeta,\n BridgeHistoryItem,\n} from './types';\nimport { type BridgeStatusControllerMessenger } from './types';\nimport { BridgeClientId } from './types';\nimport {\n fetchBridgeTxStatus,\n getStatusRequestWithSrcTxHash,\n} from './utils/bridge-status';\nimport { getTxGasEstimates } from './utils/gas';\nimport {\n getFinalizedTxProperties,\n getPriceImpactFromQuote,\n getRequestMetadataFromHistory,\n getRequestParamFromHistory,\n getTradeDataFromHistory,\n getTradeDataFromQuote,\n getEVMTxPropertiesFromTransactionMeta,\n getTxStatusesFromHistory,\n} from './utils/metrics';\nimport {\n getClientRequest,\n getKeyringRequest,\n getStatusRequestParams,\n getTxMetaFields,\n handleLineaDelay,\n handleSolanaTxResponse,\n} from './utils/transaction';\nimport { generateActionId } from './utils/transaction';\n\nconst metadata: StateMetadata<BridgeStatusControllerState> = {\n // We want to persist the bridge status state so that we can show the proper data for the Activity list\n // basically match the behavior of TransactionController\n txHistory: {\n persist: true,\n anonymous: false,\n },\n};\n\n/** The input to start polling for the {@link BridgeStatusController} */\ntype BridgeStatusPollingInput = FetchBridgeTxStatusArgs;\n\ntype SrcTxMetaId = string;\nexport type FetchBridgeTxStatusArgs = {\n bridgeTxMetaId: string;\n};\nexport class BridgeStatusController extends StaticIntervalPollingController<BridgeStatusPollingInput>()<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState,\n BridgeStatusControllerMessenger\n> {\n #pollingTokensByTxMetaId: Record<SrcTxMetaId, string> = {};\n\n readonly #clientId: BridgeClientId;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #config: {\n customBridgeApiBaseUrl: string;\n };\n\n readonly #addTransactionFn: typeof TransactionController.prototype.addTransaction;\n\n readonly #estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n\n readonly #addUserOperationFromTransactionFn?: typeof UserOperationController.prototype.addUserOperationFromTransaction;\n\n readonly #trace: TraceCallback;\n\n constructor({\n messenger,\n state,\n clientId,\n fetchFn,\n addTransactionFn,\n addUserOperationFromTransactionFn,\n estimateGasFeeFn,\n config,\n traceFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n state?: Partial<BridgeStatusControllerState>;\n clientId: BridgeClientId;\n fetchFn: FetchFunction;\n addTransactionFn: typeof TransactionController.prototype.addTransaction;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n addUserOperationFromTransactionFn?: typeof UserOperationController.prototype.addUserOperationFromTransaction;\n config?: {\n customBridgeApiBaseUrl?: string;\n };\n traceFn?: TraceCallback;\n }) {\n super({\n name: BRIDGE_STATUS_CONTROLLER_NAME,\n metadata,\n messenger,\n // Restore the persisted state\n state: {\n ...DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE,\n ...state,\n },\n });\n\n this.#clientId = clientId;\n this.#fetchFn = fetchFn;\n this.#addTransactionFn = addTransactionFn;\n this.#addUserOperationFromTransactionFn = addUserOperationFromTransactionFn;\n this.#estimateGasFeeFn = estimateGasFeeFn;\n this.#config = {\n customBridgeApiBaseUrl:\n config?.customBridgeApiBaseUrl ?? BRIDGE_PROD_API_BASE_URL,\n };\n this.#trace = traceFn ?? (((_request, fn) => fn?.()) as TraceCallback);\n\n // Register action handlers\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:startPollingForBridgeTxStatus`,\n this.startPollingForBridgeTxStatus.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:wipeBridgeStatus`,\n this.wipeBridgeStatus.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:resetState`,\n this.resetState.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_STATUS_CONTROLLER_NAME}:submitTx`,\n this.submitTx.bind(this),\n );\n\n // Set interval\n this.setIntervalLength(REFRESH_INTERVAL_MS);\n\n this.messagingSystem.subscribe(\n 'TransactionController:transactionFailed',\n ({ transactionMeta }) => {\n const { type, status, id } = transactionMeta;\n if (\n type &&\n [TransactionType.bridge, TransactionType.swap].includes(type) &&\n ![TransactionStatus.signed, TransactionStatus.approved].includes(\n status,\n )\n ) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Failed,\n id,\n getEVMTxPropertiesFromTransactionMeta(transactionMeta),\n );\n }\n },\n );\n\n this.messagingSystem.subscribe(\n 'TransactionController:transactionConfirmed',\n (transactionMeta) => {\n const { type, id } = transactionMeta;\n if (type === TransactionType.swap) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Completed,\n id,\n getEVMTxPropertiesFromTransactionMeta(transactionMeta),\n );\n }\n },\n );\n\n // If you close the extension, but keep the browser open, the polling continues\n // If you close the browser, the polling stops\n // Check for historyItems that do not have a status of complete and restart polling\n this.#restartPollingForIncompleteHistoryItems();\n }\n\n resetState = () => {\n this.update((state) => {\n state.txHistory = DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE.txHistory;\n });\n };\n\n wipeBridgeStatus = ({\n address,\n ignoreNetwork,\n }: {\n address: string;\n ignoreNetwork: boolean;\n }) => {\n // Wipe all networks for this address\n if (ignoreNetwork) {\n this.update((state) => {\n state.txHistory = DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE.txHistory;\n });\n } else {\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n const selectedNetworkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n const selectedChainId = selectedNetworkClient.configuration.chainId;\n\n this.#wipeBridgeStatusByChainId(address, selectedChainId);\n }\n };\n\n readonly #restartPollingForIncompleteHistoryItems = () => {\n // Check for historyItems that do not have a status of complete and restart polling\n const { txHistory } = this.state;\n const historyItems = Object.values(txHistory);\n const incompleteHistoryItems = historyItems\n .filter(\n (historyItem) =>\n historyItem.status.status === StatusTypes.PENDING ||\n historyItem.status.status === StatusTypes.UNKNOWN,\n )\n .filter((historyItem) => {\n // Check if we are already polling this tx, if so, skip restarting polling for that\n const srcTxMetaId = historyItem.txMetaId;\n const pollingToken = this.#pollingTokensByTxMetaId[srcTxMetaId];\n return !pollingToken;\n })\n // Swap txs don't need to have their statuses polled\n .filter((historyItem) => {\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n return isBridgeTx;\n });\n\n incompleteHistoryItems.forEach((historyItem) => {\n const bridgeTxMetaId = historyItem.txMetaId;\n\n // We manually call startPolling() here rather than go through startPollingForBridgeTxStatus()\n // because we don't want to overwrite the existing historyItem in state\n this.#pollingTokensByTxMetaId[bridgeTxMetaId] = this.startPolling({\n bridgeTxMetaId,\n });\n });\n };\n\n readonly #addTxToHistory = (\n startPollingForBridgeTxStatusArgs: StartPollingForBridgeTxStatusArgsSerialized,\n ) => {\n const {\n bridgeTxMeta,\n statusRequest,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n } = startPollingForBridgeTxStatusArgs;\n const accountAddress = this.#getMultichainSelectedAccountAddress();\n // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API\n // We know it's in progress but not the exact status yet\n const txHistoryItem = {\n txMetaId: bridgeTxMeta.id,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount.amount,\n amountSentInUsd: quoteResponse.sentAmount.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount.usd ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: accountAddress,\n status: {\n // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that\n // Also we know the bare minimum fields for status at this point in time\n status: StatusTypes.PENDING,\n srcChain: {\n chainId: statusRequest.srcChainId,\n txHash: statusRequest.srcTxHash,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: isStxEnabled ?? false,\n };\n this.update((state) => {\n // Use the txMeta.id as the key so we can reference the txMeta in TransactionController\n state.txHistory[bridgeTxMeta.id] = txHistoryItem;\n });\n };\n\n /**\n * Starts polling for the bridge tx status\n *\n * @param txHistoryMeta - The parameters for creating the history item\n */\n startPollingForBridgeTxStatus = (\n txHistoryMeta: StartPollingForBridgeTxStatusArgsSerialized,\n ) => {\n const { quoteResponse, bridgeTxMeta } = txHistoryMeta;\n\n this.#addTxToHistory(txHistoryMeta);\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n if (isBridgeTx) {\n this.#pollingTokensByTxMetaId[bridgeTxMeta.id] = this.startPolling({\n bridgeTxMetaId: bridgeTxMeta.id,\n });\n }\n };\n\n // This will be called after you call this.startPolling()\n // The args passed in are the args you passed in to startPolling()\n _executePoll = async (pollingInput: BridgeStatusPollingInput) => {\n await this.#fetchBridgeTxStatus(pollingInput);\n };\n\n #getMultichainSelectedAccount() {\n return this.messagingSystem.call(\n 'AccountsController:getSelectedMultichainAccount',\n );\n }\n\n #getMultichainSelectedAccountAddress() {\n return this.#getMultichainSelectedAccount()?.address ?? '';\n }\n\n readonly #fetchBridgeTxStatus = async ({\n bridgeTxMetaId,\n }: FetchBridgeTxStatusArgs) => {\n const { txHistory } = this.state;\n\n try {\n // We try here because we receive 500 errors from Bridge API if we try to fetch immediately after submitting the source tx\n // Oddly mostly happens on Optimism, never on Arbitrum. By the 2nd fetch, the Bridge API responds properly.\n // Also srcTxHash may not be available immediately for STX, so we don't want to fetch in those cases\n const historyItem = txHistory[bridgeTxMetaId];\n const srcTxHash = this.#getSrcTxHash(bridgeTxMetaId);\n if (!srcTxHash) {\n return;\n }\n\n this.#updateSrcTxHash(bridgeTxMetaId, srcTxHash);\n\n const statusRequest = getStatusRequestWithSrcTxHash(\n historyItem.quote,\n srcTxHash,\n );\n const status = await fetchBridgeTxStatus(\n statusRequest,\n this.#clientId,\n this.#fetchFn,\n this.#config.customBridgeApiBaseUrl,\n );\n const newBridgeHistoryItem = {\n ...historyItem,\n status,\n completionTime:\n status.status === StatusTypes.COMPLETE ||\n status.status === StatusTypes.FAILED\n ? Date.now()\n : undefined, // TODO make this more accurate by looking up dest txHash block time\n };\n\n // No need to purge these on network change or account change, TransactionController does not purge either.\n // TODO In theory we can skip checking status if it's not the current account/network\n // we need to keep track of the account that this is associated with as well so that we don't show it in Activity list for other accounts\n // First stab at this will not stop polling when you are on a different account\n this.update((state) => {\n state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;\n });\n\n const pollingToken = this.#pollingTokensByTxMetaId[bridgeTxMetaId];\n\n if (\n (status.status === StatusTypes.COMPLETE ||\n status.status === StatusTypes.FAILED) &&\n pollingToken\n ) {\n this.stopPollingByPollingToken(pollingToken);\n\n if (status.status === StatusTypes.COMPLETE) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Completed,\n bridgeTxMetaId,\n );\n }\n if (status.status === StatusTypes.FAILED) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Failed,\n bridgeTxMetaId,\n );\n }\n }\n } catch (e) {\n console.log('Failed to fetch bridge tx status', e);\n }\n };\n\n readonly #getSrcTxHash = (bridgeTxMetaId: string): string | undefined => {\n const { txHistory } = this.state;\n // Prefer the srcTxHash from bridgeStatusState so we don't have to l ook up in TransactionController\n // But it is possible to have bridgeHistoryItem in state without the srcTxHash yet when it is an STX\n const srcTxHash = txHistory[bridgeTxMetaId].status.srcChain.txHash;\n\n if (srcTxHash) {\n return srcTxHash;\n }\n\n // Look up in TransactionController if txMeta has been updated with the srcTxHash\n const txControllerState = this.messagingSystem.call(\n 'TransactionController:getState',\n );\n const txMeta = txControllerState.transactions.find(\n (tx: TransactionMeta) => tx.id === bridgeTxMetaId,\n );\n return txMeta?.hash;\n };\n\n readonly #updateSrcTxHash = (bridgeTxMetaId: string, srcTxHash: string) => {\n const { txHistory } = this.state;\n if (txHistory[bridgeTxMetaId].status.srcChain.txHash) {\n return;\n }\n\n this.update((state) => {\n state.txHistory[bridgeTxMetaId].status.srcChain.txHash = srcTxHash;\n });\n };\n\n // Wipes the bridge status for the given address and chainId\n // Will match only source chainId to the selectedChainId\n readonly #wipeBridgeStatusByChainId = (\n address: string,\n selectedChainId: Hex,\n ) => {\n const sourceTxMetaIdsToDelete = Object.keys(this.state.txHistory).filter(\n (txMetaId) => {\n const bridgeHistoryItem = this.state.txHistory[txMetaId];\n\n const hexSourceChainId = numberToHex(\n bridgeHistoryItem.quote.srcChainId,\n );\n\n return (\n bridgeHistoryItem.account === address &&\n hexSourceChainId === selectedChainId\n );\n },\n );\n\n sourceTxMetaIdsToDelete.forEach((sourceTxMetaId) => {\n const pollingToken = this.#pollingTokensByTxMetaId[sourceTxMetaId];\n\n if (pollingToken) {\n this.stopPollingByPollingToken(\n this.#pollingTokensByTxMetaId[sourceTxMetaId],\n );\n }\n });\n\n this.update((state) => {\n state.txHistory = sourceTxMetaIdsToDelete.reduce(\n (acc, sourceTxMetaId) => {\n delete acc[sourceTxMetaId];\n return acc;\n },\n state.txHistory,\n );\n });\n };\n\n /**\n * ******************************************************\n * TX SUBMISSION HANDLING\n *******************************************************\n */\n\n /**\n * Submits the transaction to the snap using the keyring rpc method\n * This adds an approval tx to the ApprovalsController in the background\n * The client needs to handle the approval tx by redirecting to the confirmation page with the approvalTxId in the URL\n *\n * @param quoteResponse - The quote response\n * @param quoteResponse.quote - The quote\n * @returns The transaction meta\n */\n readonly #handleSolanaTx = async (\n quoteResponse: QuoteResponse<string> & QuoteMetadata,\n ) => {\n const selectedAccount = this.#getMultichainSelectedAccount();\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: undefined multichain account',\n );\n }\n if (!selectedAccount?.metadata?.snap?.id) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: undefined snap id',\n );\n }\n\n const bridgeFeatureFlags = getBridgeFeatureFlags(this.messagingSystem);\n const request = bridgeFeatureFlags?.chains?.[SolScope.Mainnet]\n ?.isSnapConfirmationEnabled\n ? getKeyringRequest(quoteResponse, selectedAccount)\n : getClientRequest(quoteResponse, selectedAccount);\n const requestResponse = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n request,\n )) as string | { result: Record<string, string> } | { signature: string };\n\n // The extension client actually redirects before it can do anytyhing with this meta\n const txMeta = handleSolanaTxResponse(\n requestResponse,\n quoteResponse,\n selectedAccount,\n );\n\n // TODO remove this eventually, just returning it now to match extension behavior\n // 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\n return txMeta;\n };\n\n readonly #waitForHashAndReturnFinalTxMeta = async (\n hashPromise?:\n | Awaited<ReturnType<TransactionController['addTransaction']>>['result']\n | Awaited<\n ReturnType<UserOperationController['addUserOperationFromTransaction']>\n >['hash'],\n ): Promise<TransactionMeta> => {\n const transactionHash = await hashPromise;\n const finalTransactionMeta: TransactionMeta | undefined =\n this.messagingSystem\n .call('TransactionController:getState')\n .transactions.find(\n (tx: TransactionMeta) => tx.hash === transactionHash,\n );\n if (!finalTransactionMeta) {\n throw new Error(\n 'Failed to submit cross-chain swap tx: txMeta for txHash was not found',\n );\n }\n return finalTransactionMeta;\n };\n\n readonly #handleApprovalTx = async (\n isBridgeTx: boolean,\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata,\n requireApproval = false,\n ): Promise<TransactionMeta | undefined> => {\n const { approval } = quoteResponse;\n\n if (approval) {\n const approveTx = async () => {\n await this.#handleUSDTAllowanceReset(quoteResponse);\n\n const approvalTxMeta = await this.#handleEvmTransaction({\n transactionType: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n trade: approval,\n quoteResponse,\n requireApproval,\n });\n\n await handleLineaDelay(quoteResponse);\n return approvalTxMeta;\n };\n\n return await this.#trace(\n {\n name: isBridgeTx\n ? TraceName.BridgeTransactionApprovalCompleted\n : TraceName.SwapTransactionApprovalCompleted,\n data: {\n srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),\n stxEnabled: false,\n },\n },\n approveTx,\n );\n }\n\n return undefined;\n };\n\n readonly #handleEvmSmartTransaction = async ({\n isBridgeTx,\n trade,\n quoteResponse,\n approvalTxId,\n requireApproval = false,\n }: {\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n approvalTxId?: string;\n requireApproval?: boolean;\n }) => {\n return await this.#handleEvmTransaction({\n transactionType: isBridgeTx\n ? TransactionType.bridge\n : TransactionType.swap,\n trade,\n quoteResponse,\n approvalTxId,\n shouldWaitForHash: false, // Set to false to indicate we don't want to wait for hash\n requireApproval,\n });\n };\n\n /**\n * Submits an EVM transaction to the TransactionController\n *\n * @param params - The parameters for the transaction\n * @param params.transactionType - The type of transaction to submit\n * @param params.trade - The trade data to confirm\n * @param params.quoteResponse - The quote response\n * @param params.approvalTxId - The tx id of the approval tx\n * @param params.shouldWaitForHash - Whether to wait for the hash of the transaction\n * @param params.requireApproval - Whether to require approval for the transaction\n * @returns The transaction meta\n */\n readonly #handleEvmTransaction = async ({\n transactionType,\n trade,\n quoteResponse,\n approvalTxId,\n shouldWaitForHash = true,\n requireApproval = false,\n }: {\n transactionType: TransactionType;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n approvalTxId?: string;\n shouldWaitForHash?: boolean;\n requireApproval?: boolean;\n }): Promise<TransactionMeta> => {\n const actionId = generateActionId().toString();\n\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = this.messagingSystem.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n const requestOptions = {\n actionId,\n networkClientId,\n requireApproval,\n type: transactionType,\n origin: 'metamask',\n };\n const transactionParams: Parameters<\n TransactionController['addTransaction']\n >[0] = {\n ...trade,\n chainId: hexChainId,\n gasLimit: trade.gasLimit?.toString(),\n gas: trade.gasLimit?.toString(),\n };\n const transactionParamsWithMaxGas: TransactionParams = {\n ...transactionParams,\n ...(await this.#calculateGasFees(\n transactionParams,\n networkClientId,\n hexChainId,\n )),\n };\n\n let result:\n | Awaited<ReturnType<TransactionController['addTransaction']>>['result']\n | Awaited<\n ReturnType<UserOperationController['addUserOperationFromTransaction']>\n >['hash']\n | undefined;\n let transactionMeta: TransactionMeta | undefined;\n\n const isSmartContractAccount =\n selectedAccount.type === EthAccountType.Erc4337;\n if (isSmartContractAccount && this.#addUserOperationFromTransactionFn) {\n const smartAccountTxResult =\n await this.#addUserOperationFromTransactionFn(\n transactionParamsWithMaxGas,\n requestOptions,\n );\n result = smartAccountTxResult.transactionHash;\n transactionMeta = {\n ...requestOptions,\n chainId: hexChainId,\n txParams: transactionParamsWithMaxGas,\n time: Date.now(),\n id: smartAccountTxResult.id,\n status: TransactionStatus.confirmed,\n };\n } else {\n const addTransactionResult = await this.#addTransactionFn(\n transactionParamsWithMaxGas,\n requestOptions,\n );\n result = addTransactionResult.result;\n transactionMeta = addTransactionResult.transactionMeta;\n }\n\n if (shouldWaitForHash) {\n return await this.#waitForHashAndReturnFinalTxMeta(result);\n }\n\n return {\n ...getTxMetaFields(quoteResponse, approvalTxId),\n ...transactionMeta,\n };\n };\n\n readonly #handleUSDTAllowanceReset = async (\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n ) => {\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n if (\n quoteResponse.approval &&\n isEthUsdt(hexChainId, quoteResponse.quote.srcAsset.address)\n ) {\n const allowance = new BigNumber(\n await this.messagingSystem.call(\n 'BridgeController:getBridgeERC20Allowance',\n quoteResponse.quote.srcAsset.address,\n hexChainId,\n ),\n );\n const shouldResetApproval =\n allowance.lt(quoteResponse.sentAmount.amount) && allowance.gt(0);\n if (shouldResetApproval) {\n await this.#handleEvmTransaction({\n transactionType: TransactionType.bridgeApproval,\n trade: { ...quoteResponse.approval, data: getEthUsdtResetData() },\n quoteResponse,\n });\n }\n }\n };\n\n readonly #calculateGasFees = async (\n transactionParams: TransactionParams,\n networkClientId: string,\n chainId: Hex,\n ) => {\n const { gasFeeEstimates } = this.messagingSystem.call(\n 'GasFeeController:getState',\n );\n const { estimates: txGasFeeEstimates } = await this.#estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n };\n\n /**\n * Submits a cross-chain swap transaction\n *\n * @param quoteResponse - The quote response\n * @param isStxEnabledOnClient - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension\n * @returns The transaction meta\n */\n submitTx = async (\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n isStxEnabledOnClient: boolean,\n ): Promise<TransactionMeta & Partial<SolanaTransactionMeta>> => {\n this.messagingSystem.call('BridgeController:stopPollingForQuotes');\n\n // Before the tx is confirmed, its data is not available in txHistory\n // The quote is used to populate event properties before confirmation\n const preConfirmationProperties = {\n ...getPriceImpactFromQuote(quoteResponse.quote),\n ...getTradeDataFromQuote(quoteResponse),\n token_symbol_source: quoteResponse.quote.srcAsset.symbol,\n token_symbol_destination: quoteResponse.quote.destAsset.symbol,\n usd_amount_source: Number(quoteResponse.sentAmount?.usd ?? 0),\n stx_enabled: isStxEnabledOnClient,\n };\n // Emit Submitted event after submit button is clicked\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Submitted,\n undefined,\n preConfirmationProperties,\n );\n\n let txMeta: TransactionMeta & Partial<SolanaTransactionMeta>;\n let approvalTime: number | undefined, approvalTxId: string | undefined;\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n // Submit SOLANA tx\n if (\n isSolanaChainId(quoteResponse.quote.srcChainId) &&\n typeof quoteResponse.trade === 'string'\n ) {\n txMeta = await this.#trace(\n {\n name: isBridgeTx\n ? TraceName.BridgeTransactionCompleted\n : TraceName.SwapTransactionCompleted,\n data: {\n srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),\n stxEnabled: false,\n },\n },\n async () => {\n try {\n return await this.#handleSolanaTx(\n quoteResponse as QuoteResponse<string> & QuoteMetadata,\n );\n } catch (error) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Failed,\n txMeta?.id,\n {\n error_message: (error as Error)?.message,\n ...preConfirmationProperties,\n },\n );\n throw error;\n }\n },\n );\n } else {\n // Submit EVM tx\n // For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval\n // Extension does not have this issue\n const requireApproval =\n this.#clientId === BridgeClientId.MOBILE &&\n isHardwareWallet(this.#getMultichainSelectedAccount());\n\n // Set approval time and id if an approval tx is needed\n const approvalTxMeta = await this.#handleApprovalTx(\n isBridgeTx,\n quoteResponse,\n requireApproval,\n );\n approvalTime = approvalTxMeta?.time;\n approvalTxId = approvalTxMeta?.id;\n // Handle smart transactions if enabled\n txMeta = await this.#trace(\n {\n name: isBridgeTx\n ? TraceName.BridgeTransactionCompleted\n : TraceName.SwapTransactionCompleted,\n data: {\n srcChainId: formatChainIdToCaip(quoteResponse.quote.srcChainId),\n stxEnabled: isStxEnabledOnClient,\n },\n },\n async () =>\n isStxEnabledOnClient\n ? await this.#handleEvmSmartTransaction({\n isBridgeTx,\n trade: quoteResponse.trade as TxData,\n quoteResponse,\n approvalTxId,\n requireApproval,\n })\n : await this.#handleEvmTransaction({\n transactionType: isBridgeTx\n ? TransactionType.bridge\n : TransactionType.swap,\n trade: quoteResponse.trade as TxData,\n quoteResponse,\n approvalTxId,\n requireApproval,\n }),\n );\n }\n\n try {\n // Start polling for bridge tx status\n this.startPollingForBridgeTxStatus({\n bridgeTxMeta: txMeta, // Only the id field is used by the BridgeStatusController\n statusRequest: {\n ...getStatusRequestParams(quoteResponse),\n srcTxHash: txMeta.hash,\n },\n quoteResponse,\n slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request\n isStxEnabled: isStxEnabledOnClient,\n startTime: approvalTime ?? Date.now(),\n approvalTxId,\n });\n // Track Solana Swap completed event\n if (isSolanaChainId(quoteResponse.quote.srcChainId) && !isBridgeTx) {\n this.#trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.Completed,\n txMeta.id,\n );\n }\n } catch {\n // Ignore errors here, we don't want to crash the app if this fails and tx submission succeeds\n }\n return txMeta;\n };\n\n /**\n * Tracks post-submission events for a cross-chain swap based on the history item\n *\n * @param eventName - The name of the event to track\n * @param txMetaId - The txMetaId of the history item to track the event for\n * @param eventProperties - The properties for the event\n */\n readonly #trackUnifiedSwapBridgeEvent = <\n T extends\n | typeof UnifiedSwapBridgeEventName.Submitted\n | typeof UnifiedSwapBridgeEventName.Failed\n | typeof UnifiedSwapBridgeEventName.SnapConfirmationViewed\n | typeof UnifiedSwapBridgeEventName.Completed,\n >(\n eventName: T,\n txMetaId?: string,\n eventProperties?: Pick<RequiredEventContextFromClient, T>[T],\n ) => {\n if (!txMetaId) {\n this.messagingSystem.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n eventProperties ?? {},\n );\n return;\n }\n\n const historyItem: BridgeHistoryItem | undefined =\n this.state.txHistory[txMetaId];\n if (!historyItem) {\n this.messagingSystem.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n eventProperties ?? {},\n );\n return;\n }\n\n const selectedAccount = this.messagingSystem.call(\n 'AccountsController:getAccountByAddress',\n historyItem.account,\n );\n\n const requiredEventProperties = {\n action_type: getActionType(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n ),\n ...(eventProperties ?? {}),\n ...getRequestParamFromHistory(historyItem),\n ...getRequestMetadataFromHistory(historyItem, selectedAccount),\n ...getTradeDataFromHistory(historyItem),\n ...getTxStatusesFromHistory(historyItem),\n ...getFinalizedTxProperties(historyItem),\n ...getPriceImpactFromQuote(historyItem.quote),\n };\n\n this.messagingSystem.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n requiredEventProperties,\n );\n };\n}\n"]}
|
package/dist/types.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsCA,8EAA8E;AAC9E,2BAA2B;AAE3B,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AA2ED,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,2BAAe,CAAA;IACf,uCAA2B,CAAA;IAC3B,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,qCAAyB,CAAA;IACzB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAbW,QAAQ,wBAAR,QAAQ,QAanB;AAED,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,oCAAyB,CAAA;IACzB,4BAAiB,CAAA;AACnB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAaD,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAsDD,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,0FAAoE,CAAA;IACpE,6DAAuC,CAAA;IACvC,4CAAsB,CAAA;IACtB,gDAA0B,CAAA;IAC1B,4CAAsB,CAAA;AACxB,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B","sourcesContent":["import type {\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type {\n BridgeBackgroundAction,\n BridgeControllerAction,\n ChainId,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n StatusTypes,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type { MultichainTransactionsControllerTransactionConfirmedEvent } from '@metamask/multichain-transactions-controller';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type {\n TransactionControllerGetStateAction,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type { BridgeStatusController } from './bridge-status-controller';\nimport type { BRIDGE_STATUS_CONTROLLER_NAME } from './constants';\n\n// All fields need to be types not interfaces, same with their children fields\n// o/w you get a type error\n\nexport enum BridgeClientId {\n EXTENSION = 'extension',\n MOBILE = 'mobile',\n}\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * These fields are specific to Solana transactions and can likely be infered from TransactionMeta\n *\n * @deprecated these should be removed eventually\n */\nexport type SolanaTransactionMeta = {\n isSolana: boolean;\n isBridgeTx: boolean;\n};\n\nexport type StatusRequest = {\n bridgeId: string; // lifi, socket, squid\n srcTxHash?: string; // lifi, socket, squid, might be undefined for STX\n bridge: string; // lifi, socket, squid\n srcChainId: ChainId; // lifi, socket, squid\n destChainId: ChainId; // lifi, socket, squid\n quote?: Quote; // squid\n refuel?: boolean; // lifi\n};\n\nexport type StatusRequestDto = Omit<\n StatusRequest,\n 'quote' | 'srcChainId' | 'destChainId' | 'refuel'\n> & {\n srcChainId: string; // lifi, socket, squid\n destChainId: string; // lifi, socket, squid\n requestId?: string;\n refuel?: string; // lifi\n};\n\nexport type StatusRequestWithSrcTxHash = StatusRequest & {\n srcTxHash: string;\n};\n\nexport type Asset = {\n chainId: ChainId;\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n icon?: string | null;\n};\n\nexport type SrcChainStatus = {\n chainId: ChainId;\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash?: string;\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount?: string;\n token?: Record<string, never> | Asset;\n};\n\nexport type DestChainStatus = {\n chainId: ChainId;\n txHash?: string;\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount?: string;\n token?: Record<string, never> | Asset;\n};\n\nexport enum BridgeId {\n HOP = 'hop',\n CELER = 'celer',\n CELERCIRCLE = 'celercircle',\n CONNEXT = 'connext',\n POLYGON = 'polygon',\n AVALANCHE = 'avalanche',\n MULTICHAIN = 'multichain',\n AXELAR = 'axelar',\n ACROSS = 'across',\n STARGATE = 'stargate',\n RELAY = 'relay',\n MAYAN = 'mayan',\n}\n\nexport enum FeeType {\n METABRIDGE = 'metabridge',\n REFUEL = 'refuel',\n}\n\nexport type FeeData = {\n amount: string;\n asset: Asset;\n};\n\nexport type Protocol = {\n displayName?: string;\n icon?: string;\n name?: string; // for legacy quotes\n};\n\nexport enum ActionTypes {\n BRIDGE = 'bridge',\n SWAP = 'swap',\n REFUEL = 'refuel',\n}\n\nexport type Step = {\n action: ActionTypes;\n srcChainId: ChainId;\n destChainId?: ChainId;\n srcAsset: Asset;\n destAsset: Asset;\n srcAmount: string;\n destAmount: string;\n protocol: Protocol;\n};\n\nexport type StatusResponse = {\n status: StatusTypes;\n srcChain: SrcChainStatus;\n destChain?: DestChainStatus;\n bridge?: BridgeId;\n isExpectedToken?: boolean;\n isUnrecognizedRouterAddress?: boolean;\n refuel?: RefuelStatusResponse;\n};\n\nexport type RefuelStatusResponse = object & StatusResponse;\n\nexport type RefuelData = object & Step;\n\nexport type BridgeHistoryItem = {\n txMetaId: string; // Need this to handle STX that might not have a txHash immediately\n quote: Quote;\n status: StatusResponse;\n startTime?: number; // timestamp in ms\n estimatedProcessingTimeInSeconds: number;\n slippagePercentage: number;\n completionTime?: number; // timestamp in ms\n pricingData?: {\n /**\n * From QuoteMetadata.sentAmount.amount, the actual amount sent by user in non-atomic decimal form\n */\n amountSent: string;\n amountSentInUsd?: string;\n quotedGasInUsd?: string; // from QuoteMetadata.gasFee.usd\n quotedReturnInUsd?: string; // from QuoteMetadata.toTokenAmount.usd\n quotedRefuelSrcAmountInUsd?: string;\n quotedRefuelDestAmountInUsd?: string;\n };\n initialDestAssetBalance?: string;\n targetContractAddress?: string;\n account: string;\n hasApprovalTx: boolean;\n approvalTxId?: string;\n isStxEnabled?: boolean;\n};\n\nexport enum BridgeStatusAction {\n START_POLLING_FOR_BRIDGE_TX_STATUS = 'startPollingForBridgeTxStatus',\n WIPE_BRIDGE_STATUS = 'wipeBridgeStatus',\n GET_STATE = 'getState',\n RESET_STATE = 'resetState',\n SUBMIT_TX = 'submitTx',\n}\n\nexport type TokenAmountValuesSerialized = {\n amount: string;\n valueInCurrency: string | null;\n usd: string | null;\n};\n\nexport type QuoteMetadataSerialized = {\n gasFee: TokenAmountValuesSerialized;\n /**\n * The total network fee for the bridge transaction\n * estimatedGasFees + relayerFees\n */\n totalNetworkFee: TokenAmountValuesSerialized;\n /**\n * The total max network fee for the bridge transaction\n * maxGasFees + relayerFees\n */\n totalMaxNetworkFee: TokenAmountValuesSerialized;\n toTokenAmount: TokenAmountValuesSerialized;\n /**\n * The adjusted return for the bridge transaction\n * destTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValuesSerialized, 'amount'>;\n /**\n * The actual amount sent by user in non-atomic decimal form\n * srcTokenAmount + metabridgeFee\n */\n sentAmount: TokenAmountValuesSerialized;\n swapRate: string; // destTokenAmount / sentAmount\n /**\n * The cost of the bridge transaction\n * sentAmount - adjustedReturn\n */\n cost: Omit<TokenAmountValuesSerialized, 'amount'>;\n};\n\nexport type StartPollingForBridgeTxStatusArgs = {\n bridgeTxMeta: TransactionMeta;\n statusRequest: StatusRequest;\n quoteResponse: QuoteResponse & QuoteMetadata;\n startTime?: BridgeHistoryItem['startTime'];\n slippagePercentage: BridgeHistoryItem['slippagePercentage'];\n initialDestAssetBalance?: BridgeHistoryItem['initialDestAssetBalance'];\n targetContractAddress?: BridgeHistoryItem['targetContractAddress'];\n approvalTxId?: BridgeHistoryItem['approvalTxId'];\n isStxEnabled?: BridgeHistoryItem['isStxEnabled'];\n};\n\n/**\n * Chrome: The BigNumber values are automatically serialized to strings when sent to the background\n * Firefox: The BigNumber values are not serialized to strings when sent to the background,\n * so we force the ui to do it manually, by using StartPollingForBridgeTxStatusArgsSerialized type on the startPollingForBridgeTxStatus action\n */\nexport type StartPollingForBridgeTxStatusArgsSerialized = Omit<\n StartPollingForBridgeTxStatusArgs,\n 'quoteResponse'\n> & {\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata;\n};\n\nexport type SourceChainTxMetaId = string;\n\nexport type BridgeStatusControllerState = {\n txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>;\n};\n\n// Actions\ntype BridgeStatusControllerAction<\n FunctionName extends keyof BridgeStatusController,\n> = {\n type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeStatusController[FunctionName];\n};\n\nexport type BridgeStatusControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\n// Maps to BridgeController function names\nexport type BridgeStatusControllerStartPollingForBridgeTxStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS>;\n\nexport type BridgeStatusControllerWipeBridgeStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.WIPE_BRIDGE_STATUS>;\n\nexport type BridgeStatusControllerResetStateAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESET_STATE>;\n\nexport type BridgeStatusControllerSubmitTxAction =\n BridgeStatusControllerAction<BridgeStatusAction.SUBMIT_TX>;\n\nexport type BridgeStatusControllerActions =\n | BridgeStatusControllerStartPollingForBridgeTxStatusAction\n | BridgeStatusControllerWipeBridgeStatusAction\n | BridgeStatusControllerResetStateAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction;\n\n// Events\nexport type BridgeStatusControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\nexport type BridgeStatusControllerEvents =\n BridgeStatusControllerStateChangeEvent;\n\n/**\n * The external actions available to the BridgeStatusController.\n */\ntype AllowedActions =\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | HandleSnapRequest\n | TransactionControllerGetStateAction\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>\n | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>\n | GetGasFeeState\n | AccountsControllerGetAccountByAddressAction\n | RemoteFeatureFlagControllerGetStateAction;\n\n/**\n * The external events available to the BridgeStatusController.\n */\ntype AllowedEvents =\n | MultichainTransactionsControllerTransactionConfirmedEvent\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionConfirmedEvent;\n\n/**\n * The messenger for the BridgeStatusController.\n */\nexport type BridgeStatusControllerMessenger = RestrictedMessenger<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerActions | AllowedActions,\n BridgeStatusControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAqCA,8EAA8E;AAC9E,2BAA2B;AAE3B,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AA2ED,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,2BAAe,CAAA;IACf,uCAA2B,CAAA;IAC3B,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,qCAAyB,CAAA;IACzB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAbW,QAAQ,wBAAR,QAAQ,QAanB;AAED,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,oCAAyB,CAAA;IACzB,4BAAiB,CAAA;AACnB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAaD,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAsDD,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,0FAAoE,CAAA;IACpE,6DAAuC,CAAA;IACvC,4CAAsB,CAAA;IACtB,gDAA0B,CAAA;IAC1B,4CAAsB,CAAA;AACxB,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B","sourcesContent":["import type {\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type {\n BridgeBackgroundAction,\n BridgeControllerAction,\n ChainId,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n StatusTypes,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type {\n TransactionControllerGetStateAction,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type { BridgeStatusController } from './bridge-status-controller';\nimport type { BRIDGE_STATUS_CONTROLLER_NAME } from './constants';\n\n// All fields need to be types not interfaces, same with their children fields\n// o/w you get a type error\n\nexport enum BridgeClientId {\n EXTENSION = 'extension',\n MOBILE = 'mobile',\n}\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * These fields are specific to Solana transactions and can likely be infered from TransactionMeta\n *\n * @deprecated these should be removed eventually\n */\nexport type SolanaTransactionMeta = {\n isSolana: boolean;\n isBridgeTx: boolean;\n};\n\nexport type StatusRequest = {\n bridgeId: string; // lifi, socket, squid\n srcTxHash?: string; // lifi, socket, squid, might be undefined for STX\n bridge: string; // lifi, socket, squid\n srcChainId: ChainId; // lifi, socket, squid\n destChainId: ChainId; // lifi, socket, squid\n quote?: Quote; // squid\n refuel?: boolean; // lifi\n};\n\nexport type StatusRequestDto = Omit<\n StatusRequest,\n 'quote' | 'srcChainId' | 'destChainId' | 'refuel'\n> & {\n srcChainId: string; // lifi, socket, squid\n destChainId: string; // lifi, socket, squid\n requestId?: string;\n refuel?: string; // lifi\n};\n\nexport type StatusRequestWithSrcTxHash = StatusRequest & {\n srcTxHash: string;\n};\n\nexport type Asset = {\n chainId: ChainId;\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n icon?: string | null;\n};\n\nexport type SrcChainStatus = {\n chainId: ChainId;\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash?: string;\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount?: string;\n token?: Record<string, never> | Asset;\n};\n\nexport type DestChainStatus = {\n chainId: ChainId;\n txHash?: string;\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount?: string;\n token?: Record<string, never> | Asset;\n};\n\nexport enum BridgeId {\n HOP = 'hop',\n CELER = 'celer',\n CELERCIRCLE = 'celercircle',\n CONNEXT = 'connext',\n POLYGON = 'polygon',\n AVALANCHE = 'avalanche',\n MULTICHAIN = 'multichain',\n AXELAR = 'axelar',\n ACROSS = 'across',\n STARGATE = 'stargate',\n RELAY = 'relay',\n MAYAN = 'mayan',\n}\n\nexport enum FeeType {\n METABRIDGE = 'metabridge',\n REFUEL = 'refuel',\n}\n\nexport type FeeData = {\n amount: string;\n asset: Asset;\n};\n\nexport type Protocol = {\n displayName?: string;\n icon?: string;\n name?: string; // for legacy quotes\n};\n\nexport enum ActionTypes {\n BRIDGE = 'bridge',\n SWAP = 'swap',\n REFUEL = 'refuel',\n}\n\nexport type Step = {\n action: ActionTypes;\n srcChainId: ChainId;\n destChainId?: ChainId;\n srcAsset: Asset;\n destAsset: Asset;\n srcAmount: string;\n destAmount: string;\n protocol: Protocol;\n};\n\nexport type StatusResponse = {\n status: StatusTypes;\n srcChain: SrcChainStatus;\n destChain?: DestChainStatus;\n bridge?: BridgeId;\n isExpectedToken?: boolean;\n isUnrecognizedRouterAddress?: boolean;\n refuel?: RefuelStatusResponse;\n};\n\nexport type RefuelStatusResponse = object & StatusResponse;\n\nexport type RefuelData = object & Step;\n\nexport type BridgeHistoryItem = {\n txMetaId: string; // Need this to handle STX that might not have a txHash immediately\n quote: Quote;\n status: StatusResponse;\n startTime?: number; // timestamp in ms\n estimatedProcessingTimeInSeconds: number;\n slippagePercentage: number;\n completionTime?: number; // timestamp in ms\n pricingData?: {\n /**\n * From QuoteMetadata.sentAmount.amount, the actual amount sent by user in non-atomic decimal form\n */\n amountSent: string;\n amountSentInUsd?: string;\n quotedGasInUsd?: string; // from QuoteMetadata.gasFee.usd\n quotedReturnInUsd?: string; // from QuoteMetadata.toTokenAmount.usd\n quotedRefuelSrcAmountInUsd?: string;\n quotedRefuelDestAmountInUsd?: string;\n };\n initialDestAssetBalance?: string;\n targetContractAddress?: string;\n account: string;\n hasApprovalTx: boolean;\n approvalTxId?: string;\n isStxEnabled?: boolean;\n};\n\nexport enum BridgeStatusAction {\n START_POLLING_FOR_BRIDGE_TX_STATUS = 'startPollingForBridgeTxStatus',\n WIPE_BRIDGE_STATUS = 'wipeBridgeStatus',\n GET_STATE = 'getState',\n RESET_STATE = 'resetState',\n SUBMIT_TX = 'submitTx',\n}\n\nexport type TokenAmountValuesSerialized = {\n amount: string;\n valueInCurrency: string | null;\n usd: string | null;\n};\n\nexport type QuoteMetadataSerialized = {\n gasFee: TokenAmountValuesSerialized;\n /**\n * The total network fee for the bridge transaction\n * estimatedGasFees + relayerFees\n */\n totalNetworkFee: TokenAmountValuesSerialized;\n /**\n * The total max network fee for the bridge transaction\n * maxGasFees + relayerFees\n */\n totalMaxNetworkFee: TokenAmountValuesSerialized;\n toTokenAmount: TokenAmountValuesSerialized;\n /**\n * The adjusted return for the bridge transaction\n * destTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValuesSerialized, 'amount'>;\n /**\n * The actual amount sent by user in non-atomic decimal form\n * srcTokenAmount + metabridgeFee\n */\n sentAmount: TokenAmountValuesSerialized;\n swapRate: string; // destTokenAmount / sentAmount\n /**\n * The cost of the bridge transaction\n * sentAmount - adjustedReturn\n */\n cost: Omit<TokenAmountValuesSerialized, 'amount'>;\n};\n\nexport type StartPollingForBridgeTxStatusArgs = {\n bridgeTxMeta: TransactionMeta;\n statusRequest: StatusRequest;\n quoteResponse: QuoteResponse & QuoteMetadata;\n startTime?: BridgeHistoryItem['startTime'];\n slippagePercentage: BridgeHistoryItem['slippagePercentage'];\n initialDestAssetBalance?: BridgeHistoryItem['initialDestAssetBalance'];\n targetContractAddress?: BridgeHistoryItem['targetContractAddress'];\n approvalTxId?: BridgeHistoryItem['approvalTxId'];\n isStxEnabled?: BridgeHistoryItem['isStxEnabled'];\n};\n\n/**\n * Chrome: The BigNumber values are automatically serialized to strings when sent to the background\n * Firefox: The BigNumber values are not serialized to strings when sent to the background,\n * so we force the ui to do it manually, by using StartPollingForBridgeTxStatusArgsSerialized type on the startPollingForBridgeTxStatus action\n */\nexport type StartPollingForBridgeTxStatusArgsSerialized = Omit<\n StartPollingForBridgeTxStatusArgs,\n 'quoteResponse'\n> & {\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata;\n};\n\nexport type SourceChainTxMetaId = string;\n\nexport type BridgeStatusControllerState = {\n txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>;\n};\n\n// Actions\ntype BridgeStatusControllerAction<\n FunctionName extends keyof BridgeStatusController,\n> = {\n type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeStatusController[FunctionName];\n};\n\nexport type BridgeStatusControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\n// Maps to BridgeController function names\nexport type BridgeStatusControllerStartPollingForBridgeTxStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS>;\n\nexport type BridgeStatusControllerWipeBridgeStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.WIPE_BRIDGE_STATUS>;\n\nexport type BridgeStatusControllerResetStateAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESET_STATE>;\n\nexport type BridgeStatusControllerSubmitTxAction =\n BridgeStatusControllerAction<BridgeStatusAction.SUBMIT_TX>;\n\nexport type BridgeStatusControllerActions =\n | BridgeStatusControllerStartPollingForBridgeTxStatusAction\n | BridgeStatusControllerWipeBridgeStatusAction\n | BridgeStatusControllerResetStateAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction;\n\n// Events\nexport type BridgeStatusControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\nexport type BridgeStatusControllerEvents =\n BridgeStatusControllerStateChangeEvent;\n\n/**\n * The external actions available to the BridgeStatusController.\n */\ntype AllowedActions =\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | HandleSnapRequest\n | TransactionControllerGetStateAction\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>\n | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>\n | GetGasFeeState\n | AccountsControllerGetAccountByAddressAction\n | RemoteFeatureFlagControllerGetStateAction;\n\n/**\n * The external events available to the BridgeStatusController.\n */\ntype AllowedEvents =\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionConfirmedEvent;\n\n/**\n * The messenger for the BridgeStatusController.\n */\nexport type BridgeStatusControllerMessenger = RestrictedMessenger<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerActions | AllowedActions,\n BridgeStatusControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
package/dist/types.d.cts
CHANGED
@@ -2,7 +2,6 @@ import type { AccountsControllerGetAccountByAddressAction, AccountsControllerGet
|
|
2
2
|
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
|
3
3
|
import type { BridgeBackgroundAction, BridgeControllerAction, ChainId, Quote, QuoteMetadata, QuoteResponse, StatusTypes, TxData } from "@metamask/bridge-controller";
|
4
4
|
import type { GetGasFeeState } from "@metamask/gas-fee-controller";
|
5
|
-
import type { MultichainTransactionsControllerTransactionConfirmedEvent } from "@metamask/multichain-transactions-controller";
|
6
5
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction } from "@metamask/network-controller";
|
7
6
|
import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
|
8
7
|
import type { HandleSnapRequest } from "@metamask/snaps-controllers";
|
@@ -234,7 +233,7 @@ type AllowedActions = NetworkControllerFindNetworkClientIdByChainIdAction | Netw
|
|
234
233
|
/**
|
235
234
|
* The external events available to the BridgeStatusController.
|
236
235
|
*/
|
237
|
-
type AllowedEvents =
|
236
|
+
type AllowedEvents = TransactionControllerTransactionFailedEvent | TransactionControllerTransactionConfirmedEvent;
|
238
237
|
/**
|
239
238
|
* The messenger for the BridgeStatusController.
|
240
239
|
*/
|
package/dist/types.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2CAA2C,EAC3C,oDAAoD,EACrD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EACpB,kCAAkC;AACnC,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,OAAO,EACP,KAAK,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,MAAM,EACP,oCAAoC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,qCAAqC;AACnE,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2CAA2C,EAC3C,oDAAoD,EACrD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EACpB,kCAAkC;AACnC,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,OAAO,EACP,KAAK,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,MAAM,EACP,oCAAoC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,qCAAqC;AACnE,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAC3C,+BAA+B,EAChC,qCAAqC;AACtC,OAAO,KAAK,EAAE,yCAAyC,EAAE,iDAAiD;AAC1G,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AACrE,OAAO,KAAK,EACV,mCAAmC,EACnC,8CAA8C,EAC9C,2CAA2C,EAC3C,eAAe,EAChB,yCAAyC;AAE1C,OAAO,KAAK,EAAE,sBAAsB,EAAE,uCAAmC;AACzE,OAA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