joshstevens19 / simple-uniswap-sdk

Uniswap SDK which handles the routes automatically for you, changes in trade quotes reactive subscriptions, exposure to formatted easy to understand information, bringing back the best trade quotes automatically, generating transactions for you and much more.
MIT License
188 stars 95 forks source link

Output trade fails on Uniswap V2 #36

Open terence-crypto opened 2 years ago

terence-crypto commented 2 years ago

I found a potential bug in the code used to get the amountInMax:

https://github.com/uniswap-integration/simple-uniswap-sdk/blob/1629b680e615ce9851a4f7e7a3ba0187beac8261/src/factories/router/uniswap-router.factory.ts#L1935

Not sure why there's a check there for UniswapVersion.v3, but seems like this line causes output trades on Uniswap V2 to fail with EXCESSIVE_INPUT_AMOUNT because it subtracts the slippage, resulting in an amountInMax value lower than the expected amount.

Probably related to issue: #28

hustynetwork commented 2 years ago

Did you find a work around yet? I'm stuck with the same issue. If I change the value in second input (Exact out), the transaction data's "amountInMax" is less than "expectedConvertQuote".

Hence I'm stuck with this error :

image

However when I manually tried to increase the value of "amountInMax" it works.

tyleung commented 2 years ago

@hustynetwork Yeah, I removed the second conditional here https://github.com/joshstevens19/simple-uniswap-sdk/blob/1629b680e615ce9851a4f7e7a3ba0187beac8261/src/factories/router/uniswap-router.factory.ts#L1935 and it seems to work fine so far.

hustynetwork commented 2 years ago

@tyleung Thanks for the comment. I'm new to modifying things on node_modules directly. Can you suggest me how did you edit the file and added it into your project? When I forked and added the project, there is no "dist" file in node_modules.