v2-sdk icon indicating copy to clipboard operation
v2-sdk copied to clipboard

Providing low input amount raises an error that's never returned

Open fomotrader opened this issue 3 years ago • 1 comments

As a developer testing out the uniswap SDK, when an error is raised because the input amount I provided is too low, instead of returning that and surfacing it up to me. The SDK just swallows it and silently carries before another part of my code blows up.

Why do we do that?

https://github.com/Uniswap/uniswap-v2-sdk/blob/main/src/entities/trade.ts#L266

fomotrader avatar May 12 '21 05:05 fomotrader

Pair.getOutputAmount can throw the InsufficientInputAmount error when a swap would result in 0 output, the involvesToken invariant, as well as the InsufficientReservesError are already checked before that. In all cases it makes sense to consider this Pair as invalid and continue with the loop. If all pairs are invalid, the result of the recursive function will just be an empty Array.

Florian-S-A-W avatar May 09 '23 11:05 Florian-S-A-W