Skip to content

Commit

Permalink
fix: routerGraph cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Macket committed Nov 21, 2024
1 parent 5a90bc9 commit d8335f0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -54,9 +54,8 @@ function mapDict<T, U>(dict: IDict<T>, mapper: (key: string, value: T) => U): ID
return result;
}

const _buildRouteGraph = memoize(async (): Promise<IDict<IDict<IRouteStep[]>>> => {
const _buildRouteGraph = memoize(async (chainId: IChainId): Promise<IDict<IDict<IRouteStep[]>>> => {
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<number> = await entriesToDictAsync(allPools, _getTVL);
Expand All @@ -69,7 +68,7 @@ const _buildRouteGraph = memoize(async (): Promise<IDict<IDict<IRouteStep[]>>> =
});

const _findRoutes = async (inputCoinAddress: string, outputCoinAddress: string): Promise<IRoute[]> => {
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(),
Expand Down

0 comments on commit d8335f0

Please sign in to comment.