From 7981d22855585ffdb08b23851683f3931132cad4 Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Thu, 4 May 2023 10:56:18 +0800 Subject: [PATCH 1/2] fix: price impact high detection --- src/LiNEAR/Unstake.jsx | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/LiNEAR/Unstake.jsx b/src/LiNEAR/Unstake.jsx index 2d95b56..11f8f6c 100644 --- a/src/LiNEAR/Unstake.jsx +++ b/src/LiNEAR/Unstake.jsx @@ -79,29 +79,22 @@ const receivedDelayedUnstakeNear = getReceivedDelayedUnstakeNear(); const receivedInstantUnstakeNear = getReceivedInstantUnstakeNear(); const UNSTAKE_DIFF_ERROR_RATIO = 0.05; const IMPACT_TOO_HIGH_ERROR = "Price impact high. Unstake less or try later"; -if ( - !state.inputError && +const priceImpactHigh = isValid(receivedDelayedUnstakeNear) && isValid(receivedInstantUnstakeNear) && + receivedDelayedUnstakeNear > 0 && + receivedInstantUnstakeNear > 0 && state.inputValue === state.swapAmountIn && // compare received NEAR only if the input amounts matches Big(receivedDelayedUnstakeNear) .minus(receivedInstantUnstakeNear) .div(receivedDelayedUnstakeNear) - .gt(UNSTAKE_DIFF_ERROR_RATIO) -) { + .gt(UNSTAKE_DIFF_ERROR_RATIO); + +if (!state.inputError && priceImpactHigh) { State.update({ inputError: IMPACT_TOO_HIGH_ERROR, }); -} else if ( - state.inputError === IMPACT_TOO_HIGH_ERROR && - isValid(receivedDelayedUnstakeNear) && - isValid(receivedInstantUnstakeNear) && - state.inputValue === state.swapAmountIn && - Big(receivedDelayedUnstakeNear) - .minus(receivedInstantUnstakeNear) - .div(receivedDelayedUnstakeNear) - .lte(UNSTAKE_DIFF_ERROR_RATIO) -) { +} else if (state.inputError === IMPACT_TOO_HIGH_ERROR && priceImpactHigh) { State.update({ inputError: "", }); From 250807e0965dbfdea63c5a2b886fe0cf2a5db0f9 Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Thu, 4 May 2023 12:00:44 +0800 Subject: [PATCH 2/2] fix: price impact high condition --- src/LiNEAR/Unstake.jsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/LiNEAR/Unstake.jsx b/src/LiNEAR/Unstake.jsx index 11f8f6c..cd08a20 100644 --- a/src/LiNEAR/Unstake.jsx +++ b/src/LiNEAR/Unstake.jsx @@ -79,22 +79,32 @@ const receivedDelayedUnstakeNear = getReceivedDelayedUnstakeNear(); const receivedInstantUnstakeNear = getReceivedInstantUnstakeNear(); const UNSTAKE_DIFF_ERROR_RATIO = 0.05; const IMPACT_TOO_HIGH_ERROR = "Price impact high. Unstake less or try later"; -const priceImpactHigh = +const validReceivedUnstakeAmount = isValid(receivedDelayedUnstakeNear) && isValid(receivedInstantUnstakeNear) && receivedDelayedUnstakeNear > 0 && receivedInstantUnstakeNear > 0 && - state.inputValue === state.swapAmountIn && // compare received NEAR only if the input amounts matches + state.inputValue === state.swapAmountIn; // compare received NEAR only if the input amounts matches + +if ( + !state.inputError && + validReceivedUnstakeAmount && Big(receivedDelayedUnstakeNear) .minus(receivedInstantUnstakeNear) .div(receivedDelayedUnstakeNear) - .gt(UNSTAKE_DIFF_ERROR_RATIO); - -if (!state.inputError && priceImpactHigh) { + .gt(UNSTAKE_DIFF_ERROR_RATIO) +) { State.update({ inputError: IMPACT_TOO_HIGH_ERROR, }); -} else if (state.inputError === IMPACT_TOO_HIGH_ERROR && priceImpactHigh) { +} else if ( + state.inputError === IMPACT_TOO_HIGH_ERROR && + validReceivedUnstakeAmount && + Big(receivedDelayedUnstakeNear) + .minus(receivedInstantUnstakeNear) + .div(receivedDelayedUnstakeNear) + .lte(UNSTAKE_DIFF_ERROR_RATIO) +) { State.update({ inputError: "", });