@metamask-previews/bridge-status-controller 72.0.0-preview-4bcc1c6c1 → 72.0.1-preview-34aa73a7b
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 +11 -1
- package/dist/strategy/batch-sell-strategy.cjs +4 -2
- package/dist/strategy/batch-sell-strategy.cjs.map +1 -1
- package/dist/strategy/batch-sell-strategy.d.cts.map +1 -1
- package/dist/strategy/batch-sell-strategy.d.mts.map +1 -1
- package/dist/strategy/batch-sell-strategy.mjs +4 -2
- package/dist/strategy/batch-sell-strategy.mjs.map +1 -1
- package/dist/strategy/batch-strategy.cjs +10 -0
- package/dist/strategy/batch-strategy.cjs.map +1 -1
- package/dist/strategy/batch-strategy.d.cts.map +1 -1
- package/dist/strategy/batch-strategy.d.mts.map +1 -1
- package/dist/strategy/batch-strategy.mjs +10 -0
- package/dist/strategy/batch-strategy.mjs.map +1 -1
- package/dist/utils/transaction.cjs +11 -13
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +12 -14
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [72.0.1]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Fix gas-related transaction options for batch and batch-sell swaps ([#8979](https://github.com/MetaMask/core/pull/8979))
|
|
15
|
+
- When the fee is paid in an ERC20 token, set it as the `gasFeeToken`
|
|
16
|
+
- Set `excludeNativeTokenForFee=true` when `gasFeeToken` is set, which tells the TransactionController to use the gasFeeToken for payment regardless of whether the user has enough native assets
|
|
17
|
+
- Set `skipInitialGasEstimate=false` if submitting gasIncluded7702 quotes and account has not been upgraded to a smart account
|
|
18
|
+
|
|
10
19
|
## [72.0.0]
|
|
11
20
|
|
|
12
21
|
### Added
|
|
@@ -1238,7 +1247,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1238
1247
|
|
|
1239
1248
|
- Initial release ([#5317](https://github.com/MetaMask/core/pull/5317))
|
|
1240
1249
|
|
|
1241
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@72.0.
|
|
1250
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@72.0.1...HEAD
|
|
1251
|
+
[72.0.1]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@72.0.0...@metamask/bridge-status-controller@72.0.1
|
|
1242
1252
|
[72.0.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@71.2.1...@metamask/bridge-status-controller@72.0.0
|
|
1243
1253
|
[71.2.1]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@71.2.0...@metamask/bridge-status-controller@71.2.1
|
|
1244
1254
|
[71.2.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@71.1.4...@metamask/bridge-status-controller@71.2.0
|
|
@@ -29,8 +29,10 @@ async function* submitBatchSellHandler(args) {
|
|
|
29
29
|
disable7702: (0, transaction_1.shouldDisable7702)(gasIncluded7702, gasIncluded, isDelegatedAccount),
|
|
30
30
|
isGasFeeSponsored: gasSponsored,
|
|
31
31
|
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
32
|
-
skipInitialGasEstimate:
|
|
33
|
-
|
|
32
|
+
skipInitialGasEstimate: gasIncluded7702
|
|
33
|
+
? isDelegatedAccount
|
|
34
|
+
: Boolean(gasFeeToken),
|
|
35
|
+
excludeNativeTokenForFee: !gasFeeToken,
|
|
34
36
|
});
|
|
35
37
|
// Submit the batch to the TransactionController
|
|
36
38
|
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sell-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":";;;AACA,6EAG0C;AAG1C,0DAQ8B;AAC9B,uCAAqC;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;AACI,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,IAAA,uCAAyB,EAAC;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,EAAE,CAAC,IAAI,KAAK,wCAAe,CAAC,mBAAmB,CAC3D,EAAE,EAAE,CAAC,EAAE,CAAC;IAET,MAAM,iBAAiB,GAAG,MAAM,IAAA,0CAA4B,EAAC;QAC3D,SAAS;QACT,SAAS;QACT,eAAe;QACf,kBAAkB;QAClB,8DAA8D;QAC9D,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,IAAA,+BAAiB,EAC5B,eAAe,EACf,WAAW,EACX,kBAAkB,CACnB;QACD,iBAAiB,EAAE,YAAY;QAC/B,gBAAgB,EAAE,OAAO,CAAC,eAAe,CAAC;QAC1C,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":";;;AACA,6EAG0C;AAG1C,0DAQ8B;A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c;gBAC/B,OAAO,EAAE;oBACP,UAAU,EAAE,qBAAqB,CAAC,iBAAiB,CAAC;oBACpD,aAAa;oBACb,aAAa,EAAE,eAAe;iBAC/B;aACF,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,0DAA0D;QAC1D,6DAA6D;QAC7D,uDAAuD;QACvD,KAAK,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,gBAAgB,EAAE,CAAC;YACzD,MAAM;gBACJ,IAAI,EAAE,kBAAU,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;IAED,MAAM;QACJ,IAAI,EAAE,kBAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,SAAS,EAAE,cAAc;SAC1B;KACF,CAAC;AACJ,CAAC;AA1HD,wDA0HC","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: 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 // 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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sell-strategy.d.cts","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,
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.d.cts","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,CAwH9C"}
|
|
@@ -1 +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,
|
|
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,CAwH9C"}
|
|
@@ -26,8 +26,10 @@ export async function* submitBatchSellHandler(args) {
|
|
|
26
26
|
disable7702: shouldDisable7702(gasIncluded7702, gasIncluded, isDelegatedAccount),
|
|
27
27
|
isGasFeeSponsored: gasSponsored,
|
|
28
28
|
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
29
|
-
skipInitialGasEstimate:
|
|
30
|
-
|
|
29
|
+
skipInitialGasEstimate: gasIncluded7702
|
|
30
|
+
? isDelegatedAccount
|
|
31
|
+
: Boolean(gasFeeToken),
|
|
32
|
+
excludeNativeTokenForFee: !gasFeeToken,
|
|
31
33
|
});
|
|
32
34
|
// Submit the batch to the TransactionController
|
|
33
35
|
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
@@ -1 +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,WAAW,EAAE,YAAY,EAAE,GAAG,eAAe,CAAC;IAEvE,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAChC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,eAAe,CAAC,mBAAmB,CAC3D,EAAE,EAAE,CAAC,EAAE,CAAC;IAET,MAAM,iBAAiB,GAAG,MAAM,4BAA4B,CAAC;QAC3D,SAAS;QACT,SAAS;QACT,eAAe;QACf,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CAAC,qBAAqB,CAAC,CAAC,CACrD,CAAC;QAEF,kEAAkE;QAClE,MAAM;YACJ,IAAI,EAAE,UAAU,CAAC,cAAc;YAC/B,OAAO,EAAE;gBACP,UAAU,EAAE,cAAc,CAAC,EAAE;gBAC7B,aAAa,EAAE,sBAAsB,CAAC,aAAa;gBACnD,aAAa,EAAE,eAAe;gBAC9B,QAAQ;gBACR,YAAY,EAAE,cAAc;aAC7B;SACF,CAAC;QACF,mFAAmF;QACnF,KAAK,MAAM,iBAAiB,IAAI,gBAAgB,EAAE,CAAC;YACjD,MAAM,EAAE,aAAa,EAAE,GAAG,iBAAiB,CAAC;YAE5C,MAAM;gBACJ,IAAI,EAAE,UAAU,CAAC,cAAc;gBAC/B,OAAO,EAAE;oBACP,UAAU,EAAE,qBAAqB,CAAC,iBAAiB,CAAC;oBACpD,aAAa;oBACb,aAAa,EAAE,eAAe;iBAC/B;aACF,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,0DAA0D;QAC1D,6DAA6D;QAC7D,uDAAuD;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;IAED,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,SAAS,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: 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 // 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"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.submitBatchHandler = void 0;
|
|
4
|
+
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
4
5
|
const transaction_1 = require("../utils/transaction.cjs");
|
|
5
6
|
const types_1 = require("./types.cjs");
|
|
6
7
|
/**
|
|
@@ -15,6 +16,10 @@ async function* submitBatchHandler(args) {
|
|
|
15
16
|
quoteResponse,
|
|
16
17
|
isBridgeTx,
|
|
17
18
|
});
|
|
19
|
+
const gasFeeToken = quoteResponse.quote.feeData[bridge_controller_1.FeeType.TX_FEE]?.asset?.address &&
|
|
20
|
+
(0, bridge_controller_1.isNativeAddress)(quoteResponse.quote.feeData[bridge_controller_1.FeeType.TX_FEE].asset.address)
|
|
21
|
+
? undefined
|
|
22
|
+
: quoteResponse.quote.feeData[bridge_controller_1.FeeType.TX_FEE]?.asset?.address;
|
|
18
23
|
const transactionParams = await (0, transaction_1.getAddTransactionBatchParams)({
|
|
19
24
|
tradeData,
|
|
20
25
|
requireApproval,
|
|
@@ -24,6 +29,11 @@ async function* submitBatchHandler(args) {
|
|
|
24
29
|
disable7702: (0, transaction_1.shouldDisable7702)(quoteResponse.quote.gasIncluded7702, quoteResponse.quote.gasIncluded, isDelegatedAccount),
|
|
25
30
|
isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),
|
|
26
31
|
isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),
|
|
32
|
+
gasFeeToken,
|
|
33
|
+
skipInitialGasEstimate: quoteResponse.quote.gasIncluded7702
|
|
34
|
+
? isDelegatedAccount
|
|
35
|
+
: Boolean(gasFeeToken),
|
|
36
|
+
excludeNativeTokenForFee: !gasFeeToken,
|
|
27
37
|
});
|
|
28
38
|
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
29
39
|
const quoteAndTxMetas = (0, transaction_1.findAllTransactionsInBatch)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"batch-strategy.cjs","sourceRoot":"","sources":["../../src/str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metamask/bridge-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport type { Hex } from '@metamask/utils';\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 gasFeeToken =\n quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address &&\n isNativeAddress(quoteResponse.quote.feeData[FeeType.TX_FEE].asset.address)\n ? undefined\n : (quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address as Hex);\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 gasFeeToken,\n skipInitialGasEstimate: quoteResponse.quote.gasIncluded7702\n ? isDelegatedAccount\n : Boolean(gasFeeToken),\n excludeNativeTokenForFee: !gasFeeToken,\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-strategy.d.cts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-strategy.d.cts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAY1D,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,CAwF9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAY1D,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,CAwF9C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FeeType, isNativeAddress } from "@metamask/bridge-controller";
|
|
1
2
|
import { findAllTransactionsInBatch, getAddTransactionBatchParams, isApprovalTx, isTradeTx, shouldDisable7702, toQuoteAndTxMetadata } from "../utils/transaction.mjs";
|
|
2
3
|
import { SubmitStep } from "./types.mjs";
|
|
3
4
|
/**
|
|
@@ -12,6 +13,10 @@ export async function* submitBatchHandler(args) {
|
|
|
12
13
|
quoteResponse,
|
|
13
14
|
isBridgeTx,
|
|
14
15
|
});
|
|
16
|
+
const gasFeeToken = quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address &&
|
|
17
|
+
isNativeAddress(quoteResponse.quote.feeData[FeeType.TX_FEE].asset.address)
|
|
18
|
+
? undefined
|
|
19
|
+
: quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address;
|
|
15
20
|
const transactionParams = await getAddTransactionBatchParams({
|
|
16
21
|
tradeData,
|
|
17
22
|
requireApproval,
|
|
@@ -21,6 +26,11 @@ export async function* submitBatchHandler(args) {
|
|
|
21
26
|
disable7702: shouldDisable7702(quoteResponse.quote.gasIncluded7702, quoteResponse.quote.gasIncluded, isDelegatedAccount),
|
|
22
27
|
isGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),
|
|
23
28
|
isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),
|
|
29
|
+
gasFeeToken,
|
|
30
|
+
skipInitialGasEstimate: quoteResponse.quote.gasIncluded7702
|
|
31
|
+
? isDelegatedAccount
|
|
32
|
+
: Boolean(gasFeeToken),
|
|
33
|
+
excludeNativeTokenForFee: !gasFeeToken,
|
|
24
34
|
});
|
|
25
35
|
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
26
36
|
const quoteAndTxMetas = findAllTransactionsInBatch({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"batch-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAIvE,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,WAAW,GACf,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO;QAC3D,eAAe,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QACxE,CAAC,CAAC,SAAS;QACX,CAAC,CAAE,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAe,CAAC;IAE3E,MAAM,iBAAiB,GAAG,MAAM,4BAA4B,CAAC;QAC3D,SAAS;QACT,eAAe;QACf,kBAAkB;QAClB,SAAS;QACT,MAAM,EAAE,IAAI;QACZ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ACJ,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 { FeeType, isNativeAddress } from '@metamask/bridge-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport type { Hex } from '@metamask/utils';\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 gasFeeToken =\n quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address &&\n isNativeAddress(quoteResponse.quote.feeData[FeeType.TX_FEE].asset.address)\n ? undefined\n : (quoteResponse.quote.feeData[FeeType.TX_FEE]?.asset?.address as Hex);\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 gasFeeToken,\n skipInitialGasEstimate: quoteResponse.quote.gasIncluded7702\n ? isDelegatedAccount\n : Boolean(gasFeeToken),\n excludeNativeTokenForFee: !gasFeeToken,\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"]}
|
|
@@ -35,12 +35,9 @@ const shouldDisable7702 = (gasIncluded7702 = false, gasIncluded = false, isDeleg
|
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
37
|
// Enable batching when the account is already delegated (to avoid the in-flight transaction limit for delegated accounts)
|
|
38
|
-
if (isDelegatedAccount) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
38
|
// For gasless transactions with STX/sendBundle we keep disabling 7702
|
|
42
|
-
if (gasIncluded) {
|
|
43
|
-
return
|
|
39
|
+
if (isDelegatedAccount && !gasIncluded) {
|
|
40
|
+
return false;
|
|
44
41
|
}
|
|
45
42
|
/**
|
|
46
43
|
* Explicitly return default instead of falsy value (see TransactionBatchRequest.disable7702)
|
|
@@ -278,24 +275,25 @@ exports.toQuoteAndTxMetadataBatch = toQuoteAndTxMetadataBatch;
|
|
|
278
275
|
* @returns The gas fee estimates for the transaction
|
|
279
276
|
*/
|
|
280
277
|
const toTransactionParams = async (messenger, { chainId: tradeChainId, gasLimit, ...trade }, networkClientId, chainId, simulatedGasFeeLimits) => {
|
|
281
|
-
const
|
|
282
|
-
...trade,
|
|
278
|
+
const transactionParams = {
|
|
283
279
|
data: trade.data,
|
|
284
280
|
to: trade.to,
|
|
285
281
|
from: trade.from,
|
|
286
282
|
value: trade.value,
|
|
287
|
-
|
|
288
|
-
const transactionParams = {
|
|
289
|
-
...normalizedTrade,
|
|
290
|
-
// Only add gasLimit and gas if they're truthy
|
|
283
|
+
// Only add gas if it's truthy
|
|
291
284
|
gas: gasLimit ? (0, controller_utils_1.toHex)(gasLimit) : undefined,
|
|
292
285
|
};
|
|
293
286
|
// Use bridge-api's provided gas fee estimates
|
|
294
287
|
if (simulatedGasFeeLimits) {
|
|
295
288
|
return {
|
|
296
289
|
...transactionParams,
|
|
297
|
-
|
|
298
|
-
|
|
290
|
+
// Sometimes estimates are hex, somethings numeric strings
|
|
291
|
+
maxFeePerGas: (0, utils_1.isStrictHexString)(simulatedGasFeeLimits.maxFeePerGas)
|
|
292
|
+
? simulatedGasFeeLimits.maxFeePerGas
|
|
293
|
+
: (0, controller_utils_1.toHex)(simulatedGasFeeLimits.maxFeePerGas),
|
|
294
|
+
maxPriorityFeePerGas: (0, utils_1.isStrictHexString)(simulatedGasFeeLimits.maxPriorityFeePerGas)
|
|
295
|
+
? simulatedGasFeeLimits.maxPriorityFeePerGas
|
|
296
|
+
: (0, controller_utils_1.toHex)(simulatedGasFeeLimits.maxPriorityFeePerGas),
|
|
299
297
|
};
|
|
300
298
|
}
|
|
301
299
|
// Get transaction's 1559 gas fee estimates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.cjs","sourceRoot":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AI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;wBAC3D,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;gBACD,mDAAmD;gBACnD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;oBACrC,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC,CAAC;SACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAtCW,QAAA,0BAA0B,8BAsCrC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,yBAAyB,GAAG,CAAC,EACxC,SAAS,EACT,qBAAqB,GAItB,EAAE,EAAE;IACH,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,EAAE;QACrD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,iBAAiB,CAAC;QAE3C,IAAI,MAAM,EAAE,CAAC;YACX,+CAA+C;YAC/C,IAAA,yBAAiB,EACf,SAAS,EACT,MAAM,EACN,EAAE,IAAI,EAAE,EACR,qBAAqB,IAAI,EAAE,CAC5B,CAAC;YACF,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;YACtC,OAAO,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC3D,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAxBW,QAAA,yBAAyB,6BAwBpC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n ChainId,\n formatChainIdToHex,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n isEvmTxData,\n FeeType,\n BatchSellTransactionType,\n} from '@metamask/bridge-controller';\nimport type {\n BatchSellTradesResponse,\n QuoteMetadata,\n QuoteResponse,\n SimulatedGasFeeLimits,\n Trade,\n TxData,\n TxFeeGasLimits,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n GasFeeEstimateType,\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n TransactionMeta,\n TransactionBatchSingleRequest,\n BatchTransactionParams,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type { BridgeStatusControllerMessenger } from '../types';\nimport type { QuoteAndTxMetadata } from '../types';\nimport { getAccountByAddress } from './accounts';\nimport { getNetworkClientIdByChainId } from './network';\n\nexport const isApprovalTx = (type: TransactionType) =>\n type === TransactionType.bridgeApproval ||\n type === TransactionType.swapApproval;\nexport const isTradeTx = (type: TransactionType) =>\n type === TransactionType.bridge || type === TransactionType.swap;\nexport const isCrossChainTx = (type: TransactionType) =>\n isTradeTx(type) || isApprovalTx(type);\n\n/**\n * For 7702 delegated transactions, check for delegation-specific fields\n * These transactions might have authorizationList or delegationAddress\n *\n * @param tx - The transaction meta\n * @returns Whether the transaction is a 7702 transaction\n */\nexport const is7702Tx = (tx: TransactionMeta) => {\n return (\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress)\n );\n};\n\nexport const shouldDisable7702 = (\n gasIncluded7702: boolean = false,\n gasIncluded: boolean = false,\n isDelegatedAccount: boolean = false,\n): boolean => {\n // Enable 7702 batching when the quote includes gasless 7702 support\n if (gasIncluded7702) {\n return false;\n }\n // Enable batching when the account is already delegated (to avoid the in-flight transaction limit for delegated accounts)\n if (isDelegatedAccount) {\n return false;\n }\n // For gasless transactions with STX/sendBundle we keep disabling 7702\n if (gasIncluded) {\n return true;\n }\n /**\n * Explicitly return default instead of falsy value (see TransactionBatchRequest.disable7702)\n */\n return true;\n};\n\nexport const hasNestedSwapTransactions = (txMeta: TransactionMeta) => {\n return Boolean(\n txMeta?.nestedTransactions?.some((tx) => tx.type === TransactionType.swap),\n );\n};\n\nexport const getGasFeeEstimates = async (\n messenger: BridgeStatusControllerMessenger,\n args: Parameters<TransactionController['estimateGasFee']>[0],\n) => {\n const { estimates } = await messenger.call(\n 'TransactionController:estimateGasFee',\n args,\n );\n\n if (estimates?.type === GasFeeEstimateType.FeeMarket) {\n return estimates[BRIDGE_PREFERRED_GAS_ESTIMATE];\n }\n\n return undefined;\n};\n\nexport const getTransactions = (messenger: BridgeStatusControllerMessenger) => {\n return messenger.call('TransactionController:getState').transactions ?? [];\n};\n\nexport const getTransactionMetaById = (\n messenger: BridgeStatusControllerMessenger,\n txId?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.id === txId,\n );\n};\n\nexport const getTransactionMetaByHash = (\n messenger: BridgeStatusControllerMessenger,\n txHash?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.hash?.toLowerCase() === txHash?.toLowerCase(),\n );\n};\n\nexport const updateTransaction = (\n messenger: BridgeStatusControllerMessenger,\n txMeta: TransactionMeta,\n txMetaUpdates: Partial<TransactionMeta>,\n note: string,\n) => {\n return messenger.call(\n 'TransactionController:updateTransaction',\n { ...txMeta, ...txMetaUpdates },\n note,\n );\n};\n\nexport const checkIsDelegatedAccount = async (\n messenger: BridgeStatusControllerMessenger,\n fromAddress: Hex,\n chainIds: Hex[],\n): Promise<boolean> => {\n try {\n const atomicBatchSupport = await messenger.call(\n 'TransactionController:isAtomicBatchSupported',\n {\n address: fromAddress,\n chainIds,\n },\n );\n return atomicBatchSupport.some(\n (entry: IsAtomicBatchSupportedResultEntry) =>\n entry.isSupported && entry.delegationAddress,\n );\n } catch {\n return false;\n }\n};\n\nconst waitForHashAndReturnFinalTxMeta = async (\n messenger: BridgeStatusControllerMessenger,\n hashPromise?: Awaited<\n ReturnType<TransactionController['addTransaction']>\n >['result'],\n): Promise<TransactionMeta> => {\n const txHash = await hashPromise;\n const finalTransactionMeta = getTransactionMetaByHash(messenger, txHash);\n if (!finalTransactionMeta) {\n throw new Error(\n 'Failed to submit cross-chain swap tx: txMeta for txHash was not found',\n );\n }\n return finalTransactionMeta;\n};\n\nexport const addTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { result } = await messenger.call(\n 'TransactionController:addTransaction',\n ...args,\n );\n return await waitForHashAndReturnFinalTxMeta(messenger, result);\n};\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\n/**\n * Adds a synthetic transaction to the TransactionController to display pending intent orders in the UI\n *\n * @param messenger - The messenger to use for the transaction\n * @param args - The arguments for the transaction\n * @returns The transaction meta\n */\nexport const addSyntheticTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { transactionMeta } = await messenger.call(\n 'TransactionController:addTransaction',\n args[0],\n {\n origin: 'metamask',\n actionId: generateActionId(),\n isStateOnly: true,\n isInternal: true,\n ...args[1],\n },\n );\n return transactionMeta;\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.\n *\n * @deprecated use addTransaction util\n * @param messenger - the BridgeStatusControllerMessenger\n * @param txId - the transaction ID\n * @param options - the options for the timeout and poll\n * @param options.timeoutMs - the timeout in milliseconds\n * @param options.pollMs - the poll interval in milliseconds\n * @returns the transaction meta\n */\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const meta = getTransactionMetaById(messenger, txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\n\nexport const toQuoteAndTxMetadata = ({\n quoteResponse,\n isBridgeTx,\n}: {\n quoteResponse: QuoteResponse<Trade, Trade> & QuoteMetadata;\n isBridgeTx: boolean;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const approvalTxType = isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval;\n\n if (quoteResponse.resetApproval) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.resetApproval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n if (quoteResponse.approval && isEvmTxData(quoteResponse.approval)) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.approval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.trade as TxData,\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n assetsFiatValues: {\n sending: quoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving: quoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n\n return tradeData;\n};\n\n/**\n * Build the trade+quote metadata array for the batch sell transaction\n * This ties together the quote, the tx params and the txMeta after submission\n *\n * @param options - The options for the batch sell transaction\n * @param options.quoteResponses - The quote responses for the batch sell transaction\n * @param options.batchSellTrades - The batch sell trades for the batch sell transaction\n * @returns The trade+quote metadata array for the batch sell transaction\n */\nexport const toQuoteAndTxMetadataBatch = ({\n quoteResponses,\n batchSellTrades,\n}: {\n quoteResponses: (QuoteResponse<TxData, TxData> & QuoteMetadata)[];\n batchSellTrades: BatchSellTradesResponse;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const {\n transactions,\n gasIncluded7702,\n gasIncluded,\n gasSponsored = false,\n } = batchSellTrades;\n\n for (const transaction of transactions) {\n const { type, maxFeePerGas, maxPriorityFeePerGas, ...tx } = transaction;\n // Match the trade or approval tx data with the quote response\n const matchingQuoteResponse =\n quoteResponses.find(\n ({ approval, trade }) =>\n trade?.data.toLowerCase() === tx.data.toLowerCase() ||\n approval?.data.toLowerCase() === tx.data.toLowerCase(),\n ) ?? quoteResponses[0];\n\n // Include gasIncluded and gasIncluded7702 from the gasless batch\n const normalizedQuote = {\n ...matchingQuoteResponse,\n quote: {\n ...matchingQuoteResponse.quote,\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n };\n\n const commonTradeData = {\n tx,\n quoteResponse: normalizedQuote,\n txFee: { maxFeePerGas, maxPriorityFeePerGas },\n };\n\n if (type === BatchSellTransactionType.TRADE) {\n tradeData.push({\n ...commonTradeData,\n type: TransactionType.swap,\n assetsFiatValues: {\n sending:\n matchingQuoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving:\n matchingQuoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n } else {\n tradeData.push({\n ...commonTradeData,\n type:\n type === BatchSellTransactionType.APPROVAL\n ? TransactionType.swapApproval\n : TransactionType.tokenMethodTransfer,\n });\n }\n }\n\n return tradeData;\n};\n\n/**\n * Appends the gas fee estimates for a transaction and normalizes the trade data\n *\n * @param messenger - The messenger for the gas fee estimates\n * @param trade - the trade data to append gas fees to\n * @param trade.chainId - ignored, use chainId instead\n * @param trade.gasLimit - the gas limit to use for the gas fee estimates\n * @param networkClientId - the network client ID to use for the gas fee estimates\n * @param chainId - the chain ID to use for the gas fee estimates\n * @param simulatedGasFeeLimits - either the txFee from the quote or the simulated gas fee limits for the batch sell\n * @returns The gas fee estimates for the transaction\n */\nexport const toTransactionParams = async (\n messenger: BridgeStatusControllerMessenger,\n { chainId: tradeChainId, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n simulatedGasFeeLimits?: SimulatedGasFeeLimits | TxFeeGasLimits,\n): Promise<BatchTransactionParams> => {\n const normalizedTrade = {\n ...trade,\n data: trade.data,\n to: trade.to,\n from: trade.from,\n value: trade.value,\n };\n const transactionParams = {\n ...normalizedTrade,\n // Only add gasLimit and gas if they're truthy\n gas: gasLimit ? toHex(gasLimit) : undefined,\n };\n\n // Use bridge-api's provided gas fee estimates\n if (simulatedGasFeeLimits) {\n return {\n ...transactionParams,\n maxFeePerGas: toHex(simulatedGasFeeLimits.maxFeePerGas),\n maxPriorityFeePerGas: toHex(simulatedGasFeeLimits.maxPriorityFeePerGas),\n };\n }\n\n // Get transaction's 1559 gas fee estimates\n const gasFeeEstimates = await getGasFeeEstimates(messenger, {\n transactionParams,\n networkClientId,\n chainId,\n });\n\n return {\n ...transactionParams,\n maxFeePerGas: gasFeeEstimates?.maxFeePerGas,\n maxPriorityFeePerGas: gasFeeEstimates?.maxPriorityFeePerGas,\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n tradeData,\n requireApproval = false,\n isDelegatedAccount,\n ...addTransactionBatchParams\n}: Partial<Parameters<TransactionController['addTransactionBatch']>[0]> & {\n messenger: BridgeStatusControllerMessenger;\n tradeData: QuoteAndTxMetadata[];\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}): Promise<Parameters<TransactionController['addTransactionBatch']>[0]> => {\n const trade = tradeData[0].tx;\n const selectedAccount = getAccountByAddress(messenger, trade.from);\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);\n\n const transactions: TransactionBatchSingleRequest[] = await Promise.all(\n tradeData.map(async ({ tx, txFee, assetsFiatValues, type }) => ({\n params: await toTransactionParams(\n messenger,\n tx,\n networkClientId,\n hexChainId,\n txFee,\n ),\n assetsFiatValues,\n type,\n })),\n );\n\n return {\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: selectedAccount.address as Hex,\n isInternal: true,\n transactions,\n ...addTransactionBatchParams,\n };\n};\n\nexport const findAllTransactionsInBatch = ({\n messenger,\n batchId,\n tradeData,\n}: {\n messenger: BridgeStatusControllerMessenger;\n batchId: string;\n tradeData: QuoteAndTxMetadata[];\n}): QuoteAndTxMetadata[] => {\n // Filter for transactions with batchId\n const txs = getTransactions(messenger).filter(\n (tx: TransactionMeta) => tx.batchId === batchId,\n );\n\n return tradeData.map((tradeWithMetadata) => {\n const { tx, type } = tradeWithMetadata;\n return {\n ...tradeWithMetadata,\n txMeta: txs.find((txMeta: TransactionMeta) => {\n if (is7702Tx(txMeta)) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (isTradeTx(type) && txMeta.type === TransactionType.batch) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (isApprovalTx(type) && txMeta.txParams.data === tx.data) {\n return true;\n }\n }\n // Default matching logic for non-7702 transactions\n if (txMeta.txParams.data === tx.data) {\n return true;\n }\n return false;\n }),\n };\n });\n};\n\n/**\n * This is a workaround to update the tx type after submission. Batch txs are submitted with\n * the \"batch\" type, but we need to update to swap/bridge for display purposes.\n *\n * @param params - The parameters for the transaction search\n * @param params.messenger - The messenger to use for the transaction\n * @param params.allTradesWithMetadata - The quote, tx data and type for each transaction in the batch\n * @returns A list of transaction metas for each trade in the batch]\n *\n * @example\n * [\n * {...tradeData[0], tradeMeta: TransactionMeta}\n * {...tradeData[1], tradeMeta: TransactionMeta}\n * {...tradeData[2], tradeMeta: TransactionMeta}\n * {...tradeData[3], tradeMeta: TransactionMeta}\n * ]\n */\nexport const updateTransactionsInBatch = ({\n messenger,\n allTradesWithMetadata,\n}: {\n messenger: BridgeStatusControllerMessenger;\n allTradesWithMetadata: QuoteAndTxMetadata[];\n}) => {\n return allTradesWithMetadata.map((tradeWithMetadata) => {\n const { txMeta, type } = tradeWithMetadata;\n\n if (txMeta) {\n // Update the tx type from batch to swap/bridge\n updateTransaction(\n messenger,\n txMeta,\n { type },\n `Update tx type to ${type}`,\n );\n const updatedTx = { ...txMeta, type };\n return { ...tradeWithMetadata, txMeta: updatedTx, type };\n }\n\n return tradeWithMetadata;\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,mEAOqC;AAUrC,iEAAmD;AACnD,6EAI0C;AAQ1C,2CAAyE;AAGzE,gDAAiD;AAGjD,6CAAiD;AACjD,2CAAwD;AAEjD,MAAM,YAAY,GAAG,CAAC,IAAqB,EAAE,EAAE,CACpD,IAAI,KAAK,wCAAe,CAAC,cAAc;IACvC,IAAI,KAAK,wCAAe,CAAC,YAAY,CAAC;AAF3B,QAAA,YAAY,gBAEe;AACjC,MAAM,SAAS,GAAG,CAAC,IAAqB,EAAE,EAAE,CACjD,IAAI,KAAK,wCAAe,CAAC,MAAM,IAAI,IAAI,KAAK,wCAAe,CAAC,IAAI,CAAC;AADtD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CAAC,CAAC;AAtCW,QAAA,0BAA0B,8BAsCrC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,yBAAyB,GAAG,CAAC,EACxC,SAAS,EACT,qBAAqB,GAItB,EAAE,EAAE;IACH,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,EAAE;QACrD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,iBAAiB,CAAC;QAE3C,IAAI,MAAM,EAAE,CAAC;YACX,+CAA+C;YAC/C,IAAA,yBAAiB,EACf,SAAS,EACT,MAAM,EACN,EAAE,IAAI,EAAE,EACR,qBAAqB,IAAI,EAAE,CAC5B,CAAC;YACF,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;YACtC,OAAO,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC3D,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAxBW,QAAA,yBAAyB,6BAwBpC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n ChainId,\n formatChainIdToHex,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n isEvmTxData,\n FeeType,\n BatchSellTransactionType,\n} from '@metamask/bridge-controller';\nimport type {\n BatchSellTradesResponse,\n QuoteMetadata,\n QuoteResponse,\n SimulatedGasFeeLimits,\n Trade,\n TxData,\n TxFeeGasLimits,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n GasFeeEstimateType,\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n TransactionMeta,\n TransactionBatchSingleRequest,\n BatchTransactionParams,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger, isStrictHexString } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type { BridgeStatusControllerMessenger } from '../types';\nimport type { QuoteAndTxMetadata } from '../types';\nimport { getAccountByAddress } from './accounts';\nimport { getNetworkClientIdByChainId } from './network';\n\nexport const isApprovalTx = (type: TransactionType) =>\n type === TransactionType.bridgeApproval ||\n type === TransactionType.swapApproval;\nexport const isTradeTx = (type: TransactionType) =>\n type === TransactionType.bridge || type === TransactionType.swap;\nexport const isCrossChainTx = (type: TransactionType) =>\n isTradeTx(type) || isApprovalTx(type);\n\n/**\n * For 7702 delegated transactions, check for delegation-specific fields\n * These transactions might have authorizationList or delegationAddress\n *\n * @param tx - The transaction meta\n * @returns Whether the transaction is a 7702 transaction\n */\nexport const is7702Tx = (tx: TransactionMeta) => {\n return (\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress)\n );\n};\n\nexport const shouldDisable7702 = (\n gasIncluded7702: boolean = false,\n gasIncluded: boolean = false,\n isDelegatedAccount: boolean = false,\n): boolean => {\n // Enable 7702 batching when the quote includes gasless 7702 support\n if (gasIncluded7702) {\n return false;\n }\n // Enable batching when the account is already delegated (to avoid the in-flight transaction limit for delegated accounts)\n // For gasless transactions with STX/sendBundle we keep disabling 7702\n if (isDelegatedAccount && !gasIncluded) {\n return false;\n }\n /**\n * Explicitly return default instead of falsy value (see TransactionBatchRequest.disable7702)\n */\n return true;\n};\n\nexport const hasNestedSwapTransactions = (txMeta: TransactionMeta) => {\n return Boolean(\n txMeta?.nestedTransactions?.some((tx) => tx.type === TransactionType.swap),\n );\n};\n\nexport const getGasFeeEstimates = async (\n messenger: BridgeStatusControllerMessenger,\n args: Parameters<TransactionController['estimateGasFee']>[0],\n) => {\n const { estimates } = await messenger.call(\n 'TransactionController:estimateGasFee',\n args,\n );\n\n if (estimates?.type === GasFeeEstimateType.FeeMarket) {\n return estimates[BRIDGE_PREFERRED_GAS_ESTIMATE];\n }\n\n return undefined;\n};\n\nexport const getTransactions = (messenger: BridgeStatusControllerMessenger) => {\n return messenger.call('TransactionController:getState').transactions ?? [];\n};\n\nexport const getTransactionMetaById = (\n messenger: BridgeStatusControllerMessenger,\n txId?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.id === txId,\n );\n};\n\nexport const getTransactionMetaByHash = (\n messenger: BridgeStatusControllerMessenger,\n txHash?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.hash?.toLowerCase() === txHash?.toLowerCase(),\n );\n};\n\nexport const updateTransaction = (\n messenger: BridgeStatusControllerMessenger,\n txMeta: TransactionMeta,\n txMetaUpdates: Partial<TransactionMeta>,\n note: string,\n) => {\n return messenger.call(\n 'TransactionController:updateTransaction',\n { ...txMeta, ...txMetaUpdates },\n note,\n );\n};\n\nexport const checkIsDelegatedAccount = async (\n messenger: BridgeStatusControllerMessenger,\n fromAddress: Hex,\n chainIds: Hex[],\n): Promise<boolean> => {\n try {\n const atomicBatchSupport = await messenger.call(\n 'TransactionController:isAtomicBatchSupported',\n {\n address: fromAddress,\n chainIds,\n },\n );\n return atomicBatchSupport.some(\n (entry: IsAtomicBatchSupportedResultEntry) =>\n entry.isSupported && entry.delegationAddress,\n );\n } catch {\n return false;\n }\n};\n\nconst waitForHashAndReturnFinalTxMeta = async (\n messenger: BridgeStatusControllerMessenger,\n hashPromise?: Awaited<\n ReturnType<TransactionController['addTransaction']>\n >['result'],\n): Promise<TransactionMeta> => {\n const txHash = await hashPromise;\n const finalTransactionMeta = getTransactionMetaByHash(messenger, txHash);\n if (!finalTransactionMeta) {\n throw new Error(\n 'Failed to submit cross-chain swap tx: txMeta for txHash was not found',\n );\n }\n return finalTransactionMeta;\n};\n\nexport const addTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { result } = await messenger.call(\n 'TransactionController:addTransaction',\n ...args,\n );\n return await waitForHashAndReturnFinalTxMeta(messenger, result);\n};\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\n/**\n * Adds a synthetic transaction to the TransactionController to display pending intent orders in the UI\n *\n * @param messenger - The messenger to use for the transaction\n * @param args - The arguments for the transaction\n * @returns The transaction meta\n */\nexport const addSyntheticTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { transactionMeta } = await messenger.call(\n 'TransactionController:addTransaction',\n args[0],\n {\n origin: 'metamask',\n actionId: generateActionId(),\n isStateOnly: true,\n isInternal: true,\n ...args[1],\n },\n );\n return transactionMeta;\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.\n *\n * @deprecated use addTransaction util\n * @param messenger - the BridgeStatusControllerMessenger\n * @param txId - the transaction ID\n * @param options - the options for the timeout and poll\n * @param options.timeoutMs - the timeout in milliseconds\n * @param options.pollMs - the poll interval in milliseconds\n * @returns the transaction meta\n */\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const meta = getTransactionMetaById(messenger, txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\n\nexport const toQuoteAndTxMetadata = ({\n quoteResponse,\n isBridgeTx,\n}: {\n quoteResponse: QuoteResponse<Trade, Trade> & QuoteMetadata;\n isBridgeTx: boolean;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const approvalTxType = isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval;\n\n if (quoteResponse.resetApproval) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.resetApproval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n if (quoteResponse.approval && isEvmTxData(quoteResponse.approval)) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.approval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.trade as TxData,\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n assetsFiatValues: {\n sending: quoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving: quoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n\n return tradeData;\n};\n\n/**\n * Build the trade+quote metadata array for the batch sell transaction\n * This ties together the quote, the tx params and the txMeta after submission\n *\n * @param options - The options for the batch sell transaction\n * @param options.quoteResponses - The quote responses for the batch sell transaction\n * @param options.batchSellTrades - The batch sell trades for the batch sell transaction\n * @returns The trade+quote metadata array for the batch sell transaction\n */\nexport const toQuoteAndTxMetadataBatch = ({\n quoteResponses,\n batchSellTrades,\n}: {\n quoteResponses: (QuoteResponse<TxData, TxData> & QuoteMetadata)[];\n batchSellTrades: BatchSellTradesResponse;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const {\n transactions,\n gasIncluded7702,\n gasIncluded,\n gasSponsored = false,\n } = batchSellTrades;\n\n for (const transaction of transactions) {\n const { type, maxFeePerGas, maxPriorityFeePerGas, ...tx } = transaction;\n // Match the trade or approval tx data with the quote response\n const matchingQuoteResponse =\n quoteResponses.find(\n ({ approval, trade }) =>\n trade?.data.toLowerCase() === tx.data.toLowerCase() ||\n approval?.data.toLowerCase() === tx.data.toLowerCase(),\n ) ?? quoteResponses[0];\n\n // Include gasIncluded and gasIncluded7702 from the gasless batch\n const normalizedQuote = {\n ...matchingQuoteResponse,\n quote: {\n ...matchingQuoteResponse.quote,\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n };\n\n const commonTradeData = {\n tx,\n quoteResponse: normalizedQuote,\n txFee: { maxFeePerGas, maxPriorityFeePerGas },\n };\n\n if (type === BatchSellTransactionType.TRADE) {\n tradeData.push({\n ...commonTradeData,\n type: TransactionType.swap,\n assetsFiatValues: {\n sending:\n matchingQuoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving:\n matchingQuoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n } else {\n tradeData.push({\n ...commonTradeData,\n type:\n type === BatchSellTransactionType.APPROVAL\n ? TransactionType.swapApproval\n : TransactionType.tokenMethodTransfer,\n });\n }\n }\n\n return tradeData;\n};\n\n/**\n * Appends the gas fee estimates for a transaction and normalizes the trade data\n *\n * @param messenger - The messenger for the gas fee estimates\n * @param trade - the trade data to append gas fees to\n * @param trade.chainId - ignored, use chainId instead\n * @param trade.gasLimit - the gas limit to use for the gas fee estimates\n * @param networkClientId - the network client ID to use for the gas fee estimates\n * @param chainId - the chain ID to use for the gas fee estimates\n * @param simulatedGasFeeLimits - either the txFee from the quote or the simulated gas fee limits for the batch sell\n * @returns The gas fee estimates for the transaction\n */\nexport const toTransactionParams = async (\n messenger: BridgeStatusControllerMessenger,\n { chainId: tradeChainId, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n simulatedGasFeeLimits?: SimulatedGasFeeLimits | TxFeeGasLimits,\n): Promise<BatchTransactionParams> => {\n const transactionParams = {\n data: trade.data,\n to: trade.to,\n from: trade.from,\n value: trade.value,\n // Only add gas if it's truthy\n gas: gasLimit ? toHex(gasLimit) : undefined,\n };\n\n // Use bridge-api's provided gas fee estimates\n if (simulatedGasFeeLimits) {\n return {\n ...transactionParams,\n // Sometimes estimates are hex, somethings numeric strings\n maxFeePerGas: isStrictHexString(simulatedGasFeeLimits.maxFeePerGas)\n ? simulatedGasFeeLimits.maxFeePerGas\n : toHex(simulatedGasFeeLimits.maxFeePerGas),\n maxPriorityFeePerGas: isStrictHexString(\n simulatedGasFeeLimits.maxPriorityFeePerGas,\n )\n ? simulatedGasFeeLimits.maxPriorityFeePerGas\n : toHex(simulatedGasFeeLimits.maxPriorityFeePerGas),\n };\n }\n\n // Get transaction's 1559 gas fee estimates\n const gasFeeEstimates = await getGasFeeEstimates(messenger, {\n transactionParams,\n networkClientId,\n chainId,\n });\n\n return {\n ...transactionParams,\n maxFeePerGas: gasFeeEstimates?.maxFeePerGas,\n maxPriorityFeePerGas: gasFeeEstimates?.maxPriorityFeePerGas,\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n tradeData,\n requireApproval = false,\n isDelegatedAccount,\n ...addTransactionBatchParams\n}: Partial<Parameters<TransactionController['addTransactionBatch']>[0]> & {\n messenger: BridgeStatusControllerMessenger;\n tradeData: QuoteAndTxMetadata[];\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}): Promise<Parameters<TransactionController['addTransactionBatch']>[0]> => {\n const trade = tradeData[0].tx;\n const selectedAccount = getAccountByAddress(messenger, trade.from);\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);\n\n const transactions: TransactionBatchSingleRequest[] = await Promise.all(\n tradeData.map(async ({ tx, txFee, assetsFiatValues, type }) => ({\n params: await toTransactionParams(\n messenger,\n tx,\n networkClientId,\n hexChainId,\n txFee,\n ),\n assetsFiatValues,\n type,\n })),\n );\n\n return {\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: selectedAccount.address as Hex,\n isInternal: true,\n transactions,\n ...addTransactionBatchParams,\n };\n};\n\nexport const findAllTransactionsInBatch = ({\n messenger,\n batchId,\n tradeData,\n}: {\n messenger: BridgeStatusControllerMessenger;\n batchId: string;\n tradeData: QuoteAndTxMetadata[];\n}): QuoteAndTxMetadata[] => {\n // Filter for transactions with batchId\n const txs = getTransactions(messenger).filter(\n (tx: TransactionMeta) => tx.batchId === batchId,\n );\n\n return tradeData.map((tradeWithMetadata) => {\n const { tx, type } = tradeWithMetadata;\n return {\n ...tradeWithMetadata,\n txMeta: txs.find((txMeta: TransactionMeta) => {\n if (is7702Tx(txMeta)) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (isTradeTx(type) && txMeta.type === TransactionType.batch) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (isApprovalTx(type) && txMeta.txParams.data === tx.data) {\n return true;\n }\n }\n // Default matching logic for non-7702 transactions\n if (txMeta.txParams.data === tx.data) {\n return true;\n }\n return false;\n }),\n };\n });\n};\n\n/**\n * This is a workaround to update the tx type after submission. Batch txs are submitted with\n * the \"batch\" type, but we need to update to swap/bridge for display purposes.\n *\n * @param params - The parameters for the transaction search\n * @param params.messenger - The messenger to use for the transaction\n * @param params.allTradesWithMetadata - The quote, tx data and type for each transaction in the batch\n * @returns A list of transaction metas for each trade in the batch]\n *\n * @example\n * [\n * {...tradeData[0], tradeMeta: TransactionMeta}\n * {...tradeData[1], tradeMeta: TransactionMeta}\n * {...tradeData[2], tradeMeta: TransactionMeta}\n * {...tradeData[3], tradeMeta: TransactionMeta}\n * ]\n */\nexport const updateTransactionsInBatch = ({\n messenger,\n allTradesWithMetadata,\n}: {\n messenger: BridgeStatusControllerMessenger;\n allTradesWithMetadata: QuoteAndTxMetadata[];\n}) => {\n return allTradesWithMetadata.map((tradeWithMetadata) => {\n const { txMeta, type } = tradeWithMetadata;\n\n if (txMeta) {\n // Update the tx type from batch to swap/bridge\n updateTransaction(\n messenger,\n txMeta,\n { type },\n `Update tx type to ${type}`,\n );\n const updatedTx = { ...txMeta, type };\n return { ...tradeWithMetadata, txMeta: updatedTx, type };\n }\n\n return tradeWithMetadata;\n });\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,KAAK,EACL,MAAM,EACN,cAAc,EACf,oCAAoC;AAErC,OAAO,EAGL,eAAe,EAChB,yCAAyC;AAC1C,OAAO,KAAK,EAEV,qBAAqB,EACrB,eAAe,EAEf,sBAAsB,EACvB,yCAAyC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAiB;AAInD,eAAO,MAAM,YAAY,SAAU,eAAe,YAEX,CAAC;AACxC,eAAO,MAAM,SAAS,SAAU,eAAe,YACmB,CAAC;AACnE,eAAO,MAAM,cAAc,SAAU,eAAe,YACb,CAAC;AAExC;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,OAAQ,eAAe,YAM3C,CAAC;AAEF,eAAO,MAAM,i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,EAAE;0BAmB5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,KAAK,EACL,MAAM,EACN,cAAc,EACf,oCAAoC;AAErC,OAAO,EAGL,eAAe,EAChB,yCAAyC;AAC1C,OAAO,KAAK,EAEV,qBAAqB,EACrB,eAAe,EAEf,sBAAsB,EACvB,yCAAyC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAiB;AAInD,eAAO,MAAM,YAAY,SAAU,eAAe,YAEX,CAAC;AACxC,eAAO,MAAM,SAAS,SAAU,eAAe,YACmB,CAAC;AACnE,eAAO,MAAM,cAAc,SAAU,eAAe,YACb,CAAC;AAExC;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,OAAQ,eAAe,YAM3C,CAAC;AAEF,eAAO,MAAM,iBAAiB,qBACX,OAAO,gBACX,OAAO,uBACA,OAAO,KAC1B,
|
|
1
|
+
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,KAAK,EACL,MAAM,EACN,cAAc,EACf,oCAAoC;AAErC,OAAO,EAGL,eAAe,EAChB,yCAAyC;AAC1C,OAAO,KAAK,EAEV,qBAAqB,EACrB,eAAe,EAEf,sBAAsB,EACvB,yCAAyC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,qBAAiB;AAInD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,CAAC,GAAG,aAAa;gBAC9C,OAAO;MACjB,KAAK,kBAAkB,EAAE,QAAQ,CAAC,EAmCrC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB;oBAIpB,CAAC,cAAc,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,EAAE;qBAChD,uBAAuB;MACtC,KAAK,kBAAkB,EAAE,QAAQ,CAAC,EA4DrC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,8FAEiB,MAAM,mBACpC,MAAM,WACd,GAAG,0BACY,qBAAqB,GAAG,cAAc,KAC7D,QAAQ,sBAAsB,CAsChC,CAAC;AAEF,eAAO,MAAM,4BAA4B;;eAQ5B,kBAAkB,EAAE;;;MAG7B,QAAQ,WAAW,qBAAqB,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAkCtE,CAAC;AAEF,eAAO,MAAM,0BAA0B;;aAM5B,MAAM;eACJ,kBAAkB,EAAE;MAC7B,kBAAkB,EA8BrB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,yBAAyB;;2BAKb,kBAAkB,EAAE;0BAmB5C,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ChainId, formatChainIdToHex, BRIDGE_PREFERRED_GAS_ESTIMATE, isEvmTxData, FeeType, BatchSellTransactionType } from "@metamask/bridge-controller";
|
|
3
3
|
import { toHex } from "@metamask/controller-utils";
|
|
4
4
|
import { GasFeeEstimateType, TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
5
|
-
import { createProjectLogger } from "@metamask/utils";
|
|
5
|
+
import { createProjectLogger, isStrictHexString } from "@metamask/utils";
|
|
6
6
|
import { APPROVAL_DELAY_MS } from "../constants.mjs";
|
|
7
7
|
import { getAccountByAddress } from "./accounts.mjs";
|
|
8
8
|
import { getNetworkClientIdByChainId } from "./network.mjs";
|
|
@@ -28,12 +28,9 @@ export const shouldDisable7702 = (gasIncluded7702 = false, gasIncluded = false,
|
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
// Enable batching when the account is already delegated (to avoid the in-flight transaction limit for delegated accounts)
|
|
31
|
-
if (isDelegatedAccount) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
31
|
// For gasless transactions with STX/sendBundle we keep disabling 7702
|
|
35
|
-
if (gasIncluded) {
|
|
36
|
-
return
|
|
32
|
+
if (isDelegatedAccount && !gasIncluded) {
|
|
33
|
+
return false;
|
|
37
34
|
}
|
|
38
35
|
/**
|
|
39
36
|
* Explicitly return default instead of falsy value (see TransactionBatchRequest.disable7702)
|
|
@@ -255,24 +252,25 @@ export const toQuoteAndTxMetadataBatch = ({ quoteResponses, batchSellTrades, })
|
|
|
255
252
|
* @returns The gas fee estimates for the transaction
|
|
256
253
|
*/
|
|
257
254
|
export const toTransactionParams = async (messenger, { chainId: tradeChainId, gasLimit, ...trade }, networkClientId, chainId, simulatedGasFeeLimits) => {
|
|
258
|
-
const
|
|
259
|
-
...trade,
|
|
255
|
+
const transactionParams = {
|
|
260
256
|
data: trade.data,
|
|
261
257
|
to: trade.to,
|
|
262
258
|
from: trade.from,
|
|
263
259
|
value: trade.value,
|
|
264
|
-
|
|
265
|
-
const transactionParams = {
|
|
266
|
-
...normalizedTrade,
|
|
267
|
-
// Only add gasLimit and gas if they're truthy
|
|
260
|
+
// Only add gas if it's truthy
|
|
268
261
|
gas: gasLimit ? toHex(gasLimit) : undefined,
|
|
269
262
|
};
|
|
270
263
|
// Use bridge-api's provided gas fee estimates
|
|
271
264
|
if (simulatedGasFeeLimits) {
|
|
272
265
|
return {
|
|
273
266
|
...transactionParams,
|
|
274
|
-
|
|
275
|
-
|
|
267
|
+
// Sometimes estimates are hex, somethings numeric strings
|
|
268
|
+
maxFeePerGas: isStrictHexString(simulatedGasFeeLimits.maxFeePerGas)
|
|
269
|
+
? simulatedGasFeeLimits.maxFeePerGas
|
|
270
|
+
: toHex(simulatedGasFeeLimits.maxFeePerGas),
|
|
271
|
+
maxPriorityFeePerGas: isStrictHexString(simulatedGasFeeLimits.maxPriorityFeePerGas)
|
|
272
|
+
? simulatedGasFeeLimits.maxPriorityFeePerGas
|
|
273
|
+
: toHex(simulatedGasFeeLimits.maxPriorityFeePerGas),
|
|
276
274
|
};
|
|
277
275
|
}
|
|
278
276
|
// Get transaction's 1559 gas fee estimates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,6BAA6B,EAC7B,WAAW,EACX,OAAO,EACP,wBAAwB,EACzB,oCAAoC;AAUrC,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EAChB,yCAAyC;AAQ1C,OAAO,EAAE,mBAAmB,EAAE,wBAAwB;AAGtD,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AAGjD,OAAO,EAAE,mBAAmB,EAAE,uBAAmB;AACjD,OAAO,EAAE,2BAA2B,EAAE,sBAAkB;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAqB,EAAE,EAAE,CACpD,IAAI,KAAK,eAAe,CAAC,cAAc;IACvC,IAAI,KAAK,eAAe,CAAC,YAAY,CAAC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAqB,EAAE,EAAE,CACjD,IAAI,KAAK,eAAe,CAAC,MAAM,IAAI,IAAI,KAAK,eAAe,CAAC,IAAI,CAAC;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAqB,EAAE,EAAE,CACtD,SAAS,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAmB,EAAE,EAAE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BACd,CAAC;oBACD,sDAAsD;oBACtD,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;wBAC3D,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;gBACD,mDAAmD;gBACnD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;oBACrC,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC,CAAC;SACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,EACxC,SAAS,EACT,qBAAqB,GAItB,EAAE,EAAE;IACH,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,EAAE;QACrD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,iBAAiB,CAAC;QAE3C,IAAI,MAAM,EAAE,CAAC;YACX,+CAA+C;YAC/C,iBAAiB,CACf,SAAS,EACT,MAAM,EACN,EAAE,IAAI,EAAE,EACR,qBAAqB,IAAI,EAAE,CAC5B,CAAC;YACF,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;YACtC,OAAO,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC3D,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n ChainId,\n formatChainIdToHex,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n isEvmTxData,\n FeeType,\n BatchSellTransactionType,\n} from '@metamask/bridge-controller';\nimport type {\n BatchSellTradesResponse,\n QuoteMetadata,\n QuoteResponse,\n SimulatedGasFeeLimits,\n Trade,\n TxData,\n TxFeeGasLimits,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n GasFeeEstimateType,\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n TransactionMeta,\n TransactionBatchSingleRequest,\n BatchTransactionParams,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type { BridgeStatusControllerMessenger } from '../types';\nimport type { QuoteAndTxMetadata } from '../types';\nimport { getAccountByAddress } from './accounts';\nimport { getNetworkClientIdByChainId } from './network';\n\nexport const isApprovalTx = (type: TransactionType) =>\n type === TransactionType.bridgeApproval ||\n type === TransactionType.swapApproval;\nexport const isTradeTx = (type: TransactionType) =>\n type === TransactionType.bridge || type === TransactionType.swap;\nexport const isCrossChainTx = (type: TransactionType) =>\n isTradeTx(type) || isApprovalTx(type);\n\n/**\n * For 7702 delegated transactions, check for delegation-specific fields\n * These transactions might have authorizationList or delegationAddress\n *\n * @param tx - The transaction meta\n * @returns Whether the transaction is a 7702 transaction\n */\nexport const is7702Tx = (tx: TransactionMeta) => {\n return (\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress)\n );\n};\n\nexport const shouldDisable7702 = (\n gasIncluded7702: boolean = false,\n gasIncluded: boolean = false,\n isDelegatedAccount: boolean = false,\n): boolean => {\n // Enable 7702 batching when the quote includes gasless 7702 support\n if (gasIncluded7702) {\n return false;\n }\n // Enable batching when the account is already delegated (to avoid the in-flight transaction limit for delegated accounts)\n if (isDelegatedAccount) {\n return false;\n }\n // For gasless transactions with STX/sendBundle we keep disabling 7702\n if (gasIncluded) {\n return true;\n }\n /**\n * Explicitly return default instead of falsy value (see TransactionBatchRequest.disable7702)\n */\n return true;\n};\n\nexport const hasNestedSwapTransactions = (txMeta: TransactionMeta) => {\n return Boolean(\n txMeta?.nestedTransactions?.some((tx) => tx.type === TransactionType.swap),\n );\n};\n\nexport const getGasFeeEstimates = async (\n messenger: BridgeStatusControllerMessenger,\n args: Parameters<TransactionController['estimateGasFee']>[0],\n) => {\n const { estimates } = await messenger.call(\n 'TransactionController:estimateGasFee',\n args,\n );\n\n if (estimates?.type === GasFeeEstimateType.FeeMarket) {\n return estimates[BRIDGE_PREFERRED_GAS_ESTIMATE];\n }\n\n return undefined;\n};\n\nexport const getTransactions = (messenger: BridgeStatusControllerMessenger) => {\n return messenger.call('TransactionController:getState').transactions ?? [];\n};\n\nexport const getTransactionMetaById = (\n messenger: BridgeStatusControllerMessenger,\n txId?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.id === txId,\n );\n};\n\nexport const getTransactionMetaByHash = (\n messenger: BridgeStatusControllerMessenger,\n txHash?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.hash?.toLowerCase() === txHash?.toLowerCase(),\n );\n};\n\nexport const updateTransaction = (\n messenger: BridgeStatusControllerMessenger,\n txMeta: TransactionMeta,\n txMetaUpdates: Partial<TransactionMeta>,\n note: string,\n) => {\n return messenger.call(\n 'TransactionController:updateTransaction',\n { ...txMeta, ...txMetaUpdates },\n note,\n );\n};\n\nexport const checkIsDelegatedAccount = async (\n messenger: BridgeStatusControllerMessenger,\n fromAddress: Hex,\n chainIds: Hex[],\n): Promise<boolean> => {\n try {\n const atomicBatchSupport = await messenger.call(\n 'TransactionController:isAtomicBatchSupported',\n {\n address: fromAddress,\n chainIds,\n },\n );\n return atomicBatchSupport.some(\n (entry: IsAtomicBatchSupportedResultEntry) =>\n entry.isSupported && entry.delegationAddress,\n );\n } catch {\n return false;\n }\n};\n\nconst waitForHashAndReturnFinalTxMeta = async (\n messenger: BridgeStatusControllerMessenger,\n hashPromise?: Awaited<\n ReturnType<TransactionController['addTransaction']>\n >['result'],\n): Promise<TransactionMeta> => {\n const txHash = await hashPromise;\n const finalTransactionMeta = getTransactionMetaByHash(messenger, txHash);\n if (!finalTransactionMeta) {\n throw new Error(\n 'Failed to submit cross-chain swap tx: txMeta for txHash was not found',\n );\n }\n return finalTransactionMeta;\n};\n\nexport const addTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { result } = await messenger.call(\n 'TransactionController:addTransaction',\n ...args,\n );\n return await waitForHashAndReturnFinalTxMeta(messenger, result);\n};\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\n/**\n * Adds a synthetic transaction to the TransactionController to display pending intent orders in the UI\n *\n * @param messenger - The messenger to use for the transaction\n * @param args - The arguments for the transaction\n * @returns The transaction meta\n */\nexport const addSyntheticTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { transactionMeta } = await messenger.call(\n 'TransactionController:addTransaction',\n args[0],\n {\n origin: 'metamask',\n actionId: generateActionId(),\n isStateOnly: true,\n isInternal: true,\n ...args[1],\n },\n );\n return transactionMeta;\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.\n *\n * @deprecated use addTransaction util\n * @param messenger - the BridgeStatusControllerMessenger\n * @param txId - the transaction ID\n * @param options - the options for the timeout and poll\n * @param options.timeoutMs - the timeout in milliseconds\n * @param options.pollMs - the poll interval in milliseconds\n * @returns the transaction meta\n */\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const meta = getTransactionMetaById(messenger, txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\n\nexport const toQuoteAndTxMetadata = ({\n quoteResponse,\n isBridgeTx,\n}: {\n quoteResponse: QuoteResponse<Trade, Trade> & QuoteMetadata;\n isBridgeTx: boolean;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const approvalTxType = isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval;\n\n if (quoteResponse.resetApproval) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.resetApproval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n if (quoteResponse.approval && isEvmTxData(quoteResponse.approval)) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.approval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.trade as TxData,\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n assetsFiatValues: {\n sending: quoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving: quoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n\n return tradeData;\n};\n\n/**\n * Build the trade+quote metadata array for the batch sell transaction\n * This ties together the quote, the tx params and the txMeta after submission\n *\n * @param options - The options for the batch sell transaction\n * @param options.quoteResponses - The quote responses for the batch sell transaction\n * @param options.batchSellTrades - The batch sell trades for the batch sell transaction\n * @returns The trade+quote metadata array for the batch sell transaction\n */\nexport const toQuoteAndTxMetadataBatch = ({\n quoteResponses,\n batchSellTrades,\n}: {\n quoteResponses: (QuoteResponse<TxData, TxData> & QuoteMetadata)[];\n batchSellTrades: BatchSellTradesResponse;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const {\n transactions,\n gasIncluded7702,\n gasIncluded,\n gasSponsored = false,\n } = batchSellTrades;\n\n for (const transaction of transactions) {\n const { type, maxFeePerGas, maxPriorityFeePerGas, ...tx } = transaction;\n // Match the trade or approval tx data with the quote response\n const matchingQuoteResponse =\n quoteResponses.find(\n ({ approval, trade }) =>\n trade?.data.toLowerCase() === tx.data.toLowerCase() ||\n approval?.data.toLowerCase() === tx.data.toLowerCase(),\n ) ?? quoteResponses[0];\n\n // Include gasIncluded and gasIncluded7702 from the gasless batch\n const normalizedQuote = {\n ...matchingQuoteResponse,\n quote: {\n ...matchingQuoteResponse.quote,\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n };\n\n const commonTradeData = {\n tx,\n quoteResponse: normalizedQuote,\n txFee: { maxFeePerGas, maxPriorityFeePerGas },\n };\n\n if (type === BatchSellTransactionType.TRADE) {\n tradeData.push({\n ...commonTradeData,\n type: TransactionType.swap,\n assetsFiatValues: {\n sending:\n matchingQuoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving:\n matchingQuoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n } else {\n tradeData.push({\n ...commonTradeData,\n type:\n type === BatchSellTransactionType.APPROVAL\n ? TransactionType.swapApproval\n : TransactionType.tokenMethodTransfer,\n });\n }\n }\n\n return tradeData;\n};\n\n/**\n * Appends the gas fee estimates for a transaction and normalizes the trade data\n *\n * @param messenger - The messenger for the gas fee estimates\n * @param trade - the trade data to append gas fees to\n * @param trade.chainId - ignored, use chainId instead\n * @param trade.gasLimit - the gas limit to use for the gas fee estimates\n * @param networkClientId - the network client ID to use for the gas fee estimates\n * @param chainId - the chain ID to use for the gas fee estimates\n * @param simulatedGasFeeLimits - either the txFee from the quote or the simulated gas fee limits for the batch sell\n * @returns The gas fee estimates for the transaction\n */\nexport const toTransactionParams = async (\n messenger: BridgeStatusControllerMessenger,\n { chainId: tradeChainId, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n simulatedGasFeeLimits?: SimulatedGasFeeLimits | TxFeeGasLimits,\n): Promise<BatchTransactionParams> => {\n const normalizedTrade = {\n ...trade,\n data: trade.data,\n to: trade.to,\n from: trade.from,\n value: trade.value,\n };\n const transactionParams = {\n ...normalizedTrade,\n // Only add gasLimit and gas if they're truthy\n gas: gasLimit ? toHex(gasLimit) : undefined,\n };\n\n // Use bridge-api's provided gas fee estimates\n if (simulatedGasFeeLimits) {\n return {\n ...transactionParams,\n maxFeePerGas: toHex(simulatedGasFeeLimits.maxFeePerGas),\n maxPriorityFeePerGas: toHex(simulatedGasFeeLimits.maxPriorityFeePerGas),\n };\n }\n\n // Get transaction's 1559 gas fee estimates\n const gasFeeEstimates = await getGasFeeEstimates(messenger, {\n transactionParams,\n networkClientId,\n chainId,\n });\n\n return {\n ...transactionParams,\n maxFeePerGas: gasFeeEstimates?.maxFeePerGas,\n maxPriorityFeePerGas: gasFeeEstimates?.maxPriorityFeePerGas,\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n tradeData,\n requireApproval = false,\n isDelegatedAccount,\n ...addTransactionBatchParams\n}: Partial<Parameters<TransactionController['addTransactionBatch']>[0]> & {\n messenger: BridgeStatusControllerMessenger;\n tradeData: QuoteAndTxMetadata[];\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}): Promise<Parameters<TransactionController['addTransactionBatch']>[0]> => {\n const trade = tradeData[0].tx;\n const selectedAccount = getAccountByAddress(messenger, trade.from);\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);\n\n const transactions: TransactionBatchSingleRequest[] = await Promise.all(\n tradeData.map(async ({ tx, txFee, assetsFiatValues, type }) => ({\n params: await toTransactionParams(\n messenger,\n tx,\n networkClientId,\n hexChainId,\n txFee,\n ),\n assetsFiatValues,\n type,\n })),\n );\n\n return {\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: selectedAccount.address as Hex,\n isInternal: true,\n transactions,\n ...addTransactionBatchParams,\n };\n};\n\nexport const findAllTransactionsInBatch = ({\n messenger,\n batchId,\n tradeData,\n}: {\n messenger: BridgeStatusControllerMessenger;\n batchId: string;\n tradeData: QuoteAndTxMetadata[];\n}): QuoteAndTxMetadata[] => {\n // Filter for transactions with batchId\n const txs = getTransactions(messenger).filter(\n (tx: TransactionMeta) => tx.batchId === batchId,\n );\n\n return tradeData.map((tradeWithMetadata) => {\n const { tx, type } = tradeWithMetadata;\n return {\n ...tradeWithMetadata,\n txMeta: txs.find((txMeta: TransactionMeta) => {\n if (is7702Tx(txMeta)) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (isTradeTx(type) && txMeta.type === TransactionType.batch) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (isApprovalTx(type) && txMeta.txParams.data === tx.data) {\n return true;\n }\n }\n // Default matching logic for non-7702 transactions\n if (txMeta.txParams.data === tx.data) {\n return true;\n }\n return false;\n }),\n };\n });\n};\n\n/**\n * This is a workaround to update the tx type after submission. Batch txs are submitted with\n * the \"batch\" type, but we need to update to swap/bridge for display purposes.\n *\n * @param params - The parameters for the transaction search\n * @param params.messenger - The messenger to use for the transaction\n * @param params.allTradesWithMetadata - The quote, tx data and type for each transaction in the batch\n * @returns A list of transaction metas for each trade in the batch]\n *\n * @example\n * [\n * {...tradeData[0], tradeMeta: TransactionMeta}\n * {...tradeData[1], tradeMeta: TransactionMeta}\n * {...tradeData[2], tradeMeta: TransactionMeta}\n * {...tradeData[3], tradeMeta: TransactionMeta}\n * ]\n */\nexport const updateTransactionsInBatch = ({\n messenger,\n allTradesWithMetadata,\n}: {\n messenger: BridgeStatusControllerMessenger;\n allTradesWithMetadata: QuoteAndTxMetadata[];\n}) => {\n return allTradesWithMetadata.map((tradeWithMetadata) => {\n const { txMeta, type } = tradeWithMetadata;\n\n if (txMeta) {\n // Update the tx type from batch to swap/bridge\n updateTransaction(\n messenger,\n txMeta,\n { type },\n `Update tx type to ${type}`,\n );\n const updatedTx = { ...txMeta, type };\n return { ...tradeWithMetadata, txMeta: updatedTx, type };\n }\n\n return tradeWithMetadata;\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,6BAA6B,EAC7B,WAAW,EACX,OAAO,EACP,wBAAwB,EACzB,oCAAoC;AAUrC,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EAChB,yCAAyC;AAQ1C,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,wBAAwB;AAGzE,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AAGjD,OAAO,EAAE,mBAAmB,EAAE,uBAAmB;AACjD,OAAO,EAAE,2BAA2B,EAAE,sBAAkB;AA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BAAiB,CAAC;QAE3C,IAAI,MAAM,EAAE,CAAC;YACX,+CAA+C;YAC/C,iBAAiB,CACf,SAAS,EACT,MAAM,EACN,EAAE,IAAI,EAAE,EACR,qBAAqB,IAAI,EAAE,CAC5B,CAAC;YACF,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;YACtC,OAAO,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC3D,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n ChainId,\n formatChainIdToHex,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n isEvmTxData,\n FeeType,\n BatchSellTransactionType,\n} from '@metamask/bridge-controller';\nimport type {\n BatchSellTradesResponse,\n QuoteMetadata,\n QuoteResponse,\n SimulatedGasFeeLimits,\n Trade,\n TxData,\n TxFeeGasLimits,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n GasFeeEstimateType,\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n TransactionMeta,\n TransactionBatchSingleRequest,\n BatchTransactionParams,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger, isStrictHexString } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type { BridgeStatusControllerMessenger } from '../types';\nimport type { QuoteAndTxMetadata } from '../types';\nimport { getAccountByAddress } from './accounts';\nimport { getNetworkClientIdByChainId } from './network';\n\nexport const isApprovalTx = (type: TransactionType) =>\n type === TransactionType.bridgeApproval ||\n type === TransactionType.swapApproval;\nexport const isTradeTx = (type: TransactionType) =>\n type === TransactionType.bridge || type === TransactionType.swap;\nexport const isCrossChainTx = (type: TransactionType) =>\n isTradeTx(type) || isApprovalTx(type);\n\n/**\n * For 7702 delegated transactions, check for delegation-specific fields\n * These transactions might have authorizationList or delegationAddress\n *\n * @param tx - The transaction meta\n * @returns Whether the transaction is a 7702 transaction\n */\nexport const is7702Tx = (tx: TransactionMeta) => {\n return (\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress)\n );\n};\n\nexport const shouldDisable7702 = (\n gasIncluded7702: boolean = false,\n gasIncluded: boolean = false,\n isDelegatedAccount: boolean = false,\n): boolean => {\n // Enable 7702 batching when the quote includes gasless 7702 support\n if (gasIncluded7702) {\n return false;\n }\n // Enable batching when the account is already delegated (to avoid the in-flight transaction limit for delegated accounts)\n // For gasless transactions with STX/sendBundle we keep disabling 7702\n if (isDelegatedAccount && !gasIncluded) {\n return false;\n }\n /**\n * Explicitly return default instead of falsy value (see TransactionBatchRequest.disable7702)\n */\n return true;\n};\n\nexport const hasNestedSwapTransactions = (txMeta: TransactionMeta) => {\n return Boolean(\n txMeta?.nestedTransactions?.some((tx) => tx.type === TransactionType.swap),\n );\n};\n\nexport const getGasFeeEstimates = async (\n messenger: BridgeStatusControllerMessenger,\n args: Parameters<TransactionController['estimateGasFee']>[0],\n) => {\n const { estimates } = await messenger.call(\n 'TransactionController:estimateGasFee',\n args,\n );\n\n if (estimates?.type === GasFeeEstimateType.FeeMarket) {\n return estimates[BRIDGE_PREFERRED_GAS_ESTIMATE];\n }\n\n return undefined;\n};\n\nexport const getTransactions = (messenger: BridgeStatusControllerMessenger) => {\n return messenger.call('TransactionController:getState').transactions ?? [];\n};\n\nexport const getTransactionMetaById = (\n messenger: BridgeStatusControllerMessenger,\n txId?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.id === txId,\n );\n};\n\nexport const getTransactionMetaByHash = (\n messenger: BridgeStatusControllerMessenger,\n txHash?: string,\n) => {\n return getTransactions(messenger).find(\n (tx: TransactionMeta) => tx.hash?.toLowerCase() === txHash?.toLowerCase(),\n );\n};\n\nexport const updateTransaction = (\n messenger: BridgeStatusControllerMessenger,\n txMeta: TransactionMeta,\n txMetaUpdates: Partial<TransactionMeta>,\n note: string,\n) => {\n return messenger.call(\n 'TransactionController:updateTransaction',\n { ...txMeta, ...txMetaUpdates },\n note,\n );\n};\n\nexport const checkIsDelegatedAccount = async (\n messenger: BridgeStatusControllerMessenger,\n fromAddress: Hex,\n chainIds: Hex[],\n): Promise<boolean> => {\n try {\n const atomicBatchSupport = await messenger.call(\n 'TransactionController:isAtomicBatchSupported',\n {\n address: fromAddress,\n chainIds,\n },\n );\n return atomicBatchSupport.some(\n (entry: IsAtomicBatchSupportedResultEntry) =>\n entry.isSupported && entry.delegationAddress,\n );\n } catch {\n return false;\n }\n};\n\nconst waitForHashAndReturnFinalTxMeta = async (\n messenger: BridgeStatusControllerMessenger,\n hashPromise?: Awaited<\n ReturnType<TransactionController['addTransaction']>\n >['result'],\n): Promise<TransactionMeta> => {\n const txHash = await hashPromise;\n const finalTransactionMeta = getTransactionMetaByHash(messenger, txHash);\n if (!finalTransactionMeta) {\n throw new Error(\n 'Failed to submit cross-chain swap tx: txMeta for txHash was not found',\n );\n }\n return finalTransactionMeta;\n};\n\nexport const addTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { result } = await messenger.call(\n 'TransactionController:addTransaction',\n ...args,\n );\n return await waitForHashAndReturnFinalTxMeta(messenger, result);\n};\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\n/**\n * Adds a synthetic transaction to the TransactionController to display pending intent orders in the UI\n *\n * @param messenger - The messenger to use for the transaction\n * @param args - The arguments for the transaction\n * @returns The transaction meta\n */\nexport const addSyntheticTransaction = async (\n messenger: BridgeStatusControllerMessenger,\n ...args: Parameters<TransactionController['addTransaction']>\n) => {\n const { transactionMeta } = await messenger.call(\n 'TransactionController:addTransaction',\n args[0],\n {\n origin: 'metamask',\n actionId: generateActionId(),\n isStateOnly: true,\n isInternal: true,\n ...args[1],\n },\n );\n return transactionMeta;\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.\n *\n * @deprecated use addTransaction util\n * @param messenger - the BridgeStatusControllerMessenger\n * @param txId - the transaction ID\n * @param options - the options for the timeout and poll\n * @param options.timeoutMs - the timeout in milliseconds\n * @param options.pollMs - the poll interval in milliseconds\n * @returns the transaction meta\n */\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const meta = getTransactionMetaById(messenger, txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\n\nexport const toQuoteAndTxMetadata = ({\n quoteResponse,\n isBridgeTx,\n}: {\n quoteResponse: QuoteResponse<Trade, Trade> & QuoteMetadata;\n isBridgeTx: boolean;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const approvalTxType = isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval;\n\n if (quoteResponse.resetApproval) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.resetApproval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n if (quoteResponse.approval && isEvmTxData(quoteResponse.approval)) {\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.approval,\n type: approvalTxType,\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n }\n tradeData.push({\n quoteResponse,\n tx: quoteResponse.trade as TxData,\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n assetsFiatValues: {\n sending: quoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving: quoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n txFee: quoteResponse.quote.feeData[FeeType.TX_FEE],\n });\n\n return tradeData;\n};\n\n/**\n * Build the trade+quote metadata array for the batch sell transaction\n * This ties together the quote, the tx params and the txMeta after submission\n *\n * @param options - The options for the batch sell transaction\n * @param options.quoteResponses - The quote responses for the batch sell transaction\n * @param options.batchSellTrades - The batch sell trades for the batch sell transaction\n * @returns The trade+quote metadata array for the batch sell transaction\n */\nexport const toQuoteAndTxMetadataBatch = ({\n quoteResponses,\n batchSellTrades,\n}: {\n quoteResponses: (QuoteResponse<TxData, TxData> & QuoteMetadata)[];\n batchSellTrades: BatchSellTradesResponse;\n}): Omit<QuoteAndTxMetadata, 'txMeta'>[] => {\n const tradeData: QuoteAndTxMetadata[] = [];\n\n const {\n transactions,\n gasIncluded7702,\n gasIncluded,\n gasSponsored = false,\n } = batchSellTrades;\n\n for (const transaction of transactions) {\n const { type, maxFeePerGas, maxPriorityFeePerGas, ...tx } = transaction;\n // Match the trade or approval tx data with the quote response\n const matchingQuoteResponse =\n quoteResponses.find(\n ({ approval, trade }) =>\n trade?.data.toLowerCase() === tx.data.toLowerCase() ||\n approval?.data.toLowerCase() === tx.data.toLowerCase(),\n ) ?? quoteResponses[0];\n\n // Include gasIncluded and gasIncluded7702 from the gasless batch\n const normalizedQuote = {\n ...matchingQuoteResponse,\n quote: {\n ...matchingQuoteResponse.quote,\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n };\n\n const commonTradeData = {\n tx,\n quoteResponse: normalizedQuote,\n txFee: { maxFeePerGas, maxPriorityFeePerGas },\n };\n\n if (type === BatchSellTransactionType.TRADE) {\n tradeData.push({\n ...commonTradeData,\n type: TransactionType.swap,\n assetsFiatValues: {\n sending:\n matchingQuoteResponse.sentAmount?.valueInCurrency?.toString(),\n receiving:\n matchingQuoteResponse.toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n } else {\n tradeData.push({\n ...commonTradeData,\n type:\n type === BatchSellTransactionType.APPROVAL\n ? TransactionType.swapApproval\n : TransactionType.tokenMethodTransfer,\n });\n }\n }\n\n return tradeData;\n};\n\n/**\n * Appends the gas fee estimates for a transaction and normalizes the trade data\n *\n * @param messenger - The messenger for the gas fee estimates\n * @param trade - the trade data to append gas fees to\n * @param trade.chainId - ignored, use chainId instead\n * @param trade.gasLimit - the gas limit to use for the gas fee estimates\n * @param networkClientId - the network client ID to use for the gas fee estimates\n * @param chainId - the chain ID to use for the gas fee estimates\n * @param simulatedGasFeeLimits - either the txFee from the quote or the simulated gas fee limits for the batch sell\n * @returns The gas fee estimates for the transaction\n */\nexport const toTransactionParams = async (\n messenger: BridgeStatusControllerMessenger,\n { chainId: tradeChainId, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n simulatedGasFeeLimits?: SimulatedGasFeeLimits | TxFeeGasLimits,\n): Promise<BatchTransactionParams> => {\n const transactionParams = {\n data: trade.data,\n to: trade.to,\n from: trade.from,\n value: trade.value,\n // Only add gas if it's truthy\n gas: gasLimit ? toHex(gasLimit) : undefined,\n };\n\n // Use bridge-api's provided gas fee estimates\n if (simulatedGasFeeLimits) {\n return {\n ...transactionParams,\n // Sometimes estimates are hex, somethings numeric strings\n maxFeePerGas: isStrictHexString(simulatedGasFeeLimits.maxFeePerGas)\n ? simulatedGasFeeLimits.maxFeePerGas\n : toHex(simulatedGasFeeLimits.maxFeePerGas),\n maxPriorityFeePerGas: isStrictHexString(\n simulatedGasFeeLimits.maxPriorityFeePerGas,\n )\n ? simulatedGasFeeLimits.maxPriorityFeePerGas\n : toHex(simulatedGasFeeLimits.maxPriorityFeePerGas),\n };\n }\n\n // Get transaction's 1559 gas fee estimates\n const gasFeeEstimates = await getGasFeeEstimates(messenger, {\n transactionParams,\n networkClientId,\n chainId,\n });\n\n return {\n ...transactionParams,\n maxFeePerGas: gasFeeEstimates?.maxFeePerGas,\n maxPriorityFeePerGas: gasFeeEstimates?.maxPriorityFeePerGas,\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n tradeData,\n requireApproval = false,\n isDelegatedAccount,\n ...addTransactionBatchParams\n}: Partial<Parameters<TransactionController['addTransactionBatch']>[0]> & {\n messenger: BridgeStatusControllerMessenger;\n tradeData: QuoteAndTxMetadata[];\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}): Promise<Parameters<TransactionController['addTransactionBatch']>[0]> => {\n const trade = tradeData[0].tx;\n const selectedAccount = getAccountByAddress(messenger, trade.from);\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);\n\n const transactions: TransactionBatchSingleRequest[] = await Promise.all(\n tradeData.map(async ({ tx, txFee, assetsFiatValues, type }) => ({\n params: await toTransactionParams(\n messenger,\n tx,\n networkClientId,\n hexChainId,\n txFee,\n ),\n assetsFiatValues,\n type,\n })),\n );\n\n return {\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: selectedAccount.address as Hex,\n isInternal: true,\n transactions,\n ...addTransactionBatchParams,\n };\n};\n\nexport const findAllTransactionsInBatch = ({\n messenger,\n batchId,\n tradeData,\n}: {\n messenger: BridgeStatusControllerMessenger;\n batchId: string;\n tradeData: QuoteAndTxMetadata[];\n}): QuoteAndTxMetadata[] => {\n // Filter for transactions with batchId\n const txs = getTransactions(messenger).filter(\n (tx: TransactionMeta) => tx.batchId === batchId,\n );\n\n return tradeData.map((tradeWithMetadata) => {\n const { tx, type } = tradeWithMetadata;\n return {\n ...tradeWithMetadata,\n txMeta: txs.find((txMeta: TransactionMeta) => {\n if (is7702Tx(txMeta)) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (isTradeTx(type) && txMeta.type === TransactionType.batch) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (isApprovalTx(type) && txMeta.txParams.data === tx.data) {\n return true;\n }\n }\n // Default matching logic for non-7702 transactions\n if (txMeta.txParams.data === tx.data) {\n return true;\n }\n return false;\n }),\n };\n });\n};\n\n/**\n * This is a workaround to update the tx type after submission. Batch txs are submitted with\n * the \"batch\" type, but we need to update to swap/bridge for display purposes.\n *\n * @param params - The parameters for the transaction search\n * @param params.messenger - The messenger to use for the transaction\n * @param params.allTradesWithMetadata - The quote, tx data and type for each transaction in the batch\n * @returns A list of transaction metas for each trade in the batch]\n *\n * @example\n * [\n * {...tradeData[0], tradeMeta: TransactionMeta}\n * {...tradeData[1], tradeMeta: TransactionMeta}\n * {...tradeData[2], tradeMeta: TransactionMeta}\n * {...tradeData[3], tradeMeta: TransactionMeta}\n * ]\n */\nexport const updateTransactionsInBatch = ({\n messenger,\n allTradesWithMetadata,\n}: {\n messenger: BridgeStatusControllerMessenger;\n allTradesWithMetadata: QuoteAndTxMetadata[];\n}) => {\n return allTradesWithMetadata.map((tradeWithMetadata) => {\n const { txMeta, type } = tradeWithMetadata;\n\n if (txMeta) {\n // Update the tx type from batch to swap/bridge\n updateTransaction(\n messenger,\n txMeta,\n { type },\n `Update tx type to ${type}`,\n );\n const updatedTx = { ...txMeta, type };\n return { ...tradeWithMetadata, txMeta: updatedTx, type };\n }\n\n return tradeWithMetadata;\n });\n};\n"]}
|
package/package.json
CHANGED