@metamask-previews/bridge-controller 32.1.0-preview-8d14f81c → 32.1.0-preview-b33c0741

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Fixed
11
+
12
+ - Fetch `minimumBalanceForRentExemptionInLamports` asynchronously to prevent blocking the getQuote network call ([#5921](https://github.com/MetaMask/core/pull/5921))
13
+ - Fix invalid `getMinimumBalanceForRentExemption` commitment parameter ([#5921](https://github.com/MetaMask/core/pull/5921))
14
+
10
15
  ## [32.1.0]
11
16
 
12
17
  ### Added
@@ -103,10 +103,6 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
103
103
  ...bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest,
104
104
  ...paramsToUpdate,
105
105
  };
106
- if (paramsToUpdate.srcChainId &&
107
- paramsToUpdate.srcChainId !== this.state.quoteRequest.srcChainId) {
108
- await __classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, paramsToUpdate.srcChainId);
109
- }
110
106
  this.update((state) => {
111
107
  state.quoteRequest = updatedQuoteRequest;
112
108
  state.quotes = bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
@@ -119,6 +115,12 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
119
115
  bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount;
120
116
  state.quotesInitialLoadTime =
121
117
  bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;
118
+ // Reset required minimum balance if the source chain is not Solana
119
+ if (updatedQuoteRequest.srcChainId &&
120
+ !(0, bridge_2.isSolanaChainId)(updatedQuoteRequest.srcChainId)) {
121
+ state.minimumBalanceForRentExemptionInLamports =
122
+ bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;
123
+ }
122
124
  });
123
125
  await __classPrivateFieldGet(this, _BridgeController_fetchAssetExchangeRates, "f").call(this, updatedQuoteRequest).catch((error) => console.warn('Failed to fetch asset exchange rates', error));
124
126
  if ((0, quote_1.isValidQuoteRequest)(updatedQuoteRequest)) {
@@ -259,6 +261,9 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
259
261
  state.quoteFetchError = bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;
260
262
  });
261
263
  const fetchQuotes = async () => {
264
+ // This call is not awaited to prevent blocking quote fetching if the snap takes too long to respond
265
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
266
+ __classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, updatedQuoteRequest.srcChainId);
262
267
  const quotes = await (0, fetch_1.fetchBridgeQuotes)(updatedQuoteRequest,
263
268
  // AbortController is always defined by this line, because we assign it a few lines above,
264
269
  // not sure why Jest thinks it's not
@@ -282,7 +287,6 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
282
287
  destChainId: (0, caip_formatters_1.formatChainIdToCaip)(updatedQuoteRequest.destChainId),
283
288
  },
284
289
  }, fetchQuotes);
285
- await __classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, updatedQuoteRequest.srcChainId);
286
290
  }
287
291
  catch (error) {
288
292
  const isAbortError = error.name === 'AbortError';
@@ -370,24 +374,24 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
370
374
  }, []);
371
375
  return quotesWithL1GasFees;
372
376
  });
