Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
fix: do not construct routes with the same pool twice (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem authored Aug 11, 2021
1 parent 99a282b commit f463df9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/hooks/useAllV3Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import { useUserSingleHopOnly } from '../state/user/hooks'
import { useActiveWeb3React } from './web3'
import { useV3SwapPools } from './useV3SwapPools'

/**
* Returns true if poolA is equivalent to poolB
* @param poolA one of the two pools
* @param poolB the other pool
*/
function poolEquals(poolA: Pool, poolB: Pool): boolean {
return (
poolA === poolB ||
(poolA.token0.equals(poolB.token0) && poolA.token1.equals(poolB.token1) && poolA.fee === poolB.fee)
)
}

function computeAllRoutes(
currencyIn: Currency,
currencyOut: Currency,
Expand All @@ -20,7 +32,7 @@ function computeAllRoutes(
if (!tokenIn || !tokenOut) throw new Error('Missing tokenIn/tokenOut')

for (const pool of pools) {
if (currentPath.indexOf(pool) !== -1 || !pool.involvesToken(tokenIn)) continue
if (!pool.involvesToken(tokenIn) || currentPath.find((pathPool) => poolEquals(pool, pathPool))) continue

const outputToken = pool.token0.equals(tokenIn) ? pool.token1 : pool.token0
if (outputToken.equals(tokenOut)) {
Expand Down

0 comments on commit f463df9

Please sign in to comment.