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Ac,CAAA;IACd,sCAAU,CAAA;AACZ,CAAC,EAlBW,OAAO,KAAP,OAAO,QAkBlB;AAQD,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,uDAAW,CAAA;IACX,uDAAW,CAAA;IACX,mDAAS,CAAA;AACX,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-controller';\nimport type { AssetsControllerGetExchangeRatesForBridgeAction } from '@metamask/assets-controller';\nimport type {\n  CurrencyRateControllerGetStateAction,\n  MultichainAssetsRatesControllerGetStateAction,\n  TokenRatesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type {\n  ControllerGetStateAction,\n  ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n  NetworkControllerFindNetworkClientIdByChainIdAction,\n  NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { AuthenticationControllerGetBearerTokenAction } from '@metamask/profile-sync-controller/auth';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { SnapControllerHandleRequestAction } from '@metamask/snaps-controllers';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n  CaipAccountId,\n  CaipAssetId,\n  CaipAssetType,\n  CaipChainId,\n  Hex,\n} from '@metamask/utils';\n\nimport type { BridgeController } from './bridge-controller';\nimport type { BridgeControllerMethodActions } from './bridge-controller-method-action-types';\nimport type { BRIDGE_CONTROLLER_NAME } from './constants/bridge';\nimport type {\n  BitcoinTradeDataSchema,\n  BridgeAssetSchema,\n  ChainConfigurationSchema,\n  ChainRankingSchema,\n  FeeDataSchema,\n  IntentSchema,\n  PlatformConfigSchema,\n  ProtocolSchema,\n  QuoteResponseSchema,\n  QuoteSchema,\n  StepSchema,\n  TokenFeatureSchema,\n  QuoteStreamCompleteSchema,\n  TronTradeDataSchema,\n  TxDataSchema,\n  BatchSellTradesResponseSchema,\n  GaslessPropertiesSchema,\n  SimulatedGasFeeLimitsSchema,\n  TxFeeGasLimitsSchema,\n} from './utils/validators';\n\nexport type FetchFunction = (\n  input: RequestInfo | URL | string,\n  init?: RequestInit,\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * The types of assets that a user can send\n */\nexport enum AssetType {\n  /** The native asset for the current network, such as ETH */\n  native = 'NATIVE',\n  /** An ERC20 token */\n  token = 'TOKEN',\n  /** An ERC721 or ERC1155 token. */\n  NFT = 'NFT',\n  /**\n   * A transaction interacting with a contract that isn't a token method\n   * interaction will be marked as dealing with an unknown asset type.\n   */\n  unknown = 'UNKNOWN',\n}\n\nexport type ChainConfiguration = Infer<typeof ChainConfigurationSchema>;\n\nexport type ChainRanking = Infer<typeof ChainRankingSchema>;\n\nexport type L1GasFees = {\n  l1GasFeesInHexWei?: string; // l1 fees for approval and trade in hex wei, appended by BridgeController.#appendL1GasFees\n};\n\nexport type NonEvmFees = {\n  nonEvmFeesInNative?: string; // Non-EVM chain fees in native units (SOL for Solana, BTC for Bitcoin)\n};\n\nexport type InputPrimaryDenomination = 'token_amount' | 'fiat_value';\n\n/**\n * The types of values for the token amount and its values when converted to the user's selected currency and USD\n */\nexport type TokenAmountValues = {\n  /**\n   * The amount of the token\n   *\n   * @example \"1.005\"\n   */\n  amount: string;\n  /**\n   * The amount of the token in the user's selected currency\n   *\n   * @example \"4.55\"\n   */\n  valueInCurrency: string | null;\n  /**\n   * The amount of the token in USD\n   *\n   * @example \"1.234\"\n   */\n  usd: string | null;\n};\n\n/**\n * Asset exchange rate values for a given chain and address\n */\nexport type ExchangeRate = { exchangeRate?: string; usdExchangeRate?: string };\n\n/**\n * Values derived from the quote response\n */\nexport type QuoteMetadata = {\n  /**\n   * If gas is included, this is the value of the src or dest token that was used to pay for the gas.\n   * Show this value to indicate transaction fees for gasless quotes.\n   */\n  includedTxFees?: TokenAmountValues | null;\n  /**\n   * The gas fee for the bridge transaction.\n   * effective is the gas fee that is shown to the user. If this value is not\n   * included in the trade, the calculation falls back to the gasLimit (total)\n   * total is the gas fee that is spent by the user, including refunds.\n   * max is the max gas fee that will be used by the transaction.\n   */\n  gasFee: Record<'effective' | 'total' | 'max', TokenAmountValues>;\n  /**\n   * The total network fee required to submit the trade and any approvals. This includes\n   * the relayer fee or other native fees. Should be used for balance checks and tx submission.\n   * Note: This is only accurate for non-gasless transactions. Use {@link QuoteMetadata.includedTxFees} to\n   * get the total network fee for gasless transactions.\n   */\n  totalNetworkFee: TokenAmountValues; // estimatedGasFees + relayerFees\n  totalMaxNetworkFee: TokenAmountValues; // maxGasFees + relayerFees\n  /**\n   * The amount that the user will receive (destTokenAmount)\n   */\n  toTokenAmount: TokenAmountValues;\n  /**\n   * The minimum amount that the user will receive (minDestTokenAmount)\n   */\n  minToTokenAmount: TokenAmountValues;\n  /**\n   * If gas is included: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.includedTxFees}.\n   * Otherwise: {@link QuoteMetadata.toTokenAmount} - {@link QuoteMetadata.totalNetworkFee}.\n   */\n  adjustedReturn: Omit<TokenAmountValues, 'amount'>;\n  /**\n   * The amount that the user will send, including fees that are paid in the src token\n   * {@link Quote.srcTokenAmount} + {@link Quote.feeData[FeeType.METABRIDGE].amount} + {@link Quote.feeData[FeeType.TX_FEE].amount}\n   */\n  sentAmount: TokenAmountValues;\n  /**\n   * The swap rate is the amount that the user will receive per amount sent. Accounts for fees paid in the src or dest token.\n   * This is calculated as {@link QuoteMetadata.toTokenAmount} / {@link QuoteMetadata.sentAmount}.\n   */\n  swapRate: string;\n  /**\n   * The cost of the trade, which is the difference between the amount sent and the adjusted return.\n   * This is calculated as {@link QuoteMetadata.sentAmount} - {@link QuoteMetadata.adjustedReturn}.\n   */\n  cost: Omit<TokenAmountValues, 'amount'>; // sentAmount - adjustedReturn\n};\n\n/**\n * Sort order set by the user\n */\nexport enum SortOrder {\n  COST_ASC = 'cost_ascending',\n  ETA_ASC = 'time_descending',\n}\n\n/**\n * This is the interface for the asset object returned by the bridge-api\n * This type is used in the QuoteResponse and in the fetchBridgeTokens response\n */\nexport type BridgeAsset = Infer<typeof BridgeAssetSchema>;\n\n/**\n * This is the interface for the token object used in the extension client\n * In addition to the {@link BridgeAsset} fields, it includes balance information\n */\nexport type BridgeToken = {\n  address: string;\n  symbol: string;\n  image: string;\n  decimals: number;\n  chainId: number | Hex | ChainId | CaipChainId;\n  balance: string; // raw balance\n  // TODO deprecate this field and use balance instead\n  string: string | undefined; // normalized balance as a stringified number\n  tokenFiatAmount?: number | null;\n  occurrences?: number;\n};\n\ntype DecimalChainId = string;\nexport type GasMultiplierByChainId = Record<DecimalChainId, number>;\n\nexport type FeatureFlagResponse = Infer<typeof PlatformConfigSchema>;\n\n// TODO move definition to validators.ts\n/**\n * This is the interface for the quote request sent to the bridge-api\n * and should only be used by the fetchBridgeQuotes utility function\n * Components and redux stores should use the {@link GenericQuoteRequest} type\n */\nexport type QuoteRequest<\n  ChainIdType = ChainId | number,\n  TokenAddressType = string,\n  WalletAddressType = string,\n> = {\n  walletAddress: WalletAddressType;\n  destWalletAddress?: WalletAddressType;\n  srcChainId: ChainIdType;\n  destChainId: ChainIdType;\n  srcTokenAddress: TokenAddressType;\n  destTokenAddress: TokenAddressType;\n  /**\n   * This is the amount sent, in atomic amount\n   */\n  srcTokenAmount: string;\n  slippage?: number;\n  aggIds?: string[];\n  bridgeIds?: string[];\n  insufficientBal?: boolean;\n  resetApproval?: boolean;\n  refuel?: boolean;\n  /**\n   * Whether the response should include gasless swap quotes\n   * This should be true if the user has opted in to STX on the client\n   * and the current network has STX support\n   */\n  gasIncluded: boolean;\n  /**\n   * Whether to request quotes that use EIP-7702 delegated gasless execution\n   */\n  gasIncluded7702: boolean;\n  /**\n   * The fee that will be charged by MetaMask\n   */\n  fee?: number;\n};\n\nexport enum StatusTypes {\n  SUBMITTED = 'SUBMITTED',\n  UNKNOWN = 'UNKNOWN',\n  FAILED = 'FAILED',\n  PENDING = 'PENDING',\n  COMPLETE = 'COMPLETE',\n}\n\nexport enum FeatureId {\n  UNKNOWN = 'unknown',\n  PERPS = 'perps',\n  QUICK_BUY_FOLLOW_TRADING = 'quick_buy_follow_trading',\n  QUICK_BUY_TOKEN_DETAILS = 'quick_buy_token_details',\n  QUICK_BUY_EXPLORE = 'quick_buy_explore',\n  DAPP_SWAP = 'dapp_swap',\n  BATCH_SELL = 'batch_sell',\n  UNIFIED_SWAP_BRIDGE = 'unified_swap_bridge',\n}\n\n/**\n * These are types that components pass in. Since data is a mix of types when coming from the redux store, we need to use a generic type that can cover all the types.\n * Payloads with this type are transformed into QuoteRequest by fetchBridgeQuotes right before fetching quotes\n */\nexport type GenericQuoteRequest = QuoteRequest<\n  Hex | CaipChainId | string | number, // chainIds\n  Hex | CaipAssetId | string, // assetIds/addresses\n  Hex | CaipAccountId | string // accountIds/addresses\n>;\n\nexport type Protocol = Infer<typeof ProtocolSchema>;\n\nexport type Step = Infer<typeof StepSchema>;\n\nexport type RefuelData = Step;\n\nexport type FeeData = Infer<typeof FeeDataSchema>;\n\nexport type Quote = Infer<typeof QuoteSchema>;\n\nexport type TxData = Infer<typeof TxDataSchema>;\n\nexport type Intent = Infer<typeof IntentSchema>;\nexport type IntentOrderLike = Intent['order'];\n\nexport type BitcoinTradeData = Infer<typeof BitcoinTradeDataSchema>;\n\nexport type TronTradeData = Infer<typeof TronTradeDataSchema>;\n/**\n * This is the type for the quote response from the bridge-api\n * TxDataType can be overriden to be a string when the quote is non-evm\n * ApprovalType can be overriden when you know the specific approval type (e.g., TxData for EVM-only contexts)\n */\nexport type QuoteResponseV1<\n  TxDataType = TxData | string | BitcoinTradeData | TronTradeData,\n  ApprovalType = TxData | TronTradeData,\n> = Infer<typeof QuoteResponseSchema> & {\n  trade: TxDataType;\n  approval?: ApprovalType;\n  /**\n   * Appended to the quote response based on the quote request\n   */\n  featureId?: FeatureId;\n  /**\n   * Appended to the quote response based on the quote request resetApproval flag\n   * If defined, the quote's total network fee will include the reset approval's gas limit.\n   */\n  resetApproval?: TxData;\n  /**\n   * Appended to the quote if there are multiple quote requests in a batch. This\n   * indicates which quoteRequest the quote is for\n   */\n  quoteRequestIndex?: number;\n};\n\nexport type BatchSellTradesRequest = {\n  quotes: QuoteResponseV1[];\n  stxEnabled: boolean;\n};\n\n/**\n * This is the bridge-api response for the obtainGaslessBatch method\n */\nexport type BatchSellTradesResponse = Infer<\n  typeof BatchSellTradesResponseSchema\n>;\n\nexport type SimulatedGasFeeLimits = Infer<typeof SimulatedGasFeeLimitsSchema>;\nexport type TxFeeGasLimits = Infer<typeof TxFeeGasLimitsSchema>;\n\nexport type GaslessProperties = Infer<typeof GaslessPropertiesSchema>;\n\nexport type DeepPartial<Type> = Type extends string\n  ? Type\n  : {\n      [K in keyof Type]?: Type[K] extends (infer U)[]\n        ? DeepPartial<U>[]\n        : Type[K] extends readonly (infer U)[]\n          ? readonly DeepPartial<U>[]\n          : Type[K] extends object\n            ? DeepPartial<Type[K]>\n            : Type[K];\n    };\n\nexport enum ChainId {\n  ETH = 1,\n  OPTIMISM = 10,\n  BSC = 56,\n  POLYGON = 137,\n  ZKSYNC = 324,\n  BASE = 8453,\n  ARBITRUM = 42161,\n  AVALANCHE = 43114,\n  LINEA = 59144,\n  SOLANA = 1151111081099710,\n  BTC = 20000000000001,\n  TRON = 728126428,\n  SEI = 1329,\n  MONAD = 143,\n  HYPEREVM = 999,\n  MEGAETH = 4326,\n  ARC = 5042,\n}\n\nexport type FeatureFlagsPlatformConfig = Infer<typeof PlatformConfigSchema>;\n\nexport type TokenFeature = Infer<typeof TokenFeatureSchema>;\n\nexport type QuoteStreamCompleteData = Infer<typeof QuoteStreamCompleteSchema>;\n\nexport enum RequestStatus {\n  LOADING = 0,\n  FETCHED = 1,\n  ERROR = 2,\n}\n\nexport type BridgeControllerState = {\n  quoteRequest: Partial<GenericQuoteRequest>[];\n  quotes: (QuoteResponseV1 & L1GasFees & NonEvmFees)[];\n  /**\n   * The time elapsed between the initial quote fetch and when the first valid quote was received\n   */\n  quotesInitialLoadTime: number | null;\n  /**\n   * The timestamp of when the latest quote fetch started\n   */\n  quotesLastFetched: number | null;\n  /**\n   * The status of the quote fetch, including fee calculations and validations\n   * This is set to\n   * - LOADING when the quote fetch starts\n   * - FETCHED when the process completes successfully, including when quotes are empty\n   * - ERROR when any errors occur\n   *\n   * When SSE is enabled, this is set to LOADING even when a quote is available. It is only\n   * set to FETCHED when the stream is closed and all quotes have been received\n   */\n  quotesLoadingStatus: RequestStatus | null;\n  quoteFetchError: string | null;\n  /**\n   * The number of times the quotes have been refreshed, starts at 0 and is\n   * incremented at the end of each quote fetch\n   */\n  quotesRefreshCount: number;\n  /**\n   * Asset exchange rates for EVM and multichain assets that are not indexed by the assets controllers\n   */\n  assetExchangeRates: Record<CaipAssetType, ExchangeRate>;\n  /**\n   * When the src token is SOL, this needs to be subtracted from their balance to determine\n   * the max amount that can be sent.\n   */\n  minimumBalanceForRentExemptionInLamports: string | null;\n  /**\n   * Security alerts for the destination token in the current quote request,\n   * populated from `token_warning` SSE events.\n   */\n  tokenWarnings: TokenFeature[];\n  /**\n   * Client-supplied security classification for the destination token in the\n   * current quote request, used as the `token_security_type_destination`\n   * analytics property. Set via the `context` arg of\n   * `updateBridgeQuoteRequestParams` and reset whenever the quote request is\n   * reset. `null` when the client has no security data for the token.\n   */\n  tokenSecurityTypeDestination: string | null;\n  /**\n   * The denomination currently shown as the primary source amount input.\n   * This is persisted as a user preference so returning to the flow restores\n   * the last selected fiat/token display mode.\n   */\n  inputPrimaryDenomination: InputPrimaryDenomination;\n  /**\n   * Metadata about the completed quote stream, populated from the `complete` SSE event.\n   * Set to null at the start of each fetch and updated when the complete event is received.\n   */\n  quoteStreamComplete: QuoteStreamCompleteData | null;\n  /**\n   * Contains gasless transaction data and fees for BatchSell quotes, provided by the obtainGaslessBatch API\n   */\n  batchSellTrades: BatchSellTradesResponse | null;\n  /**\n   * The status of the batch sell trades fetch, including fee calculations and validations\n   */\n  batchSellTradesLoadingStatus: RequestStatus | null;\n};\n\n/**\n * @deprecated Use the separate method action types (e.g.,\n * `BridgeControllerFetchQuotesAction`) instead.\n */\nexport type BridgeControllerAction<\n  FunctionName extends keyof BridgeController,\n> = {\n  type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;\n  handler: BridgeController[FunctionName];\n};\n\nexport type BridgeControllerGetStateAction = ControllerGetStateAction<\n  typeof BRIDGE_CONTROLLER_NAME,\n  BridgeControllerState\n>;\n\nexport type BridgeControllerStateChangeEvent = ControllerStateChangeEvent<\n  typeof BRIDGE_CONTROLLER_NAME,\n  BridgeControllerState\n>;\n\nexport type BridgeControllerActions =\n  | BridgeControllerGetStateAction\n  | BridgeControllerMethodActions;\n\nexport type BridgeControllerEvents = BridgeControllerStateChangeEvent;\n\nexport type AllowedActions =\n  | AccountsControllerGetAccountByAddressAction\n  | AuthenticationControllerGetBearerTokenAction\n  | CurrencyRateControllerGetStateAction\n  | TokenRatesControllerGetStateAction\n  | MultichainAssetsRatesControllerGetStateAction\n  | SnapControllerHandleRequestAction\n  | NetworkControllerFindNetworkClientIdByChainIdAction\n  | NetworkControllerGetNetworkClientByIdAction\n  | RemoteFeatureFlagControllerGetStateAction\n  | AssetsControllerGetExchangeRatesForBridgeAction;\nexport type AllowedEvents = never;\n\n/**\n * The messenger for the BridgeController.\n */\nexport type BridgeControllerMessenger = Messenger<\n  typeof BRIDGE_CONTROLLER_NAME,\n  BridgeControllerActions | AllowedActions,\n  BridgeControllerEvents | AllowedEvents\n>;\n"]}