import type { FeeValuesType } from 'viem' import { type EstimateFeesPerGasErrorType, type EstimateFeesPerGasParameters, type EstimateFeesPerGasReturnType, estimateFeesPerGas, } from '../actions/estimateFeesPerGas.js' import type { Config } from '../createConfig.js' import type { ScopeKeyParameter } from '../types/properties.js' import type { QueryOptions, QueryParameter } from '../types/query.js' import type { Compute, ExactPartial } from '../types/utils.js' import { filterQueryOptions } from './utils.js' export type EstimateFeesPerGasOptions< type extends FeeValuesType, config extends Config, selectData = EstimateFeesPerGasData, > = Compute< ExactPartial> & ScopeKeyParameter > & QueryParameter< EstimateFeesPerGasQueryFnData, EstimateFeesPerGasErrorType, selectData, EstimateFeesPerGasQueryKey > export function estimateFeesPerGasQueryOptions< config extends Config, type extends FeeValuesType = 'eip1559', selectData = EstimateFeesPerGasData, >( config: config, options: EstimateFeesPerGasOptions = {}, ): EstimateFeesPerGasQueryOptions { return { ...options.query, queryFn: async (context) => { const [, { scopeKey: _, ...parameters }] = context.queryKey return estimateFeesPerGas(config, parameters) }, queryKey: estimateFeesPerGasQueryKey(options), } } export type EstimateFeesPerGasQueryFnData = EstimateFeesPerGasReturnType export type EstimateFeesPerGasData = EstimateFeesPerGasQueryFnData export function estimateFeesPerGasQueryKey< config extends Config, type extends FeeValuesType = 'eip1559', >( options: Compute< ExactPartial> & ScopeKeyParameter > = {}, ) { return ['estimateFeesPerGas', filterQueryOptions(options)] as const } export type EstimateFeesPerGasQueryKey< config extends Config, type extends FeeValuesType, > = ReturnType> export type EstimateFeesPerGasQueryOptions< type extends FeeValuesType, config extends Config, selectData = EstimateFeesPerGasData, > = QueryOptions< EstimateFeesPerGasQueryFnData, EstimateFeesPerGasErrorType, selectData, EstimateFeesPerGasQueryKey >