@metamask-previews/bridge-controller 22.0.0-preview-88c4fb60 → 24.0.0-preview-a578ea2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/bridge-controller.cjs +36 -25
  3. package/dist/bridge-controller.cjs.map +1 -1
  4. package/dist/bridge-controller.d.cts +3 -2
  5. package/dist/bridge-controller.d.cts.map +1 -1
  6. package/dist/bridge-controller.d.mts +3 -2
  7. package/dist/bridge-controller.d.mts.map +1 -1
  8. package/dist/bridge-controller.mjs +37 -26
  9. package/dist/bridge-controller.mjs.map +1 -1
  10. package/dist/constants/traces.cjs +9 -0
  11. package/dist/constants/traces.cjs.map +1 -0
  12. package/dist/constants/traces.d.cts +5 -0
  13. package/dist/constants/traces.d.cts.map +1 -0
  14. package/dist/constants/traces.d.mts +5 -0
  15. package/dist/constants/traces.d.mts.map +1 -0
  16. package/dist/constants/traces.mjs +6 -0
  17. package/dist/constants/traces.mjs.map +1 -0
  18. package/dist/index.cjs +3 -2
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +2 -2
  21. package/dist/index.d.cts.map +1 -1
  22. package/dist/index.d.mts +2 -2
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +1 -1
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/utils/bridge.cjs +20 -1
  27. package/dist/utils/bridge.cjs.map +1 -1
  28. package/dist/utils/bridge.d.cts +9 -1
  29. package/dist/utils/bridge.d.cts.map +1 -1
  30. package/dist/utils/bridge.d.mts +9 -1
  31. package/dist/utils/bridge.d.mts.map +1 -1
  32. package/dist/utils/bridge.mjs +18 -0
  33. package/dist/utils/bridge.mjs.map +1 -1
  34. package/dist/utils/metrics/properties.cjs +2 -6
  35. package/dist/utils/metrics/properties.cjs.map +1 -1
  36. package/dist/utils/metrics/properties.d.cts.map +1 -1
  37. package/dist/utils/metrics/properties.d.mts.map +1 -1
  38. package/dist/utils/metrics/properties.mjs +3 -7
  39. package/dist/utils/metrics/properties.mjs.map +1 -1
  40. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-controller.mjs","sourceRoot":"","sources":["../src/bridge-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AACpD,OAAO,EAAE,YAAY,EAAE,iCAAiC;AAGxD,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EAAE,QAAQ,EAAE,oCAAoC;AAEvD,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAG/E,OAAO,EAAE,WAAW,EAAY,wBAAwB;AAExD,OAAO,EAEL,sBAAsB,EACtB,wBAAwB,EACxB,+BAA+B,EAC/B,+BAA+B,EAC/B,mBAAmB,EACpB,+BAA2B;AAC5B,OAAO,EAAE,SAAS,EAAE,+BAA2B;AAC/C,OAAO,EAAE,gCAAgC,EAAE,wBAAoB;AAE/D,OAAO,EASL,aAAa,EACd,oBAAgB;AACjB,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,2BAAuB;AACtE,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AACvD,OAAO,EACL,+BAA+B,EAC/B,eAAe,EACf,QAAQ,EACT,2BAAuB;AACxB,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,EACnB,kBAAkB,EACnB,oCAAgC;AACjC,OAAO,EAAE,qBAAqB,EAAE,kCAA8B;AAC9D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,0BAAsB;AACpE,OAAO,EAAE,0BAA0B,EAAE,sCAAkC;AACvE,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,2BAA2B,EAC5B,uCAAmC;AAQpC,OAAO,EAAE,mBAAmB,EAAE,0BAAsB;AAEpD,MAAM,QAAQ,GAAy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AAa,EACtC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3B,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,sBAAsB,0BAA0B,EACnD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CACxC,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,sBAAsB,8BAA8B,EACvD,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC5C,CAAC;IACJ,CAAC;CA2kBF;;IA3MG,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAC9B,iDAAiD,CAClD,CAAC;AACJ,CAAC;IAGC,MAAM,EAAE,uBAAuB,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC3D,4BAA4B,CAC7B,CAAC;IACF,OAAO,uBAAuB,CAAC;AACjC,CAAC;IAGC,MAAM,uBAAuB,GAAG,uBAAA,IAAI,iFAA4B,MAAhC,IAAI,CAA8B,CAAC;IACnE,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;IACF,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { StateMetadata } from '@metamask/base-controller';\nimport type { ChainId } from '@metamask/controller-utils';\nimport { SolScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport type { CaipAssetType } from '@metamask/utils';\nimport { numberToHex, type Hex } from '@metamask/utils';\n\nimport {\n type BridgeClientId,\n BRIDGE_CONTROLLER_NAME,\n BRIDGE_PROD_API_BASE_URL,\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP,\n REFRESH_INTERVAL_MS,\n} from './constants/bridge';\nimport { CHAIN_IDS } from './constants/chains';\nimport { selectIsAssetExchangeRateInState } from './selectors';\nimport type { QuoteRequest } from './types';\nimport {\n type L1GasFees,\n type GenericQuoteRequest,\n type SolanaFees,\n type QuoteResponse,\n type TxData,\n type BridgeControllerState,\n type BridgeControllerMessenger,\n type FetchFunction,\n RequestStatus,\n} from './types';\nimport { getAssetIdsForToken, toExchangeRates } from './utils/assets';\nimport { hasSufficientBalance } from './utils/balance';\nimport {\n getDefaultBridgeControllerState,\n isSolanaChainId,\n sumHexes,\n} from './utils/bridge';\nimport {\n formatAddressToCaipReference,\n formatChainIdToCaip,\n formatChainIdToHex,\n} from './utils/caip-formatters';\nimport { getBridgeFeatureFlags } from './utils/feature-flags';\nimport { fetchAssetPrices, fetchBridgeQuotes } from './utils/fetch';\nimport { UnifiedSwapBridgeEventName } from './utils/metrics/constants';\nimport {\n formatProviderLabel,\n getActionTypeFromQuoteRequest,\n getRequestParams,\n getSwapTypeFromQuote,\n isCustomSlippage,\n isHardwareWallet,\n toInputChangedPropertyKey,\n toInputChangedPropertyValue,\n} from './utils/metrics/properties';\nimport type {\n QuoteFetchData,\n RequestMetadata,\n RequestParams,\n RequiredEventContextFromClient,\n} from './utils/metrics/types';\nimport { type CrossChainSwapsEventProperties } from './utils/metrics/types';\nimport { isValidQuoteRequest } from './utils/quote';\n\nconst metadata: StateMetadata<BridgeControllerState> = {\n quoteRequest: {\n persist: false,\n anonymous: false,\n },\n quotes: {\n persist: false,\n anonymous: false,\n },\n quotesInitialLoadTime: {\n persist: false,\n anonymous: false,\n },\n quotesLastFetched: {\n persist: false,\n anonymous: false,\n },\n quotesLoadingStatus: {\n persist: false,\n anonymous: false,\n },\n quoteFetchError: {\n persist: false,\n anonymous: false,\n },\n quotesRefreshCount: {\n persist: false,\n anonymous: false,\n },\n assetExchangeRates: {\n persist: false,\n anonymous: false,\n },\n};\n\nconst RESET_STATE_ABORT_MESSAGE = 'Reset controller state';\n\n/**\n * The input to start polling for the {@link BridgeController}\n *\n * @param networkClientId - The network client ID of the selected network\n * @param updatedQuoteRequest - The updated quote request\n * @param context - The context contains properties that can't be populated by the\n * controller and need to be provided by the client for analytics\n */\ntype BridgePollingInput = {\n networkClientId: NetworkClientId;\n updatedQuoteRequest: GenericQuoteRequest;\n context: Pick<\n RequiredEventContextFromClient,\n UnifiedSwapBridgeEventName.QuoteError\n >[UnifiedSwapBridgeEventName.QuoteError] &\n Pick<\n RequiredEventContextFromClient,\n UnifiedSwapBridgeEventName.QuotesRequested\n >[UnifiedSwapBridgeEventName.QuotesRequested];\n};\n\nexport class BridgeController extends StaticIntervalPollingController<BridgePollingInput>()<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState,\n BridgeControllerMessenger\n> {\n #abortController: AbortController | undefined;\n\n #quotesFirstFetched: number | undefined;\n\n readonly #clientId: string;\n\n readonly #getLayer1GasFee: (params: {\n transactionParams: TransactionParams;\n chainId: ChainId;\n }) => Promise<string>;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #trackMetaMetricsFn: <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n properties: CrossChainSwapsEventProperties<T>,\n ) => void;\n\n readonly #config: {\n customBridgeApiBaseUrl?: string;\n };\n\n constructor({\n messenger,\n state,\n clientId,\n getLayer1GasFee,\n fetchFn,\n config,\n trackMetaMetricsFn,\n }: {\n messenger: BridgeControllerMessenger;\n state?: Partial<BridgeControllerState>;\n clientId: BridgeClientId;\n getLayer1GasFee: (params: {\n transactionParams: TransactionParams;\n chainId: ChainId;\n }) => Promise<string>;\n fetchFn: FetchFunction;\n config?: {\n customBridgeApiBaseUrl?: string;\n };\n trackMetaMetricsFn: <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n properties: CrossChainSwapsEventProperties<T>,\n ) => void;\n }) {\n super({\n name: BRIDGE_CONTROLLER_NAME,\n metadata,\n messenger,\n state: {\n ...getDefaultBridgeControllerState(),\n ...state,\n },\n });\n\n this.setIntervalLength(REFRESH_INTERVAL_MS);\n\n this.#abortController = new AbortController();\n this.#getLayer1GasFee = getLayer1GasFee;\n this.#clientId = clientId;\n this.#fetchFn = fetchFn;\n this.#trackMetaMetricsFn = trackMetaMetricsFn;\n this.#config = config ?? {};\n\n // Register action handlers\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:setChainIntervalLength`,\n this.setChainIntervalLength.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:updateBridgeQuoteRequestParams`,\n this.updateBridgeQuoteRequestParams.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:resetState`,\n this.resetState.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:getBridgeERC20Allowance`,\n this.getBridgeERC20Allowance.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:trackUnifiedSwapBridgeEvent`,\n this.trackUnifiedSwapBridgeEvent.bind(this),\n );\n }\n\n _executePoll = async (pollingInput: BridgePollingInput) => {\n await this.#fetchBridgeQuotes(pollingInput);\n };\n\n updateBridgeQuoteRequestParams = async (\n paramsToUpdate: Partial<GenericQuoteRequest>,\n context: BridgePollingInput['context'],\n ) => {\n this.stopAllPolling();\n this.#abortController?.abort('Quote request updated');\n\n this.#trackInputChangedEvents(paramsToUpdate);\n\n const updatedQuoteRequest = {\n ...DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest,\n ...paramsToUpdate,\n };\n\n this.update((state) => {\n state.quoteRequest = updatedQuoteRequest;\n state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;\n state.quotesLastFetched =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLastFetched;\n state.quotesLoadingStatus =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLoadingStatus;\n state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;\n state.quotesRefreshCount =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount;\n state.quotesInitialLoadTime =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;\n });\n\n await this.#fetchAssetExchangeRates(updatedQuoteRequest).catch((error) =>\n console.warn('Failed to fetch asset exchange rates', error),\n );\n\n if (isValidQuoteRequest(updatedQuoteRequest)) {\n this.#quotesFirstFetched = Date.now();\n const providerConfig = this.#getSelectedNetworkClient()?.configuration;\n\n let insufficientBal: boolean | undefined;\n if (isSolanaChainId(updatedQuoteRequest.srcChainId)) {\n // If the source chain is not an EVM network, use value from params\n insufficientBal = paramsToUpdate.insufficientBal;\n } else if (providerConfig?.rpcUrl?.includes('tenderly')) {\n // If the rpcUrl is a tenderly fork (e2e tests), set insufficientBal=true\n // The bridge-api filters out quotes if the balance on mainnet is insufficient so this override allows quotes to always be returned\n insufficientBal = true;\n } else {\n // Otherwise query the src token balance from the RPC provider\n insufficientBal =\n paramsToUpdate.insufficientBal ??\n !(await this.#hasSufficientBalance(updatedQuoteRequest));\n }\n\n const networkClientId = this.#getSelectedNetworkClientId();\n // Set refresh rate based on the source chain before starting polling\n this.setChainIntervalLength();\n this.startPolling({\n networkClientId,\n updatedQuoteRequest: {\n ...updatedQuoteRequest,\n insufficientBal,\n },\n context,\n });\n }\n };\n\n readonly #getExchangeRateSources = () => {\n return {\n ...this.messagingSystem.call('MultichainAssetsRatesController:getState'),\n ...this.messagingSystem.call('CurrencyRateController:getState'),\n ...this.messagingSystem.call('TokenRatesController:getState'),\n ...this.state,\n };\n };\n\n /**\n * Fetches the exchange rates for the assets in the quote request if they are not already in the state\n * In addition to the selected tokens, this also fetches the native asset for the source and destination chains\n *\n * @param quoteRequest - The quote request\n * @param quoteRequest.srcChainId - The source chain ID\n * @param quoteRequest.srcTokenAddress - The source token address\n * @param quoteRequest.destChainId - The destination chain ID\n * @param quoteRequest.destTokenAddress - The destination token address\n */\n readonly #fetchAssetExchangeRates = async ({\n srcChainId,\n srcTokenAddress,\n destChainId,\n destTokenAddress,\n }: Partial<GenericQuoteRequest>) => {\n const assetIds: Set<CaipAssetType> = new Set([]);\n const exchangeRateSources = this.#getExchangeRateSources();\n if (\n srcTokenAddress &&\n srcChainId &&\n !selectIsAssetExchangeRateInState(\n exchangeRateSources,\n srcChainId,\n srcTokenAddress,\n )\n ) {\n getAssetIdsForToken(srcTokenAddress, srcChainId).forEach((assetId) =>\n assetIds.add(assetId),\n );\n }\n if (\n destTokenAddress &&\n destChainId &&\n !selectIsAssetExchangeRateInState(\n exchangeRateSources,\n destChainId,\n destTokenAddress,\n )\n ) {\n getAssetIdsForToken(destTokenAddress, destChainId).forEach((assetId) =>\n assetIds.add(assetId),\n );\n }\n\n const currency = this.messagingSystem.call(\n 'CurrencyRateController:getState',\n ).currentCurrency;\n\n if (assetIds.size === 0) {\n return;\n }\n\n const pricesByAssetId = await fetchAssetPrices({\n assetIds,\n currencies: new Set([currency]),\n clientId: this.#clientId,\n fetchFn: this.#fetchFn,\n });\n const exchangeRates = toExchangeRates(currency, pricesByAssetId);\n this.update((state) => {\n state.assetExchangeRates = {\n ...state.assetExchangeRates,\n ...exchangeRates,\n };\n });\n };\n\n readonly #hasSufficientBalance = async (\n quoteRequest: GenericQuoteRequest,\n ) => {\n const walletAddress = this.#getMultichainSelectedAccount()?.address;\n const srcChainIdInHex = formatChainIdToHex(quoteRequest.srcChainId);\n const provider = this.#getSelectedNetworkClient()?.provider;\n const normalizedSrcTokenAddress = formatAddressToCaipReference(\n quoteRequest.srcTokenAddress,\n );\n\n return (\n provider &&\n walletAddress &&\n normalizedSrcTokenAddress &&\n quoteRequest.srcTokenAmount &&\n srcChainIdInHex &&\n (await hasSufficientBalance(\n provider,\n walletAddress,\n normalizedSrcTokenAddress,\n quoteRequest.srcTokenAmount,\n srcChainIdInHex,\n ))\n );\n };\n\n resetState = () => {\n this.stopAllPolling();\n this.#abortController?.abort(RESET_STATE_ABORT_MESSAGE);\n\n this.update((state) => {\n // Cannot do direct assignment to state, i.e. state = {... }, need to manually assign each field\n state.quoteRequest = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest;\n state.quotesInitialLoadTime =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;\n state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;\n state.quotesLastFetched =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLastFetched;\n state.quotesLoadingStatus =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLoadingStatus;\n state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;\n state.quotesRefreshCount =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount;\n state.assetExchangeRates =\n DEFAULT_BRIDGE_CONTROLLER_STATE.assetExchangeRates;\n });\n };\n\n /**\n * Sets the interval length based on the source chain\n */\n setChainIntervalLength = () => {\n const { state } = this;\n const { srcChainId } = state.quoteRequest;\n const bridgeFeatureFlags = getBridgeFeatureFlags(this.messagingSystem);\n\n const refreshRateOverride = srcChainId\n ? bridgeFeatureFlags.chains[formatChainIdToCaip(srcChainId)]?.refreshRate\n : undefined;\n const defaultRefreshRate = bridgeFeatureFlags.refreshRate;\n this.setIntervalLength(refreshRateOverride ?? defaultRefreshRate);\n };\n\n readonly #fetchBridgeQuotes = async ({\n networkClientId: _networkClientId,\n updatedQuoteRequest,\n context,\n }: BridgePollingInput) => {\n const { quotesInitialLoadTime, quotesRefreshCount } = this.state;\n this.#abortController?.abort('New quote request');\n this.#abortController = new AbortController();\n\n this.trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.QuotesRequested,\n context,\n );\n this.update((state) => {\n state.quotesLoadingStatus = RequestStatus.LOADING;\n state.quoteRequest = updatedQuoteRequest;\n state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;\n });\n\n try {\n const quotes = await fetchBridgeQuotes(\n updatedQuoteRequest,\n // AbortController is always defined by this line, because we assign it a few lines above,\n // not sure why Jest thinks it's not\n // Linters accurately say that it's defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#abortController!.signal as AbortSignal,\n this.#clientId,\n this.#fetchFn,\n this.#config.customBridgeApiBaseUrl ?? BRIDGE_PROD_API_BASE_URL,\n );\n\n const quotesWithL1GasFees = await this.#appendL1GasFees(quotes);\n const quotesWithSolanaFees = await this.#appendSolanaFees(quotes);\n\n this.update((state) => {\n state.quotes = quotesWithL1GasFees ?? quotesWithSolanaFees ?? quotes;\n state.quotesLoadingStatus = RequestStatus.FETCHED;\n });\n } catch (error) {\n const isAbortError = (error as Error).name === 'AbortError';\n const isAbortedDueToReset = error === RESET_STATE_ABORT_MESSAGE;\n if (isAbortedDueToReset || isAbortError) {\n return;\n }\n\n this.update((state) => {\n state.quoteFetchError =\n error instanceof Error ? error.message : 'Unknown error';\n state.quotesLoadingStatus = RequestStatus.ERROR;\n state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;\n });\n this.trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.QuoteError,\n context,\n );\n console.log('Failed to fetch bridge quotes', error);\n } finally {\n const bridgeFeatureFlags = getBridgeFeatureFlags(this.messagingSystem);\n const { maxRefreshCount } = bridgeFeatureFlags;\n\n const updatedQuotesRefreshCount = quotesRefreshCount + 1;\n // Stop polling if the maximum number of refreshes has been reached\n if (\n updatedQuoteRequest.insufficientBal ||\n (!updatedQuoteRequest.insufficientBal &&\n updatedQuotesRefreshCount >= maxRefreshCount)\n ) {\n this.stopAllPolling();\n }\n\n // Update quote fetching stats\n const quotesLastFetched = Date.now();\n this.update((state) => {\n state.quotesInitialLoadTime =\n updatedQuotesRefreshCount === 1 && this.#quotesFirstFetched\n ? quotesLastFetched - this.#quotesFirstFetched\n : quotesInitialLoadTime;\n state.quotesLastFetched = quotesLastFetched;\n state.quotesRefreshCount = updatedQuotesRefreshCount;\n });\n }\n };\n\n readonly #appendL1GasFees = async (\n quotes: QuoteResponse[],\n ): Promise<(QuoteResponse & L1GasFees)[] | undefined> => {\n // Indicates whether some of the quotes are not for optimism or base\n const hasInvalidQuotes = quotes.some(({ quote }) => {\n const chainId = formatChainIdToCaip(quote.srcChainId);\n return ![CHAIN_IDS.OPTIMISM, CHAIN_IDS.BASE]\n .map(formatChainIdToCaip)\n .includes(chainId);\n });\n\n // Only append L1 gas fees if all quotes are for either optimism or base\n if (!hasInvalidQuotes) {\n return await Promise.all(\n quotes.map(async (quoteResponse) => {\n const { quote, trade, approval } = quoteResponse;\n const chainId = numberToHex(quote.srcChainId) as ChainId;\n\n const getTxParams = (txData: TxData) => ({\n from: txData.from,\n to: txData.to,\n value: txData.value,\n data: txData.data,\n gasLimit: txData.gasLimit?.toString(),\n });\n const approvalL1GasFees = approval\n ? await this.#getLayer1GasFee({\n transactionParams: getTxParams(approval),\n chainId,\n })\n : '0';\n const tradeL1GasFees = await this.#getLayer1GasFee({\n transactionParams: getTxParams(trade),\n chainId,\n });\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n }\n\n return undefined;\n };\n\n readonly #appendSolanaFees = async (\n quotes: QuoteResponse[],\n ): Promise<(QuoteResponse & SolanaFees)[] | undefined> => {\n // Return early if some of the quotes are not for solana\n if (\n quotes.some(({ quote: { srcChainId } }) => !isSolanaChainId(srcChainId))\n ) {\n return undefined;\n }\n\n return await Promise.all(\n quotes.map(async (quoteResponse) => {\n const { trade } = quoteResponse;\n const selectedAccount = this.#getMultichainSelectedAccount();\n\n if (selectedAccount?.metadata?.snap?.id && typeof trade === 'string') {\n const { value: fees } = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n {\n snapId: selectedAccount.metadata.snap?.id as never,\n origin: 'metamask',\n handler: 'onRpcRequest' as never,\n request: {\n method: 'getFeeForTransaction',\n params: {\n transaction: trade,\n scope: SolScope.Mainnet,\n },\n },\n },\n )) as { value: string };\n\n return {\n ...quoteResponse,\n solanaFeesInLamports: fees,\n };\n }\n return quoteResponse;\n }),\n );\n };\n\n #getMultichainSelectedAccount() {\n return this.messagingSystem.call(\n 'AccountsController:getSelectedMultichainAccount',\n );\n }\n\n #getSelectedNetworkClientId() {\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n return selectedNetworkClientId;\n }\n\n #getSelectedNetworkClient() {\n const selectedNetworkClientId = this.#getSelectedNetworkClientId();\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n return networkClient;\n }\n\n readonly #getRequestParams = (): Omit<\n RequestParams,\n 'token_symbol_source' | 'token_symbol_destination'\n > => {\n const srcChainIdCaip = formatChainIdToCaip(\n this.state.quoteRequest.srcChainId ||\n this.#getSelectedNetworkClient().configuration.chainId,\n );\n return getRequestParams(this.state.quoteRequest, srcChainIdCaip);\n };\n\n readonly #getRequestMetadata = (): Omit<\n RequestMetadata,\n 'stx_enabled' | 'usd_amount_source' | 'security_warnings'\n > => {\n return {\n slippage_limit: this.state.quoteRequest.slippage,\n swap_type: getSwapTypeFromQuote(this.state.quoteRequest),\n is_hardware_wallet: isHardwareWallet(\n this.#getMultichainSelectedAccount(),\n ),\n custom_slippage: isCustomSlippage(this.state.quoteRequest.slippage),\n };\n };\n\n readonly #getQuoteFetchData = (): Omit<\n QuoteFetchData,\n 'best_quote_provider' | 'price_impact'\n > => {\n return {\n can_submit: Boolean(this.state.quoteRequest.insufficientBal), // TODO check if balance is sufficient for network fees\n quotes_count: this.state.quotes.length,\n quotes_list: this.state.quotes.map(({ quote }) =>\n formatProviderLabel(quote),\n ),\n initial_load_time_all_quotes: this.state.quotesInitialLoadTime ?? 0,\n };\n };\n\n readonly #getEventProperties = <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n propertiesFromClient: Pick<RequiredEventContextFromClient, T>[T],\n ): CrossChainSwapsEventProperties<T> => {\n const baseProperties = {\n action_type: getActionTypeFromQuoteRequest(this.state.quoteRequest),\n ...propertiesFromClient,\n };\n switch (eventName) {\n case UnifiedSwapBridgeEventName.ButtonClicked:\n case UnifiedSwapBridgeEventName.PageViewed:\n return {\n ...this.#getRequestParams(),\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.QuotesReceived:\n return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n ...this.#getQuoteFetchData(),\n refresh_count: this.state.quotesRefreshCount,\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.QuotesRequested:\n case UnifiedSwapBridgeEventName.QuoteError:\n return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n error_message: this.state.quoteFetchError,\n has_sufficient_funds: !this.state.quoteRequest.insufficientBal,\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.AllQuotesOpened:\n case UnifiedSwapBridgeEventName.AllQuotesSorted:\n case UnifiedSwapBridgeEventName.QuoteSelected:\n return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n ...this.#getQuoteFetchData(),\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.SnapConfirmationViewed:\n return {\n ...baseProperties,\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n };\n // These are populated by BridgeStatusController\n case UnifiedSwapBridgeEventName.Submitted:\n case UnifiedSwapBridgeEventName.Completed:\n case UnifiedSwapBridgeEventName.Failed:\n return propertiesFromClient;\n case UnifiedSwapBridgeEventName.InputChanged:\n default:\n return baseProperties;\n }\n };\n\n readonly #trackInputChangedEvents = (\n paramsToUpdate: Partial<GenericQuoteRequest>,\n ) => {\n Object.entries(paramsToUpdate).forEach(([key, value]) => {\n const inputKey = toInputChangedPropertyKey[key as keyof QuoteRequest];\n const inputValue =\n toInputChangedPropertyValue[key as keyof QuoteRequest]?.(\n paramsToUpdate,\n );\n if (\n inputKey &&\n inputValue !== undefined &&\n value !== this.state.quoteRequest[key as keyof GenericQuoteRequest]\n ) {\n this.trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.InputChanged,\n {\n input: inputKey,\n value: inputValue,\n },\n );\n }\n });\n };\n\n /**\n * This method tracks cross-chain swaps events\n *\n * @param eventName - The name of the event to track\n * @param propertiesFromClient - Properties that can't be calculated from the event name and need to be provided by the client\n * @example\n * this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.ActionOpened, {\n * location: MetaMetricsSwapsEventSource.MainView,\n * });\n */\n trackUnifiedSwapBridgeEvent = <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n propertiesFromClient: Pick<RequiredEventContextFromClient, T>[T],\n ) => {\n try {\n const combinedPropertiesForEvent = this.#getEventProperties<T>(\n eventName,\n propertiesFromClient,\n );\n\n this.#trackMetaMetricsFn(eventName, combinedPropertiesForEvent);\n } catch (error) {\n console.error(\n 'Error tracking cross-chain swaps MetaMetrics event',\n error,\n );\n }\n };\n\n /**\n *\n * @param contractAddress - The address of the ERC20 token contract\n * @param chainId - The hex chain ID of the bridge network\n * @returns The atomic allowance of the ERC20 token contract\n */\n getBridgeERC20Allowance = async (\n contractAddress: string,\n chainId: Hex,\n ): Promise<string> => {\n const provider = this.#getSelectedNetworkClient()?.provider;\n if (!provider) {\n throw new Error('No provider found');\n }\n\n const ethersProvider = new Web3Provider(provider);\n const contract = new Contract(contractAddress, abiERC20, ethersProvider);\n const { address: walletAddress } =\n this.#getMultichainSelectedAccount() ?? {};\n const allowance: BigNumber = await contract.allowance(\n walletAddress,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP[chainId],\n );\n return allowance.toString();\n };\n}\n"]}
1
+ {"version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ACvB,CAAC","sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { StateMetadata } from '@metamask/base-controller';\nimport type { ChainId, TraceCallback } from '@metamask/controller-utils';\nimport { SolScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport type { CaipAssetType } from '@metamask/utils';\nimport { numberToHex, type Hex } from '@metamask/utils';\n\nimport {\n type BridgeClientId,\n BRIDGE_CONTROLLER_NAME,\n BRIDGE_PROD_API_BASE_URL,\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP,\n REFRESH_INTERVAL_MS,\n} from './constants/bridge';\nimport { CHAIN_IDS } from './constants/chains';\nimport { TraceName } from './constants/traces';\nimport { selectIsAssetExchangeRateInState } from './selectors';\nimport type { QuoteRequest } from './types';\nimport {\n type L1GasFees,\n type GenericQuoteRequest,\n type SolanaFees,\n type QuoteResponse,\n type TxData,\n type BridgeControllerState,\n type BridgeControllerMessenger,\n type FetchFunction,\n RequestStatus,\n} from './types';\nimport { getAssetIdsForToken, toExchangeRates } from './utils/assets';\nimport { hasSufficientBalance } from './utils/balance';\nimport {\n getDefaultBridgeControllerState,\n isCrossChain,\n isSolanaChainId,\n sumHexes,\n} from './utils/bridge';\nimport {\n formatAddressToCaipReference,\n formatChainIdToCaip,\n formatChainIdToHex,\n} from './utils/caip-formatters';\nimport { getBridgeFeatureFlags } from './utils/feature-flags';\nimport { fetchAssetPrices, fetchBridgeQuotes } from './utils/fetch';\nimport { UnifiedSwapBridgeEventName } from './utils/metrics/constants';\nimport {\n formatProviderLabel,\n getActionTypeFromQuoteRequest,\n getRequestParams,\n getSwapTypeFromQuote,\n isCustomSlippage,\n isHardwareWallet,\n toInputChangedPropertyKey,\n toInputChangedPropertyValue,\n} from './utils/metrics/properties';\nimport type {\n QuoteFetchData,\n RequestMetadata,\n RequestParams,\n RequiredEventContextFromClient,\n} from './utils/metrics/types';\nimport { type CrossChainSwapsEventProperties } from './utils/metrics/types';\nimport { isValidQuoteRequest } from './utils/quote';\n\nconst metadata: StateMetadata<BridgeControllerState> = {\n quoteRequest: {\n persist: false,\n anonymous: false,\n },\n quotes: {\n persist: false,\n anonymous: false,\n },\n quotesInitialLoadTime: {\n persist: false,\n anonymous: false,\n },\n quotesLastFetched: {\n persist: false,\n anonymous: false,\n },\n quotesLoadingStatus: {\n persist: false,\n anonymous: false,\n },\n quoteFetchError: {\n persist: false,\n anonymous: false,\n },\n quotesRefreshCount: {\n persist: false,\n anonymous: false,\n },\n assetExchangeRates: {\n persist: false,\n anonymous: false,\n },\n};\n\nconst RESET_STATE_ABORT_MESSAGE = 'Reset controller state';\n\n/**\n * The input to start polling for the {@link BridgeController}\n *\n * @param networkClientId - The network client ID of the selected network\n * @param updatedQuoteRequest - The updated quote request\n * @param context - The context contains properties that can't be populated by the\n * controller and need to be provided by the client for analytics\n */\ntype BridgePollingInput = {\n networkClientId: NetworkClientId;\n updatedQuoteRequest: GenericQuoteRequest;\n context: Pick<\n RequiredEventContextFromClient,\n UnifiedSwapBridgeEventName.QuoteError\n >[UnifiedSwapBridgeEventName.QuoteError] &\n Pick<\n RequiredEventContextFromClient,\n UnifiedSwapBridgeEventName.QuotesRequested\n >[UnifiedSwapBridgeEventName.QuotesRequested];\n};\n\nexport class BridgeController extends StaticIntervalPollingController<BridgePollingInput>()<\n typeof BRIDGE_CONTROLLER_NAME,\n BridgeControllerState,\n BridgeControllerMessenger\n> {\n #abortController: AbortController | undefined;\n\n #quotesFirstFetched: number | undefined;\n\n readonly #clientId: string;\n\n readonly #getLayer1GasFee: (params: {\n transactionParams: TransactionParams;\n chainId: ChainId;\n }) => Promise<string>;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #trackMetaMetricsFn: <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n properties: CrossChainSwapsEventProperties<T>,\n ) => void;\n\n readonly #trace: TraceCallback;\n\n readonly #config: {\n customBridgeApiBaseUrl?: string;\n };\n\n constructor({\n messenger,\n state,\n clientId,\n getLayer1GasFee,\n fetchFn,\n config,\n trackMetaMetricsFn,\n traceFn,\n }: {\n messenger: BridgeControllerMessenger;\n state?: Partial<BridgeControllerState>;\n clientId: BridgeClientId;\n getLayer1GasFee: (params: {\n transactionParams: TransactionParams;\n chainId: ChainId;\n }) => Promise<string>;\n fetchFn: FetchFunction;\n config?: {\n customBridgeApiBaseUrl?: string;\n };\n trackMetaMetricsFn: <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n properties: CrossChainSwapsEventProperties<T>,\n ) => void;\n traceFn?: TraceCallback;\n }) {\n super({\n name: BRIDGE_CONTROLLER_NAME,\n metadata,\n messenger,\n state: {\n ...getDefaultBridgeControllerState(),\n ...state,\n },\n });\n\n this.setIntervalLength(REFRESH_INTERVAL_MS);\n\n this.#abortController = new AbortController();\n this.#getLayer1GasFee = getLayer1GasFee;\n this.#clientId = clientId;\n this.#fetchFn = fetchFn;\n this.#trackMetaMetricsFn = trackMetaMetricsFn;\n this.#config = config ?? {};\n this.#trace = traceFn ?? (((_request, fn) => fn?.()) as TraceCallback);\n\n // Register action handlers\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:setChainIntervalLength`,\n this.setChainIntervalLength.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:updateBridgeQuoteRequestParams`,\n this.updateBridgeQuoteRequestParams.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:resetState`,\n this.resetState.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:getBridgeERC20Allowance`,\n this.getBridgeERC20Allowance.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${BRIDGE_CONTROLLER_NAME}:trackUnifiedSwapBridgeEvent`,\n this.trackUnifiedSwapBridgeEvent.bind(this),\n );\n }\n\n _executePoll = async (pollingInput: BridgePollingInput) => {\n await this.#fetchBridgeQuotes(pollingInput);\n };\n\n updateBridgeQuoteRequestParams = async (\n paramsToUpdate: Partial<GenericQuoteRequest>,\n context: BridgePollingInput['context'],\n ) => {\n this.stopAllPolling();\n this.#abortController?.abort('Quote request updated');\n\n this.#trackInputChangedEvents(paramsToUpdate);\n\n const updatedQuoteRequest = {\n ...DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest,\n ...paramsToUpdate,\n };\n\n this.update((state) => {\n state.quoteRequest = updatedQuoteRequest;\n state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;\n state.quotesLastFetched =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLastFetched;\n state.quotesLoadingStatus =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLoadingStatus;\n state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;\n state.quotesRefreshCount =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount;\n state.quotesInitialLoadTime =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;\n });\n\n await this.#fetchAssetExchangeRates(updatedQuoteRequest).catch((error) =>\n console.warn('Failed to fetch asset exchange rates', error),\n );\n\n if (isValidQuoteRequest(updatedQuoteRequest)) {\n this.#quotesFirstFetched = Date.now();\n const providerConfig = this.#getSelectedNetworkClient()?.configuration;\n\n let insufficientBal: boolean | undefined;\n if (isSolanaChainId(updatedQuoteRequest.srcChainId)) {\n // If the source chain is not an EVM network, use value from params\n insufficientBal = paramsToUpdate.insufficientBal;\n } else if (providerConfig?.rpcUrl?.includes('tenderly')) {\n // If the rpcUrl is a tenderly fork (e2e tests), set insufficientBal=true\n // The bridge-api filters out quotes if the balance on mainnet is insufficient so this override allows quotes to always be returned\n insufficientBal = true;\n } else {\n // Otherwise query the src token balance from the RPC provider\n insufficientBal =\n paramsToUpdate.insufficientBal ??\n !(await this.#hasSufficientBalance(updatedQuoteRequest));\n }\n\n const networkClientId = this.#getSelectedNetworkClientId();\n // Set refresh rate based on the source chain before starting polling\n this.setChainIntervalLength();\n this.startPolling({\n networkClientId,\n updatedQuoteRequest: {\n ...updatedQuoteRequest,\n insufficientBal,\n },\n context,\n });\n }\n };\n\n readonly #getExchangeRateSources = () => {\n return {\n ...this.messagingSystem.call('MultichainAssetsRatesController:getState'),\n ...this.messagingSystem.call('CurrencyRateController:getState'),\n ...this.messagingSystem.call('TokenRatesController:getState'),\n ...this.state,\n };\n };\n\n /**\n * Fetches the exchange rates for the assets in the quote request if they are not already in the state\n * In addition to the selected tokens, this also fetches the native asset for the source and destination chains\n *\n * @param quoteRequest - The quote request\n * @param quoteRequest.srcChainId - The source chain ID\n * @param quoteRequest.srcTokenAddress - The source token address\n * @param quoteRequest.destChainId - The destination chain ID\n * @param quoteRequest.destTokenAddress - The destination token address\n */\n readonly #fetchAssetExchangeRates = async ({\n srcChainId,\n srcTokenAddress,\n destChainId,\n destTokenAddress,\n }: Partial<GenericQuoteRequest>) => {\n const assetIds: Set<CaipAssetType> = new Set([]);\n const exchangeRateSources = this.#getExchangeRateSources();\n if (\n srcTokenAddress &&\n srcChainId &&\n !selectIsAssetExchangeRateInState(\n exchangeRateSources,\n srcChainId,\n srcTokenAddress,\n )\n ) {\n getAssetIdsForToken(srcTokenAddress, srcChainId).forEach((assetId) =>\n assetIds.add(assetId),\n );\n }\n if (\n destTokenAddress &&\n destChainId &&\n !selectIsAssetExchangeRateInState(\n exchangeRateSources,\n destChainId,\n destTokenAddress,\n )\n ) {\n getAssetIdsForToken(destTokenAddress, destChainId).forEach((assetId) =>\n assetIds.add(assetId),\n );\n }\n\n const currency = this.messagingSystem.call(\n 'CurrencyRateController:getState',\n ).currentCurrency;\n\n if (assetIds.size === 0) {\n return;\n }\n\n const pricesByAssetId = await fetchAssetPrices({\n assetIds,\n currencies: new Set([currency]),\n clientId: this.#clientId,\n fetchFn: this.#fetchFn,\n });\n const exchangeRates = toExchangeRates(currency, pricesByAssetId);\n this.update((state) => {\n state.assetExchangeRates = {\n ...state.assetExchangeRates,\n ...exchangeRates,\n };\n });\n };\n\n readonly #hasSufficientBalance = async (\n quoteRequest: GenericQuoteRequest,\n ) => {\n const walletAddress = this.#getMultichainSelectedAccount()?.address;\n const srcChainIdInHex = formatChainIdToHex(quoteRequest.srcChainId);\n const provider = this.#getSelectedNetworkClient()?.provider;\n const normalizedSrcTokenAddress = formatAddressToCaipReference(\n quoteRequest.srcTokenAddress,\n );\n\n return (\n provider &&\n walletAddress &&\n normalizedSrcTokenAddress &&\n quoteRequest.srcTokenAmount &&\n srcChainIdInHex &&\n (await hasSufficientBalance(\n provider,\n walletAddress,\n normalizedSrcTokenAddress,\n quoteRequest.srcTokenAmount,\n srcChainIdInHex,\n ))\n );\n };\n\n resetState = () => {\n this.stopAllPolling();\n this.#abortController?.abort(RESET_STATE_ABORT_MESSAGE);\n\n this.update((state) => {\n // Cannot do direct assignment to state, i.e. state = {... }, need to manually assign each field\n state.quoteRequest = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest;\n state.quotesInitialLoadTime =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;\n state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;\n state.quotesLastFetched =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLastFetched;\n state.quotesLoadingStatus =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLoadingStatus;\n state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;\n state.quotesRefreshCount =\n DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount;\n state.assetExchangeRates =\n DEFAULT_BRIDGE_CONTROLLER_STATE.assetExchangeRates;\n });\n };\n\n /**\n * Sets the interval length based on the source chain\n */\n setChainIntervalLength = () => {\n const { state } = this;\n const { srcChainId } = state.quoteRequest;\n const bridgeFeatureFlags = getBridgeFeatureFlags(this.messagingSystem);\n\n const refreshRateOverride = srcChainId\n ? bridgeFeatureFlags.chains[formatChainIdToCaip(srcChainId)]?.refreshRate\n : undefined;\n const defaultRefreshRate = bridgeFeatureFlags.refreshRate;\n this.setIntervalLength(refreshRateOverride ?? defaultRefreshRate);\n };\n\n readonly #fetchBridgeQuotes = async ({\n networkClientId: _networkClientId,\n updatedQuoteRequest,\n context,\n }: BridgePollingInput) => {\n this.#abortController?.abort('New quote request');\n this.#abortController = new AbortController();\n\n this.trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.QuotesRequested,\n context,\n );\n this.update((state) => {\n state.quotesLoadingStatus = RequestStatus.LOADING;\n state.quoteRequest = updatedQuoteRequest;\n state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;\n });\n\n const fetchQuotes = async () => {\n const quotes = await fetchBridgeQuotes(\n updatedQuoteRequest,\n // AbortController is always defined by this line, because we assign it a few lines above,\n // not sure why Jest thinks it's not\n // Linters accurately say that it's defined\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#abortController!.signal as AbortSignal,\n this.#clientId,\n this.#fetchFn,\n this.#config.customBridgeApiBaseUrl ?? BRIDGE_PROD_API_BASE_URL,\n );\n\n const quotesWithL1GasFees = await this.#appendL1GasFees(quotes);\n const quotesWithSolanaFees = await this.#appendSolanaFees(quotes);\n\n this.update((state) => {\n state.quotes = quotesWithL1GasFees ?? quotesWithSolanaFees ?? quotes;\n state.quotesLoadingStatus = RequestStatus.FETCHED;\n });\n };\n\n try {\n await this.#trace(\n {\n name: isCrossChain(\n updatedQuoteRequest.srcChainId,\n updatedQuoteRequest.destChainId,\n )\n ? TraceName.BridgeQuotesFetched\n : TraceName.SwapQuotesFetched,\n data: {\n srcChainId: formatChainIdToCaip(updatedQuoteRequest.srcChainId),\n destChainId: formatChainIdToCaip(updatedQuoteRequest.destChainId),\n },\n },\n fetchQuotes,\n );\n } catch (error) {\n const isAbortError = (error as Error).name === 'AbortError';\n const isAbortedDueToReset = error === RESET_STATE_ABORT_MESSAGE;\n if (isAbortedDueToReset || isAbortError) {\n // Exit the function early to avoid other state updates\n return;\n }\n\n this.update((state) => {\n state.quoteFetchError =\n error instanceof Error ? error.message : 'Unknown error';\n state.quotesLoadingStatus = RequestStatus.ERROR;\n state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;\n });\n this.trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.QuoteError,\n context,\n );\n console.log('Failed to fetch bridge quotes', error);\n }\n const bridgeFeatureFlags = getBridgeFeatureFlags(this.messagingSystem);\n const { maxRefreshCount } = bridgeFeatureFlags;\n\n // Stop polling if the maximum number of refreshes has been reached\n if (\n updatedQuoteRequest.insufficientBal ||\n (!updatedQuoteRequest.insufficientBal &&\n this.state.quotesRefreshCount >= maxRefreshCount)\n ) {\n this.stopAllPolling();\n }\n\n // Update quote fetching stats\n const quotesLastFetched = Date.now();\n this.update((state) => {\n state.quotesInitialLoadTime =\n state.quotesRefreshCount === 0 && this.#quotesFirstFetched\n ? quotesLastFetched - this.#quotesFirstFetched\n : this.state.quotesInitialLoadTime;\n state.quotesLastFetched = quotesLastFetched;\n state.quotesRefreshCount += 1;\n });\n };\n\n readonly #appendL1GasFees = async (\n quotes: QuoteResponse[],\n ): Promise<(QuoteResponse & L1GasFees)[] | undefined> => {\n // Indicates whether some of the quotes are not for optimism or base\n const hasInvalidQuotes = quotes.some(({ quote }) => {\n const chainId = formatChainIdToCaip(quote.srcChainId);\n return ![CHAIN_IDS.OPTIMISM, CHAIN_IDS.BASE]\n .map(formatChainIdToCaip)\n .includes(chainId);\n });\n\n // Only append L1 gas fees if all quotes are for either optimism or base\n if (!hasInvalidQuotes) {\n return await Promise.all(\n quotes.map(async (quoteResponse) => {\n const { quote, trade, approval } = quoteResponse;\n const chainId = numberToHex(quote.srcChainId) as ChainId;\n\n const getTxParams = (txData: TxData) => ({\n from: txData.from,\n to: txData.to,\n value: txData.value,\n data: txData.data,\n gasLimit: txData.gasLimit?.toString(),\n });\n const approvalL1GasFees = approval\n ? await this.#getLayer1GasFee({\n transactionParams: getTxParams(approval),\n chainId,\n })\n : '0';\n const tradeL1GasFees = await this.#getLayer1GasFee({\n transactionParams: getTxParams(trade),\n chainId,\n });\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n }\n\n return undefined;\n };\n\n readonly #appendSolanaFees = async (\n quotes: QuoteResponse[],\n ): Promise<(QuoteResponse & SolanaFees)[] | undefined> => {\n // Return early if some of the quotes are not for solana\n if (\n quotes.some(({ quote: { srcChainId } }) => !isSolanaChainId(srcChainId))\n ) {\n return undefined;\n }\n\n return await Promise.all(\n quotes.map(async (quoteResponse) => {\n const { trade } = quoteResponse;\n const selectedAccount = this.#getMultichainSelectedAccount();\n\n if (selectedAccount?.metadata?.snap?.id && typeof trade === 'string') {\n const { value: fees } = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n {\n snapId: selectedAccount.metadata.snap?.id as never,\n origin: 'metamask',\n handler: 'onRpcRequest' as never,\n request: {\n method: 'getFeeForTransaction',\n params: {\n transaction: trade,\n scope: SolScope.Mainnet,\n },\n },\n },\n )) as { value: string };\n\n return {\n ...quoteResponse,\n solanaFeesInLamports: fees,\n };\n }\n return quoteResponse;\n }),\n );\n };\n\n #getMultichainSelectedAccount() {\n return this.messagingSystem.call(\n 'AccountsController:getSelectedMultichainAccount',\n );\n }\n\n #getSelectedNetworkClientId() {\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n return selectedNetworkClientId;\n }\n\n #getSelectedNetworkClient() {\n const selectedNetworkClientId = this.#getSelectedNetworkClientId();\n const networkClient = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n return networkClient;\n }\n\n readonly #getRequestParams = (): Omit<\n RequestParams,\n 'token_symbol_source' | 'token_symbol_destination'\n > => {\n const srcChainIdCaip = formatChainIdToCaip(\n this.state.quoteRequest.srcChainId ||\n this.#getSelectedNetworkClient().configuration.chainId,\n );\n return getRequestParams(this.state.quoteRequest, srcChainIdCaip);\n };\n\n readonly #getRequestMetadata = (): Omit<\n RequestMetadata,\n 'stx_enabled' | 'usd_amount_source' | 'security_warnings'\n > => {\n return {\n slippage_limit: this.state.quoteRequest.slippage,\n swap_type: getSwapTypeFromQuote(this.state.quoteRequest),\n is_hardware_wallet: isHardwareWallet(\n this.#getMultichainSelectedAccount(),\n ),\n custom_slippage: isCustomSlippage(this.state.quoteRequest.slippage),\n };\n };\n\n readonly #getQuoteFetchData = (): Omit<\n QuoteFetchData,\n 'best_quote_provider' | 'price_impact'\n > => {\n return {\n can_submit: Boolean(this.state.quoteRequest.insufficientBal), // TODO check if balance is sufficient for network fees\n quotes_count: this.state.quotes.length,\n quotes_list: this.state.quotes.map(({ quote }) =>\n formatProviderLabel(quote),\n ),\n initial_load_time_all_quotes: this.state.quotesInitialLoadTime ?? 0,\n };\n };\n\n readonly #getEventProperties = <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n propertiesFromClient: Pick<RequiredEventContextFromClient, T>[T],\n ): CrossChainSwapsEventProperties<T> => {\n const baseProperties = {\n action_type: getActionTypeFromQuoteRequest(this.state.quoteRequest),\n ...propertiesFromClient,\n };\n switch (eventName) {\n case UnifiedSwapBridgeEventName.ButtonClicked:\n case UnifiedSwapBridgeEventName.PageViewed:\n return {\n ...this.#getRequestParams(),\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.QuotesReceived:\n return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n ...this.#getQuoteFetchData(),\n refresh_count: this.state.quotesRefreshCount,\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.QuotesRequested:\n case UnifiedSwapBridgeEventName.QuoteError:\n return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n error_message: this.state.quoteFetchError,\n has_sufficient_funds: !this.state.quoteRequest.insufficientBal,\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.AllQuotesOpened:\n case UnifiedSwapBridgeEventName.AllQuotesSorted:\n case UnifiedSwapBridgeEventName.QuoteSelected:\n return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n ...this.#getQuoteFetchData(),\n ...baseProperties,\n };\n case UnifiedSwapBridgeEventName.SnapConfirmationViewed:\n return {\n ...baseProperties,\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n };\n // These are populated by BridgeStatusController\n case UnifiedSwapBridgeEventName.Submitted:\n case UnifiedSwapBridgeEventName.Completed:\n case UnifiedSwapBridgeEventName.Failed:\n return propertiesFromClient;\n case UnifiedSwapBridgeEventName.InputChanged:\n default:\n return baseProperties;\n }\n };\n\n readonly #trackInputChangedEvents = (\n paramsToUpdate: Partial<GenericQuoteRequest>,\n ) => {\n Object.entries(paramsToUpdate).forEach(([key, value]) => {\n const inputKey = toInputChangedPropertyKey[key as keyof QuoteRequest];\n const inputValue =\n toInputChangedPropertyValue[key as keyof QuoteRequest]?.(\n paramsToUpdate,\n );\n if (\n inputKey &&\n inputValue !== undefined &&\n value !== this.state.quoteRequest[key as keyof GenericQuoteRequest]\n ) {\n this.trackUnifiedSwapBridgeEvent(\n UnifiedSwapBridgeEventName.InputChanged,\n {\n input: inputKey,\n value: inputValue,\n },\n );\n }\n });\n };\n\n /**\n * This method tracks cross-chain swaps events\n *\n * @param eventName - The name of the event to track\n * @param propertiesFromClient - Properties that can't be calculated from the event name and need to be provided by the client\n * @example\n * this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.ActionOpened, {\n * location: MetaMetricsSwapsEventSource.MainView,\n * });\n */\n trackUnifiedSwapBridgeEvent = <\n T extends\n (typeof UnifiedSwapBridgeEventName)[keyof typeof UnifiedSwapBridgeEventName],\n >(\n eventName: T,\n propertiesFromClient: Pick<RequiredEventContextFromClient, T>[T],\n ) => {\n try {\n const combinedPropertiesForEvent = this.#getEventProperties<T>(\n eventName,\n propertiesFromClient,\n );\n\n this.#trackMetaMetricsFn(eventName, combinedPropertiesForEvent);\n } catch (error) {\n console.error(\n 'Error tracking cross-chain swaps MetaMetrics event',\n error,\n );\n }\n };\n\n /**\n *\n * @param contractAddress - The address of the ERC20 token contract\n * @param chainId - The hex chain ID of the bridge network\n * @returns The atomic allowance of the ERC20 token contract\n */\n getBridgeERC20Allowance = async (\n contractAddress: string,\n chainId: Hex,\n ): Promise<string> => {\n const provider = this.#getSelectedNetworkClient()?.provider;\n if (!provider) {\n throw new Error('No provider found');\n }\n\n const ethersProvider = new Web3Provider(provider);\n const contract = new Contract(contractAddress, abiERC20, ethersProvider);\n const { address: walletAddress } =\n this.#getMultichainSelectedAccount() ?? {};\n const allowance: BigNumber = await contract.allowance(\n walletAddress,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP[chainId],\n );\n return allowance.toString();\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TraceName = void 0;
4
+ var TraceName;
5
+ (function (TraceName) {
6
+ TraceName["BridgeQuotesFetched"] = "Bridge Quotes Fetched";
7
+ TraceName["SwapQuotesFetched"] = "Swap Quotes Fetched";
8
+ })(TraceName || (exports.TraceName = TraceName = {}));
9
+ //# sourceMappingURL=traces.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traces.cjs","sourceRoot":"","sources":["../../src/constants/traces.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,0DAA6C,CAAA;IAC7C,sDAAyC,CAAA;AAC3C,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB","sourcesContent":["export enum TraceName {\n BridgeQuotesFetched = 'Bridge Quotes Fetched',\n SwapQuotesFetched = 'Swap Quotes Fetched',\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export declare enum TraceName {
2
+ BridgeQuotesFetched = "Bridge Quotes Fetched",
3
+ SwapQuotesFetched = "Swap Quotes Fetched"
4
+ }
5
+ //# sourceMappingURL=traces.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traces.d.cts","sourceRoot":"","sources":["../../src/constants/traces.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,mBAAmB,0BAA0B;IAC7C,iBAAiB,wBAAwB;CAC1C"}
@@ -0,0 +1,5 @@
1
+ export declare enum TraceName {
2
+ BridgeQuotesFetched = "Bridge Quotes Fetched",
3
+ SwapQuotesFetched = "Swap Quotes Fetched"
4
+ }
5
+ //# sourceMappingURL=traces.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traces.d.mts","sourceRoot":"","sources":["../../src/constants/traces.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,mBAAmB,0BAA0B;IAC7C,iBAAiB,wBAAwB;CAC1C"}
@@ -0,0 +1,6 @@
1
+ export var TraceName;
2
+ (function (TraceName) {
3
+ TraceName["BridgeQuotesFetched"] = "Bridge Quotes Fetched";
4
+ TraceName["SwapQuotesFetched"] = "Swap Quotes Fetched";
5
+ })(TraceName || (TraceName = {}));
6
+ //# sourceMappingURL=traces.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traces.mjs","sourceRoot":"","sources":["../../src/constants/traces.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,0DAA6C,CAAA;IAC7C,sDAAyC,CAAA;AAC3C,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB","sourcesContent":["export enum TraceName {\n BridgeQuotesFetched = 'Bridge Quotes Fetched',\n SwapQuotesFetched = 'Swap Quotes Fetched',\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectIsQuoteExpired = exports.selectExchangeRateByChainIdAndAddress = exports.selectBridgeQuotes = exports.formatAddressToCaipReference = exports.formatChainIdToHex = exports.formatChainIdToCaip = exports.fetchBridgeTokens = exports.calcLatestSrcBalance = exports.formatEtaInMinutes = exports.isValidQuoteRequest = exports.getDefaultBridgeControllerState = exports.getNativeAssetForChainId = exports.isSolanaChainId = exports.isNativeAddress = exports.isEthUsdt = exports.getEthUsdtResetData = exports.SWAPS_API_V2_BASE_URL = exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP = exports.BRIDGE_PROD_API_BASE_URL = exports.BRIDGE_DEV_API_BASE_URL = exports.METABRIDGE_CHAIN_TO_ADDRESS_MAP = exports.DEFAULT_BRIDGE_CONTROLLER_STATE = exports.DEFAULT_MAX_REFRESH_COUNT = exports.REFRESH_INTERVAL_MS = exports.BRIDGE_MM_FEE_RATE = exports.BRIDGE_DEFAULT_SLIPPAGE = exports.BRIDGE_PREFERRED_GAS_ESTIMATE = exports.BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE = exports.BRIDGE_QUOTE_MAX_ETA_SECONDS = exports.BRIDGE_CONTROLLER_NAME = exports.BridgeClientId = exports.ALLOWED_BRIDGE_CHAIN_IDS = exports.FeeType = exports.BridgeBackgroundAction = exports.BridgeUserAction = exports.RequestStatus = exports.ChainId = exports.ActionTypes = exports.SortOrder = exports.AssetType = exports.StatusTypes = exports.isCustomSlippage = exports.isHardwareWallet = exports.getSwapType = exports.getActionType = exports.getRequestParams = exports.formatProviderLabel = exports.UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = exports.UnifiedSwapBridgeEventName = exports.BridgeController = void 0;
4
- exports.selectBridgeFeatureFlags = void 0;
3
+ exports.selectExchangeRateByChainIdAndAddress = exports.selectBridgeQuotes = exports.formatAddressToCaipReference = exports.formatChainIdToHex = exports.formatChainIdToCaip = exports.fetchBridgeTokens = exports.calcLatestSrcBalance = exports.formatEtaInMinutes = exports.isValidQuoteRequest = exports.isCrossChain = exports.getDefaultBridgeControllerState = exports.getNativeAssetForChainId = exports.isSolanaChainId = exports.isNativeAddress = exports.isEthUsdt = exports.getEthUsdtResetData = exports.SWAPS_API_V2_BASE_URL = exports.SWAPS_CHAINID_DEFAULT_TOKEN_MAP = exports.BRIDGE_PROD_API_BASE_URL = exports.BRIDGE_DEV_API_BASE_URL = exports.METABRIDGE_CHAIN_TO_ADDRESS_MAP = exports.DEFAULT_BRIDGE_CONTROLLER_STATE = exports.DEFAULT_MAX_REFRESH_COUNT = exports.REFRESH_INTERVAL_MS = exports.BRIDGE_MM_FEE_RATE = exports.BRIDGE_DEFAULT_SLIPPAGE = exports.BRIDGE_PREFERRED_GAS_ESTIMATE = exports.BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE = exports.BRIDGE_QUOTE_MAX_ETA_SECONDS = exports.BRIDGE_CONTROLLER_NAME = exports.BridgeClientId = exports.ALLOWED_BRIDGE_CHAIN_IDS = exports.FeeType = exports.BridgeBackgroundAction = exports.BridgeUserAction = exports.RequestStatus = exports.ChainId = exports.ActionTypes = exports.SortOrder = exports.AssetType = exports.StatusTypes = exports.isCustomSlippage = exports.isHardwareWallet = exports.getSwapType = exports.getActionType = exports.getRequestParams = exports.formatProviderLabel = exports.UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = exports.UnifiedSwapBridgeEventName = exports.BridgeController = void 0;
4
+ exports.selectBridgeFeatureFlags = exports.selectIsQuoteExpired = void 0;
5
5
  var bridge_controller_1 = require("./bridge-controller.cjs");
6
6
  Object.defineProperty(exports, "BridgeController", { enumerable: true, get: function () { return bridge_controller_1.BridgeController; } });
7
7
  var constants_1 = require("./utils/metrics/constants.cjs");
@@ -54,6 +54,7 @@ Object.defineProperty(exports, "isNativeAddress", { enumerable: true, get: funct
54
54
  Object.defineProperty(exports, "isSolanaChainId", { enumerable: true, get: function () { return bridge_2.isSolanaChainId; } });
55
55
  Object.defineProperty(exports, "getNativeAssetForChainId", { enumerable: true, get: function () { return bridge_2.getNativeAssetForChainId; } });
56
56
  Object.defineProperty(exports, "getDefaultBridgeControllerState", { enumerable: true, get: function () { return bridge_2.getDefaultBridgeControllerState; } });
57
+ Object.defineProperty(exports, "isCrossChain", { enumerable: true, get: function () { return bridge_2.isCrossChain; } });
57
58
  var quote_1 = require("./utils/quote.cjs");
58
59
  Object.defineProperty(exports, "isValidQuoteRequest", { enumerable: true, get: function () { return quote_1.isValidQuoteRequest; } });
59
60
  Object.defineProperty(exports, "formatEtaInMinutes", { enumerable: true, get: function () { return quote_1.formatEtaInMinutes; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,6DAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AAEzB,2DAGmC;AAFjC,uHAAA,0BAA0B,OAAA;AAC1B,+HAAA,kCAAkC,OAAA;AAYpC,6DAOoC;AANlC,iHAAA,mBAAmB,OAAA;AACnB,8GAAA,gBAAgB,OAAA;AAChB,2GAAA,aAAa,OAAA;AACb,yGAAA,WAAW,OAAA;AACX,8GAAA,gBAAgB,OAAA;AAChB,8GAAA,gBAAgB,OAAA;AA6BlB,qCAAsC;AAA7B,oGAAA,WAAW,OAAA;AAEpB,qCASiB;AARf,kGAAA,SAAS,OAAA;AACT,kGAAA,SAAS,OAAA;AACT,oGAAA,WAAW,OAAA;AACX,gGAAA,OAAO,OAAA;AACP,sGAAA,aAAa,OAAA;AACb,yGAAA,gBAAgB,OAAA;AAChB,+GAAA,sBAAsB,OAAA;AACtB,gGAAA,OAAO,OAAA;AAGT,iDAe4B;AAd1B,kHAAA,wBAAwB,OAAA;AACxB,wGAAA,cAAc,OAAA;AACd,gHAAA,sBAAsB,OAAA;AACtB,sHAAA,4BAA4B,OAAA;AAC5B,uIAAA,6CAA6C,OAAA;AAC7C,uHAAA,6BAA6B,OAAA;AAC7B,iHAAA,uBAAuB,OAAA;AACvB,4GAAA,kBAAkB,OAAA;AAClB,6GAAA,mBAAmB,OAAA;AACnB,mHAAA,yBAAyB,OAAA;AACzB,yHAAA,+BAA+B,OAAA;AAC/B,yHAAA,+BAA+B,OAAA;AAC/B,iHAAA,uBAAuB,OAAA;AACvB,kHAAA,wBAAwB,OAAA;AAK1B,iDAS4B;AAJ1B;;GAEG;AACH,yHAAA,+BAA+B,OAAA;AAGjC,+CAA0D;AAAjD,8GAAA,qBAAqB,OAAA;AAE9B,6CAOwB;AANtB,6GAAA,mBAAmB,OAAA;AACnB,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,yGAAA,eAAe,OAAA;AACf,kHAAA,wBAAwB,OAAA;AACxB,yHAAA,+BAA+B,OAAA;AAGjC,2CAAwE;AAA/D,4GAAA,mBAAmB,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAEhD,+CAAuD;AAA9C,+GAAA,oBAAoB,OAAA;AAE7B,2CAAkD;AAAzC,0GAAA,iBAAiB,OAAA;AAE1B,+DAIiC;AAH/B,sHAAA,mBAAmB,OAAA;AACnB,qHAAA,kBAAkB,OAAA;AAClB,+HAAA,4BAA4B,OAAA;AAG9B,6CAaqB;AAZnB,+GAAA,kBAAkB,OAAA;AAElB,kIAAA,qCAAqC,OAAA;AACrC;;;;;;GAMG;AACH,iHAAA,oBAAoB,OAAA;AACpB,qHAAA,wBAAwB,OAAA","sourcesContent":["export { BridgeController } from './bridge-controller';\n\nexport {\n UnifiedSwapBridgeEventName,\n UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY,\n} from './utils/metrics/constants';\n\nexport type {\n RequiredEventContextFromClient,\n CrossChainSwapsEventProperties,\n TradeData,\n RequestParams,\n RequestMetadata,\n TxStatusData,\n} from './utils/metrics/types';\n\nexport {\n formatProviderLabel,\n getRequestParams,\n getActionType,\n getSwapType,\n isHardwareWallet,\n isCustomSlippage,\n} from './utils/metrics/properties';\n\nexport type {\n ChainConfiguration,\n L1GasFees,\n SolanaFees,\n QuoteMetadata,\n BridgeToken,\n GasMultiplierByChainId,\n FeatureFlagResponse,\n BridgeAsset,\n GenericQuoteRequest,\n Protocol,\n TokenAmountValues,\n Step,\n RefuelData,\n Quote,\n QuoteResponse,\n FeeData,\n TxData,\n BridgeControllerState,\n BridgeControllerAction,\n BridgeControllerActions,\n BridgeControllerEvents,\n BridgeControllerMessenger,\n FeatureFlagsPlatformConfig,\n} from './types';\n\nexport { StatusTypes } from './types';\n\nexport {\n AssetType,\n SortOrder,\n ActionTypes,\n ChainId,\n RequestStatus,\n BridgeUserAction,\n BridgeBackgroundAction,\n FeeType,\n} from './types';\n\nexport {\n ALLOWED_BRIDGE_CHAIN_IDS,\n BridgeClientId,\n BRIDGE_CONTROLLER_NAME,\n BRIDGE_QUOTE_MAX_ETA_SECONDS,\n BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n BRIDGE_DEFAULT_SLIPPAGE,\n BRIDGE_MM_FEE_RATE,\n REFRESH_INTERVAL_MS,\n DEFAULT_MAX_REFRESH_COUNT,\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP,\n BRIDGE_DEV_API_BASE_URL,\n BRIDGE_PROD_API_BASE_URL,\n} from './constants/bridge';\n\nexport type { AllowedBridgeChainIds } from './constants/bridge';\n\nexport {\n /**\n * @deprecated This type should not be used. Use {@link BridgeAsset} instead.\n */\n type SwapsTokenObject,\n /**\n * @deprecated This map should not be used. Use getNativeAssetForChainId\" } instead.\n */\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n} from './constants/tokens';\n\nexport { SWAPS_API_V2_BASE_URL } from './constants/swaps';\n\nexport {\n getEthUsdtResetData,\n isEthUsdt,\n isNativeAddress,\n isSolanaChainId,\n getNativeAssetForChainId,\n getDefaultBridgeControllerState,\n} from './utils/bridge';\n\nexport { isValidQuoteRequest, formatEtaInMinutes } from './utils/quote';\n\nexport { calcLatestSrcBalance } from './utils/balance';\n\nexport { fetchBridgeTokens } from './utils/fetch';\n\nexport {\n formatChainIdToCaip,\n formatChainIdToHex,\n formatAddressToCaipReference,\n} from './utils/caip-formatters';\n\nexport {\n selectBridgeQuotes,\n type BridgeAppState,\n selectExchangeRateByChainIdAndAddress,\n /**\n * Returns whether a quote is expired\n *\n * @param state The state of the bridge controller and its dependency controllers\n * @param currentTimeInMs The current timestamp in milliseconds (e.g. `Date.now()`)\n * @returns Whether the quote is expired\n */\n selectIsQuoteExpired,\n selectBridgeFeatureFlags,\n} from './selectors';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,6DAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AAEzB,2DAGmC;AAFjC,uHAAA,0BAA0B,OAAA;AAC1B,+HAAA,kCAAkC,OAAA;AAYpC,6DAOoC;AANlC,iHAAA,mBAAmB,OAAA;AACnB,8GAAA,gBAAgB,OAAA;AAChB,2GAAA,aAAa,OAAA;AACb,yGAAA,WAAW,OAAA;AACX,8GAAA,gBAAgB,OAAA;AAChB,8GAAA,gBAAgB,OAAA;AA4BlB,qCAAsC;AAA7B,oGAAA,WAAW,OAAA;AAEpB,qCASiB;AARf,kGAAA,SAAS,OAAA;AACT,kGAAA,SAAS,OAAA;AACT,oGAAA,WAAW,OAAA;AACX,gGAAA,OAAO,OAAA;AACP,sGAAA,aAAa,OAAA;AACb,yGAAA,gBAAgB,OAAA;AAChB,+GAAA,sBAAsB,OAAA;AACtB,gGAAA,OAAO,OAAA;AAGT,iDAe4B;AAd1B,kHAAA,wBAAwB,OAAA;AACxB,wGAAA,cAAc,OAAA;AACd,gHAAA,sBAAsB,OAAA;AACtB,sHAAA,4BAA4B,OAAA;AAC5B,uIAAA,6CAA6C,OAAA;AAC7C,uHAAA,6BAA6B,OAAA;AAC7B,iHAAA,uBAAuB,OAAA;AACvB,4GAAA,kBAAkB,OAAA;AAClB,6GAAA,mBAAmB,OAAA;AACnB,mHAAA,yBAAyB,OAAA;AACzB,yHAAA,+BAA+B,OAAA;AAC/B,yHAAA,+BAA+B,OAAA;AAC/B,iHAAA,uBAAuB,OAAA;AACvB,kHAAA,wBAAwB,OAAA;AAK1B,iDAS4B;AAJ1B;;GAEG;AACH,yHAAA,+BAA+B,OAAA;AAGjC,+CAA0D;AAAjD,8GAAA,qBAAqB,OAAA;AAE9B,6CAQwB;AAPtB,6GAAA,mBAAmB,OAAA;AACnB,mGAAA,SAAS,OAAA;AACT,yGAAA,eAAe,OAAA;AACf,yGAAA,eAAe,OAAA;AACf,kHAAA,wBAAwB,OAAA;AACxB,yHAAA,+BAA+B,OAAA;AAC/B,sGAAA,YAAY,OAAA;AAGd,2CAAwE;AAA/D,4GAAA,mBAAmB,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAEhD,+CAAuD;AAA9C,+GAAA,oBAAoB,OAAA;AAE7B,2CAAkD;AAAzC,0GAAA,iBAAiB,OAAA;AAE1B,+DAIiC;AAH/B,sHAAA,mBAAmB,OAAA;AACnB,qHAAA,kBAAkB,OAAA;AAClB,+HAAA,4BAA4B,OAAA;AAG9B,6CAaqB;AAZnB,+GAAA,kBAAkB,OAAA;AAElB,kIAAA,qCAAqC,OAAA;AACrC;;;;;;GAMG;AACH,iHAAA,oBAAoB,OAAA;AACpB,qHAAA,wBAAwB,OAAA","sourcesContent":["export { BridgeController } from './bridge-controller';\n\nexport {\n UnifiedSwapBridgeEventName,\n UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY,\n} from './utils/metrics/constants';\n\nexport type {\n RequiredEventContextFromClient,\n CrossChainSwapsEventProperties,\n TradeData,\n RequestParams,\n RequestMetadata,\n TxStatusData,\n} from './utils/metrics/types';\n\nexport {\n formatProviderLabel,\n getRequestParams,\n getActionType,\n getSwapType,\n isHardwareWallet,\n isCustomSlippage,\n} from './utils/metrics/properties';\n\nexport type {\n ChainConfiguration,\n L1GasFees,\n SolanaFees,\n QuoteMetadata,\n GasMultiplierByChainId,\n FeatureFlagResponse,\n BridgeAsset,\n GenericQuoteRequest,\n Protocol,\n TokenAmountValues,\n Step,\n RefuelData,\n Quote,\n QuoteResponse,\n FeeData,\n TxData,\n BridgeControllerState,\n BridgeControllerAction,\n BridgeControllerActions,\n BridgeControllerEvents,\n BridgeControllerMessenger,\n FeatureFlagsPlatformConfig,\n} from './types';\n\nexport { StatusTypes } from './types';\n\nexport {\n AssetType,\n SortOrder,\n ActionTypes,\n ChainId,\n RequestStatus,\n BridgeUserAction,\n BridgeBackgroundAction,\n FeeType,\n} from './types';\n\nexport {\n ALLOWED_BRIDGE_CHAIN_IDS,\n BridgeClientId,\n BRIDGE_CONTROLLER_NAME,\n BRIDGE_QUOTE_MAX_ETA_SECONDS,\n BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n BRIDGE_DEFAULT_SLIPPAGE,\n BRIDGE_MM_FEE_RATE,\n REFRESH_INTERVAL_MS,\n DEFAULT_MAX_REFRESH_COUNT,\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP,\n BRIDGE_DEV_API_BASE_URL,\n BRIDGE_PROD_API_BASE_URL,\n} from './constants/bridge';\n\nexport type { AllowedBridgeChainIds } from './constants/bridge';\n\nexport {\n /**\n * @deprecated This type should not be used. Use {@link BridgeAsset} instead.\n */\n type SwapsTokenObject,\n /**\n * @deprecated This map should not be used. Use getNativeAssetForChainId\" } instead.\n */\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n} from './constants/tokens';\n\nexport { SWAPS_API_V2_BASE_URL } from './constants/swaps';\n\nexport {\n getEthUsdtResetData,\n isEthUsdt,\n isNativeAddress,\n isSolanaChainId,\n getNativeAssetForChainId,\n getDefaultBridgeControllerState,\n isCrossChain,\n} from './utils/bridge';\n\nexport { isValidQuoteRequest, formatEtaInMinutes } from './utils/quote';\n\nexport { calcLatestSrcBalance } from './utils/balance';\n\nexport { fetchBridgeTokens } from './utils/fetch';\n\nexport {\n formatChainIdToCaip,\n formatChainIdToHex,\n formatAddressToCaipReference,\n} from './utils/caip-formatters';\n\nexport {\n selectBridgeQuotes,\n type BridgeAppState,\n selectExchangeRateByChainIdAndAddress,\n /**\n * Returns whether a quote is expired\n *\n * @param state The state of the bridge controller and its dependency controllers\n * @param currentTimeInMs The current timestamp in milliseconds (e.g. `Date.now()`)\n * @returns Whether the quote is expired\n */\n selectIsQuoteExpired,\n selectBridgeFeatureFlags,\n} from './selectors';\n"]}
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ export { BridgeController } from "./bridge-controller.cjs";
2
2
  export { UnifiedSwapBridgeEventName, UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY, } from "./utils/metrics/constants.cjs";
3
3
  export type { RequiredEventContextFromClient, CrossChainSwapsEventProperties, TradeData, RequestParams, RequestMetadata, TxStatusData, } from "./utils/metrics/types.cjs";
4
4
  export { formatProviderLabel, getRequestParams, getActionType, getSwapType, isHardwareWallet, isCustomSlippage, } from "./utils/metrics/properties.cjs";
5
- export type { ChainConfiguration, L1GasFees, SolanaFees, QuoteMetadata, BridgeToken, GasMultiplierByChainId, FeatureFlagResponse, BridgeAsset, GenericQuoteRequest, Protocol, TokenAmountValues, Step, RefuelData, Quote, QuoteResponse, FeeData, TxData, BridgeControllerState, BridgeControllerAction, BridgeControllerActions, BridgeControllerEvents, BridgeControllerMessenger, FeatureFlagsPlatformConfig, } from "./types.cjs";
5
+ export type { ChainConfiguration, L1GasFees, SolanaFees, QuoteMetadata, GasMultiplierByChainId, FeatureFlagResponse, BridgeAsset, GenericQuoteRequest, Protocol, TokenAmountValues, Step, RefuelData, Quote, QuoteResponse, FeeData, TxData, BridgeControllerState, BridgeControllerAction, BridgeControllerActions, BridgeControllerEvents, BridgeControllerMessenger, FeatureFlagsPlatformConfig, } from "./types.cjs";
6
6
  export { StatusTypes } from "./types.cjs";
7
7
  export { AssetType, SortOrder, ActionTypes, ChainId, RequestStatus, BridgeUserAction, BridgeBackgroundAction, FeeType, } from "./types.cjs";
8
8
  export { ALLOWED_BRIDGE_CHAIN_IDS, BridgeClientId, BRIDGE_CONTROLLER_NAME, BRIDGE_QUOTE_MAX_ETA_SECONDS, BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE, BRIDGE_PREFERRED_GAS_ESTIMATE, BRIDGE_DEFAULT_SLIPPAGE, BRIDGE_MM_FEE_RATE, REFRESH_INTERVAL_MS, DEFAULT_MAX_REFRESH_COUNT, DEFAULT_BRIDGE_CONTROLLER_STATE, METABRIDGE_CHAIN_TO_ADDRESS_MAP, BRIDGE_DEV_API_BASE_URL, BRIDGE_PROD_API_BASE_URL, } from "./constants/bridge.cjs";
@@ -17,7 +17,7 @@ type SwapsTokenObject,
17
17
  */
18
18
  SWAPS_CHAINID_DEFAULT_TOKEN_MAP, } from "./constants/tokens.cjs";
19
19
  export { SWAPS_API_V2_BASE_URL } from "./constants/swaps.cjs";
20
- export { getEthUsdtResetData, isEthUsdt, isNativeAddress, isSolanaChainId, getNativeAssetForChainId, getDefaultBridgeControllerState, } from "./utils/bridge.cjs";
20
+ export { getEthUsdtResetData, isEthUsdt, isNativeAddress, isSolanaChainId, getNativeAssetForChainId, getDefaultBridgeControllerState, isCrossChain, } from "./utils/bridge.cjs";
21
21
  export { isValidQuoteRequest, formatEtaInMinutes } from "./utils/quote.cjs";
22
22
  export { calcLatestSrcBalance } from "./utils/balance.cjs";
23
23
  export { fetchBridgeTokens } from "./utils/fetch.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EACL,0BAA0B,EAC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,mBAAmB,EAAE,kBAAkB,EAAE,0BAAsB;AAExE,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AAEvD,OAAO,EAAE,iBAAiB,EAAE,0BAAsB;AAElD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,GAC7B,oCAAgC;AAEjC,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,qCAAqC;AACrC;;;;;;GAMG;AACH,oBAAoB,EACpB,wBAAwB,GACzB,wBAAoB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,GACnC,sCAAkC;AAEnC,YAAY,EACV,8BAA8B,EAC9B,8BAA8B,EAC9B,SAAS,EACT,aAAa,EACb,eAAe,EACf,YAAY,GACb,kCAA8B;AAE/B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GACjB,uCAAmC;AAEpC,YAAY,EACV,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,EACjB,IAAI,EACJ,UAAU,EACV,KAAK,EACL,aAAa,EACb,OAAO,EACP,MAAM,EACN,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,GAC3B,oBAAgB;AAEjB,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,OAAO,GACR,oBAAgB;AAEjB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,6CAA6C,EAC7C,6BAA6B,EAC7B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,GACzB,+BAA2B;AAE5B,YAAY,EAAE,qBAAqB,EAAE,+BAA2B;AAEhE,OAAO;AACL;;GAEG;AACH,KAAK,gBAAgB;AACrB;;GAEG;AACH,+BAA+B,GAChC,+BAA2B;AAE5B,OAAO,EAAE,qBAAqB,EAAE,8BAA0B;AAE1D,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,+BAA+B,EAC/B,YAAY,GACb,2BAAuB;AAExB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,0BAAsB;AAExE,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AAEvD,OAAO,EAAE,iBAAiB,EAAE,0BAAsB;AAElD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,GAC7B,oCAAgC;AAEjC,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,qCAAqC;AACrC;;;;;;GAMG;AACH,oBAAoB,EACpB,wBAAwB,GACzB,wBAAoB"}
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ export { BridgeController } from "./bridge-controller.mjs";
2
2
  export { UnifiedSwapBridgeEventName, UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY, } from "./utils/metrics/constants.mjs";
3
3
  export type { RequiredEventContextFromClient, CrossChainSwapsEventProperties, TradeData, RequestParams, RequestMetadata, TxStatusData, } from "./utils/metrics/types.mjs";
4
4
  export { formatProviderLabel, getRequestParams, getActionType, getSwapType, isHardwareWallet, isCustomSlippage, } from "./utils/metrics/properties.mjs";
5
- export type { ChainConfiguration, L1GasFees, SolanaFees, QuoteMetadata, BridgeToken, GasMultiplierByChainId, FeatureFlagResponse, BridgeAsset, GenericQuoteRequest, Protocol, TokenAmountValues, Step, RefuelData, Quote, QuoteResponse, FeeData, TxData, BridgeControllerState, BridgeControllerAction, BridgeControllerActions, BridgeControllerEvents, BridgeControllerMessenger, FeatureFlagsPlatformConfig, } from "./types.mjs";
5
+ export type { ChainConfiguration, L1GasFees, SolanaFees, QuoteMetadata, GasMultiplierByChainId, FeatureFlagResponse, BridgeAsset, GenericQuoteRequest, Protocol, TokenAmountValues, Step, RefuelData, Quote, QuoteResponse, FeeData, TxData, BridgeControllerState, BridgeControllerAction, BridgeControllerActions, BridgeControllerEvents, BridgeControllerMessenger, FeatureFlagsPlatformConfig, } from "./types.mjs";
6
6
  export { StatusTypes } from "./types.mjs";
7
7
  export { AssetType, SortOrder, ActionTypes, ChainId, RequestStatus, BridgeUserAction, BridgeBackgroundAction, FeeType, } from "./types.mjs";
8
8
  export { ALLOWED_BRIDGE_CHAIN_IDS, BridgeClientId, BRIDGE_CONTROLLER_NAME, BRIDGE_QUOTE_MAX_ETA_SECONDS, BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE, BRIDGE_PREFERRED_GAS_ESTIMATE, BRIDGE_DEFAULT_SLIPPAGE, BRIDGE_MM_FEE_RATE, REFRESH_INTERVAL_MS, DEFAULT_MAX_REFRESH_COUNT, DEFAULT_BRIDGE_CONTROLLER_STATE, METABRIDGE_CHAIN_TO_ADDRESS_MAP, BRIDGE_DEV_API_BASE_URL, BRIDGE_PROD_API_BASE_URL, } from "./constants/bridge.mjs";
@@ -17,7 +17,7 @@ type SwapsTokenObject,
17
17
  */
18
18
  SWAPS_CHAINID_DEFAULT_TOKEN_MAP, } from "./constants/tokens.mjs";
19
19
  export { SWAPS_API_V2_BASE_URL } from "./constants/swaps.mjs";
20
- export { getEthUsdtResetData, isEthUsdt, isNativeAddress, isSolanaChainId, getNativeAssetForChainId, getDefaultBridgeControllerState, } from "./utils/bridge.mjs";
20
+ export { getEthUsdtResetData, isEthUsdt, isNativeAddress, isSolanaChainId, getNativeAssetForChainId, getDefaultBridgeControllerState, isCrossChain, } from "./utils/bridge.mjs";
21
21
  export { isValidQuoteRequest, formatEtaInMinutes } from "./utils/quote.mjs";
22
22
  export { calcLatestSrcBalance } from "./utils/balance.mjs";
23
23
  export { fetchBridgeTokens } from "./utils/fetch.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,GACnC,sCAAkC;AAEnC,YAAY,EACV,8BAA8B,EAC9B,8BAA8B,EAC9B,SAAS,EACT,aAAa,EACb,eAAe,EACf,YAAY,GACb,kCAA8B;AAE/B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GACjB,uCAAmC;AAEpC,YAAY,EACV,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,EACjB,IAAI,EACJ,UAAU,EACV,KAAK,EACL,aAAa,EACb,OAAO,EACP,MAAM,EACN,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,GAC3B,oBAAgB;AAEjB,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,OAAO,GACR,oBAAgB;AAEjB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,6CAA6C,EAC7C,6BAA6B,EAC7B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,GACzB,+BAA2B;AAE5B,YAAY,EAAE,qBAAqB,EAAE,+BAA2B;AAEhE,OAAO;AACL;;GAEG;AACH,KAAK,gBAAgB;AACrB;;GAEG;AACH,+BAA+B,GAChC,+BAA2B;AAE5B,OAAO,EAAE,qBAAqB,EAAE,8BAA0B;AAE1D,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,+BAA+B,GAChC,2BAAuB;AAExB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,0BAAsB;AAExE,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AAEvD,OAAO,EAAE,iBAAiB,EAAE,0BAAsB;AAElD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,GAC7B,oCAAgC;AAEjC,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,qCAAqC;AACrC;;;;;;GAMG;AACH,oBAAoB,EACpB,wBAAwB,GACzB,wBAAoB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,GACnC,sCAAkC;AAEnC,YAAY,EACV,8BAA8B,EAC9B,8BAA8B,EAC9B,SAAS,EACT,aAAa,EACb,eAAe,EACf,YAAY,GACb,kCAA8B;AAE/B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GACjB,uCAAmC;AAEpC,YAAY,EACV,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,iBAAiB,EACjB,IAAI,EACJ,UAAU,EACV,KAAK,EACL,aAAa,EACb,OAAO,EACP,MAAM,EACN,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,GAC3B,oBAAgB;AAEjB,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,OAAO,GACR,oBAAgB;AAEjB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,6CAA6C,EAC7C,6BAA6B,EAC7B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,GACzB,+BAA2B;AAE5B,YAAY,EAAE,qBAAqB,EAAE,+BAA2B;AAEhE,OAAO;AACL;;GAEG;AACH,KAAK,gBAAgB;AACrB;;GAEG;AACH,+BAA+B,GAChC,+BAA2B;AAE5B,OAAO,EAAE,qBAAqB,EAAE,8BAA0B;AAE1D,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,+BAA+B,EAC/B,YAAY,GACb,2BAAuB;AAExB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,0BAAsB;AAExE,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AAEvD,OAAO,EAAE,iBAAiB,EAAE,0BAAsB;AAElD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,GAC7B,oCAAgC;AAEjC,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,qCAAqC;AACrC;;;;;;GAMG;AACH,oBAAoB,EACpB,wBAAwB,GACzB,wBAAoB"}
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ export {
10
10
  */
11
11
  SWAPS_CHAINID_DEFAULT_TOKEN_MAP } from "./constants/tokens.mjs";
12
12
  export { SWAPS_API_V2_BASE_URL } from "./constants/swaps.mjs";
13
- export { getEthUsdtResetData, isEthUsdt, isNativeAddress, isSolanaChainId, getNativeAssetForChainId, getDefaultBridgeControllerState } from "./utils/bridge.mjs";
13
+ export { getEthUsdtResetData, isEthUsdt, isNativeAddress, isSolanaChainId, getNativeAssetForChainId, getDefaultBridgeControllerState, isCrossChain } from "./utils/bridge.mjs";
14
14
  export { isValidQuoteRequest, formatEtaInMinutes } from "./utils/quote.mjs";
15
15
  export { calcLatestSrcBalance } from "./utils/balance.mjs";
16
16
  export { fetchBridgeTokens } from "./utils/fetch.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,EACnC,sCAAkC;AAWnC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EACjB,uCAAmC;AA4BpC,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,OAAO,EACR,oBAAgB;AAEjB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,6CAA6C,EAC7C,6BAA6B,EAC7B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,EACzB,+BAA2B;AAI5B,OAAO;AAKL;;GAEG;AACH,+BAA+B,EAChC,+BAA2B;AAE5B,OAAO,EAAE,qBAAqB,EAAE,8BAA0B;AAE1D,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,+BAA+B,EAChC,2BAAuB;AAExB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,0BAAsB;AAExE,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AAEvD,OAAO,EAAE,iBAAiB,EAAE,0BAAsB;AAElD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC7B,oCAAgC;AAEjC,OAAO,EACL,kBAAkB,EAElB,qCAAqC;AACrC;;;;;;GAMG;AACH,oBAAoB,EACpB,wBAAwB,EACzB,wBAAoB","sourcesContent":["export { BridgeController } from './bridge-controller';\n\nexport {\n UnifiedSwapBridgeEventName,\n UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY,\n} from './utils/metrics/constants';\n\nexport type {\n RequiredEventContextFromClient,\n CrossChainSwapsEventProperties,\n TradeData,\n RequestParams,\n RequestMetadata,\n TxStatusData,\n} from './utils/metrics/types';\n\nexport {\n formatProviderLabel,\n getRequestParams,\n getActionType,\n getSwapType,\n isHardwareWallet,\n isCustomSlippage,\n} from './utils/metrics/properties';\n\nexport type {\n ChainConfiguration,\n L1GasFees,\n SolanaFees,\n QuoteMetadata,\n BridgeToken,\n GasMultiplierByChainId,\n FeatureFlagResponse,\n BridgeAsset,\n GenericQuoteRequest,\n Protocol,\n TokenAmountValues,\n Step,\n RefuelData,\n Quote,\n QuoteResponse,\n FeeData,\n TxData,\n BridgeControllerState,\n BridgeControllerAction,\n BridgeControllerActions,\n BridgeControllerEvents,\n BridgeControllerMessenger,\n FeatureFlagsPlatformConfig,\n} from './types';\n\nexport { StatusTypes } from './types';\n\nexport {\n AssetType,\n SortOrder,\n ActionTypes,\n ChainId,\n RequestStatus,\n BridgeUserAction,\n BridgeBackgroundAction,\n FeeType,\n} from './types';\n\nexport {\n ALLOWED_BRIDGE_CHAIN_IDS,\n BridgeClientId,\n BRIDGE_CONTROLLER_NAME,\n BRIDGE_QUOTE_MAX_ETA_SECONDS,\n BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n BRIDGE_DEFAULT_SLIPPAGE,\n BRIDGE_MM_FEE_RATE,\n REFRESH_INTERVAL_MS,\n DEFAULT_MAX_REFRESH_COUNT,\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP,\n BRIDGE_DEV_API_BASE_URL,\n BRIDGE_PROD_API_BASE_URL,\n} from './constants/bridge';\n\nexport type { AllowedBridgeChainIds } from './constants/bridge';\n\nexport {\n /**\n * @deprecated This type should not be used. Use {@link BridgeAsset} instead.\n */\n type SwapsTokenObject,\n /**\n * @deprecated This map should not be used. Use getNativeAssetForChainId\" } instead.\n */\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n} from './constants/tokens';\n\nexport { SWAPS_API_V2_BASE_URL } from './constants/swaps';\n\nexport {\n getEthUsdtResetData,\n isEthUsdt,\n isNativeAddress,\n isSolanaChainId,\n getNativeAssetForChainId,\n getDefaultBridgeControllerState,\n} from './utils/bridge';\n\nexport { isValidQuoteRequest, formatEtaInMinutes } from './utils/quote';\n\nexport { calcLatestSrcBalance } from './utils/balance';\n\nexport { fetchBridgeTokens } from './utils/fetch';\n\nexport {\n formatChainIdToCaip,\n formatChainIdToHex,\n formatAddressToCaipReference,\n} from './utils/caip-formatters';\n\nexport {\n selectBridgeQuotes,\n type BridgeAppState,\n selectExchangeRateByChainIdAndAddress,\n /**\n * Returns whether a quote is expired\n *\n * @param state The state of the bridge controller and its dependency controllers\n * @param currentTimeInMs The current timestamp in milliseconds (e.g. `Date.now()`)\n * @returns Whether the quote is expired\n */\n selectIsQuoteExpired,\n selectBridgeFeatureFlags,\n} from './selectors';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,EACnC,sCAAkC;AAWnC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EACjB,uCAAmC;AA2BpC,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,OAAO,EACR,oBAAgB;AAEjB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,6CAA6C,EAC7C,6BAA6B,EAC7B,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,EACzB,+BAA2B;AAI5B,OAAO;AAKL;;GAEG;AACH,+BAA+B,EAChC,+BAA2B;AAE5B,OAAO,EAAE,qBAAqB,EAAE,8BAA0B;AAE1D,OAAO,EACL,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,+BAA+B,EAC/B,YAAY,EACb,2BAAuB;AAExB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,0BAAsB;AAExE,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AAEvD,OAAO,EAAE,iBAAiB,EAAE,0BAAsB;AAElD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC7B,oCAAgC;AAEjC,OAAO,EACL,kBAAkB,EAElB,qCAAqC;AACrC;;;;;;GAMG;AACH,oBAAoB,EACpB,wBAAwB,EACzB,wBAAoB","sourcesContent":["export { BridgeController } from './bridge-controller';\n\nexport {\n UnifiedSwapBridgeEventName,\n UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY,\n} from './utils/metrics/constants';\n\nexport type {\n RequiredEventContextFromClient,\n CrossChainSwapsEventProperties,\n TradeData,\n RequestParams,\n RequestMetadata,\n TxStatusData,\n} from './utils/metrics/types';\n\nexport {\n formatProviderLabel,\n getRequestParams,\n getActionType,\n getSwapType,\n isHardwareWallet,\n isCustomSlippage,\n} from './utils/metrics/properties';\n\nexport type {\n ChainConfiguration,\n L1GasFees,\n SolanaFees,\n QuoteMetadata,\n GasMultiplierByChainId,\n FeatureFlagResponse,\n BridgeAsset,\n GenericQuoteRequest,\n Protocol,\n TokenAmountValues,\n Step,\n RefuelData,\n Quote,\n QuoteResponse,\n FeeData,\n TxData,\n BridgeControllerState,\n BridgeControllerAction,\n BridgeControllerActions,\n BridgeControllerEvents,\n BridgeControllerMessenger,\n FeatureFlagsPlatformConfig,\n} from './types';\n\nexport { StatusTypes } from './types';\n\nexport {\n AssetType,\n SortOrder,\n ActionTypes,\n ChainId,\n RequestStatus,\n BridgeUserAction,\n BridgeBackgroundAction,\n FeeType,\n} from './types';\n\nexport {\n ALLOWED_BRIDGE_CHAIN_IDS,\n BridgeClientId,\n BRIDGE_CONTROLLER_NAME,\n BRIDGE_QUOTE_MAX_ETA_SECONDS,\n BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE,\n BRIDGE_PREFERRED_GAS_ESTIMATE,\n BRIDGE_DEFAULT_SLIPPAGE,\n BRIDGE_MM_FEE_RATE,\n REFRESH_INTERVAL_MS,\n DEFAULT_MAX_REFRESH_COUNT,\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n METABRIDGE_CHAIN_TO_ADDRESS_MAP,\n BRIDGE_DEV_API_BASE_URL,\n BRIDGE_PROD_API_BASE_URL,\n} from './constants/bridge';\n\nexport type { AllowedBridgeChainIds } from './constants/bridge';\n\nexport {\n /**\n * @deprecated This type should not be used. Use {@link BridgeAsset} instead.\n */\n type SwapsTokenObject,\n /**\n * @deprecated This map should not be used. Use getNativeAssetForChainId\" } instead.\n */\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n} from './constants/tokens';\n\nexport { SWAPS_API_V2_BASE_URL } from './constants/swaps';\n\nexport {\n getEthUsdtResetData,\n isEthUsdt,\n isNativeAddress,\n isSolanaChainId,\n getNativeAssetForChainId,\n getDefaultBridgeControllerState,\n isCrossChain,\n} from './utils/bridge';\n\nexport { isValidQuoteRequest, formatEtaInMinutes } from './utils/quote';\n\nexport { calcLatestSrcBalance } from './utils/balance';\n\nexport { fetchBridgeTokens } from './utils/fetch';\n\nexport {\n formatChainIdToCaip,\n formatChainIdToHex,\n formatAddressToCaipReference,\n} from './utils/caip-formatters';\n\nexport {\n selectBridgeQuotes,\n type BridgeAppState,\n selectExchangeRateByChainIdAndAddress,\n /**\n * Returns whether a quote is expired\n *\n * @param state The state of the bridge controller and its dependency controllers\n * @param currentTimeInMs The current timestamp in milliseconds (e.g. `Date.now()`)\n * @returns Whether the quote is expired\n */\n selectIsQuoteExpired,\n selectBridgeFeatureFlags,\n} from './selectors';\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSolanaChainId = exports.isNativeAddress = exports.isSwapsDefaultTokenSymbol = exports.isSwapsDefaultTokenAddress = exports.sumHexes = exports.isEthUsdt = exports.getEthUsdtResetData = exports.getNativeAssetForChainId = exports.getDefaultBridgeControllerState = void 0;
3
+ exports.isCrossChain = exports.isSolanaChainId = exports.isNativeAddress = exports.isSwapsDefaultTokenSymbol = exports.isSwapsDefaultTokenAddress = exports.sumHexes = exports.isEthUsdt = exports.getEthUsdtResetData = exports.getNativeAssetForChainId = exports.getDefaultBridgeControllerState = void 0;
4
4
  const constants_1 = require("@ethersproject/constants");
5
5
  const contracts_1 = require("@ethersproject/contracts");
6
6
  const keyring_api_1 = require("@metamask/keyring-api");
@@ -128,4 +128,23 @@ const isSolanaChainId = (chainId) => {
128
128
  return chainId.toString() === types_1.ChainId.SOLANA.toString();
129
129
  };
130
130
  exports.isSolanaChainId = isSolanaChainId;
131
+ /**
132
+ * Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds
133
+ *
134
+ * @param srcChainId - The source chainId
135
+ * @param destChainId - The destination chainId
136
+ * @returns Whether the transaction is a cross-chain transaction
137
+ */
138
+ const isCrossChain = (srcChainId, destChainId) => {
139
+ try {
140
+ if (!destChainId) {
141
+ return false;
142
+ }
143
+ return (0, caip_formatters_1.formatChainIdToCaip)(srcChainId) !== (0, caip_formatters_1.formatChainIdToCaip)(destChainId);
144
+ }
145
+ catch {
146
+ return false;
147
+ }
148
+ };
149
+ exports.isCrossChain = isCrossChain;
131
150
  //# sourceMappingURL=bridge.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,wDAAuD;AACvD,wDAAoD;AACpD,uDAAiD;AACjD,mEAAuD;AAEvD,2CAA6E;AAE7E,2DAI2B;AAC3B,oDAI6B;AAC7B,oDAAgD;AAChD,oDAI6B;AAE7B,wCAAmC;AAE5B,MAAM,+BAA+B,GAAG,GAA0B,EAAE;IACzE,OAAO,wCAA+B,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,+BAA+B,mCAE1C;AAEF;;;;;;;GAOG;AACH,MAAM,2BAA2B,GAAG,CAClC,OAAoB,EACpB,oBAAyD,EAC1C,EAAE;IACjB,OAAO,GAAG,IAAA,qCAAmB,EAAC,OAAO,CAAC,IAAI,6BAAoB,CAAC,oBAAoB,CAAC,EAAE,CAAC;AACzF,CAAC,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,wBAAwB,GAAG,CACtC,OAA4C,EAC/B,EAAE;IACf,MAAM,aAAa,GAAG,IAAA,qCAAmB,EAAC,OAAO,CAAC,CAAC;IACnD,MAAM,WAAW,GACf,wCAA+B,CAC7B,IAAA,qCAAmB,EACjB,OAAO,CACwC,CAClD;QACD,wCAA+B,CAC7B,IAAA,oCAAkB,EAChB,OAAO,CACwC,CAClD,CAAC;IAEJ,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CACb,mDAAmD,OAAO,EAAE,CAC7D,CAAC;KACH;IAED,OAAO;QACL,GAAG,WAAW;QACd,OAAO,EAAE,IAAA,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Zero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { SolScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { CaipAssetType, CaipChainId } from '@metamask/utils';\nimport { isCaipChainId, isStrictHexString, type Hex } from '@metamask/utils';\n\nimport {\n formatChainIdToCaip,\n formatChainIdToDec,\n formatChainIdToHex,\n} from './caip-formatters';\nimport {\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n ETH_USDT_ADDRESS,\n METABRIDGE_ETHEREUM_ADDRESS,\n} from '../constants/bridge';\nimport { CHAIN_IDS } from '../constants/chains';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n type SupportedSwapsNativeCurrencySymbols,\n} from '../constants/tokens';\nimport type { BridgeAsset, BridgeControllerState } from '../types';\nimport { ChainId } from '../types';\n\nexport const getDefaultBridgeControllerState = (): BridgeControllerState => {\n return DEFAULT_BRIDGE_CONTROLLER_STATE;\n};\n\n/**\n * Returns the native assetType for a given chainId and native currency symbol\n * Note that the return value is used as the assetId although it is a CaipAssetType\n *\n * @param chainId - The chainId to get the native assetType for\n * @param nativeCurrencySymbol - The native currency symbol for the given chainId\n * @returns The native assetType for the given chainId\n */\nconst getNativeAssetCaipAssetType = (\n chainId: CaipChainId,\n nativeCurrencySymbol: SupportedSwapsNativeCurrencySymbols,\n): CaipAssetType => {\n return `${formatChainIdToCaip(chainId)}/${SYMBOL_TO_SLIP44_MAP[nativeCurrencySymbol]}`;\n};\n\n/**\n * Returns the native swaps or bridge asset for a given chainId\n *\n * @param chainId - The chainId to get the default token for\n * @returns The native asset for the given chainId\n * @throws If no native asset is defined for the given chainId\n */\nexport const getNativeAssetForChainId = (\n chainId: string | number | Hex | CaipChainId,\n): BridgeAsset => {\n const chainIdInCaip = formatChainIdToCaip(chainId);\n const nativeToken =\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToCaip(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ] ??\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToHex(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ];\n\n if (!nativeToken) {\n throw new Error(\n `No XChain Swaps native asset found for chainId: ${chainId}`,\n );\n }\n\n return {\n ...nativeToken,\n chainId: formatChainIdToDec(chainId),\n assetId: getNativeAssetCaipAssetType(chainIdInCaip, nativeToken.symbol),\n };\n};\n\n/**\n * A function to return the txParam data for setting allowance to 0 for USDT on Ethereum\n *\n * @returns The txParam data that will reset allowance to 0, combine it with the approval tx params received from Bridge API\n */\nexport const getEthUsdtResetData = () => {\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n METABRIDGE_ETHEREUM_ADDRESS,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (chainId: Hex, address: string) =>\n chainId === CHAIN_IDS.MAINNET &&\n address.toLowerCase() === ETH_USDT_ADDRESS.toLowerCase();\n\nexport const sumHexes = (...hexStrings: string[]): Hex => {\n if (hexStrings.length === 0) {\n return '0x0';\n }\n\n const sum = hexStrings.reduce((acc, hex) => acc + BigInt(hex), BigInt(0));\n return `0x${sum.toString(16)}`;\n};\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nexport const isSwapsDefaultTokenAddress = (\n address: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!address || !chainId) {\n return false;\n }\n\n return address === getNativeAssetForChainId(chainId)?.address;\n};\n\n/**\n * Checks whether the provided symbol is strictly equal to the symbol for\n * the default swaps token of the provided chain.\n *\n * @param symbol - The string to compare to the default token symbol\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the symbol is the provided chain's default token symbol\n */\nexport const isSwapsDefaultTokenSymbol = (\n symbol: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!symbol || !chainId) {\n return false;\n }\n\n return symbol === getNativeAssetForChainId(chainId)?.symbol;\n};\n\n/**\n * Checks whether the address is a native asset in any supported xchain swaps network\n *\n * @param address - The address to check\n * @returns Whether the address is a native asset\n */\nexport const isNativeAddress = (address?: string | null) =>\n address === AddressZero || // bridge and swap apis set the native asset address to zero\n address === '' || // assets controllers set the native asset address to an empty string\n !address ||\n address.endsWith('11111111111111111111111111111111') || // token-api and bridge-api use this as the solana native assetId\n [getNativeAssetForChainId(ChainId.SOLANA).assetId].some(\n (assetId) => assetId.includes(address) && !isStrictHexString(address),\n ); // solana native assetId used in the extension client\n\n/**\n * Checks whether the chainId matches Solana in CaipChainId or number format\n *\n * @param chainId - The chainId to check\n * @returns Whether the chainId is Solana\n */\nexport const isSolanaChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === SolScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.SOLANA.toString();\n};\n"]}
1
+ {"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,wDAAuD;AACvD,wDAAoD;AACpD,uDAAiD;AACjD,mEAAuD;AAEvD,2CAA6E;AAE7E,2DAI2B;AAC3B,oDAI6B;AAC7B,oDAAgD;AAChD,oDAI6B;AAM7B,wCAAmC;AAE5B,MAAM,+BAA+B,GAAG,GAA0B,EAAE;IACzE,OAAO,wCAA+B,CAAC;AACzC,CAAC,CAAC;AAFW,QAAA,+BAA+B,mCAE1C;AAEF;;;;;;;GAOG;AACH,MAAM,2BAA2B,GAAG,CAClC,OAAoB,EACpB,oBAAyD,EAC1C,EAAE;IACjB,OAAO,GAAG,IAAA,qCAAmB,EAAC,OAAO,CAAC,IAAI,6BAAoB,CAAC,oBAAoB,CAAC,EAAE,CAAC;A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IAAI,CAAC,IAAA,yBAAiB,EAAC,OAAO,CAAC,CACtE,CAAC,CAAC,qDAAqD;AAP7C,QAAA,eAAe,mBAOxB;AAEJ;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAC7B,OAA4C,EAC5C,EAAE;IACF,IAAI,IAAA,qBAAa,EAAC,OAAO,CAAC,EAAE;QAC1B,OAAO,OAAO,KAAK,sBAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;KAChD;IACD,OAAO,OAAO,CAAC,QAAQ,EAAE,KAAK,eAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC1D,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B;AAEF;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAC1B,UAA6C,EAC7C,WAAgD,EAChD,EAAE;IACF,IAAI;QACF,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAA,qCAAmB,EAAC,UAAU,CAAC,KAAK,IAAA,qCAAmB,EAAC,WAAW,CAAC,CAAC;KAC7E;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB","sourcesContent":["import { AddressZero } from '@ethersproject/constants';\nimport { Contract } from '@ethersproject/contracts';\nimport { SolScope } from '@metamask/keyring-api';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { CaipAssetType, CaipChainId } from '@metamask/utils';\nimport { isCaipChainId, isStrictHexString, type Hex } from '@metamask/utils';\n\nimport {\n formatChainIdToCaip,\n formatChainIdToDec,\n formatChainIdToHex,\n} from './caip-formatters';\nimport {\n DEFAULT_BRIDGE_CONTROLLER_STATE,\n ETH_USDT_ADDRESS,\n METABRIDGE_ETHEREUM_ADDRESS,\n} from '../constants/bridge';\nimport { CHAIN_IDS } from '../constants/chains';\nimport {\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP,\n SYMBOL_TO_SLIP44_MAP,\n type SupportedSwapsNativeCurrencySymbols,\n} from '../constants/tokens';\nimport type {\n BridgeAsset,\n BridgeControllerState,\n GenericQuoteRequest,\n} from '../types';\nimport { ChainId } from '../types';\n\nexport const getDefaultBridgeControllerState = (): BridgeControllerState => {\n return DEFAULT_BRIDGE_CONTROLLER_STATE;\n};\n\n/**\n * Returns the native assetType for a given chainId and native currency symbol\n * Note that the return value is used as the assetId although it is a CaipAssetType\n *\n * @param chainId - The chainId to get the native assetType for\n * @param nativeCurrencySymbol - The native currency symbol for the given chainId\n * @returns The native assetType for the given chainId\n */\nconst getNativeAssetCaipAssetType = (\n chainId: CaipChainId,\n nativeCurrencySymbol: SupportedSwapsNativeCurrencySymbols,\n): CaipAssetType => {\n return `${formatChainIdToCaip(chainId)}/${SYMBOL_TO_SLIP44_MAP[nativeCurrencySymbol]}`;\n};\n\n/**\n * Returns the native swaps or bridge asset for a given chainId\n *\n * @param chainId - The chainId to get the default token for\n * @returns The native asset for the given chainId\n * @throws If no native asset is defined for the given chainId\n */\nexport const getNativeAssetForChainId = (\n chainId: string | number | Hex | CaipChainId,\n): BridgeAsset => {\n const chainIdInCaip = formatChainIdToCaip(chainId);\n const nativeToken =\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToCaip(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ] ??\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n formatChainIdToHex(\n chainId,\n ) as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ];\n\n if (!nativeToken) {\n throw new Error(\n `No XChain Swaps native asset found for chainId: ${chainId}`,\n );\n }\n\n return {\n ...nativeToken,\n chainId: formatChainIdToDec(chainId),\n assetId: getNativeAssetCaipAssetType(chainIdInCaip, nativeToken.symbol),\n };\n};\n\n/**\n * A function to return the txParam data for setting allowance to 0 for USDT on Ethereum\n *\n * @returns The txParam data that will reset allowance to 0, combine it with the approval tx params received from Bridge API\n */\nexport const getEthUsdtResetData = () => {\n const UsdtContractInterface = new Contract(ETH_USDT_ADDRESS, abiERC20)\n .interface;\n const data = UsdtContractInterface.encodeFunctionData('approve', [\n METABRIDGE_ETHEREUM_ADDRESS,\n '0',\n ]);\n\n return data;\n};\n\nexport const isEthUsdt = (chainId: Hex, address: string) =>\n chainId === CHAIN_IDS.MAINNET &&\n address.toLowerCase() === ETH_USDT_ADDRESS.toLowerCase();\n\nexport const sumHexes = (...hexStrings: string[]): Hex => {\n if (hexStrings.length === 0) {\n return '0x0';\n }\n\n const sum = hexStrings.reduce((acc, hex) => acc + BigInt(hex), BigInt(0));\n return `0x${sum.toString(16)}`;\n};\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nexport const isSwapsDefaultTokenAddress = (\n address: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!address || !chainId) {\n return false;\n }\n\n return address === getNativeAssetForChainId(chainId)?.address;\n};\n\n/**\n * Checks whether the provided symbol is strictly equal to the symbol for\n * the default swaps token of the provided chain.\n *\n * @param symbol - The string to compare to the default token symbol\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the symbol is the provided chain's default token symbol\n */\nexport const isSwapsDefaultTokenSymbol = (\n symbol: string,\n chainId: Hex | CaipChainId,\n) => {\n if (!symbol || !chainId) {\n return false;\n }\n\n return symbol === getNativeAssetForChainId(chainId)?.symbol;\n};\n\n/**\n * Checks whether the address is a native asset in any supported xchain swaps network\n *\n * @param address - The address to check\n * @returns Whether the address is a native asset\n */\nexport const isNativeAddress = (address?: string | null) =>\n address === AddressZero || // bridge and swap apis set the native asset address to zero\n address === '' || // assets controllers set the native asset address to an empty string\n !address ||\n address.endsWith('11111111111111111111111111111111') || // token-api and bridge-api use this as the solana native assetId\n [getNativeAssetForChainId(ChainId.SOLANA).assetId].some(\n (assetId) => assetId.includes(address) && !isStrictHexString(address),\n ); // solana native assetId used in the extension client\n\n/**\n * Checks whether the chainId matches Solana in CaipChainId or number format\n *\n * @param chainId - The chainId to check\n * @returns Whether the chainId is Solana\n */\nexport const isSolanaChainId = (\n chainId: Hex | number | CaipChainId | string,\n) => {\n if (isCaipChainId(chainId)) {\n return chainId === SolScope.Mainnet.toString();\n }\n return chainId.toString() === ChainId.SOLANA.toString();\n};\n\n/**\n * Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds\n *\n * @param srcChainId - The source chainId\n * @param destChainId - The destination chainId\n * @returns Whether the transaction is a cross-chain transaction\n */\nexport const isCrossChain = (\n srcChainId: GenericQuoteRequest['srcChainId'],\n destChainId?: GenericQuoteRequest['destChainId'],\n) => {\n try {\n if (!destChainId) {\n return false;\n }\n return formatChainIdToCaip(srcChainId) !== formatChainIdToCaip(destChainId);\n } catch {\n return false;\n }\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { CaipChainId } from "@metamask/utils";
2
2
  import { type Hex } from "@metamask/utils";
3
- import type { BridgeAsset, BridgeControllerState } from "../types.cjs";
3
+ import type { BridgeAsset, BridgeControllerState, GenericQuoteRequest } from "../types.cjs";
4
4
  export declare const getDefaultBridgeControllerState: () => BridgeControllerState;
5
5
  /**
6
6
  * Returns the native swaps or bridge asset for a given chainId
@@ -50,4 +50,12 @@ export declare const isNativeAddress: (address?: string | null) => boolean;
50
50
  * @returns Whether the chainId is Solana
51
51
  */
52
52
  export declare const isSolanaChainId: (chainId: Hex | number | CaipChainId | string) => boolean;
53
+ /**
54
+ * Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds
55
+ *
56
+ * @param srcChainId - The source chainId
57
+ * @param destChainId - The destination chainId
58
+ * @returns Whether the transaction is a cross-chain transaction
59
+ */
60
+ export declare const isCrossChain: (srcChainId: GenericQuoteRequest['srcChainId'], destChainId?: GenericQuoteRequest['destChainId']) => boolean;
53
61
  //# sourceMappingURL=bridge.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.d.cts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAiB,WAAW,EAAE,wBAAwB;AAClE,OAAO,EAAoC,KAAK,GAAG,EAAE,wBAAwB;AAkB7E,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,qBAAiB;AAGnE,eAAO,MAAM,+BAA+B,QAAO,qBAElD,CAAC;AAiBF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,YAC1B,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,WAAW,KAC3C,WAyBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,cAS/B,CAAC;AAEF,eAAO,MAAM,SAAS,YAAa,GAAG,WAAW,MAAM,YAEG,CAAC;AAE3D,eAAO,MAAM,QAAQ,kBAAmB,MAAM,EAAE,KAAG,GAOlD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,YAC5B,MAAM,WACN,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,WACL,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAAc,MAAM,GAAG,IAAI,YAOpD,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,eAAe,YACjB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAM7C,CAAC"}
1
+ {"version":3,"file":"bridge.d.cts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAiB,WAAW,EAAE,wBAAwB;AAClE,OAAO,EAAoC,KAAK,GAAG,EAAE,wBAAwB;AAkB7E,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,mBAAmB,EACpB,qBAAiB;AAGlB,eAAO,MAAM,+BAA+B,QAAO,qBAElD,CAAC;AAiBF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,YAC1B,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,WAAW,KAC3C,WAyBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,cAS/B,CAAC;AAEF,eAAO,MAAM,SAAS,YAAa,GAAG,WAAW,MAAM,YAEG,CAAC;AAE3D,eAAO,MAAM,QAAQ,kBAAmB,MAAM,EAAE,KAAG,GAOlD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,YAC5B,MAAM,WACN,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,WACL,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAAc,MAAM,GAAG,IAAI,YAOpD,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,eAAe,YACjB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAM7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,eACX,mBAAmB,CAAC,YAAY,CAAC,gBAC/B,mBAAmB,CAAC,aAAa,CAAC,YAUjD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { CaipChainId } from "@metamask/utils";
2
2
  import { type Hex } from "@metamask/utils";
3
- import type { BridgeAsset, BridgeControllerState } from "../types.mjs";
3
+ import type { BridgeAsset, BridgeControllerState, GenericQuoteRequest } from "../types.mjs";
4
4
  export declare const getDefaultBridgeControllerState: () => BridgeControllerState;
5
5
  /**
6
6
  * Returns the native swaps or bridge asset for a given chainId
@@ -50,4 +50,12 @@ export declare const isNativeAddress: (address?: string | null) => boolean;
50
50
  * @returns Whether the chainId is Solana
51
51
  */
52
52
  export declare const isSolanaChainId: (chainId: Hex | number | CaipChainId | string) => boolean;
53
+ /**
54
+ * Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds
55
+ *
56
+ * @param srcChainId - The source chainId
57
+ * @param destChainId - The destination chainId
58
+ * @returns Whether the transaction is a cross-chain transaction
59
+ */
60
+ export declare const isCrossChain: (srcChainId: GenericQuoteRequest['srcChainId'], destChainId?: GenericQuoteRequest['destChainId']) => boolean;
53
61
  //# sourceMappingURL=bridge.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAiB,WAAW,EAAE,wBAAwB;AAClE,OAAO,EAAoC,KAAK,GAAG,EAAE,wBAAwB;AAkB7E,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,qBAAiB;AAGnE,eAAO,MAAM,+BAA+B,QAAO,qBAElD,CAAC;AAiBF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,YAC1B,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,WAAW,KAC3C,WAyBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,cAS/B,CAAC;AAEF,eAAO,MAAM,SAAS,YAAa,GAAG,WAAW,MAAM,YAEG,CAAC;AAE3D,eAAO,MAAM,QAAQ,kBAAmB,MAAM,EAAE,KAAG,GAOlD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,YAC5B,MAAM,WACN,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,WACL,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAAc,MAAM,GAAG,IAAI,YAOpD,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,eAAe,YACjB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAM7C,CAAC"}
1
+ {"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAiB,WAAW,EAAE,wBAAwB;AAClE,OAAO,EAAoC,KAAK,GAAG,EAAE,wBAAwB;AAkB7E,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,mBAAmB,EACpB,qBAAiB;AAGlB,eAAO,MAAM,+BAA+B,QAAO,qBAElD,CAAC;AAiBF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,YAC1B,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,WAAW,KAC3C,WAyBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,cAS/B,CAAC;AAEF,eAAO,MAAM,SAAS,YAAa,GAAG,WAAW,MAAM,YAEG,CAAC;AAE3D,eAAO,MAAM,QAAQ,kBAAmB,MAAM,EAAE,KAAG,GAOlD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,YAC5B,MAAM,WACN,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,WACL,GAAG,GAAG,WAAW,YAO3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAAc,MAAM,GAAG,IAAI,YAOpD,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,eAAe,YACjB,GAAG,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,YAM7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,eACX,mBAAmB,CAAC,YAAY,CAAC,gBAC/B,mBAAmB,CAAC,aAAa,CAAC,YAUjD,CAAC"}
@@ -116,4 +116,22 @@ export const isSolanaChainId = (chainId) => {
116
116
  }
117
117
  return chainId.toString() === ChainId.SOLANA.toString();
118
118
  };
119
+ /**
120
+ * Checks whether the transaction is a cross-chain transaction by comparing the source and destination chainIds
121
+ *
122
+ * @param srcChainId - The source chainId
123
+ * @param destChainId - The destination chainId
124
+ * @returns Whether the transaction is a cross-chain transaction
125
+ */
126
+ export const isCrossChain = (srcChainId, destChainId) => {
127
+ try {
128
+ if (!destChainId) {
129
+ return false;
130
+ }
131
+ return formatChainIdToCaip(srcChainId) !== formatChainIdToCaip(destChainId);
132
+ }
133
+ catch {
134
+ return false;
135
+ }
136
+ };
119
137
  //# sourceMappingURL=bridge.mjs.map