@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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BatchSellTradesResponse, TxData } from "@metamask/bridge-controller";
|
|
2
|
+
import type { SubmitStrategyParams, SubmitStepResult } from "./types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Submits batch-sell transactions to the TransactionController
|
|
5
|
+
*
|
|
6
|
+
* @param args - The parameters for the transaction
|
|
7
|
+
* @yields The approvalMeta and tradeMeta for the first batch sell transaction
|
|
8
|
+
*/
|
|
9
|
+
export declare function submitBatchSellHandler(args: SubmitStrategyParams<TxData, BatchSellTradesResponse>): AsyncGenerator<SubmitStepResult, void, void>;
|
|
10
|
+
//# sourceMappingURL=batch-sell-strategy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,oCAAoC;AAiB9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAMtE;;;;;GAKG;AACH,wBAAuB,sBAAsB,CAC3C,IAAI,EAAE,oBAAoB,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC1D,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CAsH9C"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
|
+
import { findAllTransactionsInBatch, getAddTransactionBatchParams, hasNestedSwapTransactions, is7702Tx, isTradeTx, shouldDisable7702, toQuoteAndTxMetadataBatch } from "../utils/transaction.mjs";
|
|
3
|
+
import { SubmitStep } from "./types.mjs";
|
|
4
|
+
const getHistoryKeyForQuote = ({ quoteResponse: { quoteId, quote }, }) => quoteId ?? quote.requestId;
|
|
5
|
+
/**
|
|
6
|
+
* Submits batch-sell transactions to the TransactionController
|
|
7
|
+
*
|
|
8
|
+
* @param args - The parameters for the transaction
|
|
9
|
+
* @yields The approvalMeta and tradeMeta for the first batch sell transaction
|
|
10
|
+
*/
|
|
11
|
+
export async function* submitBatchSellHandler(args) {
|
|
12
|
+
const { requireApproval, quoteResponses, messenger, addTransactionBatchFn, isDelegatedAccount, batchSellTrades, } = args;
|
|
13
|
+
const tradeData = toQuoteAndTxMetadataBatch({
|
|
14
|
+
quoteResponses,
|
|
15
|
+
batchSellTrades,
|
|
16
|
+
});
|
|
17
|
+
const { gasIncluded7702, gasIncluded, gasSponsored } = batchSellTrades;
|
|
18
|
+
const gasFeeToken = tradeData.find(({ type }) => type === TransactionType.tokenMethodTransfer)?.tx.to;
|
|
19
|
+
const transactionParams = await getAddTransactionBatchParams({
|
|
20
|
+
messenger,
|
|
21
|
+
tradeData,
|
|
22
|
+
requireApproval,
|
|
23
|
+
isDelegatedAccount,
|
|
24
|
+
// Tx success/failure is independent of other txs in the batch
|
|
25
|
+
atomic: false,
|
|
26
|
+
disable7702: shouldDisable7702(gasIncluded7702, gasIncluded, isDelegatedAccount),
|
|
27
|
+
isGasFeeSponsored: gasSponsored,
|
|
28
|
+
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
29
|
+
skipInitialGasEstimate: false,
|
|
30
|
+
excludeNativeTokenForFee: Boolean(gasFeeToken),
|
|
31
|
+
});
|
|
32
|
+
// Submit the batch to the TransactionController
|
|
33
|
+
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
34
|
+
// Find all batch transaction metas and add them to history
|
|
35
|
+
const allTradesInBatch = findAllTransactionsInBatch({
|
|
36
|
+
messenger,
|
|
37
|
+
batchId,
|
|
38
|
+
tradeData,
|
|
39
|
+
}).filter((metadata) => isTradeTx(metadata.type) && metadata.txMeta !== undefined);
|
|
40
|
+
// This is either the delegation tx or the first STX swap in the batch
|
|
41
|
+
const firstTradeWithMetadata = allTradesInBatch.find(({ txMeta }) => txMeta?.type &&
|
|
42
|
+
(isTradeTx(txMeta.type) || hasNestedSwapTransactions(txMeta)));
|
|
43
|
+
const firstTradeMeta = firstTradeWithMetadata?.txMeta;
|
|
44
|
+
if (!firstTradeMeta) {
|
|
45
|
+
throw new Error('Failed to add BatchSell trade to history: txMeta not found');
|
|
46
|
+
}
|
|
47
|
+
// Nested/7702 batch
|
|
48
|
+
if (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta)) {
|
|
49
|
+
const quoteIds = Array.from(new Set(allTradesInBatch.map(getHistoryKeyForQuote)));
|
|
50
|
+
// Create 1 history item for the parent tx, keyed by the txMeta.id
|
|
51
|
+
yield {
|
|
52
|
+
type: SubmitStep.AddHistoryItem,
|
|
53
|
+
payload: {
|
|
54
|
+
historyKey: firstTradeMeta.id,
|
|
55
|
+
quoteResponse: firstTradeWithMetadata.quoteResponse,
|
|
56
|
+
batchSellData: batchSellTrades,
|
|
57
|
+
quoteIds,
|
|
58
|
+
bridgeTxMeta: firstTradeMeta,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
// Then create a new history item for each nested trade, keyed by quoteId/requestId
|
|
62
|
+
for (const tradeWithMetadata of allTradesInBatch) {
|
|
63
|
+
const { quoteResponse } = tradeWithMetadata;
|
|
64
|
+
yield {
|
|
65
|
+
type: SubmitStep.AddHistoryItem,
|
|
66
|
+
payload: {
|
|
67
|
+
historyKey: getHistoryKeyForQuote(tradeWithMetadata),
|
|
68
|
+
quoteResponse,
|
|
69
|
+
batchSellData: batchSellTrades,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// Each trade has its own txMeta if not submitted via 7702
|
|
76
|
+
// Create a new history item for each one, keyed by txMeta.id
|
|
77
|
+
// Note that the approvalTxId is not tracked in history
|
|
78
|
+
for (const { txMeta, quoteResponse } of allTradesInBatch) {
|
|
79
|
+
yield {
|
|
80
|
+
type: SubmitStep.AddHistoryItem,
|
|
81
|
+
payload: {
|
|
82
|
+
historyKey: txMeta.id,
|
|
83
|
+
quoteResponse,
|
|
84
|
+
batchSellData: batchSellTrades,
|
|
85
|
+
bridgeTxMeta: txMeta,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
yield {
|
|
91
|
+
type: SubmitStep.SetTradeMeta,
|
|
92
|
+
payload: {
|
|
93
|
+
tradeMeta: firstTradeMeta,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=batch-sell-strategy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EAChB,yCAAyC;AAG1C,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,yBAAyB,EAC1B,iCAA6B;AAC9B,OAAO,EAAE,UAAU,EAAE,oBAAgB;AAGrC,MAAM,qBAAqB,GAAG,CAAC,EAC7B,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GACd,EAAU,EAAE,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAC3C,IAA2D;IAE3D,MAAM,EACJ,eAAe,EACf,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,GAChB,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,yBAAyB,CAAC;QAC1C,cAAc;QACd,eAAe;KAChB,CAAC,CAAC;IAEH,MAAM,EAAE,eAAe,EAAE,W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AAS,EAAE,cAAc;SAC1B;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { BatchSellTradesResponse, TxData } from '@metamask/bridge-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { QuoteAndTxMetadata } from '../types';\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n hasNestedSwapTransactions,\n is7702Tx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadataBatch,\n} from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\nconst getHistoryKeyForQuote = ({\n quoteResponse: { quoteId, quote },\n}: QuoteAndTxMetadata): string => quoteId ?? quote.requestId;\n\n/**\n * Submits batch-sell transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @yields The approvalMeta and tradeMeta for the first batch sell transaction\n */\nexport async function* submitBatchSellHandler(\n args: SubmitStrategyParams<TxData, BatchSellTradesResponse>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n requireApproval,\n quoteResponses,\n messenger,\n addTransactionBatchFn,\n isDelegatedAccount,\n batchSellTrades,\n } = args;\n\n const tradeData = toQuoteAndTxMetadataBatch({\n quoteResponses,\n batchSellTrades,\n });\n\n const { gasIncluded7702, gasIncluded, gasSponsored } = batchSellTrades;\n\n const gasFeeToken = tradeData.find(\n ({ type }) => type === TransactionType.tokenMethodTransfer,\n )?.tx.to;\n\n const transactionParams = await getAddTransactionBatchParams({\n messenger,\n tradeData,\n requireApproval,\n isDelegatedAccount,\n // Tx success/failure is independent of other txs in the batch\n atomic: false,\n disable7702: shouldDisable7702(\n gasIncluded7702,\n gasIncluded,\n isDelegatedAccount,\n ),\n isGasFeeSponsored: gasSponsored,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n skipInitialGasEstimate: false,\n excludeNativeTokenForFee: Boolean(gasFeeToken),\n });\n\n // Submit the batch to the TransactionController\n const { batchId } = await addTransactionBatchFn(transactionParams);\n\n // Find all batch transaction metas and add them to history\n const allTradesInBatch = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n }).filter(\n (metadata): metadata is QuoteAndTxMetadata & { txMeta: TransactionMeta } =>\n isTradeTx(metadata.type) && metadata.txMeta !== undefined,\n );\n\n // This is either the delegation tx or the first STX swap in the batch\n const firstTradeWithMetadata = allTradesInBatch.find(\n ({ txMeta }) =>\n txMeta?.type &&\n (isTradeTx(txMeta.type) || hasNestedSwapTransactions(txMeta)),\n );\n const firstTradeMeta = firstTradeWithMetadata?.txMeta;\n if (!firstTradeMeta) {\n throw new Error(\n 'Failed to add BatchSell trade to history: txMeta not found',\n );\n }\n\n // Nested/7702 batch\n if (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta)) {\n const quoteIds = Array.from(\n new Set(allTradesInBatch.map(getHistoryKeyForQuote)),\n );\n\n // Create 1 history item for the parent tx, keyed by the txMeta.id\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: firstTradeMeta.id,\n quoteResponse: firstTradeWithMetadata.quoteResponse,\n batchSellData: batchSellTrades,\n quoteIds,\n bridgeTxMeta: firstTradeMeta,\n },\n };\n // Then create a new history item for each nested trade, keyed by quoteId/requestId\n for (const tradeWithMetadata of allTradesInBatch) {\n const { quoteResponse } = tradeWithMetadata;\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: getHistoryKeyForQuote(tradeWithMetadata),\n quoteResponse,\n batchSellData: batchSellTrades,\n },\n };\n }\n } else {\n // Each trade has its own txMeta if not submitted via 7702\n // Create a new history item for each one, keyed by txMeta.id\n // Note that the approvalTxId is not tracked in history\n for (const { txMeta, quoteResponse } of allTradesInBatch) {\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: txMeta.id,\n quoteResponse,\n batchSellData: batchSellTrades,\n bridgeTxMeta: txMeta,\n },\n };\n }\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: firstTradeMeta,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.submitBatchHandler = void 0;
|
|
4
|
+
const transaction_1 = require("../utils/transaction.cjs");
|
|
5
|
+
const types_1 = require("./types.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Submits batched EVM transactions to the TransactionController
|
|
8
|
+
*
|
|
9
|
+
* @param args - The parameters for the transaction
|
|
10
|
+
* @yields The approvalMeta and tradeMeta for the batched transaction
|
|
11
|
+
*/
|
|
12
|
+
async function* submitBatchHandler(args) {
|
|
13
|
+
const { requireApproval, quoteResponses: [quoteResponse], messenger, isBridgeTx, addTransactionBatchFn, isDelegatedAccount, } = args;
|
|
14
|
+
const tradeData = (0, transaction_1.toQuoteAndTxMetadata)({
|
|
15
|
+
quoteResponse,
|
|
16
|
+
isBridgeTx,
|
|
17
|
+
});
|
|
18
|
+
const transactionParams = await (0, transaction_1.getAddTransactionBatchParams)({
|
|
19
|
+
tradeData,
|
|
20
|
+
requireApproval,
|
|
21
|
+
isDelegatedAccount,
|
|
22
|
+
messenger,
|
|
23
|
+
atomic: true,
|
|
24
|
+
disable7702: (0, transaction_1.shouldDisable7702)(quoteResponse.quote.gasIncluded7702, quoteResponse.quote.gasIncluded, isDelegatedAccount),
|
|
25
|
+
isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),
|
|
26
|
+
isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),
|
|
27
|
+
});
|
|
28
|
+
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
29
|
+
const quoteAndTxMetas = (0, transaction_1.findAllTransactionsInBatch)({
|
|
30
|
+
messenger,
|
|
31
|
+
batchId,
|
|
32
|
+
tradeData,
|
|
33
|
+
});
|
|
34
|
+
yield {
|
|
35
|
+
type: types_1.SubmitStep.UpdateBatchTransactions,
|
|
36
|
+
payload: {
|
|
37
|
+
quoteAndTxMetas,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const tradeMeta = quoteAndTxMetas.find(({ type, txMeta }) => (0, transaction_1.isTradeTx)(type) && txMeta)?.txMeta;
|
|
41
|
+
const approvalMeta = quoteAndTxMetas.find(({ type, txMeta }) => (0, transaction_1.isApprovalTx)(type) && txMeta)?.txMeta;
|
|
42
|
+
if (!tradeMeta) {
|
|
43
|
+
throw new Error('Failed to update cross-chain swap transaction batch: tradeMeta not found');
|
|
44
|
+
}
|
|
45
|
+
yield {
|
|
46
|
+
type: types_1.SubmitStep.SetTradeMeta,
|
|
47
|
+
payload: { tradeMeta },
|
|
48
|
+
};
|
|
49
|
+
yield {
|
|
50
|
+
type: types_1.SubmitStep.AddHistoryItem,
|
|
51
|
+
payload: {
|
|
52
|
+
historyKey: tradeMeta.id,
|
|
53
|
+
approvalTxId: approvalMeta?.id,
|
|
54
|
+
bridgeTxMeta: {
|
|
55
|
+
id: tradeMeta.id,
|
|
56
|
+
hash: tradeMeta.hash,
|
|
57
|
+
batchId: tradeMeta.batchId,
|
|
58
|
+
},
|
|
59
|
+
quoteResponse,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.submitBatchHandler = submitBatchHandler;
|
|
64
|
+
//# sourceMappingURL=batch-strategy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":";;;AAEA,0DAO8B;AAC9B,uCAAqC;AAGrC;;;;;GAKG;AACI,KAAK,SAAS,CAAC,CAAC,kBAAkB,CACvC,IAAkC;IAElC,MAAM,EACJ,eAAe,EACf,cAAc,EAAE,CAAC,aAAa,CAAC,EAC/B,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,kBAAkB,GACnB,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,IAAA,kCAAoB,EAAC;QACrC,aAAa;QACb,UAA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;IAEF,MAAM;QACJ,IAAI,EAAE,kBAAU,CAAC,cAAc;QAC/B,OAAO,EAAE;YACP,UAAU,EAAE,SAAS,CAAC,EAAE;YACxB,YAAY,EAAE,YAAY,EAAE,EAAE;YAC9B,YAAY,EAAE;gBACZ,EAAE,EAAE,SAAS,CAAC,EAAE;gBAChB,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,OAAO,EAAE,SAAS,CAAC,OAAO;aAC3B;YACD,aAAa;SACd;KACF,CAAC;AACJ,CAAC;AA/ED,gDA+EC","sourcesContent":["import type { TxData } from '@metamask/bridge-controller';\n\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n isApprovalTx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadata,\n} from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\n/**\n * Submits batched EVM transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @yields The approvalMeta and tradeMeta for the batched transaction\n */\nexport async function* submitBatchHandler(\n args: SubmitStrategyParams<TxData>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n requireApproval,\n quoteResponses: [quoteResponse],\n messenger,\n isBridgeTx,\n addTransactionBatchFn,\n isDelegatedAccount,\n } = args;\n\n const tradeData = toQuoteAndTxMetadata({\n quoteResponse,\n isBridgeTx,\n });\n\n const transactionParams = await getAddTransactionBatchParams({\n tradeData,\n requireApproval,\n isDelegatedAccount,\n messenger,\n atomic: true,\n disable7702: shouldDisable7702(\n quoteResponse.quote.gasIncluded7702,\n quoteResponse.quote.gasIncluded,\n isDelegatedAccount,\n ),\n isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),\n isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),\n });\n\n const { batchId } = await addTransactionBatchFn(transactionParams);\n\n const quoteAndTxMetas = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n });\n\n yield {\n type: SubmitStep.UpdateBatchTransactions,\n payload: {\n quoteAndTxMetas,\n },\n };\n\n const tradeMeta = quoteAndTxMetas.find(\n ({ type, txMeta }) => isTradeTx(type) && txMeta,\n )?.txMeta;\n\n const approvalMeta = quoteAndTxMetas.find(\n ({ type, txMeta }) => isApprovalTx(type) && txMeta,\n )?.txMeta;\n\n if (!tradeMeta) {\n throw new Error(\n 'Failed to update cross-chain swap transaction batch: tradeMeta not found',\n );\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: { tradeMeta },\n };\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: tradeMeta.id,\n approvalTxId: approvalMeta?.id,\n bridgeTxMeta: {\n id: tradeMeta.id,\n hash: tradeMeta.hash,\n batchId: tradeMeta.batchId,\n },\n quoteResponse,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TxData } from "@metamask/bridge-controller";
|
|
2
|
+
import type { SubmitStrategyParams, SubmitStepResult } from "./types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Submits batched EVM transactions to the TransactionController
|
|
5
|
+
*
|
|
6
|
+
* @param args - The parameters for the transaction
|
|
7
|
+
* @yields The approvalMeta and tradeMeta for the batched transaction
|
|
8
|
+
*/
|
|
9
|
+
export declare function submitBatchHandler(args: SubmitStrategyParams<TxData>): AsyncGenerator<SubmitStepResult, void, void>;
|
|
10
|
+
//# sourceMappingURL=batch-strategy.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-strategy.d.cts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAW1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAEtE;;;;;GAKG;AACH,wBAAuB,kBAAkB,CACvC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACjC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CA6E9C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TxData } from "@metamask/bridge-controller";
|
|
2
|
+
import type { SubmitStrategyParams, SubmitStepResult } from "./types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Submits batched EVM transactions to the TransactionController
|
|
5
|
+
*
|
|
6
|
+
* @param args - The parameters for the transaction
|
|
7
|
+
* @yields The approvalMeta and tradeMeta for the batched transaction
|
|
8
|
+
*/
|
|
9
|
+
export declare function submitBatchHandler(args: SubmitStrategyParams<TxData>): AsyncGenerator<SubmitStepResult, void, void>;
|
|
10
|
+
//# sourceMappingURL=batch-strategy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAW1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAEtE;;;;;GAKG;AACH,wBAAuB,kBAAkB,CACvC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACjC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CA6E9C"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { findAllTransactionsInBatch, getAddTransactionBatchParams, isApprovalTx, isTradeTx, shouldDisable7702, toQuoteAndTxMetadata } from "../utils/transaction.mjs";
|
|
2
|
+
import { SubmitStep } from "./types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Submits batched EVM transactions to the TransactionController
|
|
5
|
+
*
|
|
6
|
+
* @param args - The parameters for the transaction
|
|
7
|
+
* @yields The approvalMeta and tradeMeta for the batched transaction
|
|
8
|
+
*/
|
|
9
|
+
export async function* submitBatchHandler(args) {
|
|
10
|
+
const { requireApproval, quoteResponses: [quoteResponse], messenger, isBridgeTx, addTransactionBatchFn, isDelegatedAccount, } = args;
|
|
11
|
+
const tradeData = toQuoteAndTxMetadata({
|
|
12
|
+
quoteResponse,
|
|
13
|
+
isBridgeTx,
|
|
14
|
+
});
|
|
15
|
+
const transactionParams = await getAddTransactionBatchParams({
|
|
16
|
+
tradeData,
|
|
17
|
+
requireApproval,
|
|
18
|
+
isDelegatedAccount,
|
|
19
|
+
messenger,
|
|
20
|
+
atomic: true,
|
|
21
|
+
disable7702: shouldDisable7702(quoteResponse.quote.gasIncluded7702, quoteResponse.quote.gasIncluded, isDelegatedAccount),
|
|
22
|
+
isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),
|
|
23
|
+
isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),
|
|
24
|
+
});
|
|
25
|
+
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
26
|
+
const quoteAndTxMetas = findAllTransactionsInBatch({
|
|
27
|
+
messenger,
|
|
28
|
+
batchId,
|
|
29
|
+
tradeData,
|
|
30
|
+
});
|
|
31
|
+
yield {
|
|
32
|
+
type: SubmitStep.UpdateBatchTransactions,
|
|
33
|
+
payload: {
|
|
34
|
+
quoteAndTxMetas,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const tradeMeta = quoteAndTxMetas.find(({ type, txMeta }) => isTradeTx(type) && txMeta)?.txMeta;
|
|
38
|
+
const approvalMeta = quoteAndTxMetas.find(({ type, txMeta }) => isApprovalTx(type) && txMeta)?.txMeta;
|
|
39
|
+
if (!tradeMeta) {
|
|
40
|
+
throw new Error('Failed to update cross-chain swap transaction batch: tradeMeta not found');
|
|
41
|
+
}
|
|
42
|
+
yield {
|
|
43
|
+
type: SubmitStep.SetTradeMeta,
|
|
44
|
+
payload: { tradeMeta },
|
|
45
|
+
};
|
|
46
|
+
yield {
|
|
47
|
+
type: SubmitStep.AddHistoryItem,
|
|
48
|
+
payload: {
|
|
49
|
+
historyKey: tradeMeta.id,
|
|
50
|
+
approvalTxId: approvalMeta?.id,
|
|
51
|
+
bridgeTxMeta: {
|
|
52
|
+
id: tradeMeta.id,
|
|
53
|
+
hash: tradeMeta.hash,
|
|
54
|
+
batchId: tradeMeta.batchId,
|
|
55
|
+
},
|
|
56
|
+
quoteResponse,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=batch-strategy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACrB,iCAA6B;AAC9B,OAAO,EAAE,UAAU,EAAE,oBAAgB;AAGrC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,kBAAkB,CACvC,IAAkC;IAElC,MAAM,EACJ,eAAe,EACf,cAAc,EAAE,CAAC,aAAa,CAAC,EAC/B,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,kBAAkB,GACnB,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,oBAAoB,CAAC;QACrC,aAAa;QACb,UAAU;KACX,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,MAAM,4BAA4B,CAAC;QAC3D,SAAS;QACT,eAAe;QACf,kBAAkB;QAClB,SAAS;QACT,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,iBAAiB,CAC5B,aAAa,CAAC,KAAK,CAAC,eAAe,EACnC,aAAa,CAAC,KAAK,CAAC,WAAW,EAC/B,kBAAkB,CACnB;QACD,iBAAiB,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC;QAC5D,gBAAgB,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,eAAe,CAAC;KAC/D,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IAEnE,MAAM,eAAe,GAAG,0BAA0B,CAAC;QACjD,SAAS;QACT,OAAO;QACP,SAAS;KACV,CAAC,CAAC;IAEH,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,uBAAuB;QACxC,OAAO,EAAE;YACP,eAAe;SAChB;KACF,CAAC;IAEF,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CACpC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAAM,CAChD,EAAE,MAAM,CAAC;IAEV,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CACvC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,MAAM,CACnD,EAAE,MAAM,CAAC;IAEV,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE,EAAE,SAAS,EAAE;KACvB,CAAC;IAEF,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,cAAc;QAC/B,OAAO,EAAE;YACP,UAAU,EAAE,SAAS,CAAC,EAAE;YACxB,YAAY,EAAE,YAAY,EAAE,EAAE;YAC9B,YAAY,EAAE;gBACZ,EAAE,EAAE,SAAS,CAAC,EAAE;gBAChB,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,OAAO,EAAE,SAAS,CAAC,OAAO;aAC3B;YACD,aAAa;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { TxData } from '@metamask/bridge-controller';\n\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n isApprovalTx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadata,\n} from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\n/**\n * Submits batched EVM transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @yields The approvalMeta and tradeMeta for the batched transaction\n */\nexport async function* submitBatchHandler(\n args: SubmitStrategyParams<TxData>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n requireApproval,\n quoteResponses: [quoteResponse],\n messenger,\n isBridgeTx,\n addTransactionBatchFn,\n isDelegatedAccount,\n } = args;\n\n const tradeData = toQuoteAndTxMetadata({\n quoteResponse,\n isBridgeTx,\n });\n\n const transactionParams = await getAddTransactionBatchParams({\n tradeData,\n requireApproval,\n isDelegatedAccount,\n messenger,\n atomic: true,\n disable7702: shouldDisable7702(\n quoteResponse.quote.gasIncluded7702,\n quoteResponse.quote.gasIncluded,\n isDelegatedAccount,\n ),\n isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),\n isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),\n });\n\n const { batchId } = await addTransactionBatchFn(transactionParams);\n\n const quoteAndTxMetas = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n });\n\n yield {\n type: SubmitStep.UpdateBatchTransactions,\n payload: {\n quoteAndTxMetas,\n },\n };\n\n const tradeMeta = quoteAndTxMetas.find(\n ({ type, txMeta }) => isTradeTx(type) && txMeta,\n )?.txMeta;\n\n const approvalMeta = quoteAndTxMetas.find(\n ({ type, txMeta }) => isApprovalTx(type) && txMeta,\n )?.txMeta;\n\n if (!tradeMeta) {\n throw new Error(\n 'Failed to update cross-chain swap transaction batch: tradeMeta not found',\n );\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: { tradeMeta },\n };\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: tradeMeta.id,\n approvalTxId: approvalMeta?.id,\n bridgeTxMeta: {\n id: tradeMeta.id,\n hash: tradeMeta.hash,\n batchId: tradeMeta.batchId,\n },\n quoteResponse,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.submitEvmHandler = exports.handleEvmApprovals = exports.handleSingleTx = void 0;
|
|
4
|
+
/* eslint-disable consistent-return */
|
|
5
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
6
|
+
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
7
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
8
|
+
const accounts_1 = require("../utils/accounts.cjs");
|
|
9
|
+
const network_1 = require("../utils/network.cjs");
|
|
10
|
+
const trace_1 = require("../utils/trace.cjs");
|
|
11
|
+
const transaction_1 = require("../utils/transaction.cjs");
|
|
12
|
+
const types_1 = require("./types.cjs");
|
|
13
|
+
/**
|
|
14
|
+
* Submits a single tx to the TransactionController and returns the txMetaId
|
|
15
|
+
*
|
|
16
|
+
* @param args - The parameters for the transaction
|
|
17
|
+
* @param args.transactionType - The type of transaction to submit
|
|
18
|
+
* @param args.trade - The trade data to confirm
|
|
19
|
+
* @param args.requireApproval - Whether to require approval for the transaction
|
|
20
|
+
* @param args.txFee - Optional gas fee parameters from the quote (used when gasIncluded is true)
|
|
21
|
+
* @param args.txFee.maxFeePerGas - The maximum fee per gas from the quote
|
|
22
|
+
* @param args.txFee.maxPriorityFeePerGas - The maximum priority fee per gas from the quote
|
|
23
|
+
* @param args.actionId - Optional actionId for pre-submission history (if not provided, one is generated)
|
|
24
|
+
* @param args.messenger - The messenger to use for the transaction
|
|
25
|
+
* @returns The transaction meta
|
|
26
|
+
*/
|
|
27
|
+
const handleSingleTx = async ({ messenger, trade, transactionType, requireApproval = false, txFee,
|
|
28
|
+
// Use provided actionId (for pre-submission history) or generate one
|
|
29
|
+
actionId = (0, transaction_1.generateActionId)(), }) => {
|
|
30
|
+
const selectedAccount = (0, accounts_1.getAccountByAddress)(messenger, trade.from);
|
|
31
|
+
if (!selectedAccount) {
|
|
32
|
+
throw new Error('Failed to submit cross-chain swap transaction: unknown account in trade data');
|
|
33
|
+
}
|
|
34
|
+
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(trade.chainId);
|
|
35
|
+
const networkClientId = (0, network_1.getNetworkClientIdByChainId)(messenger, hexChainId);
|
|
36
|
+
const requestOptions = {
|
|
37
|
+
actionId,
|
|
38
|
+
networkClientId,
|
|
39
|
+
requireApproval,
|
|
40
|
+
type: transactionType,
|
|
41
|
+
origin: 'metamask',
|
|
42
|
+
isInternal: true,
|
|
43
|
+
};
|
|
44
|
+
const transactionParamsWithMaxGas = await (0, transaction_1.toTransactionParams)(messenger, trade, networkClientId, hexChainId, txFee);
|
|
45
|
+
return await (0, transaction_1.addTransaction)(messenger, { ...transactionParamsWithMaxGas, from: trade.from }, requestOptions);
|
|
46
|
+
};
|
|
47
|
+
exports.handleSingleTx = handleSingleTx;
|
|
48
|
+
/**
|
|
49
|
+
* Submits the approval and resetApproval transactions through the TransactionController.
|
|
50
|
+
* If there is a resetApproval, it will be submitted first.
|
|
51
|
+
* But only the approval's txMetaId will be returned.
|
|
52
|
+
*
|
|
53
|
+
* @param args - The parameters for the submission flow
|
|
54
|
+
*
|
|
55
|
+
* @returns The approvalTxId of the approval transaction
|
|
56
|
+
*/
|
|
57
|
+
const approve = async (args) => {
|
|
58
|
+
const { quoteResponses: [quoteResponse], isBridgeTx, } = args;
|
|
59
|
+
const { approval, resetApproval } = quoteResponse;
|
|
60
|
+
if (!approval || !(0, bridge_controller_1.isEvmTxData)(approval)) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const transactionType = isBridgeTx
|
|
64
|
+
? transaction_controller_1.TransactionType.bridgeApproval
|
|
65
|
+
: transaction_controller_1.TransactionType.swapApproval;
|
|
66
|
+
if (resetApproval) {
|
|
67
|
+
await (0, exports.handleSingleTx)({
|
|
68
|
+
...args,
|
|
69
|
+
transactionType,
|
|
70
|
+
trade: resetApproval,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (approval) {
|
|
74
|
+
const approvalTxMeta = await (0, exports.handleSingleTx)({
|
|
75
|
+
...args,
|
|
76
|
+
transactionType,
|
|
77
|
+
trade: approval,
|
|
78
|
+
});
|
|
79
|
+
return approvalTxMeta?.id;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const handleEvmApprovals = async (args) => await args.traceFn((0, trace_1.getApprovalTraceParams)(args.quoteResponses[0], args.isStxEnabled), async () => await approve(args));
|
|
83
|
+
exports.handleEvmApprovals = handleEvmApprovals;
|
|
84
|
+
/**
|
|
85
|
+
* Sequentially submits EVM resetApproval, approval and trade transactions through the TransactionController.
|
|
86
|
+
*
|
|
87
|
+
* @param args - The parameters for the transaction
|
|
88
|
+
* @yields Data for updating the BridgeStatusController
|
|
89
|
+
*/
|
|
90
|
+
async function* submitEvmHandler(args) {
|
|
91
|
+
const { quoteResponses: [quoteResponse], requireApproval, isBridgeTx, } = args;
|
|
92
|
+
// Submit resetApproval and approval transactions if present
|
|
93
|
+
const approvalTxId = await (0, exports.handleEvmApprovals)(args);
|
|
94
|
+
// Delay after approval
|
|
95
|
+
if (approvalTxId) {
|
|
96
|
+
await (0, transaction_1.handleApprovalDelay)(quoteResponse.quote.srcChainId);
|
|
97
|
+
}
|
|
98
|
+
// Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
|
|
99
|
+
// on-chain approval confirmation so swap gas estimation runs after allowance is set.
|
|
100
|
+
await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
|
|
101
|
+
if (requireApproval && approvalTxId) {
|
|
102
|
+
await (0, transaction_1.waitForTxConfirmation)(args.messenger, approvalTxId);
|
|
103
|
+
}
|
|
104
|
+
// Generate trade actionId for pre-submission history
|
|
105
|
+
const actionId = (0, transaction_1.generateActionId)();
|
|
106
|
+
// Add pre-submission history keyed by actionId
|
|
107
|
+
// This ensures we have quote data available if transaction fails during submission
|
|
108
|
+
yield {
|
|
109
|
+
type: types_1.SubmitStep.AddHistoryItem,
|
|
110
|
+
payload: {
|
|
111
|
+
historyKey: actionId,
|
|
112
|
+
approvalTxId,
|
|
113
|
+
actionId,
|
|
114
|
+
quoteResponse,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
const transactionType = isBridgeTx
|
|
118
|
+
? transaction_controller_1.TransactionType.bridge
|
|
119
|
+
: transaction_controller_1.TransactionType.swap;
|
|
120
|
+
const tradeMeta = await (0, exports.handleSingleTx)({
|
|
121
|
+
...args,
|
|
122
|
+
transactionType,
|
|
123
|
+
trade: quoteResponse.trade,
|
|
124
|
+
// TODO figure out if this is needed
|
|
125
|
+
// Pass txFee when gasIncluded is true to use the quote's gas fees
|
|
126
|
+
// instead of re-estimating (which would fail for max native token swaps)
|
|
127
|
+
txFee: quoteResponse.quote.gasIncluded
|
|
128
|
+
? quoteResponse.quote.feeData.txFee
|
|
129
|
+
: undefined,
|
|
130
|
+
actionId,
|
|
131
|
+
});
|
|
132
|
+
// Use the tradeMeta's id as history key
|
|
133
|
+
yield {
|
|
134
|
+
type: types_1.SubmitStep.RekeyHistoryItem,
|
|
135
|
+
payload: {
|
|
136
|
+
oldHistoryKey: actionId,
|
|
137
|
+
newHistoryKey: tradeMeta.id,
|
|
138
|
+
tradeMeta,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
yield {
|
|
142
|
+
type: types_1.SubmitStep.SetTradeMeta,
|
|
143
|
+
payload: {
|
|
144
|
+
tradeMeta,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
exports.submitEvmHandler = submitEvmHandler;
|
|
149
|
+
//# sourceMappingURL=evm-strategy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evm-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/evm-strategy.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,qEAAqE;AACrE,mEAA8E;AAE9E,6EAG0C;AAG1C,oDAAwD;AACxD,kDAA+D;AAC/D,8CAAwD;AACxD,0DAO8B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type */\nimport { formatChainIdToHex, isEvmTxData } from '@metamask/bridge-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\nimport { getAccountByAddress } from '../utils/accounts';\nimport { getNetworkClientIdByChainId } from '../utils/network';\nimport { getApprovalTraceParams } from '../utils/trace';\nimport {\n addTransaction,\n generateActionId,\n handleApprovalDelay,\n handleMobileHardwareWalletDelay,\n toTransactionParams,\n waitForTxConfirmation,\n} from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\n/**\n * Submits a single tx to the TransactionController and returns the txMetaId\n *\n * @param args - The parameters for the transaction\n * @param args.transactionType - The type of transaction to submit\n * @param args.trade - The trade data to confirm\n * @param args.requireApproval - Whether to require approval for the transaction\n * @param args.txFee - Optional gas fee parameters from the quote (used when gasIncluded is true)\n * @param args.txFee.maxFeePerGas - The maximum fee per gas from the quote\n * @param args.txFee.maxPriorityFeePerGas - The maximum priority fee per gas from the quote\n * @param args.actionId - Optional actionId for pre-submission history (if not provided, one is generated)\n * @param args.messenger - The messenger to use for the transaction\n * @returns The transaction meta\n */\nexport const handleSingleTx = async ({\n messenger,\n trade,\n transactionType,\n requireApproval = false,\n txFee,\n // Use provided actionId (for pre-submission history) or generate one\n actionId = generateActionId(),\n}: {\n messenger: BridgeStatusControllerMessenger;\n transactionType: TransactionType;\n trade: TxData;\n requireApproval?: boolean;\n txFee?: { maxFeePerGas: string; maxPriorityFeePerGas: string };\n actionId?: string;\n}): Promise<TransactionMeta> => {\n const selectedAccount = getAccountByAddress(messenger, trade.from);\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);\n\n const requestOptions = {\n actionId,\n networkClientId,\n requireApproval,\n type: transactionType,\n origin: 'metamask',\n isInternal: true,\n };\n\n const transactionParamsWithMaxGas = await toTransactionParams(\n messenger,\n trade,\n networkClientId,\n hexChainId,\n txFee,\n );\n\n return await addTransaction(\n messenger,\n { ...transactionParamsWithMaxGas, from: trade.from },\n requestOptions,\n );\n};\n\n/**\n * Submits the approval and resetApproval transactions through the TransactionController.\n * If there is a resetApproval, it will be submitted first.\n * But only the approval's txMetaId will be returned.\n *\n * @param args - The parameters for the submission flow\n *\n * @returns The approvalTxId of the approval transaction\n */\nconst approve = async (args: SubmitStrategyParams) => {\n const {\n quoteResponses: [quoteResponse],\n isBridgeTx,\n } = args;\n const { approval, resetApproval } = quoteResponse;\n if (!approval || !isEvmTxData(approval)) {\n return undefined;\n }\n\n const transactionType = isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval;\n\n if (resetApproval) {\n await handleSingleTx({\n ...args,\n transactionType,\n trade: resetApproval,\n });\n }\n\n if (approval) {\n const approvalTxMeta = await handleSingleTx({\n ...args,\n transactionType,\n trade: approval,\n });\n return approvalTxMeta?.id;\n }\n};\n\nexport const handleEvmApprovals = async (args: SubmitStrategyParams) =>\n await args.traceFn(\n getApprovalTraceParams(args.quoteResponses[0], args.isStxEnabled),\n async () => await approve(args),\n );\n\n/**\n * Sequentially submits EVM resetApproval, approval and trade transactions through the TransactionController.\n *\n * @param args - The parameters for the transaction\n * @yields Data for updating the BridgeStatusController\n */\nexport async function* submitEvmHandler(\n args: SubmitStrategyParams<TxData>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n quoteResponses: [quoteResponse],\n requireApproval,\n isBridgeTx,\n } = args;\n\n // Submit resetApproval and approval transactions if present\n const approvalTxId = await handleEvmApprovals(args);\n\n // Delay after approval\n if (approvalTxId) {\n await handleApprovalDelay(quoteResponse.quote.srcChainId);\n }\n // Hardware-wallet delay first (Ledger second-prompt spacing), then wait for\n // on-chain approval confirmation so swap gas estimation runs after allowance is set.\n await handleMobileHardwareWalletDelay(requireApproval);\n if (requireApproval && approvalTxId) {\n await waitForTxConfirmation(args.messenger, approvalTxId);\n }\n\n // Generate trade actionId for pre-submission history\n const actionId = generateActionId();\n\n // Add pre-submission history keyed by actionId\n // This ensures we have quote data available if transaction fails during submission\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: actionId,\n approvalTxId,\n actionId,\n quoteResponse,\n },\n };\n\n const transactionType = isBridgeTx\n ? TransactionType.bridge\n : TransactionType.swap;\n\n const tradeMeta = await handleSingleTx({\n ...args,\n transactionType,\n trade: quoteResponse.trade,\n // TODO figure out if this is needed\n // Pass txFee when gasIncluded is true to use the quote's gas fees\n // instead of re-estimating (which would fail for max native token swaps)\n txFee: quoteResponse.quote.gasIncluded\n ? quoteResponse.quote.feeData.txFee\n : undefined,\n actionId,\n });\n\n // Use the tradeMeta's id as history key\n yield {\n type: SubmitStep.RekeyHistoryItem,\n payload: {\n oldHistoryKey: actionId,\n newHistoryKey: tradeMeta.id,\n tradeMeta,\n },\n };\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TxData } from "@metamask/bridge-controller";
|
|
2
|
+
import { TransactionMeta, TransactionType } from "@metamask/transaction-controller";
|
|
3
|
+
import { BridgeStatusControllerMessenger } from "../types.cjs";
|
|
4
|
+
import type { SubmitStrategyParams, SubmitStepResult } from "./types.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* Submits a single tx to the TransactionController and returns the txMetaId
|
|
7
|
+
*
|
|
8
|
+
* @param args - The parameters for the transaction
|
|
9
|
+
* @param args.transactionType - The type of transaction to submit
|
|
10
|
+
* @param args.trade - The trade data to confirm
|
|
11
|
+
* @param args.requireApproval - Whether to require approval for the transaction
|
|
12
|
+
* @param args.txFee - Optional gas fee parameters from the quote (used when gasIncluded is true)
|
|
13
|
+
* @param args.txFee.maxFeePerGas - The maximum fee per gas from the quote
|
|
14
|
+
* @param args.txFee.maxPriorityFeePerGas - The maximum priority fee per gas from the quote
|
|
15
|
+
* @param args.actionId - Optional actionId for pre-submission history (if not provided, one is generated)
|
|
16
|
+
* @param args.messenger - The messenger to use for the transaction
|
|
17
|
+
* @returns The transaction meta
|
|
18
|
+
*/
|
|
19
|
+
export declare const handleSingleTx: ({ messenger, trade, transactionType, requireApproval, txFee, actionId, }: {
|
|
20
|
+
messenger: BridgeStatusControllerMessenger;
|
|
21
|
+
transactionType: TransactionType;
|
|
22
|
+
trade: TxData;
|
|
23
|
+
requireApproval?: boolean | undefined;
|
|
24
|
+
txFee?: {
|
|
25
|
+
maxFeePerGas: string;
|
|
26
|
+
maxPriorityFeePerGas: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
actionId?: string | undefined;
|
|
29
|
+
}) => Promise<TransactionMeta>;
|
|
30
|
+
export declare const handleEvmApprovals: (args: SubmitStrategyParams) => Promise<string | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Sequentially submits EVM resetApproval, approval and trade transactions through the TransactionController.
|
|
33
|
+
*
|
|
34
|
+
* @param args - The parameters for the transaction
|
|
35
|
+
* @yields Data for updating the BridgeStatusController
|
|
36
|
+
*/
|
|
37
|
+
export declare function submitEvmHandler(args: SubmitStrategyParams<TxData>): AsyncGenerator<SubmitStepResult, void, void>;
|
|
38
|
+
//# sourceMappingURL=evm-strategy.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evm-strategy.d.cts","sourceRoot":"","sources":["../../src/strategy/evm-strategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAC1D,OAAO,EACL,eAAe,EACf,eAAe,EAChB,yCAAyC;AAE1C,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAa3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAEtE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc;;qBAUR,eAAe;WACzB,MAAM;;;sBAEW,MAAM;8BAAwB,MAAM;;;MAE1D,QAAQ,eAAe,CAgC1B,CAAC;AA2CF,eAAO,MAAM,kBAAkB,SAAgB,oBAAoB,gCAIhE,CAAC;AAEJ;;;;;GAKG;AACH,wBAAuB,gBAAgB,CACrC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACjC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CAqE9C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TxData } from "@metamask/bridge-controller";
|
|
2
|
+
import { TransactionMeta, TransactionType } from "@metamask/transaction-controller";
|
|
3
|
+
import { BridgeStatusControllerMessenger } from "../types.mjs";
|
|
4
|
+
import type { SubmitStrategyParams, SubmitStepResult } from "./types.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Submits a single tx to the TransactionController and returns the txMetaId
|
|
7
|
+
*
|
|
8
|
+
* @param args - The parameters for the transaction
|
|
9
|
+
* @param args.transactionType - The type of transaction to submit
|
|
10
|
+
* @param args.trade - The trade data to confirm
|
|
11
|
+
* @param args.requireApproval - Whether to require approval for the transaction
|
|
12
|
+
* @param args.txFee - Optional gas fee parameters from the quote (used when gasIncluded is true)
|
|
13
|
+
* @param args.txFee.maxFeePerGas - The maximum fee per gas from the quote
|
|
14
|
+
* @param args.txFee.maxPriorityFeePerGas - The maximum priority fee per gas from the quote
|
|
15
|
+
* @param args.actionId - Optional actionId for pre-submission history (if not provided, one is generated)
|
|
16
|
+
* @param args.messenger - The messenger to use for the transaction
|
|
17
|
+
* @returns The transaction meta
|
|
18
|
+
*/
|
|
19
|
+
export declare const handleSingleTx: ({ messenger, trade, transactionType, requireApproval, txFee, actionId, }: {
|
|
20
|
+
messenger: BridgeStatusControllerMessenger;
|
|
21
|
+
transactionType: TransactionType;
|
|
22
|
+
trade: TxData;
|
|
23
|
+
requireApproval?: boolean | undefined;
|
|
24
|
+
txFee?: {
|
|
25
|
+
maxFeePerGas: string;
|
|
26
|
+
maxPriorityFeePerGas: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
actionId?: string | undefined;
|
|
29
|
+
}) => Promise<TransactionMeta>;
|
|
30
|
+
export declare const handleEvmApprovals: (args: SubmitStrategyParams) => Promise<string | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Sequentially submits EVM resetApproval, approval and trade transactions through the TransactionController.
|
|
33
|
+
*
|
|
34
|
+
* @param args - The parameters for the transaction
|
|
35
|
+
* @yields Data for updating the BridgeStatusController
|
|
36
|
+
*/
|
|
37
|
+
export declare function submitEvmHandler(args: SubmitStrategyParams<TxData>): AsyncGenerator<SubmitStepResult, void, void>;
|
|
38
|
+
//# sourceMappingURL=evm-strategy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evm-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/evm-strategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAC1D,OAAO,EACL,eAAe,EACf,eAAe,EAChB,yCAAyC;AAE1C,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAa3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAEtE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc;;qBAUR,eAAe;WACzB,MAAM;;;sBAEW,MAAM;8BAAwB,MAAM;;;MAE1D,QAAQ,eAAe,CAgC1B,CAAC;AA2CF,eAAO,MAAM,kBAAkB,SAAgB,oBAAoB,gCAIhE,CAAC;AAEJ;;;;;GAKG;AACH,wBAAuB,gBAAgB,CACrC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACjC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CAqE9C"}
|