Skip to content

Commit

Permalink
Add Insufficient Liquidity warning when tokenIn total cannot be gathered
Browse files Browse the repository at this point in the history
  • Loading branch information
dib542 committed Oct 20, 2022
1 parent 823a52c commit 3dd5f92
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/pages/Swap/hooks/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ export function router(
const sortedTicks = forward
? exactPair.poolsZeroToOne
: exactPair.poolsOneToZero;
const maxIn = sortedTicks.reduce((result, tick) => {
return result.plus(forward ? tick.reserve0 : tick.reserve1);
}, new BigNumber(0));
const amountIn = new BigNumber(value0);
if (amountIn.isGreaterThan(maxIn)) {
const error: Error & {
insufficientLiquidityIn?: boolean;
insufficientLiquidityOut?: boolean;
} = new Error('Not enough tick liquidity found to match trade');
error.insufficientLiquidityIn = true;
throw error;
}
return {
amountIn: amountIn,
tokenIn: tokenA,
Expand Down

0 comments on commit 3dd5f92

Please sign in to comment.