Skip to content

Commit

Permalink
support elastic hack
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Nov 24, 2023
1 parent ae3168b commit e91a7e6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
26 changes: 21 additions & 5 deletions src/pages/RemoveLiquidityProAmm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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,6 +155,8 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
const { position } = useProAmmPositionsFromTokenId(tokenId)
const positionManager = useProAmmNFTPositionManagerReadingContract()
const theme = useTheme()
const [claimFee, setIsClaimFee] = useState(false)

const { networkInfo, account, chainId, isEVM } = useActiveWeb3React()
const { library } = useWeb3React()
const toggleWalletModal = useWalletModalToggle()
Expand Down Expand Up @@ -317,9 +320,9 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
amount1Min.quotient.toString(),
deadline.toString(),
buildFlagsForFarmV21({
isClaimFee: !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isClaimFee: claimFee && !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isSyncFee: !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isClaimReward: true,
isClaimReward: claimFee,
isReceiveNative: !receiveWETH,
}),
]
Expand All @@ -330,7 +333,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
amount0Min.quotient.toString(),
amount1Min.quotient.toString(),
deadline.toString(),
feeValue0?.greaterThan('0'),
claimFee ? feeValue0?.greaterThan('0') : 0,
!receiveWETH,
]
: [
Expand All @@ -340,7 +343,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
amount1Min.quotient.toString(),
deadline.toString(),
!receiveWETH,
[feeValue0?.greaterThan('0'), true],
[claimFee && feeValue0?.greaterThan('0'), claimFee],
]

const gasEstimation = await contract.estimateGas.removeLiquidity(...params)
Expand Down Expand Up @@ -409,7 +412,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
recipient: account,
deadline: deadline.toString(),
isRemovingLiquid: true,
havingFee: !(feeValue0.equalTo(JSBI.BigInt('0')) && feeValue1.equalTo(JSBI.BigInt('0'))),
havingFee: claimFee && !(feeValue0.equalTo(JSBI.BigInt('0')) && feeValue1.equalTo(JSBI.BigInt('0'))),
},
})
const txn = {
Expand All @@ -434,6 +437,7 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
})
})
.catch((error: any) => {
console.log('error', error)
setAttemptingTxn(false)

if (!didUserReject(error)) {
Expand Down Expand Up @@ -780,6 +784,18 @@ 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
3 changes: 3 additions & 0 deletions src/state/farms/elastic/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ export function useJoinedPositions() {
} else {
rewardPendings[pid][i] = rewardPendings[pid][i].add(amount)
}

// TODO:
rewardPendings[pid][i] = CurrencyAmount.fromRawAmount(currency, 0)
})
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/state/farms/elasticv2/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ export default function ElasticFarmV2Updater({ interval = true }: { interval?: b
+stakedPos.amount0.toExact() * (prices[stakedPos.amount0.currency.wrapped.address] || 0) +
+stakedPos.amount1.toExact() * (prices[stakedPos.amount1.currency.wrapped.address] || 0)

const unclaimedRewards = farm.totalRewards.map((rw, i) =>
CurrencyAmount.fromRawAmount(rw.currency, item.currentUnclaimedRewards[i].toString()),
)
// TODO: temporary set 0: item.currentUnclaimedRewards[i].toString()
const unclaimedRewards = 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
4 changes: 2 additions & 2 deletions src/state/user/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDispatch, useSelector } from 'react-redux'
import { useGetParticipantInfoQuery, useLazyGetParticipantInfoQuery } from 'services/kyberAISubscription'

import { SUGGESTED_BASES } from 'constants/bases'
import { TERM_FILES_PATH } from 'constants/index'
import { INITIAL_ALLOWED_SLIPPAGE, TERM_FILES_PATH } from 'constants/index'
import { SupportedLocale } from 'constants/locales'
import { PINNED_PAIRS } from 'constants/tokens'
import { useActiveWeb3React } from 'hooks'
Expand Down Expand Up @@ -199,7 +199,7 @@ export function useSwapSlippageTolerance(): [number, (slippage: number) => void]
export function usePoolSlippageTolerance(): [number, (slippage: number) => void] {
const dispatch = useDispatch<AppDispatch>()
const poolSlippageTolerance = useSelector<AppState, AppState['user']['poolSlippageTolerance']>(state => {
return state.user.poolSlippageTolerance
return state.user.poolSlippageTolerance || INITIAL_ALLOWED_SLIPPAGE
})
const setPoolSlippageTolerance = useCallback(
(poolSlippageTolerance: number) => {
Expand Down

0 comments on commit e91a7e6

Please sign in to comment.