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

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 +71 -103
  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 +2 -0
  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 +3 -0
  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 +9 -3
  16. package/dist/strategy/evm-strategy.js.map +1 -1
  17. package/dist/strategy/types.d.ts +11 -35
  18. package/dist/strategy/types.d.ts.map +1 -1
  19. package/dist/strategy/types.js +1 -2
  20. package/dist/strategy/types.js.map +1 -1
  21. package/dist/types.d.ts +28 -12
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/types.js.map +1 -1
  24. package/dist/utils/history.d.ts +26 -6
  25. package/dist/utils/history.d.ts.map +1 -1
  26. package/dist/utils/history.js +38 -29
  27. package/dist/utils/history.js.map +1 -1
  28. package/dist/utils/quotes.d.ts +9 -0
  29. package/dist/utils/quotes.d.ts.map +1 -0
  30. package/dist/utils/quotes.js +20 -0
  31. package/dist/utils/quotes.js.map +1 -0
  32. package/dist/utils/subscriptions.d.ts +20 -0
  33. package/dist/utils/subscriptions.d.ts.map +1 -0
  34. package/dist/utils/subscriptions.js +56 -0
  35. package/dist/utils/subscriptions.js.map +1 -0
  36. package/dist/utils/transaction.d.ts +1 -0
  37. package/dist/utils/transaction.d.ts.map +1 -1
  38. package/dist/utils/transaction.js +5 -4
  39. package/dist/utils/transaction.js.map +1 -1
  40. package/package.json +1 -1
  41. package/dist/utils/accounts.d.ts +0 -36
  42. package/dist/utils/accounts.d.ts.map +0 -1
  43. package/dist/utils/accounts.js +0 -4
  44. package/dist/utils/accounts.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, StartPollingForBridgeTxStatusArgsSerialized, FetchFunction, BridgeHistoryItem } from './types.js';
9
+ import type { BridgeStatusControllerState, StartPollingForBridgeTxStatusArgs, 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: StartPollingForBridgeTxStatusArgsSerialized) => void;
83
+ startPollingForBridgeTxStatus: (txHistoryMeta: StartPollingForBridgeTxStatusArgs) => 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,EAMd,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAEV,2BAA2B,EA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AAO,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, toQuoteMetadataV1, toQuoteResponseV1, isQuoteResponseV2, FailurePhase, SwapBridgeErrorCode, } from '@metamask/bridge-controller';
2
- import { isNonEvmChainId, StatusTypes, getAccountHardwareType, UnifiedSwapBridgeEventName, isCrossChain, MetricsActionType, MetaMetricsSwapsEventSource, PollingStatus, formatChainIdToHex, } from '@metamask/bridge-controller';
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';
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,15 +10,16 @@ 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';
14
13
  import { getJwt } from './utils/authentication.js';
15
14
  import { fetchBridgeTxStatus, fetchBridgeQuoteStatus, getStatusRequestWithSrcTxHash, shouldSkipFetchDueToFetchFailures, shouldWaitForFinalBridgeStatus, } from './utils/bridge-status.js';
16
15
  import { getBatchSellTrades, stopPollingForQuotes, trackMetricsEvent, } from './utils/bridge.js';
17
- import { getInitialHistoryItem, getMatchingHistoryEntryForTxMeta, rekeyHistoryItemInState, shouldPollHistoryItem, getMatchingHistoryEntryForApprovalTxMeta, } from './utils/history.js';
16
+ import { getInitialHistoryItem, rekeyHistoryItemInState, shouldPollHistoryItem, resolveHistoryKeyForTxMeta, } from './utils/history.js';
18
17
  import { getFinalizedTxProperties, getPriceImpactFromQuote, getRequestMetadataFromHistory, getRequestParamFromHistory, getTradeDataFromHistory, getEVMTxPropertiesFromTransactionMeta, getTxStatusesFromHistory, getPreConfirmationPropertiesFromQuote, getHashPresenceProperties, getBroadcastFailureProperties, getFailurePropertiesFromHistory, promoteFailurePhase, } from './utils/metrics.js';
19
18
  import { getSelectedChainId } from './utils/network.js';
19
+ import { normalizeQuoteResponses } from './utils/quotes.js';
20
+ import { approvalUpdateHandler, tradeUpdateHandler, } from './utils/subscriptions.js';
20
21
  import { getSwapOperationCompletedTraceParams, getTraceParams, } from './utils/trace.js';
