@metamask/bridge-controller 60.0.0 → 61.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/bridge-controller.d.cts +1 -1
  3. package/dist/bridge-controller.d.mts +1 -1
  4. package/dist/constants/bridge.cjs +1 -0
  5. package/dist/constants/bridge.cjs.map +1 -1
  6. package/dist/constants/bridge.d.cts +2 -2
  7. package/dist/constants/bridge.d.cts.map +1 -1
  8. package/dist/constants/bridge.d.mts +2 -2
  9. package/dist/constants/bridge.d.mts.map +1 -1
  10. package/dist/constants/bridge.mjs +2 -1
  11. package/dist/constants/bridge.mjs.map +1 -1
  12. package/dist/constants/tokens.cjs +10 -0
  13. package/dist/constants/tokens.cjs.map +1 -1
  14. package/dist/constants/tokens.d.cts +7 -0
  15. package/dist/constants/tokens.d.cts.map +1 -1
  16. package/dist/constants/tokens.d.mts +7 -0
  17. package/dist/constants/tokens.d.mts.map +1 -1
  18. package/dist/constants/tokens.mjs +11 -1
  19. package/dist/constants/tokens.mjs.map +1 -1
  20. package/dist/index.cjs +5 -1
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +2 -1
  23. package/dist/index.d.cts.map +1 -1
  24. package/dist/index.d.mts +2 -1
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +1 -0
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/selectors.d.cts +2208 -0
  29. package/dist/selectors.d.cts.map +1 -1
  30. package/dist/selectors.d.mts +2208 -0
  31. package/dist/selectors.d.mts.map +1 -1
  32. package/dist/types.cjs +1 -0
  33. package/dist/types.cjs.map +1 -1
  34. package/dist/types.d.cts +7 -4
  35. package/dist/types.d.cts.map +1 -1
  36. package/dist/types.d.mts +7 -4
  37. package/dist/types.d.mts.map +1 -1
  38. package/dist/types.mjs +1 -0
  39. package/dist/types.mjs.map +1 -1
  40. package/dist/utils/bridge.cjs +12 -3
  41. package/dist/utils/bridge.cjs.map +1 -1
  42. package/dist/utils/bridge.d.cts +10 -1
  43. package/dist/utils/bridge.d.cts.map +1 -1
  44. package/dist/utils/bridge.d.mts +10 -1
  45. package/dist/utils/bridge.d.mts.map +1 -1
  46. package/dist/utils/bridge.mjs +11 -3
  47. package/dist/utils/bridge.mjs.map +1 -1
  48. package/dist/utils/caip-formatters.cjs +6 -0
  49. package/dist/utils/caip-formatters.cjs.map +1 -1
  50. package/dist/utils/caip-formatters.d.cts.map +1 -1
  51. package/dist/utils/caip-formatters.d.mts.map +1 -1
  52. package/dist/utils/caip-formatters.mjs +8 -2
  53. package/dist/utils/caip-formatters.mjs.map +1 -1
  54. package/dist/utils/quote-fees.cjs +11 -7
  55. package/dist/utils/quote-fees.cjs.map +1 -1
  56. package/dist/utils/quote-fees.d.cts.map +1 -1
  57. package/dist/utils/quote-fees.d.mts.map +1 -1
  58. package/dist/utils/quote-fees.mjs +11 -7
  59. package/dist/utils/quote-fees.mjs.map +1 -1
  60. package/dist/utils/quote.cjs.map +1 -1
  61. package/dist/utils/quote.d.cts +2 -2
  62. package/dist/utils/quote.d.cts.map +1 -1
  63. package/dist/utils/quote.d.mts +2 -2
  64. package/dist/utils/quote.d.mts.map +1 -1
  65. package/dist/utils/quote.mjs.map +1 -1
  66. package/dist/utils/snaps.cjs +3 -1
  67. package/dist/utils/snaps.cjs.map +1 -1
  68. package/dist/utils/snaps.d.cts +3 -1
  69. package/dist/utils/snaps.d.cts.map +1 -1
  70. package/dist/utils/snaps.d.mts +3 -1
  71. package/dist/utils/snaps.d.mts.map +1 -1
  72. package/dist/utils/snaps.mjs +3 -1
  73. package/dist/utils/snaps.mjs.map +1 -1
  74. package/dist/utils/trade-utils.cjs +65 -0
  75. package/dist/utils/trade-utils.cjs.map +1 -0
  76. package/dist/utils/trade-utils.d.cts +50 -0
  77. package/dist/utils/trade-utils.d.cts.map +1 -0
  78. package/dist/utils/trade-utils.d.mts +50 -0
  79. package/dist/utils/trade-utils.d.mts.map +1 -0
  80. package/dist/utils/trade-utils.mjs +58 -0
  81. package/dist/utils/trade-utils.mjs.map +1 -0
  82. package/dist/utils/validators.cjs +17 -3
  83. package/dist/utils/validators.cjs.map +1 -1
  84. package/dist/utils/validators.d.cts +74 -9
  85. package/dist/utils/validators.d.cts.map +1 -1
  86. package/dist/utils/validators.d.mts +74 -9
  87. package/dist/utils/validators.d.mts.map +1 -1
  88. package/dist/utils/validators.mjs +16 -2
  89. package/dist/utils/validators.mjs.map +1 -1
  90. package/package.json +4 -4
@@ -24,13 +24,13 @@ export declare const calcSentAmount: ({ srcTokenAmount, srcAsset, feeData }: Quo
24
24
  valueInCurrency: string | null;
25
25
  usd: string | null;
26
26
  };
