@metamask-previews/bridge-status-controller 78.0.2-preview-0f61514 → 78.0.2-preview-0095f3485

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.
Files changed (44) hide show
  1. package/dist/bridge-status-controller.d.ts +2 -2
  2. package/dist/bridge-status-controller.d.ts.map +1 -1
  3. package/dist/bridge-status-controller.js +103 -71
  4. package/dist/bridge-status-controller.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/strategy/batch-sell-strategy.d.ts.map +1 -1
  9. package/dist/strategy/batch-sell-strategy.js +0 -2
  10. package/dist/strategy/batch-sell-strategy.js.map +1 -1
  11. package/dist/strategy/batch-strategy.d.ts.map +1 -1
  12. package/dist/strategy/batch-strategy.js +0 -3
  13. package/dist/strategy/batch-strategy.js.map +1 -1
  14. package/dist/strategy/evm-strategy.d.ts.map +1 -1
  15. package/dist/strategy/evm-strategy.js +3 -9
  16. package/dist/strategy/evm-strategy.js.map +1 -1
  17. package/dist/strategy/types.d.ts +35 -11
  18. package/dist/strategy/types.d.ts.map +1 -1
  19. package/dist/strategy/types.js +2 -1
  20. package/dist/strategy/types.js.map +1 -1
  21. package/dist/types.d.ts +12 -28
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/types.js.map +1 -1
  24. package/dist/utils/accounts.d.ts +36 -0
  25. package/dist/utils/accounts.d.ts.map +1 -0
  26. package/dist/utils/accounts.js +4 -0
  27. package/dist/utils/accounts.js.map +1 -0
  28. package/dist/utils/history.d.ts +6 -26
  29. package/dist/utils/history.d.ts.map +1 -1
  30. package/dist/utils/history.js +29 -38
  31. package/dist/utils/history.js.map +1 -1
  32. package/dist/utils/transaction.d.ts +0 -1
  33. package/dist/utils/transaction.d.ts.map +1 -1
  34. package/dist/utils/transaction.js +4 -5
  35. package/dist/utils/transaction.js.map +1 -1
  36. package/package.json +1 -1
  37. package/dist/utils/quotes.d.ts +0 -9
  38. package/dist/utils/quotes.d.ts.map +0 -1
  39. package/dist/utils/quotes.js +0 -20
  40. package/dist/utils/quotes.js.map +0 -1
  41. package/dist/utils/subscriptions.d.ts +0 -20
  42. package/dist/utils/subscriptions.d.ts.map +0 -1
  43. package/dist/utils/subscriptions.js +0 -56
  44. package/dist/utils/subscriptions.js.map +0 -1
@@ -6,7 +6,7 @@ import type { TransactionMeta } from '@metamask/transaction-controller';
6
6
  import { BRIDGE_STATUS_CONTROLLER_NAME } from './constants.js';
7
7
  import type { TraceName } from './constants.js';
8
8
  import { QuoteStatusGetError, QuoteStatusUpdateError } from './quote-status-manager/errors.js';
9
- import type { BridgeStatusControllerState, StartPollingForBridgeTxStatusArgs, FetchFunction, BridgeHistoryItem } from './types.js';
9
+ import type { BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized, FetchFunction, BridgeHistoryItem } from './types.js';
10
10
  import type { BridgeStatusControllerMessenger } from './types.js';
11
11
  import { BridgeClientId } from './types.js';
12
12
  /** The input to start polling for the {@link BridgeStatusController} */
@@ -80,7 +80,7 @@ export declare class BridgeStatusController extends BridgeStatusController_base<
80
80
  *
81
81
  * @param txHistoryMeta - The parameters for creating the history item
82
82
  */
83
- startPollingForBridgeTxStatus: (txHistoryMeta: StartPollingForBridgeTxStatusArgs) => void;
83
+ startPollingForBridgeTxStatus: (txHistoryMeta: StartPollingForBridgeTxStatusArgsSerialized) => void;
84
84
  _executePoll: (pollingInput: BridgeStatusPollingInput) => Promise<void>;
