@metamask-previews/bridge-status-controller 44.0.0-preview-b896289e → 45.0.0-preview-6c94ae59
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 +40 -4
- package/dist/bridge-status-controller.cjs +47 -44
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +3 -3
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +3 -3
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +48 -45
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/snaps.cjs +35 -0
- package/dist/utils/snaps.cjs.map +1 -0
- package/dist/utils/snaps.d.cts +29 -0
- package/dist/utils/snaps.d.cts.map +1 -0
- package/dist/utils/snaps.d.mts +29 -0
- package/dist/utils/snaps.d.mts.map +1 -0
- package/dist/utils/snaps.mjs +31 -0
- package/dist/utils/snaps.mjs.map +1 -0
- package/dist/utils/transaction.cjs +69 -38
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +37 -27
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +37 -27
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +68 -37
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AAEA,mEAQqC;AACrC,iEAAmD;AACnD,uDAAiD;AAKjD,6EAI0C;AAC1C,2CAAsD;AACtD,+CAAyC;AACzC,+BAAkC;AAElC,mCAAyC;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AAc,EAAE,wCAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;SACf;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAxEW,QAAA,gCAAgC,oCAwE3C","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport {\n ChainId,\n formatChainIdToHex,\n getEthUsdtResetData,\n isCrossChain,\n isEthUsdt,\n type QuoteMetadata,\n type QuoteResponse,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport { SolScope } from '@metamask/keyring-api';\nimport type {\n BatchTransactionParams,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getUSDTAllowanceResetTx = async (\n messagingSystem: BridgeStatusControllerMessenger,\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n) => {\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n if (\n quoteResponse.approval &&\n isEthUsdt(hexChainId, quoteResponse.quote.srcAsset.address)\n ) {\n const allowance = new BigNumber(\n await messagingSystem.call(\n 'BridgeController:getBridgeERC20Allowance',\n quoteResponse.quote.srcAsset.address,\n hexChainId,\n ),\n );\n const shouldResetApproval =\n allowance.lt(quoteResponse.sentAmount.amount) && allowance.gt(0);\n if (shouldResetApproval) {\n return { ...quoteResponse.approval, data: getEthUsdtResetData() };\n }\n }\n return undefined;\n};\n\nexport const getStatusRequestParams = (\n quoteResponse: QuoteResponse<string | TxData>,\n) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id'\n> => {\n return {\n destinationChainId: formatChainIdToHex(quoteResponse.quote.destChainId),\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: formatChainIdToHex(quoteResponse.quote.srcChainId),\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\nexport const handleSolanaTxResponse = (\n snapResponse:\n | string\n | { result: Record<string, string> }\n | { signature: string },\n quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // If it's an object with result property, try to get the signature\n if (\n typeof snapResponse === 'object' &&\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 }\n if (\n typeof snapResponse === 'object' &&\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: quoteResponse.trade },\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 bridge flag to mark this as a Solana transaction\n isSolana: true, // TODO deprecate this and use chainId\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n quoteResponse: QuoteResponse<TxData | string>,\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(quoteResponse.quote.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\nexport const getClientRequest = (\n quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const clientReqId = uuid();\n\n return {\n origin: 'metamask',\n snapId: selectedAccount.metadata.snap?.id as never,\n handler: 'onClientRequest' as never,\n request: {\n id: clientReqId,\n jsonrpc: '2.0',\n method: 'signAndSendTransactionWithoutConfirmation',\n params: {\n account: { address: selectedAccount.address },\n transaction: quoteResponse.trade,\n scope: SolScope.Mainnet,\n },\n },\n };\n};\n\nexport const toBatchTxParams = (\n disable7702: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (!disable7702) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n estimateGasFeeFn,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messenger.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // When an active quote has gasIncluded7702 set to true,\n // enable 7702 gasless txs for smart accounts\n const disable7702 = gasIncluded7702 !== true;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(disable7702, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n txType === TransactionType.swap &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n txType === TransactionType.swapApproval &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AAEA,mEASqC;AACrC,iEAAmD;AAKnD,6EAI0C;AAC1C,2CAAsD;AACtD,+CAAyC;AACzC,+BAAkC;AAElC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ACtD,IACE,MAAM,KAAK,wCAAe,CAAC,YAAY;oBACvC,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,EAC3B;oBACA,OAAO,IAAI,CAAC;iBACb;aACF;YAED,mDAAmD;YACnD,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,EAAE;YACV,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAyB,EAAE,CAAC;YACjE,mBAAmB,CAAC,SAAS,EAAE,qBAAqB,MAAM,EAAE,CAAC,CAAC;YAC9D,OAAO,CACL,CAAC,wCAAe,CAAC,cAAc,EAAE,wCAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;SACf;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AA1EW,QAAA,gCAAgC,oCA0E3C","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport {\n ChainId,\n formatChainIdToCaip,\n formatChainIdToHex,\n getEthUsdtResetData,\n isCrossChain,\n isEthUsdt,\n type QuoteMetadata,\n type QuoteResponse,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n BatchTransactionParams,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport { createClientTransactionRequest } from './snaps';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getUSDTAllowanceResetTx = async (\n messagingSystem: BridgeStatusControllerMessenger,\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n) => {\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n if (\n quoteResponse.approval &&\n isEthUsdt(hexChainId, quoteResponse.quote.srcAsset.address)\n ) {\n const allowance = new BigNumber(\n await messagingSystem.call(\n 'BridgeController:getBridgeERC20Allowance',\n quoteResponse.quote.srcAsset.address,\n hexChainId,\n ),\n );\n const shouldResetApproval =\n allowance.lt(quoteResponse.sentAmount.amount) && allowance.gt(0);\n if (shouldResetApproval) {\n return { ...quoteResponse.approval, data: getEthUsdtResetData() };\n }\n }\n return undefined;\n};\n\nexport const getStatusRequestParams = (\n quoteResponse: QuoteResponse<string | TxData>,\n) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = '0x1' as `0x${string}`; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n quoteResponse: Omit<\n QuoteResponse<string | { unsignedPsbtBase64: string }>,\n 'approval'\n > &\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;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n // TODO: Fix chain ID activity list handling for Bitcoin\n // Fallback to Ethereum mainnet for now\n hexChainId = '0x1' as `0x${string}`;\n }\n\n // Extract the transaction data for storage\n const tradeData =\n typeof quoteResponse.trade === 'string'\n ? quoteResponse.trade\n : quoteResponse.trade.unsignedPsbtBase64;\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n quoteResponse: QuoteResponse<TxData | string>,\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(quoteResponse.quote.srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n quoteResponse: Omit<\n QuoteResponse<string | { unsignedPsbtBase64: string }>,\n 'approval'\n > &\n QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const scope = formatChainIdToCaip(quoteResponse.quote.srcChainId);\n\n // Extract the transaction data - Bitcoin uses unsignedPsbtBase64, others use string\n const transactionData =\n typeof quoteResponse.trade === 'string'\n ? quoteResponse.trade\n : quoteResponse.trade.unsignedPsbtBase64;\n\n // Use the new unified interface\n return createClientTransactionRequest(\n selectedAccount.metadata.snap?.id as string,\n transactionData,\n scope,\n selectedAccount.id,\n );\n};\n\nexport const toBatchTxParams = (\n disable7702: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (!disable7702) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messagingSystem,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n estimateGasFeeFn,\n}: {\n messagingSystem: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messagingSystem.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messagingSystem.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // When an active quote has gasIncluded7702 set to true,\n // enable 7702 gasless txs for smart accounts\n const disable7702 = gasIncluded7702 !== true;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messagingSystem,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messagingSystem,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n disable7702,\n messagingSystem,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(disable7702, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messagingSystem,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messagingSystem: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messagingSystem.call(\n 'TransactionController:getState',\n ).transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n txType === TransactionType.swap &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n txType === TransactionType.swapApproval &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\n};\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AccountsControllerState } from "@metamask/accounts-controller";
|
|
2
2
|
import type { TxData } from "@metamask/bridge-controller";
|
|
3
3
|
import { type QuoteMetadata, type QuoteResponse } from "@metamask/bridge-controller";
|
|
4
|
-
import { SolScope } from "@metamask/keyring-api";
|
|
5
4
|
import type { BatchTransactionParams, TransactionController } from "@metamask/transaction-controller";
|
|
6
5
|
import { TransactionType, type TransactionMeta } from "@metamask/transaction-controller";
|
|
7
6
|
import type { BridgeStatusControllerMessenger, SolanaTransactionMeta } from "../types.cjs";
|
|
@@ -155,12 +154,26 @@ export declare const getStatusRequestParams: (quoteResponse: QuoteResponse<strin
|
|
|
155
154
|
};
|
|
156
155
|
refuel: boolean;
|
|
157
156
|
};
|
|
158
|
-
export declare const getTxMetaFields: (quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> & QuoteMetadata, approvalTxId?: string) => Omit<TransactionMeta, 'networkClientId' | 'status' | 'time' | 'txParams' | 'id'>;
|
|
159
|
-
|
|
157
|
+
export declare const getTxMetaFields: (quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> & QuoteMetadata, approvalTxId?: string) => Omit<TransactionMeta, 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'>;
|
|
158
|
+
/**
|
|
159
|
+
* Handles the response from non-EVM transaction submission
|
|
160
|
+
* Works with the new unified ClientRequest:signAndSendTransaction interface
|
|
161
|
+
* Supports Solana, Bitcoin, and other non-EVM chains
|
|
162
|
+
*
|
|
163
|
+
* @param snapResponse - The response from the snap after transaction submission
|
|
164
|
+
* @param quoteResponse - The quote response containing trade details and metadata
|
|
165
|
+
* @param selectedAccount - The selected account information
|
|
166
|
+
* @returns The transaction metadata including non-EVM specific fields
|
|
167
|
+
*/
|
|
168
|
+
export declare const handleNonEvmTxResponse: (snapResponse: string | {
|
|
169
|
+
transactionId: string;
|
|
170
|
+
} | {
|
|
160
171
|
result: Record<string, string>;
|
|
161
172
|
} | {
|
|
162
173
|
signature: string;
|
|
163
|
-
}, quoteResponse: Omit<QuoteResponse<string
|
|
174
|
+
}, quoteResponse: Omit<QuoteResponse<string | {
|
|
175
|
+
unsignedPsbtBase64: string;
|
|
176
|
+
}>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => TransactionMeta & SolanaTransactionMeta;
|
|
164
177
|
export declare const handleApprovalDelay: (quoteResponse: QuoteResponse<TxData | string>) => Promise<void>;
|
|
165
178
|
/**
|
|
166
179
|
* Adds a delay for hardware wallet transactions on mobile to fix an issue
|
|
@@ -170,28 +183,29 @@ export declare const handleApprovalDelay: (quoteResponse: QuoteResponse<TxData |
|
|
|
170
183
|
* @param requireApproval - Whether the delay should be applied
|
|
171
184
|
*/
|
|
172
185
|
export declare const handleMobileHardwareWalletDelay: (requireApproval: boolean) => Promise<void>;
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Creates a request to sign and send a transaction for non-EVM chains
|
|
188
|
+
* Uses the new unified ClientRequest:signAndSendTransaction interface
|
|
189
|
+
*
|
|
190
|
+
* @param quoteResponse - The quote response containing trade details and metadata
|
|
191
|
+
* @param selectedAccount - The selected account information
|
|
192
|
+
* @returns The snap request object for signing and sending transaction
|
|
193
|
+
*/
|
|
194
|
+
export declare const getClientRequest: (quoteResponse: Omit<QuoteResponse<string | {
|
|
195
|
+
unsignedPsbtBase64: string;
|
|
196
|
+
}>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => {
|
|
175
197
|
snapId: never;
|
|
198
|
+
origin: string;
|
|
176
199
|
handler: never;
|
|
177
200
|
request: {
|
|
178
201
|
id: string;
|
|
179
202
|
jsonrpc: string;
|
|
180
203
|
method: string;
|
|
181
204
|
params: {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
data: string;
|
|
187
|
-
value: string;
|
|
188
|
-
to: string;
|
|
189
|
-
from: string;
|
|
190
|
-
gasLimit: number | null;
|
|
191
|
-
chainId: number;
|
|
192
|
-
effectiveGas?: number | undefined;
|
|
193
|
-
} & string);
|
|
194
|
-
scope: SolScope;
|
|
205
|
+
options?: Record<string, unknown> | undefined;
|
|
206
|
+
transaction: string;
|
|
207
|
+
scope: `${string}:${string}`;
|
|
208
|
+
accountId: string;
|
|
195
209
|
};
|
|
196
210
|
};
|
|
197
211
|
};
|
|
@@ -200,8 +214,8 @@ export declare const toBatchTxParams: (disable7702: boolean, { chainId, gasLimit
|
|
|
200
214
|
maxPriorityFeePerGas?: string | undefined;
|
|
201
215
|
gas?: string | undefined;
|
|
202
216
|
}) => BatchTransactionParams;
|
|
203
|
-
export declare const getAddTransactionBatchParams: ({
|
|
204
|
-
|
|
217
|
+
export declare const getAddTransactionBatchParams: ({ messagingSystem, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, }, sentAmount, toTokenAmount, }, requireApproval, estimateGasFeeFn, }: {
|
|
218
|
+
messagingSystem: BridgeStatusControllerMessenger;
|
|
205
219
|
isBridgeTx: boolean;
|
|
206
220
|
trade: TxData;
|
|
207
221
|
quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;
|
|
@@ -226,8 +240,8 @@ export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, app
|
|
|
226
240
|
} | undefined;
|
|
227
241
|
requireApproval?: boolean | undefined;
|
|
228
242
|
}) => Promise<import("@metamask/transaction-controller").TransactionBatchRequest>;
|
|
229
|
-
export declare const findAndUpdateTransactionsInBatch: ({
|
|
230
|
-
|
|
243
|
+
export declare const findAndUpdateTransactionsInBatch: ({ messagingSystem, updateTransactionFn, batchId, txDataByType, }: {
|
|
244
|
+
messagingSystem: BridgeStatusControllerMessenger;
|
|
231
245
|
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
232
246
|
batchId: string;
|
|
233
247
|
txDataByType: {
|
|
@@ -245,10 +259,6 @@ export declare const findAndUpdateTransactionsInBatch: ({ messenger, updateTrans
|
|
|
245
259
|
lendingWithdraw?: string | undefined;
|
|
246
260
|
perpsDeposit?: string | undefined;
|
|
247
261
|
personal_sign?: string | undefined;
|
|
248
|
-
predictBuy?: string | undefined;
|
|
249
|
-
predictClaim?: string | undefined;
|
|
250
|
-
predictDeposit?: string | undefined;
|
|
251
|
-
predictSell?: string | undefined;
|
|
252
262
|
retry?: string | undefined;
|
|
253
263
|
revokeDelegation?: string | undefined;
|
|
254
264
|
simpleSend?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAC1D,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,oCAAoC;AAErC,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,EAEL,eAAe,EACf,KAAK,eAAe,EACrB,yCAAyC;AAS1C,OAAO,KAAK,EACV,+BAA+B,EAC/B,qBAAqB,EACtB,qBAAiB;AAElB,eAAO,MAAM,gBAAgB,cAAgD,CAAC;AAE9E,eAAO,MAAM,uBAAuB,oEAEnB,cAAc,MAAM,GAAG,MAAM,CAAC,GAAG,aAAa;;;;;;;;cAqB9D,CAAC;AAEF,eAAO,MAAM,sBAAsB,kBAClB,cAAc,MAAM,GAAG,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAM;mBACE,KAAK,aAAa,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,aAAa;sBACtD,OAAO,sBAAsB,SAAS,CAAC,cAAc;;;;;;;;;;;;;;;;;;;;iFAyFxE,CAAC;AAEF,eAAO,MAAM,gCAAgC;;yBAOtB,OAAO,sBAAsB,SAAS,CAAC,iBAAiB;aACpE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkEhB,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AccountsControllerState } from "@metamask/accounts-controller";
|
|
2
2
|
import type { TxData } from "@metamask/bridge-controller";
|
|
3
3
|
import { type QuoteMetadata, type QuoteResponse } from "@metamask/bridge-controller";
|
|
4
|
-
import { SolScope } from "@metamask/keyring-api";
|
|
5
4
|
import type { BatchTransactionParams, TransactionController } from "@metamask/transaction-controller";
|
|
6
5
|
import { TransactionType, type TransactionMeta } from "@metamask/transaction-controller";
|
|
7
6
|
import type { BridgeStatusControllerMessenger, SolanaTransactionMeta } from "../types.mjs";
|
|
@@ -155,12 +154,26 @@ export declare const getStatusRequestParams: (quoteResponse: QuoteResponse<strin
|
|
|
155
154
|
};
|
|
156
155
|
refuel: boolean;
|
|
157
156
|
};
|
|
158
|
-
export declare const getTxMetaFields: (quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> & QuoteMetadata, approvalTxId?: string) => Omit<TransactionMeta, 'networkClientId' | 'status' | 'time' | 'txParams' | 'id'>;
|
|
159
|
-
|
|
157
|
+
export declare const getTxMetaFields: (quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> & QuoteMetadata, approvalTxId?: string) => Omit<TransactionMeta, 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'>;
|
|
158
|
+
/**
|
|
159
|
+
* Handles the response from non-EVM transaction submission
|
|
160
|
+
* Works with the new unified ClientRequest:signAndSendTransaction interface
|
|
161
|
+
* Supports Solana, Bitcoin, and other non-EVM chains
|
|
162
|
+
*
|
|
163
|
+
* @param snapResponse - The response from the snap after transaction submission
|
|
164
|
+
* @param quoteResponse - The quote response containing trade details and metadata
|
|
165
|
+
* @param selectedAccount - The selected account information
|
|
166
|
+
* @returns The transaction metadata including non-EVM specific fields
|
|
167
|
+
*/
|
|
168
|
+
export declare const handleNonEvmTxResponse: (snapResponse: string | {
|
|
169
|
+
transactionId: string;
|
|
170
|
+
} | {
|
|
160
171
|
result: Record<string, string>;
|
|
161
172
|
} | {
|
|
162
173
|
signature: string;
|
|
163
|
-
}, quoteResponse: Omit<QuoteResponse<string
|
|
174
|
+
}, quoteResponse: Omit<QuoteResponse<string | {
|
|
175
|
+
unsignedPsbtBase64: string;
|
|
176
|
+
}>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => TransactionMeta & SolanaTransactionMeta;
|
|
164
177
|
export declare const handleApprovalDelay: (quoteResponse: QuoteResponse<TxData | string>) => Promise<void>;
|
|
165
178
|
/**
|
|
166
179
|
* Adds a delay for hardware wallet transactions on mobile to fix an issue
|
|
@@ -170,28 +183,29 @@ export declare const handleApprovalDelay: (quoteResponse: QuoteResponse<TxData |
|
|
|
170
183
|
* @param requireApproval - Whether the delay should be applied
|
|
171
184
|
*/
|
|
172
185
|
export declare const handleMobileHardwareWalletDelay: (requireApproval: boolean) => Promise<void>;
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Creates a request to sign and send a transaction for non-EVM chains
|
|
188
|
+
* Uses the new unified ClientRequest:signAndSendTransaction interface
|
|
189
|
+
*
|
|
190
|
+
* @param quoteResponse - The quote response containing trade details and metadata
|
|
191
|
+
* @param selectedAccount - The selected account information
|
|
192
|
+
* @returns The snap request object for signing and sending transaction
|
|
193
|
+
*/
|
|
194
|
+
export declare const getClientRequest: (quoteResponse: Omit<QuoteResponse<string | {
|
|
195
|
+
unsignedPsbtBase64: string;
|
|
196
|
+
}>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => {
|
|
175
197
|
snapId: never;
|
|
198
|
+
origin: string;
|
|
176
199
|
handler: never;
|
|
177
200
|
request: {
|
|
178
201
|
id: string;
|
|
179
202
|
jsonrpc: string;
|
|
180
203
|
method: string;
|
|
181
204
|
params: {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
data: string;
|
|
187
|
-
value: string;
|
|
188
|
-
to: string;
|
|
189
|
-
from: string;
|
|
190
|
-
gasLimit: number | null;
|
|
191
|
-
chainId: number;
|
|
192
|
-
effectiveGas?: number | undefined;
|
|
193
|
-
} & string);
|
|
194
|
-
scope: SolScope;
|
|
205
|
+
options?: Record<string, unknown> | undefined;
|
|
206
|
+
transaction: string;
|
|
207
|
+
scope: `${string}:${string}`;
|
|
208
|
+
accountId: string;
|
|
195
209
|
};
|
|
196
210
|
};
|
|
197
211
|
};
|
|
@@ -200,8 +214,8 @@ export declare const toBatchTxParams: (disable7702: boolean, { chainId, gasLimit
|
|
|
200
214
|
maxPriorityFeePerGas?: string | undefined;
|
|
201
215
|
gas?: string | undefined;
|
|
202
216
|
}) => BatchTransactionParams;
|
|
203
|
-
export declare const getAddTransactionBatchParams: ({
|
|
204
|
-
|
|
217
|
+
export declare const getAddTransactionBatchParams: ({ messagingSystem, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, }, sentAmount, toTokenAmount, }, requireApproval, estimateGasFeeFn, }: {
|
|
218
|
+
messagingSystem: BridgeStatusControllerMessenger;
|
|
205
219
|
isBridgeTx: boolean;
|
|
206
220
|
trade: TxData;
|
|
207
221
|
quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;
|
|
@@ -226,8 +240,8 @@ export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, app
|
|
|
226
240
|
} | undefined;
|
|
227
241
|
requireApproval?: boolean | undefined;
|
|
228
242
|
}) => Promise<import("@metamask/transaction-controller").TransactionBatchRequest>;
|
|
229
|
-
export declare const findAndUpdateTransactionsInBatch: ({
|
|
230
|
-
|
|
243
|
+
export declare const findAndUpdateTransactionsInBatch: ({ messagingSystem, updateTransactionFn, batchId, txDataByType, }: {
|
|
244
|
+
messagingSystem: BridgeStatusControllerMessenger;
|
|
231
245
|
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
232
246
|
batchId: string;
|
|
233
247
|
txDataByType: {
|
|
@@ -245,10 +259,6 @@ export declare const findAndUpdateTransactionsInBatch: ({ messenger, updateTrans
|
|
|
245
259
|
lendingWithdraw?: string | undefined;
|
|
246
260
|
perpsDeposit?: string | undefined;
|
|
247
261
|
personal_sign?: string | undefined;
|
|
248
|
-
predictBuy?: string | undefined;
|
|
249
|
-
predictClaim?: string | undefined;
|
|
250
|
-
predictDeposit?: string | undefined;
|
|
251
|
-
predictSell?: string | undefined;
|
|
252
262
|
retry?: string | undefined;
|
|
253
263
|
revokeDelegation?: string | undefined;
|
|
254
264
|
simpleSend?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAC1D,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,oCAAoC;AAErC,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,EAEL,eAAe,EACf,KAAK,eAAe,EACrB,yCAAyC;AAS1C,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EF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,kBACZ,KACb,cAAc,MAAM,GAAG;IAAE,kBAAkB,EAAE,MAAM,CAAA;CAAE,CAAC,EACtD,UAAU,CACX,GACC,aAAa,mBACE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;CAiBjF,CAAC;AAEF,eAAO,MAAM,eAAe,gBACb,OAAO,mCACa,MAAM;;;;MAMtC,sBAiBF,CAAC;AAEF,eAAO,MAAM,4BAA4B;;gBAmB3B,OAAO;WACZ,MAAM;mBACE,KAAK,aAAa,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,aAAa;sBACtD,OAAO,sBAAsB,SAAS,CAAC,cAAc;;;;;;;;;;;;;;;;;;;;iFAyFxE,CAAC;AAEF,eAAO,MAAM,gCAAgC;;yBAOtB,OAAO,sBAAsB,SAAS,CAAC,iBAAiB;aACpE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkEhB,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ChainId, formatChainIdToHex, getEthUsdtResetData, isCrossChain, isEthUsdt } from "@metamask/bridge-controller";
|
|
1
|
+
import { ChainId, formatChainIdToCaip, formatChainIdToHex, getEthUsdtResetData, isCrossChain, isEthUsdt } from "@metamask/bridge-controller";
|
|
2
2
|
import { toHex } from "@metamask/controller-utils";
|
|
3
|
-
import { SolScope } from "@metamask/keyring-api";
|
|
4
3
|
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
5
4
|
import { createProjectLogger } from "@metamask/utils";
|
|
6
5
|
import { BigNumber } from "bignumber.js";
|
|
7
6
|
import { v4 as uuid } from "uuid";
|
|
8
7
|
import { calculateGasFees } from "./gas.mjs";
|
|
8
|
+
import { createClientTransactionRequest } from "./snaps.mjs";
|
|
9
9
|
import { APPROVAL_DELAY_MS } from "../constants.mjs";
|
|
10
10
|
export const generateActionId = () => (Date.now() + Math.random()).toString();
|
|
11
11
|
export const getUSDTAllowanceResetTx = async (messagingSystem, quoteResponse) => {
|
|
@@ -31,8 +31,17 @@ export const getStatusRequestParams = (quoteResponse) => {
|
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
export const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
|
34
|
+
// Handle destination chain ID - should always be convertible for EVM destinations
|
|
35
|
+
let destinationChainId;
|
|
36
|
+
try {
|
|
37
|
+
destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Fallback for non-EVM destination (shouldn't happen for BTC->EVM)
|
|
41
|
+
destinationChainId = '0x1'; // Default to mainnet
|
|
42
|
+
}
|
|
34
43
|
return {
|
|
35
|
-
destinationChainId
|
|
44
|
+
destinationChainId,
|
|
36
45
|
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
|
37
46
|
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
|
38
47
|
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
|
@@ -41,13 +50,23 @@ export const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
|
|
41
50
|
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
|
42
51
|
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
|
43
52
|
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
|
44
|
-
chainId
|
|
53
|
+
// chainId is now excluded from this function and handled by the caller
|
|
45
54
|
approvalTxId,
|
|
46
55
|
// this is the decimal (non atomic) amount (not USD value) of source token to swap
|
|
47
56
|
swapTokenValue: quoteResponse.sentAmount.amount,
|
|
48
57
|
};
|
|
49
58
|
};
|
|
50
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Handles the response from non-EVM transaction submission
|
|
61
|
+
* Works with the new unified ClientRequest:signAndSendTransaction interface
|
|
62
|
+
* Supports Solana, Bitcoin, and other non-EVM chains
|
|
63
|
+
*
|
|
64
|
+
* @param snapResponse - The response from the snap after transaction submission
|
|
65
|
+
* @param quoteResponse - The quote response containing trade details and metadata
|
|
66
|
+
* @param selectedAccount - The selected account information
|
|
67
|
+
* @returns The transaction metadata including non-EVM specific fields
|
|
68
|
+
*/
|
|
69
|
+
export const handleNonEvmTxResponse = (snapResponse, quoteResponse, selectedAccount) => {
|
|
51
70
|
const selectedAccountAddress = selectedAccount.address;
|
|
52
71
|
const snapId = selectedAccount.metadata.snap?.id;
|
|
53
72
|
let hash;
|
|
@@ -56,9 +75,11 @@ export const handleSolanaTxResponse = (snapResponse, quoteResponse, selectedAcco
|
|
|
56
75
|
hash = snapResponse;
|
|
57
76
|
}
|
|
58
77
|
else if (snapResponse && typeof snapResponse === 'object') {
|
|
59
|
-
//
|
|
60
|
-
if (
|
|
61
|
-
|
|
78
|
+
// Check for new unified interface response format first
|
|
79
|
+
if ('transactionId' in snapResponse && snapResponse.transactionId) {
|
|
80
|
+
hash = snapResponse.transactionId;
|
|
81
|
+
}
|
|
82
|
+
else if ('result' in snapResponse &&
|
|
62
83
|
snapResponse.result &&
|
|
63
84
|
typeof snapResponse.result === 'object') {
|
|
64
85
|
// Try to extract signature from common locations in response object
|
|
@@ -68,15 +89,26 @@ export const handleSolanaTxResponse = (snapResponse, quoteResponse, selectedAcco
|
|
|
68
89
|
snapResponse.result.hash ||
|
|
69
90
|
snapResponse.result.txHash;
|
|
70
91
|
}
|
|
71
|
-
if (
|
|
72
|
-
'signature' in snapResponse &&
|
|
92
|
+
else if ('signature' in snapResponse &&
|
|
73
93
|
snapResponse.signature &&
|
|
74
94
|
typeof snapResponse.signature === 'string') {
|
|
75
95
|
hash = snapResponse.signature;
|
|
76
96
|
}
|
|
77
97
|
}
|
|
78
|
-
const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
|
79
98
|
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
99
|
+
let hexChainId;
|
|
100
|
+
try {
|
|
101
|
+
hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// TODO: Fix chain ID activity list handling for Bitcoin
|
|
105
|
+
// Fallback to Ethereum mainnet for now
|
|
106
|
+
hexChainId = '0x1';
|
|
107
|
+
}
|
|
108
|
+
// Extract the transaction data for storage
|
|
109
|
+
const tradeData = typeof quoteResponse.trade === 'string'
|
|
110
|
+
? quoteResponse.trade
|
|
111
|
+
: quoteResponse.trade.unsignedPsbtBase64;
|
|
80
112
|
// Create a transaction meta object with bridge-specific fields
|
|
81
113
|
return {
|
|
82
114
|
...getTxMetaFields(quoteResponse),
|
|
@@ -84,12 +116,12 @@ export const handleSolanaTxResponse = (snapResponse, quoteResponse, selectedAcco
|
|
|
84
116
|
id: hash ?? uuid(),
|
|
85
117
|
chainId: hexChainId,
|
|
86
118
|
networkClientId: snapId ?? hexChainId,
|
|
87
|
-
txParams: { from: selectedAccountAddress, data:
|
|
119
|
+
txParams: { from: selectedAccountAddress, data: tradeData },
|
|
88
120
|
type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,
|
|
89
121
|
status: TransactionStatus.submitted,
|
|
90
122
|
hash,
|
|
91
123
|
origin: snapId,
|
|
92
|
-
// Add an explicit
|
|
124
|
+
// Add an explicit flag to mark this as a non-EVM transaction
|
|
93
125
|
isSolana: true,
|
|
94
126
|
isBridgeTx,
|
|
95
127
|
};
|
|
@@ -115,23 +147,22 @@ export const handleMobileHardwareWalletDelay = async (requireApproval) => {
|
|
|
115
147
|
await mobileHardwareWalletDelay;
|
|
116
148
|
}
|
|
117
149
|
};
|
|
150
|
+
/**
|
|
151
|
+
* Creates a request to sign and send a transaction for non-EVM chains
|
|
152
|
+
* Uses the new unified ClientRequest:signAndSendTransaction interface
|
|
153
|
+
*
|
|
154
|
+
* @param quoteResponse - The quote response containing trade details and metadata
|
|
155
|
+
* @param selectedAccount - The selected account information
|
|
156
|
+
* @returns The snap request object for signing and sending transaction
|
|
157
|
+
*/
|
|
118
158
|
export const getClientRequest = (quoteResponse, selectedAccount) => {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
jsonrpc: '2.0',
|
|
127
|
-
method: 'signAndSendTransactionWithoutConfirmation',
|
|
128
|
-
params: {
|
|
129
|
-
account: { address: selectedAccount.address },
|
|
130
|
-
transaction: quoteResponse.trade,
|
|
131
|
-
scope: SolScope.Mainnet,
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
};
|
|
159
|
+
const scope = formatChainIdToCaip(quoteResponse.quote.srcChainId);
|
|
160
|
+
// Extract the transaction data - Bitcoin uses unsignedPsbtBase64, others use string
|
|
161
|
+
const transactionData = typeof quoteResponse.trade === 'string'
|
|
162
|
+
? quoteResponse.trade
|
|
163
|
+
: quoteResponse.trade.unsignedPsbtBase64;
|
|
164
|
+
// Use the new unified interface
|
|
165
|
+
return createClientTransactionRequest(selectedAccount.metadata.snap?.id, transactionData, scope, selectedAccount.id);
|
|
135
166
|
};
|
|
136
167
|
export const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, { maxFeePerGas, maxPriorityFeePerGas, gas, }) => {
|
|
137
168
|
const params = {
|
|
@@ -150,20 +181,20 @@ export const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, {
|
|
|
150
181
|
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),
|
|
151
182
|
};
|
|
152
183
|
};
|
|
153
|
-
export const getAddTransactionBatchParams = async ({
|
|
184
|
+
export const getAddTransactionBatchParams = async ({ messagingSystem, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, }, sentAmount, toTokenAmount, }, requireApproval = false, estimateGasFeeFn, }) => {
|
|
154
185
|
const isGasless = gasIncluded || gasIncluded7702;
|
|
155
|
-
const selectedAccount =
|
|
186
|
+
const selectedAccount = messagingSystem.call('AccountsController:getAccountByAddress', trade.from);
|
|
156
187
|
if (!selectedAccount) {
|
|
157
188
|
throw new Error('Failed to submit cross-chain swap batch transaction: unknown account in trade data');
|
|
158
189
|
}
|
|
159
190
|
const hexChainId = formatChainIdToHex(trade.chainId);
|
|
160
|
-
const networkClientId =
|
|
191
|
+
const networkClientId = messagingSystem.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
|
|
161
192
|
// When an active quote has gasIncluded7702 set to true,
|
|
162
193
|
// enable 7702 gasless txs for smart accounts
|
|
163
194
|
const disable7702 = gasIncluded7702 !== true;
|
|
164
195
|
const transactions = [];
|
|
165
196
|
if (resetApproval) {
|
|
166
|
-
const gasFees = await calculateGasFees(disable7702,
|
|
197
|
+
const gasFees = await calculateGasFees(disable7702, messagingSystem, estimateGasFeeFn, resetApproval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
167
198
|
transactions.push({
|
|
168
199
|
type: isBridgeTx
|
|
169
200
|
? TransactionType.bridgeApproval
|
|
@@ -172,7 +203,7 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
172
203
|
});
|
|
173
204
|
}
|
|
174
205
|
if (approval) {
|
|
175
|
-
const gasFees = await calculateGasFees(disable7702,
|
|
206
|
+
const gasFees = await calculateGasFees(disable7702, messagingSystem, estimateGasFeeFn, approval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
176
207
|
transactions.push({
|
|
177
208
|
type: isBridgeTx
|
|
178
209
|
? TransactionType.bridgeApproval
|
|
@@ -180,7 +211,7 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
180
211
|
params: toBatchTxParams(disable7702, approval, gasFees),
|
|
181
212
|
});
|
|
182
213
|
}
|
|
183
|
-
const gasFees = await calculateGasFees(disable7702,
|
|
214
|
+
const gasFees = await calculateGasFees(disable7702, messagingSystem, estimateGasFeeFn, trade, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
184
215
|
transactions.push({
|
|
185
216
|
type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,
|
|
186
217
|
params: toBatchTxParams(disable7702, trade, gasFees),
|
|
@@ -200,8 +231,8 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
200
231
|
};
|
|
201
232
|
return transactionParams;
|
|
202
233
|
};
|
|
203
|
-
export const findAndUpdateTransactionsInBatch = ({
|
|
204
|
-
const txs =
|
|
234
|
+
export const findAndUpdateTransactionsInBatch = ({ messagingSystem, updateTransactionFn, batchId, txDataByType, }) => {
|
|
235
|
+
const txs = messagingSystem.call('TransactionController:getState').transactions;
|
|
205
236
|
const txBatch = {
|
|
206
237
|
approvalMeta: undefined,
|
|
207
238
|
tradeMeta: undefined,
|