Skip to content

Commit

Permalink
Merge pull request #419 from curvefi/fix/routerGraph-cache
Browse files Browse the repository at this point in the history
Fix: routerGraph cache
  • Loading branch information
Macket authored Nov 21, 2024
2 parents 5a90bc9 + 498cbc4 commit b8cea4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/api",
"version": "2.65.12",
"version": "2.65.13",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
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 b8cea4b

Please sign in to comment.