27
- export declare const calcRelayerFee: (quoteResponse: QuoteResponse<TxData>, { exchangeRate, usdExchangeRate }: ExchangeRate) => {
27
+ export declare const calcRelayerFee: (quoteResponse: QuoteResponse<TxData, TxData>, { exchangeRate, usdExchangeRate }: ExchangeRate) => {
28
28
  amount: BigNumber;
29
29
  valueInCurrency: BigNumber | null;
30
30
  usd: BigNumber | null;
31
31
  };
32
32
  export declare const calcEstimatedAndMaxTotalGasFee: ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, maxPriorityFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }: {
33
- bridgeQuote: QuoteResponse<TxData> & L1GasFees;
33
+ bridgeQuote: QuoteResponse<TxData, TxData> & L1GasFees;
34
34
  estimatedBaseFeeInDecGwei: string;
35
35
  maxFeePerGasInDecGwei: string;
36
36
  maxPriorityFeePerGasInDecGwei: string;
@@ -1 +1 @@
1
- {"version":3,"file":"quote.d.mts","sourceRoot":"","sources":["../../src/utils/quote.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAGzC,OAAO,EAAE,SAAS,EAAE,yBAAqB;AACz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;IACf,CAAC;IACD,OAAO,CAAC,gCAAgC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,MAAuB,EACvB,SAA2B,EAC3B,EAAE;IACF,4EAA4E;IAC5E,IAAI,SAAS,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC1B,OAAO,CACL,CAAC,CAAC,gCAAgC,GAAG,CAAC,CAAC,gCAAgC,CACxE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import {\n convertHexToDecimal,\n toHex,\n weiHexToGweiDec,\n} from '@metamask/controller-utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { isNativeAddress, isNonEvmChainId } from './bridge';\nimport { FeatureId } from './validators';\nimport type {\n BridgeAsset,\n ExchangeRate,\n GenericQuoteRequest,\n L1GasFees,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n NonEvmFees,\n TxData,\n} from '../types';\n\nexport const isValidQuoteRequest = (\n partialRequest: Partial<GenericQuoteRequest>,\n requireAmount = true,\n): partialRequest is GenericQuoteRequest => {\n const stringFields = [\n 'srcTokenAddress',\n 'destTokenAddress',\n 'srcChainId',\n 'destChainId',\n 'walletAddress',\n ];\n if (requireAmount) {\n stringFields.push('srcTokenAmount');\n }\n // If bridging between different chain types or different non-EVM chains, require dest wallet address\n // Cases that need destWalletAddress:\n // 1. EVM -> non-EVM\n // 2. non-EVM -> EVM\n // 3. non-EVM -> different non-EVM (e.g., SOL -> BTC)\n // Only same-chain swaps don't need destWalletAddress\n if (\n partialRequest.destChainId &&\n partialRequest.srcChainId &&\n partialRequest.destChainId !== partialRequest.srcChainId && // Different chains\n (isNonEvmChainId(partialRequest.destChainId) ||\n isNonEvmChainId(partialRequest.srcChainId)) // At least one is non-EVM\n ) {\n stringFields.push('destWalletAddress');\n if (!partialRequest.destWalletAddress) {\n return false;\n }\n }\n const numberFields = [];\n // if slippage is defined, require it to be a number\n if (partialRequest.slippage !== undefined) {\n numberFields.push('slippage');\n }\n\n return (\n stringFields.every(\n (field) =>\n field in partialRequest &&\n typeof partialRequest[field as keyof typeof partialRequest] ===\n 'string' &&\n partialRequest[field as keyof typeof partialRequest] !== undefined &&\n partialRequest[field as keyof typeof partialRequest] !== '' &&\n partialRequest[field as keyof typeof partialRequest] !== null,\n ) &&\n numberFields.every(\n (field) =>\n field in partialRequest &&\n typeof partialRequest[field as keyof typeof partialRequest] ===\n 'number' &&\n partialRequest[field as keyof typeof partialRequest] !== undefined &&\n !isNaN(Number(partialRequest[field as keyof typeof partialRequest])) &&\n partialRequest[field as keyof typeof partialRequest] !== null,\n ) &&\n (requireAmount\n ? Boolean((partialRequest.srcTokenAmount ?? '').match(/^[1-9]\\d*$/u))\n : true)\n );\n};\n\n/**\n * Generates a pseudo-unique string that identifies each quote by aggregator, bridge, and steps\n *\n * @param quote - The quote to generate an identifier for\n * @returns A pseudo-unique string that identifies the quote\n */\nexport const getQuoteIdentifier = (quote: QuoteResponse['quote']) =>\n `${quote.bridgeId}-${quote.bridges[0]}-${quote.steps.length}`;\n\nconst calcTokenAmount = (value: string | BigNumber, decimals: number) => {\n const divisor = new BigNumber(10).pow(decimals ?? 0);\n return new BigNumber(value).div(divisor);\n};\n\nexport const calcNonEvmTotalNetworkFee = (\n bridgeQuote: QuoteResponse & NonEvmFees,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n const { nonEvmFeesInNative } = bridgeQuote;\n // Fees are now stored directly in native units (SOL, BTC) without conversion\n const feeInNative = new BigNumber(nonEvmFeesInNative ?? '0');\n\n return {\n amount: feeInNative.toString(),\n valueInCurrency: exchangeRate\n ? feeInNative.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate ? feeInNative.times(usdExchangeRate).toString() : null,\n };\n};\n\nexport const calcToAmount = (\n destTokenAmount: string,\n destAsset: BridgeAsset,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n const normalizedDestAmount = calcTokenAmount(\n destTokenAmount,\n destAsset.decimals,\n );\n return {\n amount: normalizedDestAmount.toString(),\n valueInCurrency: exchangeRate\n ? normalizedDestAmount.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate\n ? normalizedDestAmount.times(usdExchangeRate).toString()\n : null,\n };\n};\n\nexport const calcSentAmount = (\n { srcTokenAmount, srcAsset, feeData }: Quote,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n // Find all fees that will be taken from the src token\n const srcTokenFees = Object.values(feeData).filter(\n (fee) => fee && fee.amount && fee.asset?.assetId === srcAsset.assetId,\n );\n const sentAmount = srcTokenFees.reduce(\n (acc, { amount }) => acc.plus(amount),\n new BigNumber(srcTokenAmount),\n );\n const normalizedSentAmount = calcTokenAmount(sentAmount, srcAsset.decimals);\n return {\n amount: normalizedSentAmount.toString(),\n valueInCurrency: exchangeRate\n ? normalizedSentAmount.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate\n ? normalizedSentAmount.times(usdExchangeRate).toString()\n : null,\n };\n};\n\nexport const calcRelayerFee = (\n quoteResponse: QuoteResponse<TxData>,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n const { quote, trade } = quoteResponse;\n const relayerFeeAmount = new BigNumber(\n convertHexToDecimal(trade.value || '0x0'),\n );\n let relayerFeeInNative = calcTokenAmount(relayerFeeAmount, 18);\n\n // Subtract srcAmount and other fees from trade value if srcAsset is native\n if (isNativeAddress(quote.srcAsset.address)) {\n const sentAmountInNative = calcSentAmount(quote, {\n exchangeRate,\n usdExchangeRate,\n }).amount;\n relayerFeeInNative = relayerFeeInNative.minus(sentAmountInNative);\n }\n\n return {\n amount: relayerFeeInNative,\n valueInCurrency: exchangeRate\n ? relayerFeeInNative.times(exchangeRate)\n : null,\n usd: usdExchangeRate ? relayerFeeInNative.times(usdExchangeRate) : null,\n };\n};\n\nconst calcTotalGasFee = ({\n approvalGasLimit,\n tradeGasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei,\n priorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n}: {\n approvalGasLimit?: number | null;\n tradeGasLimit?: number | null;\n l1GasFeesInHexWei?: string | null;\n feePerGasInDecGwei: string;\n priorityFeePerGasInDecGwei: string;\n nativeToDisplayCurrencyExchangeRate?: string;\n nativeToUsdExchangeRate?: string;\n}) => {\n const totalGasLimitInDec = new BigNumber(\n tradeGasLimit?.toString() ?? '0',\n ).plus(approvalGasLimit?.toString() ?? '0');\n\n const totalFeePerGasInDecGwei = new BigNumber(feePerGasInDecGwei).plus(\n priorityFeePerGasInDecGwei,\n );\n const l1GasFeesInDecGWei = weiHexToGweiDec(toHex(l1GasFeesInHexWei ?? '0'));\n const gasFeesInDecGwei = totalGasLimitInDec\n .times(totalFeePerGasInDecGwei)\n .plus(l1GasFeesInDecGWei);\n const gasFeesInDecEth = gasFeesInDecGwei.times(new BigNumber(10).pow(-9));\n\n const gasFeesInDisplayCurrency = nativeToDisplayCurrencyExchangeRate\n ? gasFeesInDecEth.times(nativeToDisplayCurrencyExchangeRate.toString())\n : null;\n const gasFeesInUSD = nativeToUsdExchangeRate\n ? gasFeesInDecEth.times(nativeToUsdExchangeRate.toString())\n : null;\n\n return {\n amount: gasFeesInDecEth.toString(),\n valueInCurrency: gasFeesInDisplayCurrency?.toString() ?? null,\n usd: gasFeesInUSD?.toString() ?? null,\n };\n};\n\nexport const calcEstimatedAndMaxTotalGasFee = ({\n bridgeQuote: { approval, trade, l1GasFeesInHexWei },\n estimatedBaseFeeInDecGwei,\n maxFeePerGasInDecGwei,\n maxPriorityFeePerGasInDecGwei,\n exchangeRate: nativeToDisplayCurrencyExchangeRate,\n usdExchangeRate: nativeToUsdExchangeRate,\n}: {\n bridgeQuote: QuoteResponse<TxData> & L1GasFees;\n estimatedBaseFeeInDecGwei: string;\n maxFeePerGasInDecGwei: string;\n maxPriorityFeePerGasInDecGwei: string;\n} & ExchangeRate): QuoteMetadata['gasFee'] => {\n // Estimated gas fees spent after receiving refunds, this is shown to the user\n const {\n amount: amountEffective,\n valueInCurrency: valueInCurrencyEffective,\n usd: usdEffective,\n } = calcTotalGasFee({\n // Fallback to gasLimit if effectiveGas is not available\n approvalGasLimit: approval?.effectiveGas ?? approval?.gasLimit,\n tradeGasLimit: trade?.effectiveGas ?? trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\n priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n });\n\n // Estimated total gas fee, including refunded fees (medium)\n const { amount, valueInCurrency, usd } = calcTotalGasFee({\n approvalGasLimit: approval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\n priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n });\n\n // Max gas fee (high), used to disable submission of the transaction\n const {\n amount: amountMax,\n valueInCurrency: valueInCurrencyMax,\n usd: usdMax,\n } = calcTotalGasFee({\n approvalGasLimit: approval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: maxFeePerGasInDecGwei,\n priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n });\n\n return {\n effective: {\n amount: amountEffective,\n valueInCurrency: valueInCurrencyEffective,\n usd: usdEffective,\n },\n total: {\n amount,\n valueInCurrency,\n usd,\n },\n max: {\n amount: amountMax,\n valueInCurrency: valueInCurrencyMax,\n usd: usdMax,\n },\n };\n};\n\n/**\n * Calculates the total estimated network fees for the bridge transaction\n *\n * @param gasFee - The gas fee for the bridge transaction\n * @param gasFee.effective - The fee to display to the user. If not available, this is equal to the gasLimit (total)\n * @param relayerFee - The relayer fee paid to bridge providers\n * @returns The total estimated network fee for the bridge transaction, including the relayer fee paid to bridge providers\n */\nexport const calcTotalEstimatedNetworkFee = (\n {\n effective: gasFeeToDisplay,\n }: ReturnType<typeof calcEstimatedAndMaxTotalGasFee>,\n relayerFee: ReturnType<typeof calcRelayerFee>,\n) => {\n return {\n amount: new BigNumber(gasFeeToDisplay?.amount ?? '0')\n .plus(relayerFee.amount)\n .toString(),\n valueInCurrency: gasFeeToDisplay?.valueInCurrency\n ? new BigNumber(gasFeeToDisplay.valueInCurrency)\n .plus(relayerFee.valueInCurrency || '0')\n .toString()\n : null,\n usd: gasFeeToDisplay?.usd\n ? new BigNumber(gasFeeToDisplay.usd)\n .plus(relayerFee.usd || '0')\n .toString()\n : null,\n };\n};\n\nexport const calcTotalMaxNetworkFee = (\n gasFee: ReturnType<typeof calcEstimatedAndMaxTotalGasFee>,\n relayerFee: ReturnType<typeof calcRelayerFee>,\n) => {\n return {\n amount: new BigNumber(gasFee.max.amount).plus(relayerFee.amount).toString(),\n valueInCurrency: gasFee.max.valueInCurrency\n ? new BigNumber(gasFee.max.valueInCurrency)\n .plus(relayerFee.valueInCurrency || '0')\n .toString()\n : null,\n usd: gasFee.max.usd\n ? new BigNumber(gasFee.max.usd).plus(relayerFee.usd || '0').toString()\n : null,\n };\n};\n\n// Gas is included for some swap quotes and this is the value displayed in the client\nexport const calcIncludedTxFees = (\n { gasIncluded, gasIncluded7702, srcAsset, feeData: { txFee } }: Quote,\n srcTokenExchangeRate: ExchangeRate,\n destTokenExchangeRate: ExchangeRate,\n) => {\n if (!txFee || !(gasIncluded || gasIncluded7702)) {\n return null;\n }\n // Use exchange rate of the token that is being used to pay for the transaction\n const { exchangeRate, usdExchangeRate } =\n txFee.asset.assetId === srcAsset.assetId\n ? srcTokenExchangeRate\n : destTokenExchangeRate;\n const normalizedTxFeeAmount = calcTokenAmount(\n txFee.amount,\n txFee.asset.decimals,\n );\n\n return {\n amount: normalizedTxFeeAmount.toString(),\n valueInCurrency: exchangeRate\n ? normalizedTxFeeAmount.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate\n ? normalizedTxFeeAmount.times(usdExchangeRate).toString()\n : null,\n };\n};\n\nexport const calcAdjustedReturn = (\n toTokenAmount: ReturnType<typeof calcToAmount>,\n totalEstimatedNetworkFee: ReturnType<typeof calcTotalEstimatedNetworkFee>,\n { feeData: { txFee }, destAsset: { assetId: destAssetId } }: Quote,\n) => {\n // If gas is included and is taken from the dest token, don't subtract network fee from return\n if (txFee?.asset?.assetId === destAssetId) {\n return {\n valueInCurrency: toTokenAmount.valueInCurrency,\n usd: toTokenAmount.usd,\n };\n }\n return {\n valueInCurrency:\n toTokenAmount.valueInCurrency && totalEstimatedNetworkFee.valueInCurrency\n ? new BigNumber(toTokenAmount.valueInCurrency)\n .minus(totalEstimatedNetworkFee.valueInCurrency)\n .toString()\n : null,\n usd:\n toTokenAmount.usd && totalEstimatedNetworkFee.usd\n ? new BigNumber(toTokenAmount.usd)\n .minus(totalEstimatedNetworkFee.usd)\n .toString()\n : null,\n };\n};\n\nexport const calcSwapRate = (sentAmount: string, destTokenAmount: string) =>\n new BigNumber(destTokenAmount).div(sentAmount).toString();\n\nexport const calcCost = (\n adjustedReturn: ReturnType<typeof calcAdjustedReturn>,\n sentAmount: ReturnType<typeof calcSentAmount>,\n) => ({\n valueInCurrency:\n adjustedReturn.valueInCurrency && sentAmount.valueInCurrency\n ? new BigNumber(sentAmount.valueInCurrency)\n .minus(adjustedReturn.valueInCurrency)\n .toString()\n : null,\n usd:\n adjustedReturn.usd && sentAmount.usd\n ? new BigNumber(sentAmount.usd).minus(adjustedReturn.usd).toString()\n : null,\n});\n\n/**\n * Calculates the slippage absolute value percentage based on the adjusted return and sent amount.\n *\n * @param adjustedReturn - Adjusted return value\n * @param sentAmount - Sent amount value\n * @returns the slippage in percentage\n */\nexport const calcSlippagePercentage = (\n adjustedReturn: ReturnType<typeof calcAdjustedReturn>,\n sentAmount: ReturnType<typeof calcSentAmount>,\n): string | null => {\n const cost = calcCost(adjustedReturn, sentAmount);\n\n if (cost.valueInCurrency && sentAmount.valueInCurrency) {\n return new BigNumber(cost.valueInCurrency)\n .div(sentAmount.valueInCurrency)\n .times(100)\n .abs()\n .toString();\n }\n\n if (cost.usd && sentAmount.usd) {\n return new BigNumber(cost.usd)\n .div(sentAmount.usd)\n .times(100)\n .abs()\n .toString();\n }\n\n return null;\n};\n\nexport const formatEtaInMinutes = (\n estimatedProcessingTimeInSeconds: number,\n) => {\n if (estimatedProcessingTimeInSeconds < 60) {\n return `< 1`;\n }\n return (estimatedProcessingTimeInSeconds / 60).toFixed();\n};\n\nexport const sortQuotes = (\n quotes: QuoteResponse[],\n featureId: FeatureId | null,\n) => {\n // Sort perps quotes by increasing estimated processing time (fastest first)\n if (featureId === FeatureId.PERPS) {\n return quotes.sort((a, b) => {\n return (\n a.estimatedProcessingTimeInSeconds - b.estimatedProcessingTimeInSeconds\n );\n });\n }\n return quotes;\n};\n"]}
1
+ {"version":3,"file":"quote.mjs","sourceRoot":"","sources":["../../src/utils/quote.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,EACL,eAAe,EAChB,mCAAmC;AACpC,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,qBAAiB;AAC5D,OAAO,EAAE,SAAS,EAAE,yBAAqB;AAazC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,cAA4C,EAC5C,aAAa,GAAG,IAAI,EACmB,EAAE;IACzC,MAAM,YAAY,GAAG;QACnB,iBAAiB;QACjB,kBAAkB;QAClB,YAAY;QACZ,aAAa;QACb,eAAe;KAChB,CAAC;IACF,IAAI,aAAa,EAAE,CAAC;QAClB,YAAY,CAAC,IA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M,UAAU,GAAG,CACxB,MAAuB,EACvB,SAA2B,EAC3B,EAAE;IACF,4EAA4E;IAC5E,IAAI,SAAS,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC1B,OAAO,CACL,CAAC,CAAC,gCAAgC,GAAG,CAAC,CAAC,gCAAgC,CACxE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import {\n convertHexToDecimal,\n toHex,\n weiHexToGweiDec,\n} from '@metamask/controller-utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { isNativeAddress, isNonEvmChainId } from './bridge';\nimport { FeatureId } from './validators';\nimport type {\n BridgeAsset,\n ExchangeRate,\n GenericQuoteRequest,\n L1GasFees,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n NonEvmFees,\n TxData,\n} from '../types';\n\nexport const isValidQuoteRequest = (\n partialRequest: Partial<GenericQuoteRequest>,\n requireAmount = true,\n): partialRequest is GenericQuoteRequest => {\n const stringFields = [\n 'srcTokenAddress',\n 'destTokenAddress',\n 'srcChainId',\n 'destChainId',\n 'walletAddress',\n ];\n if (requireAmount) {\n stringFields.push('srcTokenAmount');\n }\n // If bridging between different chain types or different non-EVM chains, require dest wallet address\n // Cases that need destWalletAddress:\n // 1. EVM -> non-EVM\n // 2. non-EVM -> EVM\n // 3. non-EVM -> different non-EVM (e.g., SOL -> BTC)\n // Only same-chain swaps don't need destWalletAddress\n if (\n partialRequest.destChainId &&\n partialRequest.srcChainId &&\n partialRequest.destChainId !== partialRequest.srcChainId && // Different chains\n (isNonEvmChainId(partialRequest.destChainId) ||\n isNonEvmChainId(partialRequest.srcChainId)) // At least one is non-EVM\n ) {\n stringFields.push('destWalletAddress');\n if (!partialRequest.destWalletAddress) {\n return false;\n }\n }\n const numberFields = [];\n // if slippage is defined, require it to be a number\n if (partialRequest.slippage !== undefined) {\n numberFields.push('slippage');\n }\n\n return (\n stringFields.every(\n (field) =>\n field in partialRequest &&\n typeof partialRequest[field as keyof typeof partialRequest] ===\n 'string' &&\n partialRequest[field as keyof typeof partialRequest] !== undefined &&\n partialRequest[field as keyof typeof partialRequest] !== '' &&\n partialRequest[field as keyof typeof partialRequest] !== null,\n ) &&\n numberFields.every(\n (field) =>\n field in partialRequest &&\n typeof partialRequest[field as keyof typeof partialRequest] ===\n 'number' &&\n partialRequest[field as keyof typeof partialRequest] !== undefined &&\n !isNaN(Number(partialRequest[field as keyof typeof partialRequest])) &&\n partialRequest[field as keyof typeof partialRequest] !== null,\n ) &&\n (requireAmount\n ? Boolean((partialRequest.srcTokenAmount ?? '').match(/^[1-9]\\d*$/u))\n : true)\n );\n};\n\n/**\n * Generates a pseudo-unique string that identifies each quote by aggregator, bridge, and steps\n *\n * @param quote - The quote to generate an identifier for\n * @returns A pseudo-unique string that identifies the quote\n */\nexport const getQuoteIdentifier = (quote: QuoteResponse['quote']) =>\n `${quote.bridgeId}-${quote.bridges[0]}-${quote.steps.length}`;\n\nconst calcTokenAmount = (value: string | BigNumber, decimals: number) => {\n const divisor = new BigNumber(10).pow(decimals ?? 0);\n return new BigNumber(value).div(divisor);\n};\n\nexport const calcNonEvmTotalNetworkFee = (\n bridgeQuote: QuoteResponse & NonEvmFees,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n const { nonEvmFeesInNative } = bridgeQuote;\n // Fees are now stored directly in native units (SOL, BTC) without conversion\n const feeInNative = new BigNumber(nonEvmFeesInNative ?? '0');\n\n return {\n amount: feeInNative.toString(),\n valueInCurrency: exchangeRate\n ? feeInNative.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate ? feeInNative.times(usdExchangeRate).toString() : null,\n };\n};\n\nexport const calcToAmount = (\n destTokenAmount: string,\n destAsset: BridgeAsset,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n const normalizedDestAmount = calcTokenAmount(\n destTokenAmount,\n destAsset.decimals,\n );\n return {\n amount: normalizedDestAmount.toString(),\n valueInCurrency: exchangeRate\n ? normalizedDestAmount.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate\n ? normalizedDestAmount.times(usdExchangeRate).toString()\n : null,\n };\n};\n\nexport const calcSentAmount = (\n { srcTokenAmount, srcAsset, feeData }: Quote,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n // Find all fees that will be taken from the src token\n const srcTokenFees = Object.values(feeData).filter(\n (fee) => fee && fee.amount && fee.asset?.assetId === srcAsset.assetId,\n );\n const sentAmount = srcTokenFees.reduce(\n (acc, { amount }) => acc.plus(amount),\n new BigNumber(srcTokenAmount),\n );\n const normalizedSentAmount = calcTokenAmount(sentAmount, srcAsset.decimals);\n return {\n amount: normalizedSentAmount.toString(),\n valueInCurrency: exchangeRate\n ? normalizedSentAmount.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate\n ? normalizedSentAmount.times(usdExchangeRate).toString()\n : null,\n };\n};\n\nexport const calcRelayerFee = (\n quoteResponse: QuoteResponse<TxData, TxData>,\n { exchangeRate, usdExchangeRate }: ExchangeRate,\n) => {\n const { quote, trade } = quoteResponse;\n const relayerFeeAmount = new BigNumber(\n convertHexToDecimal(trade.value || '0x0'),\n );\n let relayerFeeInNative = calcTokenAmount(relayerFeeAmount, 18);\n\n // Subtract srcAmount and other fees from trade value if srcAsset is native\n if (isNativeAddress(quote.srcAsset.address)) {\n const sentAmountInNative = calcSentAmount(quote, {\n exchangeRate,\n usdExchangeRate,\n }).amount;\n relayerFeeInNative = relayerFeeInNative.minus(sentAmountInNative);\n }\n\n return {\n amount: relayerFeeInNative,\n valueInCurrency: exchangeRate\n ? relayerFeeInNative.times(exchangeRate)\n : null,\n usd: usdExchangeRate ? relayerFeeInNative.times(usdExchangeRate) : null,\n };\n};\n\nconst calcTotalGasFee = ({\n approvalGasLimit,\n tradeGasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei,\n priorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n}: {\n approvalGasLimit?: number | null;\n tradeGasLimit?: number | null;\n l1GasFeesInHexWei?: string | null;\n feePerGasInDecGwei: string;\n priorityFeePerGasInDecGwei: string;\n nativeToDisplayCurrencyExchangeRate?: string;\n nativeToUsdExchangeRate?: string;\n}) => {\n const totalGasLimitInDec = new BigNumber(\n tradeGasLimit?.toString() ?? '0',\n ).plus(approvalGasLimit?.toString() ?? '0');\n\n const totalFeePerGasInDecGwei = new BigNumber(feePerGasInDecGwei).plus(\n priorityFeePerGasInDecGwei,\n );\n const l1GasFeesInDecGWei = weiHexToGweiDec(toHex(l1GasFeesInHexWei ?? '0'));\n const gasFeesInDecGwei = totalGasLimitInDec\n .times(totalFeePerGasInDecGwei)\n .plus(l1GasFeesInDecGWei);\n const gasFeesInDecEth = gasFeesInDecGwei.times(new BigNumber(10).pow(-9));\n\n const gasFeesInDisplayCurrency = nativeToDisplayCurrencyExchangeRate\n ? gasFeesInDecEth.times(nativeToDisplayCurrencyExchangeRate.toString())\n : null;\n const gasFeesInUSD = nativeToUsdExchangeRate\n ? gasFeesInDecEth.times(nativeToUsdExchangeRate.toString())\n : null;\n\n return {\n amount: gasFeesInDecEth.toString(),\n valueInCurrency: gasFeesInDisplayCurrency?.toString() ?? null,\n usd: gasFeesInUSD?.toString() ?? null,\n };\n};\n\nexport const calcEstimatedAndMaxTotalGasFee = ({\n bridgeQuote: { approval, trade, l1GasFeesInHexWei },\n estimatedBaseFeeInDecGwei,\n maxFeePerGasInDecGwei,\n maxPriorityFeePerGasInDecGwei,\n exchangeRate: nativeToDisplayCurrencyExchangeRate,\n usdExchangeRate: nativeToUsdExchangeRate,\n}: {\n bridgeQuote: QuoteResponse<TxData, TxData> & L1GasFees;\n estimatedBaseFeeInDecGwei: string;\n maxFeePerGasInDecGwei: string;\n maxPriorityFeePerGasInDecGwei: string;\n} & ExchangeRate): QuoteMetadata['gasFee'] => {\n // Estimated gas fees spent after receiving refunds, this is shown to the user\n const {\n amount: amountEffective,\n valueInCurrency: valueInCurrencyEffective,\n usd: usdEffective,\n } = calcTotalGasFee({\n // Fallback to gasLimit if effectiveGas is not available\n approvalGasLimit: approval?.effectiveGas ?? approval?.gasLimit,\n tradeGasLimit: trade?.effectiveGas ?? trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\n priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n });\n\n // Estimated total gas fee, including refunded fees (medium)\n const { amount, valueInCurrency, usd } = calcTotalGasFee({\n approvalGasLimit: approval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\n priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n });\n\n // Max gas fee (high), used to disable submission of the transaction\n const {\n amount: amountMax,\n valueInCurrency: valueInCurrencyMax,\n usd: usdMax,\n } = calcTotalGasFee({\n approvalGasLimit: approval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: maxFeePerGasInDecGwei,\n priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n });\n\n return {\n effective: {\n amount: amountEffective,\n valueInCurrency: valueInCurrencyEffective,\n usd: usdEffective,\n },\n total: {\n amount,\n valueInCurrency,\n usd,\n },\n max: {\n amount: amountMax,\n valueInCurrency: valueInCurrencyMax,\n usd: usdMax,\n },\n };\n};\n\n/**\n * Calculates the total estimated network fees for the bridge transaction\n *\n * @param gasFee - The gas fee for the bridge transaction\n * @param gasFee.effective - The fee to display to the user. If not available, this is equal to the gasLimit (total)\n * @param relayerFee - The relayer fee paid to bridge providers\n * @returns The total estimated network fee for the bridge transaction, including the relayer fee paid to bridge providers\n */\nexport const calcTotalEstimatedNetworkFee = (\n {\n effective: gasFeeToDisplay,\n }: ReturnType<typeof calcEstimatedAndMaxTotalGasFee>,\n relayerFee: ReturnType<typeof calcRelayerFee>,\n) => {\n return {\n amount: new BigNumber(gasFeeToDisplay?.amount ?? '0')\n .plus(relayerFee.amount)\n .toString(),\n valueInCurrency: gasFeeToDisplay?.valueInCurrency\n ? new BigNumber(gasFeeToDisplay.valueInCurrency)\n .plus(relayerFee.valueInCurrency || '0')\n .toString()\n : null,\n usd: gasFeeToDisplay?.usd\n ? new BigNumber(gasFeeToDisplay.usd)\n .plus(relayerFee.usd || '0')\n .toString()\n : null,\n };\n};\n\nexport const calcTotalMaxNetworkFee = (\n gasFee: ReturnType<typeof calcEstimatedAndMaxTotalGasFee>,\n relayerFee: ReturnType<typeof calcRelayerFee>,\n) => {\n return {\n amount: new BigNumber(gasFee.max.amount).plus(relayerFee.amount).toString(),\n valueInCurrency: gasFee.max.valueInCurrency\n ? new BigNumber(gasFee.max.valueInCurrency)\n .plus(relayerFee.valueInCurrency || '0')\n .toString()\n : null,\n usd: gasFee.max.usd\n ? new BigNumber(gasFee.max.usd).plus(relayerFee.usd || '0').toString()\n : null,\n };\n};\n\n// Gas is included for some swap quotes and this is the value displayed in the client\nexport const calcIncludedTxFees = (\n { gasIncluded, gasIncluded7702, srcAsset, feeData: { txFee } }: Quote,\n srcTokenExchangeRate: ExchangeRate,\n destTokenExchangeRate: ExchangeRate,\n) => {\n if (!txFee || !(gasIncluded || gasIncluded7702)) {\n return null;\n }\n // Use exchange rate of the token that is being used to pay for the transaction\n const { exchangeRate, usdExchangeRate } =\n txFee.asset.assetId === srcAsset.assetId\n ? srcTokenExchangeRate\n : destTokenExchangeRate;\n const normalizedTxFeeAmount = calcTokenAmount(\n txFee.amount,\n txFee.asset.decimals,\n );\n\n return {\n amount: normalizedTxFeeAmount.toString(),\n valueInCurrency: exchangeRate\n ? normalizedTxFeeAmount.times(exchangeRate).toString()\n : null,\n usd: usdExchangeRate\n ? normalizedTxFeeAmount.times(usdExchangeRate).toString()\n : null,\n };\n};\n\nexport const calcAdjustedReturn = (\n toTokenAmount: ReturnType<typeof calcToAmount>,\n totalEstimatedNetworkFee: ReturnType<typeof calcTotalEstimatedNetworkFee>,\n { feeData: { txFee }, destAsset: { assetId: destAssetId } }: Quote,\n) => {\n // If gas is included and is taken from the dest token, don't subtract network fee from return\n if (txFee?.asset?.assetId === destAssetId) {\n return {\n valueInCurrency: toTokenAmount.valueInCurrency,\n usd: toTokenAmount.usd,\n };\n }\n return {\n valueInCurrency:\n toTokenAmount.valueInCurrency && totalEstimatedNetworkFee.valueInCurrency\n ? new BigNumber(toTokenAmount.valueInCurrency)\n .minus(totalEstimatedNetworkFee.valueInCurrency)\n .toString()\n : null,\n usd:\n toTokenAmount.usd && totalEstimatedNetworkFee.usd\n ? new BigNumber(toTokenAmount.usd)\n .minus(totalEstimatedNetworkFee.usd)\n .toString()\n : null,\n };\n};\n\nexport const calcSwapRate = (sentAmount: string, destTokenAmount: string) =>\n new BigNumber(destTokenAmount).div(sentAmount).toString();\n\nexport const calcCost = (\n adjustedReturn: ReturnType<typeof calcAdjustedReturn>,\n sentAmount: ReturnType<typeof calcSentAmount>,\n) => ({\n valueInCurrency:\n adjustedReturn.valueInCurrency && sentAmount.valueInCurrency\n ? new BigNumber(sentAmount.valueInCurrency)\n .minus(adjustedReturn.valueInCurrency)\n .toString()\n : null,\n usd:\n adjustedReturn.usd && sentAmount.usd\n ? new BigNumber(sentAmount.usd).minus(adjustedReturn.usd).toString()\n : null,\n});\n\n/**\n * Calculates the slippage absolute value percentage based on the adjusted return and sent amount.\n *\n * @param adjustedReturn - Adjusted return value\n * @param sentAmount - Sent amount value\n * @returns the slippage in percentage\n */\nexport const calcSlippagePercentage = (\n adjustedReturn: ReturnType<typeof calcAdjustedReturn>,\n sentAmount: ReturnType<typeof calcSentAmount>,\n): string | null => {\n const cost = calcCost(adjustedReturn, sentAmount);\n\n if (cost.valueInCurrency && sentAmount.valueInCurrency) {\n return new BigNumber(cost.valueInCurrency)\n .div(sentAmount.valueInCurrency)\n .times(100)\n .abs()\n .toString();\n }\n\n if (cost.usd && sentAmount.usd) {\n return new BigNumber(cost.usd)\n .div(sentAmount.usd)\n .times(100)\n .abs()\n .toString();\n }\n\n return null;\n};\n\nexport const formatEtaInMinutes = (\n estimatedProcessingTimeInSeconds: number,\n) => {\n if (estimatedProcessingTimeInSeconds < 60) {\n return `< 1`;\n }\n return (estimatedProcessingTimeInSeconds / 60).toFixed();\n};\n\nexport const sortQuotes = (\n quotes: QuoteResponse[],\n featureId: FeatureId | null,\n) => {\n // Sort perps quotes by increasing estimated processing time (fastest first)\n if (featureId === FeatureId.PERPS) {\n return quotes.sort((a, b) => {\n return (\n a.estimatedProcessingTimeInSeconds - b.estimatedProcessingTimeInSeconds\n );\n });\n }\n return quotes;\n};\n"]}
@@ -50,9 +50,10 @@ exports.getMinimumBalanceForRentExemptionInLamports = getMinimumBalanceForRentEx
50
50
  * @param transaction - The base64 encoded transaction string
51
51
  * @param accountId - The account ID
52
52
  * @param scope - The CAIP-2 chain scope
53
+ * @param options - Additional options to include in the request
53
54
  * @returns The snap request object
54
55
  */
55
- const computeFeeRequest = (snapId, transaction, accountId, scope) => {
56
+ const computeFeeRequest = (snapId, transaction, accountId, scope, options) => {
56
57
  return {
57
58
  // TODO: remove 'as never' typing.
58
59
  snapId: snapId,
@@ -66,6 +67,7 @@ const computeFeeRequest = (snapId, transaction, accountId, scope) => {
66
67
  transaction,
67
68
  accountId,
68
69
  scope,
70
+ ...(options && { options }),
69
71
  },
70
72
  },
71
73
  };
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.cjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":";;;AAAA,uDAAiD;AAEjD,+BAAkC;AAElC,oDAAsE;AAG/D,MAAM,wCAAwC,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AAM,EAAE;gBACN,WAAW;gBACX,SAAS;gBACT,KAAK;aACN;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,iBAAiB,qBAsB5B","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport type { CaipChainId } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { DEFAULT_BRIDGE_CONTROLLER_STATE } from '../constants/bridge';\nimport type { BridgeControllerMessenger } from '../types';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, { commitment: 'confirmed' }],\n },\n },\n },\n };\n};\n\n/**\n * Gets the minimum balance for rent exemption in lamports for a given chain ID and selected account\n *\n * @param snapId - The snap ID to send the request to\n * @param messenger - The messaging system to use to call the snap controller\n * @returns The minimum balance for rent exemption in lamports\n */\nexport const getMinimumBalanceForRentExemptionInLamports = async (\n snapId: string,\n messenger: BridgeControllerMessenger,\n) => {\n return String(\n await messenger\n .call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(snapId),\n )\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .catch((error: any) => {\n console.error(\n 'Error setting minimum balance for rent exemption',\n error,\n );\n return DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n }),\n );\n};\n\n/**\n * Creates a request to compute fees for a transaction using the new unified interface\n * Returns fees in native token amount (e.g., Solana instead of Lamports)\n *\n * @param snapId - The snap ID to send the request to\n * @param transaction - The base64 encoded transaction string\n * @param accountId - The account ID\n * @param scope - The CAIP-2 chain scope\n * @returns The snap request object\n */\nexport const computeFeeRequest = (\n snapId: string,\n transaction: string,\n accountId: string,\n scope: CaipChainId,\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: 'computeFee',\n params: {\n transaction,\n accountId,\n scope,\n },\n },\n };\n};\n"]}
1
+ {"version":3,"file":"snaps.cjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":";;;AAAA,uDAAiD;AAEjD,+BAAkC;AAElC,oDAAsE;AAG/D,MAAM,wCAAwC,GAAG,CAAC,MAAc,EAAE,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,mBAA4B;QACrC,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACN,KAAK,EAAE,sBAAQ,CAAC,OAAO;gBACvB,OAAO,EAAE;oBACP,EAAE,EAAE,IAAA,SAAI,GAAE;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;oBAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;iBACzC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,wCAAwC,4CAmBnD;AAEF;;;;;;GAMG;AACI,MAAM,2CAA2C,GAAG,KAAK,EAC9D,MAAc,EACd,SAAoC,EACpC,EAAE;IACF,OAAO,MAAM,CACX,MAAM,SAAS;SACZ,IAAI,CACH,8BAA8B,EAC9B,IAAA,gDAAwC,EAAC,MAAM,CAAC,CACjD;QACD,8DAA8D;SAC7D,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;QACpB,OAAO,CAAC,KAAK,CACX,kDAAkD,EAClD,KAAK,CACN,CAAC;QACF,OAAO,wCAA+B,CAAC,wCAAwC,CAAC;IAClF,CAAC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,2CAA2C,+CAmBtD;AAEF;;;;;;;;;;GAUG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,WAAmB,EACnB,SAAiB,EACjB,KAAkB,EAClB,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,IAAA,SAAI,GAAE;YACV,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE;gBACN,WAAW;gBACX,SAAS;gBACT,KAAK;gBACL,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;aAC5B;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAxBW,QAAA,iBAAiB,qBAwB5B","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport type { CaipChainId } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { DEFAULT_BRIDGE_CONTROLLER_STATE } from '../constants/bridge';\nimport type { BridgeControllerMessenger } from '../types';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, { commitment: 'confirmed' }],\n },\n },\n },\n };\n};\n\n/**\n * Gets the minimum balance for rent exemption in lamports for a given chain ID and selected account\n *\n * @param snapId - The snap ID to send the request to\n * @param messenger - The messaging system to use to call the snap controller\n * @returns The minimum balance for rent exemption in lamports\n */\nexport const getMinimumBalanceForRentExemptionInLamports = async (\n snapId: string,\n messenger: BridgeControllerMessenger,\n) => {\n return String(\n await messenger\n .call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(snapId),\n )\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .catch((error: any) => {\n console.error(\n 'Error setting minimum balance for rent exemption',\n error,\n );\n return DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n }),\n );\n};\n\n/**\n * Creates a request to compute fees for a transaction using the new unified interface\n * Returns fees in native token amount (e.g., Solana instead of Lamports)\n *\n * @param snapId - The snap ID to send the request to\n * @param transaction - The base64 encoded transaction string\n * @param accountId - The account ID\n * @param scope - The CAIP-2 chain scope\n * @param options - Additional options to include in the request\n * @returns The snap request object\n */\nexport const computeFeeRequest = (\n snapId: string,\n transaction: string,\n accountId: string,\n scope: CaipChainId,\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: 'computeFee',\n params: {\n transaction,\n accountId,\n scope,\n ...(options && { options }),\n },\n },\n };\n};\n"]}
@@ -37,9 +37,10 @@ export declare const getMinimumBalanceForRentExemptionInLamports: (snapId: strin
37
37
  * @param transaction - The base64 encoded transaction string
38
38
  * @param accountId - The account ID
39
39
  * @param scope - The CAIP-2 chain scope
40
+ * @param options - Additional options to include in the request
40
41
  * @returns The snap request object
41
42
  */
42
- export declare const computeFeeRequest: (snapId: string, transaction: string, accountId: string, scope: CaipChainId) => {
43
+ export declare const computeFeeRequest: (snapId: string, transaction: string, accountId: string, scope: CaipChainId, options?: Record<string, unknown>) => {
43
44
  snapId: never;
44
45
  origin: string;
45
46
  handler: never;
@@ -48,6 +49,7 @@ export declare const computeFeeRequest: (snapId: string, transaction: string, ac
48
49
  jsonrpc: string;
49
50
  method: string;
50
51
  params: {
52
+ options?: Record<string, unknown> | undefined;
51
53
  transaction: string;
52
54
  accountId: string;
53
55
  scope: `${string}:${string}`;
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.d.cts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAInD,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAiB;AAE1D,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2CAA2C,WAC9C,MAAM,0DAkBf,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,WACpB,MAAM,eACD,MAAM,aACR,MAAM,SACV,WAAW;;;;;;;;;;;;;;CAkBnB,CAAC"}
1
+ {"version":3,"file":"snaps.d.cts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAInD,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAiB;AAE1D,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2CAA2C,WAC9C,MAAM,0DAkBf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,WACpB,MAAM,eACD,MAAM,aACR,MAAM,SACV,WAAW,YACR,OAAO,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;;;;CAmBlC,CAAC"}
@@ -37,9 +37,10 @@ export declare const getMinimumBalanceForRentExemptionInLamports: (snapId: strin
37
37
  * @param transaction - The base64 encoded transaction string
38
38
  * @param accountId - The account ID
39
39
  * @param scope - The CAIP-2 chain scope
40
+ * @param options - Additional options to include in the request
40
41
  * @returns The snap request object
41
42
  */
42
- export declare const computeFeeRequest: (snapId: string, transaction: string, accountId: string, scope: CaipChainId) => {
43
+ export declare const computeFeeRequest: (snapId: string, transaction: string, accountId: string, scope: CaipChainId, options?: Record<string, unknown>) => {
43
44
  snapId: never;
44
45
  origin: string;
45
46
  handler: never;
@@ -48,6 +49,7 @@ export declare const computeFeeRequest: (snapId: string, transaction: string, ac
48
49
  jsonrpc: string;
49
50
  method: string;
50
51
  params: {
52
+ options?: Record<string, unknown> | undefined;
51
53
  transaction: string;
52
54
  accountId: string;
53
55
  scope: `${string}:${string}`;
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.d.mts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAInD,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAiB;AAE1D,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2CAA2C,WAC9C,MAAM,0DAkBf,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,WACpB,MAAM,eACD,MAAM,aACR,MAAM,SACV,WAAW;;;;;;;;;;;;;;CAkBnB,CAAC"}
1
+ {"version":3,"file":"snaps.d.mts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAInD,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAiB;AAE1D,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2CAA2C,WAC9C,MAAM,0DAkBf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,WACpB,MAAM,eACD,MAAM,aACR,MAAM,SACV,WAAW,YACR,OAAO,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;;;;CAmBlC,CAAC"}
@@ -45,9 +45,10 @@ export const getMinimumBalanceForRentExemptionInLamports = async (snapId, messen
45
45
  * @param transaction - The base64 encoded transaction string
46
46
  * @param accountId - The account ID
47
47
  * @param scope - The CAIP-2 chain scope
48
+ * @param options - Additional options to include in the request
48
49
  * @returns The snap request object
49
50
  */
50
- export const computeFeeRequest = (snapId, transaction, accountId, scope) => {
51
+ export const computeFeeRequest = (snapId, transaction, accountId, scope, options) => {
51
52
  return {
52
53
  // TODO: remove 'as never' typing.
53
54
  snapId: snapId,
@@ -61,6 +62,7 @@ export const computeFeeRequest = (snapId, transaction, accountId, scope) => {
61
62
  transaction,
62
63
  accountId,
63
64
  scope,
65
+ ...(options && { options }),
64
66
  },
65
67
  },
66
68
  };
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.mjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAEjD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,OAAO,EAAE,+BAA+B,EAAE,gCAA4B;AAGtE,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,MAAc,EAAE,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,mBAA4B;QACrC,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACN,KAAK,EAAE,QAAQ,CAAC,OAAO;gBACvB,OAAO,EAAE;oBACP,EAAE,EAAE,IAAI,EAAE;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;oBAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;iBACzC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2CAA2C,GAAG,KAAK,EAC9D,MAAc,EACd,SAAoC,EACpC,EAAE;IACF,OAAO,MAAM,CACX,MAAM,SAAS;SACZ,IAAI,CACH,8BAA8B,EAC9B,wCAAwC,CAAC,MAAM,CAAC,CACjD;QACD,8DAA8D;SAC7D,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;QACpB,OAAO,CAAC,KAAK,CACX,kDAAkD,EAClD,KAAK,CACN,CAAC;QACF,OAAO,+BAA+B,CAAC,wCAAwC,CAAC;IAClF,CAAC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,WAAmB,EACnB,SAAiB,EACjB,KAAkB,EAClB,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,YAAY;YACpB,MAAM,EAAE;gBACN,WAAW;gBACX,SAAS;gBACT,KAAK;aACN;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport type { CaipChainId } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { DEFAULT_BRIDGE_CONTROLLER_STATE } from '../constants/bridge';\nimport type { BridgeControllerMessenger } from '../types';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, { commitment: 'confirmed' }],\n },\n },\n },\n };\n};\n\n/**\n * Gets the minimum balance for rent exemption in lamports for a given chain ID and selected account\n *\n * @param snapId - The snap ID to send the request to\n * @param messenger - The messaging system to use to call the snap controller\n * @returns The minimum balance for rent exemption in lamports\n */\nexport const getMinimumBalanceForRentExemptionInLamports = async (\n snapId: string,\n messenger: BridgeControllerMessenger,\n) => {\n return String(\n await messenger\n .call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(snapId),\n )\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .catch((error: any) => {\n console.error(\n 'Error setting minimum balance for rent exemption',\n error,\n );\n return DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n }),\n );\n};\n\n/**\n * Creates a request to compute fees for a transaction using the new unified interface\n * Returns fees in native token amount (e.g., Solana instead of Lamports)\n *\n * @param snapId - The snap ID to send the request to\n * @param transaction - The base64 encoded transaction string\n * @param accountId - The account ID\n * @param scope - The CAIP-2 chain scope\n * @returns The snap request object\n */\nexport const computeFeeRequest = (\n snapId: string,\n transaction: string,\n accountId: string,\n scope: CaipChainId,\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: 'computeFee',\n params: {\n transaction,\n accountId,\n scope,\n },\n },\n };\n};\n"]}
1
+ {"version":3,"file":"snaps.mjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAEjD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,OAAO,EAAE,+BAA+B,EAAE,gCAA4B;AAGtE,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,MAAc,EAAE,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,mBAA4B;QACrC,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACN,KAAK,EAAE,QAAQ,CAAC,OAAO;gBACvB,OAAO,EAAE;oBACP,EAAE,EAAE,IAAI,EAAE;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;oBAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;iBACzC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2CAA2C,GAAG,KAAK,EAC9D,MAAc,EACd,SAAoC,EACpC,EAAE;IACF,OAAO,MAAM,CACX,MAAM,SAAS;SACZ,IAAI,CACH,8BAA8B,EAC9B,wCAAwC,CAAC,MAAM,CAAC,CACjD;QACD,8DAA8D;SAC7D,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;QACpB,OAAO,CAAC,KAAK,CACX,kDAAkD,EAClD,KAAK,CACN,CAAC;QACF,OAAO,+BAA+B,CAAC,wCAAwC,CAAC;IAClF,CAAC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,WAAmB,EACnB,SAAiB,EACjB,KAAkB,EAClB,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,YAAY;YACpB,MAAM,EAAE;gBACN,WAAW;gBACX,SAAS;gBACT,KAAK;gBACL,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;aAC5B;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport type { CaipChainId } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { DEFAULT_BRIDGE_CONTROLLER_STATE } from '../constants/bridge';\nimport type { BridgeControllerMessenger } from '../types';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, { commitment: 'confirmed' }],\n },\n },\n },\n };\n};\n\n/**\n * Gets the minimum balance for rent exemption in lamports for a given chain ID and selected account\n *\n * @param snapId - The snap ID to send the request to\n * @param messenger - The messaging system to use to call the snap controller\n * @returns The minimum balance for rent exemption in lamports\n */\nexport const getMinimumBalanceForRentExemptionInLamports = async (\n snapId: string,\n messenger: BridgeControllerMessenger,\n) => {\n return String(\n await messenger\n .call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(snapId),\n )\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .catch((error: any) => {\n console.error(\n 'Error setting minimum balance for rent exemption',\n error,\n );\n return DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n }),\n );\n};\n\n/**\n * Creates a request to compute fees for a transaction using the new unified interface\n * Returns fees in native token amount (e.g., Solana instead of Lamports)\n *\n * @param snapId - The snap ID to send the request to\n * @param transaction - The base64 encoded transaction string\n * @param accountId - The account ID\n * @param scope - The CAIP-2 chain scope\n * @param options - Additional options to include in the request\n * @returns The snap request object\n */\nexport const computeFeeRequest = (\n snapId: string,\n transaction: string,\n accountId: string,\n scope: CaipChainId,\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: 'computeFee',\n params: {\n transaction,\n accountId,\n scope,\n ...(options && { options }),\n },\n },\n };\n};\n"]}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractTradeData = exports.isTronTrade = exports.isBitcoinTrade = exports.isEvmTxData = void 0;
4
+ /**
5
+ * Type guard to check if a trade is an EVM TxData object
6
+ *
7
+ * @param trade - The trade object to check
8
+ * @returns True if the trade is a TxData object with data property
9
+ */
10
+ const isEvmTxData = (trade) => {
11
+ return (typeof trade === 'object' &&
12
+ trade !== null &&
13
+ 'data' in trade &&
14
+ 'chainId' in trade &&
15
+ 'to' in trade);
16
+ };
17
+ exports.isEvmTxData = isEvmTxData;
18
+ /**
19
+ * Type guard to check if a trade is a Bitcoin trade with unsignedPsbtBase64
20
+ *
21
+ * @param trade - The trade object to check
22
+ * @returns True if the trade is a Bitcoin trade with unsignedPsbtBase64 property
23
+ */
24
+ const isBitcoinTrade = (trade) => {
25
+ return (typeof trade === 'object' && trade !== null && 'unsignedPsbtBase64' in trade);
26
+ };
27
+ exports.isBitcoinTrade = isBitcoinTrade;
28
+ /**
29
+ * Type guard to check if a trade is a Tron trade with raw_data_hex
30
+ *
31
+ * @param trade - The trade object to check
32
+ * @returns True if the trade is a Tron trade with raw_data_hex property
33
+ */
34
+ const isTronTrade = (trade) => {
35
+ return typeof trade === 'object' && trade !== null && 'raw_data_hex' in trade;
36
+ };
37
+ exports.isTronTrade = isTronTrade;
38
+ /**
39
+ * Extracts the transaction data from different trade formats
40
+ *
41
+ * @param trade - The trade object which can be a TxData, string, Bitcoin trade, or Tron trade
42
+ * @returns The extracted transaction data as a base64 string for SnapController
43
+ */
44
+ const extractTradeData = (trade) => {
45
+ // Check more specific trade types first to prevent misidentification
46
+ if ((0, exports.isBitcoinTrade)(trade)) {
47
+ // Bitcoin trades are already base64 encoded
48
+ return trade.unsignedPsbtBase64;
49
+ }
50
+ if ((0, exports.isTronTrade)(trade)) {
51
+ // Tron trades need hex to base64 conversion for SnapController
52
+ return Buffer.from(trade.raw_data_hex, 'hex').toString('base64');
53
+ }
54
+ if (typeof trade === 'string') {
55
+ // Solana txs - assuming already in correct format
56
+ return trade;
57
+ }
58
+ if ((0, exports.isEvmTxData)(trade)) {
59
+ // EVM TxData object - return the data property
60
+ return trade.data;
61
+ }
62
+ return '';
63
+ };
64
+ exports.extractTradeData = extractTradeData;
65
+ //# sourceMappingURL=trade-utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade-utils.cjs","sourceRoot":"","sources":["../../src/utils/trade-utils.ts"],"names":[],"mappings":";;;AAKA;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,KAAY,EAAmB,EAAE;IAC3D,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,SAAS,IAAI,KAAK;QAClB,IAAI,IAAI,KAAK,CACd,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,WAAW,eAQtB;AAEF;;;;;GAKG;AACI,MAAM,cAAc,GAAG,CAAC,KAAY,EAA6B,EAAE;IACxE,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,IAAI,KAAK,CAC7E,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,cAAc,kBAIzB;AAEF;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CAAC,KAAY,EAA0B,EAAE;IAClE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,cAAc,IAAI,KAAK,CAAC;AAChF,CAAC,CAAC;AAFW,QAAA,WAAW,eAEtB;AAEF;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAY,EAAU,EAAE;IACvD,qEAAqE;IACrE,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,4CAA4C;QAC5C,OAAO,KAAK,CAAC,kBAAkB,CAAC;IAClC,CAAC;IAED,IAAI,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE,CAAC;QACvB,+DAA+D;QAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,kDAAkD;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE,CAAC;QACvB,+CAA+C;QAC/C,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAvBW,QAAA,gBAAgB,oBAuB3B","sourcesContent":["import type { BitcoinTradeData, TronTradeData, TxData } from '../types';\n\n// Union type representing all possible trade formats (EVM, Solana, Bitcoin, Tron)\nexport type Trade = TxData | string | BitcoinTradeData | TronTradeData;\n\n/**\n * Type guard to check if a trade is an EVM TxData object\n *\n * @param trade - The trade object to check\n * @returns True if the trade is a TxData object with data property\n */\nexport const isEvmTxData = (trade: Trade): trade is TxData => {\n return (\n typeof trade === 'object' &&\n trade !== null &&\n 'data' in trade &&\n 'chainId' in trade &&\n 'to' in trade\n );\n};\n\n/**\n * Type guard to check if a trade is a Bitcoin trade with unsignedPsbtBase64\n *\n * @param trade - The trade object to check\n * @returns True if the trade is a Bitcoin trade with unsignedPsbtBase64 property\n */\nexport const isBitcoinTrade = (trade: Trade): trade is BitcoinTradeData => {\n return (\n typeof trade === 'object' && trade !== null && 'unsignedPsbtBase64' in trade\n );\n};\n\n/**\n * Type guard to check if a trade is a Tron trade with raw_data_hex\n *\n * @param trade - The trade object to check\n * @returns True if the trade is a Tron trade with raw_data_hex property\n */\nexport const isTronTrade = (trade: Trade): trade is TronTradeData => {\n return typeof trade === 'object' && trade !== null && 'raw_data_hex' in trade;\n};\n\n/**\n * Extracts the transaction data from different trade formats\n *\n * @param trade - The trade object which can be a TxData, string, Bitcoin trade, or Tron trade\n * @returns The extracted transaction data as a base64 string for SnapController\n */\nexport const extractTradeData = (trade: Trade): string => {\n // Check more specific trade types first to prevent misidentification\n if (isBitcoinTrade(trade)) {\n // Bitcoin trades are already base64 encoded\n return trade.unsignedPsbtBase64;\n }\n\n if (isTronTrade(trade)) {\n // Tron trades need hex to base64 conversion for SnapController\n return Buffer.from(trade.raw_data_hex, 'hex').toString('base64');\n }\n\n if (typeof trade === 'string') {\n // Solana txs - assuming already in correct format\n return trade;\n }\n\n if (isEvmTxData(trade)) {\n // EVM TxData object - return the data property\n return trade.data;\n }\n\n return '';\n};\n"]}
@@ -0,0 +1,50 @@
1
+ import type { BitcoinTradeData, TronTradeData, TxData } from "../types.cjs";
2
+ export type Trade = TxData | string | BitcoinTradeData | TronTradeData;
3
+ /**
4
+ * Type guard to check if a trade is an EVM TxData object
5
+ *
6
+ * @param trade - The trade object to check
7
+ * @returns True if the trade is a TxData object with data property
8
+ */
9
+ export declare const isEvmTxData: (trade: Trade) => trade is {
10
+ chainId: number;
11
+ to: string;
12
+ from: string;
13
+ value: string;
14
+ data: string;
15
+ gasLimit: number | null;
16
+ effectiveGas?: number | undefined;
17
+ };
18
+ /**
19
+ * Type guard to check if a trade is a Bitcoin trade with unsignedPsbtBase64
20
+ *
21
+ * @param trade - The trade object to check
22
+ * @returns True if the trade is a Bitcoin trade with unsignedPsbtBase64 property
23
+ */
24
+ export declare const isBitcoinTrade: (trade: Trade) => trade is {
25
+ unsignedPsbtBase64: string;
26
+ inputsToSign: {}[] | null;
27
+ };
28
+ /**
29
+ * Type guard to check if a trade is a Tron trade with raw_data_hex
30
+ *
31
+ * @param trade - The trade object to check
32
+ * @returns True if the trade is a Tron trade with raw_data_hex property
33
+ */
34
+ export declare const isTronTrade: (trade: Trade) => trade is {
35
+ raw_data_hex: string;
36
+ visible?: boolean | undefined;
37
+ raw_data?: {
38
+ contract?: {
39
+ type?: string | undefined;
40
+ }[] | undefined;
41
+ } | null | undefined;
42
+ };
43
+ /**
44
+ * Extracts the transaction data from different trade formats
45
+ *
46
+ * @param trade - The trade object which can be a TxData, string, Bitcoin trade, or Tron trade
47
+ * @returns The extracted transaction data as a base64 string for SnapController
48
+ */
49
+ export declare const extractTradeData: (trade: Trade) => string;
50
+ //# sourceMappingURL=trade-utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade-utils.d.cts","sourceRoot":"","sources":["../../src/utils/trade-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,EAAE,qBAAiB;AAGxE,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAEvE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK;;;;;;;;CAQvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,UAAW,KAAK;;;CAI1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK;;;;;;;;CAEvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,UAAW,KAAK,KAAG,MAuB/C,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { BitcoinTradeData, TronTradeData, TxData } from "../types.mjs";
2
+ export type Trade = TxData | string | BitcoinTradeData | TronTradeData;
3
+ /**
4
+ * Type guard to check if a trade is an EVM TxData object
5
+ *
6
+ * @param trade - The trade object to check
7
+ * @returns True if the trade is a TxData object with data property
8
+ */
9
+ export declare const isEvmTxData: (trade: Trade) => trade is {
10
+ chainId: number;
11
+ to: string;
12
+ from: string;
13
+ value: string;
14
+ data: string;
15
+ gasLimit: number | null;
16
+ effectiveGas?: number | undefined;
17
+ };
18
+ /**
19
+ * Type guard to check if a trade is a Bitcoin trade with unsignedPsbtBase64
20
+ *
21
+ * @param trade - The trade object to check
22
+ * @returns True if the trade is a Bitcoin trade with unsignedPsbtBase64 property
23
+ */
24
+ export declare const isBitcoinTrade: (trade: Trade) => trade is {
25
+ unsignedPsbtBase64: string;
26
+ inputsToSign: {}[] | null;
27
+ };
28
+ /**
29
+ * Type guard to check if a trade is a Tron trade with raw_data_hex
30
+ *
31
+ * @param trade - The trade object to check
32
+ * @returns True if the trade is a Tron trade with raw_data_hex property
33
+ */
34
+ export declare const isTronTrade: (trade: Trade) => trade is {
35
+ raw_data_hex: string;
36
+ visible?: boolean | undefined;
37
+ raw_data?: {
38
+ contract?: {
39
+ type?: string | undefined;
40
+ }[] | undefined;
41
+ } | null | undefined;
42
+ };
43
+ /**
44
+ * Extracts the transaction data from different trade formats
45
+ *
46
+ * @param trade - The trade object which can be a TxData, string, Bitcoin trade, or Tron trade
47
+ * @returns The extracted transaction data as a base64 string for SnapController
48
+ */
49
+ export declare const extractTradeData: (trade: Trade) => string;
50
+ //# sourceMappingURL=trade-utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade-utils.d.mts","sourceRoot":"","sources":["../../src/utils/trade-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,EAAE,qBAAiB;AAGxE,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAEvE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK;;;;;;;;CAQvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,UAAW,KAAK;;;CAI1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK;;;;;;;;CAEvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,UAAW,KAAK,KAAG,MAuB/C,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Type guard to check if a trade is an EVM TxData object
3
+ *
4
+ * @param trade - The trade object to check
5
+ * @returns True if the trade is a TxData object with data property
6
+ */
7
+ export const isEvmTxData = (trade) => {
8
+ return (typeof trade === 'object' &&
9
+ trade !== null &&
10
+ 'data' in trade &&
11
+ 'chainId' in trade &&
12
+ 'to' in trade);
13
+ };
14
+ /**
15
+ * Type guard to check if a trade is a Bitcoin trade with unsignedPsbtBase64
16
+ *
17
+ * @param trade - The trade object to check
18
+ * @returns True if the trade is a Bitcoin trade with unsignedPsbtBase64 property
19
+ */
20
+ export const isBitcoinTrade = (trade) => {
21
+ return (typeof trade === 'object' && trade !== null && 'unsignedPsbtBase64' in trade);
22
+ };
23
+ /**
24
+ * Type guard to check if a trade is a Tron trade with raw_data_hex
25
+ *
26
+ * @param trade - The trade object to check
27
+ * @returns True if the trade is a Tron trade with raw_data_hex property
28
+ */
29
+ export const isTronTrade = (trade) => {
30
+ return typeof trade === 'object' && trade !== null && 'raw_data_hex' in trade;
31
+ };
32
+ /**
33
+ * Extracts the transaction data from different trade formats
34
+ *
35
+ * @param trade - The trade object which can be a TxData, string, Bitcoin trade, or Tron trade
36
+ * @returns The extracted transaction data as a base64 string for SnapController
37
+ */
38
+ export const extractTradeData = (trade) => {
39
+ // Check more specific trade types first to prevent misidentification
40
+ if (isBitcoinTrade(trade)) {
41
+ // Bitcoin trades are already base64 encoded
42
+ return trade.unsignedPsbtBase64;
43
+ }
44
+ if (isTronTrade(trade)) {
45
+ // Tron trades need hex to base64 conversion for SnapController
46
+ return Buffer.from(trade.raw_data_hex, 'hex').toString('base64');
47
+ }
48
+ if (typeof trade === 'string') {
49
+ // Solana txs - assuming already in correct format
50
+ return trade;
51
+ }
52
+ if (isEvmTxData(trade)) {
53
+ // EVM TxData object - return the data property
54
+ return trade.data;
55
+ }
56
+ return '';
57
+ };
58
+ //# sourceMappingURL=trade-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade-utils.mjs","sourceRoot":"","sources":["../../src/utils/trade-utils.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAY,EAAmB,EAAE;IAC3D,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,SAAS,IAAI,KAAK;QAClB,IAAI,IAAI,KAAK,CACd,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAY,EAA6B,EAAE;IACxE,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,IAAI,KAAK,CAC7E,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAY,EAA0B,EAAE;IAClE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,cAAc,IAAI,KAAK,CAAC;AAChF,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAY,EAAU,EAAE;IACvD,qEAAqE;IACrE,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,4CAA4C;QAC5C,OAAO,KAAK,CAAC,kBAAkB,CAAC;IAClC,CAAC;IAED,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,+DAA+D;QAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,kDAAkD;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,+CAA+C;QAC/C,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC","sourcesContent":["import type { BitcoinTradeData, TronTradeData, TxData } from '../types';\n\n// Union type representing all possible trade formats (EVM, Solana, Bitcoin, Tron)\nexport type Trade = TxData | string | BitcoinTradeData | TronTradeData;\n\n/**\n * Type guard to check if a trade is an EVM TxData object\n *\n * @param trade - The trade object to check\n * @returns True if the trade is a TxData object with data property\n */\nexport const isEvmTxData = (trade: Trade): trade is TxData => {\n return (\n typeof trade === 'object' &&\n trade !== null &&\n 'data' in trade &&\n 'chainId' in trade &&\n 'to' in trade\n );\n};\n\n/**\n * Type guard to check if a trade is a Bitcoin trade with unsignedPsbtBase64\n *\n * @param trade - The trade object to check\n * @returns True if the trade is a Bitcoin trade with unsignedPsbtBase64 property\n */\nexport const isBitcoinTrade = (trade: Trade): trade is BitcoinTradeData => {\n return (\n typeof trade === 'object' && trade !== null && 'unsignedPsbtBase64' in trade\n );\n};\n\n/**\n * Type guard to check if a trade is a Tron trade with raw_data_hex\n *\n * @param trade - The trade object to check\n * @returns True if the trade is a Tron trade with raw_data_hex property\n */\nexport const isTronTrade = (trade: Trade): trade is TronTradeData => {\n return typeof trade === 'object' && trade !== null && 'raw_data_hex' in trade;\n};\n\n/**\n * Extracts the transaction data from different trade formats\n *\n * @param trade - The trade object which can be a TxData, string, Bitcoin trade, or Tron trade\n * @returns The extracted transaction data as a base64 string for SnapController\n */\nexport const extractTradeData = (trade: Trade): string => {\n // Check more specific trade types first to prevent misidentification\n if (isBitcoinTrade(trade)) {\n // Bitcoin trades are already base64 encoded\n return trade.unsignedPsbtBase64;\n }\n\n if (isTronTrade(trade)) {\n // Tron trades need hex to base64 conversion for SnapController\n return Buffer.from(trade.raw_data_hex, 'hex').toString('base64');\n }\n\n if (typeof trade === 'string') {\n // Solana txs - assuming already in correct format\n return trade;\n }\n\n if (isEvmTxData(trade)) {\n // EVM TxData object - return the data property\n return trade.data;\n }\n\n return '';\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateQuoteResponse = exports.QuoteResponseSchema = exports.BitcoinTradeDataSchema = exports.TxDataSchema = exports.QuoteSchema = exports.StepSchema = exports.ProtocolSchema = exports.FeeDataSchema = exports.validateSwapsTokenObject = exports.validateFeatureFlagsResponse = exports.PlatformConfigSchema = exports.PriceImpactThresholdSchema = exports.ChainConfigurationSchema = exports.BridgeAssetSchema = exports.truthyString = exports.ActionTypes = exports.FeatureId = exports.FeeType = void 0;
3
+ exports.validateQuoteResponse = exports.QuoteResponseSchema = exports.TronTradeDataSchema = exports.BitcoinTradeDataSchema = exports.TxDataSchema = exports.QuoteSchema = exports.StepSchema = exports.ProtocolSchema = exports.FeeDataSchema = exports.validateSwapsTokenObject = exports.validateFeatureFlagsResponse = exports.PlatformConfigSchema = exports.PriceImpactThresholdSchema = exports.ChainConfigurationSchema = exports.BridgeAssetSchema = exports.truthyString = exports.ActionTypes = exports.FeatureId = exports.FeeType = void 0;
4
4
  const controller_utils_1 = require("@metamask/controller-utils");
5
5
  const superstruct_1 = require("@metamask/superstruct");
6
6
  const utils_1 = require("@metamask/utils");
@@ -212,11 +212,25 @@ exports.BitcoinTradeDataSchema = (0, superstruct_1.type)({
212
212
  unsignedPsbtBase64: (0, superstruct_1.string)(),
213
213
  inputsToSign: (0, superstruct_1.nullable)((0, superstruct_1.array)((0, superstruct_1.type)({}))),
214
214
  });
215
+ exports.TronTradeDataSchema = (0, superstruct_1.type)({
216
+ raw_data_hex: (0, superstruct_1.string)(),
217
+ visible: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
218
+ raw_data: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.type)({
219
+ contract: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.type)({
220
+ type: (0, superstruct_1.optional)((0, superstruct_1.string)()),
221
+ }))),
222
+ }))),
223
+ });
215
224
  exports.QuoteResponseSchema = (0, superstruct_1.type)({
216
225
  quote: exports.QuoteSchema,
217
226
  estimatedProcessingTimeInSeconds: (0, superstruct_1.number)(),
218
- approval: (0, superstruct_1.optional)(exports.TxDataSchema),
219
- trade: (0, superstruct_1.union)([exports.TxDataSchema, exports.BitcoinTradeDataSchema, (0, superstruct_1.string)()]),
227
+ approval: (0, superstruct_1.optional)((0, superstruct_1.union)([exports.TxDataSchema, exports.TronTradeDataSchema])),
228
+ trade: (0, superstruct_1.union)([
229
+ exports.TxDataSchema,
230
+ exports.BitcoinTradeDataSchema,
231
+ exports.TronTradeDataSchema,
232
+ (0, superstruct_1.string)(),
233
+ ]),
220
234
  });
221
235
  const validateQuoteResponse = (data) => {
222
236
  (0, superstruct_1.assert)(data, exports.QuoteResponseSchema);