Skip to content

Commit

Permalink
fix: use 99.99% in case remove liq and pos in dynamic farm (#2418)
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv authored Dec 1, 2023
1 parent 7b009d4 commit 930d495
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pages/RemoveLiquidityProAmm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]))
Expand Down
6 changes: 6 additions & 0 deletions src/state/burn/proamm/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function useBurnProAmmState(): AppState['burnProAmm'] {
export function useDerivedProAmmBurnInfo(
position?: PositionDetails,
asWETH = false,
isDynamicFarm = false,
): {
position?: Position
liquidityPercentage?: Percent
Expand Down Expand Up @@ -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]) {
Expand All @@ -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
Expand Down

0 comments on commit 930d495

Please sign in to comment.