{"version":3,"file":"abstract-token-prices-service.mjs","sourceRoot":"","sources":["../../src/token-prices-service/abstract-token-prices-service.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicePolicy } from '@metamask/controller-utils';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\n\nimport type { MarketDataDetails } from '../TokenRatesController';\n\n/**\n * A map of CAIP-2 chain IDs to their native asset identifiers (CAIP-19 format).\n */\nexport type NativeAssetIdentifiersMap = Record<CaipChainId, CaipAssetType>;\n\n/**\n * Represents an exchange rate.\n */\nexport type ExchangeRate = {\n  name: string;\n  ticker: string;\n  value: number;\n  currencyType: string;\n  usd?: number;\n};\n\n/**\n * A map of currency to its exchange rate.\n */\nexport type ExchangeRatesByCurrency<Currency extends string> = {\n  [C in Currency]: ExchangeRate;\n};\n\nexport type EvmAssetAddressWithChain<ChainId extends Hex = Hex> = {\n  tokenAddress: Hex;\n  chainId: ChainId;\n};\n\nexport type EvmAssetWithId<ChainId extends Hex = Hex> =\n  EvmAssetAddressWithChain<ChainId> & {\n    assetId: CaipAssetType;\n  };\n\nexport type EvmAssetWithMarketData<\n  ChainId extends Hex = Hex,\n  Currency extends string = string,\n> = EvmAssetAddressWithChain<ChainId> &\n  MarketDataDetails & { currency: Currency };\n\n/**\n * An ideal token prices service. All implementations must confirm to this\n * interface.\n *\n * @template ChainId - A type union of valid arguments for the `chainId`\n * argument to `fetchTokenPrices`.\n * @template Currency - A type union of valid arguments for the `currency`\n * argument to `fetchTokenPrices`.\n */\nexport type AbstractTokenPricesService<\n  ChainId extends Hex = Hex,\n  Currency extends string = string,\n> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {\n  /**\n   * Retrieves prices in the given currency for the tokens identified by the\n   * given addresses which are expected to live on the given chain.\n   *\n   * @param args - The arguments to this function.\n   * @param args.assets - The assets to get prices for.\n   * @param args.currency - The desired currency of the token prices.\n   * @returns The prices for the requested tokens.\n   */\n  fetchTokenPrices({\n    assets,\n    currency,\n  }: {\n    assets: EvmAssetAddressWithChain<ChainId>[];\n    currency: Currency;\n  }): Promise<EvmAssetWithMarketData<ChainId, Currency>[]>;\n\n  /**\n   * Retrieves exchange rates in the given currency.\n   *\n   * @param args - The arguments to this function.\n   * @param args.baseCurrency - The desired currency of the token prices.\n   * @param args.includeUsdRate - Whether to include the USD rate in the response.\n   * @param args.cryptocurrencies - The cryptocurrencies to get exchange rates for.\n   * @returns The exchange rates in the requested base currency.\n   */\n  fetchExchangeRates({\n    baseCurrency,\n    includeUsdRate,\n    cryptocurrencies,\n  }: {\n    baseCurrency: Currency;\n    includeUsdRate: boolean;\n    cryptocurrencies: string[];\n  }): Promise<ExchangeRatesByCurrency<Currency>>;\n\n  /**\n   * Type guard for whether the API can return token prices for the given chain\n   * ID.\n   *\n   * @param chainId - The chain ID to check.\n   * @returns True if the API supports the chain ID, false otherwise.\n   */\n  validateChainIdSupported(chainId: unknown): chainId is ChainId;\n\n  /**\n   * Type guard for whether the API can return token prices in the given\n   * currency.\n   *\n   * @param currency - The currency to check.\n   * @returns True if the API supports the currency, false otherwise.\n   */\n  validateCurrencySupported(currency: unknown): currency is Currency;\n\n  /**\n   * Sets the native asset identifiers map for resolving native token CAIP-19 IDs.\n   * This should be called with data from NetworkEnablementController.state.nativeAssetIdentifiers.\n   *\n   * @param nativeAssetIdentifiers - Map of CAIP-2 chain IDs to native asset identifiers.\n   */\n  setNativeAssetIdentifiers?(\n    nativeAssetIdentifiers: NativeAssetIdentifiersMap,\n  ): void;\n};\n"]}