85
85
  /**
86
86
  * Submits a cross-chain swap transaction
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-status-controller.d.ts","sourceRoot":"","sources":["../src/bridge-status-controller.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,8BAA8B,EAC9B,eAAe,EACf,KAAK,EAEL,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,EAGd,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAEV,2BAA2B,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,OAAO,CAAC;QACvB,qBAAqB,CAAC,EAAE,8BAA8B,CAAC,0BAA0B,CAAC,cAAc,CAAC,CAAC;QAClG,cAAc,CAAC,EAAE,2BAA2B,CAAC;KAC9C,KAAG,OAAO,CAAC,eAAe,CAAC,CA2B1B;IAEF,eAAe,WAAkB;QAC/B,cAAc,EAAE,CAAC,aAAa,GAAG,IAAI,CAAC,EAAE,CAAC;QACzC,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,2BAA2B,CAAC;QACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,aAAa,CAAC,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QACjD,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,qBAAqB,CAAC,EAAE,8BAA8B,CAAC,0BAA0B,CAAC,cAAc,CAAC,CAAC;QAClG,4BAA4B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7C,cAAc,CAAC,EAAE,2BAA2B,CAAC;KAC9C,KAAG,OAAO,CAAC,eAAe,CAAC,CAsB1B;CAsNH"}
@@ -1,5 +1,5 @@
1
- import { FeatureId, FailurePhase, SwapBridgeErrorCode, } from '@metamask/bridge-controller';
2
- import { isNonEvmChainId, StatusTypes, getAccountHardwareType, UnifiedSwapBridgeEventName, isCrossChain, MetricsActionType, MetaMetricsSwapsEventSource, PollingStatus, formatChainIdToHex, getAccountByAddress, } from '@metamask/bridge-controller';
1
+ import { FeatureId, toQuoteMetadataV1, toQuoteResponseV1, isQuoteResponseV2, FailurePhase, SwapBridgeErrorCode, } from '@metamask/bridge-controller';
2
+ import { isNonEvmChainId, StatusTypes, getAccountHardwareType, UnifiedSwapBridgeEventName, isCrossChain, MetricsActionType, MetaMetricsSwapsEventSource, PollingStatus, formatChainIdToHex, } from '@metamask/bridge-controller';
3
3
  import { StaticIntervalPollingController } from '@metamask/polling-controller';
4
4
  import { TransactionStatus, TransactionType, generateBatchId, } from '@metamask/transaction-controller';
5
5
  import { numberToHex } from '@metamask/utils';
@@ -10,16 +10,15 @@ import { QuoteStatusManager } from './quote-status-manager/quotes-status-manager
10
10
  import executeSubmitStrategy from './strategy/index.js';
11
11
  import { SubmitStep } from './strategy/types.js';
12
12
  import { BridgeClientId } from './types.js';
13
+ import { getAccountByAddress } from './utils/accounts.js';
13
14
  import { getJwt } from './utils/authentication.js';
14
15
  import { fetchBridgeTxStatus, fetchBridgeQuoteStatus, getStatusRequestWithSrcTxHash, shouldSkipFetchDueToFetchFailures, shouldWaitForFinalBridgeStatus, } from './utils/bridge-status.js';
15
16
  import { getBatchSellTrades, stopPollingForQuotes, trackMetricsEvent, } from './utils/bridge.js';
16
- import { getInitialHistoryItem, rekeyHistoryItemInState, shouldPollHistoryItem, resolveHistoryKeyForTxMeta, } from './utils/history.js';
17
+ import { getInitialHistoryItem, getMatchingHistoryEntryForTxMeta, rekeyHistoryItemInState, shouldPollHistoryItem, getMatchingHistoryEntryForApprovalTxMeta, } from './utils/history.js';
17
18
  import { getFinalizedTxProperties, getPriceImpactFromQuote, getRequestMetadataFromHistory, getRequestParamFromHistory, getTradeDataFromHistory, getEVMTxPropertiesFromTransactionMeta, getTxStatusesFromHistory, getPreConfirmationPropertiesFromQuote, getHashPresenceProperties, getBroadcastFailureProperties, getFailurePropertiesFromHistory, promoteFailurePhase, } from './utils/metrics.js';
18
19
  import { getSelectedChainId } from './utils/network.js';
19
- import { normalizeQuoteResponses } from './utils/quotes.js';
20
- import { approvalUpdateHandler, tradeUpdateHandler, } from './utils/subscriptions.js';
21
20
  import { getSwapOperationCompletedTraceParams, getTraceParams, } from './utils/trace.js';
22
- import { getTransactionMetaById, getTransactions, checkIsDelegatedAccount, isCrossChainTx, updateTransactionsInBatch, hasNestedSwapTransactions, hasNestedBridgeTransactions, } from './utils/transaction.js';
21
+ import { getTransactionMetaById, getTransactions, checkIsDelegatedAccount, isApprovalTx, isCrossChainTx, updateTransactionsInBatch, hasNestedSwapTransactions, } from './utils/transaction.js';
23
22
  const metadata = {
24
23
  // We want to persist the bridge status state so that we can show the proper data for the Activity list
25
24
  // basically match the behavior of TransactionController
@@ -100,38 +99,57 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
100
99
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
101
100
  // Set interval
102
101
  this.setIntervalLength(REFRESH_INTERVAL_MS);
103
- this.messenger.subscribe('TransactionController:transactionStatusUpdated', (args) => {
104
- let handler = tradeUpdateHandler;
105
- const params = {
106
- ...args,
107
- onTransactionConfirmed: this.#onTransactionConfirmed,
108
- onTransactionFailed: this.#onTransactionFailed,
109
- onReportSubmittedOnce: this.#reportSubmittedOnce,
110
- };
111
- // Match handler by type first
112
- switch (args.txMeta.type) {
113
- case TransactionType.swapApproval:
114
- case TransactionType.bridgeApproval:
115
- handler = approvalUpdateHandler;
102
+ this.messenger.subscribe('TransactionController:transactionStatusUpdated', ({ txMeta, historyKey, historyItem, isApprovalTxMeta }) => {
103
+ if (!txMeta) {
104
+ return;
105
+ }
106
+ const { type, status } = txMeta;
107
+ // Allow event publishing if the txMeta is a swap/bridge OR if the
108
+ // corresponding history item exists
109
+ const isSwapOrBridgeTransaction = type && isCrossChainTx(type);
110
+ if (!isSwapOrBridgeTransaction && !historyKey && !historyItem) {
111
+ return;
112
+ }
113
+ switch (status) {
114
+ case TransactionStatus.submitted:
115
+ // EVM txs report SUBMITTED here (not via transactionSubmitted) so hash
116
+ // replacements before confirmation still reach the Bridge API.
117
+ if (txMeta.hash &&
118
+ txMeta.type &&
119
+ isCrossChainTx(txMeta.type) &&
120
+ !isApprovalTxMeta &&
121
+ historyKey) {
122
+ this.#reportSubmittedOnce(historyKey, txMeta.hash, txMeta.id);
123
+ }
124
+ break;
125
+ case TransactionStatus.confirmed:
126
+ this.#onTransactionConfirmed({
127
+ txMeta,
128
+ historyKey,
129
+ isApprovalTxMeta,
130
+ });
116
131
  break;
117
- case TransactionType.bridge:
118
- case TransactionType.swap:
119
- handler = tradeUpdateHandler;
132
+ case TransactionStatus.failed:
133
+ case TransactionStatus.dropped:
134
+ case TransactionStatus.rejected:
135
+ this.#onTransactionFailed({ txMeta, historyKey, isApprovalTxMeta });
120
136
  break;
121
137
  default:
122
- // Otherwise check for matching nested transactions
123
- if (hasNestedSwapTransactions(args.txMeta) ||
124
- hasNestedBridgeTransactions(args.txMeta)) {
125
- handler = tradeUpdateHandler;
126
- }
127
- else {
128
- // This handler only checks for failures, so it's safe to use
129
- // for unrecognized transactions
130
- handler = approvalUpdateHandler;
131
- }
138
+ break;
132
139
  }
133
- handler(params);
134
- }, (payload) => resolveHistoryKeyForTxMeta(payload, this.state.txHistory));
140
+ }, ({ transactionMeta }) => {
141
+ const entry = getMatchingHistoryEntryForTxMeta(this.state.txHistory, transactionMeta);
142
+ const approvalEntry = getMatchingHistoryEntryForApprovalTxMeta(this.state.txHistory, transactionMeta);
143
+ const entryToUse = entry ?? approvalEntry;
144
+ return {
145
+ historyKey: entryToUse?.[0],
146
+ historyItem: entryToUse?.[1],
147
+ txMeta: transactionMeta,
148
+ // Means that the triggering event was for an approval tx
149
+ isApprovalTxMeta: entryToUse?.[1]?.approvalTxId === transactionMeta.id ||
150
+ Boolean(transactionMeta.type && isApprovalTx(transactionMeta.type)),
151
+ };
152
+ });
135
153
  // Seed any missing quote-status entries from persisted history before
136
154
  // init(), so init()'s reconciliation loop can finalize quotes whose
137
155
  // deferred entry was never created (e.g. the client closed before
@@ -211,43 +229,47 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
211
229
  this.#quoteStatusManager.reportFinalised(txMeta.id, false, txMeta.chainId, txMeta.hash);
212
230
  }
213
231
  };
214
- /**
215
- * Handles the confirmed status for EVM swap, bridge src, batch or deposit txs
216
- * @param txMeta - The transaction meta
217
- * @param historyKey - The history key
218
- */
219
- #onTransactionConfirmed = ({ txMeta, historyKey, }) => {
220
- const { type, hash: txHash, id, chainId } = txMeta;
221
- const isBridge = type === TransactionType.bridge || hasNestedBridgeTransactions(txMeta);
222
- if (isBridge) {
223
- this.#updateHistoryItem({
224
- historyKey,
225
- txHash,
226
- });
227
- this.#startPollingForTxId(historyKey);
232
+ // Only EVM txs
233
+ #onTransactionConfirmed = ({ txMeta, historyKey, isApprovalTxMeta, }) => {
234
+ // Return early if the confirmed txMeta is for an approval since we
235
+ // still need to wait for the trade to be confirmed
236
+ if (isApprovalTxMeta) {
228
237
  return;
229
238
  }
