@metamask-previews/bridge-controller 64.0.0-preview-db01d69 → 64.0.0-preview-aabe1c65

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 CHANGED
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
  - Bump `@metamask/remote-feature-flag-controller` from `^2.0.1` to `^3.0.0` ([#7309](https://github.com/MetaMask/core/pull/7309)
14
14
  - Bump `@metamask/transaction-controller` from `^62.4.0` to `^62.5.0` ([#7325](https://github.com/MetaMask/core/pull/7325))
15
15
 
16
+ ### Fixed
17
+
18
+ - Update gas calculation logic to use the priority fee provided by the gas-api and stop adding the base fee ([#7403](https://github.com/MetaMask/core/pull/7403))
19
+
16
20
  ## [64.0.0]
17
21
 
18
22
  ### Added
@@ -130,14 +130,13 @@ const calcRelayerFee = (quoteResponse, { exchangeRate, usdExchangeRate }) => {
130
130
  };
131
131
  };
132
132
  exports.calcRelayerFee = calcRelayerFee;
133
- const calcTotalGasFee = ({ approvalGasLimit, resetApprovalGasLimit, tradeGasLimit, l1GasFeesInHexWei, feePerGasInDecGwei, priorityFeePerGasInDecGwei, nativeToDisplayCurrencyExchangeRate, nativeToUsdExchangeRate, }) => {
133
+ const calcTotalGasFee = ({ approvalGasLimit, resetApprovalGasLimit, tradeGasLimit, l1GasFeesInHexWei, feePerGasInDecGwei, nativeToDisplayCurrencyExchangeRate, nativeToUsdExchangeRate, }) => {
134
134
  const totalGasLimitInDec = new bignumber_js_1.BigNumber(tradeGasLimit?.toString() ?? '0')
135
135
  .plus(approvalGasLimit?.toString() ?? '0')
136
136
  .plus(resetApprovalGasLimit?.toString() ?? '0');
137
- const totalFeePerGasInDecGwei = new bignumber_js_1.BigNumber(feePerGasInDecGwei).plus(priorityFeePerGasInDecGwei);
138
137
  const l1GasFeesInDecGWei = (0, controller_utils_1.weiHexToGweiDec)((0, controller_utils_1.toHex)(l1GasFeesInHexWei ?? '0'));
139
138
  const gasFeesInDecGwei = totalGasLimitInDec
140
- .times(totalFeePerGasInDecGwei)
139
+ .times(feePerGasInDecGwei)
141
140
  .plus(l1GasFeesInDecGWei);
142
141
  const gasFeesInDecEth = gasFeesInDecGwei.times(new bignumber_js_1.BigNumber(10).pow(-9));
143
142
  const gasFeesInDisplayCurrency = nativeToDisplayCurrencyExchangeRate
@@ -152,7 +151,7 @@ const calcTotalGasFee = ({ approvalGasLimit, resetApprovalGasLimit, tradeGasLimi
152
151
  usd: gasFeesInUSD?.toString() ?? null,
153
152
  };
154
153
  };
155
- const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, maxPriorityFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }) => {
154
+ const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }) => {
156
155
  // Estimated gas fees spent after receiving refunds, this is shown to the user
157
156
  const { amount: amountEffective, valueInCurrency: valueInCurrencyEffective, usd: usdEffective, } = calcTotalGasFee({
158
157
  // Fallback to gasLimit if effectiveGas is not available
@@ -161,7 +160,6 @@ const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade, l1GasF
161
160
  tradeGasLimit: trade?.effectiveGas ?? trade?.gasLimit,
162
161
  l1GasFeesInHexWei,
163
162
  feePerGasInDecGwei: estimatedBaseFeeInDecGwei,
164
- priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,
165
163
  nativeToDisplayCurrencyExchangeRate,
166
164
  nativeToUsdExchangeRate,
167
165
  });
@@ -172,7 +170,6 @@ const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade, l1GasF
172
170
  tradeGasLimit: trade?.gasLimit,
173
171
  l1GasFeesInHexWei,
174
172
  feePerGasInDecGwei: estimatedBaseFeeInDecGwei,
175
- priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,
176
173
  nativeToDisplayCurrencyExchangeRate,
177
174
  nativeToUsdExchangeRate,
178
175
  });
@@ -183,7 +180,6 @@ const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade, l1GasF
183
180
  tradeGasLimit: trade?.gasLimit,
184
181
  l1GasFeesInHexWei,
185
182
  feePerGasInDecGwei: maxFeePerGasInDecGwei,
186
- priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,
187
183
  nativeToDisplayCurrencyExchangeRate,
188
184
  nativeToUsdExchangeRate,
189
185
  });
@@ -1 +1 @@
1
- {"version":3,"file":"quote.cjs","sourceRoot":"","sources":["../../src/utils/quote.ts"],"names":[],"mappings":";;;AAAA,iEAIoC;AACpC,+CAAyC;AAEzC,yCAA4D;AAC5D,iDAAyC;AAalC,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,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IACD,qGAAqG;IACrG,qCAAqC;IACrC,oBAAoB;IACpB,oBAAoB;IACpB,qDAAqD;IACrD,qDAAqD;IACrD,IACE,cAAc,CAAC,WAAW;QAC1B,cAAc,CAAC,UAAU;QACzB,cAAc,CAAC,WAAW,KAAK,cAAc,CAAC,UAAU,IAAI,mBAAmB;QAC/E,CAAC,IAAA,wBAAe,EAAC,cAAc,CAAC,WAAW,CAAC;YAC1C,IAAA,wBAAe,EAAC,cAAc,CAAC,UAAU,CA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,gCAAwC,EACxC,EAAE;IACF,IAAI,gCAAgC,GAAG,EAAE,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,gCAAgC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3D,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B;AAEK,MAAM,UAAU,GAAG,CACxB,MAAuB,EACvB,SAA2B,EAC3B,EAAE;IACF,4EAA4E;IAC5E,IAAI,SAAS,KAAK,sBAAS,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;AAbW,QAAA,UAAU,cAarB","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 resetApprovalGasLimit,\n tradeGasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei,\n priorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n}: {\n approvalGasLimit?: number | null;\n resetApprovalGasLimit?: 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(tradeGasLimit?.toString() ?? '0')\n .plus(approvalGasLimit?.toString() ?? '0')\n .plus(resetApprovalGasLimit?.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, resetApproval },\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 resetApprovalGasLimit:\n resetApproval?.effectiveGas ?? resetApproval?.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 resetApprovalGasLimit: resetApproval?.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 resetApprovalGasLimit: resetApproval?.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.cjs","sourceRoot":"","sources":["../../src/utils/quote.ts"],"names":[],"mappings":";;;AAAA,iEAIoC;AACpC,+CAAyC;AAEzC,yCAA4D;AAC5D,iDAAyC;AAalC,MAAM,mBAAmB,GAAG,CACjC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G,IAAI,UAAU,CAAC,GAAG,EAAE,CAAC;QAC/B,OAAO,IAAI,wBAAS,CAAC,IAAI,CAAC,GAAG,CAAC;aAC3B,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;aACnB,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,EAAE;aACL,QAAQ,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAvBW,QAAA,sBAAsB,0BAuBjC;AAEK,MAAM,kBAAkB,GAAG,CAChC,gCAAwC,EACxC,EAAE;IACF,IAAI,gCAAgC,GAAG,EAAE,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,gCAAgC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3D,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B;AAEK,MAAM,UAAU,GAAG,CACxB,MAAuB,EACvB,SAA2B,EAC3B,EAAE;IACF,4EAA4E;IAC5E,IAAI,SAAS,KAAK,sBAAS,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;AAbW,QAAA,UAAU,cAarB","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 resetApprovalGasLimit,\n tradeGasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n}: {\n approvalGasLimit?: number | null;\n resetApprovalGasLimit?: number | null;\n tradeGasLimit?: number | null;\n l1GasFeesInHexWei?: string | null;\n feePerGasInDecGwei: string;\n nativeToDisplayCurrencyExchangeRate?: string;\n nativeToUsdExchangeRate?: string;\n}) => {\n const totalGasLimitInDec = new BigNumber(tradeGasLimit?.toString() ?? '0')\n .plus(approvalGasLimit?.toString() ?? '0')\n .plus(resetApprovalGasLimit?.toString() ?? '0');\n\n const l1GasFeesInDecGWei = weiHexToGweiDec(toHex(l1GasFeesInHexWei ?? '0'));\n const gasFeesInDecGwei = totalGasLimitInDec\n .times(feePerGasInDecGwei)\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, resetApproval },\n estimatedBaseFeeInDecGwei,\n maxFeePerGasInDecGwei,\n exchangeRate: nativeToDisplayCurrencyExchangeRate,\n usdExchangeRate: nativeToUsdExchangeRate,\n}: {\n bridgeQuote: QuoteResponse<TxData, TxData> & L1GasFees;\n estimatedBaseFeeInDecGwei: string;\n maxFeePerGasInDecGwei: 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 resetApprovalGasLimit:\n resetApproval?.effectiveGas ?? resetApproval?.gasLimit,\n tradeGasLimit: trade?.effectiveGas ?? trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\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 resetApprovalGasLimit: resetApproval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\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 resetApprovalGasLimit: resetApproval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: maxFeePerGasInDecGwei,\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"]}
@@ -29,11 +29,10 @@ export declare const calcRelayerFee: (quoteResponse: QuoteResponse<TxData, TxDat
29
29
  valueInCurrency: BigNumber | null;
30
30
  usd: BigNumber | null;
31
31
  };
