From 15d61a9ddf98953cce915760e5bc95158be19b8f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 25 Jan 2023 10:39:36 +0800 Subject: [PATCH 1/2] Only add the pools if there is a complete path tokenIn -> connectingToken -> tokenOut --- src/routeProposal/filtering.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/routeProposal/filtering.ts b/src/routeProposal/filtering.ts index 75a34f7e..2def85b7 100644 --- a/src/routeProposal/filtering.ts +++ b/src/routeProposal/filtering.ts @@ -211,21 +211,24 @@ export function getBoostedGraph( } // add best pools tokenIn -> connectingToken and connectingToken -> tokenOut for (const connectingToken of config.connectingTokens) { - const bestTokenInToConnectingToken = getHighestLiquidityPool( + const bestTokenInToConnectingTokenPoolId = getHighestLiquidityPool( tokenIn, connectingToken.address, poolsAllDict ); - if (bestTokenInToConnectingToken) { - graphPoolsSet.add(poolsAllDict[bestTokenInToConnectingToken]); - } - const bestConnectingTokenToTokenOut = getHighestLiquidityPool( + const bestConnectingTokenToTokenOutPoolId = getHighestLiquidityPool( connectingToken.address, tokenOut, poolsAllDict ); - if (bestConnectingTokenToTokenOut) { - graphPoolsSet.add(poolsAllDict[bestConnectingTokenToTokenOut]); + if ( + bestTokenInToConnectingTokenPoolId && + bestConnectingTokenToTokenOutPoolId + ) { + graphPoolsSet.add(poolsAllDict[bestTokenInToConnectingTokenPoolId]); + graphPoolsSet.add( + poolsAllDict[bestConnectingTokenToTokenOutPoolId] + ); } } if (linearPools.length == 0) return {}; From bdf30c03ad9549e66c1488206e1944e732d87f20 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 25 Jan 2023 10:40:32 +0800 Subject: [PATCH 2/2] move the connectingTokens.map call to the top of the function, no need to call it multiple times --- src/routeProposal/filtering.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routeProposal/filtering.ts b/src/routeProposal/filtering.ts index 2def85b7..63ae200a 100644 --- a/src/routeProposal/filtering.ts +++ b/src/routeProposal/filtering.ts @@ -176,6 +176,9 @@ export function getBoostedGraph( const graphPoolsSet: Set = new Set(); const linearPools: PoolBase[] = []; const phantomPools: PoolBase[] = []; + const connectingTokens = config.connectingTokens.map( + (connectingToken) => connectingToken.address + ); // Here we add all linear pools, take note of phantom pools, // add LBP pools with tokenIn or tokenOut and their corresponding // highest liquidity WETH connections @@ -194,9 +197,6 @@ export function getBoostedGraph( phantomPools.push(pool); } if (config.lbpRaisingTokens && pool.isLBP) { - const connectingTokens = config.connectingTokens.map( - (connectingToken) => connectingToken.address - ); handleLBPCase( graphPoolsSet, config.lbpRaisingTokens,