diff --git a/src/router.ts b/src/router.ts index 59fae84a..440e74b4 100644 --- a/src/router.ts +++ b/src/router.ts @@ -3,7 +3,7 @@ import memoize from "memoizee"; import BigNumber from "bignumber.js"; import {ethers} from "ethers"; import { curve, OLD_CHAINS } from "./curve.js"; -import {IDict, IRoute, IRouteOutputAndCost, IRouteStep} from "./interfaces"; +import {IDict, IRoute, IRouteOutputAndCost, IRouteStep, IChainId} from "./interfaces"; import { _cutZeros, _get_price_impact, @@ -54,9 +54,8 @@ function mapDict(dict: IDict, mapper: (key: string, value: T) => U): ID return result; } -const _buildRouteGraph = memoize(async (): Promise>> => { +const _buildRouteGraph = memoize(async (chainId: IChainId): Promise>> => { const constants = curve.constants; - const chainId = curve.chainId; const allPools = Object.entries(curve.getPoolsData()).filter(([id]) => !["crveth", "y", "busd", "pax"].includes(id)); const amplificationCoefficientDict = await _getAmplificationCoefficientsFromApi(); const poolTvlDict: IDict = await entriesToDictAsync(allPools, _getTVL); @@ -69,7 +68,7 @@ const _buildRouteGraph = memoize(async (): Promise>> = }); const _findRoutes = async (inputCoinAddress: string, outputCoinAddress: string): Promise => { - const routerGraph = await _buildRouteGraph(); + const routerGraph = await _buildRouteGraph(curve.chainId); // It's important to pass chainId to not use cache from another network // extract only the fields we need for the worker const poolData = mapDict( curve.getPoolsData(),