373
- _BridgeController_setMinimumBalanceForRentExemptionInLamports.set(this, async (srcChainId) => {
377
+ _BridgeController_setMinimumBalanceForRentExemptionInLamports.set(this, (srcChainId) => {
374
378
  const selectedAccount = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this);
375
- try {
376
- if ((0, bridge_2.isSolanaChainId)(srcChainId) && selectedAccount?.metadata?.snap?.id) {
377
- const fees = (await this.messagingSystem.call('SnapController:handleRequest', (0, snaps_1.getMinimumBalanceForRentExemptionRequest)(selectedAccount.metadata.snap?.id)));
379
+ return (0, bridge_2.isSolanaChainId)(srcChainId) && selectedAccount?.metadata?.snap?.id
380
+ ? this.messagingSystem
381
+ .call('SnapController:handleRequest', (0, snaps_1.getMinimumBalanceForRentExemptionRequest)(selectedAccount.metadata.snap?.id)) // eslint-disable-next-line promise/always-return
382
+ .then((result) => {
378
383
  this.update((state) => {
379
- state.minimumBalanceForRentExemptionInLamports = fees;
384
+ state.minimumBalanceForRentExemptionInLamports = String(result);
380
385
  });
381
- return;
382
- }
383
- }
384
- catch (error) {
385
- console.error('Error setting minimum balance for rent exemption', error);
386
- }
387
- this.update((state) => {
388
- state.minimumBalanceForRentExemptionInLamports =
389
- bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;
390
- });
386
+ })
387
+ .catch((error) => {
388
+ console.error('Error setting minimum balance for rent exemption', error);
389
+ this.update((state) => {
390
+ state.minimumBalanceForRentExemptionInLamports =
391
+ bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;
392
+ });
393
+ })
394
+ : undefined;
391
395
  });
392
396
  _BridgeController_appendSolanaFees.set(this, async (quotes) => {
393
397
  // Return early if some of the quotes are not for solana
@@ -569,6 +573,7 @@ _BridgeController_abortController = new WeakMap(), _BridgeController_quotesFirst
569
573
  return this.messagingSystem.call('AccountsController:getSelectedMultichainAccount');
570
574
  }, _BridgeController_getSelectedNetworkClientId = function _BridgeController_getSelectedNetworkClientId() {
571
575
  const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
576
+ // console.log('===selectedNetworkClientId', selectedNetworkClientId);
572
577
  return selectedNetworkClientId;
573
578
  }, _BridgeController_getSelectedNetworkClient = function _BridgeController_getSelectedNetworkClient() {
574
579
  const selectedNetworkClientId = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getSelectedNetworkClientId).call(this);
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-controller.cjs","sourceRoot":"","sources":["../src/bridge-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,wDAAoD;AACpD,wDAAwD;AAGxD,mEAAuD;AAEvD,qEAA+E;AAG/E,2CAAwD;AAExD,mDAO4B;AAC5B,mDAA+C;AAC/C,mDAA+C;AAC/C,+CAA+D;AAE/D,uCAUiB;AACjB,+CAAsE;AACtE,iDAAuD;AACvD,+CAKwB;AACxB,iEAIiC;AACjC,6DAA8D;AAC9D,6CAAoE;AACpE,6DAAuE;AACvE,+DASoC;AAQpC,6CAAoD;AACpD,6CAGuB;AAEvB,MAAM,QAAQ,GAAyC;IACrD,YAAY,EAAE;QACZ,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,MAAM,EAAE;QACN,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,qBAAqB,EAAE;QACrB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,iBAAiB,EAAE;QACjB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,eAAe,EAAE;QACf,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,wCAAwC,EAAE;QACxC,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEF,MAAM,yBAAyB,GAAG,wBAAwB,CAAC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AG,+BAAsB,0BAA0B,EACnD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CACxC,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,+BAAsB,8BAA8B,EACvD,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC5C,CAAC;IACJ,CAAC;CAiqBF;AAlwBD,4CAkwBC;;IAjNG,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, TraceCallback } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionController } 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';\nimport {\n getFeeForTransactionRequest,\n getMinimumBalanceForRentExemptionRequest,\n} from './utils/snaps';\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 minimumBalanceForRentExemptionInLamports: {\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: typeof TransactionController.prototype.getLayer1GasFee;\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: typeof TransactionController.prototype.getLayer1GasFee;\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 if (\n paramsToUpdate.srcChainId &&\n paramsToUpdate.srcChainId !== this.state.quoteRequest.srcChainId\n ) {\n await this.#setMinimumBalanceForRentExemptionInLamports(\n paramsToUpdate.srcChainId,\n );\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 state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\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 await this.#setMinimumBalanceForRentExemptionInLamports(\n updatedQuoteRequest.srcChainId,\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 undefined;\n }\n\n const l1GasFeePromises = Promise.allSettled(\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 : '0x0';\n const tradeL1GasFees = await this.#getLayer1GasFee({\n transactionParams: getTxParams(trade),\n chainId,\n });\n\n if (approvalL1GasFees === undefined || tradeL1GasFees === undefined) {\n return undefined;\n }\n\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n\n const quotesWithL1GasFees = (await l1GasFeePromises).reduce<\n (QuoteResponse & L1GasFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating L1 gas fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithL1GasFees;\n };\n\n readonly #setMinimumBalanceForRentExemptionInLamports = async (\n srcChainId: GenericQuoteRequest['srcChainId'],\n ) => {\n const selectedAccount = this.#getMultichainSelectedAccount();\n\n try {\n if (isSolanaChainId(srcChainId) && selectedAccount?.metadata?.snap?.id) {\n const fees = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(\n selectedAccount.metadata.snap?.id,\n ),\n )) as string;\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports = fees;\n });\n return;\n }\n } catch (error) {\n console.error('Error setting minimum balance for rent exemption', error);\n }\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n });\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 const solanaFeePromises = Promise.allSettled(\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 getFeeForTransactionRequest(\n selectedAccount.metadata.snap?.id,\n trade,\n ),\n )) as { value: string };\n\n return {\n ...quoteResponse,\n solanaFeesInLamports: fees,\n };\n }\n return quoteResponse;\n }),\n );\n\n const quotesWithSolanaFees = (await solanaFeePromises).reduce<\n (QuoteResponse & SolanaFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating solana fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithSolanaFees;\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 return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n has_sufficient_funds: !this.state.quoteRequest.insufficientBal,\n ...baseProperties,\n };\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":3,"file":"bridge-controller.cjs","sourceRoot":"","sources":["../src/bridge-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,wDAAoD;AACpD,wDAAwD;AAGxD,mEAAuD;AAEvD,qEAA+E;AAG/E,2CAAwD;AAExD,mDAO4B;AAC5B,mDAA+C;AAC/C,mDAA+C;AAC/C,+CAA+D;AAE/D,uCAUiB;AACjB,+CAAsE;AACtE,iDAAuD;AACvD,+CAKwB;AACxB,iEAIiC;AACjC,6DAA8D;AAC9D,6CAAoE;AACpE,6DAAuE;AACvE,+DASoC;AAQpC,6CAAoD;AACpD,6CAGuB;AAEvB,MAAM,QAAQ,GAAyC;IACrD,YAAY,EAAE;QACZ,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,MAAM,EAAE;QACN,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,qBAAqB,EAAE;QACrB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,iBAAiB,EAAE;QACjB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,eAAe,EAAE;QACf,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;KACjB;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;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IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/C,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,+BAAsB,aAAa,EACtC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3B,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,+BAAsB,0BAA0B,EACnD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CACxC,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,+BAAsB,8BAA8B,EACvD,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC5C,CAAC;IACJ,CAAC;CAuqBF;AAxwBD,4CAwwBC;;IAlNG,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,sEAAsE;IACtE,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, TraceCallback } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionController } 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';\nimport {\n getFeeForTransactionRequest,\n getMinimumBalanceForRentExemptionRequest,\n} from './utils/snaps';\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 minimumBalanceForRentExemptionInLamports: {\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: typeof TransactionController.prototype.getLayer1GasFee;\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: typeof TransactionController.prototype.getLayer1GasFee;\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 // Reset required minimum balance if the source chain is not Solana\n if (\n updatedQuoteRequest.srcChainId &&\n !isSolanaChainId(updatedQuoteRequest.srcChainId)\n ) {\n state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n }\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 state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\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 // This call is not awaited to prevent blocking quote fetching if the snap takes too long to respond\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#setMinimumBalanceForRentExemptionInLamports(\n updatedQuoteRequest.srcChainId,\n );\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 undefined;\n }\n\n const l1GasFeePromises = Promise.allSettled(\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 : '0x0';\n const tradeL1GasFees = await this.#getLayer1GasFee({\n transactionParams: getTxParams(trade),\n chainId,\n });\n\n if (approvalL1GasFees === undefined || tradeL1GasFees === undefined) {\n return undefined;\n }\n\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n\n const quotesWithL1GasFees = (await l1GasFeePromises).reduce<\n (QuoteResponse & L1GasFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating L1 gas fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithL1GasFees;\n };\n\n readonly #setMinimumBalanceForRentExemptionInLamports = (\n srcChainId: GenericQuoteRequest['srcChainId'],\n ): Promise<void> | undefined => {\n const selectedAccount = this.#getMultichainSelectedAccount();\n\n return isSolanaChainId(srcChainId) && selectedAccount?.metadata?.snap?.id\n ? this.messagingSystem\n .call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(\n selectedAccount.metadata.snap?.id,\n ),\n ) // eslint-disable-next-line promise/always-return\n .then((result) => {\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports = String(result);\n });\n })\n .catch((error) => {\n console.error(\n 'Error setting minimum balance for rent exemption',\n error,\n );\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n });\n })\n : 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 const solanaFeePromises = Promise.allSettled(\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 getFeeForTransactionRequest(\n selectedAccount.metadata.snap?.id,\n trade,\n ),\n )) as { value: string };\n\n return {\n ...quoteResponse,\n solanaFeesInLamports: fees,\n };\n }\n return quoteResponse;\n }),\n );\n\n const quotesWithSolanaFees = (await solanaFeePromises).reduce<\n (QuoteResponse & SolanaFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating solana fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithSolanaFees;\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 // console.log('===selectedNetworkClientId', selectedNetworkClientId);\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 return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n has_sufficient_funds: !this.state.quoteRequest.insufficientBal,\n ...baseProperties,\n };\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 +1 @@
1
- {"version":3,"file":"bridge-controller.d.cts","sourceRoot":"","sources":["../src/bridge-controller.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAW,aAAa,EAAE,mCAAmC;AAEzE,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAEpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAE9E,OAAO,EAAe,KAAK,GAAG,EAAE,wBAAwB;AAExD,OAAO,EACL,KAAK,cAAc,EACnB,sBAAsB,EAKvB,+BAA2B;AAK5B,OAAO,EAEL,KAAK,mBAAmB,EAIxB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAEnB,oBAAgB;AAgBjB,OAAO,EAAE,0BAA0B,EAAE,sCAAkC;AAWvE,OAAO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,EAC9B,0BAA0B,CAAC,eAAe,CAC3C,CAAC,0BAA0B,CAAC,eAAe,CAAC,CAAC;CACjD,CAAC;;;;;;;;;;;;;;;;AAEF,qBAAa,gBAAiB,SAAQ,sBACpC,OAAO,sBAAsB,EAC7B,qBAAqB,EACrB,yBAAyB,CAC1B;;gBAyBa,EACV,SAAS,EACT,KAAK,EACL,QAAQ,EACR,eAAe,EACf,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,OAAO,GACR,EAAE;QACD,SAAS,EAAE,yBAAyB,CAAC;QACrC,KAAK,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;QACvC,QAAQ,EAAE,cAAc,CAAC;QACzB,eAAe,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,eAAe,CAAC;QACxE,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE;YACP,sBAAsB,CAAC,EAAE,MAAM,CAAC;SACjC,CAAC;QACF,kBAAkB,EAAE,CAClB,CAAC,SACC,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,OAAO,0BAA0B,CAAC,EAE9E,SAAS,EAAE,CAAC,EACZ,UAAU,EAAE,8BAA8B,CAAC,CAAC,CAAC,KAC1C,IAAI,CAAC;QACV,OAAO,CAAC,EAAE,aAAa,CAAC;KACzB;IA4CD,YAAY,iBAAwB,kBAAkB,mBAEpD;IAEF,8BAA8B,mBACZ,QAAQ,mBAAmB,CAAC,WACnC,kBAAkB,CAAC,SAAS,CAAC,mBAqEtC;IAyGF,UAAU,aAsBR;IAEF;;OAEG;IACH,sBAAsB,aAUpB;IAmZF;;;;;;;;;OASG;IACH,2BAA2B,iIAoBzB;IAEF;;;;;OAKG;IACH,uBAAuB,oBACJ,MAAM,WACd,GAAG,KACX,QAAQ,MAAM,CAAC,CAehB;CACH"}
@@ -100,10 +100,6 @@ export class BridgeController extends StaticIntervalPollingController() {
100
100
  ...DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest,
101
101
  ...paramsToUpdate,
102
102
  };
103
- if (paramsToUpdate.srcChainId &&
104
- paramsToUpdate.srcChainId !== this.state.quoteRequest.srcChainId) {
105
- await __classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, paramsToUpdate.srcChainId);
106
- }
107
103
  this.update((state) => {
108
104
  state.quoteRequest = updatedQuoteRequest;
109
105
  state.quotes = DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
@@ -116,6 +112,12 @@ export class BridgeController extends StaticIntervalPollingController() {
116
112
  DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount;
117
113
  state.quotesInitialLoadTime =
118
114
  DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;
115
+ // Reset required minimum balance if the source chain is not Solana
116
+ if (updatedQuoteRequest.srcChainId &&
117
+ !isSolanaChainId(updatedQuoteRequest.srcChainId)) {
118
+ state.minimumBalanceForRentExemptionInLamports =
119
+ DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;
120
+ }
119
121
  });
120
122
  await __classPrivateFieldGet(this, _BridgeController_fetchAssetExchangeRates, "f").call(this, updatedQuoteRequest).catch((error) => console.warn('Failed to fetch asset exchange rates', error));
121
123
  if (isValidQuoteRequest(updatedQuoteRequest)) {
@@ -256,6 +258,9 @@ export class BridgeController extends StaticIntervalPollingController() {
256
258
  state.quoteFetchError = DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;
257
259
  });
258
260
  const fetchQuotes = async () => {
261
+ // This call is not awaited to prevent blocking quote fetching if the snap takes too long to respond
262
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
263
+ __classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, updatedQuoteRequest.srcChainId);
259
264
  const quotes = await fetchBridgeQuotes(updatedQuoteRequest,
260
265
  // AbortController is always defined by this line, because we assign it a few lines above,
261
266
  // not sure why Jest thinks it's not
@@ -279,7 +284,6 @@ export class BridgeController extends StaticIntervalPollingController() {
279
284
  destChainId: formatChainIdToCaip(updatedQuoteRequest.destChainId),
280
285
  },
281
286
  }, fetchQuotes);
282
- await __classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, updatedQuoteRequest.srcChainId);
283
287
  }
