Skip to content

Commit 8596481

Browse files
authored
Add logging for /v2/apr and handle Inf values (#432)
1 parent 301f449 commit 8596481

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/v2/service/stats.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ func (s *V2Service) GetStakingAPR(ctx context.Context, satoshisStaked, ubbnStake
160160
}
161161

162162
func (s *V2Service) calculateCoStakingAPR(ctx context.Context, babyPrice, btcPrice float64, totalScore int64) (float64, error) {
163+
if totalScore == 0 {
164+
log.Ctx(ctx).Info().Msg("empty total score")
165+
return 0, nil
166+
}
167+
163168
const (
164169
totalInflation = 5.5
165170
coStakingInflationPart = 2.35
@@ -170,6 +175,13 @@ func (s *V2Service) calculateCoStakingAPR(ctx context.Context, babyPrice, btcPri
170175
return 0, err
171176
}
172177

178+
log.Ctx(ctx).Info().
179+
Float64("annualProvisions", annualProvisions).
180+
Float64("babyPrice", babyPrice).
181+
Float64("btcPrice", btcPrice).
182+
Int64("totalScore", totalScore).
183+
Msg("values for costaking apr calculation")
184+
173185
// annualProvisions * (coStakingInflationPart / totalInflation) * babyPrice / (total_score / satoshisPerBTC * btcPrice) / ubbnPerBaby
174186
// if you need percentage multiply final value by 100 (done on frontend)
175187
apr := annualProvisions * (coStakingInflationPart / totalInflation) * babyPrice / ((float64(totalScore) / pkg.SatoshiPerBTC) * btcPrice) / pkg.UbbnPerBaby

0 commit comments

Comments
 (0)