@metamask/bridge-status-controller 68.1.0 → 69.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 +22 -1
- package/dist/bridge-status-controller.cjs +50 -33
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +3 -6
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +4 -3
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +4 -3
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +4 -7
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +50 -33
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/bridge-status.cjs +2 -4
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +2 -4
- package/dist/utils/bridge-status.mjs.map +1 -1
- package/dist/utils/gas.cjs +2 -2
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +1 -1
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +1 -1
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +2 -2
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/intent-api.cjs +2 -2
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +8 -7
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +8 -7
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +4 -4
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/transaction.cjs +23 -14
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +4 -2
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +4 -2
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +23 -14
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.cjs +5 -5
- package/dist/utils/validators.cjs.map +1 -1
- package/dist/utils/validators.d.cts +5 -10
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +5 -10
- package/dist/utils/validators.d.mts.map +1 -1
- package/dist/utils/validators.mjs +3 -3
- package/dist/utils/validators.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -10,9 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _IntentApiImpl_baseUrl, _IntentApiImpl_fetchFn, _IntentApiImpl_getJwt;
|
|
13
|
-
import { getClientHeaders, StatusTypes } from "@metamask/bridge-controller";
|
|
13
|
+
import { BridgeClientId, ChainId, getClientHeaders, StatusTypes } from "@metamask/bridge-controller";
|
|
14
14
|
import { TransactionStatus } from "@metamask/transaction-controller";
|
|
15
|
-
import { IntentOrderStatus,
|
|
15
|
+
import { IntentOrderStatus, validateIntentStatusResponse } from "./validators.mjs";
|
|
16
16
|
export class IntentApiImpl {
|
|
17
17
|
constructor(baseUrl, fetchFn, getJwt) {
|
|
18
18
|
_IntentApiImpl_baseUrl.set(this, void 0);
|
|
@@ -34,7 +34,7 @@ export class IntentApiImpl {
|
|
|
34
34
|
},
|
|
35
35
|
body: JSON.stringify(params),
|
|
36
36
|
});
|
|
37
|
-
if (!
|
|
37
|
+
if (!validateIntentStatusResponse(response)) {
|
|
38
38
|
throw new Error('Invalid submitOrder response');
|
|
39
39
|
}
|
|
40
40
|
return response;
|
|
@@ -54,7 +54,7 @@ export class IntentApiImpl {
|
|
|
54
54
|
method: 'GET',
|
|
55
55
|
headers: getClientHeaders({ clientId, jwt }),
|
|
56
56
|
});
|
|
57
|
-
if (!
|
|
57
|
+
if (!validateIntentStatusResponse(response)) {
|
|
58
58
|
throw new Error('Invalid getOrderStatus response');
|
|
59
59
|
}
|
|
60
60
|
return response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-api.mjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"intent-api.mjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,WAAW,EACZ,oCAAoC;AACrC,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AAErE,OAAO,EAEL,iBAAiB,EACjB,4BAA4B,EAC7B,yBAAqB;AA2BtB,MAAM,OAAO,aAAa;IAOxB,YAAY,OAAe,EAAE,OAAsB,EAAE,MAAgB;QAN5D,yCAAiB;QAEjB,yCAAwB;QAExB,wCAAkB;QAGzB,uBAAA,IAAI,0BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,0BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,MAA8B,EAC9B,QAAwB;QAExB,MAAM,QAAQ,GAAG,GAAG,uBAAA,IAAI,8BAAS,cAAc,CAAC;QAChD,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,uBAAA,IAAI,6BAAQ,MAAZ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SACP;KACF,CAAC;IAEF,OAAO;QACL,MAAM;QACN,MAAM;QACN,iBAAiB,EAAE,uCAAuC,CACxD,WAAW,CAAC,MAAM,CACnB;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,uCAAuC,CACrD,YAA+B;IAE/B,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,iBAAiB,CAAC,OAAO,CAAC;QAC/B,KAAK,iBAAiB,CAAC,SAAS;YAC9B,OAAO,iBAAiB,CAAC,SAAS,CAAC;QACrC,KAAK,iBAAiB,CAAC,SAAS,CAAC;QACjC,KAAK,iBAAiB,CAAC,SAAS;YAC9B,OAAO,iBAAiB,CAAC,SAAS,CAAC;QACrC,KAAK,iBAAiB,CAAC,MAAM,CAAC;QAC9B,KAAK,iBAAiB,CAAC,OAAO,CAAC;QAC/B,KAAK,iBAAiB,CAAC,SAAS;YAC9B,OAAO,iBAAiB,CAAC,MAAM,CAAC;QAClC;YACE,OAAO,iBAAiB,CAAC,SAAS,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import {\n BridgeClientId,\n ChainId,\n getClientHeaders,\n StatusTypes,\n} from '@metamask/bridge-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\n\nimport {\n IntentStatusResponse,\n IntentOrderStatus,\n validateIntentStatusResponse,\n} from './validators';\nimport type { FetchFunction, StatusResponse } from '../types';\n\nexport type IntentSubmissionParams = {\n srcChainId: ChainId;\n quoteId: string;\n signature: string;\n order: unknown;\n userAddress: string;\n aggregatorId: string;\n};\n\nexport type IntentApi = {\n submitIntent(\n params: IntentSubmissionParams,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse>;\n getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse>;\n};\n\nexport type GetJwtFn = () => Promise<string | undefined>;\n\nexport class IntentApiImpl implements IntentApi {\n readonly #baseUrl: string;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #getJwt: GetJwtFn;\n\n constructor(baseUrl: string, fetchFn: FetchFunction, getJwt: GetJwtFn) {\n this.#baseUrl = baseUrl;\n this.#fetchFn = fetchFn;\n this.#getJwt = getJwt;\n }\n\n async submitIntent(\n params: IntentSubmissionParams,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> {\n const endpoint = `${this.#baseUrl}/submitOrder`;\n try {\n const jwt = await this.#getJwt();\n const response = await this.#fetchFn(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...getClientHeaders({ clientId, jwt }),\n },\n body: JSON.stringify(params),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid submitOrder response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to submit intent: ${error.message}`);\n }\n throw new Error('Failed to submit intent');\n }\n }\n\n async getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> {\n const endpoint = `${this.#baseUrl}/getOrderStatus?orderId=${orderId}&aggregatorId=${encodeURIComponent(aggregatorId)}&srcChainId=${srcChainId}`;\n try {\n const jwt = await this.#getJwt();\n const response = await this.#fetchFn(endpoint, {\n method: 'GET',\n headers: getClientHeaders({ clientId, jwt }),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid getOrderStatus response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to get order status: ${error.message}`);\n }\n throw new Error('Failed to get order status');\n }\n }\n}\n\nexport type IntentBridgeStatus = {\n status: StatusResponse;\n txHash?: string;\n transactionStatus: TransactionStatus;\n};\n\nexport const translateIntentOrderToBridgeStatus = (\n intentOrder: IntentStatusResponse,\n srcChainId: number,\n fallbackTxHash?: string,\n): IntentBridgeStatus => {\n let statusType: StatusTypes;\n switch (intentOrder.status) {\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n statusType = StatusTypes.COMPLETE;\n break;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n statusType = StatusTypes.FAILED;\n break;\n case IntentOrderStatus.PENDING:\n statusType = StatusTypes.PENDING;\n break;\n case IntentOrderStatus.SUBMITTED:\n statusType = StatusTypes.SUBMITTED;\n break;\n default:\n statusType = StatusTypes.UNKNOWN;\n }\n\n const txHash = intentOrder.txHash ?? fallbackTxHash ?? '';\n const status: StatusResponse = {\n status: statusType,\n srcChain: {\n chainId: srcChainId,\n txHash,\n },\n };\n\n return {\n status,\n txHash,\n transactionStatus: mapIntentOrderStatusToTransactionStatus(\n intentOrder.status,\n ),\n };\n};\n\nexport function mapIntentOrderStatusToTransactionStatus(\n intentStatus: IntentOrderStatus,\n): TransactionStatus {\n switch (intentStatus) {\n case IntentOrderStatus.PENDING:\n case IntentOrderStatus.SUBMITTED:\n return TransactionStatus.submitted;\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n return TransactionStatus.confirmed;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n return TransactionStatus.failed;\n default:\n return TransactionStatus.submitted;\n }\n}\n"]}
|
|
@@ -207,14 +207,14 @@ const rekeyHistoryItemInState = (state, actionId, txMeta) => {
|
|
|
207
207
|
return true;
|
|
208
208
|
};
|
|
209
209
|
exports.rekeyHistoryItemInState = rekeyHistoryItemInState;
|
|
210
|
-
const toBatchTxParams = (
|
|
210
|
+
const toBatchTxParams = (skipGasFields, { chainId, gasLimit, ...trade }, { maxFeePerGas, maxPriorityFeePerGas, gas, }) => {
|
|
211
211
|
const params = {
|
|
212
212
|
...trade,
|
|
213
213
|
data: trade.data,
|
|
214
214
|
to: trade.to,
|
|
215
215
|
value: trade.value,
|
|
216
216
|
};
|
|
217
|
-
if (
|
|
217
|
+
if (skipGasFields) {
|
|
218
218
|
return params;
|
|
219
219
|
}
|
|
220
220
|
return {
|
|
@@ -225,7 +225,7 @@ const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, { maxFeeP
|
|
|
225
225
|
};
|
|
226
226
|
};
|
|
227
227
|
exports.toBatchTxParams = toBatchTxParams;
|
|
228
|
-
const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false, estimateGasFeeFn, }) => {
|
|
228
|
+
const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false, isDelegatedAccount = false, estimateGasFeeFn, }) => {
|
|
229
229
|
const isGasless = gasIncluded || gasIncluded7702;
|
|
230
230
|
const selectedAccount = messenger.call('AccountsController:getAccountByAddress', trade.from);
|
|
231
231
|
if (!selectedAccount) {
|
|
@@ -233,32 +233,35 @@ const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, r
|
|
|
233
233
|
}
|
|
234
234
|
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(trade.chainId);
|
|
235
235
|
const networkClientId = messenger.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
// Gas fields should be omitted only when gas is sponsored via 7702
|
|
237
|
+
const skipGasFields = gasIncluded7702 === true;
|
|
238
|
+
// Enable 7702 batching when the quote includes gasless 7702 support,
|
|
239
|
+
// or when the account is already delegated (to avoid the in-flight
|
|
240
|
+
// transaction limit for delegated accounts)
|
|
241
|
+
const disable7702 = !skipGasFields && !isDelegatedAccount;
|
|
239
242
|
const transactions = [];
|
|
240
243
|
if (resetApproval) {
|
|
241
|
-
const gasFees = await (0, gas_1.calculateGasFees)(
|
|
244
|
+
const gasFees = await (0, gas_1.calculateGasFees)(skipGasFields, messenger, estimateGasFeeFn, resetApproval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
242
245
|
transactions.push({
|
|
243
246
|
type: isBridgeTx
|
|
244
247
|
? transaction_controller_1.TransactionType.bridgeApproval
|
|
245
248
|
: transaction_controller_1.TransactionType.swapApproval,
|
|
246
|
-
params: (0, exports.toBatchTxParams)(
|
|
249
|
+
params: (0, exports.toBatchTxParams)(skipGasFields, resetApproval, gasFees),
|
|
247
250
|
});
|
|
248
251
|
}
|
|
249
252
|
if (approval) {
|
|
250
|
-
const gasFees = await (0, gas_1.calculateGasFees)(
|
|
253
|
+
const gasFees = await (0, gas_1.calculateGasFees)(skipGasFields, messenger, estimateGasFeeFn, approval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
251
254
|
transactions.push({
|
|
252
255
|
type: isBridgeTx
|
|
253
256
|
? transaction_controller_1.TransactionType.bridgeApproval
|
|
254
257
|
: transaction_controller_1.TransactionType.swapApproval,
|
|
255
|
-
params: (0, exports.toBatchTxParams)(
|
|
258
|
+
params: (0, exports.toBatchTxParams)(skipGasFields, approval, gasFees),
|
|
256
259
|
});
|
|
257
260
|
}
|
|
258
|
-
const gasFees = await (0, gas_1.calculateGasFees)(
|
|
261
|
+
const gasFees = await (0, gas_1.calculateGasFees)(skipGasFields, messenger, estimateGasFeeFn, trade, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
259
262
|
transactions.push({
|
|
260
263
|
type: isBridgeTx ? transaction_controller_1.TransactionType.bridge : transaction_controller_1.TransactionType.swap,
|
|
261
|
-
params: (0, exports.toBatchTxParams)(
|
|
264
|
+
params: (0, exports.toBatchTxParams)(skipGasFields, trade, gasFees),
|
|
262
265
|
assetsFiatValues: {
|
|
263
266
|
sending: sentAmount?.valueInCurrency?.toString(),
|
|
264
267
|
receiving: toTokenAmount?.valueInCurrency?.toString(),
|
|
@@ -286,6 +289,10 @@ const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionFn, batc
|
|
|
286
289
|
// This is a workaround to update the tx type after the tx is signed
|
|
287
290
|
// TODO: remove this once the tx type for batch txs is preserved in the tx controller
|
|
288
291
|
Object.entries(txDataByType).forEach(([txType, txData]) => {
|
|
292
|
+
// Skip types not present in the batch (e.g. swap entry is undefined for bridge txs)
|
|
293
|
+
if (txData === undefined) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
289
296
|
// Find transaction by batchId and either matching data or delegation characteristics
|
|
290
297
|
const txMeta = txs.find((tx) => {
|
|
291
298
|
if (tx.batchId !== batchId) {
|
|
@@ -299,12 +306,14 @@ const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionFn, batc
|
|
|
299
306
|
if (is7702Transaction) {
|
|
300
307
|
// For 7702 transactions, we need to match based on transaction type
|
|
301
308
|
// since the data field might be different (batch execute call)
|
|
302
|
-
if (txType === transaction_controller_1.TransactionType.swap
|
|
309
|
+
if ((txType === transaction_controller_1.TransactionType.swap ||
|
|
310
|
+
txType === transaction_controller_1.TransactionType.bridge) &&
|
|
303
311
|
tx.type === transaction_controller_1.TransactionType.batch) {
|
|
304
312
|
return true;
|
|
305
313
|
}
|
|
306
314
|
// Also check if it's an approval transaction for 7702
|
|
307
|
-
if (txType === transaction_controller_1.TransactionType.swapApproval
|
|
315
|
+
if ((txType === transaction_controller_1.TransactionType.swapApproval ||
|
|
316
|
+
txType === transaction_controller_1.TransactionType.bridgeApproval) &&
|
|
308
317
|
tx.txParams.data === txData) {
|
|
309
318
|
return true;
|
|
310
319
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AACA,mEAOqC;AAQrC,iEAAmD;AACnD,6EAG0C;AAM1C,2CAAsD;AACtD,+BAAkC;AAElC,mCAAyC;AACzC,uCAAyD;AAEzD,gDAAiD;AAO1C,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,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ACD,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,gDAQC","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport {\n ChainId,\n extractTradeData,\n isTronTrade,\n formatChainIdToCaip,\n formatChainIdToHex,\n isCrossChain,\n} from '@metamask/bridge-controller';\nimport type {\n Intent,\n QuoteMetadata,\n QuoteResponse,\n Trade,\n TxData,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport { createClientTransactionRequest } from './snaps';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\nimport type { BridgeStatusControllerState } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (quoteResponse: QuoteResponse) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<Trade, Trade>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = '0x1' as `0x${string}`; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n quoteResponse: Omit<QuoteResponse<Trade>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // Check for new unified interface response format first\n if ('transactionId' in snapResponse && snapResponse.transactionId) {\n hash = snapResponse.transactionId;\n } else if (\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n } else if (\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n let hexChainId;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n // TODO: Fix chain ID activity list handling for Bitcoin\n // Fallback to Ethereum mainnet for now\n hexChainId = '0x1' as `0x${string}`;\n }\n\n // Extract the transaction data for storage\n const tradeData = extractTradeData(quoteResponse.trade);\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param trade - The trade data\n * @param srcChainId - The source chain ID\n * @param selectedAccount - The selected account information\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n trade: Trade,\n srcChainId: number,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const scope = formatChainIdToCaip(srcChainId);\n\n const transactionData = extractTradeData(trade);\n\n // Tron trades need the visible flag and contract type to be included in the request options\n const options = isTronTrade(trade)\n ? {\n visible: trade.visible,\n type: trade.raw_data?.contract?.[0]?.type,\n }\n : undefined;\n\n // Use the new unified interface\n return createClientTransactionRequest(\n selectedAccount.metadata.snap?.id as string,\n transactionData,\n scope,\n selectedAccount.id,\n options,\n );\n};\n\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const { transactions } = messenger.call('TransactionController:getState');\n const meta = transactions.find((tx: TransactionMeta) => tx.id === txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\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\nexport const toBatchTxParams = (\n disable7702: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (!disable7702) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n estimateGasFeeFn,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> &\n Partial<QuoteMetadata>;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messenger.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // When an active quote has gasIncluded7702 set to true,\n // enable 7702 gasless txs for smart accounts\n const disable7702 = gasIncluded7702 !== true;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(disable7702, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n isGasFeeSponsored: Boolean(gasSponsored),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n txType === TransactionType.swap &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n txType === TransactionType.swapApproval &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\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 * @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): string {\n const historyKey = actionId ?? bridgeTxMetaId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided',\n );\n }\n return historyKey;\n}\n\n/**\n * Extracts and validates the intent data from a quote response.\n *\n * @param quoteResponse - The quote response that may contain intent data\n * @returns The intent data from the quote\n * @throws Error if the quote does not contain intent data\n */\nexport function getIntentFromQuote(\n quoteResponse: QuoteResponse & { quote: { intent?: Intent } },\n): Intent {\n const { intent } = quoteResponse.quote;\n if (!intent) {\n throw new Error('submitIntent: missing intent data');\n }\n return intent;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AACA,mEAOqC;AAQrC,iEAAmD;AACnD,6EAG0C;AAM1C,2CAAsD;AACtD,+BAAkC;AAElC,mCAAyC;AACzC,uCAAyD;AAEzD,gDAAiD;AAO1C,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAAjE,QAAA,gBAAgB,oBAAiD;AAEvE,MAAM,sBAAsB,GAAG,CAAC,aAA4B,EAAE,EAAE;IACrE,OAAO;QACL,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ;QACtC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACtC,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,UAAU;QAC1C,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW;QAC5C,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;KAC5C,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,sBAAsB,0BASjC;AAEK,MAAM,eAAe,GAAG,CAC7B,aACe,EACf,YAAqB,EAIrB,EAAE;IACF,kFAAkF;IAClF,IAAI,kBAAkB,CAAC;IACvB,IAAI,CAAC;QACH,kBAAkB,GAAG,IAAA,sCAAkB,EAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC3E,CAAC;IAAC,MAAM,CAAC;QACP,mEAAmE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AAC,CAAC;YAC9D,OAAO,CACL,CAAC,wCAAe,CAAC,cAAc,EAAE,wCAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AA/EW,QAAA,gCAAgC,oCA+E3C;AAEF;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAC3B,QAA4B,EAC5B,cAAkC;IAElC,MAAM,UAAU,GAAG,QAAQ,IAAI,cAAc,CAAC;IAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAXD,sCAWC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,aAA6D;IAE7D,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC;IACvC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,gDAQC","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport {\n ChainId,\n extractTradeData,\n isTronTrade,\n formatChainIdToCaip,\n formatChainIdToHex,\n isCrossChain,\n} from '@metamask/bridge-controller';\nimport type {\n Intent,\n QuoteMetadata,\n QuoteResponse,\n Trade,\n TxData,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport { createClientTransactionRequest } from './snaps';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\nimport type { BridgeStatusControllerState } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (quoteResponse: QuoteResponse) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<Trade, Trade>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = '0x1' as `0x${string}`; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n quoteResponse: Omit<QuoteResponse<Trade>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // Check for new unified interface response format first\n if ('transactionId' in snapResponse && snapResponse.transactionId) {\n hash = snapResponse.transactionId;\n } else if (\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n } else if (\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n let hexChainId;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n // TODO: Fix chain ID activity list handling for Bitcoin\n // Fallback to Ethereum mainnet for now\n hexChainId = '0x1' as `0x${string}`;\n }\n\n // Extract the transaction data for storage\n const tradeData = extractTradeData(quoteResponse.trade);\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param trade - The trade data\n * @param srcChainId - The source chain ID\n * @param selectedAccount - The selected account information\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n trade: Trade,\n srcChainId: number,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const scope = formatChainIdToCaip(srcChainId);\n\n const transactionData = extractTradeData(trade);\n\n // Tron trades need the visible flag and contract type to be included in the request options\n const options = isTronTrade(trade)\n ? {\n visible: trade.visible,\n type: trade.raw_data?.contract?.[0]?.type,\n }\n : undefined;\n\n // Use the new unified interface\n return createClientTransactionRequest(\n selectedAccount.metadata.snap?.id as string,\n transactionData,\n scope,\n selectedAccount.id,\n options,\n );\n};\n\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const { transactions } = messenger.call('TransactionController:getState');\n const meta = transactions.find((tx: TransactionMeta) => tx.id === txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\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\nexport const toBatchTxParams = (\n skipGasFields: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (skipGasFields) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n isDelegatedAccount = false,\n estimateGasFeeFn,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> &\n Partial<QuoteMetadata>;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messenger.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // Gas fields should be omitted only when gas is sponsored via 7702\n const skipGasFields = gasIncluded7702 === true;\n // Enable 7702 batching when the quote includes gasless 7702 support,\n // or when the account is already delegated (to avoid the in-flight\n // transaction limit for delegated accounts)\n const disable7702 = !skipGasFields && !isDelegatedAccount;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(skipGasFields, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n isGasFeeSponsored: Boolean(gasSponsored),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Skip types not present in the batch (e.g. swap entry is undefined for bridge txs)\n if (txData === undefined) {\n return;\n }\n\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n (txType === TransactionType.swap ||\n txType === TransactionType.bridge) &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n (txType === TransactionType.swapApproval ||\n txType === TransactionType.bridgeApproval) &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\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 * @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): string {\n const historyKey = actionId ?? bridgeTxMetaId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided',\n );\n }\n return historyKey;\n}\n\n/**\n * Extracts and validates the intent data from a quote response.\n *\n * @param quoteResponse - The quote response that may contain intent data\n * @returns The intent data from the quote\n * @throws Error if the quote does not contain intent data\n */\nexport function getIntentFromQuote(\n quoteResponse: QuoteResponse & { quote: { intent?: Intent } },\n): Intent {\n const { intent } = quoteResponse.quote;\n if (!intent) {\n throw new Error('submitIntent: missing intent data');\n }\n return intent;\n}\n"]}
|
|
@@ -233,12 +233,12 @@ export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerStat
|
|
|
233
233
|
id: string;
|
|
234
234
|
hash?: string;
|
|
235
235
|
}) => boolean;
|
|
236
|
-
export declare const toBatchTxParams: (
|
|
236
|
+
export declare const toBatchTxParams: (skipGasFields: boolean, { chainId, gasLimit, ...trade }: TxData, { maxFeePerGas, maxPriorityFeePerGas, gas, }: {
|
|
237
237
|
maxFeePerGas?: string | undefined;
|
|
238
238
|
maxPriorityFeePerGas?: string | undefined;
|
|
239
239
|
gas?: string | undefined;
|
|
240
240
|
}) => BatchTransactionParams;
|
|
241
|
-
export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval, estimateGasFeeFn, }: {
|
|
241
|
+
export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval, isDelegatedAccount, estimateGasFeeFn, }: {
|
|
242
242
|
messenger: BridgeStatusControllerMessenger;
|
|
243
243
|
isBridgeTx: boolean;
|
|
244
244
|
trade: TxData;
|
|
@@ -263,6 +263,7 @@ export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, app
|
|
|
263
263
|
effectiveGas?: number | undefined;
|
|
264
264
|
} | undefined;
|
|
265
265
|
requireApproval?: boolean | undefined;
|
|
266
|
+
isDelegatedAccount?: boolean | undefined;
|
|
266
267
|
}) => Promise<import("@metamask/transaction-controller").TransactionBatchRequest>;
|
|
267
268
|
export declare const findAndUpdateTransactionsInBatch: ({ messenger, updateTransactionFn, batchId, txDataByType, }: {
|
|
268
269
|
messenger: BridgeStatusControllerMessenger;
|
|
@@ -292,6 +293,7 @@ export declare const findAndUpdateTransactionsInBatch: ({ messenger, updateTrans
|
|
|
292
293
|
predictBuy?: string | undefined;
|
|
293
294
|
predictClaim?: string | undefined;
|
|
294
295
|
predictDeposit?: string | undefined;
|
|
296
|
+
predictDepositAndOrder?: string | undefined;
|
|
295
297
|
predictSell?: string | undefined;
|
|
296
298
|
predictWithdraw?: string | undefined;
|
|
297
299
|
predictRelayDeposit?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAS7E,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,aAAa,EACb,KAAK,EACL,MAAM,EACP,oCAAoC;AAErC,OAAO,EAEL,eAAe,EAChB,yCAAyC;AAC1C,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EAChB,yCAAyC;AAQ1C,OAAO,KAAK,EACV,+BAA+B,EAC/B,qBAAqB,EACtB,qBAAiB;AAClB,OAAO,KAAK,EAAE,2BAA2B,EAAE,qBAAiB;AAE5D,eAAO,MAAM,gBAAgB,cAAgD,CAAC;AAE9E,eAAO,MAAM,sBAAsB,kBAAmB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASlE,CAAC;AAEF,eAAO,MAAM,eAAe,kBACX,KAAK,cAAc,KAAK,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,GACpE,aAAa,iBACA,MAAM,KACpB,KACD,eAAe,EACf,iBAAiB,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,CA4BtE,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,iBAE7B,M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AAM,mBACD,uBAAuB,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;CAsBjF,CAAC;AAEF,eAAO,MAAM,qBAAqB,qDAE1B,MAAM;;;MAKX,QAAQ,eAAe,CAyBzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,YACxB,MAAM,UACR;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAoBF,CAAC;AAEF,eAAO,MAAM,eAAe,kBACX,OAAO,mCACW,MAAM;;;;MAMtC,sBAiBF,CAAC;AAEF,eAAO,MAAM,4BAA4B;;gBAqB3B,OAAO;WACZ,MAAM;mBACE,KAAK,aAAa,EAAE,UAAU,GAAG,OAAO,CAAC,GACtD,QAAQ,aAAa,CAAC;sBACN,OAAO,sBAAsB,SAAS,CAAC,cAAc;;;;;;;;;;;;;;;;;;;;;iFA8FxE,CAAC;AAEF,eAAO,MAAM,gCAAgC;;yBAOtB,OAAO,sBAAsB,SAAS,CAAC,iBAAiB;aACpE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuEhB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,MAAM,CAQR;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,aAAa,GAAG;IAAE,KAAK,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC5D,MAAM,CAMR"}
|
|
@@ -233,12 +233,12 @@ export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerStat
|
|
|
233
233
|
id: string;
|
|
234
234
|
hash?: string;
|
|
235
235
|
}) => boolean;
|
|
236
|
-
export declare const toBatchTxParams: (
|
|
236
|
+
export declare const toBatchTxParams: (skipGasFields: boolean, { chainId, gasLimit, ...trade }: TxData, { maxFeePerGas, maxPriorityFeePerGas, gas, }: {
|
|
237
237
|
maxFeePerGas?: string | undefined;
|
|
238
238
|
maxPriorityFeePerGas?: string | undefined;
|
|
239
239
|
gas?: string | undefined;
|
|
240
240
|
}) => BatchTransactionParams;
|
|
241
|
-
export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval, estimateGasFeeFn, }: {
|
|
241
|
+
export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval, isDelegatedAccount, estimateGasFeeFn, }: {
|
|
242
242
|
messenger: BridgeStatusControllerMessenger;
|
|
243
243
|
isBridgeTx: boolean;
|
|
244
244
|
trade: TxData;
|
|
@@ -263,6 +263,7 @@ export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, app
|
|
|
263
263
|
effectiveGas?: number | undefined;
|
|
264
264
|
} | undefined;
|
|
265
265
|
requireApproval?: boolean | undefined;
|
|
266
|
+
isDelegatedAccount?: boolean | undefined;
|
|
266
267
|
}) => Promise<import("@metamask/transaction-controller").TransactionBatchRequest>;
|
|
267
268
|
export declare const findAndUpdateTransactionsInBatch: ({ messenger, updateTransactionFn, batchId, txDataByType, }: {
|
|
268
269
|
messenger: BridgeStatusControllerMessenger;
|
|
@@ -292,6 +293,7 @@ export declare const findAndUpdateTransactionsInBatch: ({ messenger, updateTrans
|
|
|
292
293
|
predictBuy?: string | undefined;
|
|
293
294
|
predictClaim?: string | undefined;
|
|
294
295
|
predictDeposit?: string | undefined;
|
|
296
|
+
predictDepositAndOrder?: string | undefined;
|
|
295
297
|
predictSell?: string | undefined;
|
|
296
298
|
predictWithdraw?: string | undefined;
|
|
297
299
|
predictRelayDeposit?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAS7E,OAAO,KAAK,EACV,MAAM,EACN,aAAa,EACb,aAAa,EACb,KAAK,EACL,MAAM,EACP,oCAAoC;AAErC,OAAO,EAEL,eAAe,EAChB,yCAAyC;AAC1C,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EAChB,yCAAyC;AAQ1C,OAAO,KAAK,EACV,+BAA+B,EAC/B,qBAAqB,EACtB,qBAAiB;AAClB,OAAO,KAAK,EAAE,2BAA2B,EAAE,qBAAiB;AAE5D,eAAO,MAAM,gBAAgB,cAAgD,CAAC;AAE9E,eAAO,MAAM,sBAAsB,kBAAmB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASlE,CAAC;AAEF,eAAO,MAAM,eAAe,kBACX,KAAK,cAAc,KAAK,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,GACpE,aAAa,iBACA,MAAM,KACpB,KACD,eAAe,EACf,iBAAiB,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,CA4BtE,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,iBAE7B,MAAM,GACN;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAClC;IAAE,SAAS,EAAE,MAAM,CAAA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;;;MAKX,QAAQ,eAAe,CAyBzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,YACxB,MAAM,UACR;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAoBF,CAAC;AAEF,eAAO,MAAM,eAAe,kBACX,OAAO,mCACW,MAAM;;;;MAMtC,sBAiBF,CAAC;AAEF,eAAO,MAAM,4BAA4B;;gBAqB3B,OAAO;WACZ,MAAM;mBACE,KAAK,aAAa,EAAE,UAAU,GAAG,OAAO,CAAC,GACtD,QAAQ,aAAa,CAAC;sBACN,OAAO,sBAAsB,SAAS,CAAC,cAAc;;;;;;;;;;;;;;;;;;;;;iFA8FxE,CAAC;AAEF,eAAO,MAAM,gCAAgC;;yBAOtB,OAAO,sBAAsB,SAAS,CAAC,iBAAiB;aACpE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuEhB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,MAAM,CAQR;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,aAAa,GAAG;IAAE,KAAK,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC5D,MAAM,CAMR"}
|
|
@@ -195,14 +195,14 @@ export const rekeyHistoryItemInState = (state, actionId, txMeta) => {
|
|
|
195
195
|
delete state.txHistory[actionId];
|
|
196
196
|
return true;
|
|
197
197
|
};
|
|
198
|
-
export const toBatchTxParams = (
|
|
198
|
+
export const toBatchTxParams = (skipGasFields, { chainId, gasLimit, ...trade }, { maxFeePerGas, maxPriorityFeePerGas, gas, }) => {
|
|
199
199
|
const params = {
|
|
200
200
|
...trade,
|
|
201
201
|
data: trade.data,
|
|
202
202
|
to: trade.to,
|
|
203
203
|
value: trade.value,
|
|
204
204
|
};
|
|
205
|
-
if (
|
|
205
|
+
if (skipGasFields) {
|
|
206
206
|
return params;
|
|
207
207
|
}
|
|
208
208
|
return {
|
|
@@ -212,7 +212,7 @@ export const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, {
|
|
|
212
212
|
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),
|
|
213
213
|
};
|
|
214
214
|
};
|
|
215
|
-
export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false, estimateGasFeeFn, }) => {
|
|
215
|
+
export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false, isDelegatedAccount = false, estimateGasFeeFn, }) => {
|
|
216
216
|
const isGasless = gasIncluded || gasIncluded7702;
|
|
217
217
|
const selectedAccount = messenger.call('AccountsController:getAccountByAddress', trade.from);
|
|
218
218
|
if (!selectedAccount) {
|
|
@@ -220,32 +220,35 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
220
220
|
}
|
|
221
221
|
const hexChainId = formatChainIdToHex(trade.chainId);
|
|
222
222
|
const networkClientId = messenger.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
// Gas fields should be omitted only when gas is sponsored via 7702
|
|
224
|
+
const skipGasFields = gasIncluded7702 === true;
|
|
225
|
+
// Enable 7702 batching when the quote includes gasless 7702 support,
|
|
226
|
+
// or when the account is already delegated (to avoid the in-flight
|
|
227
|
+
// transaction limit for delegated accounts)
|
|
228
|
+
const disable7702 = !skipGasFields && !isDelegatedAccount;
|
|
226
229
|
const transactions = [];
|
|
227
230
|
if (resetApproval) {
|
|
228
|
-
const gasFees = await calculateGasFees(
|
|
231
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, estimateGasFeeFn, resetApproval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
229
232
|
transactions.push({
|
|
230
233
|
type: isBridgeTx
|
|
231
234
|
? TransactionType.bridgeApproval
|
|
232
235
|
: TransactionType.swapApproval,
|
|
233
|
-
params: toBatchTxParams(
|
|
236
|
+
params: toBatchTxParams(skipGasFields, resetApproval, gasFees),
|
|
234
237
|
});
|
|
235
238
|
}
|
|
236
239
|
if (approval) {
|
|
237
|
-
const gasFees = await calculateGasFees(
|
|
240
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, estimateGasFeeFn, approval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
238
241
|
transactions.push({
|
|
239
242
|
type: isBridgeTx
|
|
240
243
|
? TransactionType.bridgeApproval
|
|
241
244
|
: TransactionType.swapApproval,
|
|
242
|
-
params: toBatchTxParams(
|
|
245
|
+
params: toBatchTxParams(skipGasFields, approval, gasFees),
|
|
243
246
|
});
|
|
244
247
|
}
|
|
245
|
-
const gasFees = await calculateGasFees(
|
|
248
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, estimateGasFeeFn, trade, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
246
249
|
transactions.push({
|
|
247
250
|
type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,
|
|
248
|
-
params: toBatchTxParams(
|
|
251
|
+
params: toBatchTxParams(skipGasFields, trade, gasFees),
|
|
249
252
|
assetsFiatValues: {
|
|
250
253
|
sending: sentAmount?.valueInCurrency?.toString(),
|
|
251
254
|
receiving: toTokenAmount?.valueInCurrency?.toString(),
|
|
@@ -272,6 +275,10 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
272
275
|
// This is a workaround to update the tx type after the tx is signed
|
|
273
276
|
// TODO: remove this once the tx type for batch txs is preserved in the tx controller
|
|
274
277
|
Object.entries(txDataByType).forEach(([txType, txData]) => {
|
|
278
|
+
// Skip types not present in the batch (e.g. swap entry is undefined for bridge txs)
|
|
279
|
+
if (txData === undefined) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
275
282
|
// Find transaction by batchId and either matching data or delegation characteristics
|
|
276
283
|
const txMeta = txs.find((tx) => {
|
|
277
284
|
if (tx.batchId !== batchId) {
|
|
@@ -285,12 +292,14 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
285
292
|
if (is7702Transaction) {
|
|
286
293
|
// For 7702 transactions, we need to match based on transaction type
|
|
287
294
|
// since the data field might be different (batch execute call)
|
|
288
|
-
if (txType === TransactionType.swap
|
|
295
|
+
if ((txType === TransactionType.swap ||
|
|
296
|
+
txType === TransactionType.bridge) &&
|
|
289
297
|
tx.type === TransactionType.batch) {
|
|
290
298
|
return true;
|
|
291
299
|
}
|
|
292
300
|
// Also check if it's an approval transaction for 7702
|
|
293
|
-
if (txType === TransactionType.swapApproval
|
|
301
|
+
if ((txType === TransactionType.swapApproval ||
|
|
302
|
+
txType === TransactionType.bridgeApproval) &&
|
|
294
303
|
tx.txParams.data === txData) {
|
|
295
304
|
return true;
|
|
296
305
|
}
|