Uniswap / smart-order-router

GNU General Public License v3.0
412 stars 419 forks source link

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

Open Brenzee opened 9 months ago

Brenzee commented 9 months ago

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.

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 commented 2 months ago

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: https://github.com/Uniswap/smart-order-router/blob/7d166a0e6bd209807cf6f4a4fc33161f90468985/src/routers/alpha-router/alpha-router.ts#L970

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 commented 2 months ago

@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.