rewards-from-state-sync - #2158
Open
franciscotobar wants to merge 8 commits into
Open
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
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-claimedendpoint 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.
| 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, | ||
| }) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We switched getting the events from blockscout to use a time based information from the state sync.
It covers the TOK-1152