284
288
  catch (error) {
285
289
  const isAbortError = error.name === 'AbortError';
@@ -367,24 +371,24 @@ export class BridgeController extends StaticIntervalPollingController() {
367
371
  }, []);
368
372
  return quotesWithL1GasFees;
369
373
  });
370
- _BridgeController_setMinimumBalanceForRentExemptionInLamports.set(this, async (srcChainId) => {
374
+ _BridgeController_setMinimumBalanceForRentExemptionInLamports.set(this, (srcChainId) => {
371
375
  const selectedAccount = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this);
372
- try {
373
- if (isSolanaChainId(srcChainId) && selectedAccount?.metadata?.snap?.id) {
374
- const fees = (await this.messagingSystem.call('SnapController:handleRequest', getMinimumBalanceForRentExemptionRequest(selectedAccount.metadata.snap?.id)));
376
+ return isSolanaChainId(srcChainId) && selectedAccount?.metadata?.snap?.id
377
+ ? this.messagingSystem
378
+ .call('SnapController:handleRequest', getMinimumBalanceForRentExemptionRequest(selectedAccount.metadata.snap?.id)) // eslint-disable-next-line promise/always-return
379
+ .then((result) => {
375
380
  this.update((state) => {
376
- state.minimumBalanceForRentExemptionInLamports = fees;
381
+ state.minimumBalanceForRentExemptionInLamports = String(result);
377
382
  });
378
- return;
379
- }
380
- }
381
- catch (error) {
382
- console.error('Error setting minimum balance for rent exemption', error);
383
- }
384
- this.update((state) => {
385
- state.minimumBalanceForRentExemptionInLamports =
386
- DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;
387
- });
383
+ })
384
+ .catch((error) => {
385
+ console.error('Error setting minimum balance for rent exemption', error);
386
+ this.update((state) => {
387
+ state.minimumBalanceForRentExemptionInLamports =
388
+ DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;
389
+ });
390
+ })
391
+ : undefined;
388
392
  });
389
393
  _BridgeController_appendSolanaFees.set(this, async (quotes) => {
390
394
  // Return early if some of the quotes are not for solana
@@ -565,6 +569,7 @@ _BridgeController_abortController = new WeakMap(), _BridgeController_quotesFirst
565
569
  return this.messagingSystem.call('AccountsController:getSelectedMultichainAccount');
566
570
  }, _BridgeController_getSelectedNetworkClientId = function _BridgeController_getSelectedNetworkClientId() {
567
571
  const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
572
+ // console.log('===selectedNetworkClientId', selectedNetworkClientId);
568
573
  return selectedNetworkClientId;
569
574
  }, _BridgeController_getSelectedNetworkClient = function _BridgeController_getSelectedNetworkClient() {
570
575
  const selectedNetworkClientId = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getSelectedNetworkClientId).call(this);
@@ -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,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,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,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AAC;CAiqBF;;IAjNG,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, TraceCallback } from '@metamask/controller-utils';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionController } 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';\nimport {\n getFeeForTransactionRequest,\n getMinimumBalanceForRentExemptionRequest,\n} from './utils/snaps';\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 minimumBalanceForRentExemptionInLamports: {\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: typeof TransactionController.prototype.getLayer1GasFee;\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: typeof TransactionController.prototype.getLayer1GasFee;\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 if (\n paramsToUpdate.srcChainId &&\n paramsToUpdate.srcChainId !== this.state.quoteRequest.srcChainId\n ) {\n await this.#setMinimumBalanceForRentExemptionInLamports(\n paramsToUpdate.srcChainId,\n );\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 state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\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 await this.#setMinimumBalanceForRentExemptionInLamports(\n updatedQuoteRequest.srcChainId,\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 undefined;\n }\n\n const l1GasFeePromises = Promise.allSettled(\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 : '0x0';\n const tradeL1GasFees = await this.#getLayer1GasFee({\n transactionParams: getTxParams(trade),\n chainId,\n });\n\n if (approvalL1GasFees === undefined || tradeL1GasFees === undefined) {\n return undefined;\n }\n\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n\n const quotesWithL1GasFees = (await l1GasFeePromises).reduce<\n (QuoteResponse & L1GasFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating L1 gas fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithL1GasFees;\n };\n\n readonly #setMinimumBalanceForRentExemptionInLamports = async (\n srcChainId: GenericQuoteRequest['srcChainId'],\n ) => {\n const selectedAccount = this.#getMultichainSelectedAccount();\n\n try {\n if (isSolanaChainId(srcChainId) && selectedAccount?.metadata?.snap?.id) {\n const fees = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(\n selectedAccount.metadata.snap?.id,\n ),\n )) as string;\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports = fees;\n });\n return;\n }\n } catch (error) {\n console.error('Error setting minimum balance for rent exemption', error);\n }\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n });\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 const solanaFeePromises = Promise.allSettled(\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 getFeeForTransactionRequest(\n selectedAccount.metadata.snap?.id,\n trade,\n ),\n )) as { value: string };\n\n return {\n ...quoteResponse,\n solanaFeesInLamports: fees,\n };\n }\n return quoteResponse;\n }),\n );\n\n const quotesWithSolanaFees = (await solanaFeePromises).reduce<\n (QuoteResponse & SolanaFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating solana fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithSolanaFees;\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 return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n has_sufficient_funds: !this.state.quoteRequest.insufficientBal,\n ...baseProperties,\n };\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":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,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,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,YAAY,EACZ,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;AACpD,OAAO,EACL,2BAA2B,EAC3B,wCAAwC,EACzC,0BAAsB;AAEvB,MAAM,QAAQ,GAAyC;IACrD,YAAY,E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ent":["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 { abiERC20 } from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { TransactionController } 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';\nimport {\n getFeeForTransactionRequest,\n getMinimumBalanceForRentExemptionRequest,\n} from './utils/snaps';\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 minimumBalanceForRentExemptionInLamports: {\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: typeof TransactionController.prototype.getLayer1GasFee;\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: typeof TransactionController.prototype.getLayer1GasFee;\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 // Reset required minimum balance if the source chain is not Solana\n if (\n updatedQuoteRequest.srcChainId &&\n !isSolanaChainId(updatedQuoteRequest.srcChainId)\n ) {\n state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n }\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 state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\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 // This call is not awaited to prevent blocking quote fetching if the snap takes too long to respond\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.#setMinimumBalanceForRentExemptionInLamports(\n updatedQuoteRequest.srcChainId,\n );\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 undefined;\n }\n\n const l1GasFeePromises = Promise.allSettled(\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 : '0x0';\n const tradeL1GasFees = await this.#getLayer1GasFee({\n transactionParams: getTxParams(trade),\n chainId,\n });\n\n if (approvalL1GasFees === undefined || tradeL1GasFees === undefined) {\n return undefined;\n }\n\n return {\n ...quoteResponse,\n l1GasFeesInHexWei: sumHexes(approvalL1GasFees, tradeL1GasFees),\n };\n }),\n );\n\n const quotesWithL1GasFees = (await l1GasFeePromises).reduce<\n (QuoteResponse & L1GasFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating L1 gas fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithL1GasFees;\n };\n\n readonly #setMinimumBalanceForRentExemptionInLamports = (\n srcChainId: GenericQuoteRequest['srcChainId'],\n ): Promise<void> | undefined => {\n const selectedAccount = this.#getMultichainSelectedAccount();\n\n return isSolanaChainId(srcChainId) && selectedAccount?.metadata?.snap?.id\n ? this.messagingSystem\n .call(\n 'SnapController:handleRequest',\n getMinimumBalanceForRentExemptionRequest(\n selectedAccount.metadata.snap?.id,\n ),\n ) // eslint-disable-next-line promise/always-return\n .then((result) => {\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports = String(result);\n });\n })\n .catch((error) => {\n console.error(\n 'Error setting minimum balance for rent exemption',\n error,\n );\n this.update((state) => {\n state.minimumBalanceForRentExemptionInLamports =\n DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;\n });\n })\n : 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 const solanaFeePromises = Promise.allSettled(\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 getFeeForTransactionRequest(\n selectedAccount.metadata.snap?.id,\n trade,\n ),\n )) as { value: string };\n\n return {\n ...quoteResponse,\n solanaFeesInLamports: fees,\n };\n }\n return quoteResponse;\n }),\n );\n\n const quotesWithSolanaFees = (await solanaFeePromises).reduce<\n (QuoteResponse & SolanaFees)[]\n >((acc, result) => {\n if (result.status === 'fulfilled' && result.value) {\n acc.push(result.value);\n } else if (result.status === 'rejected') {\n console.error('Error calculating solana fees for quote', result.reason);\n }\n return acc;\n }, []);\n\n return quotesWithSolanaFees;\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 // console.log('===selectedNetworkClientId', selectedNetworkClientId);\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 return {\n ...this.#getRequestParams(),\n ...this.#getRequestMetadata(),\n has_sufficient_funds: !this.state.quoteRequest.insufficientBal,\n ...baseProperties,\n };\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"]}
@@ -17,7 +17,7 @@ const getMinimumBalanceForRentExemptionRequest = (snapId) => {
17
17
  id: (0, uuid_1.v4)(),
18
18
  jsonrpc: '2.0',
19
19
  method: 'getMinimumBalanceForRentExemption',
20
- params: [0, 'confirmed'],
20
+ params: [0, { commitment: 'confirmed' }],
21
21
  },
22
22
  },
