Skip to content

rewards-from-state-sync - #2158

Open
franciscotobar wants to merge 8 commits into
mainfrom
rewards-from-state-sync
Open

rewards-from-state-sync#2158
franciscotobar wants to merge 8 commits into
mainfrom
rewards-from-state-sync

Conversation

@franciscotobar

@franciscotobar franciscotobar commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

We switched getting the events from blockscout to use a time based information from the state sync.

  • Collective Rewards -> total rewards distributed
  • My Rewards -> backer rewards -> total earned
  • My Rewards -> builder rewards -> all time share
  • Builders -> last cycle rewards -> pending

It covers the TOK-1152

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates rewards aggregation to primarily use StateSync/DB-derived totals (when healthy) and fall back to onchain event-derived totals when needed, improving consistency and reducing reliance on event log parsing in the UI.

Changes:

  • Added hooks to compute “Total Rewards Distributed” from /api/cycles (StateSync healthy) with a fallback to notify-reward events.
  • Added a new /api/backers/[backer]/rewards-claimed endpoint and a hook to source backer “claimed rewards” from DB when StateSync is healthy, falling back to Blockscout event logs otherwise.
  • Simplified claimed-reward aggregation across the app by switching from “array of claim events” to “per-gauge bigint totals”.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/app/my-rewards/backers/hooks/useBackerTotalEarned.ts Updates claimed aggregation to sum bigint totals directly.
src/app/collective-rewards/rewards/hooks/useGetTotalRewardsFromEvents.ts New: aggregates total distributed rewards from NotifyReward events.
src/app/collective-rewards/rewards/hooks/useGetTotalRewardsFromCycles.ts New: aggregates total distributed rewards from cycles API with StateSync gating.
src/app/collective-rewards/rewards/hooks/useGetGaugesEvents.ts Adds enabled support and avoids querying when gauges are empty.
src/app/collective-rewards/rewards/hooks/index.ts Exposes new total-rewards hooks via barrel export.
src/app/collective-rewards/rewards/backers/hooks/useGetRBI.ts Updates claimed aggregation to sum bigint totals directly.
src/app/collective-rewards/rewards/backers/hooks/useGetGaugesBackerRewardsClaimed.ts Adds enabled passthrough for conditional event fetching.
src/app/collective-rewards/rewards/backers/hooks/useGetBackerRewardsClaimed.ts New: StateSync-health-gated DB → (placeholder Graph) → Blockscout fallback for claimed totals.
src/app/collective-rewards/rewards/backers/hooks/useGetBackerRewards.ts Adjusts claimed value access to match new bigint totals shape.
src/app/collective-rewards/rewards/backers/hooks/index.ts Exports the new useGetBackerRewardsClaimed hook.
src/app/collective-rewards/rewards/backers/context/BackerRewardsContext.tsx Switches claimed data source to new hook and updates claimed type to bigint totals.
src/app/collective-rewards/components/TotalRewardsDistributed/TotalRewardsDistributed.tsx Refactors to use withDataFallback between cycles (primary) and events (fallback).
src/app/api/db/constants.ts Adds allowed columns list for backer rewards claimed pagination/sorting.
src/app/api/backers/[backer]/rewards-claimed/route.ts New API endpoint to serve claimed rewards rows from DB with pagination and optional token filter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/collective-rewards/rewards/backers/hooks/useGetBackerRewardsClaimed.ts Outdated
Comment thread src/app/collective-rewards/rewards/backers/hooks/useGetBackerRewardsClaimed.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Comment thread src/app/my-rewards/builder/hooks/useGetBuilderAllTimeShare.ts Outdated
Comment thread src/app/my-rewards/builder/hooks/useGetBuilderAllTimeShare.ts Outdated
Comment thread src/app/collective-rewards/rewards/backers/hooks/useGetBackerRewardsClaimed.ts Outdated
Comment thread src/app/collective-rewards/rewards/backers/hooks/useGetBackerRewardsClaimed.ts Outdated
@franciscotobar
franciscotobar requested a review from Copilot June 9, 2026 11:19
@franciscotobar franciscotobar changed the title feat: total rewards distributed and backer rewards claimed from state… rewards-from-state-sync Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Comment thread src/app/my-rewards/builder/hooks/useGetBuilderAllTimeShare.ts Outdated
Comment thread src/app/api/backers/[backer]/rewards-claimed/route.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

queryFn: fetchAllCycles,
queryKey: ['totalRewardsDistributedCycles'],
refetchInterval: AVERAGE_BLOCKTIME,
enabled: !healthCheckIsLoading && !!isStateSyncHealthy,
Comment on lines +59 to +62
queryFn: fetchAllCycles,
queryKey: ['totalRewardsDistributedCycles'],
refetchInterval: AVERAGE_BLOCKTIME,
enabled: !healthCheckIsLoading && !!isStateSyncHealthy,
Comment on lines +118 to +122
return {
data: normalizeEventData(eventData ?? {}),
isLoading: eventLoading,
error: eventError ?? healthCheckError,
}
Comment on lines +85 to +90
} = useQuery({
queryKey: ['backerRewardsClaimed', 'db', backer, token],
queryFn: () => fetchAllBackerRewardsClaimed(backer, token),
refetchInterval: AVERAGE_BLOCKTIME,
enabled: useDb,
})
Comment on lines +109 to +113
error:
healthCheckError ??
(useCycles ? cyclesError : notifyRewardError) ??
builderRewardsPerTokenError ??
claimableRewardsError,
Comment on lines +47 to +52
} = useQuery<CycleRewardsItem[], Error>({
queryFn: fetchAllCycles,
queryKey: ['totalRewardsDistributedCycles'],
refetchInterval: AVERAGE_BLOCKTIME,
enabled: useCycles,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants