@metamask-previews/bridge-controller 77.0.0-preview-18dd0df9c → 77.0.0-preview-bd7b53f49
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 +13 -0
- package/dist/bridge-controller.cjs +48 -0
- package/dist/bridge-controller.cjs.map +1 -1
- package/dist/bridge-controller.d.cts +6 -5
- package/dist/bridge-controller.d.cts.map +1 -1
- package/dist/bridge-controller.d.mts +6 -5
- package/dist/bridge-controller.d.mts.map +1 -1
- package/dist/bridge-controller.mjs +49 -1
- package/dist/bridge-controller.mjs.map +1 -1
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +4 -7
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +15 -135
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +15 -135
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +4 -7
- package/dist/selectors.mjs.map +1 -1
- package/dist/utils/metrics/constants.cjs +17 -1
- package/dist/utils/metrics/constants.cjs.map +1 -1
- package/dist/utils/metrics/constants.d.cts +16 -0
- package/dist/utils/metrics/constants.d.cts.map +1 -1
- package/dist/utils/metrics/constants.d.mts +16 -0
- package/dist/utils/metrics/constants.d.mts.map +1 -1
- package/dist/utils/metrics/constants.mjs +16 -0
- package/dist/utils/metrics/constants.mjs.map +1 -1
- package/dist/utils/metrics/types.cjs.map +1 -1
- package/dist/utils/metrics/types.d.cts +66 -21
- package/dist/utils/metrics/types.d.cts.map +1 -1
- package/dist/utils/metrics/types.d.mts +66 -21
- package/dist/utils/metrics/types.d.mts.map +1 -1
- package/dist/utils/metrics/types.mjs.map +1 -1
- package/package.json +1 -1
package/dist/selectors.mjs
CHANGED
|
@@ -182,12 +182,7 @@ const selectBridgeFeesPerGas = createBridgeSelector([
|
|
|
182
182
|
const selectBridgeQuotesWithMetadata = createBridgeSelector([
|
|
183
183
|
({ quotes }) => quotes,
|
|
184
184
|
selectBridgeFeesPerGas,
|
|
185
|
-
|
|
186
|
-
(state) => state,
|
|
187
|
-
({ quoteRequest: [{ srcChainId, srcTokenAddress }] }) => srcTokenAddress
|
|
188
|
-
? formatAddressToAssetId(srcTokenAddress, srcChainId)
|
|
189
|
-
: undefined,
|
|
190
|
-
], selectExchangeRateByAssetId),
|
|
185
|
+
(state) => state,
|
|
191
186
|
createBridgeSelector([
|
|
192
187
|
(state) => state,
|
|
193
188
|
({ quoteRequest: [{ destChainId, destTokenAddress }] }) => destTokenAddress
|
|
@@ -200,8 +195,10 @@ const selectBridgeQuotesWithMetadata = createBridgeSelector([
|
|
|
200
195
|
? getNativeAssetForChainId(srcChainId)?.assetId
|
|
201
196
|
: undefined,
|
|
202
197
|
], selectExchangeRateByAssetId),
|
|
203
|
-
], (quotes, bridgeFeesPerGas,
|
|
198
|
+
], (quotes, bridgeFeesPerGas, exchangeRateSources, destTokenExchangeRate, nativeExchangeRate) => {
|
|
204
199
|
const newQuotes = quotes.map((quote) => {
|
|
200
|
+
const sourceAssetId = formatAddressToAssetId(quote.quote.srcAsset.address, quote.quote.srcChainId) ?? quote.quote.srcAsset.assetId;
|
|
201
|
+
const srcTokenExchangeRate = selectExchangeRateByAssetId(exchangeRateSources, sourceAssetId);
|
|
205
202
|
const sentAmount = calcSentAmount(quote.quote, srcTokenExchangeRate);
|
|
206
203
|
const toTokenAmount = calcToAmount(quote.quote.destTokenAmount, quote.quote.destAsset, destTokenExchangeRate);
|
|
207
204
|
const minToTokenAmount = calcToAmount(quote.quote.minDestTokenAmount, quote.quote.destAsset, destTokenExchangeRate);
|
package/dist/selectors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.mjs","sourceRoot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CAAC,SAAS;IACf,CAAC,CAAC,EAAE,cAAkE,EAAE,EAAE,CACxE,cAAc,CAAC,WAAW;QACxB,CAAC,CAAC,mBAAmB,CAAC,cAAc,CAAC,WAAW,CAAC;QACjD,CAAC,CAAC,SAAS;CAChB,EACD,CACE,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,EAAE;IACF,OAAO,4BAA4B,CACjC;QACE,eAAe;QACf,gBAAgB;QAChB,UAAU;QACV,WAAW;KACZ,EACD,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,SAAS,EACrE,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,SAAS,CACxE,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { getAddress } from '@ethersproject/address';\nimport type {\n CurrencyRateState,\n MultichainAssetsRatesControllerState,\n TokenRatesControllerState,\n} from '@metamask/assets-controllers';\nimport type {\n GasFeeEstimates,\n GasFeeEstimatesByChainId,\n} from '@metamask/gas-fee-controller';\nimport type { CaipAssetType } from '@metamask/utils';\nimport { isStrictHexString, parseCaipAssetType } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { orderBy } from 'lodash';\nimport {\n createSelector as createSelector_,\n createStructuredSelector as createStructuredSelector_,\n} from 'reselect';\n\nimport { BRIDGE_PREFERRED_GAS_ESTIMATE } from './constants/bridge';\nimport type {\n BridgeControllerState,\n ExchangeRate,\n QuoteMetadata,\n QuoteResponseV1,\n TokenAmountValues,\n} from './types';\nimport { RequestStatus, SortOrder } from './types';\nimport {\n getNativeAssetForChainId,\n isEvmQuoteResponse,\n isNativeAddress,\n isNonEvmChainId,\n} from './utils/bridge';\nimport {\n formatAddressToAssetId,\n formatAddressToCaipReference,\n formatChainIdToCaip,\n formatChainIdToHex,\n} from './utils/caip-formatters';\nimport { processFeatureFlags } from './utils/feature-flags';\nimport {\n calcAdjustedReturn,\n calcCost,\n calcEstimatedAndMaxTotalGasFee,\n calcIncludedTxFees,\n calcRelayerFee,\n calcSentAmount,\n calcNonEvmTotalNetworkFee,\n calcSwapRate,\n calcToAmount,\n calcTotalEstimatedNetworkFee,\n calcTotalMaxNetworkFee,\n calcBatchFees,\n} from './utils/quote';\nimport { getDefaultSlippagePercentage } from './utils/slippage';\n\n/**\n * The controller states that provide exchange rates\n */\ntype ExchangeRateControllerState = MultichainAssetsRatesControllerState &\n TokenRatesControllerState &\n CurrencyRateState &\n Pick<BridgeControllerState, 'assetExchangeRates'>;\n/**\n * The state of the bridge controller and all its dependency controllers\n */\ntype RemoteFeatureFlagControllerState = {\n remoteFeatureFlags: {\n bridgeConfig: unknown;\n };\n};\n\n/**\n * Minimal shape required for exchange-rate lookups (used by getExchangeRateByChainIdAndAddress).\n * Uses types from assets-controllers; marketData and conversionRates also accept the bridge format.\n */\nexport type ExchangeRateSourcesForLookup = Pick<\n BridgeControllerState,\n 'assetExchangeRates'\n> &\n Partial<Pick<CurrencyRateState, 'currencyRates'>> &\n Partial<Pick<MultichainAssetsRatesControllerState, 'historicalPrices'>> & {\n marketData?:\n | TokenRatesControllerState['marketData']\n | Record<string, Record<string, { price?: number; currency?: string }>>;\n conversionRates?:\n | MultichainAssetsRatesControllerState['conversionRates']\n | Record<string, { rate: string }>;\n };\n\nexport type BridgeAppState = BridgeControllerState & {\n gasFeeEstimatesByChainId: GasFeeEstimatesByChainId;\n} & ExchangeRateControllerState & {\n participateInMetaMetrics: boolean;\n } & RemoteFeatureFlagControllerState;\n/**\n * Creates a structured selector for the bridge controller\n */\nconst createStructuredBridgeSelector =\n createStructuredSelector_.withTypes<BridgeAppState>();\n/**\n * Creates a typed selector for the bridge controller\n */\nconst createBridgeSelector = createSelector_.withTypes<BridgeAppState>();\n/**\n * Required parameters that clients must provide for the bridge quotes selector\n */\ntype BridgeQuotesClientParams = {\n sortOrder: SortOrder;\n selectedQuote: (QuoteResponseV1 & QuoteMetadata) | null;\n};\n\ntype EvmTokenExchangeRate = { price?: number; currency?: string };\ntype EvmTokenExchangeRates = Record<string, EvmTokenExchangeRate>;\n\nconst createFeatureFlagsSelector =\n createSelector_.withTypes<RemoteFeatureFlagControllerState>();\n\n/**\n * Selects the bridge feature flags\n *\n * @param state - The state of the bridge controller\n * @returns The bridge feature flags\n *\n * @example\n * ```ts\n * const featureFlags = useSelector(state => selectBridgeFeatureFlags(state));\n *\n * Or\n *\n * export const selectBridgeFeatureFlags = createSelector(\n * selectRemoteFeatureFlags,\n * (remoteFeatureFlags) =>\n * selectBridgeFeatureFlagsBase({\n * bridgeConfig: remoteFeatureFlags.bridgeConfig,\n * }),\n * );\n * ```\n */\nexport const selectBridgeFeatureFlags = createFeatureFlagsSelector(\n [(state) => state.remoteFeatureFlags.bridgeConfig],\n (bridgeConfig: unknown) => processFeatureFlags(bridgeConfig),\n);\n\nconst getEvmTokenExchangeRateForAddress = (\n evmTokenExchangeRates: EvmTokenExchangeRates | undefined,\n address: string,\n): EvmTokenExchangeRate | null | undefined => {\n try {\n return isStrictHexString(address)\n ? (evmTokenExchangeRates?.[getAddress(address)] ??\n evmTokenExchangeRates?.[address.toLowerCase()])\n : null;\n } catch {\n return null;\n }\n};\n\n/**\n * Selects the asset exchange rate for a given chain and address\n *\n * @param exchangeRateSources - the controller states containing the exchange rates\n * @param assetId - the assetId to get the exchange rate for\n * @returns The asset exchange rate for the given assetId\n */\nexport const selectExchangeRateByAssetId = (\n exchangeRateSources: ExchangeRateSourcesForLookup,\n assetId?: CaipAssetType,\n): ExchangeRate => {\n if (!assetId) {\n return {};\n }\n\n const { assetExchangeRates, currencyRates, marketData, conversionRates } =\n exchangeRateSources;\n\n // If the asset exchange rate is available in the bridge controller, use it\n // This is defined if the token's rate is not available from the assets controllers\n const bridgeControllerRate =\n assetExchangeRates?.[assetId.toLowerCase() as CaipAssetType] ??\n assetExchangeRates?.[assetId];\n if (\n bridgeControllerRate?.exchangeRate &&\n bridgeControllerRate?.usdExchangeRate\n ) {\n return bridgeControllerRate;\n }\n\n const { chainId } = parseCaipAssetType(assetId);\n\n // If the chain is a non-EVM chain, use the conversion rate from the multichain assets controller\n if (isNonEvmChainId(chainId)) {\n const conversionRatesByKey = conversionRates as\n | Record<string, { rate?: string }>\n | undefined;\n const multichainAssetExchangeRate = conversionRatesByKey?.[assetId];\n const rate = multichainAssetExchangeRate?.rate;\n if (rate) {\n // The multichain rate is denominated in the user's selected currency.\n // To get a USD rate, find the user's-currency-to-USD conversion factor from any EVM native currency rate.\n const nativeCurrencyRate = Object.values(currencyRates ?? {}).find(\n (rateEntry) =>\n rateEntry?.conversionRate !== undefined &&\n rateEntry?.conversionRate !== null &&\n rateEntry?.usdConversionRate !== undefined &&\n rateEntry?.usdConversionRate !== null,\n );\n const usersCurrencyToUsdRate =\n nativeCurrencyRate?.conversionRate !== undefined &&\n nativeCurrencyRate?.conversionRate !== null &&\n nativeCurrencyRate?.usdConversionRate !== undefined &&\n nativeCurrencyRate?.usdConversionRate !== null\n ? new BigNumber(nativeCurrencyRate.usdConversionRate).div(\n nativeCurrencyRate.conversionRate,\n )\n : undefined;\n const usdExchangeRate = usersCurrencyToUsdRate\n ? new BigNumber(rate).times(usersCurrencyToUsdRate).toString()\n : undefined;\n return {\n exchangeRate: rate,\n usdExchangeRate,\n };\n }\n return {};\n }\n\n const address = formatAddressToCaipReference(assetId);\n\n // If the chain is an EVM chain, use the conversion rate from the currency rates controller\n if (isNativeAddress(address)) {\n const { symbol } = getNativeAssetForChainId(chainId);\n const evmNativeExchangeRate = currencyRates?.[symbol];\n if (evmNativeExchangeRate) {\n return {\n exchangeRate: evmNativeExchangeRate.conversionRate?.toString(),\n usdExchangeRate: evmNativeExchangeRate.usdConversionRate?.toString(),\n };\n }\n return {};\n }\n // If the chain is an EVM chain and the asset is not the native asset, use the conversion rate from the token rates controller\n if (!isNonEvmChainId(chainId)) {\n const marketDataByChain =\n (marketData as Record<string, EvmTokenExchangeRates> | undefined) ?? {};\n const evmTokenExchangeRates =\n marketDataByChain[formatChainIdToHex(chainId)];\n const evmTokenExchangeRateForAddress = getEvmTokenExchangeRateForAddress(\n evmTokenExchangeRates,\n address,\n );\n const currencyKey = evmTokenExchangeRateForAddress?.currency;\n const nativeCurrencyRate =\n currencyKey !== undefined && currencyKey !== null\n ? currencyRates?.[currencyKey]\n : undefined;\n const price = evmTokenExchangeRateForAddress?.price ?? 0;\n if (evmTokenExchangeRateForAddress && nativeCurrencyRate) {\n return {\n exchangeRate: new BigNumber(price)\n .multipliedBy(nativeCurrencyRate.conversionRate ?? 0)\n .toString(),\n usdExchangeRate: new BigNumber(price)\n .multipliedBy(nativeCurrencyRate.usdConversionRate ?? 0)\n .toString(),\n };\n }\n }\n\n return {};\n};\n\n/**\n * Checks whether an exchange rate is available for a given assetId\n *\n * @param state The state of the bridge controller and its dependency controllers\n * @param assetId The assetId to check\n * @returns Whether an exchange rate is available for the given chain and address\n */\nexport const selectIsAssetExchangeRateInState = (\n state: ExchangeRateSourcesForLookup,\n assetId?: CaipAssetType,\n) =>\n Boolean(selectExchangeRateByAssetId(state, assetId)?.exchangeRate) &&\n Boolean(selectExchangeRateByAssetId(state, assetId)?.usdExchangeRate);\n\n/**\n * Selects the gas fee estimates from the gas fee controller. All potential networks\n * support EIP1559 gas fees so assume that gasFeeEstimates is of type GasFeeEstimates\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @param state.gasFeeEstimatesByChainId - gasEstimates by Hex ChainId\n * @param state.quotes - Fetched bridge/swap quotes\n * @returns The gas fee estimates in decGWEI\n */\nconst selectBridgeFeesPerGas = createBridgeSelector(\n [\n (state) => state.gasFeeEstimatesByChainId,\n (state) => state.quotes?.[0]?.quote.srcChainId,\n ],\n (gasFeeEstimatesByChainId, srcChainId) => {\n if (!srcChainId) {\n return null;\n }\n if (isNonEvmChainId(srcChainId)) {\n return null;\n }\n // @ts-expect-error - all supported networks use this type of estimates\n const gasFeeEstimates: GasFeeEstimates | undefined =\n gasFeeEstimatesByChainId?.[\n formatChainIdToHex(srcChainId) as keyof typeof gasFeeEstimatesByChainId\n ]?.gasFeeEstimates;\n if (!gasFeeEstimates) {\n return null;\n }\n return {\n estimatedBaseFeeInDecGwei: gasFeeEstimates.estimatedBaseFee,\n feePerGasInDecGwei:\n gasFeeEstimates[BRIDGE_PREFERRED_GAS_ESTIMATE]?.suggestedMaxFeePerGas,\n maxFeePerGasInDecGwei: gasFeeEstimates.high?.suggestedMaxFeePerGas,\n };\n },\n);\n\n// Selects cross-chain swap quotes including their metadata\nconst selectBridgeQuotesWithMetadata = createBridgeSelector(\n [\n ({ quotes }) => quotes,\n selectBridgeFeesPerGas,\n createBridgeSelector(\n [\n (state) => state,\n ({ quoteRequest: [{ srcChainId, srcTokenAddress }] }) =>\n srcTokenAddress\n ? formatAddressToAssetId(srcTokenAddress, srcChainId)\n : undefined,\n ],\n selectExchangeRateByAssetId,\n ),\n createBridgeSelector(\n [\n (state) => state,\n ({ quoteRequest: [{ destChainId, destTokenAddress }] }) =>\n destTokenAddress\n ? formatAddressToAssetId(destTokenAddress, destChainId)\n : undefined,\n ],\n selectExchangeRateByAssetId,\n ),\n createBridgeSelector(\n [\n (state) => state,\n ({ quoteRequest: [{ srcChainId }] }) =>\n srcChainId\n ? getNativeAssetForChainId(srcChainId)?.assetId\n : undefined,\n ],\n selectExchangeRateByAssetId,\n ),\n ],\n (\n quotes,\n bridgeFeesPerGas,\n srcTokenExchangeRate,\n destTokenExchangeRate,\n nativeExchangeRate,\n ) => {\n const newQuotes = quotes.map((quote) => {\n const sentAmount = calcSentAmount(quote.quote, srcTokenExchangeRate);\n const toTokenAmount = calcToAmount(\n quote.quote.destTokenAmount,\n quote.quote.destAsset,\n destTokenExchangeRate,\n );\n const minToTokenAmount = calcToAmount(\n quote.quote.minDestTokenAmount,\n quote.quote.destAsset,\n destTokenExchangeRate,\n );\n\n const includedTxFees = calcIncludedTxFees(\n quote.quote,\n srcTokenExchangeRate,\n destTokenExchangeRate,\n );\n\n let totalEstimatedNetworkFee,\n totalMaxNetworkFee,\n relayerFee,\n gasFee: QuoteMetadata['gasFee'];\n\n if (isEvmQuoteResponse(quote)) {\n relayerFee = calcRelayerFee(quote, nativeExchangeRate);\n gasFee = calcEstimatedAndMaxTotalGasFee({\n bridgeQuote: quote,\n ...bridgeFeesPerGas,\n ...nativeExchangeRate,\n });\n // Uses effectiveGasFee to calculate the total estimated network fee\n totalEstimatedNetworkFee = calcTotalEstimatedNetworkFee(\n gasFee,\n relayerFee,\n );\n totalMaxNetworkFee = calcTotalMaxNetworkFee(gasFee, relayerFee);\n } else {\n // Use the new generic function for all non-EVM chains\n totalEstimatedNetworkFee = calcNonEvmTotalNetworkFee(\n quote,\n nativeExchangeRate,\n );\n gasFee = {\n effective: totalEstimatedNetworkFee,\n total: totalEstimatedNetworkFee,\n max: totalEstimatedNetworkFee,\n };\n totalMaxNetworkFee = totalEstimatedNetworkFee;\n }\n\n const adjustedReturn = calcAdjustedReturn(\n toTokenAmount,\n totalEstimatedNetworkFee,\n quote.quote,\n );\n const cost = calcCost(adjustedReturn, sentAmount);\n\n return {\n ...quote,\n // QuoteMetadata fields\n sentAmount,\n toTokenAmount,\n minToTokenAmount,\n swapRate: calcSwapRate(sentAmount.amount, toTokenAmount.amount),\n /**\n This is the amount required to submit all the transactions.\n Includes the relayer fee or other native fees.\n Should be used for balance checks and tx submission.\n */\n totalNetworkFee: totalEstimatedNetworkFee,\n totalMaxNetworkFee,\n /**\n This contains gas fee estimates for the bridge transaction\n Does not include the relayer fee (if needed), just the gasLimit and effectiveGas returned by the bridge API.\n Should only be used for display purposes.\n */\n gasFee,\n adjustedReturn,\n cost,\n includedTxFees,\n };\n });\n\n return newQuotes;\n },\n);\n\nconst selectSortedBridgeQuotes = createBridgeSelector(\n [\n selectBridgeQuotesWithMetadata,\n (_, { sortOrder }: BridgeQuotesClientParams) => sortOrder,\n ],\n (quotesWithMetadata, sortOrder): (QuoteResponseV1 & QuoteMetadata)[] => {\n switch (sortOrder) {\n case SortOrder.ETA_ASC:\n return orderBy(\n quotesWithMetadata,\n (quote) => quote.estimatedProcessingTimeInSeconds,\n 'asc',\n );\n default:\n if (quotesWithMetadata.every((quote) => quote.cost.valueInCurrency)) {\n return orderBy(\n quotesWithMetadata,\n ({ cost }) => Number(cost.valueInCurrency),\n 'asc',\n );\n }\n if (\n quotesWithMetadata.every(\n (quote) => quote.quote.priceData?.priceImpact,\n )\n ) {\n return orderBy(\n quotesWithMetadata,\n ({ quote }) => Number(quote.priceData?.priceImpact),\n 'asc',\n );\n }\n return orderBy(\n quotesWithMetadata,\n ({ quote }) => Number(quote.destTokenAmount),\n 'desc',\n );\n }\n },\n);\n\nconst selectRecommendedQuote = createBridgeSelector(\n [selectSortedBridgeQuotes],\n (quotes) => (quotes.length > 0 ? quotes[0] : null),\n);\n\nconst selectActiveQuote = createBridgeSelector(\n [\n selectRecommendedQuote,\n selectSortedBridgeQuotes,\n (_, { selectedQuote }) => selectedQuote,\n ],\n (recommendedQuote, sortedQuotes, selectedQuote) =>\n sortedQuotes.find(\n (quote) => quote.quote.requestId === selectedQuote?.quote.requestId,\n ) ?? recommendedQuote,\n);\n\nconst selectIsQuoteGoingToRefresh = createBridgeSelector(\n [\n selectBridgeFeatureFlags,\n // If at least one quote request is sufficiently funded, continue polling until max refresh count is reached\n (state) =>\n state.quoteRequest.every((quoteRequest) =>\n Boolean(quoteRequest.insufficientBal),\n ),\n (state) => state.quotesRefreshCount,\n ],\n (featureFlags, insufficientBal, quotesRefreshCount) =>\n insufficientBal ? false : featureFlags.maxRefreshCount > quotesRefreshCount,\n);\n\nconst selectQuoteRefreshRate = createBridgeSelector(\n [selectBridgeFeatureFlags, (state) => state.quoteRequest[0]?.srcChainId],\n (featureFlags, srcChainId) =>\n (srcChainId\n ? featureFlags.chains[formatChainIdToCaip(srcChainId)]?.refreshRate\n : featureFlags.refreshRate) ?? featureFlags.refreshRate,\n);\n\nexport const selectIsQuoteExpired = createBridgeSelector(\n [\n selectIsQuoteGoingToRefresh,\n ({ quotesLastFetched }) => quotesLastFetched,\n selectQuoteRefreshRate,\n (_, _ignoredParam, currentTimeInMs: number) => currentTimeInMs,\n ],\n (isQuoteGoingToRefresh, quotesLastFetched, refreshRate, currentTimeInMs) =>\n Boolean(\n !isQuoteGoingToRefresh &&\n quotesLastFetched &&\n currentTimeInMs - quotesLastFetched > refreshRate,\n ),\n);\n\n/**\n * Selects sorted cross-chain swap quotes. By default, the quotes are sorted by cost in ascending order.\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @param sortOrder - The sort order of the quotes\n * @param selectedQuote - The quote that is currently selected by the user, should be cleared by clients when the req params change\n * @returns The activeQuote, recommendedQuote, sortedQuotes, and other quote fetching metadata\n *\n * @example\n * ```ts\n * const quotes = useSelector(state => selectBridgeQuotes(\n * { ...state.metamask, bridgeConfig: remoteFeatureFlags.bridgeConfig },\n * {\n * sortOrder: state.bridge.sortOrder,\n * selectedQuote: state.bridge.selectedQuote,\n * }\n * ));\n * ```\n */\nexport const selectBridgeQuotes = createStructuredBridgeSelector({\n sortedQuotes: selectSortedBridgeQuotes,\n recommendedQuote: selectRecommendedQuote,\n activeQuote: selectActiveQuote,\n quotesLastFetchedMs: (state) => state.quotesLastFetched,\n isLoading: (state) => state.quotesLoadingStatus === RequestStatus.LOADING,\n quoteFetchError: (state) => state.quoteFetchError,\n quotesRefreshCount: (state) => state.quotesRefreshCount,\n quotesInitialLoadTimeMs: (state) => state.quotesInitialLoadTime,\n isQuoteGoingToRefresh: selectIsQuoteGoingToRefresh,\n});\n\nconst selectRecommendedQuotes = createBridgeSelector(\n [\n selectSortedBridgeQuotes,\n (_, { requestCount }: { requestCount: number }) => requestCount,\n ],\n (quotes, requestCount) =>\n quotes.reduce((acc, quote) => {\n const requestIndex = quote.quoteRequestIndex ?? 0;\n acc[requestIndex] ??= quote;\n return acc;\n }, Array<(QuoteResponseV1 & QuoteMetadata) | null>(requestCount).fill(null)),\n);\n\nconst selectMetadataSum = createBridgeSelector(\n [\n selectRecommendedQuotes,\n (\n _,\n {\n key,\n }: { key: 'totalNetworkFee' | 'minToTokenAmount' | 'toTokenAmount' },\n ) => key,\n ],\n (recommendedQuotes, key) =>\n recommendedQuotes.reduce<TokenAmountValues>(\n (acc, quote) => {\n acc.usd = new BigNumber(acc.usd ?? 0)\n .plus(quote?.[key]?.usd ?? 0)\n .toString();\n acc.valueInCurrency = new BigNumber(acc.valueInCurrency ?? 0)\n .plus(quote?.[key]?.valueInCurrency ?? 0)\n .toString();\n acc.amount = new BigNumber(acc.amount ?? 0)\n .plus(quote?.[key]?.amount ?? 0)\n .toString();\n return acc;\n },\n { usd: null, valueInCurrency: null, amount: '0' },\n ),\n);\n\n/**\n * Selects the recommended swap quotes for a batch of quote requests.\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @param sortOrder - The sort order of the quotes\n * @param requestCount - The number of quote requests fetched in the batch\n * @returns The quotes for multiple quote requests, including their recommendedQuotes,\n * totalReceived, minimumReceived, totalNetworkFee, and other quote fetching metadata.\n *\n * @example\n * ```ts\n * const quotes = useSelector(state => selectBatchSellQuotes(\n * { ...state.metamask },\n * {\n * sortOrder: state.bridge.sortOrder,\n * requestCount: 4,\n * }\n * ));\n * ```\n */\nexport const selectBatchSellQuotes = createStructuredBridgeSelector({\n recommendedQuotes: selectRecommendedQuotes,\n totalReceived: (state, opts) =>\n selectMetadataSum(state, { ...opts, key: 'toTokenAmount' }),\n minimumReceived: (state, opts) =>\n selectMetadataSum(state, { ...opts, key: 'minToTokenAmount' }),\n quotesLastFetchedMs: (state) => state.quotesLastFetched,\n isLoading: (state) => state.quotesLoadingStatus === RequestStatus.LOADING,\n quoteFetchError: (state) => state.quoteFetchError,\n quotesRefreshCount: (state) => state.quotesRefreshCount,\n quotesInitialLoadTimeMs: (state) => state.quotesInitialLoadTime,\n isQuoteGoingToRefresh: selectIsQuoteGoingToRefresh,\n});\n\nconst selectBatchSellFees = createBridgeSelector(\n [\n (state) => state.batchSellTrades?.fee?.amount,\n (state) => state.batchSellTrades?.fee?.asset,\n (state) =>\n selectExchangeRateByAssetId(\n state,\n state.batchSellTrades?.fee?.asset?.assetId,\n ),\n ],\n (feeAmount, feeAsset, exchangeRate) => {\n return feeAmount && feeAsset && exchangeRate\n ? calcBatchFees(feeAmount, feeAsset, exchangeRate)\n : undefined;\n },\n);\n\n/**\n * Selects the batch transactions and fees for a batch of quotes\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @returns The total transaction fees and whether the batch sell trades are submittable.\n *\n * @example\n * ```ts\n * const { totalNetworkFee, isBatchSellTradeAvailable } = useSelector(state => selectBatchSellTrades(state.metamask));\n * ```\n */\nexport const selectBatchSellTrades = createBridgeSelector(\n [\n (state) => state.batchSellTradesLoadingStatus === RequestStatus.FETCHED,\n (state) => state.batchSellTrades,\n selectBatchSellFees,\n (state) => state.batchSellTradesLoadingStatus === RequestStatus.LOADING,\n ],\n (isBatchSellTradeAvailable, batchSellTrades, batchFees, isLoading) => {\n return {\n totalNetworkFee: batchFees,\n /**\n * Whether the batch sell trades have been fetched and transactions are ready to be submitted\n */\n isBatchSellTradeAvailable:\n isBatchSellTradeAvailable &&\n Boolean(batchSellTrades?.transactions?.length),\n isLoading,\n };\n },\n);\n\nexport const selectMinimumBalanceForRentExemptionInSOL = (\n state: BridgeAppState,\n) =>\n new BigNumber(state.minimumBalanceForRentExemptionInLamports ?? 0)\n .div(10 ** 9)\n .toString();\n\nexport const selectTokenWarnings = (state: BridgeAppState) =>\n state.tokenWarnings;\n\nexport const selectDefaultSlippagePercentage = createBridgeSelector(\n [\n (state) => selectBridgeFeatureFlags(state).chains,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.srcTokenAddress,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.destTokenAddress,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.srcChainId\n ? formatChainIdToCaip(slippageParams.srcChainId)\n : undefined,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.destChainId\n ? formatChainIdToCaip(slippageParams.destChainId)\n : undefined,\n ],\n (\n featureFlagsByChain,\n srcTokenAddress,\n destTokenAddress,\n srcChainId,\n destChainId,\n ) => {\n return getDefaultSlippagePercentage(\n {\n srcTokenAddress,\n destTokenAddress,\n srcChainId,\n destChainId,\n },\n srcChainId ? featureFlagsByChain[srcChainId]?.stablecoins : undefined,\n destChainId ? featureFlagsByChain[destChainId]?.stablecoins : undefined,\n );\n },\n);\n"]}
|
|
1
|
+
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,UAAU,EAAE,+BAA+B;AAWpD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,wBAAwB;AACxE,OAAO,EAAE,SAAS,EAAE,qBAAqB;;;AAEzC,OAAO,EACL,cAAc,IAAI,eAAe,EACjC,wBAAwB,IAAI,yBAAyB,EACtD,iBAAiB;AAElB,OAAO,EAAE,6BAA6B,EAAE,+BAA2B;AAQnE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,oBAAgB;AACnD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,EACf,eAAe,EAChB,2BAAuB;AACxB,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,mBAAmB,EACnB,kBAAkB,EACnB,oCAAgC;AACjC,OAAO,EAAE,mBAAmB,EAAE,kCAA8B;AAC5D,OAAO,EACL,kBAAkB,EAClB,QAAQ,EACR,8BAA8B,EAC9B,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,yBAAyB,EACzB,YAAY,EACZ,YAAY,EACZ,4BAA4B,EAC5B,sBAAsB,EACtB,aAAa,EACd,0BAAsB;AACvB,OAAO,EAAE,4BAA4B,EAAE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AAC,MAAM,mBAAmB,GAAG,CAAC,KAAqB,EAAE,EAAE,CAC3D,KAAK,CAAC,aAAa,CAAC;AAEtB,MAAM,CAAC,MAAM,+BAA+B,GAAG,oBAAoB,CACjE;IACE,CAAC,KAAK,EAAE,EAAE,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,MAAM;IACjD,CAAC,CAAC,EAAE,cAAkE,EAAE,EAAE,CACxE,cAAc,CAAC,eAAe;IAChC,CAAC,CAAC,EAAE,cAAkE,EAAE,EAAE,CACxE,cAAc,CAAC,gBAAgB;IACjC,CAAC,CAAC,EAAE,cAAkE,EAAE,EAAE,CACxE,cAAc,CAAC,UAAU;QACvB,CAAC,CAAC,mBAAmB,CAAC,cAAc,CAAC,UAAU,CAAC;QAChD,CAAC,CAAC,SAAS;IACf,CAAC,CAAC,EAAE,cAAkE,EAAE,EAAE,CACxE,cAAc,CAAC,WAAW;QACxB,CAAC,CAAC,mBAAmB,CAAC,cAAc,CAAC,WAAW,CAAC;QACjD,CAAC,CAAC,SAAS;CAChB,EACD,CACE,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,EAAE;IACF,OAAO,4BAA4B,CACjC;QACE,eAAe;QACf,gBAAgB;QAChB,UAAU;QACV,WAAW;KACZ,EACD,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,SAAS,EACrE,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,SAAS,CACxE,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { getAddress } from '@ethersproject/address';\nimport type {\n CurrencyRateState,\n MultichainAssetsRatesControllerState,\n TokenRatesControllerState,\n} from '@metamask/assets-controllers';\nimport type {\n GasFeeEstimates,\n GasFeeEstimatesByChainId,\n} from '@metamask/gas-fee-controller';\nimport type { CaipAssetType } from '@metamask/utils';\nimport { isStrictHexString, parseCaipAssetType } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { orderBy } from 'lodash';\nimport {\n createSelector as createSelector_,\n createStructuredSelector as createStructuredSelector_,\n} from 'reselect';\n\nimport { BRIDGE_PREFERRED_GAS_ESTIMATE } from './constants/bridge';\nimport type {\n BridgeControllerState,\n ExchangeRate,\n QuoteMetadata,\n QuoteResponseV1,\n TokenAmountValues,\n} from './types';\nimport { RequestStatus, SortOrder } from './types';\nimport {\n getNativeAssetForChainId,\n isEvmQuoteResponse,\n isNativeAddress,\n isNonEvmChainId,\n} from './utils/bridge';\nimport {\n formatAddressToAssetId,\n formatAddressToCaipReference,\n formatChainIdToCaip,\n formatChainIdToHex,\n} from './utils/caip-formatters';\nimport { processFeatureFlags } from './utils/feature-flags';\nimport {\n calcAdjustedReturn,\n calcCost,\n calcEstimatedAndMaxTotalGasFee,\n calcIncludedTxFees,\n calcRelayerFee,\n calcSentAmount,\n calcNonEvmTotalNetworkFee,\n calcSwapRate,\n calcToAmount,\n calcTotalEstimatedNetworkFee,\n calcTotalMaxNetworkFee,\n calcBatchFees,\n} from './utils/quote';\nimport { getDefaultSlippagePercentage } from './utils/slippage';\n\n/**\n * The controller states that provide exchange rates\n */\ntype ExchangeRateControllerState = MultichainAssetsRatesControllerState &\n TokenRatesControllerState &\n CurrencyRateState &\n Pick<BridgeControllerState, 'assetExchangeRates'>;\n/**\n * The state of the bridge controller and all its dependency controllers\n */\ntype RemoteFeatureFlagControllerState = {\n remoteFeatureFlags: {\n bridgeConfig: unknown;\n };\n};\n\n/**\n * Minimal shape required for exchange-rate lookups (used by getExchangeRateByChainIdAndAddress).\n * Uses types from assets-controllers; marketData and conversionRates also accept the bridge format.\n */\nexport type ExchangeRateSourcesForLookup = Pick<\n BridgeControllerState,\n 'assetExchangeRates'\n> &\n Partial<Pick<CurrencyRateState, 'currencyRates'>> &\n Partial<Pick<MultichainAssetsRatesControllerState, 'historicalPrices'>> & {\n marketData?:\n | TokenRatesControllerState['marketData']\n | Record<string, Record<string, { price?: number; currency?: string }>>;\n conversionRates?:\n | MultichainAssetsRatesControllerState['conversionRates']\n | Record<string, { rate: string }>;\n };\n\nexport type BridgeAppState = BridgeControllerState & {\n gasFeeEstimatesByChainId: GasFeeEstimatesByChainId;\n} & ExchangeRateControllerState & {\n participateInMetaMetrics: boolean;\n } & RemoteFeatureFlagControllerState;\n/**\n * Creates a structured selector for the bridge controller\n */\nconst createStructuredBridgeSelector =\n createStructuredSelector_.withTypes<BridgeAppState>();\n/**\n * Creates a typed selector for the bridge controller\n */\nconst createBridgeSelector = createSelector_.withTypes<BridgeAppState>();\n/**\n * Required parameters that clients must provide for the bridge quotes selector\n */\ntype BridgeQuotesClientParams = {\n sortOrder: SortOrder;\n selectedQuote: (QuoteResponseV1 & QuoteMetadata) | null;\n};\n\ntype EvmTokenExchangeRate = { price?: number; currency?: string };\ntype EvmTokenExchangeRates = Record<string, EvmTokenExchangeRate>;\n\nconst createFeatureFlagsSelector =\n createSelector_.withTypes<RemoteFeatureFlagControllerState>();\n\n/**\n * Selects the bridge feature flags\n *\n * @param state - The state of the bridge controller\n * @returns The bridge feature flags\n *\n * @example\n * ```ts\n * const featureFlags = useSelector(state => selectBridgeFeatureFlags(state));\n *\n * Or\n *\n * export const selectBridgeFeatureFlags = createSelector(\n * selectRemoteFeatureFlags,\n * (remoteFeatureFlags) =>\n * selectBridgeFeatureFlagsBase({\n * bridgeConfig: remoteFeatureFlags.bridgeConfig,\n * }),\n * );\n * ```\n */\nexport const selectBridgeFeatureFlags = createFeatureFlagsSelector(\n [(state) => state.remoteFeatureFlags.bridgeConfig],\n (bridgeConfig: unknown) => processFeatureFlags(bridgeConfig),\n);\n\nconst getEvmTokenExchangeRateForAddress = (\n evmTokenExchangeRates: EvmTokenExchangeRates | undefined,\n address: string,\n): EvmTokenExchangeRate | null | undefined => {\n try {\n return isStrictHexString(address)\n ? (evmTokenExchangeRates?.[getAddress(address)] ??\n evmTokenExchangeRates?.[address.toLowerCase()])\n : null;\n } catch {\n return null;\n }\n};\n\n/**\n * Selects the asset exchange rate for a given chain and address\n *\n * @param exchangeRateSources - the controller states containing the exchange rates\n * @param assetId - the assetId to get the exchange rate for\n * @returns The asset exchange rate for the given assetId\n */\nexport const selectExchangeRateByAssetId = (\n exchangeRateSources: ExchangeRateSourcesForLookup,\n assetId?: CaipAssetType,\n): ExchangeRate => {\n if (!assetId) {\n return {};\n }\n\n const { assetExchangeRates, currencyRates, marketData, conversionRates } =\n exchangeRateSources;\n\n // If the asset exchange rate is available in the bridge controller, use it\n // This is defined if the token's rate is not available from the assets controllers\n const bridgeControllerRate =\n assetExchangeRates?.[assetId.toLowerCase() as CaipAssetType] ??\n assetExchangeRates?.[assetId];\n if (\n bridgeControllerRate?.exchangeRate &&\n bridgeControllerRate?.usdExchangeRate\n ) {\n return bridgeControllerRate;\n }\n\n const { chainId } = parseCaipAssetType(assetId);\n\n // If the chain is a non-EVM chain, use the conversion rate from the multichain assets controller\n if (isNonEvmChainId(chainId)) {\n const conversionRatesByKey = conversionRates as\n | Record<string, { rate?: string }>\n | undefined;\n const multichainAssetExchangeRate = conversionRatesByKey?.[assetId];\n const rate = multichainAssetExchangeRate?.rate;\n if (rate) {\n // The multichain rate is denominated in the user's selected currency.\n // To get a USD rate, find the user's-currency-to-USD conversion factor from any EVM native currency rate.\n const nativeCurrencyRate = Object.values(currencyRates ?? {}).find(\n (rateEntry) =>\n rateEntry?.conversionRate !== undefined &&\n rateEntry?.conversionRate !== null &&\n rateEntry?.usdConversionRate !== undefined &&\n rateEntry?.usdConversionRate !== null,\n );\n const usersCurrencyToUsdRate =\n nativeCurrencyRate?.conversionRate !== undefined &&\n nativeCurrencyRate?.conversionRate !== null &&\n nativeCurrencyRate?.usdConversionRate !== undefined &&\n nativeCurrencyRate?.usdConversionRate !== null\n ? new BigNumber(nativeCurrencyRate.usdConversionRate).div(\n nativeCurrencyRate.conversionRate,\n )\n : undefined;\n const usdExchangeRate = usersCurrencyToUsdRate\n ? new BigNumber(rate).times(usersCurrencyToUsdRate).toString()\n : undefined;\n return {\n exchangeRate: rate,\n usdExchangeRate,\n };\n }\n return {};\n }\n\n const address = formatAddressToCaipReference(assetId);\n\n // If the chain is an EVM chain, use the conversion rate from the currency rates controller\n if (isNativeAddress(address)) {\n const { symbol } = getNativeAssetForChainId(chainId);\n const evmNativeExchangeRate = currencyRates?.[symbol];\n if (evmNativeExchangeRate) {\n return {\n exchangeRate: evmNativeExchangeRate.conversionRate?.toString(),\n usdExchangeRate: evmNativeExchangeRate.usdConversionRate?.toString(),\n };\n }\n return {};\n }\n // If the chain is an EVM chain and the asset is not the native asset, use the conversion rate from the token rates controller\n if (!isNonEvmChainId(chainId)) {\n const marketDataByChain =\n (marketData as Record<string, EvmTokenExchangeRates> | undefined) ?? {};\n const evmTokenExchangeRates =\n marketDataByChain[formatChainIdToHex(chainId)];\n const evmTokenExchangeRateForAddress = getEvmTokenExchangeRateForAddress(\n evmTokenExchangeRates,\n address,\n );\n const currencyKey = evmTokenExchangeRateForAddress?.currency;\n const nativeCurrencyRate =\n currencyKey !== undefined && currencyKey !== null\n ? currencyRates?.[currencyKey]\n : undefined;\n const price = evmTokenExchangeRateForAddress?.price ?? 0;\n if (evmTokenExchangeRateForAddress && nativeCurrencyRate) {\n return {\n exchangeRate: new BigNumber(price)\n .multipliedBy(nativeCurrencyRate.conversionRate ?? 0)\n .toString(),\n usdExchangeRate: new BigNumber(price)\n .multipliedBy(nativeCurrencyRate.usdConversionRate ?? 0)\n .toString(),\n };\n }\n }\n\n return {};\n};\n\n/**\n * Checks whether an exchange rate is available for a given assetId\n *\n * @param state The state of the bridge controller and its dependency controllers\n * @param assetId The assetId to check\n * @returns Whether an exchange rate is available for the given chain and address\n */\nexport const selectIsAssetExchangeRateInState = (\n state: ExchangeRateSourcesForLookup,\n assetId?: CaipAssetType,\n) =>\n Boolean(selectExchangeRateByAssetId(state, assetId)?.exchangeRate) &&\n Boolean(selectExchangeRateByAssetId(state, assetId)?.usdExchangeRate);\n\n/**\n * Selects the gas fee estimates from the gas fee controller. All potential networks\n * support EIP1559 gas fees so assume that gasFeeEstimates is of type GasFeeEstimates\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @param state.gasFeeEstimatesByChainId - gasEstimates by Hex ChainId\n * @param state.quotes - Fetched bridge/swap quotes\n * @returns The gas fee estimates in decGWEI\n */\nconst selectBridgeFeesPerGas = createBridgeSelector(\n [\n (state) => state.gasFeeEstimatesByChainId,\n (state) => state.quotes?.[0]?.quote.srcChainId,\n ],\n (gasFeeEstimatesByChainId, srcChainId) => {\n if (!srcChainId) {\n return null;\n }\n if (isNonEvmChainId(srcChainId)) {\n return null;\n }\n // @ts-expect-error - all supported networks use this type of estimates\n const gasFeeEstimates: GasFeeEstimates | undefined =\n gasFeeEstimatesByChainId?.[\n formatChainIdToHex(srcChainId) as keyof typeof gasFeeEstimatesByChainId\n ]?.gasFeeEstimates;\n if (!gasFeeEstimates) {\n return null;\n }\n return {\n estimatedBaseFeeInDecGwei: gasFeeEstimates.estimatedBaseFee,\n feePerGasInDecGwei:\n gasFeeEstimates[BRIDGE_PREFERRED_GAS_ESTIMATE]?.suggestedMaxFeePerGas,\n maxFeePerGasInDecGwei: gasFeeEstimates.high?.suggestedMaxFeePerGas,\n };\n },\n);\n\n// Selects cross-chain swap quotes including their metadata\nconst selectBridgeQuotesWithMetadata = createBridgeSelector(\n [\n ({ quotes }) => quotes,\n selectBridgeFeesPerGas,\n (state) => state,\n createBridgeSelector(\n [\n (state) => state,\n ({ quoteRequest: [{ destChainId, destTokenAddress }] }) =>\n destTokenAddress\n ? formatAddressToAssetId(destTokenAddress, destChainId)\n : undefined,\n ],\n selectExchangeRateByAssetId,\n ),\n createBridgeSelector(\n [\n (state) => state,\n ({ quoteRequest: [{ srcChainId }] }) =>\n srcChainId\n ? getNativeAssetForChainId(srcChainId)?.assetId\n : undefined,\n ],\n selectExchangeRateByAssetId,\n ),\n ],\n (\n quotes,\n bridgeFeesPerGas,\n exchangeRateSources,\n destTokenExchangeRate,\n nativeExchangeRate,\n ) => {\n const newQuotes = quotes.map((quote) => {\n const sourceAssetId =\n formatAddressToAssetId(\n quote.quote.srcAsset.address,\n quote.quote.srcChainId,\n ) ?? quote.quote.srcAsset.assetId;\n const srcTokenExchangeRate = selectExchangeRateByAssetId(\n exchangeRateSources,\n sourceAssetId,\n );\n const sentAmount = calcSentAmount(quote.quote, srcTokenExchangeRate);\n const toTokenAmount = calcToAmount(\n quote.quote.destTokenAmount,\n quote.quote.destAsset,\n destTokenExchangeRate,\n );\n const minToTokenAmount = calcToAmount(\n quote.quote.minDestTokenAmount,\n quote.quote.destAsset,\n destTokenExchangeRate,\n );\n\n const includedTxFees = calcIncludedTxFees(\n quote.quote,\n srcTokenExchangeRate,\n destTokenExchangeRate,\n );\n\n let totalEstimatedNetworkFee,\n totalMaxNetworkFee,\n relayerFee,\n gasFee: QuoteMetadata['gasFee'];\n\n if (isEvmQuoteResponse(quote)) {\n relayerFee = calcRelayerFee(quote, nativeExchangeRate);\n gasFee = calcEstimatedAndMaxTotalGasFee({\n bridgeQuote: quote,\n ...bridgeFeesPerGas,\n ...nativeExchangeRate,\n });\n // Uses effectiveGasFee to calculate the total estimated network fee\n totalEstimatedNetworkFee = calcTotalEstimatedNetworkFee(\n gasFee,\n relayerFee,\n );\n totalMaxNetworkFee = calcTotalMaxNetworkFee(gasFee, relayerFee);\n } else {\n // Use the new generic function for all non-EVM chains\n totalEstimatedNetworkFee = calcNonEvmTotalNetworkFee(\n quote,\n nativeExchangeRate,\n );\n gasFee = {\n effective: totalEstimatedNetworkFee,\n total: totalEstimatedNetworkFee,\n max: totalEstimatedNetworkFee,\n };\n totalMaxNetworkFee = totalEstimatedNetworkFee;\n }\n\n const adjustedReturn = calcAdjustedReturn(\n toTokenAmount,\n totalEstimatedNetworkFee,\n quote.quote,\n );\n const cost = calcCost(adjustedReturn, sentAmount);\n\n return {\n ...quote,\n // QuoteMetadata fields\n sentAmount,\n toTokenAmount,\n minToTokenAmount,\n swapRate: calcSwapRate(sentAmount.amount, toTokenAmount.amount),\n /**\n This is the amount required to submit all the transactions.\n Includes the relayer fee or other native fees.\n Should be used for balance checks and tx submission.\n */\n totalNetworkFee: totalEstimatedNetworkFee,\n totalMaxNetworkFee,\n /**\n This contains gas fee estimates for the bridge transaction\n Does not include the relayer fee (if needed), just the gasLimit and effectiveGas returned by the bridge API.\n Should only be used for display purposes.\n */\n gasFee,\n adjustedReturn,\n cost,\n includedTxFees,\n };\n });\n\n return newQuotes;\n },\n);\n\nconst selectSortedBridgeQuotes = createBridgeSelector(\n [\n selectBridgeQuotesWithMetadata,\n (_, { sortOrder }: BridgeQuotesClientParams) => sortOrder,\n ],\n (quotesWithMetadata, sortOrder): (QuoteResponseV1 & QuoteMetadata)[] => {\n switch (sortOrder) {\n case SortOrder.ETA_ASC:\n return orderBy(\n quotesWithMetadata,\n (quote) => quote.estimatedProcessingTimeInSeconds,\n 'asc',\n );\n default:\n if (quotesWithMetadata.every((quote) => quote.cost.valueInCurrency)) {\n return orderBy(\n quotesWithMetadata,\n ({ cost }) => Number(cost.valueInCurrency),\n 'asc',\n );\n }\n if (\n quotesWithMetadata.every(\n (quote) => quote.quote.priceData?.priceImpact,\n )\n ) {\n return orderBy(\n quotesWithMetadata,\n ({ quote }) => Number(quote.priceData?.priceImpact),\n 'asc',\n );\n }\n return orderBy(\n quotesWithMetadata,\n ({ quote }) => Number(quote.destTokenAmount),\n 'desc',\n );\n }\n },\n);\n\nconst selectRecommendedQuote = createBridgeSelector(\n [selectSortedBridgeQuotes],\n (quotes) => (quotes.length > 0 ? quotes[0] : null),\n);\n\nconst selectActiveQuote = createBridgeSelector(\n [\n selectRecommendedQuote,\n selectSortedBridgeQuotes,\n (_, { selectedQuote }) => selectedQuote,\n ],\n (recommendedQuote, sortedQuotes, selectedQuote) =>\n sortedQuotes.find(\n (quote) => quote.quote.requestId === selectedQuote?.quote.requestId,\n ) ?? recommendedQuote,\n);\n\nconst selectIsQuoteGoingToRefresh = createBridgeSelector(\n [\n selectBridgeFeatureFlags,\n // If at least one quote request is sufficiently funded, continue polling until max refresh count is reached\n (state) =>\n state.quoteRequest.every((quoteRequest) =>\n Boolean(quoteRequest.insufficientBal),\n ),\n (state) => state.quotesRefreshCount,\n ],\n (featureFlags, insufficientBal, quotesRefreshCount) =>\n insufficientBal ? false : featureFlags.maxRefreshCount > quotesRefreshCount,\n);\n\nconst selectQuoteRefreshRate = createBridgeSelector(\n [selectBridgeFeatureFlags, (state) => state.quoteRequest[0]?.srcChainId],\n (featureFlags, srcChainId) =>\n (srcChainId\n ? featureFlags.chains[formatChainIdToCaip(srcChainId)]?.refreshRate\n : featureFlags.refreshRate) ?? featureFlags.refreshRate,\n);\n\nexport const selectIsQuoteExpired = createBridgeSelector(\n [\n selectIsQuoteGoingToRefresh,\n ({ quotesLastFetched }) => quotesLastFetched,\n selectQuoteRefreshRate,\n (_, _ignoredParam, currentTimeInMs: number) => currentTimeInMs,\n ],\n (isQuoteGoingToRefresh, quotesLastFetched, refreshRate, currentTimeInMs) =>\n Boolean(\n !isQuoteGoingToRefresh &&\n quotesLastFetched &&\n currentTimeInMs - quotesLastFetched > refreshRate,\n ),\n);\n\n/**\n * Selects sorted cross-chain swap quotes. By default, the quotes are sorted by cost in ascending order.\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @param sortOrder - The sort order of the quotes\n * @param selectedQuote - The quote that is currently selected by the user, should be cleared by clients when the req params change\n * @returns The activeQuote, recommendedQuote, sortedQuotes, and other quote fetching metadata\n *\n * @example\n * ```ts\n * const quotes = useSelector(state => selectBridgeQuotes(\n * { ...state.metamask, bridgeConfig: remoteFeatureFlags.bridgeConfig },\n * {\n * sortOrder: state.bridge.sortOrder,\n * selectedQuote: state.bridge.selectedQuote,\n * }\n * ));\n * ```\n */\nexport const selectBridgeQuotes = createStructuredBridgeSelector({\n sortedQuotes: selectSortedBridgeQuotes,\n recommendedQuote: selectRecommendedQuote,\n activeQuote: selectActiveQuote,\n quotesLastFetchedMs: (state) => state.quotesLastFetched,\n isLoading: (state) => state.quotesLoadingStatus === RequestStatus.LOADING,\n quoteFetchError: (state) => state.quoteFetchError,\n quotesRefreshCount: (state) => state.quotesRefreshCount,\n quotesInitialLoadTimeMs: (state) => state.quotesInitialLoadTime,\n isQuoteGoingToRefresh: selectIsQuoteGoingToRefresh,\n});\n\nconst selectRecommendedQuotes = createBridgeSelector(\n [\n selectSortedBridgeQuotes,\n (_, { requestCount }: { requestCount: number }) => requestCount,\n ],\n (quotes, requestCount) =>\n quotes.reduce((acc, quote) => {\n const requestIndex = quote.quoteRequestIndex ?? 0;\n acc[requestIndex] ??= quote;\n return acc;\n }, Array<(QuoteResponseV1 & QuoteMetadata) | null>(requestCount).fill(null)),\n);\n\nconst selectMetadataSum = createBridgeSelector(\n [\n selectRecommendedQuotes,\n (\n _,\n {\n key,\n }: { key: 'totalNetworkFee' | 'minToTokenAmount' | 'toTokenAmount' },\n ) => key,\n ],\n (recommendedQuotes, key) =>\n recommendedQuotes.reduce<TokenAmountValues>(\n (acc, quote) => {\n acc.usd = new BigNumber(acc.usd ?? 0)\n .plus(quote?.[key]?.usd ?? 0)\n .toString();\n acc.valueInCurrency = new BigNumber(acc.valueInCurrency ?? 0)\n .plus(quote?.[key]?.valueInCurrency ?? 0)\n .toString();\n acc.amount = new BigNumber(acc.amount ?? 0)\n .plus(quote?.[key]?.amount ?? 0)\n .toString();\n return acc;\n },\n { usd: null, valueInCurrency: null, amount: '0' },\n ),\n);\n\n/**\n * Selects the recommended swap quotes for a batch of quote requests.\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @param sortOrder - The sort order of the quotes\n * @param requestCount - The number of quote requests fetched in the batch\n * @returns The quotes for multiple quote requests, including their recommendedQuotes,\n * totalReceived, minimumReceived, totalNetworkFee, and other quote fetching metadata.\n *\n * @example\n * ```ts\n * const quotes = useSelector(state => selectBatchSellQuotes(\n * { ...state.metamask },\n * {\n * sortOrder: state.bridge.sortOrder,\n * requestCount: 4,\n * }\n * ));\n * ```\n */\nexport const selectBatchSellQuotes = createStructuredBridgeSelector({\n recommendedQuotes: selectRecommendedQuotes,\n totalReceived: (state, opts) =>\n selectMetadataSum(state, { ...opts, key: 'toTokenAmount' }),\n minimumReceived: (state, opts) =>\n selectMetadataSum(state, { ...opts, key: 'minToTokenAmount' }),\n quotesLastFetchedMs: (state) => state.quotesLastFetched,\n isLoading: (state) => state.quotesLoadingStatus === RequestStatus.LOADING,\n quoteFetchError: (state) => state.quoteFetchError,\n quotesRefreshCount: (state) => state.quotesRefreshCount,\n quotesInitialLoadTimeMs: (state) => state.quotesInitialLoadTime,\n isQuoteGoingToRefresh: selectIsQuoteGoingToRefresh,\n});\n\nconst selectBatchSellFees = createBridgeSelector(\n [\n (state) => state.batchSellTrades?.fee?.amount,\n (state) => state.batchSellTrades?.fee?.asset,\n (state) =>\n selectExchangeRateByAssetId(\n state,\n state.batchSellTrades?.fee?.asset?.assetId,\n ),\n ],\n (feeAmount, feeAsset, exchangeRate) => {\n return feeAmount && feeAsset && exchangeRate\n ? calcBatchFees(feeAmount, feeAsset, exchangeRate)\n : undefined;\n },\n);\n\n/**\n * Selects the batch transactions and fees for a batch of quotes\n *\n * @param state - The state of the bridge controller and its dependency controllers\n * @returns The total transaction fees and whether the batch sell trades are submittable.\n *\n * @example\n * ```ts\n * const { totalNetworkFee, isBatchSellTradeAvailable } = useSelector(state => selectBatchSellTrades(state.metamask));\n * ```\n */\nexport const selectBatchSellTrades = createBridgeSelector(\n [\n (state) => state.batchSellTradesLoadingStatus === RequestStatus.FETCHED,\n (state) => state.batchSellTrades,\n selectBatchSellFees,\n (state) => state.batchSellTradesLoadingStatus === RequestStatus.LOADING,\n ],\n (isBatchSellTradeAvailable, batchSellTrades, batchFees, isLoading) => {\n return {\n totalNetworkFee: batchFees,\n /**\n * Whether the batch sell trades have been fetched and transactions are ready to be submitted\n */\n isBatchSellTradeAvailable:\n isBatchSellTradeAvailable &&\n Boolean(batchSellTrades?.transactions?.length),\n isLoading,\n };\n },\n);\n\nexport const selectMinimumBalanceForRentExemptionInSOL = (\n state: BridgeAppState,\n) =>\n new BigNumber(state.minimumBalanceForRentExemptionInLamports ?? 0)\n .div(10 ** 9)\n .toString();\n\nexport const selectTokenWarnings = (state: BridgeAppState) =>\n state.tokenWarnings;\n\nexport const selectDefaultSlippagePercentage = createBridgeSelector(\n [\n (state) => selectBridgeFeatureFlags(state).chains,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.srcTokenAddress,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.destTokenAddress,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.srcChainId\n ? formatChainIdToCaip(slippageParams.srcChainId)\n : undefined,\n (_, slippageParams: Parameters<typeof getDefaultSlippagePercentage>[0]) =>\n slippageParams.destChainId\n ? formatChainIdToCaip(slippageParams.destChainId)\n : undefined,\n ],\n (\n featureFlagsByChain,\n srcTokenAddress,\n destTokenAddress,\n srcChainId,\n destChainId,\n ) => {\n return getDefaultSlippagePercentage(\n {\n srcTokenAddress,\n destTokenAddress,\n srcChainId,\n destChainId,\n },\n srcChainId ? featureFlagsByChain[srcChainId]?.stablecoins : undefined,\n destChainId ? featureFlagsByChain[destChainId]?.stablecoins : undefined,\n );\n },\n);\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetricsSwapType = exports.MetricsActionType = exports.InputAmountPreset = exports.MetaMetricsSwapsEventSource = exports.AbortReason = exports.PollingStatus = exports.UnifiedSwapBridgeEventName = exports.UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = void 0;
|
|
3
|
+
exports.MetricsSwapType = exports.MetricsActionType = exports.InputAmountPreset = exports.BatchSellMetricsLocation = exports.MetaMetricsSwapsEventSource = exports.AbortReason = exports.PollingStatus = exports.BatchSellMetricsEventName = exports.UnifiedSwapBridgeEventName = exports.BATCH_SELL_EVENT_CATEGORY = exports.UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
5
|
exports.UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = 'Unified SwapBridge';
|
|
6
|
+
exports.BATCH_SELL_EVENT_CATEGORY = 'Batch Sell';
|
|
6
7
|
/**
|
|
7
8
|
* These event names map to events defined in the segment-schema: https://github.com/Consensys/segment-schema/tree/main/libraries/events/metamask-cross-chain-swaps
|
|
8
9
|
*/
|
|
@@ -28,6 +29,14 @@ var UnifiedSwapBridgeEventName;
|
|
|
28
29
|
UnifiedSwapBridgeEventName["AssetPickerOpened"] = "Unified SwapBridge Asset Picker Opened";
|
|
29
30
|
UnifiedSwapBridgeEventName["PollingStatusUpdated"] = "Unified SwapBridge Polling Status Updated";
|
|
30
31
|
})(UnifiedSwapBridgeEventName || (exports.UnifiedSwapBridgeEventName = UnifiedSwapBridgeEventName = {}));
|
|
32
|
+
var BatchSellMetricsEventName;
|
|
33
|
+
(function (BatchSellMetricsEventName) {
|
|
34
|
+
BatchSellMetricsEventName["BatchSellTokenPageViewed"] = "Batch Sell Token Page Viewed";
|
|
35
|
+
BatchSellMetricsEventName["BatchSellTokenPageContinueClicked"] = "Batch Sell Token Page Continue Clicked";
|
|
36
|
+
BatchSellMetricsEventName["BatchSellQuotePageViewed"] = "Batch Sell Quote Page Viewed";
|
|
37
|
+
BatchSellMetricsEventName["BatchSellQuotePageReviewClicked"] = "Batch Sell Quote Page Review Clicked";
|
|
38
|
+
BatchSellMetricsEventName["BatchSellReviewModalSubmitted"] = "Batch Sell Review Modal Submitted";
|
|
39
|
+
})(BatchSellMetricsEventName || (exports.BatchSellMetricsEventName = BatchSellMetricsEventName = {}));
|
|
31
40
|
var PollingStatus;
|
|
32
41
|
(function (PollingStatus) {
|
|
33
42
|
PollingStatus["MaxPollingReached"] = "max_polling_reached";
|
|
@@ -59,6 +68,13 @@ var MetaMetricsSwapsEventSource;
|
|
|
59
68
|
MetaMetricsSwapsEventSource["DeepLink"] = "Deep Link";
|
|
60
69
|
MetaMetricsSwapsEventSource["Unknown"] = "Unknown";
|
|
61
70
|
})(MetaMetricsSwapsEventSource || (exports.MetaMetricsSwapsEventSource = MetaMetricsSwapsEventSource = {}));
|
|
71
|
+
var BatchSellMetricsLocation;
|
|
72
|
+
(function (BatchSellMetricsLocation) {
|
|
73
|
+
BatchSellMetricsLocation["TradeMenu"] = "trade_menu";
|
|
74
|
+
BatchSellMetricsLocation["Deeplink"] = "deeplink";
|
|
75
|
+
BatchSellMetricsLocation["AssetPicker"] = "asset_picker";
|
|
76
|
+
BatchSellMetricsLocation["Unknown"] = "Unknown";
|
|
77
|
+
})(BatchSellMetricsLocation || (exports.BatchSellMetricsLocation = BatchSellMetricsLocation = {}));
|
|
62
78
|
var InputAmountPreset;
|
|
63
79
|
(function (InputAmountPreset) {
|
|
64
80
|
InputAmountPreset["PERCENT_25"] = "25%";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AAC5C,QAAA,kCAAkC,GAAG,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AAC5C,QAAA,kCAAkC,GAAG,oBAAoB,CAAC;AAC1D,QAAA,yBAAyB,GAAG,YAAY,CAAC;AAEtD;;GAEG;AACH,IAAY,0BAoBX;AApBD,WAAY,0BAA0B;IACpC,iFAAsE,CAAA;IACtE,2EAAgE,CAAA;IAChE,+EAAoE,CAAA;IACpE,uGAA4F,CAAA;IAC5F,+GAAoG,CAAA;IACpG,qFA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A4B,CAAA;IAC5B,+CAAmB,CAAA;AACrB,CAAC,EALW,wBAAwB,wCAAxB,wBAAwB,QAKnC;AAMD,IAAY,iBAOX;AAPD,WAAY,iBAAiB;IAC3B,uCAAkB,CAAA;IAClB,uCAAkB,CAAA;IAClB,uCAAkB,CAAA;IAClB,uCAAkB,CAAA;IAClB,uEAAuE;IACvE,gCAAW,CAAA;AACb,CAAC,EAPW,iBAAiB,iCAAjB,iBAAiB,QAO5B;AAED,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B;;OAEG;IACH,oDAA+B,CAAA;IAC/B,oDAA+B,CAAA;AACjC,CAAC,EANW,iBAAiB,iCAAjB,iBAAiB,QAM5B;AAED,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,4CAAyB,CAAA;AAC3B,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nexport const UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = 'Unified SwapBridge';\nexport const BATCH_SELL_EVENT_CATEGORY = 'Batch Sell';\n\n/**\n * These event names map to events defined in the segment-schema: https://github.com/Consensys/segment-schema/tree/main/libraries/events/metamask-cross-chain-swaps\n */\nexport enum UnifiedSwapBridgeEventName {\n ButtonClicked = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Button Clicked`,\n PageViewed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Page Viewed`,\n InputChanged = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Input Changed`,\n FiatCryptoToggleClicked = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Fiat Crypto Toggle Clicked`,\n InputSourceDestinationSwitched = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Source Destination Switched`,\n QuotesRequested = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Requested`,\n QuotesReceived = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Received`,\n QuotesError = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Error`,\n Submitted = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Submitted`,\n Completed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Completed`,\n Failed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Failed`,\n AllQuotesOpened = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} All Quotes Opened`,\n AllQuotesSorted = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} All Quotes Sorted`,\n QuoteSelected = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quote Selected`,\n AssetDetailTooltipClicked = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Asset Detail Tooltip Clicked`,\n QuotesValidationFailed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Failed Validation`,\n StatusValidationFailed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Status Failed Validation`,\n AssetPickerOpened = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Asset Picker Opened`,\n PollingStatusUpdated = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Polling Status Updated`,\n}\n\nexport enum BatchSellMetricsEventName {\n BatchSellTokenPageViewed = `${BATCH_SELL_EVENT_CATEGORY} Token Page Viewed`,\n BatchSellTokenPageContinueClicked = `${BATCH_SELL_EVENT_CATEGORY} Token Page Continue Clicked`,\n BatchSellQuotePageViewed = `${BATCH_SELL_EVENT_CATEGORY} Quote Page Viewed`,\n BatchSellQuotePageReviewClicked = `${BATCH_SELL_EVENT_CATEGORY} Quote Page Review Clicked`,\n BatchSellReviewModalSubmitted = `${BATCH_SELL_EVENT_CATEGORY} Review Modal Submitted`,\n}\n\nexport type BridgeControllerMetricsEventName =\n | UnifiedSwapBridgeEventName\n | BatchSellMetricsEventName;\n\nexport enum PollingStatus {\n MaxPollingReached = 'max_polling_reached',\n InvalidTransactionHash = 'invalid_transaction_hash',\n ManuallyRestarted = 'manually_restarted',\n}\n\nexport enum AbortReason {\n NewQuoteRequest = 'New Quote Request',\n QuoteRequestUpdated = 'Quote Request Updated',\n ResetState = 'Reset controller state',\n TransactionSubmitted = 'Transaction submitted',\n GaslessTxBatchFetched = 'Gasless transaction batch fetched',\n}\n\n/**\n * Identifies the entry point from which the user initiated a swap or bridge flow.\n * Included as the `location` property on every Unified SwapBridge event so\n * analytics can trace the user's origin regardless of where they are in the flow.\n */\nexport enum MetaMetricsSwapsEventSource {\n MainView = 'Main View',\n TokenView = 'Token View',\n TrendingExplore = 'Trending Explore',\n Rewards = 'Rewards',\n ActivityTabEmptyState = 'Activity Tab Empty State',\n TransactionShield = 'Transaction Shield',\n TransactionDetails = 'Transaction Details',\n DeepLink = 'Deep Link',\n Unknown = 'Unknown',\n}\n\nexport enum BatchSellMetricsLocation {\n TradeMenu = 'trade_menu',\n Deeplink = 'deeplink',\n AssetPicker = 'asset_picker',\n Unknown = 'Unknown',\n}\n\nexport type BridgeControllerMetricsLocation =\n | MetaMetricsSwapsEventSource\n | BatchSellMetricsLocation;\n\nexport enum InputAmountPreset {\n PERCENT_25 = '25%',\n PERCENT_50 = '50%',\n PERCENT_75 = '75%',\n PERCENT_90 = '90%',\n // \"Max\" may not equal 100% of balance (e.g. gas reserves are withheld)\n MAX = 'MAX',\n}\n\nexport enum MetricsActionType {\n /**\n * @deprecated new events should use SWAPBRIDGE_V1 instead\n */\n CROSSCHAIN_V1 = 'crosschain-v1',\n SWAPBRIDGE_V1 = 'swapbridge-v1',\n}\n\nexport enum MetricsSwapType {\n SINGLE = 'single_chain',\n CROSSCHAIN = 'crosschain',\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = "Unified SwapBridge";
|
|
2
|
+
export declare const BATCH_SELL_EVENT_CATEGORY = "Batch Sell";
|
|
2
3
|
/**
|
|
3
4
|
* These event names map to events defined in the segment-schema: https://github.com/Consensys/segment-schema/tree/main/libraries/events/metamask-cross-chain-swaps
|
|
4
5
|
*/
|
|
@@ -23,6 +24,14 @@ export declare enum UnifiedSwapBridgeEventName {
|
|
|
23
24
|
AssetPickerOpened = "Unified SwapBridge Asset Picker Opened",
|
|
24
25
|
PollingStatusUpdated = "Unified SwapBridge Polling Status Updated"
|
|
25
26
|
}
|
|
27
|
+
export declare enum BatchSellMetricsEventName {
|
|
28
|
+
BatchSellTokenPageViewed = "Batch Sell Token Page Viewed",
|
|
29
|
+
BatchSellTokenPageContinueClicked = "Batch Sell Token Page Continue Clicked",
|
|
30
|
+
BatchSellQuotePageViewed = "Batch Sell Quote Page Viewed",
|
|
31
|
+
BatchSellQuotePageReviewClicked = "Batch Sell Quote Page Review Clicked",
|
|
32
|
+
BatchSellReviewModalSubmitted = "Batch Sell Review Modal Submitted"
|
|
33
|
+
}
|
|
34
|
+
export type BridgeControllerMetricsEventName = UnifiedSwapBridgeEventName | BatchSellMetricsEventName;
|
|
26
35
|
export declare enum PollingStatus {
|
|
27
36
|
MaxPollingReached = "max_polling_reached",
|
|
28
37
|
InvalidTransactionHash = "invalid_transaction_hash",
|
|
@@ -51,6 +60,13 @@ export declare enum MetaMetricsSwapsEventSource {
|
|
|
51
60
|
DeepLink = "Deep Link",
|
|
52
61
|
Unknown = "Unknown"
|
|
53
62
|
}
|
|
63
|
+
export declare enum BatchSellMetricsLocation {
|
|
64
|
+
TradeMenu = "trade_menu",
|
|
65
|
+
Deeplink = "deeplink",
|
|
66
|
+
AssetPicker = "asset_picker",
|
|
67
|
+
Unknown = "Unknown"
|
|
68
|
+
}
|
|
69
|
+
export type BridgeControllerMetricsLocation = MetaMetricsSwapsEventSource | BatchSellMetricsLocation;
|
|
54
70
|
export declare enum InputAmountPreset {
|
|
55
71
|
PERCENT_25 = "25%",
|
|
56
72
|
PERCENT_50 = "50%",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kCAAkC,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kCAAkC,uBAAuB,CAAC;AACvE,eAAO,MAAM,yBAAyB,eAAe,CAAC;AAEtD;;GAEG;AACH,oBAAY,0BAA0B;IACpC,aAAa,sCAAyD;IACtE,UAAU,mCAAsD;IAChE,YAAY,qCAAwD;IACpE,uBAAuB,kDAAqE;IAC5F,8BAA8B,mDAAsE;IACpG,eAAe,wCAA2D;IAC1E,cAAc,uCAA0D;IACxE,WAAW,oCAAuD;IAClE,SAAS,iCAAoD;IAC7D,SAAS,iCAAoD;IAC7D,MAAM,8BAAiD;IACvD,eAAe,yCAA4D;IAC3E,eAAe,yCAA4D;IAC3E,aAAa,sCAAyD;IACtE,yBAAyB,oDAAuE;IAChG,sBAAsB,gDAAmE;IACzF,sBAAsB,gDAAmE;IACzF,iBAAiB,2CAA8D;IAC/E,oBAAoB,8CAAiE;CACtF;AAED,oBAAY,yBAAyB;IACnC,wBAAwB,iCAAmD;IAC3E,iCAAiC,2CAA6D;IAC9F,wBAAwB,iCAAmD;IAC3E,+BAA+B,yCAA2D;IAC1F,6BAA6B,sCAAwD;CACtF;AAED,MAAM,MAAM,gCAAgC,GACxC,0BAA0B,GAC1B,yBAAyB,CAAC;AAE9B,oBAAY,aAAa;IACvB,iBAAiB,wBAAwB;IACzC,sBAAsB,6BAA6B;IACnD,iBAAiB,uBAAuB;CACzC;AAED,oBAAY,WAAW;IACrB,eAAe,sBAAsB;IACrC,mBAAmB,0BAA0B;IAC7C,UAAU,2BAA2B;IACrC,oBAAoB,0BAA0B;IAC9C,qBAAqB,sCAAsC;CAC5D;AAED;;;;GAIG;AACH,oBAAY,2BAA2B;IACrC,QAAQ,cAAc;IACtB,SAAS,eAAe;IACxB,eAAe,qBAAqB;IACpC,OAAO,YAAY;IACnB,qBAAqB,6BAA6B;IAClD,iBAAiB,uBAAuB;IACxC,kBAAkB,wBAAwB;IAC1C,QAAQ,cAAc;IACtB,OAAO,YAAY;CACpB;AAED,oBAAY,wBAAwB;IAClC,SAAS,eAAe;IACxB,QAAQ,aAAa;IACrB,WAAW,iBAAiB;IAC5B,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,+BAA+B,GACvC,2BAA2B,GAC3B,wBAAwB,CAAC;AAE7B,oBAAY,iBAAiB;IAC3B,UAAU,QAAQ;IAClB,UAAU,QAAQ;IAClB,UAAU,QAAQ;IAClB,UAAU,QAAQ;IAElB,GAAG,QAAQ;CACZ;AAED,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;CAChC;AAED,oBAAY,eAAe;IACzB,MAAM,iBAAiB;IACvB,UAAU,eAAe;CAC1B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = "Unified SwapBridge";
|
|
2
|
+
export declare const BATCH_SELL_EVENT_CATEGORY = "Batch Sell";
|
|
2
3
|
/**
|
|
3
4
|
* These event names map to events defined in the segment-schema: https://github.com/Consensys/segment-schema/tree/main/libraries/events/metamask-cross-chain-swaps
|
|
4
5
|
*/
|
|
@@ -23,6 +24,14 @@ export declare enum UnifiedSwapBridgeEventName {
|
|
|
23
24
|
AssetPickerOpened = "Unified SwapBridge Asset Picker Opened",
|
|
24
25
|
PollingStatusUpdated = "Unified SwapBridge Polling Status Updated"
|
|
25
26
|
}
|
|
27
|
+
export declare enum BatchSellMetricsEventName {
|
|
28
|
+
BatchSellTokenPageViewed = "Batch Sell Token Page Viewed",
|
|
29
|
+
BatchSellTokenPageContinueClicked = "Batch Sell Token Page Continue Clicked",
|
|
30
|
+
BatchSellQuotePageViewed = "Batch Sell Quote Page Viewed",
|
|
31
|
+
BatchSellQuotePageReviewClicked = "Batch Sell Quote Page Review Clicked",
|
|
32
|
+
BatchSellReviewModalSubmitted = "Batch Sell Review Modal Submitted"
|
|
33
|
+
}
|
|
34
|
+
export type BridgeControllerMetricsEventName = UnifiedSwapBridgeEventName | BatchSellMetricsEventName;
|
|
26
35
|
export declare enum PollingStatus {
|
|
27
36
|
MaxPollingReached = "max_polling_reached",
|
|
28
37
|
InvalidTransactionHash = "invalid_transaction_hash",
|
|
@@ -51,6 +60,13 @@ export declare enum MetaMetricsSwapsEventSource {
|
|
|
51
60
|
DeepLink = "Deep Link",
|
|
52
61
|
Unknown = "Unknown"
|
|
53
62
|
}
|
|
63
|
+
export declare enum BatchSellMetricsLocation {
|
|
64
|
+
TradeMenu = "trade_menu",
|
|
65
|
+
Deeplink = "deeplink",
|
|
66
|
+
AssetPicker = "asset_picker",
|
|
67
|
+
Unknown = "Unknown"
|
|
68
|
+
}
|
|
69
|
+
export type BridgeControllerMetricsLocation = MetaMetricsSwapsEventSource | BatchSellMetricsLocation;
|
|
54
70
|
export declare enum InputAmountPreset {
|
|
55
71
|
PERCENT_25 = "25%",
|
|
56
72
|
PERCENT_50 = "50%",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kCAAkC,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kCAAkC,uBAAuB,CAAC;AACvE,eAAO,MAAM,yBAAyB,eAAe,CAAC;AAEtD;;GAEG;AACH,oBAAY,0BAA0B;IACpC,aAAa,sCAAyD;IACtE,UAAU,mCAAsD;IAChE,YAAY,qCAAwD;IACpE,uBAAuB,kDAAqE;IAC5F,8BAA8B,mDAAsE;IACpG,eAAe,wCAA2D;IAC1E,cAAc,uCAA0D;IACxE,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AAiB;IAC3B;;OAEG;IACH,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;CAChC;AAED,oBAAY,eAAe;IACzB,MAAM,iBAAiB;IACvB,UAAU,eAAe;CAC1B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
2
|
export const UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = 'Unified SwapBridge';
|
|
3
|
+
export const BATCH_SELL_EVENT_CATEGORY = 'Batch Sell';
|
|
3
4
|
/**
|
|
4
5
|
* These event names map to events defined in the segment-schema: https://github.com/Consensys/segment-schema/tree/main/libraries/events/metamask-cross-chain-swaps
|
|
5
6
|
*/
|
|
@@ -25,6 +26,14 @@ export var UnifiedSwapBridgeEventName;
|
|
|
25
26
|
UnifiedSwapBridgeEventName["AssetPickerOpened"] = "Unified SwapBridge Asset Picker Opened";
|
|
26
27
|
UnifiedSwapBridgeEventName["PollingStatusUpdated"] = "Unified SwapBridge Polling Status Updated";
|
|
27
28
|
})(UnifiedSwapBridgeEventName || (UnifiedSwapBridgeEventName = {}));
|
|
29
|
+
export var BatchSellMetricsEventName;
|
|
30
|
+
(function (BatchSellMetricsEventName) {
|
|
31
|
+
BatchSellMetricsEventName["BatchSellTokenPageViewed"] = "Batch Sell Token Page Viewed";
|
|
32
|
+
BatchSellMetricsEventName["BatchSellTokenPageContinueClicked"] = "Batch Sell Token Page Continue Clicked";
|
|
33
|
+
BatchSellMetricsEventName["BatchSellQuotePageViewed"] = "Batch Sell Quote Page Viewed";
|
|
34
|
+
BatchSellMetricsEventName["BatchSellQuotePageReviewClicked"] = "Batch Sell Quote Page Review Clicked";
|
|
35
|
+
BatchSellMetricsEventName["BatchSellReviewModalSubmitted"] = "Batch Sell Review Modal Submitted";
|
|
36
|
+
})(BatchSellMetricsEventName || (BatchSellMetricsEventName = {}));
|
|
28
37
|
export var PollingStatus;
|
|
29
38
|
(function (PollingStatus) {
|
|
30
39
|
PollingStatus["MaxPollingReached"] = "max_polling_reached";
|
|
@@ -56,6 +65,13 @@ export var MetaMetricsSwapsEventSource;
|
|
|
56
65
|
MetaMetricsSwapsEventSource["DeepLink"] = "Deep Link";
|
|
57
66
|
MetaMetricsSwapsEventSource["Unknown"] = "Unknown";
|
|
58
67
|
})(MetaMetricsSwapsEventSource || (MetaMetricsSwapsEventSource = {}));
|
|
68
|
+
export var BatchSellMetricsLocation;
|
|
69
|
+
(function (BatchSellMetricsLocation) {
|
|
70
|
+
BatchSellMetricsLocation["TradeMenu"] = "trade_menu";
|
|
71
|
+
BatchSellMetricsLocation["Deeplink"] = "deeplink";
|
|
72
|
+
BatchSellMetricsLocation["AssetPicker"] = "asset_picker";
|
|
73
|
+
BatchSellMetricsLocation["Unknown"] = "Unknown";
|
|
74
|
+
})(BatchSellMetricsLocation || (BatchSellMetricsLocation = {}));
|
|
59
75
|
export var InputAmountPreset;
|
|
60
76
|
(function (InputAmountPreset) {
|
|
61
77
|
InputAmountPreset["PERCENT_25"] = "25%";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,CAAC,MAAM,kCAAkC,GAAG,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/utils/metrics/constants.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,CAAC,MAAM,kCAAkC,GAAG,oBAAoB,CAAC;AACvE,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAN,IAAY,0BAoBX;AApBD,WAAY,0BAA0B;IACpC,iFAAsE,CAAA;IACtE,2EAAgE,CAAA;IAChE,+EAAoE,CAAA;IACpE,uGAA4F,CAAA;IAC5F,+GAAoG,CAAA;IACpG,qFAA0E,CAAA;IAC1E,mFAAwE,CAAA;IACxE,6EAAkE,C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B,wDAA4B,CAAA;IAC5B,+CAAmB,CAAA;AACrB,CAAC,EALW,wBAAwB,KAAxB,wBAAwB,QAKnC;AAMD,MAAM,CAAN,IAAY,iBAOX;AAPD,WAAY,iBAAiB;IAC3B,uCAAkB,CAAA;IAClB,uCAAkB,CAAA;IAClB,uCAAkB,CAAA;IAClB,uCAAkB,CAAA;IAClB,uEAAuE;IACvE,gCAAW,CAAA;AACb,CAAC,EAPW,iBAAiB,KAAjB,iBAAiB,QAO5B;AAED,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B;;OAEG;IACH,oDAA+B,CAAA;IAC/B,oDAA+B,CAAA;AACjC,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,4CAAyB,CAAA;AAC3B,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nexport const UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = 'Unified SwapBridge';\nexport const BATCH_SELL_EVENT_CATEGORY = 'Batch Sell';\n\n/**\n * These event names map to events defined in the segment-schema: https://github.com/Consensys/segment-schema/tree/main/libraries/events/metamask-cross-chain-swaps\n */\nexport enum UnifiedSwapBridgeEventName {\n ButtonClicked = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Button Clicked`,\n PageViewed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Page Viewed`,\n InputChanged = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Input Changed`,\n FiatCryptoToggleClicked = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Fiat Crypto Toggle Clicked`,\n InputSourceDestinationSwitched = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Source Destination Switched`,\n QuotesRequested = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Requested`,\n QuotesReceived = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Received`,\n QuotesError = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Error`,\n Submitted = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Submitted`,\n Completed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Completed`,\n Failed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Failed`,\n AllQuotesOpened = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} All Quotes Opened`,\n AllQuotesSorted = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} All Quotes Sorted`,\n QuoteSelected = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quote Selected`,\n AssetDetailTooltipClicked = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Asset Detail Tooltip Clicked`,\n QuotesValidationFailed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Failed Validation`,\n StatusValidationFailed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Status Failed Validation`,\n AssetPickerOpened = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Asset Picker Opened`,\n PollingStatusUpdated = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Polling Status Updated`,\n}\n\nexport enum BatchSellMetricsEventName {\n BatchSellTokenPageViewed = `${BATCH_SELL_EVENT_CATEGORY} Token Page Viewed`,\n BatchSellTokenPageContinueClicked = `${BATCH_SELL_EVENT_CATEGORY} Token Page Continue Clicked`,\n BatchSellQuotePageViewed = `${BATCH_SELL_EVENT_CATEGORY} Quote Page Viewed`,\n BatchSellQuotePageReviewClicked = `${BATCH_SELL_EVENT_CATEGORY} Quote Page Review Clicked`,\n BatchSellReviewModalSubmitted = `${BATCH_SELL_EVENT_CATEGORY} Review Modal Submitted`,\n}\n\nexport type BridgeControllerMetricsEventName =\n | UnifiedSwapBridgeEventName\n | BatchSellMetricsEventName;\n\nexport enum PollingStatus {\n MaxPollingReached = 'max_polling_reached',\n InvalidTransactionHash = 'invalid_transaction_hash',\n ManuallyRestarted = 'manually_restarted',\n}\n\nexport enum AbortReason {\n NewQuoteRequest = 'New Quote Request',\n QuoteRequestUpdated = 'Quote Request Updated',\n ResetState = 'Reset controller state',\n TransactionSubmitted = 'Transaction submitted',\n GaslessTxBatchFetched = 'Gasless transaction batch fetched',\n}\n\n/**\n * Identifies the entry point from which the user initiated a swap or bridge flow.\n * Included as the `location` property on every Unified SwapBridge event so\n * analytics can trace the user's origin regardless of where they are in the flow.\n */\nexport enum MetaMetricsSwapsEventSource {\n MainView = 'Main View',\n TokenView = 'Token View',\n TrendingExplore = 'Trending Explore',\n Rewards = 'Rewards',\n ActivityTabEmptyState = 'Activity Tab Empty State',\n TransactionShield = 'Transaction Shield',\n TransactionDetails = 'Transaction Details',\n DeepLink = 'Deep Link',\n Unknown = 'Unknown',\n}\n\nexport enum BatchSellMetricsLocation {\n TradeMenu = 'trade_menu',\n Deeplink = 'deeplink',\n AssetPicker = 'asset_picker',\n Unknown = 'Unknown',\n}\n\nexport type BridgeControllerMetricsLocation =\n | MetaMetricsSwapsEventSource\n | BatchSellMetricsLocation;\n\nexport enum InputAmountPreset {\n PERCENT_25 = '25%',\n PERCENT_50 = '50%',\n PERCENT_75 = '75%',\n PERCENT_90 = '90%',\n // \"Max\" may not equal 100% of balance (e.g. gas reserves are withheld)\n MAX = 'MAX',\n}\n\nexport enum MetricsActionType {\n /**\n * @deprecated new events should use SWAPBRIDGE_V1 instead\n */\n CROSSCHAIN_V1 = 'crosschain-v1',\n SWAPBRIDGE_V1 = 'swapbridge-v1',\n}\n\nexport enum MetricsSwapType {\n SINGLE = 'single_chain',\n CROSSCHAIN = 'crosschain',\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/utils/metrics/types.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { CaipAssetType, CaipChainId } from '@metamask/utils';\n\nimport type {\n FeatureId,\n InputPrimaryDenomination,\n SortOrder,\n StatusTypes,\n} from '../../types';\nimport type {\n UnifiedSwapBridgeEventName,\n MetaMetricsSwapsEventSource,\n MetricsActionType,\n MetricsSwapType,\n PollingStatus,\n} from './constants';\n\n/**\n * These properties map to properties required by the segment-schema. For example: https://github.com/Consensys/segment-schema/blob/main/libraries/properties/cross-chain-swaps-action.yaml\n */\nexport type RequestParams = {\n chain_id_source: CaipChainId;\n chain_id_destination: CaipChainId | null;\n token_symbol_source: string;\n token_symbol_destination: string | null;\n token_address_source: CaipAssetType;\n token_address_destination: CaipAssetType | null;\n /**\n * Client-supplied security classification for the destination token\n * (e.g. from token security/scanning data). Stored on the controller\n * and merged into every analytics event that includes\n * `token_address_destination`. Pass `null` when no security data is\n * available for the selected destination token.\n */\n token_security_type_destination: string | null;\n};\n\nexport type AccountHardwareType =\n | 'Ledger'\n | 'Trezor'\n | 'QR Hardware'\n | 'Lattice'\n | null;\n\nexport type RequestMetadata = {\n slippage_limit?: number; // undefined === auto\n custom_slippage: boolean;\n usd_amount_source: number; // Use quoteResponse when available\n stx_enabled: boolean;\n is_hardware_wallet: boolean;\n account_hardware_type: AccountHardwareType;\n swap_type: MetricsSwapType;\n security_warnings: string[];\n};\n\nexport type QuoteFetchData = {\n can_submit: boolean;\n best_quote_provider?: `${string}_${string}`;\n quotes_count: number;\n quotes_list: `${string}_${string}`[];\n initial_load_time_all_quotes: number;\n price_impact: number;\n has_gas_included_quote: boolean;\n};\n\nexport type TradeData = {\n usd_quoted_gas: number;\n gas_included: boolean;\n gas_included_7702: boolean;\n quoted_time_minutes: number;\n usd_quoted_return: number;\n provider: `${string}_${string}`;\n};\n\nexport type TxStatusData = {\n allowance_reset_transaction?: StatusTypes;\n approval_transaction?: StatusTypes;\n source_transaction?: StatusTypes;\n destination_transaction?: StatusTypes;\n};\n\nexport type InputPrimaryDenominationData = {\n input_primary_denomination?: InputPrimaryDenomination;\n};\n\nexport type InputKeys =\n | 'token_source'\n | 'token_destination'\n | 'chain_source'\n | 'chain_destination'\n | 'slippage'\n | 'token_amount_source';\n\nexport type InputValues = {\n token_source: CaipAssetType;\n token_destination: CaipAssetType;\n chain_source: CaipChainId;\n chain_destination: CaipChainId;\n slippage: number;\n token_amount_source: string;\n};\n\nexport type QuoteWarning =\n | 'low_return'\n | 'no_quotes'\n | 'insufficient_gas_balance'\n | 'insufficient_gas_for_selected_quote'\n | 'insufficient_balance'\n | 'market_closed'\n | 'price_impact'\n | 'quote_expired'\n | 'tx_alert';\n\n/**\n * Properties that are required to be provided when trackUnifiedSwapBridgeEvent is called.\n * This is the base type without the `location` property which is added to all events\n * via the RequiredEventContextFromClient mapped type.\n */\ntype RequiredEventContextFromClientBase = {\n [UnifiedSwapBridgeEventName.ButtonClicked]: Pick<\n RequestParams,\n 'token_symbol_source' | 'token_symbol_destination'\n > & { environment_type?: string };\n // When type is object, the payload can be anything\n [UnifiedSwapBridgeEventName.PageViewed]: object;\n [UnifiedSwapBridgeEventName.InputChanged]: {\n input:\n | 'token_source'\n | 'token_destination'\n | 'chain_source'\n | 'chain_destination'\n | 'slippage'\n | 'token_amount_source';\n input_value: InputValues[keyof InputValues];\n input_amount_preset?: string;\n };\n [UnifiedSwapBridgeEventName.FiatCryptoToggleClicked]: {\n token_symbol_source: string;\n token_symbol_destination: string | null;\n previous_primary_denomination: InputPrimaryDenomination;\n new_primary_denomination: InputPrimaryDenomination;\n chain_id_source?: RequestParams['chain_id_source'];\n chain_id_destination?: RequestParams['chain_id_destination'];\n token_address_source?: RequestParams['token_address_source'];\n token_address_destination?: RequestParams['token_address_destination'];\n token_security_type_destination?: RequestParams['token_security_type_destination'];\n swap_type?: RequestMetadata['swap_type'];\n };\n [UnifiedSwapBridgeEventName.InputSourceDestinationSwitched]: {\n token_symbol_source: RequestParams['token_symbol_source'];\n token_symbol_destination: RequestParams['token_symbol_destination'];\n token_address_source: RequestParams['token_address_source'];\n token_address_destination: RequestParams['token_address_destination'];\n token_security_type_destination: RequestParams['token_security_type_destination'];\n chain_id_source: RequestParams['chain_id_source'];\n chain_id_destination: RequestParams['chain_id_destination'];\n } & Pick<RequestMetadata, 'security_warnings'>;\n [UnifiedSwapBridgeEventName.QuotesRequested]: Pick<\n RequestMetadata,\n 'stx_enabled' | 'usd_amount_source'\n > & {\n token_symbol_source: RequestParams['token_symbol_source'];\n token_symbol_destination: RequestParams['token_symbol_destination'];\n token_security_type_destination: RequestParams['token_security_type_destination'];\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.QuotesReceived]: TradeData &\n Pick<RequestParams, 'token_symbol_source' | 'token_symbol_destination'> &\n InputPrimaryDenominationData & {\n warnings: QuoteWarning[];\n best_quote_provider: QuoteFetchData['best_quote_provider'];\n price_impact: QuoteFetchData['price_impact'];\n can_submit: QuoteFetchData['can_submit'];\n usd_balance_source?: number;\n has_sufficient_gas_for_quote?: boolean | null;\n };\n [UnifiedSwapBridgeEventName.QuotesError]: Pick<\n RequestMetadata,\n 'stx_enabled'\n > & {\n token_symbol_source: RequestParams['token_symbol_source'];\n token_symbol_destination: RequestParams['token_symbol_destination'];\n } & Pick<RequestMetadata, 'security_warnings'>;\n // Emitted by BridgeStatusController\n [UnifiedSwapBridgeEventName.Submitted]: TradeData &\n Pick<QuoteFetchData, 'price_impact'> &\n Omit<RequestMetadata, 'security_warnings'> &\n Pick<\n RequestParams,\n | 'token_symbol_source'\n | 'token_symbol_destination'\n | 'token_address_source'\n | 'token_address_destination'\n | 'chain_id_source'\n | 'chain_id_destination'\n | 'token_security_type_destination'\n > & {\n action_type: MetricsActionType;\n batch_id?: string;\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.Completed]: TradeData &\n Pick<QuoteFetchData, 'price_impact'> &\n Omit<RequestMetadata, 'security_warnings'> &\n TxStatusData &\n RequestParams & {\n actual_time_minutes: number;\n usd_actual_return: number;\n usd_actual_gas: number;\n quote_vs_execution_ratio: number;\n quoted_vs_used_gas_ratio: number;\n action_type: MetricsActionType;\n batch_id?: string;\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.Failed]: (\n | // Tx failed before confirmation\n (Pick<\n RequestMetadata,\n | 'stx_enabled'\n | 'usd_amount_source'\n | 'is_hardware_wallet'\n | 'account_hardware_type'\n > &\n Pick<\n RequestParams,\n | 'token_symbol_source'\n | 'token_symbol_destination'\n | 'token_address_source'\n | 'token_address_destination'\n | 'token_security_type_destination'\n >)\n // Tx failed after confirmation\n | (RequestParams &\n RequestMetadata &\n TxStatusData & {\n actual_time_minutes: number;\n })\n ) &\n TradeData &\n Pick<QuoteFetchData, 'price_impact'> & {\n error_message: string;\n batch_id?: string;\n };\n [UnifiedSwapBridgeEventName.PollingStatusUpdated]: {\n polling_status: PollingStatus;\n retry_attempts: number;\n };\n [UnifiedSwapBridgeEventName.StatusValidationFailed]: {\n failures: string[];\n refresh_count: number;\n } & Partial<RequestParams>;\n // Emitted by clients\n [UnifiedSwapBridgeEventName.AllQuotesOpened]: Pick<\n TradeData,\n 'gas_included'\n > &\n Pick<QuoteFetchData, 'price_impact'> &\n Pick<RequestParams, 'token_symbol_source' | 'token_symbol_destination'> & {\n stx_enabled: RequestMetadata['stx_enabled'];\n can_submit: QuoteFetchData['can_submit'];\n };\n [UnifiedSwapBridgeEventName.AllQuotesSorted]: Pick<\n TradeData,\n 'gas_included'\n > &\n Pick<QuoteFetchData, 'price_impact'> &\n Pick<RequestParams, 'token_symbol_source' | 'token_symbol_destination'> & {\n stx_enabled: RequestMetadata['stx_enabled'];\n sort_order: SortOrder;\n best_quote_provider: QuoteFetchData['best_quote_provider'];\n can_submit: QuoteFetchData['can_submit'];\n };\n [UnifiedSwapBridgeEventName.QuoteSelected]: TradeData & {\n is_best_quote: boolean;\n best_quote_provider: QuoteFetchData['best_quote_provider'];\n price_impact: QuoteFetchData['price_impact'];\n can_submit: QuoteFetchData['can_submit'];\n };\n [UnifiedSwapBridgeEventName.AssetDetailTooltipClicked]: {\n token_name: string;\n token_symbol: string;\n token_contract: string;\n chain_name: string;\n chain_id: string;\n };\n [UnifiedSwapBridgeEventName.QuotesValidationFailed]: {\n failures: string[];\n };\n [UnifiedSwapBridgeEventName.AssetPickerOpened]: {\n asset_location: 'source' | 'destination';\n };\n};\n\n/**\n * Properties that are required to be provided when trackUnifiedSwapBridgeEvent is called.\n * This combines the event-specific properties from RequiredEventContextFromClientBase\n * with an optional `location` property. When `location` is omitted, the controller\n * falls back to the value stored via `setLocation()` (defaults to Unknown).\n *\n * `ab_tests` is the legacy field and `active_ab_tests` is the newer field.\n * Both are kept for a migration window and are treated as separate payloads.\n */\nexport type RequiredEventContextFromClient = {\n [K in keyof RequiredEventContextFromClientBase]: RequiredEventContextFromClientBase[K] & {\n location?: MetaMetricsSwapsEventSource;\n ab_tests?: Record<string, string>;\n active_ab_tests?: { key: string; value: string }[];\n feature_id: FeatureId;\n };\n};\n\n/**\n * Properties that can be derived from the bridge controller state\n */\nexport type EventPropertiesFromControllerState = {\n [UnifiedSwapBridgeEventName.ButtonClicked]: RequestParams;\n [UnifiedSwapBridgeEventName.PageViewed]: RequestParams &\n Omit<\n RequestMetadata,\n 'stx_enabled' | 'usd_amount_source' | 'security_warnings'\n > &\n InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.InputChanged]: {\n input: InputKeys;\n input_value: string;\n };\n [UnifiedSwapBridgeEventName.FiatCryptoToggleClicked]: RequestParams &\n Pick<RequestMetadata, 'swap_type'>;\n [UnifiedSwapBridgeEventName.InputSourceDestinationSwitched]: RequestParams;\n [UnifiedSwapBridgeEventName.QuotesRequested]: RequestParams &\n RequestMetadata & {\n has_sufficient_funds: boolean;\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.QuotesReceived]: RequestParams &\n RequestMetadata &\n QuoteFetchData &\n TradeData & {\n refresh_count: number; // starts from 0\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.QuotesError]: RequestParams &\n RequestMetadata & {\n has_sufficient_funds: boolean;\n error_message: string;\n };\n [UnifiedSwapBridgeEventName.Submitted]: null;\n [UnifiedSwapBridgeEventName.Completed]: null;\n [UnifiedSwapBridgeEventName.Failed]: RequestParams &\n RequestMetadata &\n TxStatusData &\n TradeData &\n Pick<QuoteFetchData, 'price_impact'> & {\n actual_time_minutes: number;\n };\n [UnifiedSwapBridgeEventName.AllQuotesOpened]: RequestParams &\n RequestMetadata &\n TradeData &\n QuoteFetchData;\n [UnifiedSwapBridgeEventName.AllQuotesSorted]: RequestParams &\n RequestMetadata &\n TradeData &\n QuoteFetchData;\n [UnifiedSwapBridgeEventName.QuoteSelected]: RequestParams &\n RequestMetadata &\n QuoteFetchData &\n TradeData;\n [UnifiedSwapBridgeEventName.AssetDetailTooltipClicked]: null;\n [UnifiedSwapBridgeEventName.QuotesValidationFailed]: RequestParams & {\n refresh_count: number;\n };\n [UnifiedSwapBridgeEventName.StatusValidationFailed]: RequestParams;\n [UnifiedSwapBridgeEventName.AssetPickerOpened]: null;\n [UnifiedSwapBridgeEventName.PollingStatusUpdated]: TradeData &\n Pick<QuoteFetchData, 'price_impact'> &\n Omit<RequestMetadata, 'security_warnings'> &\n Pick<\n RequestParams,\n | 'token_symbol_source'\n | 'token_symbol_destination'\n | 'chain_id_source'\n | 'chain_id_destination'\n > & {\n batch_id?: string;\n };\n};\n\n/**\n * trackUnifiedSwapBridgeEvent payload properties consist of required properties from the client\n * and properties from the bridge controller\n *\n * `ab_tests` will be deprecated in favor of `active_ab_tests` in the future.\n * `ab_tests` and `active_ab_tests` intentionally coexist during migration.\n */\nexport type CrossChainSwapsEventProperties<\n T extends UnifiedSwapBridgeEventName,\n> =\n | {\n feature_id: FeatureId;\n action_type: MetricsActionType;\n location: MetaMetricsSwapsEventSource;\n ab_tests?: Record<string, string>;\n active_ab_tests?: { key: string; value: string }[];\n }\n | Pick<EventPropertiesFromControllerState, T>[T]\n | Pick<RequiredEventContextFromClient, T>[T];\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/utils/metrics/types.ts"],"names":[],"mappings":"","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { CaipAssetType, CaipChainId } from '@metamask/utils';\n\nimport type {\n FeatureId,\n InputPrimaryDenomination,\n SortOrder,\n StatusTypes,\n} from '../../types';\nimport type {\n UnifiedSwapBridgeEventName,\n BatchSellMetricsEventName,\n BatchSellMetricsLocation,\n BridgeControllerMetricsEventName,\n BridgeControllerMetricsLocation,\n MetricsActionType,\n MetricsSwapType,\n PollingStatus,\n} from './constants';\n\n/**\n * These properties map to properties required by the segment-schema. For example: https://github.com/Consensys/segment-schema/blob/main/libraries/properties/cross-chain-swaps-action.yaml\n */\nexport type RequestParams = {\n chain_id_source: CaipChainId;\n chain_id_destination: CaipChainId | null;\n token_symbol_source: string;\n token_symbol_destination: string | null;\n token_address_source: CaipAssetType;\n token_address_destination: CaipAssetType | null;\n /**\n * Client-supplied security classification for the destination token\n * (e.g. from token security/scanning data). Stored on the controller\n * and merged into every analytics event that includes\n * `token_address_destination`. Pass `null` when no security data is\n * available for the selected destination token.\n */\n token_security_type_destination: string | null;\n};\n\nexport type AccountHardwareType =\n | 'Ledger'\n | 'Trezor'\n | 'QR Hardware'\n | 'Lattice'\n | null;\n\nexport type RequestMetadata = {\n slippage_limit?: number; // undefined === auto\n custom_slippage: boolean;\n usd_amount_source: number; // Use quoteResponse when available\n stx_enabled: boolean;\n is_hardware_wallet: boolean;\n account_hardware_type: AccountHardwareType;\n swap_type: MetricsSwapType;\n security_warnings: string[];\n};\n\nexport type QuoteFetchData = {\n can_submit: boolean;\n best_quote_provider?: `${string}_${string}`;\n quotes_count: number;\n quotes_list: `${string}_${string}`[];\n initial_load_time_all_quotes: number;\n price_impact: number;\n has_gas_included_quote: boolean;\n};\n\nexport type TradeData = {\n usd_quoted_gas: number;\n gas_included: boolean;\n gas_included_7702: boolean;\n quoted_time_minutes: number;\n usd_quoted_return: number;\n provider: `${string}_${string}`;\n};\n\nexport type TxStatusData = {\n allowance_reset_transaction?: StatusTypes;\n approval_transaction?: StatusTypes;\n source_transaction?: StatusTypes;\n destination_transaction?: StatusTypes;\n};\n\nexport type InputPrimaryDenominationData = {\n input_primary_denomination?: InputPrimaryDenomination;\n};\n\nexport type InputKeys =\n | 'token_source'\n | 'token_destination'\n | 'chain_source'\n | 'chain_destination'\n | 'slippage'\n | 'token_amount_source';\n\nexport type InputValues = {\n token_source: CaipAssetType;\n token_destination: CaipAssetType;\n chain_source: CaipChainId;\n chain_destination: CaipChainId;\n slippage: number;\n token_amount_source: string;\n};\n\nexport type QuoteWarning =\n | 'low_return'\n | 'no_quotes'\n | 'insufficient_gas_balance'\n | 'insufficient_gas_for_selected_quote'\n | 'insufficient_balance'\n | 'market_closed'\n | 'price_impact'\n | 'quote_expired'\n | 'tx_alert';\n\ntype BatchSellChainProperties = {\n chain_id_source: CaipChainId;\n chain_id_destination: CaipChainId | null;\n};\n\ntype BatchSellTokenPageEventContext = BatchSellChainProperties & {\n location: BatchSellMetricsLocation;\n};\n\ntype BatchSellSourceTokenEventContext = BatchSellTokenPageEventContext & {\n source_token_symbols: string[];\n source_token_addresses: CaipAssetType[];\n};\n\ntype BatchSellQuotePageEventContext = BatchSellSourceTokenEventContext & {\n destination_token_symbol: string;\n destination_token_address: CaipAssetType;\n usd_amount_source_tokens: number[];\n usd_amount_source_total: number;\n source_token_slippages: number[];\n};\n\ntype BatchSellReviewModalSubmittedEventContext =\n BatchSellQuotePageEventContext &\n Pick<TradeData, 'usd_quoted_gas' | 'usd_quoted_return'>;\n\ntype BatchSellTokenPageEventProperties = BatchSellChainProperties &\n BatchSellTokenPageEventContext;\n\ntype BatchSellSourceTokenEventProperties = BatchSellChainProperties &\n BatchSellSourceTokenEventContext & {\n source_token_count: number;\n };\n\ntype BatchSellQuotePageEventProperties = BatchSellChainProperties &\n BatchSellQuotePageEventContext & {\n source_token_count: number;\n };\n\ntype BatchSellReviewModalSubmittedEventProperties = BatchSellChainProperties &\n BatchSellReviewModalSubmittedEventContext & {\n source_token_count: number;\n };\n\ntype SharedEventContextFromClient = {\n ab_tests?: Record<string, string>;\n active_ab_tests?: { key: string; value: string }[];\n feature_id: FeatureId;\n};\n\ntype OptionalLocationContextFromClient<T> = T extends {\n location: unknown;\n}\n ? object\n : { location?: BridgeControllerMetricsLocation };\n\n/**\n * Properties that are required to be provided when trackUnifiedSwapBridgeEvent is called.\n * Most events receive an optional location via RequiredEventContextFromClient;\n * Batch Sell events define their own required location enum.\n */\ntype RequiredEventContextFromClientBase = {\n [UnifiedSwapBridgeEventName.ButtonClicked]: Pick<\n RequestParams,\n 'token_symbol_source' | 'token_symbol_destination'\n > & { environment_type?: string };\n // When type is object, the payload can be anything\n [UnifiedSwapBridgeEventName.PageViewed]: object;\n [UnifiedSwapBridgeEventName.InputChanged]: {\n input:\n | 'token_source'\n | 'token_destination'\n | 'chain_source'\n | 'chain_destination'\n | 'slippage'\n | 'token_amount_source';\n input_value: InputValues[keyof InputValues];\n input_amount_preset?: string;\n };\n [UnifiedSwapBridgeEventName.FiatCryptoToggleClicked]: {\n token_symbol_source: string;\n token_symbol_destination: string | null;\n previous_primary_denomination: InputPrimaryDenomination;\n new_primary_denomination: InputPrimaryDenomination;\n chain_id_source?: RequestParams['chain_id_source'];\n chain_id_destination?: RequestParams['chain_id_destination'];\n token_address_source?: RequestParams['token_address_source'];\n token_address_destination?: RequestParams['token_address_destination'];\n token_security_type_destination?: RequestParams['token_security_type_destination'];\n swap_type?: RequestMetadata['swap_type'];\n };\n [UnifiedSwapBridgeEventName.InputSourceDestinationSwitched]: {\n token_symbol_source: RequestParams['token_symbol_source'];\n token_symbol_destination: RequestParams['token_symbol_destination'];\n token_address_source: RequestParams['token_address_source'];\n token_address_destination: RequestParams['token_address_destination'];\n token_security_type_destination: RequestParams['token_security_type_destination'];\n chain_id_source: RequestParams['chain_id_source'];\n chain_id_destination: RequestParams['chain_id_destination'];\n } & Pick<RequestMetadata, 'security_warnings'>;\n [UnifiedSwapBridgeEventName.QuotesRequested]: Pick<\n RequestMetadata,\n 'stx_enabled' | 'usd_amount_source'\n > & {\n token_symbol_source: RequestParams['token_symbol_source'];\n token_symbol_destination: RequestParams['token_symbol_destination'];\n token_security_type_destination: RequestParams['token_security_type_destination'];\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.QuotesReceived]: TradeData &\n Pick<RequestParams, 'token_symbol_source' | 'token_symbol_destination'> &\n InputPrimaryDenominationData & {\n warnings: QuoteWarning[];\n best_quote_provider: QuoteFetchData['best_quote_provider'];\n price_impact: QuoteFetchData['price_impact'];\n can_submit: QuoteFetchData['can_submit'];\n usd_balance_source?: number;\n has_sufficient_gas_for_quote?: boolean | null;\n };\n [UnifiedSwapBridgeEventName.QuotesError]: Pick<\n RequestMetadata,\n 'stx_enabled'\n > & {\n token_symbol_source: RequestParams['token_symbol_source'];\n token_symbol_destination: RequestParams['token_symbol_destination'];\n } & Pick<RequestMetadata, 'security_warnings'>;\n // Emitted by BridgeStatusController\n [UnifiedSwapBridgeEventName.Submitted]: TradeData &\n Pick<QuoteFetchData, 'price_impact'> &\n Omit<RequestMetadata, 'security_warnings'> &\n Pick<\n RequestParams,\n | 'token_symbol_source'\n | 'token_symbol_destination'\n | 'token_address_source'\n | 'token_address_destination'\n | 'chain_id_source'\n | 'chain_id_destination'\n | 'token_security_type_destination'\n > & {\n action_type: MetricsActionType;\n batch_id?: string;\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.Completed]: TradeData &\n Pick<QuoteFetchData, 'price_impact'> &\n Omit<RequestMetadata, 'security_warnings'> &\n TxStatusData &\n RequestParams & {\n actual_time_minutes: number;\n usd_actual_return: number;\n usd_actual_gas: number;\n quote_vs_execution_ratio: number;\n quoted_vs_used_gas_ratio: number;\n action_type: MetricsActionType;\n batch_id?: string;\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.Failed]: (\n | // Tx failed before confirmation\n (Pick<\n RequestMetadata,\n | 'stx_enabled'\n | 'usd_amount_source'\n | 'is_hardware_wallet'\n | 'account_hardware_type'\n > &\n Pick<\n RequestParams,\n | 'token_symbol_source'\n | 'token_symbol_destination'\n | 'token_address_source'\n | 'token_address_destination'\n | 'token_security_type_destination'\n >)\n // Tx failed after confirmation\n | (RequestParams &\n RequestMetadata &\n TxStatusData & {\n actual_time_minutes: number;\n })\n ) &\n TradeData &\n Pick<QuoteFetchData, 'price_impact'> & {\n error_message: string;\n batch_id?: string;\n };\n [UnifiedSwapBridgeEventName.PollingStatusUpdated]: {\n polling_status: PollingStatus;\n retry_attempts: number;\n };\n [UnifiedSwapBridgeEventName.StatusValidationFailed]: {\n failures: string[];\n refresh_count: number;\n } & Partial<RequestParams>;\n // Emitted by clients\n [UnifiedSwapBridgeEventName.AllQuotesOpened]: Pick<\n TradeData,\n 'gas_included'\n > &\n Pick<QuoteFetchData, 'price_impact'> &\n Pick<RequestParams, 'token_symbol_source' | 'token_symbol_destination'> & {\n stx_enabled: RequestMetadata['stx_enabled'];\n can_submit: QuoteFetchData['can_submit'];\n };\n [UnifiedSwapBridgeEventName.AllQuotesSorted]: Pick<\n TradeData,\n 'gas_included'\n > &\n Pick<QuoteFetchData, 'price_impact'> &\n Pick<RequestParams, 'token_symbol_source' | 'token_symbol_destination'> & {\n stx_enabled: RequestMetadata['stx_enabled'];\n sort_order: SortOrder;\n best_quote_provider: QuoteFetchData['best_quote_provider'];\n can_submit: QuoteFetchData['can_submit'];\n };\n [UnifiedSwapBridgeEventName.QuoteSelected]: TradeData & {\n is_best_quote: boolean;\n best_quote_provider: QuoteFetchData['best_quote_provider'];\n price_impact: QuoteFetchData['price_impact'];\n can_submit: QuoteFetchData['can_submit'];\n };\n [UnifiedSwapBridgeEventName.AssetDetailTooltipClicked]: {\n token_name: string;\n token_symbol: string;\n token_contract: string;\n chain_name: string;\n chain_id: string;\n };\n [UnifiedSwapBridgeEventName.QuotesValidationFailed]: {\n failures: string[];\n };\n [UnifiedSwapBridgeEventName.AssetPickerOpened]: {\n asset_location: 'source' | 'destination';\n };\n [BatchSellMetricsEventName.BatchSellTokenPageViewed]: BatchSellTokenPageEventContext;\n [BatchSellMetricsEventName.BatchSellTokenPageContinueClicked]: BatchSellSourceTokenEventContext;\n [BatchSellMetricsEventName.BatchSellQuotePageViewed]: BatchSellQuotePageEventContext;\n [BatchSellMetricsEventName.BatchSellQuotePageReviewClicked]: BatchSellQuotePageEventContext;\n [BatchSellMetricsEventName.BatchSellReviewModalSubmitted]: BatchSellReviewModalSubmittedEventContext;\n};\n\n/**\n * Properties that are required to be provided when trackUnifiedSwapBridgeEvent is called.\n * This combines the event-specific properties from RequiredEventContextFromClientBase\n * with an optional `location` property. When `location` is omitted, the controller\n * falls back to the value stored via `setLocation()` (defaults to Unknown).\n *\n * `ab_tests` is the legacy field and `active_ab_tests` is the newer field.\n * Both are kept for a migration window and are treated as separate payloads.\n */\nexport type RequiredEventContextFromClient = {\n [K in keyof RequiredEventContextFromClientBase]: K extends BatchSellMetricsEventName\n ? RequiredEventContextFromClientBase[K]\n : RequiredEventContextFromClientBase[K] &\n OptionalLocationContextFromClient<\n RequiredEventContextFromClientBase[K]\n > &\n SharedEventContextFromClient;\n};\n\n/**\n * Properties that can be derived from the bridge controller state\n */\nexport type EventPropertiesFromControllerState = {\n [UnifiedSwapBridgeEventName.ButtonClicked]: RequestParams;\n [UnifiedSwapBridgeEventName.PageViewed]: RequestParams &\n Omit<\n RequestMetadata,\n 'stx_enabled' | 'usd_amount_source' | 'security_warnings'\n > &\n InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.InputChanged]: {\n input: InputKeys;\n input_value: string;\n };\n [UnifiedSwapBridgeEventName.FiatCryptoToggleClicked]: RequestParams &\n Pick<RequestMetadata, 'swap_type'>;\n [UnifiedSwapBridgeEventName.InputSourceDestinationSwitched]: RequestParams;\n [UnifiedSwapBridgeEventName.QuotesRequested]: RequestParams &\n RequestMetadata & {\n has_sufficient_funds: boolean;\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.QuotesReceived]: RequestParams &\n RequestMetadata &\n QuoteFetchData &\n TradeData & {\n refresh_count: number; // starts from 0\n } & InputPrimaryDenominationData;\n [UnifiedSwapBridgeEventName.QuotesError]: RequestParams &\n RequestMetadata & {\n has_sufficient_funds: boolean;\n error_message: string;\n };\n [UnifiedSwapBridgeEventName.Submitted]: null;\n [UnifiedSwapBridgeEventName.Completed]: null;\n [UnifiedSwapBridgeEventName.Failed]: RequestParams &\n RequestMetadata &\n TxStatusData &\n TradeData &\n Pick<QuoteFetchData, 'price_impact'> & {\n actual_time_minutes: number;\n };\n [UnifiedSwapBridgeEventName.AllQuotesOpened]: RequestParams &\n RequestMetadata &\n TradeData &\n QuoteFetchData;\n [UnifiedSwapBridgeEventName.AllQuotesSorted]: RequestParams &\n RequestMetadata &\n TradeData &\n QuoteFetchData;\n [UnifiedSwapBridgeEventName.QuoteSelected]: RequestParams &\n RequestMetadata &\n QuoteFetchData &\n TradeData;\n [UnifiedSwapBridgeEventName.AssetDetailTooltipClicked]: null;\n [UnifiedSwapBridgeEventName.QuotesValidationFailed]: RequestParams & {\n refresh_count: number;\n };\n [UnifiedSwapBridgeEventName.StatusValidationFailed]: RequestParams;\n [UnifiedSwapBridgeEventName.AssetPickerOpened]: null;\n [UnifiedSwapBridgeEventName.PollingStatusUpdated]: TradeData &\n Pick<QuoteFetchData, 'price_impact'> &\n Omit<RequestMetadata, 'security_warnings'> &\n Pick<\n RequestParams,\n | 'token_symbol_source'\n | 'token_symbol_destination'\n | 'chain_id_source'\n | 'chain_id_destination'\n > & {\n batch_id?: string;\n };\n [BatchSellMetricsEventName.BatchSellTokenPageViewed]: BatchSellTokenPageEventProperties;\n [BatchSellMetricsEventName.BatchSellTokenPageContinueClicked]: BatchSellSourceTokenEventProperties;\n [BatchSellMetricsEventName.BatchSellQuotePageViewed]: BatchSellQuotePageEventProperties;\n [BatchSellMetricsEventName.BatchSellQuotePageReviewClicked]: BatchSellQuotePageEventProperties;\n [BatchSellMetricsEventName.BatchSellReviewModalSubmitted]: BatchSellReviewModalSubmittedEventProperties;\n};\n\ntype SharedCrossChainSwapsEventProperties<\n T extends BridgeControllerMetricsEventName,\n> =\n | {\n feature_id: FeatureId;\n action_type: MetricsActionType;\n location: BridgeControllerMetricsLocation;\n ab_tests?: Record<string, string>;\n active_ab_tests?: { key: string; value: string }[];\n }\n | Pick<EventPropertiesFromControllerState, T>[T]\n | Pick<RequiredEventContextFromClient, T>[T];\n\n/**\n * trackUnifiedSwapBridgeEvent payload properties consist of required properties from the client\n * and properties from the bridge controller\n *\n * `ab_tests` will be deprecated in favor of `active_ab_tests` in the future.\n * `ab_tests` and `active_ab_tests` intentionally coexist during migration.\n */\nexport type CrossChainSwapsEventProperties<\n T extends BridgeControllerMetricsEventName,\n> = T extends BatchSellMetricsEventName\n ? Pick<EventPropertiesFromControllerState, T>[T]\n : SharedCrossChainSwapsEventProperties<T>;\n"]}
|