23
23
  },
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.cjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":";;;AAAA,uDAAiD;AACjD,+BAAkC;AAE3B,MAAM,wCAAwC,GAAG,CAAC,MAAc,EAAE,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,mBAA4B;QACrC,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACN,KAAK,EAAE,sBAAQ,CAAC,OAAO;gBACvB,OAAO,EAAE;oBACP,EAAE,EAAE,IAAA,SAAI,GAAE;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;oBAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC;iBACzB;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,wCAAwC,4CAmBnD;AAEK,MAAM,2BAA2B,GAAG,CACzC,MAAc,EACd,WAAmB,EACnB,EAAE;IACF,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,cAAuB;QAChC,OAAO,EAAE;YACP,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,WAAW;gBACX,KAAK,EAAE,sBAAQ,CAAC,OAAO;aACxB;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,2BAA2B,+BAgBtC","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport { v4 as uuid } from 'uuid';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, 'confirmed'],\n },\n },\n },\n };\n};\n\nexport const getFeeForTransactionRequest = (\n snapId: string,\n transaction: string,\n) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onRpcRequest' as never,\n request: {\n method: 'getFeeForTransaction',\n params: {\n transaction,\n scope: SolScope.Mainnet,\n },\n },\n };\n};\n"]}
1
+ {"version":3,"file":"snaps.cjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":";;;AAAA,uDAAiD;AACjD,+BAAkC;AAE3B,MAAM,wCAAwC,GAAG,CAAC,MAAc,EAAE,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,mBAA4B;QACrC,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACN,KAAK,EAAE,sBAAQ,CAAC,OAAO;gBACvB,OAAO,EAAE;oBACP,EAAE,EAAE,IAAA,SAAI,GAAE;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;oBAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;iBACzC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,wCAAwC,4CAmBnD;AAEK,MAAM,2BAA2B,GAAG,CACzC,MAAc,EACd,WAAmB,EACnB,EAAE;IACF,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,cAAuB;QAChC,OAAO,EAAE;YACP,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,WAAW;gBACX,KAAK,EAAE,sBAAQ,CAAC,OAAO;aACxB;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,2BAA2B,+BAgBtC","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport { v4 as uuid } from 'uuid';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, { commitment: 'confirmed' }],\n },\n },\n },\n };\n};\n\nexport const getFeeForTransactionRequest = (\n snapId: string,\n transaction: string,\n) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onRpcRequest' as never,\n request: {\n method: 'getFeeForTransaction',\n params: {\n transaction,\n scope: SolScope.Mainnet,\n },\n },\n };\n};\n"]}
@@ -12,7 +12,9 @@ export declare const getMinimumBalanceForRentExemptionRequest: (snapId: string)
12
12
  id: string;
