Skip to content

Commit

Permalink
hardcode reward and fee to 0 (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv authored Nov 30, 2023
1 parent 9719cdd commit 7b009d4
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 92 deletions.
13 changes: 5 additions & 8 deletions src/components/ClassicElasticTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ function ClassicElasticTab() {
const isFarmPage = location.pathname.startsWith(APP_PATHS.FARMS)
const isMyPoolPage = location.pathname.startsWith(APP_PATHS.MY_POOLS)
const [isOpenElasticHacked, setOpenElasticHacked] = useState(
tab === VERSION.ELASTIC && !notSupportedElasticMsg && !skipAlert,
isMyPoolPage ? false : tab === VERSION.ELASTIC && !notSupportedElasticMsg && !skipAlert,
)

useEffect(() => {
if (isMyPoolPage) return
if (notSupportedClassicMsg) {
setOpenElasticHacked(!skipAlert)
}
if (tab === VERSION.ELASTIC && !notSupportedElasticMsg) {
setOpenElasticHacked(!skipAlert)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [chainId])
}, [chainId, isMyPoolPage])

const upToMedium = useMedia(`(max-width: ${MEDIA_WIDTHS.upToMedium}px)`)

Expand Down Expand Up @@ -282,15 +283,11 @@ function ClassicElasticTab() {
isOpen={isOpenElasticHacked}
onClose={() => {
setOpenElasticHacked(false)
if (!isMyPoolPage) {
handleSwitchTab(VERSION.CLASSIC)
}
handleSwitchTab(VERSION.CLASSIC)
}}
onConfirm={() => {
setOpenElasticHacked(false)
if (!isMyPoolPage) {
navigate({ pathname: APP_PATHS.MY_POOLS, search: 'skipAlert=1' })
}
navigate({ pathname: APP_PATHS.MY_POOLS, search: 'skipAlert=1' })
}}
/>
</Flex>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ProAmm/ProAmmFee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export default function ProAmmFee({
amount1Min.quotient.toString(),
deadline?.toString(),
buildFlagsForFarmV21({
isClaimFee: !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isSyncFee: !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isClaimFee: false, // !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isSyncFee: false, // !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isClaimReward: false,
isReceiveNative: true,
}),
Expand Down
33 changes: 16 additions & 17 deletions src/pages/ProAmmPool/PositionGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { FixedSizeGrid as FixedSizeGridRW, GridChildComponentProps, areEqual } f
import styled from 'styled-components'

import { useActiveWeb3React } from 'hooks'
import { useProAmmTickReader } from 'hooks/useContract'
import { useKyberSwapConfig } from 'state/application/hooks'
import { useSingleContractMultipleData } from 'state/multicall/hooks'
import { MEDIA_WIDTHS } from 'theme'
import { PositionDetails } from 'types/position'

Expand Down Expand Up @@ -65,7 +63,7 @@ const queryPositionLastCollectedTimes = gql`
`

function PositionGrid({ positions, refe }: { positions: PositionDetails[]; refe?: React.MutableRefObject<any> }) {
const { networkInfo, chainId } = useActiveWeb3React()
const { chainId } = useActiveWeb3React()
const { elasticClient } = useKyberSwapConfig(chainId)

const upToSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToSmall}px)`)
Expand Down Expand Up @@ -117,26 +115,27 @@ function PositionGrid({ positions, refe }: { positions: PositionDetails[]; refe?
[data],
)

const tickReaderContract = useProAmmTickReader()
const rewardRes = useSingleContractMultipleData(
tickReaderContract,
'getTotalFeesOwedToPosition',
positions.map(item => [networkInfo.elastic.nonfungiblePositionManager, item.poolId, item.tokenId]),
)
// TODO: Temporary hardcoded fee to 0
// const rewardRes = useSingleContractMultipleData(
// tickReaderContract,
// 'getTotalFeesOwedToPosition',
// positions.map(item => [networkInfo.elastic.nonfungiblePositionManager, item.poolId, item.tokenId]),
// )

const feeRewards = useMemo(() => {
return positions.reduce<{ [tokenId: string]: [string, string] }>((acc, item, index) => {
return positions.reduce<{ [tokenId: string]: [string, string] }>((acc, item, _index) => {
return {
...acc,
[item.tokenId.toString()]: rewardRes[index].result
? [
rewardRes[index].result?.token0Owed?.toString() || '0',
rewardRes[index].result?.token1Owed.toString() || '0',
]
: ['0', '0'],
[item.tokenId.toString()]: ['0', '0'],
// rewardRes[index].result
// ? [
// rewardRes[index].result?.token0Owed?.toString() || '0',
// rewardRes[index].result?.token1Owed.toString() || '0',
// ]
// : ['0', '0'] ,
}
}, {})
}, [positions, rewardRes])
}, [positions])

const itemData = createItemData(positions, liquidityTimes, farmingTimes, feeRewards, createdAts, refe)

Expand Down
40 changes: 19 additions & 21 deletions src/pages/ProAmmPool/PositionListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, t } from '@lingui/macro'
import { BigNumber } from 'ethers'
import mixpanel from 'mixpanel-browser'
import { stringify } from 'querystring'
import React, { useEffect, useMemo, useState } from 'react'
import React, { useMemo, useState } from 'react'
import { Link } from 'react-router-dom'
import { Flex, Text } from 'rebass'
import styled from 'styled-components'
Expand All @@ -22,15 +22,13 @@ import { MouseoverTooltip } from 'components/Tooltip'
import { APP_PATHS, PROMM_ANALYTICS_URL } from 'constants/index'
import { useActiveWeb3React } from 'hooks'
import { useToken } from 'hooks/Tokens'
import { useProMMFarmReadingContract } from 'hooks/useContract'
import useIsTickAtLimit from 'hooks/useIsTickAtLimit'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import { usePool } from 'hooks/usePools'
import useTheme from 'hooks/useTheme'
import { useElasticFarms } from 'state/farms/elastic/hooks'
import { UserPositionFarm } from 'state/farms/elastic/types'
import { useElasticFarmsV2 } from 'state/farms/elasticv2/hooks'
import { NEVER_RELOAD, useSingleCallResult } from 'state/multicall/hooks'
import { useTokenPrices } from 'state/tokenPrices/hooks'
import { ExternalLink, StyledInternalLink } from 'theme'
import { PositionDetails } from 'types/position'
Expand Down Expand Up @@ -165,7 +163,7 @@ function PositionListItem({
const { farms: farmV2s, userInfo } = useElasticFarmsV2()

let farmAddress = ''
let pid = ''
// let pid = ''
let rewardTokens: Currency[] = []

let hasActiveFarm = false
Expand All @@ -175,7 +173,7 @@ function PositionListItem({
farmAddress = farm.id
rewardTokens = pool.rewardTokens
if (pool.endTime > Date.now() / 1000) {
pid = pool.pid
// pid = pool.pid
hasActiveFarm = true
}
}
Expand All @@ -189,25 +187,25 @@ function PositionListItem({
f.ranges.some(r => positionDetails.tickLower <= r.tickLower && positionDetails.tickUpper >= r.tickUpper),
).length

const farmContract = useProMMFarmReadingContract(farmAddress)
// const farmContract = useProMMFarmReadingContract(farmAddress)

const tokenId = positionDetails.tokenId.toString()

const [farmReward, setFarmReward] = useState<BigNumber[] | null>(null)

const res = useSingleCallResult(
pid !== '' ? farmContract : undefined,
'getUserInfo',
pid !== '' ? [tokenId, pid] : undefined,
NEVER_RELOAD,
)
useEffect(() => {
if (res?.result?.rewardPending) {
setFarmReward(res.result.rewardPending)
} else {
setFarmReward(null)
}
}, [res])
const [farmReward, _setFarmReward] = useState<BigNumber[] | null>(null)

// const res = useSingleCallResult(
// pid !== '' ? farmContract : undefined,
// 'getUserInfo',
// pid !== '' ? [tokenId, pid] : undefined,
// NEVER_RELOAD,
// )
// useEffect(() => {
// if (res?.result?.rewardPending) {
// setFarmReward(res.result.rewardPending)
// } else {
// setFarmReward(null)
// }
// }, [res])

const token0 = useToken(token0Address)
const token1 = useToken(token1Address)
Expand Down
32 changes: 7 additions & 25 deletions src/pages/RemoveLiquidityProAmm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber } from '@ethersproject/bignumber'
import { TransactionResponse } from '@ethersproject/providers'
import { ZERO } from '@kyberswap/ks-sdk-classic'
import { ChainId, Currency, CurrencyAmount, Percent, WETH } from '@kyberswap/ks-sdk-core'
import { Currency, CurrencyAmount, Percent, WETH } from '@kyberswap/ks-sdk-core'
import { FeeAmount, NonfungiblePositionManager } from '@kyberswap/ks-sdk-elastic'
import { Trans, t } from '@lingui/macro'
import { captureException } from '@sentry/react'
Expand Down Expand Up @@ -29,7 +29,6 @@ import ProAmmPooledTokens from 'components/ProAmm/ProAmmPooledTokens'
import { RowBetween } from 'components/Row'
import Slider from 'components/Slider'
import { SLIPPAGE_EXPLANATION_URL } from 'components/SlippageWarningNote'
import Toggle from 'components/Toggle'
import { MouseoverTooltip, TextDashed } from 'components/Tooltip'
import TransactionConfirmationModal, {
ConfirmationModalContent,
Expand Down Expand Up @@ -154,14 +153,9 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
const { position } = useProAmmPositionsFromTokenId(tokenId)
const positionManager = useProAmmNFTPositionManagerReadingContract()
const theme = useTheme()
const [claimFee, setIsClaimFee] = useState(false)
const [claimFee, _setIsClaimFee] = useState(false)

const { networkInfo, account, chainId } = useActiveWeb3React()
useEffect(() => {
if (chainId === ChainId.LINEA || chainId === ChainId.SCROLL) {
setIsClaimFee(true)
}
}, [chainId])

const { library } = useWeb3React()
const toggleWalletModal = useWalletModalToggle()
Expand Down Expand Up @@ -317,9 +311,9 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
amount1Min.quotient.toString(),
deadline.toString(),
buildFlagsForFarmV21({
isClaimFee: claimFee && !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isSyncFee: !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isClaimReward: claimFee,
isClaimFee: false,
isSyncFee: false,
isClaimReward: false,
isReceiveNative: !receiveWETH,
}),
]
Expand All @@ -330,7 +324,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
amount0Min.quotient.toString(),
amount1Min.quotient.toString(),
deadline.toString(),
claimFee ? feeValue0?.greaterThan('0') : 0,
false, // isClaimFee
!receiveWETH,
]
: [
Expand All @@ -340,7 +334,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
amount1Min.quotient.toString(),
deadline.toString(),
!receiveWETH,
[claimFee && feeValue0?.greaterThan('0'), claimFee],
[false, false],
]

const gasEstimation = await contract.estimateGas.removeLiquidity(...params)
Expand Down Expand Up @@ -781,18 +775,6 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
/>
</div>
</TokenInputWrapper>

<Flex alignItems="center" sx={{ gap: '12px' }} marginTop="0.75rem">
<Text fontSize="12px" fontWeight="500">
Claim Your Fees Earned
</Text>
<Toggle
isActive={claimFee}
toggle={() => {
setIsClaimFee(prev => !prev)
}}
/>
</Flex>
</AmoutToRemoveContent>

{slippageStatus === SLIPPAGE_STATUS.HIGH && (
Expand Down
11 changes: 5 additions & 6 deletions src/state/burn/proamm/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ReactNode, useCallback, useMemo } from 'react'
import { useActiveWeb3React } from 'hooks'
import { useToken } from 'hooks/Tokens'
import { usePool } from 'hooks/usePools'
import { useTotalFeeOwedByElasticPosition } from 'hooks/useProAmmPreviousTicks'
import { AppState } from 'state'
import { useAppDispatch, useAppSelector } from 'state/hooks'
import { tryParseAmount } from 'state/swap/hooks'
Expand Down Expand Up @@ -128,9 +127,9 @@ export function useDerivedProAmmBurnInfo(
// error = error ?? <Trans>Enter a percent</Trans>
// }

const { feeOwed, loading: loadingFee } = useTotalFeeOwedByElasticPosition(pool, position?.tokenId.toString(), asWETH)
// const { feeOwed, loading: loadingFee } = useTotalFeeOwedByElasticPosition(pool, position?.tokenId.toString(), asWETH)

const [feeValue0, feeValue1] = feeOwed
// const [feeValue0, feeValue1] = feeOwed

const parsedAmounts: {
[Field.LIQUIDITY_PERCENT]: Percent
Expand All @@ -155,9 +154,9 @@ export function useDerivedProAmmBurnInfo(
liquidityPercentage,
liquidityValue0,
liquidityValue1,
feeValue0,
feeValue1,
loadingFee,
feeValue0: liquidityValue0?.currency ? CurrencyAmount.fromRawAmount(liquidityValue0?.currency, 0) : undefined,
feeValue1: liquidityValue1?.currency ? CurrencyAmount.fromRawAmount(liquidityValue1?.currency, 0) : undefined,
loadingFee: false,
outOfRange,
error,
parsedAmounts,
Expand Down
11 changes: 5 additions & 6 deletions src/state/farms/elastic/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultAbiCoder } from '@ethersproject/abi'
import { ChainId, Currency, CurrencyAmount, Token } from '@kyberswap/ks-sdk-core'
import { Currency, CurrencyAmount, Token } from '@kyberswap/ks-sdk-core'
import { FeeAmount, Position, computePoolAddress } from '@kyberswap/ks-sdk-elastic'
import { t } from '@lingui/macro'
import { BigNumber } from 'ethers'
Expand Down Expand Up @@ -672,7 +672,6 @@ const getUserInfoFragment = farmInterface.getFunction('getUserInfo')
export function useJoinedPositions() {
const positions = useDepositedNfts()
const { farms } = useElasticFarms()
const { chainId } = useActiveWeb3React()

const params = useMemo(() => {
return (farms || []).map(farm => {
Expand Down Expand Up @@ -759,9 +758,9 @@ export function useJoinedPositions() {
rewardPendings[pid][i] = rewardPendings[pid][i].add(amount)
}

// TODO:
if (chainId !== ChainId.LINEA && chainId !== ChainId.SCROLL)
rewardPendings[pid][i] = CurrencyAmount.fromRawAmount(currency, 0)
// TODO: hardcode for now. maybe all farm code will be delete in the future :/
rewardPendings[pid][i] = CurrencyAmount.fromRawAmount(currency, 0)
rewardByNft[id][i] = CurrencyAmount.fromRawAmount(currency, 0)
})
}
}
Expand All @@ -774,7 +773,7 @@ export function useJoinedPositions() {
}
})
return userInfo
}, [result, params, chainId, farms, positions])
}, [result, params, farms, positions])
}

export function useUserInfoByFarm(farmAddress: string): UserInfo {
Expand Down
12 changes: 5 additions & 7 deletions src/state/farms/elasticv2/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { gql, useLazyQuery } from '@apollo/client'
import { defaultAbiCoder } from '@ethersproject/abi'
import { getCreate2Address } from '@ethersproject/address'
import { keccak256 } from '@ethersproject/solidity'
import { ChainId, CurrencyAmount, Token, WETH } from '@kyberswap/ks-sdk-core'
import { CurrencyAmount, Token, WETH } from '@kyberswap/ks-sdk-core'
import { FeeAmount, Pool, Position } from '@kyberswap/ks-sdk-elastic'
import { BigNumber } from 'ethers'
import { Interface } from 'ethers/lib/utils'
Expand Down Expand Up @@ -416,12 +416,10 @@ export default function ElasticFarmV2Updater({ interval = true }: { interval?: b
+stakedPos.amount1.toExact() * (prices[stakedPos.amount1.currency.wrapped.address] || 0)

// TODO: temporary set 0: item.currentUnclaimedRewards[i].toString()
const unclaimedRewards =
chainId === ChainId.LINEA || chainId === ChainId.SCROLL
? farm.totalRewards.map((rw, i) =>
CurrencyAmount.fromRawAmount(rw.currency, item.currentUnclaimedRewards[i].toString()),
)
: farm.totalRewards.map((rw, _i) => CurrencyAmount.fromRawAmount(rw.currency, 0))
const unclaimedRewards = farm.totalRewards.map((rw, i) =>
CurrencyAmount.fromRawAmount(rw.currency, item.currentUnclaimedRewards[i].toString()),
)
// : farm.totalRewards.map((rw, _i) => CurrencyAmount.fromRawAmount(rw.currency, 0))

const unclaimedRewardsUsd = unclaimedRewards.reduce(
(total, item) => total + +item.toExact() * (prices[item.currency.wrapped.address] || 0),
Expand Down

0 comments on commit 7b009d4

Please sign in to comment.