import { filterPoolsOfInterest , filterHopPools , getLinearStaBal3Paths , getPathsUsingStaBalPool , parseToPoolsDict , } from './filtering' ; import { calculatePathLimits } from './pathLimits' ; import { SwapOptions , SwapTypes , NewPath , SubgraphPoolBase , SorConfig , } from '../types' ; export class RouteProposer { cache : Record < string , { paths : NewPath [ ] ; } > = { } ; constructor ( private readonly config ) { } /**
     * Given a list of pools and a desired input/output, returns a set of possible paths to route through
     */ getCandidatePaths ( tokenIn , tokenOut , swapType , pools , swapOptions ) { if ( pools . length === 0 ) return [ ] ; const cache = this . cache [ `${ tokenIn }${ tokenOut }${ swapType }${ swapOptions . timestamp }` ] ; if ( ! swapOptions . forceRefresh && ! ! cache ) { return cache . paths ; } const poolsAllDict = parseToPoolsDict ( pools , swapOptions . timestamp ) ; const [ poolsFilteredDict , hopTokens ] = filterPoolsOfInterest ( poolsAllDict , tokenIn , tokenOut , swapOptions . maxPools ) ; const [ , pathData ] = filterHopPools ( tokenIn , tokenOut , hopTokens , poolsFilteredDict ) ; const pathsUsingLinear = getLinearStaBal3Paths ( tokenIn , tokenOut , poolsAllDict , poolsFilteredDict , this . config ) ; const pathsUsingStaBal = getPathsUsingStaBalPool ( tokenIn , tokenOut , poolsAllDict , poolsFilteredDict , this . config ) ; const combinedPathData = pathData . concat ( ... pathsUsingLinear ) . concat ( ... pathsUsingStaBal ) ; const [ paths ] = calculatePathLimits ( combinedPathData , swapType ) ; this . cache [ `${ tokenIn }${ tokenOut }${ swapType }${ swapOptions . timestamp }` ] = { paths : paths , } ; return paths ; } }