import { BigNumberish } from 'ethers' export enum PriceGranularity { BLOCK = 'block', ONE_MIN = '1min', FIVE_MIN = '5min', HOUR = 'hour', DAY = 'day', } export type PriceData = { chainId: number tokenAddress: string isNativeToken: boolean amountUsd: number timestamp: number timeBucket: string granularity: PriceGranularity plugin: string // coingecko, coinmarketcap, etc source: string // arbitrary value set by plugin createdAt: number } export type PriceEntity = { entityId: string entityType: 'TokenPrice' data: PriceData } export type PriceRequestArgs = { chainId?: number tokenAddress?: string tokenDecimals?: number idealBlockNumber?: number | string idealTimestamp?: number idealGranularity?: PriceGranularity } export type PricingPluginConfig = { id: string getUsdAmountByAddress: ( args: PriceRequestArgs, ) => Promise | null> } export type FallbackToken = { chainId: number tokenAddress: string } export type TokenMapper = ( chainId: number, tokenAddress: string, ) => Promise export type PriceAcceptanceInfo = { granularityDifferenceSeconds: number | null idealGranularitySeconds: number fetchedPrices: PriceData[] } export type PricesConfig = { userNamespace?: string defaultIdealGranularity?: PriceGranularity plugins: PricingPluginConfig[] shouldAcceptPlugin?: ( args: PriceRequestArgs, plugin: string, context?: { tokenMapperFallbackToken: FallbackToken }, ) => Promise shouldAcceptPrice?: ( args: PriceRequestArgs, price: PriceData | null, info: PriceAcceptanceInfo, ) => Promise } export const integrations = { prices: { getUsdAmountByAddress: async (args: { chainId?: number tokenAddress?: string tokenAmount?: BigNumberish tokenDecimals?: number idealBlockNumber?: number | string idealTimestamp?: number idealGranularity?: PriceGranularity allowSymbolMapping?: boolean skipCache?: boolean }): Promise => { args throw new Error( 'prices.getUsdAmountByAddress() is a native function implemented by the platform runtime', ) }, configure: (config: PricesConfig) => { config throw new Error( 'prices.configure() is a native function implemented by the platform runtime', ) }, // stablecoinsPlugin: stablecoinsDefault, coinGeckoPlugin: {} as PricingPluginConfig, moralisPlugin: {} as PricingPluginConfig, tokenMapperPlugin: (upstreams: PricingPluginConfig[], fn: TokenMapper) => { upstreams fn throw new Error( 'prices.tokenMapperPlugin() is a native function implemented by the platform runtime', ) }, }, }