diff --git a/src/pages/MyEarnings/ElasticPools/SinglePosition/CollectFeesPanel.tsx b/src/pages/MyEarnings/ElasticPools/SinglePosition/CollectFeesPanel.tsx index f5d1d35766..417ba4dc86 100644 --- a/src/pages/MyEarnings/ElasticPools/SinglePosition/CollectFeesPanel.tsx +++ b/src/pages/MyEarnings/ElasticPools/SinglePosition/CollectFeesPanel.tsx @@ -13,6 +13,7 @@ import { ButtonOutlined } from 'components/Button' import CurrencyLogo from 'components/CurrencyLogo' import { MouseoverTooltip } from 'components/Tooltip' import PROMM_FARM_ABI from 'constants/abis/v2/farm.json' +import FarmV2ABI from 'constants/abis/v2/farmv2.json' import { useActiveWeb3React, useWeb3React } from 'hooks' import { useProAmmNFTPositionManagerContract } from 'hooks/useContract' import { config } from 'hooks/useElasticLegacy' @@ -31,6 +32,7 @@ import { formatDollarAmount } from 'utils/numbers' type Props = { nftId: string + fId: string feeValue0: CurrencyAmount feeValue1: CurrencyAmount feeUsd: number @@ -43,9 +45,11 @@ type Props = { } const FarmInterface = new Interface(PROMM_FARM_ABI) +const FarmV2Interface = new Interface(FarmV2ABI) const CollectFeesPanel: React.FC = ({ nftId, + fId, chainId, feeUsd, feeValue0, @@ -140,14 +144,19 @@ const CollectFeesPanel: React.FC = ({ const amount0Min = feeValue0.subtract(feeValue0.multiply(basisPointsToPercent(allowedSlippage))) const amount1Min = feeValue1.subtract(feeValue1.multiply(basisPointsToPercent(allowedSlippage))) try { - const encoded = FarmInterface.encodeFunctionData('claimFee', [ - [nftId], - amount0Min.quotient.toString(), - amount1Min.quotient.toString(), - poolAddress, - true, - deadline?.toString(), - ]) + const encoded = (fId ? FarmV2Interface : FarmInterface).encodeFunctionData( + 'claimFee', + fId + ? [fId, [nftId], amount0Min.quotient.toString(), amount1Min.quotient.toString(), deadline?.toString(), true] + : [ + [nftId], + amount0Min.quotient.toString(), + amount1Min.quotient.toString(), + poolAddress, + true, + deadline?.toString(), + ], + ) sendTransaction({ to: farmAddress, diff --git a/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx b/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx index 87d0b21586..96a319db56 100644 --- a/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx +++ b/src/pages/MyEarnings/ElasticPools/SinglePosition/PositionView.tsx @@ -15,6 +15,7 @@ import Divider from 'components/Divider' import FormattedCurrencyAmount from 'components/FormattedCurrencyAmount' import { MouseoverTooltip } from 'components/Tooltip' import PROMM_FARM_ABI from 'constants/abis/v2/farm.json' +import FarmV2ABI from 'constants/abis/v2/farmv2.json' import { VERSION } from 'constants/v2' import { useActiveWeb3React, useWeb3React } from 'hooks' import { useAllTokens } from 'hooks/Tokens' @@ -39,6 +40,7 @@ import { formatDollarAmount } from 'utils/numbers' import ActionButtons from './ActionButtons' const FarmInterface = new Interface(PROMM_FARM_ABI) +const FarmV2Interface = new Interface(FarmV2ABI) const PositionView: React.FC = props => { const { positionEarning, position, pendingFee, tokenPrices: prices, chainId, currency0, currency1 } = props @@ -103,6 +105,7 @@ const PositionView: React.FC = props => { const onRemoveLiquidityFromLegacyPosition = async () => { if (currentChainId !== chainId) { changeNetwork(chainId, () => { + console.log(chainId) dispatch(updateChainId(chainId)) removeLiquidity() }) @@ -114,35 +117,62 @@ const PositionView: React.FC = props => { const theme = useTheme() const tokens = useAllTokens(true, chainId) - const farmRewards = positionEarning.joinedPositions?.[0]?.farmingPool?.rewardTokensIds?.map((rwId, index) => { - const token = tokens[rwId] || new Token(chainId, rwId, 18, '', '') + let farmRewards = + positionEarning.joinedPositions?.[0]?.farmingPool?.rewardTokensIds?.map((rwId, index) => { + const token = tokens[rwId] || new Token(chainId, rwId, 18, '', '') - return CurrencyAmount.fromRawAmount(token, positionEarning.joinedPositions?.[0]?.pendingRewards?.[index] || '0') - }) + return CurrencyAmount.fromRawAmount(token, positionEarning.joinedPositions?.[0]?.pendingRewards?.[index] || '0') + }) || [] + + const farmV2Rewards = + positionEarning.farmV2DepositedPosition?.pendingRewards.map((amount, index) => { + const tokenId = positionEarning.farmV2DepositedPosition?.farmV2.rewards[index].token || '' + const token = tokens[tokenId] || new Token(chainId, tokenId, 18, '', '') + + return CurrencyAmount.fromRawAmount(token, amount) + }) || [] + + farmRewards = farmRewards.concat(farmV2Rewards) + + console.log(farmRewards) + + const disabledHarvest = + !positionEarning.joinedPositions?.[0]?.pendingRewards?.some(item => item !== '0') && + !positionEarning.farmV2DepositedPosition?.pendingRewards?.some(item => item !== '0') const addTransactionWithType = useTransactionAdder() const handleHarvest = () => { - const farmContract = positionEarning.joinedPositions?.[0]?.farmId + const farmContract = + positionEarning.joinedPositions?.[0]?.farmId || positionEarning.farmV2DepositedPosition?.farmV2.id.split('_')[0] + const isInFarmV2 = !!positionEarning.farmV2DepositedPosition const pId = positionEarning.joinedPositions?.[0]?.pid + const fId = positionEarning?.farmV2DepositedPosition?.farmV2.id.split('_')[1] + const library = libraryRef.current dispatch(setShowPendingModal(MODAL_PENDING_TEXTS.HARVEST)) dispatch(setAttemptingTxn(true)) - if (!library || !pId || !farmContract) { + if (!library || (isInFarmV2 ? !fId : !pId) || !farmContract) { dispatch(setAttemptingTxn(false)) dispatch(setTxError('Something went wrong!')) return } - const encodedPid = defaultAbiCoder.encode(['tupple(uint256[] pIds)'], [{ pIds: [pId] }]) - const encodedData = FarmInterface.encodeFunctionData('harvestMultiplePools', [[positionEarning.id], [encodedPid]]) + let encodedData = '' + if (isInFarmV2) { + encodedData = FarmV2Interface.encodeFunctionData('claimReward', [fId, [positionEarning.id]]) + } else { + const encodedPid = defaultAbiCoder.encode(['tupple(uint256[] pIds)'], [{ pIds: [pId] }]) + encodedData = FarmInterface.encodeFunctionData('harvestMultiplePools', [[positionEarning.id], [encodedPid]]) + } const txn = { to: farmContract, data: encodedData, } + library .getSigner() .estimateGas(txn) @@ -251,12 +281,17 @@ const PositionView: React.FC = props => { = props => { item !== '0')} + disabled={disabledHarvest} style={{ height: '36px', width: 'fit-content', diff --git a/src/services/earning/types.ts b/src/services/earning/types.ts index 3813e85228..e6c0ad8891 100644 --- a/src/services/earning/types.ts +++ b/src/services/earning/types.ts @@ -85,6 +85,14 @@ export type ElasticPositionEarningWithDetails = { pendingRewardUSD: string[] liquidity: string }[] + + farmV2DepositedPosition: { + farmV2: { + id: string + rewards: Array<{ amount: string; index: number; token: string }> + } + pendingRewards: Array + } } & HistoricalEarning export type ClassicPositionEarningWithDetails = {