32
- export declare const calcEstimatedAndMaxTotalGasFee: ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, maxPriorityFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }: {
32
+ export declare const calcEstimatedAndMaxTotalGasFee: ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }: {
33
33
  bridgeQuote: QuoteResponse<TxData, TxData> & L1GasFees;
34
34
  estimatedBaseFeeInDecGwei: string;
35
35
  maxFeePerGasInDecGwei: string;
36
- maxPriorityFeePerGasInDecGwei: string;
37
36
  } & ExchangeRate) => QuoteMetadata['gasFee'];
38
37
  /**
39
38
  * Calculates the total estimated network fees for the bridge transaction
@@ -1 +1 @@
1
- {"version":3,"file":"quote.d.cts","sourceRoot":"","sources":["../../src/utils/quote.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAGzC,OAAO,EAAE,SAAS,EAAE,yBAAqB;AACzC,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,KAAK,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,MAAM,EACP,qBAAiB;AAElB,eAAO,MAAM,mBAAmB,mBACd,QAAQ,mBAAmB,CAAC,mEA4D7C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,UAAW,aAAa,CAAC,OAAO,CAAC,WACD,CAAC;AAOhE,eAAO,MAAM,yBAAyB,gBACvB,aAAa,GAAG,UAAU,qCACJ,YAAY;;;;CAahD,CAAC;AAEF,eAAO,MAAM,YAAY,oBACN,MAAM,aACZ,WAAW,qCACa,YAAY;;;;CAehD,CAAC;AAEF,eAAO,MAAM,cAAc,0CACc,KAAK,qCACT,YAAY;;;;C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E5D,eAAO,MAAM,QAAQ,mBACH,WAAW,yBAAyB,CAAC,cACzC,WAAW,qBAAqB,CAAC;;;CAY7C,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,mBACjB,WAAW,yBAAyB,CAAC,cACzC,WAAW,qBAAqB,CAAC,KAC5C,MAAM,GAAG,IAoBX,CAAC;AAEF,eAAO,MAAM,kBAAkB,qCACK,MAAM,WAMzC,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,aAAa,EAAE,aACZ,SAAS,GAAG,IAAI,oBAW5B,CAAC"}
@@ -29,11 +29,10 @@ export declare const calcRelayerFee: (quoteResponse: QuoteResponse<TxData, TxDat
29
29
  valueInCurrency: BigNumber | null;
30
30
  usd: BigNumber | null;
31
31
  };
32
- export declare const calcEstimatedAndMaxTotalGasFee: ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, maxPriorityFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }: {
32
+ export declare const calcEstimatedAndMaxTotalGasFee: ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }: {
33
33
  bridgeQuote: QuoteResponse<TxData, TxData> & L1GasFees;
34
34
  estimatedBaseFeeInDecGwei: string;
35
35
  maxFeePerGasInDecGwei: string;
36
- maxPriorityFeePerGasInDecGwei: string;
37
36
  } & ExchangeRate) => QuoteMetadata['gasFee'];
38
37
  /**
39
38
  * Calculates the total estimated network fees for the bridge transaction
@@ -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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Aa,CAAC,QAAQ,CA6DxC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,oCAGpC,WAAW,qCAAqC,CAAC,cACxC,WAAW,qBAAqB,CAAC;;;;CAiB9C,CAAC;AAEF,eAAO,MAAM,sBAAsB,WACzB,WAAW,qCAAqC,CAAC,cAC7C,WAAW,qBAAqB,CAAC;;;;CAa9C,CAAC;AAGF,eAAO,MAAM,kBAAkB,mEACmC,KAAK,wBAC/C,YAAY,yBACX,YAAY;;;;QAwBpC,CAAC;AAEF,eAAO,MAAM,kBAAkB,kBACd,WAAW,mBAAmB,CAAC,4BACpB,WAAW,mCAAmC,CAAC,+DACZ,KAAK;;;CAuBnE,CAAC;AAEF,eAAO,MAAM,YAAY,eAAgB,MAAM,mBAAmB,MAAM,WACb,CAAC;AAE5D,eAAO,MAAM,QAAQ,mBACH,WAAW,yBAAyB,CAAC,cACzC,WAAW,qBAAqB,CAAC;;;CAY7C,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,mBACjB,WAAW,yBAAyB,CAAC,cACzC,WAAW,qBAAqB,CAAC,KAC5C,MAAM,GAAG,IAoBX,CAAC;AAEF,eAAO,MAAM,kBAAkB,qCACK,MAAM,WAMzC,CAAC;AAEF,eAAO,MAAM,UAAU,WACb,aAAa,EAAE,aACZ,SAAS,GAAG,IAAI,oBAW5B,CAAC"}
@@ -121,14 +121,13 @@ export const calcRelayerFee = (quoteResponse, { exchangeRate, usdExchangeRate })
121
121
  usd: usdExchangeRate ? relayerFeeInNative.times(usdExchangeRate) : null,
122
122
  };
123
123
  };
124
- const calcTotalGasFee = ({ approvalGasLimit, resetApprovalGasLimit, tradeGasLimit, l1GasFeesInHexWei, feePerGasInDecGwei, priorityFeePerGasInDecGwei, nativeToDisplayCurrencyExchangeRate, nativeToUsdExchangeRate, }) => {
124
+ const calcTotalGasFee = ({ approvalGasLimit, resetApprovalGasLimit, tradeGasLimit, l1GasFeesInHexWei, feePerGasInDecGwei, nativeToDisplayCurrencyExchangeRate, nativeToUsdExchangeRate, }) => {
125
125
  const totalGasLimitInDec = new BigNumber(tradeGasLimit?.toString() ?? '0')
126
126
  .plus(approvalGasLimit?.toString() ?? '0')
127
127
  .plus(resetApprovalGasLimit?.toString() ?? '0');
128
- const totalFeePerGasInDecGwei = new BigNumber(feePerGasInDecGwei).plus(priorityFeePerGasInDecGwei);
129
128
  const l1GasFeesInDecGWei = weiHexToGweiDec(toHex(l1GasFeesInHexWei ?? '0'));
130
129
  const gasFeesInDecGwei = totalGasLimitInDec
131
- .times(totalFeePerGasInDecGwei)
130
+ .times(feePerGasInDecGwei)
132
131
  .plus(l1GasFeesInDecGWei);
133
132
  const gasFeesInDecEth = gasFeesInDecGwei.times(new BigNumber(10).pow(-9));
134
133
  const gasFeesInDisplayCurrency = nativeToDisplayCurrencyExchangeRate
@@ -143,7 +142,7 @@ const calcTotalGasFee = ({ approvalGasLimit, resetApprovalGasLimit, tradeGasLimi
143
142
  usd: gasFeesInUSD?.toString() ?? null,
144
143
  };
145
144
  };
146
- export const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, maxPriorityFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }) => {
145
+ export const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade, l1GasFeesInHexWei, resetApproval }, estimatedBaseFeeInDecGwei, maxFeePerGasInDecGwei, exchangeRate: nativeToDisplayCurrencyExchangeRate, usdExchangeRate: nativeToUsdExchangeRate, }) => {
147
146
  // Estimated gas fees spent after receiving refunds, this is shown to the user
148
147
  const { amount: amountEffective, valueInCurrency: valueInCurrencyEffective, usd: usdEffective, } = calcTotalGasFee({
149
148
  // Fallback to gasLimit if effectiveGas is not available
@@ -152,7 +151,6 @@ export const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade,
152
151
  tradeGasLimit: trade?.effectiveGas ?? trade?.gasLimit,
153
152
  l1GasFeesInHexWei,
154
153
  feePerGasInDecGwei: estimatedBaseFeeInDecGwei,
155
- priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,
156
154
  nativeToDisplayCurrencyExchangeRate,
157
155
  nativeToUsdExchangeRate,
158
156
  });
@@ -163,7 +161,6 @@ export const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade,
163
161
  tradeGasLimit: trade?.gasLimit,
164
162
  l1GasFeesInHexWei,
165
163
  feePerGasInDecGwei: estimatedBaseFeeInDecGwei,
166
- priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,
167
164
  nativeToDisplayCurrencyExchangeRate,
168
165
  nativeToUsdExchangeRate,
169
166
  });
@@ -174,7 +171,6 @@ export const calcEstimatedAndMaxTotalGasFee = ({ bridgeQuote: { approval, trade,
174
171
  tradeGasLimit: trade?.gasLimit,
175
172
  l1GasFeesInHexWei,
176
173
  feePerGasInDecGwei: maxFeePerGasInDecGwei,
177
- priorityFeePerGasInDecGwei: maxPriorityFeePerGasInDecGwei,
178
174
  nativeToDisplayCurrencyExchangeRate,
179
175
  nativeToUsdExchangeRate,
180
176
  });
@@ -1 +1 @@
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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IAChB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,gCAAwC,EACxC,EAAE;IACF,IAAI,gCAAgC,GAAG,EAAE,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;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, 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 resetApprovalGasLimit,\n tradeGasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei,\n priorityFeePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n}: {\n approvalGasLimit?: number | null;\n resetApprovalGasLimit?: 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(tradeGasLimit?.toString() ?? '0')\n .plus(approvalGasLimit?.toString() ?? '0')\n .plus(resetApprovalGasLimit?.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, resetApproval },\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 resetApprovalGasLimit:\n resetApproval?.effectiveGas ?? resetApproval?.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 resetApprovalGasLimit: resetApproval?.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 resetApprovalGasLimit: resetApproval?.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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G,CAAC,UAAU,CAAC,GAAG,CAAC;aACnB,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,EAAE;aACL,QAAQ,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,gCAAwC,EACxC,EAAE;IACF,IAAI,gCAAgC,GAAG,EAAE,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;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, 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 resetApprovalGasLimit,\n tradeGasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei,\n nativeToDisplayCurrencyExchangeRate,\n nativeToUsdExchangeRate,\n}: {\n approvalGasLimit?: number | null;\n resetApprovalGasLimit?: number | null;\n tradeGasLimit?: number | null;\n l1GasFeesInHexWei?: string | null;\n feePerGasInDecGwei: string;\n nativeToDisplayCurrencyExchangeRate?: string;\n nativeToUsdExchangeRate?: string;\n}) => {\n const totalGasLimitInDec = new BigNumber(tradeGasLimit?.toString() ?? '0')\n .plus(approvalGasLimit?.toString() ?? '0')\n .plus(resetApprovalGasLimit?.toString() ?? '0');\n\n const l1GasFeesInDecGWei = weiHexToGweiDec(toHex(l1GasFeesInHexWei ?? '0'));\n const gasFeesInDecGwei = totalGasLimitInDec\n .times(feePerGasInDecGwei)\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, resetApproval },\n estimatedBaseFeeInDecGwei,\n maxFeePerGasInDecGwei,\n exchangeRate: nativeToDisplayCurrencyExchangeRate,\n usdExchangeRate: nativeToUsdExchangeRate,\n}: {\n bridgeQuote: QuoteResponse<TxData, TxData> & L1GasFees;\n estimatedBaseFeeInDecGwei: string;\n maxFeePerGasInDecGwei: 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 resetApprovalGasLimit:\n resetApproval?.effectiveGas ?? resetApproval?.gasLimit,\n tradeGasLimit: trade?.effectiveGas ?? trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\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 resetApprovalGasLimit: resetApproval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: estimatedBaseFeeInDecGwei,\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 resetApprovalGasLimit: resetApproval?.gasLimit,\n tradeGasLimit: trade?.gasLimit,\n l1GasFeesInHexWei,\n feePerGasInDecGwei: maxFeePerGasInDecGwei,\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/bridge-controller",
3
- "version": "64.0.0-preview-db01d69",
3
+ "version": "64.0.0-preview-aabe1c65",
4
4
  "description": "Manages bridge-related quote fetching functionality for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",