230
- const isSwap = type === TransactionType.swap || hasNestedSwapTransactions(txMeta);
231
- const isIntent = this.#isIntentHistoryItem(historyKey);
232
- if (isSwap && !isIntent) {
233
- // Smart/batch transactions can be assigned their hash only once
234
- // confirmed, so the submitted status handler never had one to report.
235
- // Report it here (before reportFinalised) so the deferred-queue entry
236
- // exists.
237
- const historyItem = this.state.txHistory[historyKey];
238
- if (txHash && !isNonEvmChainId(historyItem.quote.srcChainId)) {
239
- this.#reportSubmittedOnce(historyKey, txHash, id);
240
- }
241
- this.#quoteStatusManager.reportFinalised(id, true, chainId, txHash);
242
- this.#traceSwapOperationCompleted(historyKey, 'success', 'source').catch(() => undefined);
243
- }
244
239
  this.#updateHistoryItem({
245
240
  historyKey,
246
- status: StatusTypes.COMPLETE,
247
241
  txHash: txMeta.hash,
248
- completionTime: Date.now(),
249
242
  });
250
- this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Completed, historyKey);
243
+ const isIntent = this.#isIntentHistoryItem(historyKey);
244
+ const isSwap = txMeta.type === TransactionType.swap || hasNestedSwapTransactions(txMeta);
245
+ if (isSwap) {
246
+ this.#updateHistoryItem({
247
+ historyKey,
248
+ status: StatusTypes.COMPLETE,
249
+ completionTime: Date.now(),
250
+ });
251
+ if (!isIntent) {
252
+ // Smart/batch transactions can be assigned their hash only once
253
+ // confirmed, so the submitted status handler never had one to report.
254
+ // Report it here (before reportFinalised) so the deferred-queue entry
255
+ // exists.
256
+ const historyItem = historyKey
257
+ ? this.state.txHistory[historyKey]
258
+ : undefined;
259
+ if (historyKey &&
260
+ historyItem &&
261
+ txMeta.hash &&
262
+ !isNonEvmChainId(historyItem.quote.srcChainId)) {
263
+ this.#reportSubmittedOnce(historyKey, txMeta.hash, txMeta.id);
264
+ }
265
+ this.#quoteStatusManager.reportFinalised(txMeta.id, true, txMeta.chainId, txMeta.hash);
266
+ this.#traceSwapOperationCompleted(historyKey, 'success', 'source').catch(() => undefined);
267
+ }
268
+ this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Completed, historyKey);
269
+ }
270
+ else if (historyKey) {
271
+ this.#startPollingForTxId(historyKey);
272
+ }
251
273
  };
