Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting V2 trades always throw an error "Unexpected pool type in route when constructing trade object" #477

Open
Brenzee opened this issue Jan 22, 2024 · 2 comments

Comments

@Brenzee
Copy link

Brenzee commented Jan 22, 2024

  • I'm submitting a ...
    [X] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

When route is called with config

{
   protocols: ["V2"]
}

it always fails with error

"Unexpected pool type in route when constructing trade object"

This error comes from the @uniswap/router-sdk

This makes the smart-order-router unusable for any V2 swaps unless a specific @uniswap/router-sdk version is forced.

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

I am pretty confident this happens because smart-order-router uses "@uniswap/v2-sdk": "^3.2.3", but the router-sdk uses "@uniswap/v2-sdk": "^4.0.1"

When I force @uniswap/router-sdk to be version 1.7.1, it works fine. I suggest either support the @uniswap/v2-sdk versioni 4 or use a specific @uniswap/router-sdk version, that does not use @uniswap/v2-sdk version 4.

@kasparkallas
Copy link

kasparkallas commented Aug 19, 2024

I very often get this error even when I try to force it to only look for "V3" by specifying protocols: [ "V3" ].

Update 1

This line is probably the issue for me:

protocols: [Protocol.V3, Protocol.V2],

Update 2

I think I fixed it for my use-case like this:

  const swapRoute = await alphaRouter.route(
    swapInTokenAmount,
    swapOutToken,
    TradeType.EXACT_INPUT, 
    swapOptions,
    {
      v2PoolSelection: undefined, // Hacky way to make sure Uniswap doesn't use V2 pools.
      protocols: ["V3" as any], // Uniswap type issue, and this is not respected anyway, but added for completeness sake.
    }
  );

and:

  const alphaRouter = new AlphaRouter({
    chainId: config.chainId,
    provider: new ethers.providers.JsonRpcProvider(config.rpcUrl),
    v2Supported: [] // Remove V2 routes
  });

Update 3

Nope, still getting the error sometimes.

Update 4

Direct link to the problematic code in router SDK: https://github.com/Uniswap/sdks/blob/b2148e66482d72d0948895ad90b7dbd481616000/sdks/router-sdk/src/entities/trade.ts#L133

@kasparkallas
Copy link

kasparkallas commented Aug 19, 2024

@Brenzee I don't quite get the explanation about the versions as the latest @uniswap/smart-order-router is referencing the following packages in the published package.json:

    "@uniswap/default-token-list": "^11.13.0",
    "@uniswap/permit2-sdk": "^1.3.0",
    "@uniswap/router-sdk": "^1.10.0",
    "@uniswap/sdk-core": "^5.3.0",
    "@uniswap/swap-router-contracts": "^1.3.1",
    "@uniswap/token-lists": "^1.0.0-beta.31",
    "@uniswap/universal-router": "^1.6.0",
    "@uniswap/universal-router-sdk": "^2.2.4",
    "@uniswap/v2-sdk": "^4.3.2",
    "@uniswap/v3-sdk": "^3.13.0",
    "@uniswap/v4-sdk": "^1.0.0",

These packages seem to be the latest and don't align with your description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants