Skip to content

Commit 46913a9

Browse files
authored
fix: expose stakes as Near instead of yoctoNear (#6)
1 parent 8005224 commit 46913a9

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

pkg/watcher/watcher.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ import (
1414
"github.com/fatih/color"
1515
"github.com/kilnfi/near-validator-watcher/pkg/metrics"
1616
"github.com/kilnfi/near-validator-watcher/pkg/near"
17+
"github.com/shopspring/decimal"
1718
"github.com/sirupsen/logrus"
1819
)
1920

21+
var yoctoUnit = decimal.NewFromInt(10).Pow(decimal.NewFromInt(24))
22+
2023
type Watcher struct {
2124
config *Config
2225
client *near.Client
@@ -158,7 +161,7 @@ func (w *Watcher) collectValidators(ctx context.Context) (near.ValidatorsRespons
158161
w.metrics.ValidatorProducedChunks.WithLabelValues(labels...).Set(float64(v.NumProducedChunks))
159162

160163
w.metrics.ValidatorSlashed.WithLabelValues(labels...).Set(metrics.BoolToFloat64(v.IsSlashed))
161-
w.metrics.ValidatorStake.WithLabelValues(labels...).Set(v.Stake.InexactFloat64())
164+
w.metrics.ValidatorStake.WithLabelValues(labels...).Set(v.Stake.Div(yoctoUnit).InexactFloat64())
162165

163166
t := v.Stake.InexactFloat64()
164167
if seatPrice == 0 {
@@ -174,13 +177,13 @@ func (w *Watcher) collectValidators(ctx context.Context) (near.ValidatorsRespons
174177
for _, v := range validators.NextValidators {
175178
w.metrics.NextValidatorStake.
176179
WithLabelValues(v.AccountId, v.PublicKey, labelEpochStartHeight, w.isTracked(v.AccountId)).
177-
Set(v.Stake.InexactFloat64())
180+
Set(v.Stake.Div(yoctoUnit).InexactFloat64())
178181
}
179182

180183
for _, v := range validators.CurrentProposals {
181184
w.metrics.CurrentProposals.
182185
WithLabelValues(v.AccountId, v.PublicKey, labelEpochStartHeight, w.isTracked(v.AccountId)).
183-
Set(v.Stake.InexactFloat64())
186+
Set(v.Stake.Div(yoctoUnit).InexactFloat64())
184187
}
185188

186189
for _, v := range validators.PrevEpochKickOut {

pkg/watcher/watcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ func TestWatcher(t *testing.T) {
400400

401401
// Stake
402402
assert.Equal(t, 5, testutil.CollectAndCount(metrics.ValidatorStake))
403-
assert.Equal(t, float64(47595986932991225292162473028453), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
403+
assert.Equal(t, float64(47595986.932991225292162473028453), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
404404
"node2",
405405
`ed25519:GkDv7nSMS3xcqA45cpMvFmfV1o4fRF6zYo1JRR6mNqg5`,
406406
"142256359",
407407
"0",
408408
)))
409-
assert.Equal(t, float64(6736422258840329637507414885764), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
409+
assert.Equal(t, float64(6736422.258840329637507414885764), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
410410
"kiln.pool.f863973.m0",
411411
`ed25519:Bq8fe1eUgDRexX2CYDMhMMQBiN13j8vTAVFyTNhEfh1W`,
412412
"142256359",

0 commit comments

Comments
 (0)