From f500aae7a694c97209c10120fc967b1e53c50633 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Thu, 3 Oct 2024 11:56:37 +0200 Subject: [PATCH 1/2] fix price impact in swap simulation --- src/store/sagas/swap.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/store/sagas/swap.ts b/src/store/sagas/swap.ts index 1675fa7a..32d2bbbf 100644 --- a/src/store/sagas/swap.ts +++ b/src/store/sagas/swap.ts @@ -303,7 +303,7 @@ export function* handleGetSimulateResult(action: PayloadAction) { byAmountIn, xToY ? MIN_SQRT_PRICE : MAX_SQRT_PRICE ) - console.log(result) + if (result.maxSwapStepsReached || result.globalInsufficientLiquidity) { if ( byAmountIn @@ -312,7 +312,6 @@ export function* handleGetSimulateResult(action: PayloadAction) { ) { insufficientLiquidityAmountOut = byAmountIn ? result.amountOut : result.amountIn fee = pool.poolKey.feeTier.fee - priceImpact = 1 errors.push(SwapError.MaxSwapStepsReached) } @@ -351,7 +350,7 @@ export function* handleGetSimulateResult(action: PayloadAction) { actions.setSimulateResult({ poolKey: swapPossible ? poolKey : null, amountOut: validatedAmountOut, - priceImpact, + priceImpact: swapPossible ? priceImpact : 1, targetSqrtPrice, fee, errors From 4a1d7711dbd3103e1a18fab329c3e67037c5c2c9 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Thu, 3 Oct 2024 13:11:57 +0200 Subject: [PATCH 2/2] fix slippage formatting --- src/components/Swap/Swap.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Swap/Swap.tsx b/src/components/Swap/Swap.tsx index 2a6c1b66..689a4020 100644 --- a/src/components/Swap/Swap.tsx +++ b/src/components/Swap/Swap.tsx @@ -748,7 +748,7 @@ export const Swap: React.FC = ({ onSwap( simulateResult.poolKey, - BigInt((+slippTolerance * Number(PERCENTAGE_DENOMINATOR)) / 100), + BigInt(Math.round((+slippTolerance * Number(PERCENTAGE_DENOMINATOR)) / 100)), simulateResult.targetSqrtPrice, tokenFrom, tokenTo, @@ -777,7 +777,7 @@ export const Swap: React.FC = ({ onSwap( simulateResult.poolKey, - BigInt((+slippTolerance * Number(PERCENTAGE_DENOMINATOR)) / 100), + BigInt(Math.round((+slippTolerance * Number(PERCENTAGE_DENOMINATOR)) / 100)), simulateResult.targetSqrtPrice, tokenFrom, tokenTo,