Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BEDS-1184) return el rewards for guest dashboards #1314

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Changes from 1 commit
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
13 changes: 6 additions & 7 deletions backend/pkg/api/data_access/vdb_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ func (d *DataAccessService) GetValidatorDashboardRewards(ctx context.Context, da
Select(
goqu.L("b.epoch"),
goqu.COALESCE(goqu.SUM(goqu.I("value")), 0).As("el_rewards")).
From(goqu.L("users_val_dashboards_validators v")).
From(goqu.I("execution_rewards_finalized").As("b")).
Where(goqu.L("b.epoch >= ?", startEpoch)).
LeftJoin(goqu.I("execution_rewards_finalized").As("b"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
GroupBy(goqu.L("b.epoch"))

if dashboardId.Validators == nil {
rewardsDs = rewardsDs.
InnerJoin(goqu.L("validators v"), goqu.On(goqu.L("e.validator_index = v.validator_index"))).
Where(goqu.L("e.validator_index IN (SELECT validator_index FROM validators)"))
elDs = elDs.
InnerJoin(goqu.I("users_val_dashboards_validators").As("v"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
Where(goqu.L("v.dashboard_id = ?", dashboardId.Id))
if currentCursor.IsValid() {
if currentCursor.IsReverse() {
Expand Down Expand Up @@ -546,10 +546,8 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
Where(goqu.L("e.epoch_timestamp = fromUnixTimestamp(?)", utils.EpochToTime(epoch).Unix()))

elDs := goqu.Dialect("postgres").
Select(
goqu.COALESCE(goqu.SUM(goqu.I("value")), 0).As("blocks_el_rewards")).
From(goqu.L("users_val_dashboards_validators v")).
LeftJoin(goqu.I("execution_rewards_finalized").As("b"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
Select(goqu.COALESCE(goqu.SUM(goqu.I("value")), 0).As("blocks_el_rewards")).
From(goqu.I("execution_rewards_finalized").As("b")).
Where(goqu.L("b.epoch = ?", epoch))

// handle the case when we have a list of validators
Expand All @@ -559,6 +557,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
InnerJoin(goqu.L("validators v"), goqu.On(goqu.L("e.validator_index = v.validator_index"))).
Where(goqu.L("e.validator_index IN (SELECT validator_index FROM validators)"))
elDs = elDs.
InnerJoin(goqu.I("users_val_dashboards_validators").As("v"), goqu.On(goqu.L("v.validator_index = b.proposer"))).
Where(goqu.L("v.dashboard_id = ?", dashboardId.Id))
if groupId != t.AllGroups {
rewardsDs = rewardsDs.Where(goqu.L("v.group_id = ?", groupId))
Expand Down Expand Up @@ -678,7 +677,7 @@ func (d *DataAccessService) GetValidatorDashboardGroupRewards(ctx context.Contex
ret.ProposalClSlashingIncReward = ret.ProposalClSlashingIncReward.Add(entry.SlasherRewards.Mul(gWei))
}

ret.Proposal.Income = ret.Proposal.Income.Add(elRewards)
ret.Proposal.Income = ret.Proposal.Income.Add(d.convertElToMain(elRewards).Mul(decimal.NewFromInt(d.config.Frontend.ElCurrencyDivisor)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue: You're converting the EL currency to the main currency and adding it to a field that contains values in the CL currency. On Gnosis, this would mean that you've converted xDai to GNO and then added it to a mGNO value. This field should be a ClElValue struct.

Copy link
Contributor Author

@remoterami remoterami Feb 7, 2025

Choose a reason for hiding this comment

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

Applied your suggestion. Could also just make use of the already existing ret.ProposalElReward, but keeping it explicit to reduce any future source of error also shouldn't hurt

Also if it's fine from the API side, would you please fix the frontend data type issue? 😅

ret.ProposalElReward = elRewards

return ret, nil
Expand Down
Loading