@metamask-previews/bridge-status-controller 76.4.0-preview-686aaf7 → 76.4.0-preview-d687d3ab2

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 (35) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/bridge-status-controller.d.ts.map +1 -1
  3. package/dist/bridge-status-controller.js +78 -40
  4. package/dist/bridge-status-controller.js.map +1 -1
  5. package/dist/strategy/batch-sell-strategy.d.ts.map +1 -1
  6. package/dist/strategy/batch-sell-strategy.js +62 -34
  7. package/dist/strategy/batch-sell-strategy.js.map +1 -1
  8. package/dist/strategy/batch-strategy.d.ts.map +1 -1
  9. package/dist/strategy/batch-strategy.js +38 -13
  10. package/dist/strategy/batch-strategy.js.map +1 -1
  11. package/dist/strategy/evm-strategy.d.ts +2 -28
  12. package/dist/strategy/evm-strategy.d.ts.map +1 -1
  13. package/dist/strategy/evm-strategy.js +62 -39
  14. package/dist/strategy/evm-strategy.js.map +1 -1
  15. package/dist/strategy/intent-strategy.d.ts.map +1 -1
  16. package/dist/strategy/intent-strategy.js +2 -1
  17. package/dist/strategy/intent-strategy.js.map +1 -1
  18. package/dist/strategy/types.d.ts +3 -2
  19. package/dist/strategy/types.d.ts.map +1 -1
  20. package/dist/strategy/types.js.map +1 -1
  21. package/dist/types.d.ts +1 -2
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/types.js.map +1 -1
  24. package/dist/utils/history.d.ts +2 -2
  25. package/dist/utils/history.d.ts.map +1 -1
  26. package/dist/utils/history.js +64 -25
  27. package/dist/utils/history.js.map +1 -1
  28. package/dist/utils/metrics.d.ts +2 -33
  29. package/dist/utils/metrics.d.ts.map +1 -1
  30. package/dist/utils/metrics.js.map +1 -1
  31. package/dist/utils/transaction.d.ts +2 -0
  32. package/dist/utils/transaction.d.ts.map +1 -1
  33. package/dist/utils/transaction.js +16 -4
  34. package/dist/utils/transaction.js.map +1 -1
  35. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -9,6 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