13
13
  jsonrpc: string;
14
14
  method: string;
15
- params: (string | number)[];
15
+ params: (number | {
16
+ commitment: string;
17
+ })[];
16
18
  };
17
19
  };
18
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.d.cts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,WAC9B,MAAM,eACD,MAAM;;;;;;;;;;;CAcpB,CAAC"}
1
+ {"version":3,"file":"snaps.d.cts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,WAC9B,MAAM,eACD,MAAM;;;;;;;;;;;CAcpB,CAAC"}
@@ -12,7 +12,9 @@ export declare const getMinimumBalanceForRentExemptionRequest: (snapId: string)
12
12
  id: string;
13
13
  jsonrpc: string;
14
14
  method: string;
15
- params: (string | number)[];
15
+ params: (number | {
16
+ commitment: string;
17
+ })[];
16
18
  };
17
19
  };
18
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.d.mts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,WAC9B,MAAM,eACD,MAAM;;;;;;;;;;;CAcpB,CAAC"}
1
+ {"version":3,"file":"snaps.d.mts","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,eAAO,MAAM,wCAAwC,WAAY,MAAM;;;;;;;;;;;;;;;;;;;CAmBtE,CAAC;AAEF,eAAO,MAAM,2BAA2B,WAC9B,MAAM,eACD,MAAM;;;;;;;;;;;CAcpB,CAAC"}
@@ -14,7 +14,7 @@ export const getMinimumBalanceForRentExemptionRequest = (snapId) => {
14
14
  id: uuid(),
15
15
  jsonrpc: '2.0',
16
16
  method: 'getMinimumBalanceForRentExemption',
17
- params: [0, 'confirmed'],
17
+ params: [0, { commitment: 'confirmed' }],
18
18
  },
