Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto claim reward farm v2 #2271

Merged
merged 9 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
VITE_TAG: ${{ needs.prepare.outputs.image_tag }}
CURRENT_BRANCH: ${{ needs.prepare.outputs.current_branch }}
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn build-prod
run: yarn build

- name: Docker build and push
uses: docker/build-push-action@v2
Expand Down
5 changes: 5 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const disabledPrimary = css<{
export const ButtonPrimary = styled(Base)`
background-color: ${({ theme }) => theme.primary};
color: ${({ theme }) => theme.textReverse};
&:hover {
color: ${({ theme }) => theme.textReverse};
filter: brightness(0.8);
}

&:active {
box-shadow: 0 0 0 1pt ${({ theme }) => darken(0.1, theme.primary)};
background-color: ${({ theme }) => darken(0.1, theme.primary)};
Expand Down
12 changes: 10 additions & 2 deletions src/components/ClassicElasticTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ function ClassicElasticTab() {

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

const showLegacyExplicit = upToMedium ? false : isFarmpage ? shouldShowFarmTab : shouldShowPositionTab

const dontShowLegacy = [ChainId.ZKEVM, ChainId.BASE, ChainId.LINEA].includes(chainId)

const showLegacyExplicit =
upToMedium || dontShowLegacy ? false : isFarmpage ? shouldShowFarmTab : shouldShowPositionTab

useEffect(() => {
if (dontShowLegacy && tab === VERSION.ELASTIC_LEGACY) {
const newQs = { ...qs, tab: VERSION.ELASTIC }
navigate({ search: stringify(newQs) }, { replace: true })
}
}, [tab, dontShowLegacy, navigate, qs])

const legacyTag = (small?: boolean) => (
<Text
sx={{
Expand Down
44 changes: 33 additions & 11 deletions src/components/ProAmm/ProAmmFee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import FormattedCurrencyAmount from 'components/FormattedCurrencyAmount'
import QuestionHelper from 'components/QuestionHelper'
import { RowBetween, RowFixed } from 'components/Row'
import TransactionConfirmationModal, { TransactionErrorContent } from 'components/TransactionConfirmationModal'
import FarmV21ABI from 'constants/abis/v2/farmv2.1.json'
import FarmV2ABI from 'constants/abis/v2/farmv2.json'
import { EVMNetworkInfo } from 'constants/networks/type'
import { useActiveWeb3React, useWeb3React } from 'hooks'
import { useContract, useProAmmNFTPositionManagerContract, useProMMFarmContract } from 'hooks/useContract'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
Expand All @@ -26,7 +28,7 @@ import { useElasticFarmsV2 } from 'state/farms/elasticv2/hooks'
import { useTransactionAdder } from 'state/transactions/hooks'
import { TRANSACTION_TYPE } from 'state/transactions/type'
import { useUserSlippageTolerance } from 'state/user/hooks'
import { basisPointsToPercent, calculateGasMargin, formattedNumLong } from 'utils'
import { basisPointsToPercent, buildFlagsForFarmV21, calculateGasMargin, formattedNumLong } from 'utils'

export default function ProAmmFee({
tokenId,
Expand All @@ -50,7 +52,7 @@ export default function ProAmmFee({
feeValue0: CurrencyAmount<Currency> | undefined
feeValue1: CurrencyAmount<Currency> | undefined
}) {
const { account } = useActiveWeb3React()
const { account, networkInfo } = useActiveWeb3React()
const { library } = useWeb3React()
const theme = useTheme()
const token0Shown = feeValue0?.currency || position.pool.token0
Expand Down Expand Up @@ -108,12 +110,18 @@ export default function ProAmmFee({
const { userInfo } = useElasticFarmsV2()
const info = userInfo?.find(item => item.nftId.toString() === tokenId.toString())
const address = info?.farmAddress

const isFarmV21 = (networkInfo as EVMNetworkInfo).elastic['farmV2.1S']
?.map(item => item.toLowerCase())
.includes(address?.toLowerCase())

const farmV2Contract = useContract(address, FarmV2ABI)
const farmV21Contract = useContract(address, FarmV21ABI)

const collectFeeFromFarmContract = async () => {
const isInFarmV2 = !!info

const contract = isInFarmV2 ? farmV2Contract : farmContract
const contract = isInFarmV2 ? (isFarmV21 ? farmV21Contract : farmV2Contract) : farmContract

if (!contract || !feeValue0 || !feeValue1) {
setAttemptingTxn(false)
Expand All @@ -125,14 +133,28 @@ export default function ProAmmFee({
const amount1Min = feeValue1.subtract(feeValue1.multiply(basisPointsToPercent(allowedSlippage)))
try {
const params = isInFarmV2
? [
info.fId,
[tokenId.toString()],
amount0Min.quotient.toString(),
amount1Min.quotient.toString(),
deadline?.toString(),
true,
]
? isFarmV21
? [
info.fId,
[tokenId.toString()],
amount0Min.quotient.toString(),
amount1Min.quotient.toString(),
deadline?.toString(),
buildFlagsForFarmV21({
isClaimFee: !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isSyncFee: !!feeValue0?.greaterThan('0') && !!feeValue1?.greaterThan('0'),
isClaimReward: false,
isReceiveNative: true,
}),
]
: [
info.fId,
[tokenId.toString()],
amount0Min.quotient.toString(),
amount1Min.quotient.toString(),
deadline?.toString(),
true,
]
: [
[tokenId.toString()],
amount0Min.quotient.toString(),
Expand Down
Loading
Loading