252
274
  /**
253
275
  * Reports the SUBMITTED quote status for non-EVM transactions.
@@ -511,9 +533,9 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
511
533
  * @param txMeta.hash - The transaction hash to set on the history item
512
534
  * @param historyItemOverrides - The history item overrides to set on the history item
513
535
  */
514
- #rekeyHistoryItem = (oldKey, newKey, historyItemOverrides) => {
536
+ #rekeyHistoryItem = (oldKey, newKey, txMeta, historyItemOverrides) => {
515
537
  this.update((state) => {
516
- rekeyHistoryItemInState(state, oldKey, newKey, historyItemOverrides);
538
+ rekeyHistoryItemInState(state, oldKey, newKey, txMeta, historyItemOverrides);
517
539
  });
518
540
  };
519
541
  #startPollingForTxId = (txId) => {
@@ -709,8 +731,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
709
731
  ? 'destination'
710
732
  : 'source').catch(() => undefined);
711
733
  if (status.status === StatusTypes.COMPLETE) {
712
- this.messenger.publish('BridgeStatusController:destinationTransactionCompleted', historyItem.quote.destAsset.assetId);
713
734
  this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
735
+ this.messenger.publish('BridgeStatusController:destinationTransactionCompleted', historyItem.quote.destAsset.assetId);
714
736
  }
