-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...rewards/metrics/components/ABIMetrics.tsx → ...rics/components/ABIMetrics/ABIMetrics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/app/collective-rewards/metrics/components/ABIMetrics/hooks/useGetABI.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useGetRewardsERC20 } from '@/app/collective-rewards/rewards' | ||
import { usePricesContext } from '@/shared/context/PricesContext' | ||
import { useGetTotalAllocation } from '../../../hooks/useGetTotalAllocation' | ||
import { useBuilderContext, useGetGaugesArrayByType } from '@/app/collective-rewards/user' | ||
|
||
export const useGetABI = () => { | ||
const { data: cyclePayout, isLoading: isCyclePayoutLoading, error: cyclePayoutError } = useGetRewardsERC20() | ||
const { data: builders } = useBuilderContext() | ||
// FIXME: verify if this filter is correct | ||
// activatedBuilders already include the backer rewards percentage | ||
const activatedBuilders = builders.filter(builder => builder.stateFlags?.activated === false) | ||
// FIXME: for each builder, get votes allocated to that builder and calculate the weighted average | ||
const weightedAverageBuilderRewardsPct = 0n | ||
|
||
const { data: gauges } = useGetGaugesArrayByType('active') | ||
const { | ||
data: totalAllocation, | ||
isLoading: isTotalAllocationLoading, | ||
error: totalAllocationError, | ||
} = useGetTotalAllocation(gauges ?? []) | ||
// FIXME: verify if we need to use the cyclePayout in wei or in RIF and if we need to use bigint or Number | ||
const rewardsPerStRIFPerCycle = Number( | ||
((cyclePayout ?? 1n) * weightedAverageBuilderRewardsPct) / totalAllocation, | ||
) | ||
const { prices } = usePricesContext() | ||
const rifPrice = prices.RIF?.price ?? 0 | ||
const abi = rifPrice ? Math.pow(1 + rewardsPerStRIFPerCycle / rifPrice, 26) - 1 : 0 | ||
|
||
const isLoading = isCyclePayoutLoading || isTotalAllocationLoading | ||
const error = cyclePayoutError ?? totalAllocationError | ||
return { | ||
data: abi, | ||
isLoading, | ||
error, | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/app/collective-rewards/metrics/components/ABIMetrics/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ABIMetrics' |
12 changes: 12 additions & 0 deletions
12
src/app/collective-rewards/metrics/hooks/useGetTotalAllocation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useGaugesGetFunction } from '../../shared' | ||
|
||
export const useGetTotalAllocation = (gauges: any[]) => { | ||
const { data, isLoading, error } = useGaugesGetFunction(gauges, 'totalAllocation') | ||
|
||
const totalAllocations = Object.values(data).reduce((acc, allocation) => acc + allocation, 0n) | ||
return { | ||
data: totalAllocations, | ||
isLoading, | ||
error, | ||
} | ||
} |