@metamask-previews/bridge-status-controller 76.3.5-preview-6c5c11696 → 76.4.0-preview-625bad5
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 +10 -2
- package/dist/strategy/batch-sell-strategy.js +1 -1
- package/dist/strategy/batch-sell-strategy.js.map +1 -1
- package/dist/strategy/batch-strategy.js +1 -1
- package/dist/strategy/batch-strategy.js.map +1 -1
- package/dist/strategy/non-evm-strategy.d.ts.map +1 -1
- package/dist/strategy/non-evm-strategy.js +1 -1
- package/dist/strategy/non-evm-strategy.js.map +1 -1
- package/dist/utils/snaps.d.ts +2 -1
- package/dist/utils/snaps.d.ts.map +1 -1
- package/dist/utils/snaps.js +19 -14
- package/dist/utils/snaps.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,9 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** Pass `forceIsGasFeeSponsored` instead of `isGasFeeSponsored` when submitting gasless batch transactions ([#10575](https://github.com/MetaMask/core/pull/10575))
|
|
13
|
+
|
|
14
|
+
## [76.4.0]
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Pass the swap/bridge `sourceAssetId` and `destAssetId` to Tron, Solana, and Bitcoin Snap `signAndSendTransaction` requests. ([#10775](https://github.com/MetaMask/core/pull/10775))
|
|
12
19
|
- Bump `@metamask/profile-sync-controller` from `^34.0.0` to `^34.0.3` ([#10752](https://github.com/MetaMask/core/pull/10752), [#10756](https://github.com/MetaMask/core/pull/10756), [#10761](https://github.com/MetaMask/core/pull/10761))
|
|
13
20
|
- Bump `@metamask/snaps-controllers` from `^19.0.0` to `^19.0.1` ([#10719](https://github.com/MetaMask/core/pull/10719))
|
|
14
|
-
- Bump `@metamask/transaction-controller` from `^72.1.0` to `^72.2.
|
|
21
|
+
- Bump `@metamask/transaction-controller` from `^72.1.0` to `^72.2.1` ([#10772](https://github.com/MetaMask/core/pull/10772), [#10817](https://github.com/MetaMask/core/pull/10817))
|
|
15
22
|
- Bump `@metamask/bridge-controller` from `^82.0.2` to `^82.0.3` ([#10788](https://github.com/MetaMask/core/pull/10788))
|
|
16
23
|
|
|
17
24
|
## [76.3.5]
|
|
@@ -1654,7 +1661,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1654
1661
|
|
|
1655
1662
|
- Initial release ([#5317](https://github.com/MetaMask/core/pull/5317))
|
|
1656
1663
|
|
|
1657
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@76.
|
|
1664
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@76.4.0...HEAD
|
|
1665
|
+
[76.4.0]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@76.3.5...@metamask/bridge-status-controller@76.4.0
|
|
1658
1666
|
[76.3.5]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@76.3.4...@metamask/bridge-status-controller@76.3.5
|
|
1659
1667
|
[76.3.4]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@76.3.3...@metamask/bridge-status-controller@76.3.4
|
|
1660
1668
|
[76.3.3]: https://github.com/MetaMask/core/compare/@metamask/bridge-status-controller@76.3.2...@metamask/bridge-status-controller@76.3.3
|
|
@@ -24,7 +24,7 @@ export async function* submitBatchSellHandler(args) {
|
|
|
24
24
|
// Tx success/failure is independent of other txs in the batch
|
|
25
25
|
atomic: false,
|
|
26
26
|
disable7702: shouldDisable7702(gasIncluded7702, gasIncluded, isDelegatedAccount),
|
|
27
|
-
|
|
27
|
+
forceIsGasFeeSponsored: gasSponsored,
|
|
28
28
|
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
29
29
|
batchId: batchIdParam,
|
|
30
30
|
skipInitialGasEstimate: gasIncluded7702
|
|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|
+
{"version":3,"file":"batch-sell-strategy.js","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,qBAAqB,GAAG,CAAC,EAC7B,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GACd,EAAU,EAAE,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAC3C,IAA2D;IAE3D,MAAM,EACJ,eAAe,EACf,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,OAAO,EAAE,YAAY,GACtB,GAAG,IAAI,CAAC;IAET,MAAM,SAAS,GAAG,yBAAyB,CAAC;QAC1C,cAAc;QACd,eAAe;KAChB,CAAC,CAAC;IAEH,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,eAAe,CAAC;IAEvE,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAChC,CAAC,EAAE,IAAI,EAAE,EAAE,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,kBAAkB;QAClB,8DAA8D;QAC9D,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,iBAAiB,CAC5B,eAAe,EACf,WAAW,EACX,kBAAkB,CACnB;QACD,sBAAsB,EAAE,YAAY;QACpC,gBAAgB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, TxData } from '@metamask/bridge-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { QuoteAndTxMetadata } from '../types.js';\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n hasNestedSwapTransactions,\n is7702Tx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadataBatch,\n} from '../utils/transaction.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\n\nconst getHistoryKeyForQuote = ({\n quoteResponse: { quoteId, quote },\n}: QuoteAndTxMetadata): string => quoteId ?? quote.requestId;\n\n/**\n * Submits batch-sell transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @yields The approvalMeta and tradeMeta for the first batch sell transaction\n */\nexport async function* submitBatchSellHandler(\n args: SubmitStrategyParams<TxData, BatchSellTradesResponse>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n requireApproval,\n quoteResponses,\n messenger,\n addTransactionBatchFn,\n isDelegatedAccount,\n batchSellTrades,\n batchId: batchIdParam,\n } = args;\n\n const tradeData = toQuoteAndTxMetadataBatch({\n quoteResponses,\n batchSellTrades,\n });\n\n const { gasIncluded7702, gasIncluded, gasSponsored } = batchSellTrades;\n\n const gasFeeToken = tradeData.find(\n ({ type }) => type === TransactionType.tokenMethodTransfer,\n )?.tx.to;\n\n const transactionParams = await getAddTransactionBatchParams({\n messenger,\n tradeData,\n requireApproval,\n isDelegatedAccount,\n // Tx success/failure is independent of other txs in the batch\n atomic: false,\n disable7702: shouldDisable7702(\n gasIncluded7702,\n gasIncluded,\n isDelegatedAccount,\n ),\n forceIsGasFeeSponsored: gasSponsored,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n batchId: batchIdParam,\n skipInitialGasEstimate: gasIncluded7702\n ? isDelegatedAccount\n : Boolean(gasFeeToken),\n excludeNativeTokenForFee: !gasFeeToken,\n });\n\n // Submit the batch to the TransactionController\n const { batchId } = await addTransactionBatchFn(transactionParams);\n\n // Find all batch transaction metas and add them to history\n const allTradesInBatch = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n }).filter(\n (metadata): metadata is QuoteAndTxMetadata & { txMeta: TransactionMeta } =>\n isTradeTx(metadata.type) && metadata.txMeta !== undefined,\n );\n\n // This is either the delegation tx or the first STX swap in the batch\n const firstTradeWithMetadata = allTradesInBatch.find(\n ({ txMeta }) =>\n txMeta?.type &&\n (isTradeTx(txMeta.type) || hasNestedSwapTransactions(txMeta)),\n );\n const firstTradeMeta = firstTradeWithMetadata?.txMeta;\n if (!firstTradeMeta) {\n throw new Error(\n 'Failed to add BatchSell trade to history: txMeta not found',\n );\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: firstTradeMeta,\n },\n };\n\n // Each quote must be reported to the reconsiler service (through QuoteStatusManager) with the hash of the tx that\n // actually executed it. So the number of distinct txs the batch produced\n // decides how quotes are tracked:\n // - one tx (atomic 7702 batch): all quotes share the single hash.\n // - many txs (e.g. STX/sendBundle): each quote has its own hash.\n // `is7702Tx` only means the account is delegated (true even for many-tx\n // batches), so count the unique txs instead.\n const isSingleBatchTx =\n new Set(allTradesInBatch.map(({ txMeta }) => txMeta.id)).size === 1;\n\n // Nested/7702 batch\n if (\n isSingleBatchTx &&\n (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta))\n ) {\n const quoteIds = Array.from(\n new Set(allTradesInBatch.map(getHistoryKeyForQuote)),\n );\n\n // Create 1 history item for the parent tx, keyed by the txMeta.id\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: firstTradeMeta.id,\n quoteResponse: firstTradeWithMetadata.quoteResponse,\n batchSellData: batchSellTrades,\n quoteIds,\n bridgeTxMeta: firstTradeMeta,\n },\n };\n // Then create a new history item for each nested trade, keyed by quoteId/requestId\n for (const tradeWithMetadata of allTradesInBatch) {\n const { quoteResponse } = tradeWithMetadata;\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: getHistoryKeyForQuote(tradeWithMetadata),\n quoteResponse,\n batchSellData: batchSellTrades,\n },\n };\n }\n } else {\n // Each trade has its own txMeta if not submitted via 7702\n // Create a new history item for each one, keyed by txMeta.id\n // Note that the approvalTxId is not tracked in history\n for (const { txMeta, quoteResponse } of allTradesInBatch) {\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: txMeta.id,\n quoteResponse,\n batchSellData: batchSellTrades,\n bridgeTxMeta: txMeta,\n },\n };\n }\n }\n}\n"]}
|
|
@@ -19,7 +19,7 @@ export async function* submitBatchHandler(args) {
|
|
|
19
19
|
messenger,
|
|
20
20
|
atomic: true,
|
|
21
21
|
disable7702: shouldDisable7702(quoteResponse.quote.gasIncluded7702, quoteResponse.quote.gasIncluded, isDelegatedAccount),
|
|
22
|
-
|
|
22
|
+
forceIsGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),
|
|
23
23
|
isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),
|
|
24
24
|
});
|
|
25
25
|
const { batchId } = await addTransactionBatchFn(transactionParams);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-strategy.js","sourceRoot":"","sources":["../../src/strategy/batch-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;;GAKG;AACH,MAAM,CAAC,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,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AAO,EAAE,GAAG,MAAM,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IAEnE,MAAM,eAAe,GAAG,0BAA0B,CAAC;QACjD,SAAS;QACT,OAAO;QACP,SAAS;KACV,CAAC,CAAC;IAEH,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,uBAAuB;QACxC,OAAO,EAAE;YACP,eAAe;SAChB;KACF,CAAC;IAEF,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CACpC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAAM,CAChD,EAAE,MAAM,CAAC;IAEV,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CACvC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,MAAM,CACnD,EAAE,MAAM,CAAC;IAEV,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE,EAAE,SAAS,EAAE;KACvB,CAAC;IAEF,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,cAAc;QAC/B,OAAO,EAAE;YACP,UAAU,EAAE,SAAS,CAAC,EAAE;YACxB,YAAY,EAAE,YAAY,EAAE,EAAE;YAC9B,YAAY,EAAE;gBACZ,EAAE,EAAE,SAAS,CAAC,EAAE;gBAChB,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,OAAO,EAAE,SAAS,CAAC,OAAO;aAC3B;YACD,aAAa;SACd;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { TxData } from '@metamask/bridge-controller';\n\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n isApprovalTx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadata,\n} from '../utils/transaction.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\n\n/**\n * Submits batched EVM transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @yields The approvalMeta and tradeMeta for the batched transaction\n */\nexport async function* submitBatchHandler(\n args: SubmitStrategyParams<TxData>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n requireApproval,\n quoteResponses: [quoteResponse],\n messenger,\n isBridgeTx,\n addTransactionBatchFn,\n isDelegatedAccount,\n } = args;\n\n const tradeData = toQuoteAndTxMetadata({\n quoteResponse,\n isBridgeTx,\n });\n\n const transactionParams = await getAddTransactionBatchParams({\n tradeData,\n requireApproval,\n isDelegatedAccount,\n messenger,\n atomic: true,\n disable7702: shouldDisable7702(\n quoteResponse.quote.gasIncluded7702,\n quoteResponse.quote.gasIncluded,\n isDelegatedAccount,\n ),\n forceIsGasFeeSponsored: Boolean(quoteResponse.quote.gasSponsored),\n isGasFeeIncluded: Boolean(quoteResponse.quote.gasIncluded7702),\n });\n\n const { batchId } = await addTransactionBatchFn(transactionParams);\n\n const quoteAndTxMetas = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n });\n\n yield {\n type: SubmitStep.UpdateBatchTransactions,\n payload: {\n quoteAndTxMetas,\n },\n };\n\n const tradeMeta = quoteAndTxMetas.find(\n ({ type, txMeta }) => isTradeTx(type) && txMeta,\n )?.txMeta;\n\n const approvalMeta = quoteAndTxMetas.find(\n ({ type, txMeta }) => isApprovalTx(type) && txMeta,\n )?.txMeta;\n\n if (!tradeMeta) {\n throw new Error(\n 'Failed to update cross-chain swap transaction batch: tradeMeta not found',\n );\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: { tradeMeta },\n };\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: tradeMeta.id,\n approvalTxId: approvalMeta?.id,\n bridgeTxMeta: {\n id: tradeMeta.id,\n hash: tradeMeta.hash,\n batchId: tradeMeta.batchId,\n },\n quoteResponse,\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-evm-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,MAAM,EACP,MAAM,6BAA6B,CAAC;AAMrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"non-evm-strategy.d.ts","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,MAAM,EACP,MAAM,6BAA6B,CAAC;AAMrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA2CzE;;;;;;;;;;GAUG;AACH,wBAAuB,mBAAmB,CACxC,IAAI,EAAE,oBAAoB,CACxB,gBAAgB,GAAG,gBAAgB,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,CACtE,GACA,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CAkD9C"}
|
|
@@ -14,7 +14,7 @@ const handleTronApproval = async (args) => {
|
|
|
14
14
|
const { quoteResponses: [quoteResponse], traceFn, } = args;
|
|
15
15
|
const approvalTxId = await traceFn(getApprovalTraceParams(quoteResponse, false), async () => {
|
|
16
16
|
if (quoteResponse.approval) {
|
|
17
|
-
const txMeta = await handleNonEvmTx(args.messenger, quoteResponse.approval, quoteResponse, args.selectedAccount);
|
|
17
|
+
const txMeta = await handleNonEvmTx(args.messenger, quoteResponse.approval, quoteResponse, args.selectedAccount, true);
|
|
18
18
|
return txMeta.id;
|
|
19
19
|
}
|
|
20
20
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-evm-strategy.js","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAQ5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,KAAK,EAC9B,IAEC,EACD,EAAE;IACF,MAAM,EACJ,cAAc,EAAE,CAAC,aAAa,CAAC,EAC/B,OAAO,GACR,GAAG,IAAI,CAAC;IAET,MAAM,YAAY,GAAG,MAAM,OAAO,CAChC,sBAAsB,CAAC,aAAa,EAAE,KAAK,CAAC,EAC5C,KAAK,IAAI,EAAE;QACT,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,cAAc,CACjC,IAAI,CAAC,SAAS,EACd,aAAa,CAAC,QAAQ,EACtB,aAAa,EACb,IAAI,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"non-evm-strategy.js","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAQ5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,KAAK,EAC9B,IAEC,EACD,EAAE;IACF,MAAM,EACJ,cAAc,EAAE,CAAC,aAAa,CAAC,EAC/B,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,EAAE,SAAS,CAAC,IAAI;aACrB;YACD,aAAa;SACd;KACF,CAAC;IAEF,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,UAAU,EAAE,SAAS,CAAC,EAAE;SACzB;KACF,CAAC;IAEF,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClE,MAAM;YACJ,IAAI,EAAE,UAAU,CAAC,qBAAqB;YACtC,OAAO,EAAE;gBACP,UAAU,EAAE,SAAS,CAAC,EAAE;aACzB;SACF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { isTronChainId } from '@metamask/bridge-controller';\nimport type {\n BitcoinTradeData,\n StellarTradeData,\n TronTradeData,\n TxData,\n} from '@metamask/bridge-controller';\n\nimport { handleNonEvmTx } from '../utils/snaps.js';\nimport { getApprovalTraceParams } from '../utils/trace.js';\nimport { handleApprovalDelay } from '../utils/transaction.js';\nimport { SubmitStep } from './types.js';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types.js';\n\n/**\n * Submits the approval transaction for a non-EVM transaction if present\n *\n * @param args - The parameters for the transaction\n * @returns The tx id of the approval transaction\n */\nconst handleTronApproval = async (\n args: SubmitStrategyParams<\n TronTradeData | BitcoinTradeData | StellarTradeData | string | TxData\n >,\n) => {\n const {\n quoteResponses: [quoteResponse],\n traceFn,\n } = args;\n\n const approvalTxId = await traceFn(\n getApprovalTraceParams(quoteResponse, false),\n async () => {\n if (quoteResponse.approval) {\n const txMeta = await handleNonEvmTx(\n args.messenger,\n quoteResponse.approval,\n quoteResponse,\n args.selectedAccount,\n true,\n );\n return txMeta.id;\n }\n return;\n },\n );\n\n if (approvalTxId) {\n // Add delay after approval similar to EVM flow\n await handleApprovalDelay(quoteResponse.quote.srcChainId);\n return approvalTxId;\n }\n return;\n};\n\n/**\n * Submits Solana, Bitcoin, or Tron transactions to the snap controller\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @yields The approvalTxId and tradeMeta for the non-EVM transaction\n */\nexport async function* submitNonEvmHandler(\n args: SubmitStrategyParams<\n BitcoinTradeData | StellarTradeData | TronTradeData | string | TxData\n >,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n quoteResponses: [quoteResponse],\n isBridgeTx,\n } = args;\n\n const approvalTxId = await handleTronApproval(args);\n\n // TODO bridge-status should update history with actionId if approvalTxId is present\n\n const tradeMeta = await handleNonEvmTx(\n args.messenger,\n quoteResponse.trade,\n quoteResponse,\n args.selectedAccount,\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,\n bridgeTxMeta: {\n id: tradeMeta.id,\n hash: tradeMeta.hash,\n },\n quoteResponse,\n },\n };\n\n yield {\n type: SubmitStep.StartPolling,\n payload: {\n historyKey: tradeMeta.id,\n },\n };\n\n if (!isTronChainId(quoteResponse.quote.srcChainId) && !isBridgeTx) {\n yield {\n type: SubmitStep.PublishCompletedEvent,\n payload: {\n historyKey: tradeMeta.id,\n },\n };\n }\n}\n"]}
|
package/dist/utils/snaps.d.ts
CHANGED
|
@@ -73,7 +73,8 @@ export declare const handleNonEvmTxResponse: (snapResponse: string | {
|
|
|
73
73
|
* @param trade - The trade data (can be approval or main trade)
|
|
74
74
|
* @param quoteResponse - The quote response containing metadata
|
|
75
75
|
* @param selectedAccount - The account to submit the transaction for
|
|
76
|
+
* @param isApproval - Whether the trade is the approval transaction rather than the main trade
|
|
76
77
|
* @returns The transaction meta
|
|
77
78
|
*/
|
|
78
|
-
export declare const handleNonEvmTx: (messenger: BridgeStatusControllerMessenger, trade: Trade, quoteResponse: QuoteResponseV1<Trade, Trade> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => Promise<TransactionMeta>;
|
|
79
|
+
export declare const handleNonEvmTx: (messenger: BridgeStatusControllerMessenger, trade: Trade, quoteResponse: QuoteResponseV1<Trade, Trade> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string], isApproval?: boolean) => Promise<TransactionMeta>;
|
|
79
80
|
//# sourceMappingURL=snaps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snaps.d.ts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,KAAK,EACN,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"snaps.d.ts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,KAAK,EACN,MAAM,6BAA6B,CAAC;AAUrC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAM7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAO,MAAM,iBAAiB,CAAC;AAGvE,OAAO,KAAK,EACV,+BAA+B,EAC/B,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,8BAA8B,WACjC,MAAM,eACD,MAAM,SACZ,WAAW,aACP,MAAM,YACP,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;YAIb,KAAK;;aAEO,KAAK;;;;;;;;;;;;CAatC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eA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Caip, formatChainIdToHex, isCrossChain,
|
|
1
|
+
import { extractTradeData, formatChainIdToCaip, formatChainIdToHex, isCrossChain, isNonEvmChainId, isTronChainId, isTronTrade, } from '@metamask/bridge-controller';
|
|
2
2
|
import { CHAIN_IDS, TransactionStatus, TransactionType, } from '@metamask/transaction-controller';
|
|
3
3
|
import { v4 as uuid } from 'uuid';
|
|
4
4
|
/**
|
|
@@ -47,10 +47,10 @@ export const getClientRequest = (trade, srcChainId, accountId, snapId, sourceAss
|
|
|
47
47
|
const scope = formatChainIdToCaip(srcChainId);
|
|
48
48
|
const transaction = extractTradeData(trade);
|
|
49
49
|
let options;
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
if (
|
|
50
|
+
const isTron = isTronChainId(srcChainId);
|
|
51
|
+
// Stellar, Solana, and Bitcoin trades expect the swap/bridge asset IDs in the
|
|
52
|
+
// request options; Tron also adds its own fields in the branch below.
|
|
53
|
+
if (isNonEvmChainId(srcChainId)) {
|
|
54
54
|
if (sourceAssetId !== undefined || destAssetId !== undefined) {
|
|
55
55
|
options = {
|
|
56
56
|
...(sourceAssetId !== undefined && {
|
|
@@ -61,13 +61,13 @@ export const getClientRequest = (trade, srcChainId, accountId, snapId, sourceAss
|
|
|
61
61
|
}),
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
64
|
+
if (isTron && isTronTrade(trade)) {
|
|
65
|
+
options = {
|
|
66
|
+
...(options ?? {}),
|
|
67
|
+
visible: trade.visible,
|
|
68
|
+
type: trade.raw_data?.contract?.[0]?.type,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
71
|
}
|
|
72
72
|
return createClientTransactionRequest(snapId, transaction, scope, accountId, options);
|
|
73
73
|
};
|
|
@@ -174,13 +174,18 @@ export const handleNonEvmTxResponse = (snapResponse, trade, quoteResponse, selec
|
|
|
174
174
|
* @param trade - The trade data (can be approval or main trade)
|
|
175
175
|
* @param quoteResponse - The quote response containing metadata
|
|
176
176
|
* @param selectedAccount - The account to submit the transaction for
|
|
177
|
+
* @param isApproval - Whether the trade is the approval transaction rather than the main trade
|
|
177
178
|
* @returns The transaction meta
|
|
178
179
|
*/
|
|
179
|
-
export const handleNonEvmTx = async (messenger, trade, quoteResponse, selectedAccount) => {
|
|
180
|
+
export const handleNonEvmTx = async (messenger, trade, quoteResponse, selectedAccount, isApproval = false) => {
|
|
180
181
|
if (!selectedAccount.metadata?.snap?.id) {
|
|
181
182
|
throw new Error('Failed to submit cross-chain swap transaction: undefined snap id');
|
|
182
183
|
}
|
|
183
|
-
|
|
184
|
+
// The quote's asset ids describe the swap/bridge transaction, not the token
|
|
185
|
+
// approval that precedes it. Passing them for the approval would make the snap
|
|
186
|
+
// classify the approval as a swap or a bridge, so they are only attached to
|
|
187
|
+
// the main trade.
|
|
188
|
+
const request = getClientRequest(trade, quoteResponse.quote.srcChainId, selectedAccount.id, selectedAccount.metadata?.snap?.id, isApproval ? undefined : quoteResponse.quote.srcAsset.assetId, isApproval ? undefined : quoteResponse.quote.destAsset.assetId);
|
|
184
189
|
const requestResponse = (await messenger.call('SnapController:handleRequest', request));
|
|
185
190
|
const txMeta = handleNonEvmTxResponse(requestResponse, trade, quoteResponse, selectedAccount);
|
|
186
191
|
// TODO remove this eventually, just returning it now to match extension behavior
|
package/dist/utils/snaps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snaps.js","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,WAAW,GACZ,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,EAAE,IAAI,IAAI,E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,CAAC,OAAO,CACtC,CAAC;IACF,MAAM,eAAe,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,CAC3C,8BAA8B,EAC9B,OAAO,CACR,CAIwB,CAAC;IAE1B,MAAM,MAAM,GAAG,sBAAsB,CACnC,eAAe,EACf,KAAK,EACL,aAAa,EACb,eAAe,CAChB,CAAC;IAEF,iFAAiF;IACjF,uNAAuN;IACvN,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type {\n QuoteMetadata,\n QuoteResponseV1,\n Trade,\n} from '@metamask/bridge-controller';\nimport {\n extractTradeData,\n formatChainIdToCaip,\n formatChainIdToHex,\n isCrossChain,\n isStellarTrade,\n isTronTrade,\n} from '@metamask/bridge-controller';\nimport { SnapController } from '@metamask/snaps-controllers';\nimport {\n CHAIN_IDS,\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types.js';\n\n/**\n * Creates a client request object for signing and sending a transaction\n * Works for Solana, BTC, Tron, and other non-EVM networks\n *\n * @param snapId - The snap ID to send the request to\n * @param transaction - The base64 encoded transaction string\n * @param scope - The CAIP-2 chain scope\n * @param accountId - The account ID\n * @param options - Optional network-specific options\n * @returns The snap request object\n */\nexport const createClientTransactionRequest = (\n snapId: string,\n transaction: string,\n scope: CaipChainId,\n accountId: string,\n options?: Record<string, unknown>,\n) => {\n return {\n // TODO: remove 'as never' typing.\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onClientRequest' as never,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'signAndSendTransaction',\n params: {\n transaction,\n scope,\n accountId,\n ...(options && { options }),\n },\n },\n };\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param trade - The trade data\n * @param srcChainId - The source chain ID\n * @param accountId - The account ID\n * @param snapId - The snap ID\n * @param sourceAssetId - The source asset ID\n * @param destAssetId - The destination asset ID\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n trade: Trade,\n srcChainId: number,\n accountId: AccountsControllerState['internalAccounts']['accounts'][string]['id'],\n snapId: string,\n sourceAssetId?: CaipAssetType,\n destAssetId?: CaipAssetType,\n): Parameters<SnapController['handleRequest']>[0] => {\n const scope = formatChainIdToCaip(srcChainId);\n\n const transaction = extractTradeData(trade);\n\n let options: Record<string, unknown> | undefined;\n\n // Only Stellar trades expect asset IDs in the request options. Passing them\n // for other non-EVM chains (e.g. Bitcoin) breaks strict snap request\n // validation and prevents the transaction from being broadcast.\n if (isStellarTrade(trade)) {\n if (sourceAssetId !== undefined || destAssetId !== undefined) {\n options = {\n ...(sourceAssetId !== undefined && {\n sourceAssetId,\n }),\n ...(destAssetId !== undefined && {\n destAssetId,\n }),\n };\n }\n }\n\n if (isTronTrade(trade)) {\n // Tron trades need the visible flag and contract type to be included in the request options\n options = {\n visible: trade.visible,\n type: trade.raw_data?.contract?.[0]?.type,\n };\n }\n\n return createClientTransactionRequest(\n snapId,\n transaction,\n scope,\n accountId,\n options,\n );\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponseV1<Trade, Trade>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = CHAIN_IDS.MAINNET; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse?.sentAmount?.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param trade - The non-evm trade or approval data\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n trade: Trade,\n quoteResponse: Omit<QuoteResponseV1<Trade>, 'trade' | 'approval'> &\n QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // Check for new unified interface response format first\n if ('transactionId' in snapResponse && snapResponse.transactionId) {\n hash = snapResponse.transactionId;\n } else if (\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n } else if (\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n let hexChainId: Hex;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n hexChainId = '0x1';\n }\n // Extract the transaction data for storage\n const tradeData = extractTradeData(trade);\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? 'mainnet',\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\n/**\n * Submits the transaction to the snap using the new unified ClientRequest interface\n * Works for all non-EVM chains (Solana, BTC, Tron)\n * This adds an approval tx to the ApprovalsController in the background\n * The client needs to handle the approval tx by redirecting to the confirmation page with the approvalTxId in the URL\n *\n * @param messenger - The BridgeStatusControllerMessenger instance\n * @param trade - The trade data (can be approval or main trade)\n * @param quoteResponse - The quote response containing metadata\n * @param selectedAccount - The account to submit the transaction for\n * @returns The transaction meta\n */\nexport const handleNonEvmTx = async (\n messenger: BridgeStatusControllerMessenger,\n trade: Trade,\n quoteResponse: QuoteResponseV1<Trade, Trade> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): Promise<TransactionMeta> => {\n if (!selectedAccount.metadata?.snap?.id) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: undefined snap id',\n );\n }\n\n const request = getClientRequest(\n trade,\n quoteResponse.quote.srcChainId,\n selectedAccount.id,\n selectedAccount.metadata?.snap?.id,\n quoteResponse.quote.srcAsset.assetId,\n quoteResponse.quote.destAsset.assetId,\n );\n const requestResponse = (await messenger.call(\n 'SnapController:handleRequest',\n request,\n )) as\n | string\n | { transactionId: string }\n | { result: Record<string, string> }\n | { signature: string };\n\n const txMeta = handleNonEvmTxResponse(\n requestResponse,\n trade,\n quoteResponse,\n selectedAccount,\n );\n\n // TODO remove this eventually, just returning it now to match extension behavior\n // OR if the snap can propagate the snapRequestId or keyringReqId to the ApprovalsController, this can return the approvalTxId instead and clients won't need to subscribe to the ApprovalsController state to redirect\n return txMeta;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"snaps.js","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,GACZ,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAOlC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,MAAc,EACd,WAAmB,EACnB,KAAkB,EAClB,SAAiB,EACjB,OAAiC,EACjC,EAAE;IACF,OAAO;QACL,kCAAkC;QAClC,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,iBAA0B;QACnC,OAAO,EAAE;YACP,EAAE,EAAE,IAAI,EAAE;YACV,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,wBAAwB;YAChC,MAAM,EAAE;gBACN,WAAW;gBACX,KAAK;gBACL,SAAS;gBACT,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;aAC5B;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,C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CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type {\n QuoteMetadata,\n QuoteResponseV1,\n Trade,\n} from '@metamask/bridge-controller';\nimport {\n extractTradeData,\n formatChainIdToCaip,\n formatChainIdToHex,\n isCrossChain,\n isNonEvmChainId,\n isTronChainId,\n isTronTrade,\n} from '@metamask/bridge-controller';\nimport { SnapController } from '@metamask/snaps-controllers';\nimport {\n CHAIN_IDS,\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types.js';\n\n/**\n * Creates a client request object for signing and sending a transaction\n * Works for Solana, BTC, Tron, and other non-EVM networks\n *\n * @param snapId - The snap ID to send the request to\n * @param transaction - The base64 encoded transaction string\n * @param scope - The CAIP-2 chain scope\n * @param accountId - The account ID\n * @param options - Optional network-specific options\n * @returns The snap request object\n */\nexport const createClientTransactionRequest = (\n snapId: string,\n transaction: string,\n scope: CaipChainId,\n accountId: string,\n options?: Record<string, unknown>,\n) => {\n return {\n // TODO: remove 'as never' typing.\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onClientRequest' as never,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'signAndSendTransaction',\n params: {\n transaction,\n scope,\n accountId,\n ...(options && { options }),\n },\n },\n };\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param trade - The trade data\n * @param srcChainId - The source chain ID\n * @param accountId - The account ID\n * @param snapId - The snap ID\n * @param sourceAssetId - The source asset ID\n * @param destAssetId - The destination asset ID\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n trade: Trade,\n srcChainId: number,\n accountId: AccountsControllerState['internalAccounts']['accounts'][string]['id'],\n snapId: string,\n sourceAssetId?: CaipAssetType,\n destAssetId?: CaipAssetType,\n): Parameters<SnapController['handleRequest']>[0] => {\n const scope = formatChainIdToCaip(srcChainId);\n\n const transaction = extractTradeData(trade);\n\n let options: Record<string, unknown> | undefined;\n const isTron = isTronChainId(srcChainId);\n\n // Stellar, Solana, and Bitcoin trades expect the swap/bridge asset IDs in the\n // request options; Tron also adds its own fields in the branch below.\n if (isNonEvmChainId(srcChainId)) {\n if (sourceAssetId !== undefined || destAssetId !== undefined) {\n options = {\n ...(sourceAssetId !== undefined && {\n sourceAssetId,\n }),\n ...(destAssetId !== undefined && {\n destAssetId,\n }),\n };\n }\n\n if (isTron && isTronTrade(trade)) {\n options = {\n ...(options ?? {}),\n visible: trade.visible,\n type: trade.raw_data?.contract?.[0]?.type,\n };\n }\n }\n\n return createClientTransactionRequest(\n snapId,\n transaction,\n scope,\n accountId,\n options,\n );\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponseV1<Trade, Trade>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = CHAIN_IDS.MAINNET; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse?.sentAmount?.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param trade - The non-evm trade or approval data\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n trade: Trade,\n quoteResponse: Omit<QuoteResponseV1<Trade>, 'trade' | 'approval'> &\n QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // Check for new unified interface response format first\n if ('transactionId' in snapResponse && snapResponse.transactionId) {\n hash = snapResponse.transactionId;\n } else if (\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n } else if (\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n let hexChainId: Hex;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n hexChainId = '0x1';\n }\n // Extract the transaction data for storage\n const tradeData = extractTradeData(trade);\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? 'mainnet',\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\n/**\n * Submits the transaction to the snap using the new unified ClientRequest interface\n * Works for all non-EVM chains (Solana, BTC, Tron)\n * This adds an approval tx to the ApprovalsController in the background\n * The client needs to handle the approval tx by redirecting to the confirmation page with the approvalTxId in the URL\n *\n * @param messenger - The BridgeStatusControllerMessenger instance\n * @param trade - The trade data (can be approval or main trade)\n * @param quoteResponse - The quote response containing metadata\n * @param selectedAccount - The account to submit the transaction for\n * @param isApproval - Whether the trade is the approval transaction rather than the main trade\n * @returns The transaction meta\n */\nexport const handleNonEvmTx = async (\n messenger: BridgeStatusControllerMessenger,\n trade: Trade,\n quoteResponse: QuoteResponseV1<Trade, Trade> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n isApproval = false,\n): Promise<TransactionMeta> => {\n if (!selectedAccount.metadata?.snap?.id) {\n throw new Error(\n 'Failed to submit cross-chain swap transaction: undefined snap id',\n );\n }\n\n // The quote's asset ids describe the swap/bridge transaction, not the token\n // approval that precedes it. Passing them for the approval would make the snap\n // classify the approval as a swap or a bridge, so they are only attached to\n // the main trade.\n const request = getClientRequest(\n trade,\n quoteResponse.quote.srcChainId,\n selectedAccount.id,\n selectedAccount.metadata?.snap?.id,\n isApproval ? undefined : quoteResponse.quote.srcAsset.assetId,\n isApproval ? undefined : quoteResponse.quote.destAsset.assetId,\n );\n const requestResponse = (await messenger.call(\n 'SnapController:handleRequest',\n request,\n )) as\n | string\n | { transactionId: string }\n | { result: Record<string, string> }\n | { signature: string };\n\n const txMeta = handleNonEvmTxResponse(\n requestResponse,\n trade,\n quoteResponse,\n selectedAccount,\n );\n\n // TODO remove this eventually, just returning it now to match extension behavior\n // OR if the snap can propagate the snapRequestId or keyringReqId to the ApprovalsController, this can return the approvalTxId instead and clients won't need to subscribe to the ApprovalsController state to redirect\n return txMeta;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/bridge-status-controller",
|
|
3
|
-
"version": "76.
|
|
3
|
+
"version": "76.4.0-preview-625bad5",
|
|
4
4
|
"description": "Manages bridge-related status fetching functionality for MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@metamask/profile-sync-controller": "^34.0.3",
|
|
63
63
|
"@metamask/snaps-controllers": "^19.0.1",
|
|
64
64
|
"@metamask/superstruct": "^3.4.1",
|
|
65
|
-
"@metamask/transaction-controller": "^72.2.
|
|
65
|
+
"@metamask/transaction-controller": "^72.2.1",
|
|
66
66
|
"@metamask/utils": "^12.0.0",
|
|
67
67
|
"bignumber.js": "^9.1.2",
|
|
68
68
|
"uuid": "^11.1.1"
|