Skip to content

Commit

Permalink
fix: uniswap route encoding for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mds1 committed Aug 25, 2021
1 parent 3db2054 commit 765e9aa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion contracts/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,17 @@ async function getRoute(tokens: SupportedToken[]): Promise<Route<Token, Token>>
poolPromises.push(getPoolInstance(inputToken, outputToken));
});
const pools = await Promise.all(poolPromises);
return new Route(pools, pools[0].token0, pools[pools.length - 1].token1);

// Get input token. First we guess that our input token is token 0 for a pool, and if not then it must be token 1
const inSymbol = tokens[0] === 'eth' ? 'weth' : tokens[0];
let inToken = pools.find((pool) => pool.token0.symbol?.toLowerCase() === inSymbol)?.token0;
inToken = inToken ? inToken : pools.find((pool) => pool.token1.symbol?.toLowerCase() === inSymbol)?.token1;

// Get output token using same process
const outSymbol = tokens[tokens.length - 1] === 'eth' ? 'weth' : tokens[tokens.length - 1];
let outToken = pools.find((pool) => pool.token0.symbol?.toLowerCase() === outSymbol)?.token0;
outToken = outToken ? outToken : pools.find((pool) => pool.token1.symbol?.toLowerCase() === outSymbol)?.token1;
return new Route(pools, inToken as Token, outToken as Token);
}

async function getPoolInstance(token0: SupportedToken, token1: SupportedToken): Promise<Pool> {
Expand Down

0 comments on commit 765e9aa

Please sign in to comment.