+ - Update batch-strategy and batch-sell-strategy history persistence ([#10814](https://github.com/MetaMask/core/pull/10814))
13
+ - add a history item before submitting transactions. This enables the `TransactionController:transactionStatusUpdated` listener to match the txMeta with history and determine whether to publish the Failed event
14
+ - include latest `TransactionStatus` when rekey-ing or adding to history
15
+ - Update evm-strategy history persistence ([#10814](https://github.com/MetaMask/core/pull/10814))
16
+ - if an approval is required, key initial historyItem by `actionId`
17
+ - rekey to the trade's `actionId` if the approval succeeds
18
+ - rekey to the trade's `id` on confirmation
19
+
20
+ ### Fixed
21
+
22
+ - Emit only one `Unified SwapBridge Failed` event when `addTransaction` or `addTransactionBatch` fails ([#10814](https://github.com/MetaMask/core/pull/10814))
23
+ - Pre-submit history: evm keyed by actionId, batch + batch-sell keyed by batchId
24
+ - After tx exists: listener publishes Failed; submitTx returns the txMeta
25
+ - Before tx exists: submitTx catch publishes Failed
12
26
  - Bump `@metamask/accounts-controller` from `^40.0.0` to `^40.1.0` ([#10851](https://github.com/MetaMask/core/pull/10851))
13
27
  - Bump `@metamask/keyring-controller` from `^28.1.0` to `^28.2.0` ([#10851](https://github.com/MetaMask/core/pull/10851))
14
28
  - Bump `@metamask/base-controller` from `^10.0.0` to `^10.1.0` ([#10864](https://github.com/MetaMask/core/pull/10864))
@@ -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,EAC5B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAIL,0BAA0B,EAG1B,2BAA2B,EAG5B,MAAM,6BAA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AAC,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"}
@@ -18,7 +18,7 @@ import { getInitialHistoryItem, getMatchingHistoryEntryForTxMeta, rekeyHistoryIt
18
18
  import { getFinalizedTxProperties, getPriceImpactFromQuote, getRequestMetadataFromHistory, getRequestParamFromHistory, getTradeDataFromHistory, getEVMTxPropertiesFromTransactionMeta, getTxStatusesFromHistory, getPreConfirmationPropertiesFromQuote, getHashPresenceProperties, getBroadcastFailureProperties, getFailurePropertiesFromHistory, promoteFailurePhase, } from './utils/metrics.js';
19
19
  import { getSelectedChainId } from './utils/network.js';
20
20
  import { getSwapOperationCompletedTraceParams, getTraceParams, } from './utils/trace.js';
21
- import { getTransactionMetaById, getTransactions, checkIsDelegatedAccount, isCrossChainTx, updateTransactionsInBatch, hasNestedSwapTransactions, } from './utils/transaction.js';
21
+ import { getTransactionMetaById, getTransactions, checkIsDelegatedAccount, isApprovalTx, isCrossChainTx, updateTransactionsInBatch, hasNestedSwapTransactions, } from './utils/transaction.js';
22
22
  const metadata = {
23
23
  // We want to persist the bridge status state so that we can show the proper data for the Activity list
24
24
  // basically match the behavior of TransactionController
@@ -145,7 +145,9 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
145
145
  historyKey: entryToUse?.[0],
146
146
  historyItem: entryToUse?.[1],
147
147
  txMeta: transactionMeta,
148
- isApprovalTxMeta: entryToUse?.[1]?.approvalTxId === transactionMeta.id,
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)),
149
151
  };
150
152
  });
151
153
  // Seed any missing quote-status entries from persisted history before
@@ -187,36 +189,45 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
187
189
  #isIntentHistoryItem = (historyKey) => historyKey
188
190
  ? Boolean(this.state.txHistory[historyKey]?.quote.intent)
189
191
  : false;
190
- #onTransactionFailed = ({ txMeta, historyKey, isApprovalTxMeta, }) => {
191
- const isHistoryItemAlreadyFailed = historyKey
192
- ? this.state.txHistory[historyKey]?.status.status === StatusTypes.FAILED
193
- : false;
194
- const isIntent = this.#isIntentHistoryItem(historyKey);
192
+ #onTransactionFailed = ({ txMeta, historyKey, isApprovalTxMeta, eventProperties, }) => {
193
+ const isHistoryItemAlreadyFailed = historyKey &&
194
+ this.state.txHistory[historyKey]?.status.status === StatusTypes.FAILED;
195
+ if (isHistoryItemAlreadyFailed) {
196
+ return;
197
+ }
195
198
  this.#updateHistoryItem({
196
199
  historyKey,
197
200
  status: StatusTypes.FAILED,
198
- txHash: isApprovalTxMeta ? undefined : txMeta.hash,
201
+ // Only update txHash if it's not an approval tx failure
202
+ txHash: isApprovalTxMeta ? undefined : txMeta?.hash,
199
203
  completionTime: Date.now(),
200
204
  });
201
- if (txMeta.status === TransactionStatus.rejected) {
205
+ if (txMeta?.status === TransactionStatus.rejected) {
202
206
  return;
203
207
  }
204
- if (isHistoryItemAlreadyFailed) {
208
+ // Pre-confirmation failues
209
+ if (eventProperties || !txMeta) {
210
+ this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Failed, historyKey, eventProperties);
205
211
  return;
206
212
  }
207
- if (!isIntent) {
208
- this.#traceSwapOperationCompleted(historyKey, 'error', 'source').catch(() => undefined);
213
+ this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Failed, historyKey, getEVMTxPropertiesFromTransactionMeta(txMeta));
214
+ const isIntent = this.#isIntentHistoryItem(historyKey);
215
+ if (isIntent) {
216
+ return;
217
+ }
218
+ this.#traceSwapOperationCompleted(historyKey, 'error', 'source').catch(() => undefined);
219
+ // Ignore approval failures, subsequent trade failures will be reported.
220
+ if (isApprovalTxMeta) {
221
+ return;
209
222
  }
210
223
  // Report finalized failure for swap/bridge transactions.
211
224
  // Note: TransactionStatus.rejected means the user cancelled signing, so the tx was never broadcast.
212
225
  // `hasNestedSwapTransactions` also covers batch/7702 swaps whose type may
213
226
  // still read as `batch` rather than `swap`.
214
- if (!isIntent &&
215
- ((txMeta.type && isCrossChainTx(txMeta.type)) ||
216
- hasNestedSwapTransactions(txMeta))) {
227
+ if ((txMeta.type && isCrossChainTx(txMeta.type)) ||
228
+ hasNestedSwapTransactions(txMeta)) {
217
229
  this.#quoteStatusManager.reportFinalised(txMeta.id, false, txMeta.chainId, txMeta.hash);
218
230
  }
219
- this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Failed, historyKey, getEVMTxPropertiesFromTransactionMeta(txMeta));
220
231
  };
221
232
  // Only EVM txs
222
233
  #onTransactionConfirmed = ({ txMeta, historyKey, isApprovalTxMeta, }) => {
@@ -520,10 +531,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
520
531
  * @param txMeta - The transaction meta from the successful submission
521
532
  * @param txMeta.id - The transaction meta id to use as the new key
522
533
  * @param txMeta.hash - The transaction hash to set on the history item
534
+ * @param historyItemOverrides - The history item overrides to set on the history item
523
535
  */
524
- #rekeyHistoryItem = (oldKey, newKey, txMeta) => {
536
+ #rekeyHistoryItem = (oldKey, newKey, txMeta, historyItemOverrides) => {
525
537
  this.update((state) => {
526
- rekeyHistoryItemInState(state, oldKey, newKey, txMeta);
538
+ rekeyHistoryItemInState(state, oldKey, newKey, txMeta, historyItemOverrides);
527
539
  });
528
540
  };
529
541
  #startPollingForTxId = (txId) => {
@@ -825,17 +837,19 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
825
837
  */
826
838
  #executeSubmitStrategy = async (params, sharedHistoryItemProperties) => {
827
839
  let tradeTxMeta;
840
+ let latestHistoryItemKey;
828
841
  const steps = executeSubmitStrategy(params);
829
842
  // Each submission strategy determines when to execute step, which means these actions can happen in any order
830
- for await (const { type, payload } of steps) {
831
- try {
843
+ try {
844
+ for await (const { type, payload } of steps) {
832
845
  switch (type) {
833
846
  case SubmitStep.RekeyHistoryItem:
834
- this.#rekeyHistoryItem(payload.oldHistoryKey, payload.newHistoryKey, payload.tradeMeta);
847
+ this.#rekeyHistoryItem(payload.oldHistoryKey, payload.newHistoryKey, payload.tradeMeta, payload.historyItemOverrides);
848
+ latestHistoryItemKey = payload.newHistoryKey;
835
849
  // Report SUBMITTED as soon as the trade hash is known at submission
836
850
  // time, instead of waiting for the delayed transactionStatusUpdated
837
851
  // (submitted) event.
838
- if (payload.tradeMeta.hash) {
852
+ if (payload.tradeMeta?.hash && payload.tradeMeta.id) {
839
853
  this.#reportSubmittedOnce(payload.newHistoryKey, payload.tradeMeta.hash, payload.tradeMeta.id);
840
854
  }
841
855
  break;
@@ -859,6 +873,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
859
873
  payload.quoteResponse.quote.slippage ??
860
874
  0,
861
875
  });
876
+ latestHistoryItemKey = payload.historyKey;
862
877
  this.#reportSubmittedForNonEvmTx(payload.historyKey, payload.bridgeTxMeta);
863
878
  break;
864
879
  case SubmitStep.StartPolling:
@@ -877,11 +892,16 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
877
892
  /* c8 ignore end */
878
893
  }
879
894
  }
880
- catch (error) {
881
- console.error('Failed to add to bridge history and start polling.', error);
882
- }
883
895
  }
884
- return tradeTxMeta;
896
+ catch (error) {
897
+ console.error('Failed to persist transaction to history and start polling.', error);
898
+ return {
899
+ txMeta: tradeTxMeta,
900
+ error: error,
901
+ txHistoryKey: latestHistoryItemKey,
902
+ };
903
+ }
904
+ return { txMeta: tradeTxMeta, txHistoryKey: latestHistoryItemKey };
885
905
  };
886
906
  /**
887
907
  * Submits a cross-chain swap transaction
@@ -935,10 +955,12 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
935
955
  */
936
956
  const requireApproval = this.#clientId === BridgeClientId.MOBILE && accountHardwareType !== null;
937
957
  const isBridgeTx = isCrossChain(quote.srcChainId, quote.destChainId);
958
+ // Appended to batch-sell events
938
959
  const batchId = quoteResponses.some(({ featureId: quoteFeatureId }) => quoteFeatureId === FeatureId.BATCH_SELL)
939
960
  ? generateBatchId()
940
961
  : undefined;
941
962
  const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, isStxEnabled, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades, batchId, quotesReceivedContext);
963
+ let historyKey;
942
964
  try {
943
965
  // Emit Submitted event after submit button is clicked
944
966
  this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Submitted, undefined, {
@@ -973,22 +995,38 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
973
995
  traceFn: this.#trace,
974
996
  batchId,
975
997
  };
976
- return await this.#trace(getTraceParams(quoteResponse, isStxEnabled), async () => await this.#executeSubmitStrategy(strategyParams, {
977
- startTime,
978
- location,
979
- abTests,
980
- activeAbTests,
981
- tokenSecurityTypeDestination,
982
- inputPrimaryDenomination,
983
- customSlippage: quotesReceivedContext?.custom_slippage,
984
- slippagePercentage: quotesReceivedContext?.slippage_limit,
985
- }));
998
+ return await this.#trace(getTraceParams(quoteResponse, isStxEnabled), async () => {
999
+ const res = await this.#executeSubmitStrategy(strategyParams, {
1000
+ startTime,
1001
+ location,
1002
+ abTests,
1003
+ activeAbTests,
1004
+ tokenSecurityTypeDestination,
1005
+ inputPrimaryDenomination,
1006
+ customSlippage: quotesReceivedContext?.custom_slippage,
1007
+ slippagePercentage: quotesReceivedContext?.slippage_limit,
1008
+ });
1009
+ historyKey = res.txHistoryKey;
1010
+ if (res.txMeta) {
1011
+ return res.txMeta;
1012
+ }
1013
+ if (res.error) {
1014
+ throw res.error;
1015
+ }
1016
+ throw new Error('Failed to submit transaction');
1017
+ });
986
1018
  }
987
1019
  catch (error) {
988
- this.#trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.Failed, undefined, {
989
- error_message: error?.message,
990
- ...preConfirmationProperties,
991
- ...getBroadcastFailureProperties(error),
1020
+ this.#onTransactionFailed({
1021
+ isApprovalTxMeta: false,
1022
+ txMeta: undefined,
1023
+ // Include latest history key to mark it Failed
1024
+ historyKey,
1025
+ eventProperties: {
1026
+ error_message: error?.message,
1027
+ ...preConfirmationProperties,
1028
+ ...getBroadcastFailureProperties(error),
1029
+ },
992
1030
  });
993
1031
  throw error;
994
1032
  }