Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 committed Feb 6, 2025
1 parent d4d5bef commit fc0fb89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions sdks/router-sdk/src/entities/mixedRoute/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('MixedRoute', () => {

it('real v3 weth pool and real v4 eth pool', () => {
const route = new MixedRouteSDK([pool_v3_0_weth, pool_v4_weth_eth, pool_v4_1_eth], token0, token1)
console.log(JSON.stringify(route.path, null, 2))
expect(route.path).toEqual([token0, weth, token1])
expect(route.pools).toEqual([pool_v3_0_weth, pool_v4_1_eth])
})
Expand Down Expand Up @@ -118,11 +117,21 @@ describe('MixedRoute', () => {
})

it('cannot wrap mixed route object with pure v4 route that converts ETH -> WETH ', () => {
expect(() => new MixedRouteSDK([pool_v4_1_eth, pool_v4_0_weth], token1, token0)).toThrow('PATH')
const route = new MixedRouteSDK([pool_v4_1_eth, pool_v4_0_weth], token1, token0)
expect(route.pools).toEqual([pool_v4_1_eth, pool_v4_0_weth])
expect(route.path).toEqual([token1, ETHER, token0])
expect(route.input).toEqual(token1)
expect(route.output).toEqual(token0)
expect(route.chainId).toEqual(1)
})

it('cannot wrap mixed route object with pure v4 route that converts WETH -> ETH ', () => {
expect(() => new MixedRouteSDK([pool_v4_0_weth, pool_v4_1_eth], token0, token1)).toThrow('PATH')
const route = new MixedRouteSDK([pool_v4_0_weth, pool_v4_1_eth], token0, token1)
expect(route.pools).toEqual([pool_v4_0_weth, pool_v4_1_eth])
expect(route.path).toEqual([token0, weth, token1])
expect(route.input).toEqual(token0)
expect(route.output).toEqual(token1)
expect(route.chainId).toEqual(1)
})

it('wraps complex mixed route object and successfully constructs a path from the tokens', () => {
Expand Down
4 changes: 2 additions & 2 deletions sdks/router-sdk/src/entities/mixedRoute/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class MixedRouteSDK<TInput extends Currency, TOutput extends Currency> {

let outputToken
if (
(pool instanceof V4Pool && !pool.involvesToken(inputToken) && !(prevPool instanceof V4Pool)) ||
(!(pool instanceof V4Pool) && inputToken.isNative && prevPool instanceof V4Pool)
(pool instanceof V4Pool && !pool.involvesToken(inputToken)) ||
(!(pool instanceof V4Pool) && inputToken.isNative)
) {
// We handle the case where the inputToken =/= pool.token0 or pool.token1. There are 2 specific cases.
if (inputToken.equals(pool.token0.wrapped)) {
Expand Down

0 comments on commit fc0fb89

Please sign in to comment.