@metamask/bridge-status-controller 71.2.1 → 72.0.0
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 +30 -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 +101 -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 +97 -0
- package/dist/strategy/batch-sell-strategy.mjs.map +1 -0
- package/dist/strategy/batch-strategy.cjs +64 -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 +60 -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 +223 -252
- 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 +214 -247
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,88 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.updateTransactionsInBatch = exports.findAllTransactionsInBatch = exports.getAddTransactionBatchParams = exports.toTransactionParams = exports.toQuoteAndTxMetadataBatch = exports.toQuoteAndTxMetadata = exports.waitForTxConfirmation = exports.handleMobileHardwareWalletDelay = exports.handleApprovalDelay = exports.addSyntheticTransaction = exports.generateActionId = exports.addTransaction = exports.checkIsDelegatedAccount = exports.updateTransaction = exports.getTransactionMetaByHash = exports.getTransactionMetaById = exports.getTransactions = exports.getGasFeeEstimates = exports.hasNestedSwapTransactions = exports.shouldDisable7702 = exports.is7702Tx = exports.isCrossChainTx = exports.isTradeTx = exports.isApprovalTx = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
5
5
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
6
6
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
7
7
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
8
8
|
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
10
9
|
const constants_1 = require("../constants.cjs");
|
|
11
10
|
const accounts_1 = require("./accounts.cjs");
|
|
12
11
|
const network_1 = require("./network.cjs");
|
|
13
12
|
const isApprovalTx = (type) => type === transaction_controller_1.TransactionType.bridgeApproval ||
|
|
14
13
|
type === transaction_controller_1.TransactionType.swapApproval;
|
|
14
|
+
exports.isApprovalTx = isApprovalTx;
|
|
15
15
|
const isTradeTx = (type) => type === transaction_controller_1.TransactionType.bridge || type === transaction_controller_1.TransactionType.swap;
|
|
16
|
-
|
|
16
|
+
exports.isTradeTx = isTradeTx;
|
|
17
|
+
const isCrossChainTx = (type) => (0, exports.isTradeTx)(type) || (0, exports.isApprovalTx)(type);
|
|
17
18
|
exports.isCrossChainTx = isCrossChainTx;
|
|
18
|
-
const getGasFeeEstimates = async (messenger, args) => {
|
|
19
|
-
const { estimates } = await messenger.call('TransactionController:estimateGasFee', args);
|
|
20
|
-
if (bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE in estimates &&
|
|
21
|
-
typeof estimates[bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE] === 'object' &&
|
|
22
|
-
'maxFeePerGas' in estimates[bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE] &&
|
|
23
|
-
'maxPriorityFeePerGas' in estimates[bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE]) {
|
|
24
|
-
return estimates[bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE];
|
|
25
|
-
}
|
|
26
|
-
return {};
|
|
27
|
-
};
|
|
28
|
-
exports.getGasFeeEstimates = getGasFeeEstimates;
|
|
29
19
|
/**
|
|
30
|
-
*
|
|
20
|
+
* For 7702 delegated transactions, check for delegation-specific fields
|
|
21
|
+
* These transactions might have authorizationList or delegationAddress
|
|
31
22
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @
|
|
34
|
-
|
|
35
|
-
* @returns The gas fee estimates for the transaction
|
|
23
|
+
* @param tx - The transaction meta
|
|
24
|
+
* @returns Whether the transaction is a 7702 transaction
|
|
36
25
|
*/
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
26
|
+
const is7702Tx = (tx) => {
|
|
27
|
+
return ((Array.isArray(tx.txParams.authorizationList) &&
|
|
28
|
+
tx.txParams.authorizationList.length > 0) ||
|
|
29
|
+
Boolean(tx.delegationAddress));
|
|
30
|
+
};
|
|
31
|
+
exports.is7702Tx = is7702Tx;
|
|
32
|
+
const shouldDisable7702 = (gasIncluded7702 = false, gasIncluded = false, isDelegatedAccount = false) => {
|
|
33
|
+
// Enable 7702 batching when the quote includes gasless 7702 support
|
|
34
|
+
if (gasIncluded7702) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
// Enable batching when the account is already delegated (to avoid the in-flight transaction limit for delegated accounts)
|
|
38
|
+
if (isDelegatedAccount) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// For gasless transactions with STX/sendBundle we keep disabling 7702
|
|
42
|
+
if (gasIncluded) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
44
45
|
/**
|
|
45
|
-
*
|
|
46
|
+
* Explicitly return default instead of falsy value (see TransactionBatchRequest.disable7702)
|
|
46
47
|
*/
|
|
47
|
-
|
|
48
|
-
? new bignumber_js_1.BigNumber(estimatedBaseFee, 10)
|
|
49
|
-
.times(10 ** 9)
|
|
50
|
-
.plus(maxPriorityFeePerGas, 16)
|
|
51
|
-
: undefined;
|
|
52
|
-
return {
|
|
53
|
-
baseAndPriorityFeePerGas,
|
|
54
|
-
maxFeePerGas,
|
|
55
|
-
maxPriorityFeePerGas,
|
|
56
|
-
};
|
|
48
|
+
return true;
|
|
57
49
|
};
|
|
58
|
-
exports.
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
exports.shouldDisable7702 = shouldDisable7702;
|
|
51
|
+
const hasNestedSwapTransactions = (txMeta) => {
|
|
52
|
+
return Boolean(txMeta?.nestedTransactions?.some((tx) => tx.type === transaction_controller_1.TransactionType.swap));
|
|
53
|
+
};
|
|
54
|
+
exports.hasNestedSwapTransactions = hasNestedSwapTransactions;
|
|
55
|
+
const getGasFeeEstimates = async (messenger, args) => {
|
|
56
|
+
const { estimates } = await messenger.call('TransactionController:estimateGasFee', args);
|
|
57
|
+
if (estimates?.type === transaction_controller_1.GasFeeEstimateType.FeeMarket) {
|
|
58
|
+
return estimates[bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE];
|
|
65
59
|
}
|
|
66
|
-
|
|
67
|
-
...trade,
|
|
68
|
-
gas: gasLimit?.toString(),
|
|
69
|
-
data: trade.data,
|
|
70
|
-
to: trade.to,
|
|
71
|
-
value: trade.value,
|
|
72
|
-
};
|
|
73
|
-
const { maxFeePerGas, maxPriorityFeePerGas } = await (0, exports.getTxGasEstimates)(messenger, {
|
|
74
|
-
transactionParams,
|
|
75
|
-
networkClientId,
|
|
76
|
-
chainId,
|
|
77
|
-
});
|
|
78
|
-
const maxGasLimit = (0, controller_utils_1.toHex)(transactionParams.gas ?? 0);
|
|
79
|
-
return {
|
|
80
|
-
maxFeePerGas,
|
|
81
|
-
maxPriorityFeePerGas,
|
|
82
|
-
gas: maxGasLimit,
|
|
83
|
-
};
|
|
60
|
+
return undefined;
|
|
84
61
|
};
|
|
85
|
-
exports.
|
|
62
|
+
exports.getGasFeeEstimates = getGasFeeEstimates;
|
|
86
63
|
const getTransactions = (messenger) => {
|
|
87
64
|
return messenger.call('TransactionController:getState').transactions ?? [];
|
|
88
65
|
};
|
|
@@ -200,227 +177,221 @@ const waitForTxConfirmation = async (messenger, txId, { timeoutMs = 5 * 60000, p
|
|
|
200
177
|
}
|
|
201
178
|
};
|
|
202
179
|
exports.waitForTxConfirmation = waitForTxConfirmation;
|
|
203
|
-
const
|
|
204
|
-
const
|
|
180
|
+
const toQuoteAndTxMetadata = ({ quoteResponse, isBridgeTx, }) => {
|
|
181
|
+
const tradeData = [];
|
|
182
|
+
const approvalTxType = isBridgeTx
|
|
183
|
+
? transaction_controller_1.TransactionType.bridgeApproval
|
|
184
|
+
: transaction_controller_1.TransactionType.swapApproval;
|
|
185
|
+
if (quoteResponse.resetApproval) {
|
|
186
|
+
tradeData.push({
|
|
187
|
+
quoteResponse,
|
|
188
|
+
tx: quoteResponse.resetApproval,
|
|
189
|
+
type: approvalTxType,
|
|
190
|
+
txFee: quoteResponse.quote.feeData[bridge_controller_1.FeeType.TX_FEE],
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (quoteResponse.approval && (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)) {
|
|
194
|
+
tradeData.push({
|
|
195
|
+
quoteResponse,
|
|
196
|
+
tx: quoteResponse.approval,
|
|
197
|
+
type: approvalTxType,
|
|
198
|
+
txFee: quoteResponse.quote.feeData[bridge_controller_1.FeeType.TX_FEE],
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
tradeData.push({
|
|
202
|
+
quoteResponse,
|
|
203
|
+
tx: quoteResponse.trade,
|
|
204
|
+
type: isBridgeTx ? transaction_controller_1.TransactionType.bridge : transaction_controller_1.TransactionType.swap,
|
|
205
|
+
assetsFiatValues: {
|
|
206
|
+
sending: quoteResponse.sentAmount?.valueInCurrency?.toString(),
|
|
207
|
+
receiving: quoteResponse.toTokenAmount?.valueInCurrency?.toString(),
|
|
208
|
+
},
|
|
209
|
+
txFee: quoteResponse.quote.feeData[bridge_controller_1.FeeType.TX_FEE],
|
|
210
|
+
});
|
|
211
|
+
return tradeData;
|
|
212
|
+
};
|
|
213
|
+
exports.toQuoteAndTxMetadata = toQuoteAndTxMetadata;
|
|
214
|
+
/**
|
|
215
|
+
* Build the trade+quote metadata array for the batch sell transaction
|
|
216
|
+
* This ties together the quote, the tx params and the txMeta after submission
|
|
217
|
+
*
|
|
218
|
+
* @param options - The options for the batch sell transaction
|
|
219
|
+
* @param options.quoteResponses - The quote responses for the batch sell transaction
|
|
220
|
+
* @param options.batchSellTrades - The batch sell trades for the batch sell transaction
|
|
221
|
+
* @returns The trade+quote metadata array for the batch sell transaction
|
|
222
|
+
*/
|
|
223
|
+
const toQuoteAndTxMetadataBatch = ({ quoteResponses, batchSellTrades, }) => {
|
|
224
|
+
const tradeData = [];
|
|
225
|
+
const { transactions, gasIncluded7702, gasIncluded, gasSponsored = false, } = batchSellTrades;
|
|
226
|
+
for (const transaction of transactions) {
|
|
227
|
+
const { type, maxFeePerGas, maxPriorityFeePerGas, ...tx } = transaction;
|
|
228
|
+
// Match the trade or approval tx data with the quote response
|
|
229
|
+
const matchingQuoteResponse = quoteResponses.find(({ approval, trade }) => trade?.data.toLowerCase() === tx.data.toLowerCase() ||
|
|
230
|
+
approval?.data.toLowerCase() === tx.data.toLowerCase()) ?? quoteResponses[0];
|
|
231
|
+
// Include gasIncluded and gasIncluded7702 from the gasless batch
|
|
232
|
+
const normalizedQuote = {
|
|
233
|
+
...matchingQuoteResponse,
|
|
234
|
+
quote: {
|
|
235
|
+
...matchingQuoteResponse.quote,
|
|
236
|
+
gasIncluded,
|
|
237
|
+
gasIncluded7702,
|
|
238
|
+
gasSponsored,
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
const commonTradeData = {
|
|
242
|
+
tx,
|
|
243
|
+
quoteResponse: normalizedQuote,
|
|
244
|
+
txFee: { maxFeePerGas, maxPriorityFeePerGas },
|
|
245
|
+
};
|
|
246
|
+
if (type === bridge_controller_1.BatchSellTransactionType.TRADE) {
|
|
247
|
+
tradeData.push({
|
|
248
|
+
...commonTradeData,
|
|
249
|
+
type: transaction_controller_1.TransactionType.swap,
|
|
250
|
+
assetsFiatValues: {
|
|
251
|
+
sending: matchingQuoteResponse.sentAmount?.valueInCurrency?.toString(),
|
|
252
|
+
receiving: matchingQuoteResponse.toTokenAmount?.valueInCurrency?.toString(),
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
tradeData.push({
|
|
258
|
+
...commonTradeData,
|
|
259
|
+
type: type === bridge_controller_1.BatchSellTransactionType.APPROVAL
|
|
260
|
+
? transaction_controller_1.TransactionType.swapApproval
|
|
261
|
+
: transaction_controller_1.TransactionType.tokenMethodTransfer,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return tradeData;
|
|
266
|
+
};
|
|
267
|
+
exports.toQuoteAndTxMetadataBatch = toQuoteAndTxMetadataBatch;
|
|
268
|
+
/**
|
|
269
|
+
* Appends the gas fee estimates for a transaction and normalizes the trade data
|
|
270
|
+
*
|
|
271
|
+
* @param messenger - The messenger for the gas fee estimates
|
|
272
|
+
* @param trade - the trade data to append gas fees to
|
|
273
|
+
* @param trade.chainId - ignored, use chainId instead
|
|
274
|
+
* @param trade.gasLimit - the gas limit to use for the gas fee estimates
|
|
275
|
+
* @param networkClientId - the network client ID to use for the gas fee estimates
|
|
276
|
+
* @param chainId - the chain ID to use for the gas fee estimates
|
|
277
|
+
* @param simulatedGasFeeLimits - either the txFee from the quote or the simulated gas fee limits for the batch sell
|
|
278
|
+
* @returns The gas fee estimates for the transaction
|
|
279
|
+
*/
|
|
280
|
+
const toTransactionParams = async (messenger, { chainId: tradeChainId, gasLimit, ...trade }, networkClientId, chainId, simulatedGasFeeLimits) => {
|
|
281
|
+
const normalizedTrade = {
|
|
205
282
|
...trade,
|
|
206
283
|
data: trade.data,
|
|
207
284
|
to: trade.to,
|
|
285
|
+
from: trade.from,
|
|
208
286
|
value: trade.value,
|
|
209
287
|
};
|
|
210
|
-
|
|
211
|
-
|
|
288
|
+
const transactionParams = {
|
|
289
|
+
...normalizedTrade,
|
|
290
|
+
// Only add gasLimit and gas if they're truthy
|
|
291
|
+
gas: gasLimit ? (0, controller_utils_1.toHex)(gasLimit) : undefined,
|
|
292
|
+
};
|
|
293
|
+
// Use bridge-api's provided gas fee estimates
|
|
294
|
+
if (simulatedGasFeeLimits) {
|
|
295
|
+
return {
|
|
296
|
+
...transactionParams,
|
|
297
|
+
maxFeePerGas: (0, controller_utils_1.toHex)(simulatedGasFeeLimits.maxFeePerGas),
|
|
298
|
+
maxPriorityFeePerGas: (0, controller_utils_1.toHex)(simulatedGasFeeLimits.maxPriorityFeePerGas),
|
|
299
|
+
};
|
|
212
300
|
}
|
|
301
|
+
// Get transaction's 1559 gas fee estimates
|
|
302
|
+
const gasFeeEstimates = await (0, exports.getGasFeeEstimates)(messenger, {
|
|
303
|
+
transactionParams,
|
|
304
|
+
networkClientId,
|
|
305
|
+
chainId,
|
|
306
|
+
});
|
|
213
307
|
return {
|
|
214
|
-
...
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
maxPriorityFeePerGas: (0, controller_utils_1.toHex)(maxPriorityFeePerGas ?? 0),
|
|
308
|
+
...transactionParams,
|
|
309
|
+
maxFeePerGas: gasFeeEstimates?.maxFeePerGas,
|
|
310
|
+
maxPriorityFeePerGas: gasFeeEstimates?.maxPriorityFeePerGas,
|
|
218
311
|
};
|
|
219
312
|
};
|
|
220
|
-
exports.
|
|
221
|
-
const getAddTransactionBatchParams = async ({ messenger,
|
|
222
|
-
|
|
223
|
-
const isGasless = gasIncluded || gasIncluded7702;
|
|
313
|
+
exports.toTransactionParams = toTransactionParams;
|
|
314
|
+
const getAddTransactionBatchParams = async ({ messenger, tradeData, requireApproval = false, isDelegatedAccount, ...addTransactionBatchParams }) => {
|
|
315
|
+
const trade = tradeData[0].tx;
|
|
224
316
|
const selectedAccount = (0, accounts_1.getAccountByAddress)(messenger, trade.from);
|
|
225
317
|
if (!selectedAccount) {
|
|
226
318
|
throw new Error('Failed to submit cross-chain swap batch transaction: unknown account in trade data');
|
|
227
319
|
}
|
|
228
320
|
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(trade.chainId);
|
|
229
321
|
const networkClientId = (0, network_1.getNetworkClientIdByChainId)(messenger, hexChainId);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// For gasless transactions with STX/sendBundle we keep disabling 7702.
|
|
237
|
-
if (gasIncluded && !gasIncluded7702) {
|
|
238
|
-
disable7702 = true;
|
|
239
|
-
}
|
|
240
|
-
const transactions = [];
|
|
241
|
-
if (resetApproval) {
|
|
242
|
-
const gasFees = await (0, exports.calculateGasFees)(skipGasFields, messenger, resetApproval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
243
|
-
transactions.push({
|
|
244
|
-
type: isBridgeTx
|
|
245
|
-
? transaction_controller_1.TransactionType.bridgeApproval
|
|
246
|
-
: transaction_controller_1.TransactionType.swapApproval,
|
|
247
|
-
params: (0, exports.toBatchTxParams)(skipGasFields, resetApproval, gasFees),
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
if (approval) {
|
|
251
|
-
const gasFees = await (0, exports.calculateGasFees)(skipGasFields, messenger, approval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
252
|
-
transactions.push({
|
|
253
|
-
type: isBridgeTx
|
|
254
|
-
? transaction_controller_1.TransactionType.bridgeApproval
|
|
255
|
-
: transaction_controller_1.TransactionType.swapApproval,
|
|
256
|
-
params: (0, exports.toBatchTxParams)(skipGasFields, approval, gasFees),
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
const gasFees = await (0, exports.calculateGasFees)(skipGasFields, messenger, trade, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
260
|
-
transactions.push({
|
|
261
|
-
type: isBridgeTx ? transaction_controller_1.TransactionType.bridge : transaction_controller_1.TransactionType.swap,
|
|
262
|
-
params: (0, exports.toBatchTxParams)(skipGasFields, trade, gasFees),
|
|
263
|
-
assetsFiatValues: {
|
|
264
|
-
sending: sentAmount?.valueInCurrency?.toString(),
|
|
265
|
-
receiving: toTokenAmount?.valueInCurrency?.toString(),
|
|
266
|
-
},
|
|
267
|
-
});
|
|
268
|
-
const transactionParams = {
|
|
269
|
-
disable7702,
|
|
270
|
-
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
271
|
-
isGasFeeSponsored: Boolean(gasSponsored),
|
|
322
|
+
const transactions = await Promise.all(tradeData.map(async ({ tx, txFee, assetsFiatValues, type }) => ({
|
|
323
|
+
params: await (0, exports.toTransactionParams)(messenger, tx, networkClientId, hexChainId, txFee),
|
|
324
|
+
assetsFiatValues,
|
|
325
|
+
type,
|
|
326
|
+
})));
|
|
327
|
+
return {
|
|
272
328
|
networkClientId,
|
|
273
329
|
requireApproval,
|
|
274
330
|
origin: 'metamask',
|
|
275
|
-
from:
|
|
331
|
+
from: selectedAccount.address,
|
|
276
332
|
isInternal: true,
|
|
277
333
|
transactions,
|
|
334
|
+
...addTransactionBatchParams,
|
|
278
335
|
};
|
|
279
|
-
return transactionParams;
|
|
280
336
|
};
|
|
281
337
|
exports.getAddTransactionBatchParams = getAddTransactionBatchParams;
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
// For 7702 delegated transactions, check for delegation-specific fields
|
|
302
|
-
// These transactions might have authorizationList or delegationAddress
|
|
303
|
-
const is7702Transaction = (Array.isArray(tx.txParams.authorizationList) &&
|
|
304
|
-
tx.txParams.authorizationList.length > 0) ||
|
|
305
|
-
Boolean(tx.delegationAddress);
|
|
306
|
-
if (is7702Transaction) {
|
|
307
|
-
// For 7702 transactions, we need to match based on transaction type
|
|
308
|
-
// since the data field might be different (batch execute call)
|
|
309
|
-
if (isTradeTx(txType) && tx.type === transaction_controller_1.TransactionType.batch) {
|
|
310
|
-
return true;
|
|
338
|
+
const findAllTransactionsInBatch = ({ messenger, batchId, tradeData, }) => {
|
|
339
|
+
// Filter for transactions with batchId
|
|
340
|
+
const txs = (0, exports.getTransactions)(messenger).filter((tx) => tx.batchId === batchId);
|
|
341
|
+
return tradeData.map((tradeWithMetadata) => {
|
|
342
|
+
const { tx, type } = tradeWithMetadata;
|
|
343
|
+
return {
|
|
344
|
+
...tradeWithMetadata,
|
|
345
|
+
txMeta: txs.find((txMeta) => {
|
|
346
|
+
if ((0, exports.is7702Tx)(txMeta)) {
|
|
347
|
+
// For 7702 transactions, we need to match based on transaction type
|
|
348
|
+
// since the data field might be different (batch execute call)
|
|
349
|
+
if ((0, exports.isTradeTx)(type) && txMeta.type === transaction_controller_1.TransactionType.batch) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
// Also check if it's an approval transaction for 7702
|
|
353
|
+
if ((0, exports.isApprovalTx)(type) && txMeta.txParams.data === tx.data) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
311
356
|
}
|
|
312
|
-
//
|
|
313
|
-
if (
|
|
357
|
+
// Default matching logic for non-7702 transactions
|
|
358
|
+
if (txMeta.txParams.data === tx.data) {
|
|
314
359
|
return true;
|
|
315
360
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
return tx.txParams.data === txData;
|
|
319
|
-
});
|
|
320
|
-
if (txMeta) {
|
|
321
|
-
const updatedTx = { ...txMeta, type: txType };
|
|
322
|
-
(0, exports.updateTransaction)(messenger, txMeta, { type: txType }, `Update tx type to ${txType}`);
|
|
323
|
-
const txTypes = [
|
|
324
|
-
transaction_controller_1.TransactionType.bridgeApproval,
|
|
325
|
-
transaction_controller_1.TransactionType.swapApproval,
|
|
326
|
-
];
|
|
327
|
-
txBatch[txTypes.includes(txType) ? 'approvalMeta' : 'tradeMeta'] =
|
|
328
|
-
updatedTx;
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
return txBatch;
|
|
332
|
-
};
|
|
333
|
-
exports.findAndUpdateTransactionsInBatch = findAndUpdateTransactionsInBatch;
|
|
334
|
-
const addTransactionBatch = async (messenger, addTransactionBatchFn, ...args) => {
|
|
335
|
-
const txDataByType = {
|
|
336
|
-
[transaction_controller_1.TransactionType.bridgeApproval]: args[0].transactions.find(({ type }) => type === transaction_controller_1.TransactionType.bridgeApproval)?.params.data,
|
|
337
|
-
[transaction_controller_1.TransactionType.swapApproval]: args[0].transactions.find(({ type }) => type === transaction_controller_1.TransactionType.swapApproval)?.params.data,
|
|
338
|
-
[transaction_controller_1.TransactionType.bridge]: args[0].transactions.find(({ type }) => type === transaction_controller_1.TransactionType.bridge)?.params.data,
|
|
339
|
-
[transaction_controller_1.TransactionType.swap]: args[0].transactions.find(({ type }) => type === transaction_controller_1.TransactionType.swap)?.params.data,
|
|
340
|
-
};
|
|
341
|
-
const { batchId } = await addTransactionBatchFn(...args);
|
|
342
|
-
const { approvalMeta, tradeMeta } = (0, exports.findAndUpdateTransactionsInBatch)({
|
|
343
|
-
messenger,
|
|
344
|
-
batchId,
|
|
345
|
-
txDataByType,
|
|
346
|
-
});
|
|
347
|
-
if (!tradeMeta) {
|
|
348
|
-
throw new Error('Failed to update cross-chain swap transaction batch: tradeMeta not found');
|
|
349
|
-
}
|
|
350
|
-
return { approvalMeta, tradeMeta };
|
|
351
|
-
};
|
|
352
|
-
exports.addTransactionBatch = addTransactionBatch;
|
|
353
|
-
// TODO rename
|
|
354
|
-
const getGasFeesForSubmission = async (messenger, transactionParams, networkClientId, chainId, txFee) => {
|
|
355
|
-
const { gas } = transactionParams;
|
|
356
|
-
// If txFee is provided (gasIncluded case), use the quote's gas fees
|
|
357
|
-
// Convert to hex since txFee values from the quote are decimal strings
|
|
358
|
-
if (txFee) {
|
|
359
|
-
return {
|
|
360
|
-
maxFeePerGas: (0, controller_utils_1.toHex)(txFee.maxFeePerGas),
|
|
361
|
-
maxPriorityFeePerGas: (0, controller_utils_1.toHex)(txFee.maxPriorityFeePerGas),
|
|
362
|
-
gas: gas ? (0, controller_utils_1.toHex)(gas) : undefined,
|
|
361
|
+
return false;
|
|
362
|
+
}),
|
|
363
363
|
};
|
|
364
|
-
}
|
|
365
|
-
const { maxFeePerGas, maxPriorityFeePerGas } = await (0, exports.getTxGasEstimates)(messenger, {
|
|
366
|
-
transactionParams,
|
|
367
|
-
chainId,
|
|
368
|
-
networkClientId,
|
|
369
364
|
});
|
|
370
|
-
return {
|
|
371
|
-
maxFeePerGas,
|
|
372
|
-
maxPriorityFeePerGas,
|
|
373
|
-
gas: gas ? (0, controller_utils_1.toHex)(gas) : undefined,
|
|
374
|
-
};
|
|
375
365
|
};
|
|
366
|
+
exports.findAllTransactionsInBatch = findAllTransactionsInBatch;
|
|
376
367
|
/**
|
|
377
|
-
*
|
|
368
|
+
* This is a workaround to update the tx type after submission. Batch txs are submitted with
|
|
369
|
+
* the "batch" type, but we need to update to swap/bridge for display purposes.
|
|
378
370
|
*
|
|
379
|
-
* @param params - The parameters for the transaction
|
|
380
|
-
* @param params.transactionType - The type of transaction to submit
|
|
381
|
-
* @param params.trade - The trade data to confirm
|
|
382
|
-
* @param params.requireApproval - Whether to require approval for the transaction
|
|
383
|
-
* @param params.txFee - Optional gas fee parameters from the quote (used when gasIncluded is true)
|
|
384
|
-
* @param params.txFee.maxFeePerGas - The maximum fee per gas from the quote
|
|
385
|
-
* @param params.txFee.maxPriorityFeePerGas - The maximum priority fee per gas from the quote
|
|
386
|
-
* @param params.actionId - Optional actionId for pre-submission history (if not provided, one is generated)
|
|
371
|
+
* @param params - The parameters for the transaction search
|
|
387
372
|
* @param params.messenger - The messenger to use for the transaction
|
|
388
|
-
* @
|
|
373
|
+
* @param params.allTradesWithMetadata - The quote, tx data and type for each transaction in the batch
|
|
374
|
+
* @returns A list of transaction metas for each trade in the batch]
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* [
|
|
378
|
+
* {...tradeData[0], tradeMeta: TransactionMeta}
|
|
379
|
+
* {...tradeData[1], tradeMeta: TransactionMeta}
|
|
380
|
+
* {...tradeData[2], tradeMeta: TransactionMeta}
|
|
381
|
+
* {...tradeData[3], tradeMeta: TransactionMeta}
|
|
382
|
+
* ]
|
|
389
383
|
*/
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
networkClientId,
|
|
402
|
-
requireApproval,
|
|
403
|
-
type: transactionType,
|
|
404
|
-
origin: 'metamask',
|
|
405
|
-
isInternal: true,
|
|
406
|
-
};
|
|
407
|
-
// Exclude gasLimit from trade to avoid type issues (it can be null)
|
|
408
|
-
const { gasLimit: tradeGasLimit, ...tradeWithoutGasLimit } = trade;
|
|
409
|
-
const transactionParams = {
|
|
410
|
-
...tradeWithoutGasLimit,
|
|
411
|
-
chainId: hexChainId,
|
|
412
|
-
// Only add gasLimit and gas if they're valid (not undefined/null/zero)
|
|
413
|
-
...(tradeGasLimit &&
|
|
414
|
-
tradeGasLimit !== 0 && {
|
|
415
|
-
gasLimit: tradeGasLimit.toString(),
|
|
416
|
-
gas: tradeGasLimit.toString(),
|
|
417
|
-
}),
|
|
418
|
-
};
|
|
419
|
-
const transactionParamsWithMaxGas = {
|
|
420
|
-
...transactionParams,
|
|
421
|
-
...(await getGasFeesForSubmission(messenger, transactionParams, networkClientId, hexChainId, txFee)),
|
|
422
|
-
};
|
|
423
|
-
return await (0, exports.addTransaction)(messenger, transactionParamsWithMaxGas, requestOptions);
|
|
384
|
+
const updateTransactionsInBatch = ({ messenger, allTradesWithMetadata, }) => {
|
|
385
|
+
return allTradesWithMetadata.map((tradeWithMetadata) => {
|
|
386
|
+
const { txMeta, type } = tradeWithMetadata;
|
|
387
|
+
if (txMeta) {
|
|
388
|
+
// Update the tx type from batch to swap/bridge
|
|
389
|
+
(0, exports.updateTransaction)(messenger, txMeta, { type }, `Update tx type to ${type}`);
|
|
390
|
+
const updatedTx = { ...txMeta, type };
|
|
391
|
+
return { ...tradeWithMetadata, txMeta: updatedTx, type };
|
|
392
|
+
}
|
|
393
|
+
return tradeWithMetadata;
|
|
394
|
+
});
|
|
424
395
|
};
|
|
425
|
-
exports.
|
|
396
|
+
exports.updateTransactionsInBatch = updateTransactionsInBatch;
|
|
426
397
|
//# sourceMappingURL=transaction.cjs.map
|