715
737
  if (status.status === StatusTypes.FAILED) {
716
738
  this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Failed, bridgeTxMetaId);
@@ -822,7 +844,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
822
844
  for await (const { type, payload } of steps) {
823
845
  switch (type) {
824
846
  case SubmitStep.RekeyHistoryItem:
825
- this.#rekeyHistoryItem(payload.oldHistoryKey, payload.newHistoryKey, payload.historyItemOverrides);
847
+ this.#rekeyHistoryItem(payload.oldHistoryKey, payload.newHistoryKey, payload.tradeMeta, payload.historyItemOverrides);
826
848
  latestHistoryItemKey = payload.newHistoryKey;
827
849
  // Report SUBMITTED as soon as the trade hash is known at submission
828
850
  // time, instead of waiting for the delayed transactionStatusUpdated
@@ -899,8 +921,18 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
899
921
  * @returns The transaction meta
900
922
  * @throws An error if transaction submission fails before it gets published
901
923
  */
902
- submitTx = async ({ accountAddress, quoteResponses: quoteResponsesV1orV2, isStxEnabled, quotesReceivedContext, location = MetaMetricsSwapsEventSource.Unknown, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades = null, inputPrimaryDenomination, migrationPhase, }) => {
903
- const quoteResponses = normalizeQuoteResponses(quoteResponsesV1orV2, migrationPhase);
924
+ submitTx = async ({ accountAddress, quoteResponses: quoteResponsesV1orV2, isStxEnabled, quotesReceivedContext, location = MetaMetricsSwapsEventSource.Unknown, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades, inputPrimaryDenomination, migrationPhase, }) => {
925
+ // Convert quote responses to V1 format and preserve metadata for consistency
926
+ const quoteResponses = quoteResponsesV1orV2.map((quote) => {
927
+ if (!isQuoteResponseV2(quote)) {
928
+ return quote;
929
+ }
930
+ const quoteMetadataV1 = toQuoteMetadataV1(quote, migrationPhase);
931
+ // This coercion omits legacy metadata from the resulting V1 quote
932
+ const quoteResponseV1 = toQuoteResponseV1(quote);
933
+ // Merge legacy-shaped metadata to V1-shaped quote response
934
+ return { ...quoteResponseV1, ...quoteMetadataV1 };
935
+ });
904
936
  const quoteResponse = quoteResponses[0];
905
937
  const { quote } = quoteResponse;
906
938
  const startTime = Date.now();