import type { Currency , Token } from '@uniswap/sdk-core' ; import { FeeAmount , Pool } from '@uniswap/v3-sdk' ; import { useMemo } from 'react' ; import { useAllCurrencyCombinations } from './useAllCommonPairs' ; import { PoolState , usePools } from './usePools' ; import { TradeProvider } from '@masknet/public-api' ; param currencyIn param currencyOut export function useV3SwapPools ( currencyIn ? , currencyOut ? ) { const allCurrencyCombinations = useAllCurrencyCombinations ( TradeProvider . UNISWAP_V3 , currencyIn , currencyOut ) ; const allCurrencyCombinationsWithAllFees = useMemo ( ( ) => allCurrencyCombinations . reduce < [ Token , Token , FeeAmount ] [ ] > ( ( list , [ tokenA , tokenB ] ) => { return list . concat ( [ [ tokenA , tokenB , FeeAmount . LOW ] , [ tokenA , tokenB , FeeAmount . MEDIUM ] , [ tokenA , tokenB , FeeAmount . HIGH ] , ] ) ; } , [ ] ) , [ allCurrencyCombinations ] ) ; const pools = usePools ( TradeProvider . UNISWAP_V3 , allCurrencyCombinationsWithAllFees ) ; return useMemo ( ( ) => { return { pools : pools . filter ( ( tuple ) : tuple is [ PoolState . EXISTS , Pool ] => { return tuple [ 0 ] === PoolState . EXISTS && tuple [ 1 ] !== null ; } ) . map ( ( [ , pool ] ) => pool ) , loading : pools . some ( ( [ state ] ) => state === PoolState . LOADING ) , } ; } , [ pools ] ) ; }