21
- import { getTransactionMetaById, getTransactions, checkIsDelegatedAccount, isApprovalTx, isCrossChainTx, updateTransactionsInBatch, hasNestedSwapTransactions, } from './utils/transaction.js';
22
+ import { getTransactionMetaById, getTransactions, checkIsDelegatedAccount, isCrossChainTx, updateTransactionsInBatch, hasNestedSwapTransactions, hasNestedBridgeTransactions, } from './utils/transaction.js';
22
23
  const metadata = {
23
24
  // We want to persist the bridge status state so that we can show the proper data for the Activity list
24
25
  // basically match the behavior of TransactionController
@@ -99,57 +100,38 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
99
100
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
100
101
  // Set interval
101
102
  this.setIntervalLength(REFRESH_INTERVAL_MS);
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
- });
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;
131
116
  break;
132
- case TransactionStatus.failed:
133
- case TransactionStatus.dropped:
134
- case TransactionStatus.rejected:
135
- this.#onTransactionFailed({ txMeta, historyKey, isApprovalTxMeta });
117
+ case TransactionType.bridge:
118
+ case TransactionType.swap:
119
+ handler = tradeUpdateHandler;
136
120
  break;
137
121
  default:
138
- break;
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
+ }
139
132
  }
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
- });
133
+ handler(params);
134
+ }, (payload) => resolveHistoryKeyForTxMeta(payload, this.state.txHistory));
153
135
  // Seed any missing quote-status entries from persisted history before
154
136
  // init(), so init()'s reconciliation loop can finalize quotes whose
155
137
  // deferred entry was never created (e.g. the client closed before
@@ -229,47 +211,43 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
229
211
  this.#quoteStatusManager.reportFinalised(txMeta.id, false, txMeta.chainId, txMeta.hash);
230
212
  }
231
213
  };
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) {
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);
237
228
  return;
238
229
  }
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
+ }
239
244
  this.#updateHistoryItem({
240
245
  historyKey,
246
+ status: StatusTypes.COMPLETE,
241
247
  txHash: txMeta.hash,
248
+ completionTime: Date.now(),
242
249
  });
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
- }
250
+ this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Completed, historyKey);
273
251
  };
274
252
  /**
275
253
  * Reports the SUBMITTED quote status for non-EVM transactions.
@@ -533,9 +511,9 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
533
511
  * @param txMeta.hash - The transaction hash to set on the history item
534
512
  * @param historyItemOverrides - The history item overrides to set on the history item
535
513
  */
536
- #rekeyHistoryItem = (oldKey, newKey, txMeta, historyItemOverrides) => {
514
+ #rekeyHistoryItem = (oldKey, newKey, historyItemOverrides) => {
537
515
  this.update((state) => {
538
- rekeyHistoryItemInState(state, oldKey, newKey, txMeta, historyItemOverrides);
516
+ rekeyHistoryItemInState(state, oldKey, newKey, historyItemOverrides);
539
517
  });
540
518
  };
541
519
  #startPollingForTxId = (txId) => {
@@ -731,8 +709,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
731
709
  ? 'destination'
732
710
  : 'source').catch(() => undefined);
733
711
  if (status.status === StatusTypes.COMPLETE) {
734
- this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
735
712
  this.messenger.publish('BridgeStatusController:destinationTransactionCompleted', historyItem.quote.destAsset.assetId);
713
+ this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
736
714
  }
737
715
  if (status.status === StatusTypes.FAILED) {
738
716
  this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Failed, bridgeTxMetaId);
@@ -844,7 +822,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
844
822
  for await (const { type, payload } of steps) {
845
823
  switch (type) {
846
824
  case SubmitStep.RekeyHistoryItem:
847
- this.#rekeyHistoryItem(payload.oldHistoryKey, payload.newHistoryKey, payload.tradeMeta, payload.historyItemOverrides);
825
+ this.#rekeyHistoryItem(payload.oldHistoryKey, payload.newHistoryKey, payload.historyItemOverrides);
848
826
  latestHistoryItemKey = payload.newHistoryKey;
849
827
  // Report SUBMITTED as soon as the trade hash is known at submission
850
828
  // time, instead of waiting for the delayed transactionStatusUpdated
@@ -921,18 +899,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
921
899
  * @returns The transaction meta
922
900
  * @throws An error if transaction submission fails before it gets published
923
901
  */
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
- });
902
+ submitTx = async ({ accountAddress, quoteResponses: quoteResponsesV1orV2, isStxEnabled, quotesReceivedContext, location = MetaMetricsSwapsEventSource.Unknown, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades = null, inputPrimaryDenomination, migrationPhase, }) => {
903
+ const quoteResponses = normalizeQuoteResponses(quoteResponsesV1orV2, migrationPhase);
936
904
  const quoteResponse = quoteResponses[0];
937
905
  const { quote } = quoteResponse;
938
906
  const startTime = Date.now();