Skip to content

Commit

Permalink
chore: Don't do mint calls for non bal reward gauges
Browse files Browse the repository at this point in the history
  • Loading branch information
garethfuller committed Sep 10, 2024
1 parent 7d526bc commit 7c1f2ea
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
14 changes: 7 additions & 7 deletions lib/modules/pool/actions/claim/useClaimAllRewardsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { BalTokenRewardsResult } from '@/lib/modules/portfolio/PortfolioClaim/us
import { ClaimableBalancesResult } from '@/lib/modules/portfolio/PortfolioClaim/useClaimableBalances'
import { allClaimableGaugeAddressesFor } from '../../pool.helpers'
import { ClaimablePool } from './ClaimProvider'
import { Address } from 'viem'

const claimAllRewardsStepId = 'claim-all-rewards'

Expand Down Expand Up @@ -47,13 +48,12 @@ export function useClaimAllRewardsStep({
const gaugeAddresses = pools.flatMap(pool => allClaimableGaugeAddressesFor(pool))
const shouldClaimMany = gaugeAddresses.length > 1
const stakingService = selectStakingService(chain, stakingType)
const { data: claimData, isLoading } = useClaimCallDataQuery(
gaugeAddresses,
stakingService,
nonBalRewards.length > 0,
balRewards.length > 0,
isClaimQueryEnabled
)
const { data: claimData, isLoading } = useClaimCallDataQuery({
claimRewardGauges: nonBalRewards.map(r => r.gaugeAddress),
mintBalRewardGauges: balRewards.map(r => r.gaugeAddress as Address),
gaugeService: stakingService,
enabled: isClaimQueryEnabled,
})

const labels: TransactionLabels = {
init: `Claim${shouldClaimMany ? ' all' : ''}`,
Expand Down
14 changes: 11 additions & 3 deletions lib/modules/pool/actions/claim/useClaimAllRewardsSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useApproveMinterStep } from '@/lib/modules/staking/gauge/useMinterAppro
import { TransactionStep } from '@/lib/modules/transactions/transaction-steps/lib'
import { useMemo } from 'react'
import { ClaimAllRewardsStepParams, useClaimAllRewardsStep } from './useClaimAllRewardsStep'
import { useApproveRelayerStep } from '@/lib/modules/relayer/useApproveRelayerStep'
import { getChainId } from '@/lib/config/app.config'

export function useClaimAllRewardsSteps(params: ClaimAllRewardsStepParams) {
const pool = params.pools[0]
Expand All @@ -10,23 +12,29 @@ export function useClaimAllRewardsSteps(params: ClaimAllRewardsStepParams) {
}

const { chain } = pool
const chainId = getChainId(pool.chain)

const { step: relayerApprovalStep, isLoading: isLoadingRelayerApprovalStep } =
useApproveRelayerStep(chainId)
const { step: minterApprovalStep, isLoading: isLoadingMinterApprovalStep } =
useApproveMinterStep(chain)

const { step: claimAllRewardsStep, isLoading: isLoadingClaimAllRewards } =
useClaimAllRewardsStep(params)

const steps = useMemo((): TransactionStep[] => {
const steps = [claimAllRewardsStep]
const steps = [relayerApprovalStep, claimAllRewardsStep]

if (params.balTokenRewardsQuery.balRewardsData.length > 0) {
steps.unshift(minterApprovalStep)
}

return steps
}, [claimAllRewardsStep, minterApprovalStep, params])
}, [relayerApprovalStep, claimAllRewardsStep, minterApprovalStep, params])

return {
isLoading: isLoadingMinterApprovalStep || isLoadingClaimAllRewards,
isLoading:
isLoadingRelayerApprovalStep || isLoadingMinterApprovalStep || isLoadingClaimAllRewards,
steps,
}
}
55 changes: 38 additions & 17 deletions lib/modules/pool/actions/claim/useClaimCallDataQuery.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
import { useQuery } from '@tanstack/react-query'
import { Address } from 'viem'
import { Address, Hex } from 'viem'
import { GaugeService } from '@/lib/shared/services/staking/gauge.service'
import { useMemo } from 'react'

export function useClaimCallDataQuery(
gaugeAddresses: Address[],
gaugeService: GaugeService | undefined,
hasUnclaimedNonBalRewards: boolean,
hasUnclaimedBalRewards: boolean,
enabled = true
) {
const inputData = {
hasUnclaimedNonBalRewards,
hasUnclaimedBalRewards,
gauges: gaugeAddresses,
outputReference: 0n,
}
export function useClaimCallDataQuery({
claimRewardGauges,
mintBalRewardGauges,
gaugeService,
enabled = true,
}: {
claimRewardGauges: Address[]
mintBalRewardGauges: Address[]
gaugeService: GaugeService | undefined
enabled?: boolean
}) {
const allGauges = useMemo(() => {
return [...claimRewardGauges, ...mintBalRewardGauges]
}, [claimRewardGauges, mintBalRewardGauges])

const queryKey = ['claim', 'gauge', 'callData', allGauges]

const queryKey = ['claim', 'gauge', 'callData', inputData]
const queryFn = (): `0x${string}`[] => {
if (!gaugeService) return []
return gaugeService.getGaugeClaimRewardsContractCallData(inputData)

const calls: Hex[] = []

if (claimRewardGauges.length > 0) {
const claimRewardsCallData = gaugeService.getGaugeEncodeClaimRewardsCallData({
gauges: claimRewardGauges,
})
calls.push(claimRewardsCallData)
}

if (mintBalRewardGauges.length > 0) {
const mintCallData = gaugeService.getGaugeEncodeMintCallData({
gauges: mintBalRewardGauges,
outputReference: 0n,
})
calls.push(mintCallData)
}

return calls
}

const query = useQuery({
queryKey,
queryFn,
enabled: enabled && gaugeService && gaugeAddresses.length > 0,
enabled: enabled && gaugeService && allGauges.length > 0,
})

return {
Expand Down

0 comments on commit 7c1f2ea

Please sign in to comment.