@@ -156,7 +156,14 @@ func (d *DataAccessService) getTotalRewardsColumns() string {
156156 return rewardColumns
157157}
158158
159- func (d * DataAccessService ) getElClAPR (ctx context.Context , dashboardId t.VDBId , groupId int64 , hours int ) (elIncome decimal.Decimal , elAPR float64 , clIncome decimal.Decimal , clAPR float64 , err error ) {
159+ type IncomeInfo struct {
160+ Rewards t.ClElValue [decimal.Decimal ]
161+
162+ Apr t.ClElValue [float64 ]
163+ }
164+
165+ func (d * DataAccessService ) getElClAPR (ctx context.Context , dashboardId t.VDBId , groupId int64 , hours int ) (rewardsApr IncomeInfo , err error ) {
166+ result := IncomeInfo {}
160167 table := ""
161168
162169 switch hours {
@@ -171,7 +178,7 @@ func (d *DataAccessService) getElClAPR(ctx context.Context, dashboardId t.VDBId,
171178 case - 1 :
172179 table = "validator_dashboard_data_rolling_90d"
173180 default :
174- return decimal . Zero , 0 , decimal . Zero , 0 , fmt .Errorf ("invalid hours value: %v" , hours )
181+ return IncomeInfo {} , fmt .Errorf ("invalid hours value: %v" , hours )
175182 }
176183
177184 type RewardsResult struct {
@@ -209,16 +216,16 @@ func (d *DataAccessService) getElClAPR(ctx context.Context, dashboardId t.VDBId,
209216
210217 query , args , err := rewardsDs .Prepared (true ).ToSQL ()
211218 if err != nil {
212- return decimal . Zero , 0 , decimal . Zero , 0 , fmt .Errorf ("error preparing query: %w" , err )
219+ return IncomeInfo {} , fmt .Errorf ("error preparing query: %w" , err )
213220 }
214221
215222 err = d .clickhouseReader .GetContext (ctx , & rewardsResultTable , query , args ... )
216223 if err != nil || ! rewardsResultTable .Reward .Valid {
217- return decimal . Zero , 0 , decimal . Zero , 0 , err
224+ return IncomeInfo {} , err
218225 }
219226
220227 if rewardsResultTable .ValidatorCount == 0 {
221- return decimal . Zero , 0 , decimal . Zero , 0 , nil
228+ return IncomeInfo {} , nil
222229 }
223230
224231 aprDivisor := hours
@@ -228,31 +235,31 @@ func (d *DataAccessService) getElClAPR(ctx context.Context, dashboardId t.VDBId,
228235
229236 investedAmountUInt , err := d .GetValidatorDashboardEffectiveBalanceTotal (ctx , dashboardId , true )
230237 if err != nil {
231- return decimal . Zero , 0 , decimal . Zero , 0 , fmt .Errorf ("error retrieving total effective balance: %w" , err )
238+ return IncomeInfo {} , fmt .Errorf ("error retrieving total effective balance: %w" , err )
232239 }
233240 // invested amount is wrong if the effective balance changed during the period (because of auto compound, consolidation, partial withdrawal etc.)
234241 // would need to split at eb changes and weigh results
235242 investedAmount := d .convertClToMain (decimal .NewFromUint64 (investedAmountUInt ))
236243
237- clAPR = calcAPR (d .convertClToMain (decimal .NewFromInt (rewardsResultTable .Reward .Int64 )), investedAmount , aprDivisor )
244+ result . Apr . Cl = calcAPR (d .convertClToMain (decimal .NewFromInt (rewardsResultTable .Reward .Int64 )), investedAmount , aprDivisor )
238245
239- clIncome = decimal .NewFromInt (rewardsResultTable .Reward .Int64 ).Mul (decimal .NewFromInt (1e9 ))
246+ result . Rewards . Cl = decimal .NewFromInt (rewardsResultTable .Reward .Int64 ).Mul (decimal .NewFromInt (1e9 ))
240247
241248 if hours == - 1 {
242249 rewardsDs = rewardsDs .
243250 From (goqu .L ("validator_dashboard_data_rolling_total AS r FINAL" ))
244251
245252 query , args , err = rewardsDs .Prepared (true ).ToSQL ()
246253 if err != nil {
247- return decimal . Zero , 0 , decimal . Zero , 0 , fmt .Errorf ("error preparing query: %w" , err )
254+ return IncomeInfo {} , fmt .Errorf ("error preparing query: %w" , err )
248255 }
249256
250257 err = d .clickhouseReader .GetContext (ctx , & rewardsResultTotal , query , args ... )
251258 if err != nil || ! rewardsResultTotal .Reward .Valid {
252- return decimal . Zero , 0 , decimal . Zero , 0 , err
259+ return IncomeInfo {} , err
253260 }
254261
255- clIncome = decimal .NewFromInt (rewardsResultTotal .Reward .Int64 ).Mul (decimal .NewFromInt (1e9 ))
262+ result . Rewards . Cl = decimal .NewFromInt (rewardsResultTotal .Reward .Int64 ).Mul (decimal .NewFromInt (1e9 ))
256263 }
257264
258265 elDs := goqu .Dialect ("postgres" ).
@@ -278,32 +285,32 @@ func (d *DataAccessService) getElClAPR(ctx context.Context, dashboardId t.VDBId,
278285
279286 query , args , err = elTableDs .Prepared (true ).ToSQL ()
280287 if err != nil {
281- return decimal . Zero , 0 , decimal . Zero , 0 , fmt .Errorf ("error preparing query: %w" , err )
288+ return IncomeInfo {} , fmt .Errorf ("error preparing query: %w" , err )
282289 }
283290
284- err = d .alloyReader .GetContext (ctx , & elIncome , query , args ... )
291+ err = d .alloyReader .GetContext (ctx , & result . Rewards . El , query , args ... )
285292 if err != nil {
286- return decimal . Zero , 0 , decimal . Zero , 0 , err
293+ return IncomeInfo {} , err
287294 }
288295
289- elAPR = calcAPR (d .convertElToMain (elIncome ), investedAmount , aprDivisor )
296+ result . Apr . El = calcAPR (d .convertElToMain (result . Rewards . El ), investedAmount , aprDivisor )
290297
291298 if hours == - 1 {
292299 elTotalDs := elDs .
293300 Where (goqu .L ("b.epoch >= ? AND b.epoch <= ?" , rewardsResultTotal .EpochStart , rewardsResultTotal .EpochEnd ))
294301
295302 query , args , err = elTotalDs .Prepared (true ).ToSQL ()
296303 if err != nil {
297- return decimal . Zero , 0 , decimal . Zero , 0 , fmt .Errorf ("error preparing query: %w" , err )
304+ return IncomeInfo {} , fmt .Errorf ("error preparing query: %w" , err )
298305 }
299306
300- err = d .alloyReader .GetContext (ctx , & elIncome , query , args ... )
307+ err = d .alloyReader .GetContext (ctx , & result . Rewards . El , query , args ... )
301308 if err != nil {
302- return decimal . Zero , 0 , decimal . Zero , 0 , err
309+ return IncomeInfo {} , err
303310 }
304311 }
305312
306- return elIncome , elAPR , clIncome , clAPR , nil
313+ return result , nil
307314}
308315
309316// precondition: invested amount and rewards are in the same currency
0 commit comments