@metamask/bridge-status-controller 71.2.1 → 72.0.1
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 +40 -1
- package/dist/bridge-status-controller-method-action-types.cjs.map +1 -1
- package/dist/bridge-status-controller-method-action-types.d.cts +5 -1
- package/dist/bridge-status-controller-method-action-types.d.cts.map +1 -1
- package/dist/bridge-status-controller-method-action-types.d.mts +5 -1
- package/dist/bridge-status-controller-method-action-types.d.mts.map +1 -1
- package/dist/bridge-status-controller-method-action-types.mjs.map +1 -1
- package/dist/bridge-status-controller.cjs +161 -366
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +27 -7
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +27 -7
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +162 -370
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/strategy/batch-sell-strategy.cjs +103 -0
- package/dist/strategy/batch-sell-strategy.cjs.map +1 -0
- package/dist/strategy/batch-sell-strategy.d.cts +10 -0
- package/dist/strategy/batch-sell-strategy.d.cts.map +1 -0
- package/dist/strategy/batch-sell-strategy.d.mts +10 -0
- package/dist/strategy/batch-sell-strategy.d.mts.map +1 -0
- package/dist/strategy/batch-sell-strategy.mjs +99 -0
- package/dist/strategy/batch-sell-strategy.mjs.map +1 -0
- package/dist/strategy/batch-strategy.cjs +74 -0
- package/dist/strategy/batch-strategy.cjs.map +1 -0
- package/dist/strategy/batch-strategy.d.cts +10 -0
- package/dist/strategy/batch-strategy.d.cts.map +1 -0
- package/dist/strategy/batch-strategy.d.mts +10 -0
- package/dist/strategy/batch-strategy.d.mts.map +1 -0
- package/dist/strategy/batch-strategy.mjs +70 -0
- package/dist/strategy/batch-strategy.mjs.map +1 -0
- package/dist/strategy/evm-strategy.cjs +149 -0
- package/dist/strategy/evm-strategy.cjs.map +1 -0
- package/dist/strategy/evm-strategy.d.cts +38 -0
- package/dist/strategy/evm-strategy.d.cts.map +1 -0
- package/dist/strategy/evm-strategy.d.mts +38 -0
- package/dist/strategy/evm-strategy.d.mts.map +1 -0
- package/dist/strategy/evm-strategy.mjs +143 -0
- package/dist/strategy/evm-strategy.mjs.map +1 -0
- package/dist/strategy/index.cjs +70 -0
- package/dist/strategy/index.cjs.map +1 -0
- package/dist/strategy/index.d.cts +12 -0
- package/dist/strategy/index.d.cts.map +1 -0
- package/dist/strategy/index.d.mts +12 -0
- package/dist/strategy/index.d.mts.map +1 -0
- package/dist/strategy/index.mjs +68 -0
- package/dist/strategy/index.mjs.map +1 -0
- package/dist/strategy/intent-strategy.cjs +160 -0
- package/dist/strategy/intent-strategy.cjs.map +1 -0
- package/dist/strategy/intent-strategy.d.cts +17 -0
- package/dist/strategy/intent-strategy.d.cts.map +1 -0
- package/dist/strategy/intent-strategy.d.mts +17 -0
- package/dist/strategy/intent-strategy.d.mts.map +1 -0
- package/dist/strategy/intent-strategy.mjs +156 -0
- package/dist/strategy/intent-strategy.mjs.map +1 -0
- package/dist/strategy/non-evm-strategy.cjs +80 -0
- package/dist/strategy/non-evm-strategy.cjs.map +1 -0
- package/dist/strategy/non-evm-strategy.d.cts +15 -0
- package/dist/strategy/non-evm-strategy.d.cts.map +1 -0
- package/dist/strategy/non-evm-strategy.d.mts +15 -0
- package/dist/strategy/non-evm-strategy.d.mts.map +1 -0
- package/dist/strategy/non-evm-strategy.mjs +76 -0
- package/dist/strategy/non-evm-strategy.mjs.map +1 -0
- package/dist/strategy/types.cjs +13 -0
- package/dist/strategy/types.cjs.map +1 -0
- package/dist/strategy/types.d.cts +77 -0
- package/dist/strategy/types.d.cts.map +1 -0
- package/dist/strategy/types.d.mts +77 -0
- package/dist/strategy/types.d.mts.map +1 -0
- package/dist/strategy/types.mjs +10 -0
- package/dist/strategy/types.mjs.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +41 -6
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +41 -6
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/bridge.cjs +5 -1
- package/dist/utils/bridge.cjs.map +1 -1
- package/dist/utils/bridge.d.cts +2 -2
- package/dist/utils/bridge.d.cts.map +1 -1
- package/dist/utils/bridge.d.mts +2 -2
- package/dist/utils/bridge.d.mts.map +1 -1
- package/dist/utils/bridge.mjs +3 -0
- package/dist/utils/bridge.mjs.map +1 -1
- package/dist/utils/history.cjs +72 -20
- package/dist/utils/history.cjs.map +1 -1
- package/dist/utils/history.d.cts +19 -5
- package/dist/utils/history.d.cts.map +1 -1
- package/dist/utils/history.d.mts +19 -5
- package/dist/utils/history.d.mts.map +1 -1
- package/dist/utils/history.mjs +69 -19
- package/dist/utils/history.mjs.map +1 -1
- package/dist/utils/metrics.cjs +10 -7
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +7 -6
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +7 -6
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +10 -7
- package/dist/utils/metrics.mjs.map +1 -1
- package/dist/utils/trace.cjs +4 -4
- package/dist/utils/trace.cjs.map +1 -1
- package/dist/utils/trace.d.cts +2 -2
- package/dist/utils/trace.d.cts.map +1 -1
- package/dist/utils/trace.d.mts +2 -2
- package/dist/utils/trace.d.mts.map +1 -1
- package/dist/utils/trace.mjs +4 -4
- package/dist/utils/trace.mjs.map +1 -1
- package/dist/utils/transaction.cjs +222 -253
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +68 -147
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +68 -147
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +213 -248
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +2 -2
package/dist/utils/history.cjs
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isHistoryItemTooOld = exports.shouldPollHistoryItem = exports.getInitialHistoryItem = exports.getHistoryKey = exports.getMatchingHistoryEntryForApprovalTxMeta = exports.getMatchingHistoryEntryForTxMeta = exports.rekeyHistoryItemInState = void 0;
|
|
3
|
+
exports.isHistoryItemTooOld = exports.shouldPollHistoryItem = exports.getInitialHistoryItem = exports.getHistoryKey = exports.getBatchSellHistoryItemsForTxHash = exports.getMatchingHistoryEntryForApprovalTxMeta = exports.getMatchingHistoryEntryForTxMeta = exports.isBatchSellHistoryItem = exports.rekeyHistoryItemInState = void 0;
|
|
4
4
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
5
5
|
const feature_flags_1 = require("./feature-flags.cjs");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
state.txHistory[txMeta.id] = {
|
|
12
|
-
...historyItem,
|
|
6
|
+
const updateHistoryItem = (oldHistoryItem, txMeta) => {
|
|
7
|
+
return {
|
|
8
|
+
...oldHistoryItem,
|
|
13
9
|
txMetaId: txMeta.id,
|
|
14
|
-
originalTransactionId:
|
|
10
|
+
originalTransactionId: oldHistoryItem.originalTransactionId ?? txMeta.id,
|
|
15
11
|
status: {
|
|
16
|
-
...
|
|
12
|
+
...oldHistoryItem.status,
|
|
17
13
|
srcChain: {
|
|
18
|
-
...
|
|
19
|
-
txHash: txMeta.hash ??
|
|
14
|
+
...oldHistoryItem.status.srcChain,
|
|
15
|
+
txHash: txMeta.hash ?? oldHistoryItem.status.srcChain?.txHash,
|
|
20
16
|
},
|
|
21
17
|
},
|
|
22
18
|
};
|
|
23
|
-
|
|
19
|
+
};
|
|
20
|
+
const rekeyHistoryItemInState = (state, oldKey, newKey, txMeta) => {
|
|
21
|
+
const historyItem = state.txHistory[oldKey];
|
|
22
|
+
if (!historyItem) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
state.txHistory[newKey] = {
|
|
26
|
+
...historyItem,
|
|
27
|
+
...updateHistoryItem(historyItem, txMeta),
|
|
28
|
+
};
|
|
29
|
+
delete state.txHistory[oldKey];
|
|
24
30
|
return true;
|
|
25
31
|
};
|
|
26
32
|
exports.rekeyHistoryItemInState = rekeyHistoryItemInState;
|
|
33
|
+
const isBatchSellHistoryItem = (historyItem) => Boolean(historyItem?.batchSellData);
|
|
34
|
+
exports.isBatchSellHistoryItem = isBatchSellHistoryItem;
|
|
27
35
|
/**
|
|
28
36
|
* Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash
|
|
29
37
|
*
|
|
@@ -39,7 +47,12 @@ const getMatchingHistoryEntryForTxMeta = (txHistory, txMeta) => {
|
|
|
39
47
|
key === txMeta.actionId ||
|
|
40
48
|
txMetaId === txMeta.id ||
|
|
41
49
|
(actionId ? actionId === txMeta.actionId : false) ||
|
|
42
|
-
(
|
|
50
|
+
// When the batch is not atomic (BatchSell), ignore batchId matching to prevent txs
|
|
51
|
+
// in the batch from getting marked complete/failed too early if one fails
|
|
52
|
+
// Multiple BatchSell STX trades may have the same batchId
|
|
53
|
+
(Boolean(batchId) &&
|
|
54
|
+
!(0, exports.isBatchSellHistoryItem)(value) &&
|
|
55
|
+
batchId === txMeta.batchId) ||
|
|
43
56
|
(txHash ? txHash.toLowerCase() === txMeta.hash?.toLowerCase() : false));
|
|
44
57
|
});
|
|
45
58
|
};
|
|
@@ -56,10 +69,47 @@ const getMatchingHistoryEntryForApprovalTxMeta = (txHistory, txMeta) => {
|
|
|
56
69
|
return historyEntries.find(([_, value]) => value.approvalTxId ? value.approvalTxId === txMeta.id : false);
|
|
57
70
|
};
|
|
58
71
|
exports.getMatchingHistoryEntryForApprovalTxMeta = getMatchingHistoryEntryForApprovalTxMeta;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the BatchSell history items in the same batch as the provided tx hash.
|
|
74
|
+
*
|
|
75
|
+
* @param txHistory - The bridge status controller's history to search for matching history items
|
|
76
|
+
* @param txHashOrId - the hash or txMeta.id of a single trade in a BatchSell
|
|
77
|
+
* @returns The matching history items for the tx hash and a boolean indicating if it's a 7702 batch.
|
|
78
|
+
* @example
|
|
79
|
+
* getBatchSellHistoryItemsForTxHash(txHistory, id)
|
|
80
|
+
* If id is the hash or txMetaId of a BatchSell trade, it will return the history items for
|
|
81
|
+
* the trade and all other trades in the same batch.
|
|
82
|
+
*/
|
|
83
|
+
const getBatchSellHistoryItemsForTxHash = (txHistory, txHashOrId) => {
|
|
84
|
+
const historyItems = Object.values(txHistory);
|
|
85
|
+
if (!txHashOrId) {
|
|
86
|
+
return {
|
|
87
|
+
historyItems: [],
|
|
88
|
+
is7702Batch: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Either a delegation tx or a single STX BatchSell trade
|
|
93
|
+
*/
|
|
94
|
+
const parentHistoryItem = historyItems.find(({ status, txMetaId }) => status.srcChain.txHash?.toLowerCase() === txHashOrId.toLowerCase() ||
|
|
95
|
+
txMetaId === txHashOrId);
|
|
96
|
+
// Match by batchId or by quoteId
|
|
97
|
+
const matchingHistoryItems = parentHistoryItem?.quoteIds?.map((quoteId) => txHistory[quoteId]) ??
|
|
98
|
+
historyItems.filter(({ batchId }) => batchId &&
|
|
99
|
+
parentHistoryItem?.batchId &&
|
|
100
|
+
batchId === parentHistoryItem.batchId);
|
|
101
|
+
return {
|
|
102
|
+
historyItems: matchingHistoryItems.filter((item) => item !== undefined),
|
|
103
|
+
is7702Batch: Boolean(parentHistoryItem) &&
|
|
104
|
+
Boolean(parentHistoryItem?.quoteIds?.length),
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
exports.getBatchSellHistoryItemsForTxHash = getBatchSellHistoryItemsForTxHash;
|
|
59
108
|
/**
|
|
60
109
|
* Determines the key to use for storing a bridge history item.
|
|
61
110
|
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
62
111
|
*
|
|
112
|
+
* @deprecated specify an explicit history key instead
|
|
63
113
|
* @param actionId - The action ID used for pre-submission tracking
|
|
64
114
|
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
65
115
|
* @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
|
|
@@ -75,11 +125,7 @@ function getHistoryKey(actionId, bridgeTxMetaId, syntheticTransactionId) {
|
|
|
75
125
|
}
|
|
76
126
|
exports.getHistoryKey = getHistoryKey;
|
|
77
127
|
const getInitialHistoryItem = (args) => {
|
|
78
|
-
const { bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, originalTransactionId, actionId, tokenSecurityTypeDestination, } = args;
|
|
79
|
-
// Determine the key for this history item:
|
|
80
|
-
// - For pre-submission (non-batch EVM): use actionId
|
|
81
|
-
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
82
|
-
const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id, originalTransactionId);
|
|
128
|
+
const { bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, originalTransactionId, actionId, tokenSecurityTypeDestination, batchSellData, quoteIds, } = args;
|
|
83
129
|
// Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
|
|
84
130
|
// We know it's in progress but not the exact status yet
|
|
85
131
|
const txHistoryItem = {
|
|
@@ -125,7 +171,13 @@ const getInitialHistoryItem = (args) => {
|
|
|
125
171
|
tokenSecurityTypeDestination,
|
|
126
172
|
}),
|
|
127
173
|
};
|
|
128
|
-
|
|
174
|
+
if (batchSellData) {
|
|
175
|
+
txHistoryItem.batchSellData = batchSellData;
|
|
176
|
+
}
|
|
177
|
+
if (quoteIds) {
|
|
178
|
+
txHistoryItem.quoteIds = quoteIds;
|
|
179
|
+
}
|
|
180
|
+
return txHistoryItem;
|
|
129
181
|
};
|
|
130
182
|
exports.getInitialHistoryItem = getInitialHistoryItem;
|
|
131
183
|
const shouldPollHistoryItem = (historyItem) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.cjs","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":";;;AAAA,mEAKqC;AASrC,uDAAgE;AAEzD,MAAM,uBAAuB,GAAG,CACrC,KAAkC,EAClC,QAAgB,EAChB,MAAqC,EAC5B,EAAE;IACX,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG;QAC3B,GAAG,WAAW;QACd,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,qBAAqB,EAAE,WAAW,CAAC,qBAAqB,IAAI,MAAM,CAAC,EAAE;QACrE,MAAM,EAAE;YACN,GAAG,WAAW,CAAC,MAAM;YACrB,QAAQ,EAAE;gBACR,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ;gBAC9B,MAAM,EAAE,MAAM,CAAC,IAAI,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM;aAC3D;SACF;KACF,CAAC;IACF,OAAO,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAxBW,QAAA,uBAAuB,2BAwBlC;AAEF;;;;;;GAMG;AACI,MAAM,gCAAgC,GAAG,CAC9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AC5B,WAAW,CAAC,KAAK,CAAC,WAAW,CAC9B,CAAC;IACF,MAAM,QAAQ,GAAG,IAAA,iCAAa,EAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE7D,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC;AAXW,QAAA,qBAAqB,yBAWhC;AAEK,MAAM,mBAAmB,GAAG,CACjC,SAA0C,EAC1C,WAA8B,EACrB,EAAE;IACX,MAAM,0BAA0B,GAAG,IAAA,6CAA6B,EAAC,SAAS,CAAC,CAAC;IAE5E,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,SAAS,GAAG,0BAA0B,CAAC;AACzE,CAAC,CAAC;AAPW,QAAA,mBAAmB,uBAO9B","sourcesContent":["import {\n StatusTypes,\n isCrossChain,\n isNonEvmChainId,\n isTronChainId,\n} from '@metamask/bridge-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\nimport { getMaxPendingHistoryItemAgeMs } from './feature-flags';\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n actionId: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[actionId];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[txMeta.id] = {\n ...historyItem,\n txMetaId: txMeta.id,\n originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,\n status: {\n ...historyItem.status,\n srcChain: {\n ...historyItem.status.srcChain,\n txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,\n },\n },\n };\n delete state.txHistory[actionId];\n return true;\n};\n\n/**\n * Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([key, value]) => {\n const {\n txMetaId,\n actionId,\n batchId,\n status: {\n srcChain: { txHash },\n },\n } = value;\n return (\n key === txMeta.id ||\n key === txMeta.actionId ||\n txMetaId === txMeta.id ||\n (actionId ? actionId === txMeta.actionId : false) ||\n (batchId ? batchId === txMeta.batchId : false) ||\n (txHash ? txHash.toLowerCase() === txMeta.hash?.toLowerCase() : false)\n );\n });\n};\n\n/**\n * Returns the history entry whose approvalTxId matches the approval transaction\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForApprovalTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([_, value]) =>\n value.approvalTxId ? value.approvalTxId === txMeta.id : false,\n );\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n syntheticTransactionId?: string,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n args: StartPollingForBridgeTxStatusArgsSerialized,\n): {\n historyKey: string;\n txHistoryItem: BridgeHistoryItem;\n} => {\n const {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n activeAbTests,\n accountAddress: selectedAddress,\n originalTransactionId,\n actionId,\n tokenSecurityTypeDestination,\n } = args;\n // Determine the key for this history item:\n // - For pre-submission (non-batch EVM): use actionId\n // - For post-submission or other cases: use bridgeTxMeta.id\n const historyKey = getHistoryKey(\n actionId,\n bridgeTxMeta?.id,\n originalTransactionId,\n );\n\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 actionId,\n originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\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: quoteResponse.quote.srcChainId,\n // We don't set the initial tx hash for STX transactions because they return a hash on submission\n // but it is not finalized until confirmation on chain\n txHash:\n isNonEvmChainId(quoteResponse.quote.srcChainId) || !isStxEnabled\n ? bridgeTxMeta?.hash\n : undefined,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n ...(tokenSecurityTypeDestination !== undefined && {\n tokenSecurityTypeDestination,\n }),\n };\n\n return { historyKey, txHistoryItem };\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n\nexport const isHistoryItemTooOld = (\n messenger: BridgeStatusControllerMessenger,\n historyItem: BridgeHistoryItem,\n): boolean => {\n const maxPendingHistoryItemAgeMs = getMaxPendingHistoryItemAgeMs(messenger);\n\n return Date.now() - historyItem.startTime > maxPendingHistoryItemAgeMs;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"history.cjs","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":";;;AAAA,mEAKqC;AASrC,uDAAgE;AAEhE,MAAM,iBAAiB,GAAG,CACxB,cAAiC,EACjC,MAAqC,EACT,EAAE;IAC9B,OAAO;QACL,GAAG,cAAc;QACjB,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,qBAAqB,EAAE,cAAc,CAAC,qBAAqB,IAAI,MAAM,CAAC,EAAE;QACxE,MAAM,EAAE;YACN,GAAG,cAAc,CAAC,MAAM;YACxB,QAAQ,EAAE;gBACR,GAAG,cAAc,CAAC,MAAM,CAAC,QAAQ;gBACjC,MAAM,EAAE,MAAM,CAAC,IAAI,IAAI,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM;aAC9D;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEK,MAAM,uBAAuB,GAAG,CACrC,KAAkC,EAClC,MAAc,EACd,MAAc,EACd,MAAqC,EAC5B,EAAE;IACX,MAAM,W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4BAA4B,KAAK,SAAS,IAAI;YAChD,4BAA4B;SAC7B,CAAC;KACH,CAAC;IAEF,IAAI,aAAa,EAAE,CAAC;QAClB,aAAa,CAAC,aAAa,GAAG,aAAa,CAAC;IAC9C,CAAC;IACD,IAAI,QAAQ,EAAE,CAAC;QACb,aAAa,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACpC,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AA/EW,QAAA,qBAAqB,yBA+EhC;AAEK,MAAM,qBAAqB,GAAG,CACnC,WAA8B,EACrB,EAAE;IACX,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,IAAA,gCAAY,EAC7B,WAAW,CAAC,KAAK,CAAC,UAAU,EAC5B,WAAW,CAAC,KAAK,CAAC,WAAW,CAC9B,CAAC;IACF,MAAM,QAAQ,GAAG,IAAA,iCAAa,EAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE7D,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC;AAXW,QAAA,qBAAqB,yBAWhC;AAEK,MAAM,mBAAmB,GAAG,CACjC,SAA0C,EAC1C,WAA8B,EACrB,EAAE;IACX,MAAM,0BAA0B,GAAG,IAAA,6CAA6B,EAAC,SAAS,CAAC,CAAC;IAE5E,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,SAAS,GAAG,0BAA0B,CAAC;AACzE,CAAC,CAAC;AAPW,QAAA,mBAAmB,uBAO9B","sourcesContent":["import {\n StatusTypes,\n isCrossChain,\n isNonEvmChainId,\n isTronChainId,\n} from '@metamask/bridge-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\nimport { getMaxPendingHistoryItemAgeMs } from './feature-flags';\n\nconst updateHistoryItem = (\n oldHistoryItem: BridgeHistoryItem,\n txMeta: { id: string; hash?: string },\n): Partial<BridgeHistoryItem> => {\n return {\n ...oldHistoryItem,\n txMetaId: txMeta.id,\n originalTransactionId: oldHistoryItem.originalTransactionId ?? txMeta.id,\n status: {\n ...oldHistoryItem.status,\n srcChain: {\n ...oldHistoryItem.status.srcChain,\n txHash: txMeta.hash ?? oldHistoryItem.status.srcChain?.txHash,\n },\n },\n };\n};\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n oldKey: string,\n newKey: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[oldKey];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[newKey] = {\n ...historyItem,\n ...updateHistoryItem(historyItem, txMeta),\n };\n delete state.txHistory[oldKey];\n return true;\n};\n\nexport const isBatchSellHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => Boolean(historyItem?.batchSellData);\n\n/**\n * Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([key, value]) => {\n const {\n txMetaId,\n actionId,\n batchId,\n status: {\n srcChain: { txHash },\n },\n } = value;\n return (\n key === txMeta.id ||\n key === txMeta.actionId ||\n txMetaId === txMeta.id ||\n (actionId ? actionId === txMeta.actionId : false) ||\n // When the batch is not atomic (BatchSell), ignore batchId matching to prevent txs\n // in the batch from getting marked complete/failed too early if one fails\n // Multiple BatchSell STX trades may have the same batchId\n (Boolean(batchId) &&\n !isBatchSellHistoryItem(value) &&\n batchId === txMeta.batchId) ||\n (txHash ? txHash.toLowerCase() === txMeta.hash?.toLowerCase() : false)\n );\n });\n};\n\n/**\n * Returns the history entry whose approvalTxId matches the approval transaction\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForApprovalTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([_, value]) =>\n value.approvalTxId ? value.approvalTxId === txMeta.id : false,\n );\n};\n\n/**\n * Returns the BatchSell history items in the same batch as the provided tx hash.\n *\n * @param txHistory - The bridge status controller's history to search for matching history items\n * @param txHashOrId - the hash or txMeta.id of a single trade in a BatchSell\n * @returns The matching history items for the tx hash and a boolean indicating if it's a 7702 batch.\n * @example\n * getBatchSellHistoryItemsForTxHash(txHistory, id)\n * If id is the hash or txMetaId of a BatchSell trade, it will return the history items for\n * the trade and all other trades in the same batch.\n */\nexport const getBatchSellHistoryItemsForTxHash = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txHashOrId?: string,\n): { historyItems: BridgeHistoryItem[]; is7702Batch: boolean } => {\n const historyItems = Object.values(txHistory);\n\n if (!txHashOrId) {\n return {\n historyItems: [],\n is7702Batch: false,\n };\n }\n\n /**\n * Either a delegation tx or a single STX BatchSell trade\n */\n const parentHistoryItem = historyItems.find(\n ({ status, txMetaId }) =>\n status.srcChain.txHash?.toLowerCase() === txHashOrId.toLowerCase() ||\n txMetaId === txHashOrId,\n );\n\n // Match by batchId or by quoteId\n const matchingHistoryItems =\n parentHistoryItem?.quoteIds?.map((quoteId) => txHistory[quoteId]) ??\n historyItems.filter(\n ({ batchId }) =>\n batchId &&\n parentHistoryItem?.batchId &&\n batchId === parentHistoryItem.batchId,\n );\n\n return {\n historyItems: matchingHistoryItems.filter((item) => item !== undefined),\n is7702Batch:\n Boolean(parentHistoryItem) &&\n Boolean(parentHistoryItem?.quoteIds?.length),\n };\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @deprecated specify an explicit history key instead\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n syntheticTransactionId?: string,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n args: StartPollingForBridgeTxStatusArgsSerialized,\n): BridgeHistoryItem => {\n const {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n activeAbTests,\n accountAddress: selectedAddress,\n originalTransactionId,\n actionId,\n tokenSecurityTypeDestination,\n batchSellData,\n quoteIds,\n } = args;\n\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: BridgeHistoryItem = {\n txMetaId: bridgeTxMeta?.id,\n actionId,\n originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\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: quoteResponse.quote.srcChainId,\n // We don't set the initial tx hash for STX transactions because they return a hash on submission\n // but it is not finalized until confirmation on chain\n txHash:\n isNonEvmChainId(quoteResponse.quote.srcChainId) || !isStxEnabled\n ? bridgeTxMeta?.hash\n : undefined,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n ...(tokenSecurityTypeDestination !== undefined && {\n tokenSecurityTypeDestination,\n }),\n };\n\n if (batchSellData) {\n txHistoryItem.batchSellData = batchSellData;\n }\n if (quoteIds) {\n txHistoryItem.quoteIds = quoteIds;\n }\n\n return txHistoryItem;\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n\nexport const isHistoryItemTooOld = (\n messenger: BridgeStatusControllerMessenger,\n historyItem: BridgeHistoryItem,\n): boolean => {\n const maxPendingHistoryItemAgeMs = getMaxPendingHistoryItemAgeMs(messenger);\n\n return Date.now() - historyItem.startTime > maxPendingHistoryItemAgeMs;\n};\n"]}
|
package/dist/utils/history.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
2
2
|
import type { BridgeHistoryItem, BridgeStatusControllerMessenger, BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized } from "../types.cjs";
|
|
3
|
-
export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState,
|
|
3
|
+
export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState, oldKey: string, newKey: string, txMeta: {
|
|
4
4
|
id: string;
|
|
5
5
|
hash?: string;
|
|
6
6
|
}) => boolean;
|
|
7
|
+
export declare const isBatchSellHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
|
|
7
8
|
/**
|
|
8
9
|
* Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash
|
|
9
10
|
*
|
|
@@ -20,10 +21,26 @@ export declare const getMatchingHistoryEntryForTxMeta: (txHistory: BridgeStatusC
|
|
|
20
21
|
* @returns The history entry that matches the txMeta
|
|
21
22
|
*/
|
|
22
23
|
export declare const getMatchingHistoryEntryForApprovalTxMeta: (txHistory: BridgeStatusControllerState['txHistory'], txMeta: TransactionMeta) => [string, BridgeHistoryItem] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the BatchSell history items in the same batch as the provided tx hash.
|
|
26
|
+
*
|
|
27
|
+
* @param txHistory - The bridge status controller's history to search for matching history items
|
|
28
|
+
* @param txHashOrId - the hash or txMeta.id of a single trade in a BatchSell
|
|
29
|
+
* @returns The matching history items for the tx hash and a boolean indicating if it's a 7702 batch.
|
|
30
|
+
* @example
|
|
31
|
+
* getBatchSellHistoryItemsForTxHash(txHistory, id)
|
|
32
|
+
* If id is the hash or txMetaId of a BatchSell trade, it will return the history items for
|
|
33
|
+
* the trade and all other trades in the same batch.
|
|
34
|
+
*/
|
|
35
|
+
export declare const getBatchSellHistoryItemsForTxHash: (txHistory: BridgeStatusControllerState['txHistory'], txHashOrId?: string) => {
|
|
36
|
+
historyItems: BridgeHistoryItem[];
|
|
37
|
+
is7702Batch: boolean;
|
|
38
|
+
};
|
|
23
39
|
/**
|
|
24
40
|
* Determines the key to use for storing a bridge history item.
|
|
25
41
|
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
26
42
|
*
|
|
43
|
+
* @deprecated specify an explicit history key instead
|
|
27
44
|
* @param actionId - The action ID used for pre-submission tracking
|
|
28
45
|
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
29
46
|
* @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
|
|
@@ -31,10 +48,7 @@ export declare const getMatchingHistoryEntryForApprovalTxMeta: (txHistory: Bridg
|
|
|
31
48
|
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
32
49
|
*/
|
|
33
50
|
export declare function getHistoryKey(actionId: string | undefined, bridgeTxMetaId: string | undefined, syntheticTransactionId?: string): string;
|
|
34
|
-
export declare const getInitialHistoryItem: (args: StartPollingForBridgeTxStatusArgsSerialized) =>
|
|
35
|
-
historyKey: string;
|
|
36
|
-
txHistoryItem: BridgeHistoryItem;
|
|
37
|
-
};
|
|
51
|
+
export declare const getInitialHistoryItem: (args: StartPollingForBridgeTxStatusArgsSerialized) => BridgeHistoryItem;
|
|
38
52
|
export declare const shouldPollHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
|
|
39
53
|
export declare const isHistoryItemTooOld: (messenger: BridgeStatusControllerMessenger, historyItem: BridgeHistoryItem) => boolean;
|
|
40
54
|
//# sourceMappingURL=history.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.cts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAExE,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;
|
|
1
|
+
{"version":3,"file":"history.d.cts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAExE,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;AAqBlB,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,UAC1B,MAAM,UACN,MAAM,UACN;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAYF,CAAC;AAEF,eAAO,MAAM,sBAAsB,gBACpB,iBAAiB,KAC7B,OAA8C,CAAC;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,cAChC,2BAA2B,CAAC,WAAW,CAAC,UAC3C,eAAe,KACtB,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,SA0BhC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wCAAwC,cACxC,2BAA2B,CAAC,WAAW,CAAC,UAC3C,eAAe,KACtB,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,SAMhC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,cACjC,2BAA2B,CAAC,WAAW,CAAC,eACtC,MAAM;kBACF,iBAAiB,EAAE;iBAAe,OAAO;CAmC3D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,sBAAsB,CAAC,EAAE,MAAM,GAC9B,MAAM,CAQR;AAED,eAAO,MAAM,qBAAqB,SAC1B,2CAA2C,KAChD,iBA6EF,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBACnB,iBAAiB,KAC7B,OASF,CAAC;AAEF,eAAO,MAAM,mBAAmB,4DAEjB,iBAAiB,KAC7B,OAIF,CAAC"}
|
package/dist/utils/history.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
2
2
|
import type { BridgeHistoryItem, BridgeStatusControllerMessenger, BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized } from "../types.mjs";
|
|
3
|
-
export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState,
|
|
3
|
+
export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState, oldKey: string, newKey: string, txMeta: {
|
|
4
4
|
id: string;
|
|
5
5
|
hash?: string;
|
|
6
6
|
}) => boolean;
|
|
7
|
+
export declare const isBatchSellHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
|
|
7
8
|
/**
|
|
8
9
|
* Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash
|
|
9
10
|
*
|
|
@@ -20,10 +21,26 @@ export declare const getMatchingHistoryEntryForTxMeta: (txHistory: BridgeStatusC
|
|
|
20
21
|
* @returns The history entry that matches the txMeta
|
|
21
22
|
*/
|
|
22
23
|
export declare const getMatchingHistoryEntryForApprovalTxMeta: (txHistory: BridgeStatusControllerState['txHistory'], txMeta: TransactionMeta) => [string, BridgeHistoryItem] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the BatchSell history items in the same batch as the provided tx hash.
|
|
26
|
+
*
|
|
27
|
+
* @param txHistory - The bridge status controller's history to search for matching history items
|
|
28
|
+
* @param txHashOrId - the hash or txMeta.id of a single trade in a BatchSell
|
|
29
|
+
* @returns The matching history items for the tx hash and a boolean indicating if it's a 7702 batch.
|
|
30
|
+
* @example
|
|
31
|
+
* getBatchSellHistoryItemsForTxHash(txHistory, id)
|
|
32
|
+
* If id is the hash or txMetaId of a BatchSell trade, it will return the history items for
|
|
33
|
+
* the trade and all other trades in the same batch.
|
|
34
|
+
*/
|
|
35
|
+
export declare const getBatchSellHistoryItemsForTxHash: (txHistory: BridgeStatusControllerState['txHistory'], txHashOrId?: string) => {
|
|
36
|
+
historyItems: BridgeHistoryItem[];
|
|
37
|
+
is7702Batch: boolean;
|
|
38
|
+
};
|
|
23
39
|
/**
|
|
24
40
|
* Determines the key to use for storing a bridge history item.
|
|
25
41
|
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
26
42
|
*
|
|
43
|
+
* @deprecated specify an explicit history key instead
|
|
27
44
|
* @param actionId - The action ID used for pre-submission tracking
|
|
28
45
|
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
29
46
|
* @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
|
|
@@ -31,10 +48,7 @@ export declare const getMatchingHistoryEntryForApprovalTxMeta: (txHistory: Bridg
|
|
|
31
48
|
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
32
49
|
*/
|
|
33
50
|
export declare function getHistoryKey(actionId: string | undefined, bridgeTxMetaId: string | undefined, syntheticTransactionId?: string): string;
|
|
34
|
-
export declare const getInitialHistoryItem: (args: StartPollingForBridgeTxStatusArgsSerialized) =>
|
|
35
|
-
historyKey: string;
|
|
36
|
-
txHistoryItem: BridgeHistoryItem;
|
|
37
|
-
};
|
|
51
|
+
export declare const getInitialHistoryItem: (args: StartPollingForBridgeTxStatusArgsSerialized) => BridgeHistoryItem;
|
|
38
52
|
export declare const shouldPollHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
|
|
39
53
|
export declare const isHistoryItemTooOld: (messenger: BridgeStatusControllerMessenger, historyItem: BridgeHistoryItem) => boolean;
|
|
40
54
|
//# sourceMappingURL=history.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.mts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAExE,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;
|
|
1
|
+
{"version":3,"file":"history.d.mts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAExE,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;AAqBlB,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,UAC1B,MAAM,UACN,MAAM,UACN;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAYF,CAAC;AAEF,eAAO,MAAM,sBAAsB,gBACpB,iBAAiB,KAC7B,OAA8C,CAAC;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,cAChC,2BAA2B,CAAC,WAAW,CAAC,UAC3C,eAAe,KACtB,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,SA0BhC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wCAAwC,cACxC,2BAA2B,CAAC,WAAW,CAAC,UAC3C,eAAe,KACtB,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,SAMhC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iCAAiC,cACjC,2BAA2B,CAAC,WAAW,CAAC,eACtC,MAAM;kBACF,iBAAiB,EAAE;iBAAe,OAAO;CAmC3D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,sBAAsB,CAAC,EAAE,MAAM,GAC9B,MAAM,CAQR;AAED,eAAO,MAAM,qBAAqB,SAC1B,2CAA2C,KAChD,iBA6EF,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBACnB,iBAAiB,KAC7B,OASF,CAAC;AAEF,eAAO,MAAM,mBAAmB,4DAEjB,iBAAiB,KAC7B,OAIF,CAAC"}
|
package/dist/utils/history.mjs
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
import { StatusTypes, isCrossChain, isNonEvmChainId, isTronChainId } from "@metamask/bridge-controller";
|
|
2
2
|
import { getMaxPendingHistoryItemAgeMs } from "./feature-flags.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
state.txHistory[txMeta.id] = {
|
|
9
|
-
...historyItem,
|
|
3
|
+
const updateHistoryItem = (oldHistoryItem, txMeta) => {
|
|
4
|
+
return {
|
|
5
|
+
...oldHistoryItem,
|
|
10
6
|
txMetaId: txMeta.id,
|
|
11
|
-
originalTransactionId:
|
|
7
|
+
originalTransactionId: oldHistoryItem.originalTransactionId ?? txMeta.id,
|
|
12
8
|
status: {
|
|
13
|
-
...
|
|
9
|
+
...oldHistoryItem.status,
|
|
14
10
|
srcChain: {
|
|
15
|
-
...
|
|
16
|
-
txHash: txMeta.hash ??
|
|
11
|
+
...oldHistoryItem.status.srcChain,
|
|
12
|
+
txHash: txMeta.hash ?? oldHistoryItem.status.srcChain?.txHash,
|
|
17
13
|
},
|
|
18
14
|
},
|
|
19
15
|
};
|
|
20
|
-
|
|
16
|
+
};
|
|
17
|
+
export const rekeyHistoryItemInState = (state, oldKey, newKey, txMeta) => {
|
|
18
|
+
const historyItem = state.txHistory[oldKey];
|
|
19
|
+
if (!historyItem) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
state.txHistory[newKey] = {
|
|
23
|
+
...historyItem,
|
|
24
|
+
...updateHistoryItem(historyItem, txMeta),
|
|
25
|
+
};
|
|
26
|
+
delete state.txHistory[oldKey];
|
|
21
27
|
return true;
|
|
22
28
|
};
|
|
29
|
+
export const isBatchSellHistoryItem = (historyItem) => Boolean(historyItem?.batchSellData);
|
|
23
30
|
/**
|
|
24
31
|
* Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash
|
|
25
32
|
*
|
|
@@ -35,7 +42,12 @@ export const getMatchingHistoryEntryForTxMeta = (txHistory, txMeta) => {
|
|
|
35
42
|
key === txMeta.actionId ||
|
|
36
43
|
txMetaId === txMeta.id ||
|
|
37
44
|
(actionId ? actionId === txMeta.actionId : false) ||
|
|
38
|
-
(
|
|
45
|
+
// When the batch is not atomic (BatchSell), ignore batchId matching to prevent txs
|
|
46
|
+
// in the batch from getting marked complete/failed too early if one fails
|
|
47
|
+
// Multiple BatchSell STX trades may have the same batchId
|
|
48
|
+
(Boolean(batchId) &&
|
|
49
|
+
!isBatchSellHistoryItem(value) &&
|
|
50
|
+
batchId === txMeta.batchId) ||
|
|
39
51
|
(txHash ? txHash.toLowerCase() === txMeta.hash?.toLowerCase() : false));
|
|
40
52
|
});
|
|
41
53
|
};
|
|
@@ -50,10 +62,46 @@ export const getMatchingHistoryEntryForApprovalTxMeta = (txHistory, txMeta) => {
|
|
|
50
62
|
const historyEntries = Object.entries(txHistory);
|
|
51
63
|
return historyEntries.find(([_, value]) => value.approvalTxId ? value.approvalTxId === txMeta.id : false);
|
|
52
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Returns the BatchSell history items in the same batch as the provided tx hash.
|
|
67
|
+
*
|
|
68
|
+
* @param txHistory - The bridge status controller's history to search for matching history items
|
|
69
|
+
* @param txHashOrId - the hash or txMeta.id of a single trade in a BatchSell
|
|
70
|
+
* @returns The matching history items for the tx hash and a boolean indicating if it's a 7702 batch.
|
|
71
|
+
* @example
|
|
72
|
+
* getBatchSellHistoryItemsForTxHash(txHistory, id)
|
|
73
|
+
* If id is the hash or txMetaId of a BatchSell trade, it will return the history items for
|
|
74
|
+
* the trade and all other trades in the same batch.
|
|
75
|
+
*/
|
|
76
|
+
export const getBatchSellHistoryItemsForTxHash = (txHistory, txHashOrId) => {
|
|
77
|
+
const historyItems = Object.values(txHistory);
|
|
78
|
+
if (!txHashOrId) {
|
|
79
|
+
return {
|
|
80
|
+
historyItems: [],
|
|
81
|
+
is7702Batch: false,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Either a delegation tx or a single STX BatchSell trade
|
|
86
|
+
*/
|
|
87
|
+
const parentHistoryItem = historyItems.find(({ status, txMetaId }) => status.srcChain.txHash?.toLowerCase() === txHashOrId.toLowerCase() ||
|
|
88
|
+
txMetaId === txHashOrId);
|
|
89
|
+
// Match by batchId or by quoteId
|
|
90
|
+
const matchingHistoryItems = parentHistoryItem?.quoteIds?.map((quoteId) => txHistory[quoteId]) ??
|
|
91
|
+
historyItems.filter(({ batchId }) => batchId &&
|
|
92
|
+
parentHistoryItem?.batchId &&
|
|
93
|
+
batchId === parentHistoryItem.batchId);
|
|
94
|
+
return {
|
|
95
|
+
historyItems: matchingHistoryItems.filter((item) => item !== undefined),
|
|
96
|
+
is7702Batch: Boolean(parentHistoryItem) &&
|
|
97
|
+
Boolean(parentHistoryItem?.quoteIds?.length),
|
|
98
|
+
};
|
|
99
|
+
};
|
|
53
100
|
/**
|
|
54
101
|
* Determines the key to use for storing a bridge history item.
|
|
55
102
|
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
56
103
|
*
|
|
104
|
+
* @deprecated specify an explicit history key instead
|
|
57
105
|
* @param actionId - The action ID used for pre-submission tracking
|
|
58
106
|
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
59
107
|
* @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
|
|
@@ -68,11 +116,7 @@ export function getHistoryKey(actionId, bridgeTxMetaId, syntheticTransactionId)
|
|
|
68
116
|
return historyKey;
|
|
69
117
|
}
|
|
70
118
|
export const getInitialHistoryItem = (args) => {
|
|
71
|
-
const { bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, originalTransactionId, actionId, tokenSecurityTypeDestination, } = args;
|
|
72
|
-
// Determine the key for this history item:
|
|
73
|
-
// - For pre-submission (non-batch EVM): use actionId
|
|
74
|
-
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
75
|
-
const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id, originalTransactionId);
|
|
119
|
+
const { bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, originalTransactionId, actionId, tokenSecurityTypeDestination, batchSellData, quoteIds, } = args;
|
|
76
120
|
// Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
|
|
77
121
|
// We know it's in progress but not the exact status yet
|
|
78
122
|
const txHistoryItem = {
|
|
@@ -118,7 +162,13 @@ export const getInitialHistoryItem = (args) => {
|
|
|
118
162
|
tokenSecurityTypeDestination,
|
|
119
163
|
}),
|
|
120
164
|
};
|
|
121
|
-
|
|
165
|
+
if (batchSellData) {
|
|
166
|
+
txHistoryItem.batchSellData = batchSellData;
|
|
167
|
+
}
|
|
168
|
+
if (quoteIds) {
|
|
169
|
+
txHistoryItem.quoteIds = quoteIds;
|
|
170
|
+
}
|
|
171
|
+
return txHistoryItem;
|
|
122
172
|
};
|
|
123
173
|
export const shouldPollHistoryItem = (historyItem) => {
|
|
124
174
|
const isIntent = Boolean(historyItem?.quote?.intent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.mjs","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACd,oCAAoC;AASrC,OAAO,EAAE,6BAA6B,EAAE,4BAAwB;AAEhE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAkC,EAClC,QAAgB,EAChB,MAAqC,EAC5B,EAAE;IACX,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG;QAC3B,GAAG,WAAW;QACd,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,qBAAqB,EAAE,WAAW,CAAC,qBAAqB,IAAI,MAAM,CAAC,EAAE;QACrE,MAAM,EAAE;YACN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AEF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,WAA8B,EACrB,EAAE;IACX,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,YAAY,CAC7B,WAAW,CAAC,KAAK,CAAC,UAAU,EAC5B,WAAW,CAAC,KAAK,CAAC,WAAW,CAC9B,CAAC;IACF,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE7D,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAA0C,EAC1C,WAA8B,EACrB,EAAE;IACX,MAAM,0BAA0B,GAAG,6BAA6B,CAAC,SAAS,CAAC,CAAC;IAE5E,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,SAAS,GAAG,0BAA0B,CAAC;AACzE,CAAC,CAAC","sourcesContent":["import {\n StatusTypes,\n isCrossChain,\n isNonEvmChainId,\n isTronChainId,\n} from '@metamask/bridge-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\nimport { getMaxPendingHistoryItemAgeMs } from './feature-flags';\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n actionId: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[actionId];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[txMeta.id] = {\n ...historyItem,\n txMetaId: txMeta.id,\n originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,\n status: {\n ...historyItem.status,\n srcChain: {\n ...historyItem.status.srcChain,\n txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,\n },\n },\n };\n delete state.txHistory[actionId];\n return true;\n};\n\n/**\n * Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([key, value]) => {\n const {\n txMetaId,\n actionId,\n batchId,\n status: {\n srcChain: { txHash },\n },\n } = value;\n return (\n key === txMeta.id ||\n key === txMeta.actionId ||\n txMetaId === txMeta.id ||\n (actionId ? actionId === txMeta.actionId : false) ||\n (batchId ? batchId === txMeta.batchId : false) ||\n (txHash ? txHash.toLowerCase() === txMeta.hash?.toLowerCase() : false)\n );\n });\n};\n\n/**\n * Returns the history entry whose approvalTxId matches the approval transaction\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForApprovalTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([_, value]) =>\n value.approvalTxId ? value.approvalTxId === txMeta.id : false,\n );\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n syntheticTransactionId?: string,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n args: StartPollingForBridgeTxStatusArgsSerialized,\n): {\n historyKey: string;\n txHistoryItem: BridgeHistoryItem;\n} => {\n const {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n activeAbTests,\n accountAddress: selectedAddress,\n originalTransactionId,\n actionId,\n tokenSecurityTypeDestination,\n } = args;\n // Determine the key for this history item:\n // - For pre-submission (non-batch EVM): use actionId\n // - For post-submission or other cases: use bridgeTxMeta.id\n const historyKey = getHistoryKey(\n actionId,\n bridgeTxMeta?.id,\n originalTransactionId,\n );\n\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 actionId,\n originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\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: quoteResponse.quote.srcChainId,\n // We don't set the initial tx hash for STX transactions because they return a hash on submission\n // but it is not finalized until confirmation on chain\n txHash:\n isNonEvmChainId(quoteResponse.quote.srcChainId) || !isStxEnabled\n ? bridgeTxMeta?.hash\n : undefined,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n ...(tokenSecurityTypeDestination !== undefined && {\n tokenSecurityTypeDestination,\n }),\n };\n\n return { historyKey, txHistoryItem };\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n\nexport const isHistoryItemTooOld = (\n messenger: BridgeStatusControllerMessenger,\n historyItem: BridgeHistoryItem,\n): boolean => {\n const maxPendingHistoryItemAgeMs = getMaxPendingHistoryItemAgeMs(messenger);\n\n return Date.now() - historyItem.startTime > maxPendingHistoryItemAgeMs;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"history.mjs","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACd,oCAAoC;AASrC,OAAO,EAAE,6BAA6B,EAAE,4BAAwB;AAEhE,MAAM,iBAAiB,GAAG,CACxB,cAAiC,EACjC,MAAqC,EACT,EAAE;IAC9B,OAAO;QACL,GAAG,cAAc;QACjB,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,qBAAqB,EAAE,cAAc,CAAC,qBAAqB,IAAI,MAAM,CAAC,EAAE;QACxE,MAAM,EAAE;YACN,GAAG,cAAc,CAAC,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-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\nimport { getMaxPendingHistoryItemAgeMs } from './feature-flags';\n\nconst updateHistoryItem = (\n oldHistoryItem: BridgeHistoryItem,\n txMeta: { id: string; hash?: string },\n): Partial<BridgeHistoryItem> => {\n return {\n ...oldHistoryItem,\n txMetaId: txMeta.id,\n originalTransactionId: oldHistoryItem.originalTransactionId ?? txMeta.id,\n status: {\n ...oldHistoryItem.status,\n srcChain: {\n ...oldHistoryItem.status.srcChain,\n txHash: txMeta.hash ?? oldHistoryItem.status.srcChain?.txHash,\n },\n },\n };\n};\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n oldKey: string,\n newKey: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[oldKey];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[newKey] = {\n ...historyItem,\n ...updateHistoryItem(historyItem, txMeta),\n };\n delete state.txHistory[oldKey];\n return true;\n};\n\nexport const isBatchSellHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => Boolean(historyItem?.batchSellData);\n\n/**\n * Returns the history entry that matches the txMeta by id, actionId, batchId, or txHash\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([key, value]) => {\n const {\n txMetaId,\n actionId,\n batchId,\n status: {\n srcChain: { txHash },\n },\n } = value;\n return (\n key === txMeta.id ||\n key === txMeta.actionId ||\n txMetaId === txMeta.id ||\n (actionId ? actionId === txMeta.actionId : false) ||\n // When the batch is not atomic (BatchSell), ignore batchId matching to prevent txs\n // in the batch from getting marked complete/failed too early if one fails\n // Multiple BatchSell STX trades may have the same batchId\n (Boolean(batchId) &&\n !isBatchSellHistoryItem(value) &&\n batchId === txMeta.batchId) ||\n (txHash ? txHash.toLowerCase() === txMeta.hash?.toLowerCase() : false)\n );\n });\n};\n\n/**\n * Returns the history entry whose approvalTxId matches the approval transaction\n *\n * @param txHistory - The transaction history\n * @param txMeta - The transaction meta\n * @returns The history entry that matches the txMeta\n */\nexport const getMatchingHistoryEntryForApprovalTxMeta = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txMeta: TransactionMeta,\n): [string, BridgeHistoryItem] | undefined => {\n const historyEntries = Object.entries(txHistory);\n\n return historyEntries.find(([_, value]) =>\n value.approvalTxId ? value.approvalTxId === txMeta.id : false,\n );\n};\n\n/**\n * Returns the BatchSell history items in the same batch as the provided tx hash.\n *\n * @param txHistory - The bridge status controller's history to search for matching history items\n * @param txHashOrId - the hash or txMeta.id of a single trade in a BatchSell\n * @returns The matching history items for the tx hash and a boolean indicating if it's a 7702 batch.\n * @example\n * getBatchSellHistoryItemsForTxHash(txHistory, id)\n * If id is the hash or txMetaId of a BatchSell trade, it will return the history items for\n * the trade and all other trades in the same batch.\n */\nexport const getBatchSellHistoryItemsForTxHash = (\n txHistory: BridgeStatusControllerState['txHistory'],\n txHashOrId?: string,\n): { historyItems: BridgeHistoryItem[]; is7702Batch: boolean } => {\n const historyItems = Object.values(txHistory);\n\n if (!txHashOrId) {\n return {\n historyItems: [],\n is7702Batch: false,\n };\n }\n\n /**\n * Either a delegation tx or a single STX BatchSell trade\n */\n const parentHistoryItem = historyItems.find(\n ({ status, txMetaId }) =>\n status.srcChain.txHash?.toLowerCase() === txHashOrId.toLowerCase() ||\n txMetaId === txHashOrId,\n );\n\n // Match by batchId or by quoteId\n const matchingHistoryItems =\n parentHistoryItem?.quoteIds?.map((quoteId) => txHistory[quoteId]) ??\n historyItems.filter(\n ({ batchId }) =>\n batchId &&\n parentHistoryItem?.batchId &&\n batchId === parentHistoryItem.batchId,\n );\n\n return {\n historyItems: matchingHistoryItems.filter((item) => item !== undefined),\n is7702Batch:\n Boolean(parentHistoryItem) &&\n Boolean(parentHistoryItem?.quoteIds?.length),\n };\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @deprecated specify an explicit history key instead\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n syntheticTransactionId?: string,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n args: StartPollingForBridgeTxStatusArgsSerialized,\n): BridgeHistoryItem => {\n const {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n activeAbTests,\n accountAddress: selectedAddress,\n originalTransactionId,\n actionId,\n tokenSecurityTypeDestination,\n batchSellData,\n quoteIds,\n } = args;\n\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: BridgeHistoryItem = {\n txMetaId: bridgeTxMeta?.id,\n actionId,\n originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\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: quoteResponse.quote.srcChainId,\n // We don't set the initial tx hash for STX transactions because they return a hash on submission\n // but it is not finalized until confirmation on chain\n txHash:\n isNonEvmChainId(quoteResponse.quote.srcChainId) || !isStxEnabled\n ? bridgeTxMeta?.hash\n : undefined,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n ...(tokenSecurityTypeDestination !== undefined && {\n tokenSecurityTypeDestination,\n }),\n };\n\n if (batchSellData) {\n txHistoryItem.batchSellData = batchSellData;\n }\n if (quoteIds) {\n txHistoryItem.quoteIds = quoteIds;\n }\n\n return txHistoryItem;\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n\nexport const isHistoryItemTooOld = (\n messenger: BridgeStatusControllerMessenger,\n historyItem: BridgeHistoryItem,\n): boolean => {\n const maxPendingHistoryItemAgeMs = getMaxPendingHistoryItemAgeMs(messenger);\n\n return Date.now() - historyItem.startTime > maxPendingHistoryItemAgeMs;\n};\n"]}
|
package/dist/utils/metrics.cjs
CHANGED
|
@@ -86,11 +86,13 @@ const getRequestParamFromHistory = (historyItem) => {
|
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
88
|
exports.getRequestParamFromHistory = getRequestParamFromHistory;
|
|
89
|
-
const getTradeDataFromQuote = (quoteResponse) => {
|
|
89
|
+
const getTradeDataFromQuote = (quoteResponse, batchSellTrades) => {
|
|
90
90
|
return {
|
|
91
91
|
usd_quoted_gas: Number(quoteResponse.gasFee?.effective?.usd ?? 0),
|
|
92
|
-
gas_included: quoteResponse.quote.gasIncluded ?? false,
|
|
93
|
-
gas_included_7702: quoteResponse.quote.gasIncluded7702 ??
|
|
92
|
+
gas_included: quoteResponse.quote.gasIncluded ?? batchSellTrades?.gasIncluded ?? false,
|
|
93
|
+
gas_included_7702: quoteResponse.quote.gasIncluded7702 ??
|
|
94
|
+
batchSellTrades?.gasIncluded7702 ??
|
|
95
|
+
false,
|
|
94
96
|
provider: (0, bridge_controller_1.formatProviderLabel)(quoteResponse.quote),
|
|
95
97
|
quoted_time_minutes: Number(quoteResponse.estimatedProcessingTimeInSeconds / 60),
|
|
96
98
|
usd_quoted_return: Number(quoteResponse.adjustedReturn?.usd ?? 0),
|
|
@@ -106,19 +108,20 @@ exports.getPriceImpactFromQuote = getPriceImpactFromQuote;
|
|
|
106
108
|
* The quote is used to populate event properties before confirmation
|
|
107
109
|
*
|
|
108
110
|
* @param quoteResponse - The quote response
|
|
109
|
-
* @param
|
|
111
|
+
* @param isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
|
|
110
112
|
* @param accountHardwareType - The hardware wallet type used to submit the tx, or null if not a hardware wallet
|
|
111
113
|
* @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)
|
|
112
114
|
* @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
|
|
113
115
|
* @param activeAbTests - New A/B test context for `active_ab_tests` (migration target)
|
|
114
116
|
* @param tokenSecurityTypeDestination - The security classification of the destination token, supplied by the client (e.g. from token security/scanning data). Pass `null` when no security data is available.
|
|
117
|
+
* @param batchSellTrades - The batch sell trades response
|
|
115
118
|
* @returns The properties for the pre-confirmation event
|
|
116
119
|
*/
|
|
117
|
-
const getPreConfirmationPropertiesFromQuote = (quoteResponse,
|
|
120
|
+
const getPreConfirmationPropertiesFromQuote = (quoteResponse, isStxEnabled, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades) => {
|
|
118
121
|
const { quote } = quoteResponse;
|
|
119
122
|
return {
|
|
120
123
|
...(0, exports.getPriceImpactFromQuote)(quote),
|
|
121
|
-
...(0, exports.getTradeDataFromQuote)(quoteResponse),
|
|
124
|
+
...(0, exports.getTradeDataFromQuote)(quoteResponse, batchSellTrades),
|
|
122
125
|
chain_id_source: (0, bridge_controller_1.formatChainIdToCaip)(quote.srcChainId),
|
|
123
126
|
token_symbol_source: quote.srcAsset.symbol,
|
|
124
127
|
token_address_source: quote.srcAsset.assetId,
|
|
@@ -130,7 +133,7 @@ const getPreConfirmationPropertiesFromQuote = (quoteResponse, isStxEnabledOnClie
|
|
|
130
133
|
is_hardware_wallet: accountHardwareType !== null,
|
|
131
134
|
swap_type: (0, bridge_controller_1.getSwapType)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId),
|
|
132
135
|
usd_amount_source: Number(quoteResponse.sentAmount?.usd ?? 0),
|
|
133
|
-
stx_enabled:
|
|
136
|
+
stx_enabled: isStxEnabled,
|
|
134
137
|
action_type: bridge_controller_1.MetricsActionType.SWAPBRIDGE_V1,
|
|
135
138
|
custom_slippage: false, // TODO detect whether the user changed the default slippage
|
|
136
139
|
location,
|