Skip to content
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
60 changes: 0 additions & 60 deletions src/app/api/metrics/abi/context/route.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/backing/BackingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const BackingPage = () => {

return (
<div data-testid={NAME} className="flex flex-col items-start w-full h-full gap-2 rounded-sm">
<PageBanner dataTestId="BackingPageBanner" dismissible title={NAME} />
<PageBanner dataTestId="BackingPageBanner" title={NAME} />
{!hasAllocations && (
<div
data-testid="CenterContainer"
Expand Down
2 changes: 1 addition & 1 deletion src/app/btc-vault/BtcVaultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const BtcVaultPage = () => {
data-testid={NAME} // TODO: DAO-2029 Standardize data-test-ids to using kebab-case only
className="flex flex-col items-start w-full h-full gap-6 rounded-sm"
>
<PageBanner dataTestId="BtcVaultBanner" dismissible title={NAME} />
<PageBanner dataTestId="BtcVaultBanner" title={NAME} />
<BtcVaultBanners />
{/* Active Request Zone - F7 (STORY-EPIC-7-001) */}
<ActiveRequestSection data={activeRequests} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,4 @@ describe('BuildersBanner', () => {
fireEvent.click(screen.getByTestId('ApplyForGrantButton'))
expect(push).toHaveBeenCalledWith('/proposals/new?type=Grants')
})

it('hides the banner when dismissed, without persisting the choice', () => {
render(<BuildersBanner />)

fireEvent.click(screen.getByTestId('DismissBannerButton'))

expect(screen.queryByTestId('BuildersBanner')).not.toBeInTheDocument()
expect(Object.keys(localStorage)).toHaveLength(0)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const BuildersBanner = ({ className }: CommonComponentProps) => {
return (
<PageBanner
dataTestId="BuildersBanner"
dismissible
title="Builders"
description="Join a growing network of innovators building the future of decentralised infrastructure."
className={className}
Expand Down
10 changes: 3 additions & 7 deletions src/app/builders/components/Table/BuildersTableTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AccentSquare } from '@/components/AccentSquare'
import { FilterIcon } from '@/components/Icons'
import { Header } from '@/components/Typography'
import { useTableContext } from '@/shared/context'
Expand Down Expand Up @@ -36,12 +35,9 @@ export const BuildersTableTitle = ({

return (
<div className="flex items-center justify-between px-4 md:px-0">
<div className="flex items-center gap-3">
<AccentSquare />
<Header variant="h3" caps className="text-nowrap">
All Builders
</Header>
</div>
<Header variant="h3" caps className="text-nowrap">
All Builders
</Header>
{isDesktop ? (
<BuilderFilterDropdown
onSelected={onFilterSelected}
Expand Down
2 changes: 1 addition & 1 deletion src/app/collective-rewards/CollectiveRewardsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const NAME = 'Collective Rewards'
/** Sections carry `sr-only` headings so the page is navigable by landmark. */
export const CollectiveRewardsPage = () => (
<div className="flex flex-col gap-2">
<PageBanner dataTestId="CollectiveRewardsBanner" dismissible title={NAME} />
<PageBanner dataTestId="CollectiveRewardsBanner" title={NAME} />

<CycleDashboardProvider>
<div className="flex flex-col gap-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const DashboardMetrics = ({ className }: { className?: string }) => {
paidAllTime={paidAllTime}
buildersCount={buildersCount}
strifPrice={strifPrice}
// `useGetABI` yields 0, not "loading", while the RIF price is still missing.
isLoading={isLoading || isAbiLoading || !prices[RIF]?.price}
isLoading={isLoading || isAbiLoading}
className={className}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const Figure = ({ label, value, sub }: { label: string; value: string; sub: stri
export interface PositionSimulatorProps {
/** `null` while it loads. */
abiPct: number | null
/** USD figures show `—` while it is 0 (price not loaded yet). */
rifPrice: number
className?: string
}
Expand Down Expand Up @@ -105,7 +106,7 @@ export const PositionSimulator = ({ abiPct, rifPrice, className }: PositionSimul
<Figure
label="Annual rewards"
value={annualRif === null ? '—' : `${formatNumberWithCommas(annualRif.round(0))} ${RIF}`}
sub={annualRif === null ? '—' : formatUsdWhole(annualRif.mul(rifPrice))}
sub={annualRif === null || !rifPrice ? '—' : formatUsdWhole(annualRif.mul(rifPrice))}
/>
<Figure
label="Per cycle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export const RewardsActionsSection = ({ className }: { className?: string }) =>
<AnnualBackerIncentivesLoader
render={({ data: abiPct, isLoading }) => (
<PositionSimulator
// `useGetABI` yields 0, not "loading", while the RIF price is still missing.
abiPct={isLoading || !prices[RIF]?.price ? null : abiPct.toNumber()}
abiPct={isLoading ? null : abiPct.toNumber()}
rifPrice={prices[RIF]?.price ?? 0}
/>
)}
Expand Down
78 changes: 0 additions & 78 deletions src/app/collective-rewards/shared/actions/fetchABIData.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/app/collective-rewards/shared/hooks/getCyclePayout.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/collective-rewards/shared/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export * from './useGetABI'
export * from './useGetABIFromChain'
export * from './useGetABIWithGraph'
export * from './useGetABIWithStateSync'
export * from './useGetBackerABI'
export * from './useGetLastCycleRewardsFromChain'
export * from './useGetLastCycleRewardsWithStateSync'
Expand Down
104 changes: 1 addition & 103 deletions src/app/collective-rewards/shared/hooks/useGetABI.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
import { useMemo } from 'react'
import { Address } from 'viem'

import { getBackerRewardPercentage } from '@/app/collective-rewards/rewards/utils/getBackerRewardPercentage'
import Big from '@/lib/big'
import { ABI_CYCLES_LIMIT, CYCLES_PER_YEAR, RBTC, RIF, USDRIF, WeiPerEther } from '@/lib/constants'
import { TOKENS } from '@/lib/tokens'
import { usePricesContext } from '@/shared/context/PricesContext'

import { BuilderStateFlags } from '../../types'
import { isBuilderRewardable } from '../../utils'
import { getCyclePayout } from './getCyclePayout'
import { CYCLES_PER_YEAR, WeiPerEther } from '@/lib/constants'

export interface CycleData {
id: string
currentCycleStart: number
rewardPerToken: Record<string, string>
}

interface BackerRewardPercentageData {
next: string
previous: string
cooldownEndTime: string
}

export interface BuilderData {
address: Address
backerRewardPct: BackerRewardPercentageData
totalAllocation: string
stateFlags: BuilderStateFlags
}

export interface AbiData {
builders: BuilderData[]
cycles: CycleData[]
}

/** Per-cycle rate compounded over `CYCLES_PER_YEAR`, as a percentage. Inverse: `getCycleRateFromAbi`. */
export const calculateAbi = (rewardsPerStRif: Big, rifPrice: number): Big => {
if (!rifPrice) {
Expand All @@ -54,77 +26,3 @@ export const getCycleRateFromAbi = (abiPct: number | null): number | null => {

return Math.pow(1 + abiPct / 100, 1 / CYCLES_PER_YEAR) - 1
}

export const useGetABI = (abiData: AbiData | undefined) => {
const { prices } = usePricesContext()

return useMemo(() => {
if (!abiData?.builders || !abiData.cycles?.length) {
return Big(0)
}

const { builders, cycles } = abiData

const rifPrice = prices[RIF]?.price ?? 0
const rbtcPrice = prices[RBTC]?.price ?? 0
const usdrifPrice = prices[USDRIF]?.price ?? 0

// Compute the average cycle payout for the last cycles (limited by ABI_CYCLES_LIMIT)
const lastCycles = cycles.slice(0, ABI_CYCLES_LIMIT)
const cyclePayout =
lastCycles.length === 0
? Big(0)
: lastCycles
.map(cycle => {
const rewardPerToken = cycle.rewardPerToken
return Big(
getCyclePayout(
rifPrice,
rbtcPrice,
usdrifPrice,
BigInt(rewardPerToken[TOKENS.rif.address.toLowerCase()] ?? 0n),
BigInt(rewardPerToken[TOKENS.rbtc.address.toLowerCase()] ?? 0n),
BigInt(rewardPerToken[TOKENS.usdrif.address.toLowerCase()] ?? 0n),
).toString(),
)
})
.reduce((acc, payout) => acc.plus(payout), Big(0))
.div(lastCycles.length)

const sumTotalAllocation = builders.reduce<Big>(
(acc, builder) => acc.plus(Big(builder?.totalAllocation ?? 0)),
Big(0),
)

if (sumTotalAllocation.eq(0)) {
return Big(0)
}

// We use the multiplication with the current backer rewards % to avoid losing precision
// Thats why we don't need to multiply by 100
const top5Builders = builders.filter(b => isBuilderRewardable(b.stateFlags)).slice(0, 5)
const top5BuildersTotalAllocation = top5Builders.reduce<Big>(
(acc, { totalAllocation }) => acc.plus(Big(totalAllocation)),
Big(0),
)
const weightedAverageBuilderRewardsPct = top5Builders.reduce<Big>(
(acc, { backerRewardPct, totalAllocation }) => {
const currentBackerRewardPercentage = backerRewardPct
? getBackerRewardPercentage(
BigInt(backerRewardPct.previous ?? 0n),
BigInt(backerRewardPct.next ?? 0n),
BigInt(backerRewardPct.cooldownEndTime ?? 0n),
).current.toString()
: 0
return acc.plus(
Big(totalAllocation).mul(Big(currentBackerRewardPercentage)).div(top5BuildersTotalAllocation),
)
},
Big(0),
)

const rewardsPerStRif = cyclePayout.mul(weightedAverageBuilderRewardsPct).div(sumTotalAllocation)

return calculateAbi(rewardsPerStRif, rifPrice)
}, [abiData, prices])
}
Loading
Loading