From 930d4955ea23b83b186093bf1065a475e9032ff8 Mon Sep 17 00:00:00 2001 From: Nguyen Van Viet Date: Fri, 1 Dec 2023 15:08:41 +0700 Subject: [PATCH] fix: use 99.99% in case remove liq and pos in dynamic farm (#2418) --- src/pages/RemoveLiquidityProAmm/index.tsx | 5 +++-- src/state/burn/proamm/hooks.tsx | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pages/RemoveLiquidityProAmm/index.tsx b/src/pages/RemoveLiquidityProAmm/index.tsx index d0523fe4da..9ce51d4687 100644 --- a/src/pages/RemoveLiquidityProAmm/index.tsx +++ b/src/pages/RemoveLiquidityProAmm/index.tsx @@ -164,8 +164,9 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { const owner = useSingleCallResult(!!tokenId ? positionManager : null, 'ownerOf', [tokenId.toNumber()]).result?.[0] const isFarmV2 = networkInfo.elastic.farmV2S?.map(item => item.toLowerCase()).includes(owner?.toLowerCase()) const isFarmV21 = networkInfo.elastic['farmV2.1S']?.map(item => item.toLowerCase()).includes(owner?.toLowerCase()) + const isDynamicFarm = networkInfo.elastic.farms.flat().includes(isAddressString(chainId, owner)) - const ownByFarm = networkInfo.elastic.farms.flat().includes(isAddressString(chainId, owner)) || isFarmV2 || isFarmV21 + const ownByFarm = isDynamicFarm || isFarmV2 || isFarmV21 const ownsNFT = owner === account || ownByFarm @@ -195,7 +196,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) { outOfRange, error, parsedAmounts, - } = useDerivedProAmmBurnInfo(position, receiveWETH) + } = useDerivedProAmmBurnInfo(position, receiveWETH, isDynamicFarm) const currency0IsETHER = !!(chainId && liquidityValue0?.currency.isNative) const currency0IsWETH = !!(chainId && liquidityValue0?.currency.equals(WETH[chainId])) diff --git a/src/state/burn/proamm/hooks.tsx b/src/state/burn/proamm/hooks.tsx index 4820a46297..c113bc0ca5 100644 --- a/src/state/burn/proamm/hooks.tsx +++ b/src/state/burn/proamm/hooks.tsx @@ -21,6 +21,7 @@ export function useBurnProAmmState(): AppState['burnProAmm'] { export function useDerivedProAmmBurnInfo( position?: PositionDetails, asWETH = false, + isDynamicFarm = false, ): { position?: Position liquidityPercentage?: Percent @@ -90,6 +91,7 @@ export function useDerivedProAmmBurnInfo( if (independentField === Field.LIQUIDITY_PERCENT) { liquidityPercentage = new Percent(typedValue, '100') } + // user specified a specific amount of token a or b else { if (!!tokens[independentField]) { @@ -101,6 +103,10 @@ export function useDerivedProAmmBurnInfo( } } + if (isDynamicFarm && +liquidityPercentage.toFixed() === 100) { + liquidityPercentage = new Percent('9999', '10000') + } + const discountedAmount0 = positionSDK ? liquidityPercentage.multiply(positionSDK.amount0.quotient).quotient : undefined