import type { BaseConfig, BaseState } from '@metamask/base-controller'; import { BaseController } from '@metamask/base-controller'; import type { NetworkState } from '@metamask/network-controller'; import type { PreferencesState } from '@metamask/preferences-controller'; import type { Hex } from '@metamask/utils'; import type { TokensState } from './TokensController'; /** * @type CoinGeckoResponse * * CoinGecko API response representation */ export interface CoinGeckoResponse { [address: string]: { [currency: string]: number; }; } /** * @type CoinGeckoPlatform * * CoinGecko supported platform API representation */ export interface CoinGeckoPlatform { id: string; chain_identifier: null | number; name: string; shortname: string; } /** * @type Token * * Token representation * @property address - Hex address of the token contract * @property decimals - Number of decimals the token uses * @property symbol - Symbol of the token * @property image - Image of the token, url or bit32 image */ export interface Token { address: string; decimals: number; symbol: string; aggregators?: string[]; image?: string; balanceError?: unknown; isERC721?: boolean; name?: string; } /** * @type TokenRatesConfig * * Token rates controller configuration * @property interval - Polling interval used to fetch new token rates * @property nativeCurrency - Current native currency selected to use base of rates * @property chainId - Current network chainId * @property tokens - List of tokens to track exchange rates for * @property threshold - Threshold to invalidate the supportedChains */ export interface TokenRatesConfig extends BaseConfig { interval: number; nativeCurrency: string; chainId: Hex; selectedAddress: string; allTokens: { [chainId: Hex]: { [key: string]: Token[]; }; }; allDetectedTokens: { [chainId: Hex]: { [key: string]: Token[]; }; }; threshold: number; } interface ContractExchangeRates { [address: string]: number | undefined; } /** * @type TokenRatesState * * Token rates controller state * @property contractExchangeRates - Hash of token contract addresses to exchange rates * @property supportedChains - Cached chain data */ export interface TokenRatesState extends BaseState { contractExchangeRates: ContractExchangeRates; } /** * Controller that passively polls on a set interval for token-to-fiat exchange rates * for tokens stored in the TokensController */ export declare class TokenRatesController extends BaseController { #private; private handle?; private tokenList; private supportedChains; private supportedVsCurrencies; /** * Name of this controller used during composition */ name: string; /** * Creates a TokenRatesController instance. * * @param options - The controller options. * @param options.chainId - The chain ID of the current network. * @param options.ticker - The ticker for the current network. * @param options.selectedAddress - The current selected address. * @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes. * @param options.onTokensStateChange - Allows subscribing to token controller state changes. * @param options.onNetworkStateChange - Allows subscribing to network state changes. * @param config - Initial options used to configure this controller. * @param state - Initial state to set on this controller. */ constructor({ chainId: initialChainId, ticker: initialTicker, selectedAddress: initialSelectedAddress, onPreferencesStateChange, onTokensStateChange, onNetworkStateChange, }: { chainId: Hex; ticker: string; selectedAddress: string; onPreferencesStateChange: (listener: (preferencesState: PreferencesState) => void) => void; onTokensStateChange: (listener: (tokensState: TokensState) => void) => void; onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void; }, config?: Partial, state?: Partial); /** * Start (or restart) polling. */ start(): Promise; /** * Stop polling. */ stop(): void; /** * Fetches a pairs of token address and native currency. * * @param chainSlug - Chain string identifier. * @param vsCurrency - Query according to tokens in tokenList and native currency. * @returns The exchange rates for the given pairs. */ fetchExchangeRate(chainSlug: string, vsCurrency: string): Promise; /** * Checks if the current native currency is a supported vs currency to use * to query for token exchange rates. * * @param nativeCurrency - The native currency of the currently active network. * @returns A boolean indicating whether it's a supported vsCurrency. */ private checkIsSupportedVsCurrency; /** * Gets current chain ID slug from cached supported platforms CoinGecko API response. * If cached supported platforms response is stale, fetches and updates it. * * @returns The CoinGecko slug for the current chain ID. */ getChainSlug(): Promise; /** * Updates exchange rates for all tokens. */ updateExchangeRates(): Promise; /** * Checks if the active network's native currency is supported by the coingecko API. * If supported, it fetches and maps contractExchange rates to a format to be consumed by the UI. * If not supported, it fetches contractExchange rates and maps them from token/fallback-currency * to token/nativeCurrency. * * @param nativeCurrency - The native currency of the currently active network. * @param slug - The unique slug used to id the chain by the coingecko api * should be used to query token exchange rates. * @returns An object with conversion rates for each token * related to the network's native currency. */ fetchAndMapExchangeRates(nativeCurrency: string, slug: string): Promise; } export default TokenRatesController; //# sourceMappingURL=TokenRatesController.d.ts.map