19
19
  },
20
20
  },
@@ -1 +1 @@
1
- {"version":3,"file":"snaps.mjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,MAAc,EAAE,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,mBAA4B;QACrC,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACN,KAAK,EAAE,QAAQ,CAAC,OAAO;gBACvB,OAAO,EAAE;oBACP,EAAE,EAAE,IAAI,EAAE;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;oBAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC;iBACzB;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,MAAc,EACd,WAAmB,EACnB,EAAE;IACF,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,cAAuB;QAChC,OAAO,EAAE;YACP,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,WAAW;gBACX,KAAK,EAAE,QAAQ,CAAC,OAAO;aACxB;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport { v4 as uuid } from 'uuid';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, 'confirmed'],\n },\n },\n },\n };\n};\n\nexport const getFeeForTransactionRequest = (\n snapId: string,\n transaction: string,\n) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onRpcRequest' as never,\n request: {\n method: 'getFeeForTransaction',\n params: {\n transaction,\n scope: SolScope.Mainnet,\n },\n },\n };\n};\n"]}
1
+ {"version":3,"file":"snaps.mjs","sourceRoot":"","sources":["../../src/utils/snaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AACjD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,MAAc,EAAE,EAAE;IACzE,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,mBAA4B;QACrC,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,MAAM,EAAE;gBACN,KAAK,EAAE,QAAQ,CAAC,OAAO;gBACvB,OAAO,EAAE;oBACP,EAAE,EAAE,IAAI,EAAE;oBACV,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,mCAAmC;oBAC3C,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;iBACzC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,MAAc,EACd,WAAmB,EACnB,EAAE;IACF,OAAO;QACL,MAAM,EAAE,MAAe;QACvB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,cAAuB;QAChC,OAAO,EAAE;YACP,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,WAAW;gBACX,KAAK,EAAE,QAAQ,CAAC,OAAO;aACxB;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { SolScope } from '@metamask/keyring-api';\nimport { v4 as uuid } from 'uuid';\n\nexport const getMinimumBalanceForRentExemptionRequest = (snapId: string) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onProtocolRequest' as never,\n request: {\n method: ' ',\n jsonrpc: '2.0',\n params: {\n scope: SolScope.Mainnet,\n request: {\n id: uuid(),\n jsonrpc: '2.0',\n method: 'getMinimumBalanceForRentExemption',\n params: [0, { commitment: 'confirmed' }],\n },\n },\n },\n };\n};\n\nexport const getFeeForTransactionRequest = (\n snapId: string,\n transaction: string,\n) => {\n return {\n snapId: snapId as never,\n origin: 'metamask',\n handler: 'onRpcRequest' as never,\n request: {\n method: 'getFeeForTransaction',\n params: {\n transaction,\n scope: SolScope.Mainnet,\n },\n },\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/bridge-controller",
3
- "version": "32.1.0-preview-8d14f81c",
3
+ "version": "32.1.0-preview-b33c0741",
4
4
  "description": "Manages bridge-related quote fetching functionality for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -73,7 +73,7 @@
73
73
  "@metamask/remote-feature-flag-controller": "^1.6.0",
74
74
  "@metamask/snaps-controllers": "^12.3.1",
75
75
  "@metamask/superstruct": "^3.1.0",
76
- "@metamask/transaction-controller": "^57.0.0",
76
+ "@metamask/transaction-controller": "^57.1.0",
77
77
  "@types/jest": "^27.4.1",
78
78
  "deepmerge": "^4.2.2",
79
79
  "jest": "^27.5.1",