@metamask-previews/bridge-status-controller 76.4.0-preview-51ecba2 → 76.4.0-preview-b50d61887
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 +0 -14
- package/dist/bridge-status-controller.d.ts.map +1 -1
- package/dist/bridge-status-controller.js +40 -78
- package/dist/bridge-status-controller.js.map +1 -1
- package/dist/strategy/batch-sell-strategy.d.ts.map +1 -1
- package/dist/strategy/batch-sell-strategy.js +34 -62
- package/dist/strategy/batch-sell-strategy.js.map +1 -1
- package/dist/strategy/batch-strategy.d.ts.map +1 -1
- package/dist/strategy/batch-strategy.js +13 -38
- package/dist/strategy/batch-strategy.js.map +1 -1
- package/dist/strategy/evm-strategy.d.ts +28 -2
- package/dist/strategy/evm-strategy.d.ts.map +1 -1
- package/dist/strategy/evm-strategy.js +39 -62
- package/dist/strategy/evm-strategy.js.map +1 -1
- package/dist/strategy/intent-strategy.d.ts.map +1 -1
- package/dist/strategy/intent-strategy.js +1 -2
- package/dist/strategy/intent-strategy.js.map +1 -1
- package/dist/strategy/types.d.ts +2 -3
- package/dist/strategy/types.d.ts.map +1 -1
- package/dist/strategy/types.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/history.d.ts +2 -2
- package/dist/utils/history.d.ts.map +1 -1
- package/dist/utils/history.js +25 -64
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/metrics.d.ts +33 -2
- package/dist/utils/metrics.d.ts.map +1 -1
- package/dist/utils/metrics.js.map +1 -1
- package/dist/utils/transaction.d.ts +0 -2
- package/dist/utils/transaction.d.ts.map +1 -1
- package/dist/utils/transaction.js +4 -16
- package/dist/utils/transaction.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransactionType, } from '@metamask/transaction-controller';
|
|
2
2
|
import { findAllTransactionsInBatch, getAddTransactionBatchParams, hasNestedSwapTransactions, is7702Tx, isTradeTx, shouldDisable7702, toQuoteAndTxMetadataBatch, } from '../utils/transaction.js';
|
|
3
3
|
import { SubmitStep } from './types.js';
|
|
4
4
|
const getHistoryKeyForQuote = ({ quoteResponse: { quoteId, quote }, }) => quoteId ?? quote.requestId;
|
|
@@ -16,19 +16,6 @@ export async function* submitBatchSellHandler(args) {
|
|
|
16
16
|
});
|
|
17
17
|
const { gasIncluded7702, gasIncluded, gasSponsored } = batchSellTrades;
|
|
18
18
|
const gasFeeToken = tradeData.find(({ type }) => type === TransactionType.tokenMethodTransfer)?.tx.to;
|
|
19
|
-
const batchId = batchIdParam ?? generateBatchId();
|
|
20
|
-
// Create 1 history item for the parent tx or first quote, keyed by the batchId
|
|
21
|
-
yield {
|
|
22
|
-
type: SubmitStep.AddHistoryItem,
|
|
23
|
-
payload: {
|
|
24
|
-
historyKey: batchId,
|
|
25
|
-
quoteResponse: tradeData[0].quoteResponse,
|
|
26
|
-
batchSellData: batchSellTrades,
|
|
27
|
-
bridgeTxMeta: {
|
|
28
|
-
batchId,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
19
|
const transactionParams = await getAddTransactionBatchParams({
|
|
33
20
|
messenger,
|
|
34
21
|
tradeData,
|
|
@@ -39,27 +26,14 @@ export async function* submitBatchSellHandler(args) {
|
|
|
39
26
|
disable7702: shouldDisable7702(gasIncluded7702, gasIncluded, isDelegatedAccount),
|
|
40
27
|
isGasFeeSponsored: gasSponsored,
|
|
41
28
|
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
42
|
-
batchId,
|
|
29
|
+
batchId: batchIdParam,
|
|
43
30
|
skipInitialGasEstimate: gasIncluded7702
|
|
44
31
|
? isDelegatedAccount
|
|
45
32
|
: Boolean(gasFeeToken),
|
|
46
33
|
excludeNativeTokenForFee: !gasFeeToken,
|
|
47
34
|
});
|
|
48
35
|
// Submit the batch to the TransactionController
|
|
49
|
-
|
|
50
|
-
await addTransactionBatchFn(transactionParams);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
const allTradesInBatch = findAllTransactionsInBatch({
|
|
54
|
-
messenger,
|
|
55
|
-
batchId,
|
|
56
|
-
tradeData,
|
|
57
|
-
});
|
|
58
|
-
// Propagate the error if tx has not been added to the TransactionController
|
|
59
|
-
if (!allTradesInBatch.some(({ txMeta }) => txMeta)) {
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
36
|
+
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
63
37
|
// Find all batch transaction metas and add them to history
|
|
64
38
|
const allTradesInBatch = findAllTransactionsInBatch({
|
|
65
39
|
messenger,
|
|
@@ -87,48 +61,46 @@ export async function* submitBatchSellHandler(args) {
|
|
|
87
61
|
// `is7702Tx` only means the account is delegated (true even for many-tx
|
|
88
62
|
// batches), so count the unique txs instead.
|
|
89
63
|
const isSingleBatchTx = new Set(allTradesInBatch.map(({ txMeta }) => txMeta.id)).size === 1;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
64
|
+
// Nested/7702 batch
|
|
65
|
+
if (isSingleBatchTx &&
|
|
66
|
+
(is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta))) {
|
|
67
|
+
const quoteIds = Array.from(new Set(allTradesInBatch.map(getHistoryKeyForQuote)));
|
|
68
|
+
// Create 1 history item for the parent tx, keyed by the txMeta.id
|
|
69
|
+
yield {
|
|
70
|
+
type: SubmitStep.AddHistoryItem,
|
|
71
|
+
payload: {
|
|
72
|
+
historyKey: firstTradeMeta.id,
|
|
73
|
+
quoteResponse: firstTradeWithMetadata.quoteResponse,
|
|
74
|
+
batchSellData: batchSellTrades,
|
|
75
|
+
quoteIds,
|
|
76
|
+
bridgeTxMeta: firstTradeMeta,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
// Then create a new history item for each nested trade, keyed by quoteId/requestId
|
|
80
|
+
for (const tradeWithMetadata of allTradesInBatch) {
|
|
81
|
+
const { quoteResponse } = tradeWithMetadata;
|
|
104
82
|
yield {
|
|
105
|
-
type: SubmitStep.
|
|
83
|
+
type: SubmitStep.AddHistoryItem,
|
|
106
84
|
payload: {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
quote: initialTrade.quoteResponse.quote,
|
|
111
|
-
quoteIds,
|
|
112
|
-
},
|
|
113
|
-
tradeMeta: initialTrade.txMeta,
|
|
85
|
+
historyKey: getHistoryKeyForQuote(tradeWithMetadata),
|
|
86
|
+
quoteResponse,
|
|
87
|
+
batchSellData: batchSellTrades,
|
|
114
88
|
},
|
|
115
89
|
};
|
|
116
90
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
? undefined
|
|
124
|
-
: tradeWithMetadata.txMeta;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Each trade has its own txMeta if not submitted via 7702
|
|
94
|
+
// Create a new history item for each one, keyed by txMeta.id
|
|
95
|
+
// Note that the approvalTxId is not tracked in history
|
|
96
|
+
for (const { txMeta, quoteResponse } of allTradesInBatch) {
|
|
125
97
|
yield {
|
|
126
98
|
type: SubmitStep.AddHistoryItem,
|
|
127
99
|
payload: {
|
|
128
|
-
historyKey,
|
|
129
|
-
quoteResponse
|
|
100
|
+
historyKey: txMeta.id,
|
|
101
|
+
quoteResponse,
|
|
130
102
|
batchSellData: batchSellTrades,
|
|
131
|
-
bridgeTxMeta,
|
|
103
|
+
bridgeTxMeta: txMeta,
|
|
132
104
|
},
|
|
133
105
|
};
|
|
134
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sell-strategy.js","source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;gBACjC,OAAO,EAAE;oBACP,aAAa,EAAE,OAAO;oBACtB,aAAa,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE;oBACrC,oBAAoB,EAAE;wBACpB,KAAK,EAAE,YAAY,CAAC,aAAa,CAAC,KAAK;wBACvC,QAAQ;qBACT;oBACD,SAAS,EAAE,YAAY,CAAC,MAAM;iBAC/B;aACF,CAAC;QACJ,CAAC;QACD,yEAAyE;QACzE,IAAI,KAAK,GAAG,CAAC,IAAI,mBAAmB,EAAE,CAAC;YACrC,MAAM,UAAU,GAAG,mBAAmB;gBACpC,CAAC,CAAC,qBAAqB,CAAC,iBAAiB,CAAC;gBAC1C,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;YAChC,MAAM,YAAY,GAAG,mBAAmB;gBACtC,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC;YAC7B,MAAM;gBACJ,IAAI,EAAE,UAAU,CAAC,cAAc;gBAC/B,OAAO,EAAE;oBACP,UAAU;oBACV,aAAa,EAAE,iBAAiB,CAAC,aAAa;oBAC9C,aAAa,EAAE,eAAe;oBAC9B,YAAY;iBACb;aACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { BatchSellTradesResponse, TxData } from '@metamask/bridge-controller';\nimport {\n generateBatchId,\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { QuoteAndTxMetadata } from '../types.js';\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n hasNestedSwapTransactions,\n is7702Tx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadataBatch,\n} from '../utils/transaction.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\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 batchId: batchIdParam,\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 batchId = batchIdParam ?? generateBatchId();\n\n // Create 1 history item for the parent tx or first quote, keyed by the batchId\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: batchId,\n quoteResponse: tradeData[0].quoteResponse,\n batchSellData: batchSellTrades,\n bridgeTxMeta: {\n batchId,\n },\n },\n };\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 batchId,\n skipInitialGasEstimate: gasIncluded7702\n ? isDelegatedAccount\n : Boolean(gasFeeToken),\n excludeNativeTokenForFee: !gasFeeToken,\n });\n\n // Submit the batch to the TransactionController\n try {\n await addTransactionBatchFn(transactionParams);\n } catch (error) {\n const allTradesInBatch = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n });\n // Propagate the error if tx has not been added to the TransactionController\n if (!allTradesInBatch.some(({ txMeta }) => txMeta)) {\n throw error;\n }\n }\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 yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: firstTradeMeta,\n },\n };\n\n // Each quote must be reported to the reconsiler service (through QuoteStatusManager) with the hash of the tx that\n // actually executed it. So the number of distinct txs the batch produced\n // decides how quotes are tracked:\n // - one tx (atomic 7702 batch): all quotes share the single hash.\n // - many txs (e.g. STX/sendBundle): each quote has its own hash.\n // `is7702Tx` only means the account is delegated (true even for many-tx\n // batches), so count the unique txs instead.\n const isSingleBatchTx =\n new Set(allTradesInBatch.map(({ txMeta }) => txMeta.id)).size === 1;\n const isNested7702BatchTx =\n isSingleBatchTx &&\n (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta));\n\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 [index, tradeWithMetadata] of allTradesInBatch.entries()) {\n // Rekey the initial trade\n if (index === 0) {\n const quoteIds = isNested7702BatchTx\n ? Array.from(new Set(allTradesInBatch.map(getHistoryKeyForQuote)))\n : undefined;\n const initialTrade = isNested7702BatchTx\n ? firstTradeWithMetadata\n : tradeWithMetadata;\n yield {\n type: SubmitStep.RekeyHistoryItem,\n payload: {\n oldHistoryKey: batchId,\n newHistoryKey: initialTrade.txMeta.id,\n historyItemOverrides: {\n quote: initialTrade.quoteResponse.quote,\n quoteIds,\n },\n tradeMeta: initialTrade.txMeta,\n },\n };\n }\n // Create a new history item for each trade, keyed by quoteId or txMetaId\n if (index > 0 || isNested7702BatchTx) {\n const historyKey = isNested7702BatchTx\n ? getHistoryKeyForQuote(tradeWithMetadata)\n : tradeWithMetadata.txMeta.id;\n const bridgeTxMeta = isNested7702BatchTx\n ? undefined\n : tradeWithMetadata.txMeta;\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey,\n quoteResponse: tradeWithMetadata.quoteResponse,\n batchSellData: batchSellTrades,\n bridgeTxMeta,\n },\n };\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.js","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,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,EACf,OAAO,EAAE,YAAY,GACtB,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,yBAAyB,CAAC;QAC1C,cAAc;QACd,eAAe;KAChB,CAAC,CAAC;IAEH,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,eAAe,CAAC;IAEvE,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAChC,CAAC,EAAE,IAAI,EAAE,EAAE,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D;QACvD,KAAK,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,gBAAgB,EAAE,CAAC;YACzD,MAAM;gBACJ,IAAI,EAAE,UAAU,CAAC,cAAc;gBAC/B,OAAO,EAAE;oBACP,UAAU,EAAE,MAAM,CAAC,EAAE;oBACrB,aAAa;oBACb,aAAa,EAAE,eAAe;oBAC9B,YAAY,EAAE,MAAM;iBACrB;aACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { BatchSellTradesResponse, TxData } from '@metamask/bridge-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { QuoteAndTxMetadata } from '../types.js';\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n hasNestedSwapTransactions,\n is7702Tx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadataBatch,\n} from '../utils/transaction.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\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 batchId: batchIdParam,\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 batchId: batchIdParam,\n skipInitialGasEstimate: gasIncluded7702\n ? isDelegatedAccount\n : Boolean(gasFeeToken),\n excludeNativeTokenForFee: !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 yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: firstTradeMeta,\n },\n };\n\n // Each quote must be reported to the reconsiler service (through QuoteStatusManager) with the hash of the tx that\n // actually executed it. So the number of distinct txs the batch produced\n // decides how quotes are tracked:\n // - one tx (atomic 7702 batch): all quotes share the single hash.\n // - many txs (e.g. STX/sendBundle): each quote has its own hash.\n // `is7702Tx` only means the account is delegated (true even for many-tx\n // batches), so count the unique txs instead.\n const isSingleBatchTx =\n new Set(allTradesInBatch.map(({ txMeta }) => txMeta.id)).size === 1;\n\n // Nested/7702 batch\n if (\n isSingleBatchTx &&\n (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta))\n ) {\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"batch-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAW1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;GAKG;AACH,wBAAuB,kBAAkB,CACvC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACjC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CA6E9C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { generateBatchId } from '@metamask/transaction-controller';
|
|
2
1
|
import { findAllTransactionsInBatch, getAddTransactionBatchParams, isApprovalTx, isTradeTx, shouldDisable7702, toQuoteAndTxMetadata, } from '../utils/transaction.js';
|
|
3
2
|
import { SubmitStep } from './types.js';
|
|
4
3
|
/**
|
|
@@ -13,17 +12,6 @@ export async function* submitBatchHandler(args) {
|
|
|
13
12
|
quoteResponse,
|
|
14
13
|
isBridgeTx,
|
|
15
14
|
});
|
|
16
|
-
const batchId = generateBatchId();
|
|
17
|
-
yield {
|
|
18
|
-
type: SubmitStep.AddHistoryItem,
|
|
19
|
-
payload: {
|
|
20
|
-
historyKey: batchId,
|
|
21
|
-
quoteResponse,
|
|
22
|
-
bridgeTxMeta: {
|
|
23
|
-
batchId,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
15
|
const transactionParams = await getAddTransactionBatchParams({
|
|
28
16
|
tradeData,
|
|
29
17
|
requireApproval,
|
|
@@ -33,28 +21,13 @@ export async function* submitBatchHandler(args) {
|
|
|
33
21
|
disable7702: shouldDisable7702(quoteResponse.quote.gasIncluded7702, quoteResponse.quote.gasIncluded, isDelegatedAccount),
|
|
34
22
|
isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),
|
|
35
23
|
isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),
|
|
24
|
+
});
|
|
25
|
+
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
26
|
+
const quoteAndTxMetas = findAllTransactionsInBatch({
|
|
27
|
+
messenger,
|
|
36
28
|
batchId,
|
|
29
|
+
tradeData,
|
|
37
30
|
});
|
|
38
|
-
let quoteAndTxMetas = [];
|
|
39
|
-
try {
|
|
40
|
-
await addTransactionBatchFn(transactionParams);
|
|
41
|
-
quoteAndTxMetas = findAllTransactionsInBatch({
|
|
42
|
-
messenger,
|
|
43
|
-
batchId,
|
|
44
|
-
tradeData,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
quoteAndTxMetas = findAllTransactionsInBatch({
|
|
49
|
-
messenger,
|
|
50
|
-
batchId,
|
|
51
|
-
tradeData,
|
|
52
|
-
});
|
|
53
|
-
// If txMeta has not been added to the TransactionController, propagate the error
|
|
54
|
-
if (!quoteAndTxMetas.some(({ txMeta }) => txMeta)) {
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
31
|
yield {
|
|
59
32
|
type: SubmitStep.UpdateBatchTransactions,
|
|
60
33
|
payload: {
|
|
@@ -71,14 +44,16 @@ export async function* submitBatchHandler(args) {
|
|
|
71
44
|
payload: { tradeMeta },
|
|
72
45
|
};
|
|
73
46
|
yield {
|
|
74
|
-
type: SubmitStep.
|
|
47
|
+
type: SubmitStep.AddHistoryItem,
|
|
75
48
|
payload: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
49
|
+
historyKey: tradeMeta.id,
|
|
50
|
+
approvalTxId: approvalMeta?.id,
|
|
51
|
+
bridgeTxMeta: {
|
|
52
|
+
id: tradeMeta.id,
|
|
53
|
+
hash: tradeMeta.hash,
|
|
54
|
+
batchId: tradeMeta.batchId,
|
|
80
55
|
},
|
|
81
|
-
|
|
56
|
+
quoteResponse,
|
|
82
57
|
},
|
|
83
58
|
};
|
|
84
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-strategy.js","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-strategy.js","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;;GAKG;AACH,MAAM,CAAC,KAA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,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.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\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"]}
|
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
import type { TxData } from '@metamask/bridge-controller';
|
|
2
|
-
import { TransactionMeta } from '@metamask/transaction-controller';
|
|
2
|
+
import { TransactionMeta, TransactionType } from '@metamask/transaction-controller';
|
|
3
|
+
import { BridgeStatusControllerMessenger } from '../types.js';
|
|
3
4
|
import type { SubmitStrategyParams, SubmitStepResult } from './types.js';
|
|
4
|
-
|
|
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;
|
|
24
|
+
txFee?: {
|
|
25
|
+
maxFeePerGas: string;
|
|
26
|
+
maxPriorityFeePerGas: string;
|
|
27
|
+
};
|
|
28
|
+
actionId?: string;
|
|
29
|
+
}) => Promise<TransactionMeta>;
|
|
30
|
+
export declare const handleEvmApprovals: (args: SubmitStrategyParams) => Promise<string | undefined>;
|
|
5
31
|
/**
|
|
6
32
|
* Sequentially submits EVM resetApproval, approval and trade transactions through the TransactionController.
|
|
7
33
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/evm-strategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACL,eAAe,
|
|
1
|
+
{"version":3,"file":"evm-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/evm-strategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACL,eAAe,EACf,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAa9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,6EAQxB;IACD,SAAS,EAAE,+BAA+B,CAAC;IAC3C,eAAe,EAAE,eAAe,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,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"}
|
|
@@ -5,7 +5,7 @@ import { TransactionType, } from '@metamask/transaction-controller';
|
|
|
5
5
|
import { getAccountByAddress } from '../utils/accounts.js';
|
|
6
6
|
import { getNetworkClientIdByChainId } from '../utils/network.js';
|
|
7
7
|
import { getApprovalTraceParams } from '../utils/trace.js';
|
|
8
|
-
import { addTransaction, generateActionId,
|
|
8
|
+
import { addTransaction, generateActionId, handleApprovalDelay, handleMobileHardwareWalletDelay, toTransactionParams, waitForTxConfirmation, } from '../utils/transaction.js';
|
|
9
9
|
import { SubmitStep } from './types.js';
|
|
10
10
|
/**
|
|
11
11
|
* Submits a single tx to the TransactionController and returns the txMetaId
|
|
@@ -21,7 +21,7 @@ import { SubmitStep } from './types.js';
|
|
|
21
21
|
* @param args.messenger - The messenger to use for the transaction
|
|
22
22
|
* @returns The transaction meta
|
|
23
23
|
*/
|
|
24
|
-
const handleSingleTx = async ({ messenger, trade, transactionType, requireApproval = false, txFee,
|
|
24
|
+
export const handleSingleTx = async ({ messenger, trade, transactionType, requireApproval = false, txFee,
|
|
25
25
|
// Use provided actionId (for pre-submission history) or generate one
|
|
26
26
|
actionId = generateActionId(), }) => {
|
|
27
27
|
const selectedAccount = getAccountByAddress(messenger, trade.from);
|
|
@@ -47,11 +47,10 @@ actionId = generateActionId(), }) => {
|
|
|
47
47
|
* But only the approval's txMetaId will be returned.
|
|
48
48
|
*
|
|
49
49
|
* @param args - The parameters for the submission flow
|
|
50
|
-
* @param actionId - The actionId for the approval transaction
|
|
51
50
|
*
|
|
52
|
-
* @returns The
|
|
51
|
+
* @returns The approvalTxId of the approval transaction
|
|
53
52
|
*/
|
|
54
|
-
const approve = async (args
|
|
53
|
+
const approve = async (args) => {
|
|
55
54
|
const { quoteResponses: [quoteResponse], isBridgeTx, } = args;
|
|
56
55
|
const { approval, resetApproval } = quoteResponse;
|
|
57
56
|
if (!approval || !isEvmTxData(approval)) {
|
|
@@ -72,12 +71,11 @@ const approve = async (args, actionId) => {
|
|
|
72
71
|
...args,
|
|
73
72
|
transactionType,
|
|
74
73
|
trade: approval,
|
|
75
|
-
actionId,
|
|
76
74
|
});
|
|
77
|
-
return approvalTxMeta;
|
|
75
|
+
return approvalTxMeta?.id;
|
|
78
76
|
}
|
|
79
77
|
};
|
|
80
|
-
export const handleEvmApprovals = async (args
|
|
78
|
+
export const handleEvmApprovals = async (args) => await args.traceFn(getApprovalTraceParams(args.quoteResponses[0], args.isStxEnabled), async () => await approve(args));
|
|
81
79
|
/**
|
|
82
80
|
* Sequentially submits EVM resetApproval, approval and trade transactions through the TransactionController.
|
|
83
81
|
*
|
|
@@ -86,36 +84,10 @@ export const handleEvmApprovals = async (args, actionId) => await args.traceFn(g
|
|
|
86
84
|
*/
|
|
87
85
|
export async function* submitEvmHandler(args) {
|
|
88
86
|
const { quoteResponses: [quoteResponse], requireApproval, isBridgeTx, } = args;
|
|
89
|
-
// Generate actionId for pre-submission history
|
|
90
|
-
const actionId = generateActionId();
|
|
91
|
-
// Add pre-submission history keyed by actionId
|
|
92
|
-
// This ensures we have quote data available if transaction fails during submission
|
|
93
|
-
yield {
|
|
94
|
-
type: SubmitStep.AddHistoryItem,
|
|
95
|
-
payload: {
|
|
96
|
-
historyKey: actionId,
|
|
97
|
-
actionId,
|
|
98
|
-
quoteResponse,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
87
|
// Submit resetApproval and approval transactions if present
|
|
102
|
-
const
|
|
103
|
-
const approvalTxId = approvalTxMeta?.id;
|
|
104
|
-
let tradeActionId = actionId;
|
|
88
|
+
const approvalTxId = await handleEvmApprovals(args);
|
|
105
89
|
// Delay after approval
|
|
106
90
|
if (approvalTxId) {
|
|
107
|
-
// Generate a new actionId for the trade transaction since approval used the first one
|
|
108
|
-
tradeActionId = generateActionId();
|
|
109
|
-
yield {
|
|
110
|
-
type: SubmitStep.RekeyHistoryItem,
|
|
111
|
-
payload: {
|
|
112
|
-
oldHistoryKey: actionId,
|
|
113
|
-
newHistoryKey: tradeActionId,
|
|
114
|
-
historyItemOverrides: {
|
|
115
|
-
approvalTxId,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
91
|
await handleApprovalDelay(quoteResponse.quote.srcChainId);
|
|
120
92
|
}
|
|
121
93
|
// Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
|
|
@@ -124,43 +96,48 @@ export async function* submitEvmHandler(args) {
|
|
|
124
96
|
if (requireApproval && approvalTxId) {
|
|
125
97
|
await waitForTxConfirmation(args.messenger, approvalTxId);
|
|
126
98
|
}
|
|
99
|
+
// Generate trade actionId for pre-submission history
|
|
100
|
+
const actionId = generateActionId();
|
|
101
|
+
// Add pre-submission history keyed by actionId
|
|
102
|
+
// This ensures we have quote data available if transaction fails during submission
|
|
103
|
+
yield {
|
|
104
|
+
type: SubmitStep.AddHistoryItem,
|
|
105
|
+
payload: {
|
|
106
|
+
historyKey: actionId,
|
|
107
|
+
approvalTxId,
|
|
108
|
+
actionId,
|
|
109
|
+
quoteResponse,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
127
112
|
const transactionType = isBridgeTx
|
|
128
113
|
? TransactionType.bridge
|
|
129
114
|
: TransactionType.swap;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
actionId: tradeActionId,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
// Silence the error if tx has been added to the TransactionController to prevent duplicate Failed events
|
|
147
|
-
tradeMeta = getTransactionMetaByActionId(args.messenger, tradeActionId);
|
|
148
|
-
if (!tradeMeta) {
|
|
149
|
-
throw error;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
yield {
|
|
153
|
-
type: SubmitStep.SetTradeMeta,
|
|
154
|
-
payload: { tradeMeta },
|
|
155
|
-
};
|
|
115
|
+
const tradeMeta = await handleSingleTx({
|
|
116
|
+
...args,
|
|
117
|
+
transactionType,
|
|
118
|
+
trade: quoteResponse.trade,
|
|
119
|
+
// TODO figure out if this is needed
|
|
120
|
+
// Pass txFee when gasIncluded is true to use the quote's gas fees
|
|
121
|
+
// instead of re-estimating (which would fail for max native token swaps)
|
|
122
|
+
txFee: quoteResponse.quote.gasIncluded
|
|
123
|
+
? quoteResponse.quote.feeData.txFee
|
|
124
|
+
: undefined,
|
|
125
|
+
actionId,
|
|
126
|
+
});
|
|
156
127
|
// Use the tradeMeta's id as history key
|
|
157
128
|
yield {
|
|
158
129
|
type: SubmitStep.RekeyHistoryItem,
|
|
159
130
|
payload: {
|
|
160
|
-
oldHistoryKey:
|
|
131
|
+
oldHistoryKey: actionId,
|
|
161
132
|
newHistoryKey: tradeMeta.id,
|
|
162
133
|
tradeMeta,
|
|
163
134
|
},
|
|
164
135
|
};
|
|
136
|
+
yield {
|
|
137
|
+
type: SubmitStep.SetTradeMeta,
|
|
138
|
+
payload: {
|
|
139
|
+
tradeMeta,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
165
142
|
}
|
|
166
143
|
//# sourceMappingURL=evm-strategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm-strategy.js","sourceRoot":"","sources":["../../src/strategy/evm-strategy.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qEAAqE;AACrE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAEL,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;;;;;;;;;;GAaG;AACH,MAAM,cAAc,GAAG,KAAK,EAAE,EAC5B,SAAS,EACT,KAAK,EACL,eAAe,EACf,eAAe,GAAG,KAAK,EACvB,KAAK;AACL,qEAAqE;AACrE,QAAQ,GAAG,gBAAgB,EAAE,GAQ9B,EAA4B,EAAE;IAC7B,MAAM,eAAe,GAAG,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACnE,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,GAAG,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrD,MAAM,eAAe,GAAG,2BAA2B,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAE3E,MAAM,cAAc,GAAG;QACrB,QAAQ;QACR,eAAe;QACf,eAAe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AqB,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,eAAe,GAAG,UAAU;QAChC,CAAC,CAAC,eAAe,CAAC,MAAM;QACxB,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC;IAEzB,IAAI,SAAsC,CAAC;IAC3C,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,cAAc,CAAC;YAC/B,GAAG,IAAI;YACP,eAAe;YACf,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,oCAAoC;YACpC,kEAAkE;YAClE,yEAAyE;YACzE,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW;gBACpC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK;gBACnC,CAAC,CAAC,SAAS;YACb,QAAQ,EAAE,aAAa;SACxB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yGAAyG;QACzG,SAAS,GAAG,4BAA4B,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QACxE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE,EAAE,SAAS,EAAE;KACvB,CAAC;IAEF,wCAAwC;IACxC,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,gBAAgB;QACjC,OAAO,EAAE;YACP,aAAa,EAAE,aAAa;YAC5B,aAAa,EAAE,SAAS,CAAC,EAAE;YAC3B,SAAS;SACV;KACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable consistent-return */\n/* eslint-disable @typescript-eslint/explicit-function-return-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.js';\nimport { getAccountByAddress } from '../utils/accounts.js';\nimport { getNetworkClientIdByChainId } from '../utils/network.js';\nimport { getApprovalTraceParams } from '../utils/trace.js';\nimport {\n addTransaction,\n generateActionId,\n getTransactionMetaByActionId,\n handleApprovalDelay,\n handleMobileHardwareWalletDelay,\n toTransactionParams,\n waitForTxConfirmation,\n} from '../utils/transaction.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\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 */\nconst 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 * @param actionId - The actionId for the approval transaction\n *\n * @returns The approval txMeta of the approval transaction\n */\nconst approve = async (args: SubmitStrategyParams, actionId?: string) => {\n const {\n quoteResponses: [quoteResponse],\n isBridgeTx,\n } = args;\n const { approval, resetApproval } = quoteResponse;\n if (!approval || !isEvmTxData(approval)) {\n return;\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 actionId,\n });\n return approvalTxMeta;\n }\n};\n\nexport const handleEvmApprovals = async (\n args: SubmitStrategyParams,\n actionId?: string,\n) =>\n await args.traceFn(\n getApprovalTraceParams(args.quoteResponses[0], args.isStxEnabled),\n async () => await approve(args, actionId),\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 // Generate 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 actionId,\n quoteResponse,\n },\n };\n\n // Submit resetApproval and approval transactions if present\n const approvalTxMeta = await handleEvmApprovals(args, actionId);\n const approvalTxId = approvalTxMeta?.id;\n\n let tradeActionId = actionId;\n\n // Delay after approval\n if (approvalTxId) {\n // Generate a new actionId for the trade transaction since approval used the first one\n tradeActionId = generateActionId();\n yield {\n type: SubmitStep.RekeyHistoryItem,\n payload: {\n oldHistoryKey: actionId,\n newHistoryKey: tradeActionId,\n historyItemOverrides: {\n approvalTxId,\n },\n },\n };\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 const transactionType = isBridgeTx\n ? TransactionType.bridge\n : TransactionType.swap;\n\n let tradeMeta: TransactionMeta | undefined;\n try {\n 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: tradeActionId,\n });\n } catch (error) {\n // Silence the error if tx has been added to the TransactionController to prevent duplicate Failed events\n tradeMeta = getTransactionMetaByActionId(args.messenger, tradeActionId);\n if (!tradeMeta) {\n throw error;\n }\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: { tradeMeta },\n };\n\n // Use the tradeMeta's id as history key\n yield {\n type: SubmitStep.RekeyHistoryItem,\n payload: {\n oldHistoryKey: tradeActionId,\n newHistoryKey: tradeMeta.id,\n tradeMeta,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evm-strategy.js","sourceRoot":"","sources":["../../src/strategy/evm-strategy.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,qEAAqE;AACrE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,EAEL,eAAe,GAChB,MAAM,kCAAkC,CAAC;AA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QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,SAAS;SACV;KACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable consistent-return */\n/* eslint-disable @typescript-eslint/explicit-function-return-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.js';\nimport { getAccountByAddress } from '../utils/accounts.js';\nimport { getNetworkClientIdByChainId } from '../utils/network.js';\nimport { getApprovalTraceParams } from '../utils/trace.js';\nimport {\n addTransaction,\n generateActionId,\n handleApprovalDelay,\n handleMobileHardwareWalletDelay,\n toTransactionParams,\n waitForTxConfirmation,\n} from '../utils/transaction.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\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;\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/intent-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,MAAM,EACP,MAAM,6BAA6B,CAAC;AAgBrC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAc,MAAM,YAAY,CAAC;AAsHhF;;;;;;;;;;;;GAYG;AACH,wBAAuB,mBAAmB,CACxC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACjC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"intent-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/intent-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,MAAM,EACP,MAAM,6BAA6B,CAAC;AAgBrC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAc,MAAM,YAAY,CAAC;AAsHhF;;;;;;;;;;;;GAYG;AACH,wBAAuB,mBAAmB,CACxC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACjC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CAoD9C"}
|
|
@@ -108,8 +108,7 @@ const handleSubmitIntent = async (args) => {
|
|
|
108
108
|
*/
|
|
109
109
|
export async function* submitIntentHandler(args) {
|
|
110
110
|
// TODO handle STX/batch approvals
|
|
111
|
-
const
|
|
112
|
-
const approvalTxId = approvalTxMeta?.id;
|
|
111
|
+
const approvalTxId = await handleEvmApprovals(args);
|
|
113
112
|
approvalTxId && (await waitForTxConfirmation(args.messenger, approvalTxId));
|
|
114
113
|
// TODO add to history after approval tx is confirmed
|
|
115
114
|
// Submit the intent order to the bridge-api
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-strategy.js","sourceRoot":"","sources":["../../src/strategy/intent-strategy.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EACL,kBAAkB,EAClB,WAAW,GAEZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,uCAAuC,EACvC,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,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C;IAClC,MAAM,cAAc,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,cAAc,EAAE,EAAE,CAAC;IACxC,YAAY,IAAI,CAAC,MAAM,qBAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5E,qDAAqD;IAErD,4CAA4C;IAC5C,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAEjE,wDAAwD;IACxD,MAAM,eAAe,GAAG,MAAM,iBAAiB,CAAC,QAAQ,EAAE;QACxD,GAAG,IAAI;QACP,eAAe,EAAE,KAAK;QACtB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IAEH,uFAAuF;IACvF,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,SAAS,EAAE;gBACT,GAAG,eAAe;gBAClB,0DAA0D;gBAC1D,MAAM,EAAE,uCAAuC,CAAC,WAAW,CAAC;aAC7D;SACF;KACF,CAAC;IAEF,sDAAsD;IACtD,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,cAAc;QAC/B,OAAO,EAAE;YACP,yDAAyD;YACzD,UAAU,EAAE,QAAQ;YACpB,YAAY,EAAE;gBACZ,EAAE,EAAE,eAAe,EAAE,EAAE;aACxB;YACD,YAAY;YACZ,uDAAuD;YACvD,qBAAqB,EAAE,eAAe,EAAE,EAAE;YAC1C,aAAa,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;SACtC;KACF,CAAC;IAEF,qDAAqD;IACrD,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,UAAU,EAAE,QAAQ;SACrB;KACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n formatChainIdToHex,\n isEvmTxData,\n TxData,\n} from '@metamask/bridge-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\n\nimport { getJwt } from '../utils/authentication.js';\nimport {\n getIntentFromQuote,\n mapIntentOrderStatusToTransactionStatus,\n postSubmitOrder,\n} from '../utils/intent-api.js';\nimport { signTypedMessage } from '../utils/keyring.js';\nimport { getNetworkClientIdByChainId } from '../utils/network.js';\nimport {\n addSyntheticTransaction,\n waitForTxConfirmation,\n} from '../utils/transaction.js';\nimport { handleEvmApprovals } from './evm-strategy.js';\nimport { SubmitStrategyParams, SubmitStepResult, SubmitStep } from './types.js';\n\n/**\n * Submits a synthetic EVM transaction to the TransactionController in order to display the intent order's\n * status in theclients, before the actual transaction is finalized on chain. The resulting transaction\n * is only available locally and is not submitted to the chain.\n *\n * @param orderUid - The order uid of the intent transaction\n * @param args - The parameters for the transaction\n * @returns The tradeMeta for the synthetic transaction\n */\nconst handleSyntheticTx = async (\n orderUid: string,\n args: SubmitStrategyParams,\n) => {\n const {\n quoteResponses: [quoteResponse],\n messenger,\n isBridgeTx,\n selectedAccount,\n } = args;\n const {\n quote: { srcChainId },\n } = quoteResponse;\n\n // Determine transaction type: swap for same-chain, bridge for cross-chain\n const transactionType = isBridgeTx\n ? /* c8 ignore start */\n TransactionType.bridge\n : /* c8 ignore end */\n TransactionType.swap;\n\n const networkClientId = getNetworkClientIdByChainId(messenger, srcChainId);\n\n // This is a synthetic transaction whose purpose is to be able\n // to track the order status via the history\n if (!isEvmTxData(quoteResponse.trade)) {\n throw new Error('Failed to submit intent: trade is not an EVM transaction');\n }\n const intent = getIntentFromQuote(quoteResponse);\n // This is a synthetic transaction whose purpose is to be able\n // to track the order status via the history\n /**\n * @deprecated use trade data from quote response instead\n */\n const intentTransactionParams = {\n chainId: formatChainIdToHex(srcChainId),\n from: selectedAccount.address,\n to:\n intent.settlementContract ?? '0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract\n data: `0x${orderUid?.slice(-8)}`, // Use last 8 chars of orderUid to make each transaction unique\n value: '0x0',\n gas: '0x5208', // Minimal gas for display purposes\n gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it\n };\n\n const initialTxMeta = await addSyntheticTransaction(\n messenger,\n intentTransactionParams,\n {\n requireApproval: false,\n networkClientId,\n type: transactionType,\n },\n );\n return initialTxMeta;\n};\n\n/**\n * Submits batched EVM transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @returns The approvalTxId and tradeMeta for the non-EVM transaction\n */\nconst handleSubmitIntent = async (args: SubmitStrategyParams<TxData>) => {\n const {\n quoteResponses: [quoteResponse],\n messenger,\n selectedAccount,\n clientId,\n fetchFn,\n bridgeApiBaseUrl,\n } = args;\n const { srcChainId, requestId } = quoteResponse.quote;\n\n const intent = getIntentFromQuote(quoteResponse);\n const signature = await signTypedMessage({\n messenger,\n accountAddress: selectedAccount.address,\n typedData: intent.typedData,\n });\n\n const { id: orderUid, status } = await postSubmitOrder({\n params: {\n srcChainId,\n quoteId: requestId,\n signature,\n order: intent.order,\n userAddress: selectedAccount.address,\n aggregatorId: intent.protocol,\n },\n clientId,\n jwt: await getJwt(messenger),\n fetchFn,\n bridgeApiBaseUrl,\n });\n\n return {\n orderUid,\n orderStatus: status,\n };\n};\n\n/**\n * Submits an approval tx to the TransactionController,\n * posts an intent order to the bridge-api,\n * and creates a synthetic transaction in the TransactionController\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @yields The approvalTxId and tradeMeta for the intent transaction\n */\nexport async function* submitIntentHandler(\n args: SubmitStrategyParams<TxData>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n // TODO handle STX/batch approvals\n const approvalTxMeta = await handleEvmApprovals(args);\n const approvalTxId = approvalTxMeta?.id;\n approvalTxId && (await waitForTxConfirmation(args.messenger, approvalTxId));\n\n // TODO add to history after approval tx is confirmed\n\n // Submit the intent order to the bridge-api\n const { orderUid, orderStatus } = await handleSubmitIntent(args);\n\n // Initialize a transaction in the TransactionController\n const syntheticTxMeta = await handleSyntheticTx(orderUid, {\n ...args,\n requireApproval: false,\n isStxEnabled: false,\n });\n\n // Use synthetic transaction metadata + translated intent order status as the tradeMeta\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: {\n ...syntheticTxMeta,\n // Map intent order status to TransactionController status\n status: mapIntentOrderStatusToTransactionStatus(orderStatus),\n },\n },\n };\n\n // Update txHistory with synthetic txMeta and order id\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n // Use orderId as the history key for intent transactions\n historyKey: orderUid,\n bridgeTxMeta: {\n id: syntheticTxMeta?.id,\n },\n approvalTxId,\n // Keep original txId for TransactionController updates\n originalTransactionId: syntheticTxMeta?.id,\n quoteResponse: args.quoteResponses[0],\n },\n };\n\n // Start polling using the orderId as the history key\n yield {\n type: SubmitStep.StartPolling,\n payload: {\n historyKey: orderUid,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"intent-strategy.js","sourceRoot":"","sources":["../../src/strategy/intent-strategy.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EACL,kBAAkB,EAClB,WAAW,GAEZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,uCAAuC,EACvC,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EACL,uBAAuB,E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CACxC,IAAkC;IAElC,kCAAkC;IAClC,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACpD,YAAY,IAAI,CAAC,MAAM,qBAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5E,qDAAqD;IAErD,4CAA4C;IAC5C,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAEjE,wDAAwD;IACxD,MAAM,eAAe,GAAG,MAAM,iBAAiB,CAAC,QAAQ,EAAE;QACxD,GAAG,IAAI;QACP,eAAe,EAAE,KAAK;QACtB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IAEH,uFAAuF;IACvF,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,SAAS,EAAE;gBACT,GAAG,eAAe;gBAClB,0DAA0D;gBAC1D,MAAM,EAAE,uCAAuC,CAAC,WAAW,CAAC;aAC7D;SACF;KACF,CAAC;IAEF,sDAAsD;IACtD,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,cAAc;QAC/B,OAAO,EAAE;YACP,yDAAyD;YACzD,UAAU,EAAE,QAAQ;YACpB,YAAY,EAAE;gBACZ,EAAE,EAAE,eAAe,EAAE,EAAE;aACxB;YACD,YAAY;YACZ,uDAAuD;YACvD,qBAAqB,EAAE,eAAe,EAAE,EAAE;YAC1C,aAAa,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;SACtC;KACF,CAAC;IAEF,qDAAqD;IACrD,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,UAAU,EAAE,QAAQ;SACrB;KACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n formatChainIdToHex,\n isEvmTxData,\n TxData,\n} from '@metamask/bridge-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\n\nimport { getJwt } from '../utils/authentication.js';\nimport {\n getIntentFromQuote,\n mapIntentOrderStatusToTransactionStatus,\n postSubmitOrder,\n} from '../utils/intent-api.js';\nimport { signTypedMessage } from '../utils/keyring.js';\nimport { getNetworkClientIdByChainId } from '../utils/network.js';\nimport {\n addSyntheticTransaction,\n waitForTxConfirmation,\n} from '../utils/transaction.js';\nimport { handleEvmApprovals } from './evm-strategy.js';\nimport { SubmitStrategyParams, SubmitStepResult, SubmitStep } from './types.js';\n\n/**\n * Submits a synthetic EVM transaction to the TransactionController in order to display the intent order's\n * status in theclients, before the actual transaction is finalized on chain. The resulting transaction\n * is only available locally and is not submitted to the chain.\n *\n * @param orderUid - The order uid of the intent transaction\n * @param args - The parameters for the transaction\n * @returns The tradeMeta for the synthetic transaction\n */\nconst handleSyntheticTx = async (\n orderUid: string,\n args: SubmitStrategyParams,\n) => {\n const {\n quoteResponses: [quoteResponse],\n messenger,\n isBridgeTx,\n selectedAccount,\n } = args;\n const {\n quote: { srcChainId },\n } = quoteResponse;\n\n // Determine transaction type: swap for same-chain, bridge for cross-chain\n const transactionType = isBridgeTx\n ? /* c8 ignore start */\n TransactionType.bridge\n : /* c8 ignore end */\n TransactionType.swap;\n\n const networkClientId = getNetworkClientIdByChainId(messenger, srcChainId);\n\n // This is a synthetic transaction whose purpose is to be able\n // to track the order status via the history\n if (!isEvmTxData(quoteResponse.trade)) {\n throw new Error('Failed to submit intent: trade is not an EVM transaction');\n }\n const intent = getIntentFromQuote(quoteResponse);\n // This is a synthetic transaction whose purpose is to be able\n // to track the order status via the history\n /**\n * @deprecated use trade data from quote response instead\n */\n const intentTransactionParams = {\n chainId: formatChainIdToHex(srcChainId),\n from: selectedAccount.address,\n to:\n intent.settlementContract ?? '0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract\n data: `0x${orderUid?.slice(-8)}`, // Use last 8 chars of orderUid to make each transaction unique\n value: '0x0',\n gas: '0x5208', // Minimal gas for display purposes\n gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it\n };\n\n const initialTxMeta = await addSyntheticTransaction(\n messenger,\n intentTransactionParams,\n {\n requireApproval: false,\n networkClientId,\n type: transactionType,\n },\n );\n return initialTxMeta;\n};\n\n/**\n * Submits batched EVM transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @returns The approvalTxId and tradeMeta for the non-EVM transaction\n */\nconst handleSubmitIntent = async (args: SubmitStrategyParams<TxData>) => {\n const {\n quoteResponses: [quoteResponse],\n messenger,\n selectedAccount,\n clientId,\n fetchFn,\n bridgeApiBaseUrl,\n } = args;\n const { srcChainId, requestId } = quoteResponse.quote;\n\n const intent = getIntentFromQuote(quoteResponse);\n const signature = await signTypedMessage({\n messenger,\n accountAddress: selectedAccount.address,\n typedData: intent.typedData,\n });\n\n const { id: orderUid, status } = await postSubmitOrder({\n params: {\n srcChainId,\n quoteId: requestId,\n signature,\n order: intent.order,\n userAddress: selectedAccount.address,\n aggregatorId: intent.protocol,\n },\n clientId,\n jwt: await getJwt(messenger),\n fetchFn,\n bridgeApiBaseUrl,\n });\n\n return {\n orderUid,\n orderStatus: status,\n };\n};\n\n/**\n * Submits an approval tx to the TransactionController,\n * posts an intent order to the bridge-api,\n * and creates a synthetic transaction in the TransactionController\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @yields The approvalTxId and tradeMeta for the intent transaction\n */\nexport async function* submitIntentHandler(\n args: SubmitStrategyParams<TxData>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n // TODO handle STX/batch approvals\n const approvalTxId = await handleEvmApprovals(args);\n approvalTxId && (await waitForTxConfirmation(args.messenger, approvalTxId));\n\n // TODO add to history after approval tx is confirmed\n\n // Submit the intent order to the bridge-api\n const { orderUid, orderStatus } = await handleSubmitIntent(args);\n\n // Initialize a transaction in the TransactionController\n const syntheticTxMeta = await handleSyntheticTx(orderUid, {\n ...args,\n requireApproval: false,\n isStxEnabled: false,\n });\n\n // Use synthetic transaction metadata + translated intent order status as the tradeMeta\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: {\n ...syntheticTxMeta,\n // Map intent order status to TransactionController status\n status: mapIntentOrderStatusToTransactionStatus(orderStatus),\n },\n },\n };\n\n // Update txHistory with synthetic txMeta and order id\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n // Use orderId as the history key for intent transactions\n historyKey: orderUid,\n bridgeTxMeta: {\n id: syntheticTxMeta?.id,\n },\n approvalTxId,\n // Keep original txId for TransactionController updates\n originalTransactionId: syntheticTxMeta?.id,\n quoteResponse: args.quoteResponses[0],\n },\n };\n\n // Start polling using the orderId as the history key\n yield {\n type: SubmitStep.StartPolling,\n payload: {\n historyKey: orderUid,\n },\n };\n}\n"]}
|