Skip to content

Commit

Permalink
Various number fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
batphonghan committed Jan 16, 2024
1 parent 4eeecf5 commit 04e3834
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions shared/services/state/network-state.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type MetricDetails struct {
LockedEth float64

// done
HealthFactor *big.Int
HealthFactor float64
}

type MetricsCache struct {
Expand Down Expand Up @@ -575,7 +575,7 @@ func CreateMetricsCache(
metricsDetails.SdCollateralPct = collateralPct

metricsDetails.LockedEth = math.RoundDown(eth.WeiToEth(userData.LockedEth), SixDecimalRound)
metricsDetails.HealthFactor = userData.HealthFactor
metricsDetails.HealthFactor = math.RoundDown(eth.WeiToEth(userData.HealthFactor), SixDecimalRound)

metricsDetails.OperatorSDUtilizationPosition = math.RoundDown(eth.WeiToEth(totalPosition), SixDecimalRound)

Expand Down
6 changes: 3 additions & 3 deletions stader-cli/node/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func getNodeStatus(c *cli.Context) error {
}
collateralPct := 0.0
sdStatus := sdStatusResp.SDStatus
totalCollateral := new(big.Int).Add(sdStatus.SdCollateralCurrentAmount, sdStatus.SdUtilizerLatestBalance)
totalCollateral := new(big.Int).Add(sdStatus.SdCollateralCurrentAmount, sdStatus.SdUtilizedBalance)

current := eth.WeiToEth(totalCollateral)
require := eth.WeiToEth(sdStatus.SdCollateralRequireAmount)
Expand Down Expand Up @@ -209,8 +209,8 @@ func getNodeStatus(c *cli.Context) error {

if sdStatus.SdUtilizedBalance.Cmp(big.NewInt(0)) != 0 {
fmt.Printf(
"The Operator has a Health Factor of %s. \nNote: Please ensure your Health Factor is greater than 1 to avoid liquidations.\n\n",
sdStatus.HealthFactor.String())
"The Operator has a Health Factor of %.6f. \nNote: Please ensure your Health Factor is greater than 1 to avoid liquidations.\n\n",
eth.WeiToEth(sdStatus.HealthFactor))
}

fmt.Printf(
Expand Down
7 changes: 3 additions & 4 deletions stader-cli/node/utilize-sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func GetMinUtility(sdStatus *api.SdStatusResponse) *big.Int {
}

func GetMaxUtility(sdStatus *api.SdStatusResponse) *big.Int {
maxUtility := new(big.Int).Sub(sdStatus.SdMaxUtilizableAmount, sdStatus.SdUtilizerLatestBalance)
maxUtility := new(big.Int).Sub(sdStatus.SdMaxUtilizableAmount, sdStatus.SdUtilizedBalance)

if maxUtility.Cmp(sdStatus.PoolAvailableSDBalance) > 0 {
maxUtility = sdStatus.PoolAvailableSDBalance
Expand All @@ -117,8 +117,7 @@ func PromptChooseUtilityAmount(sdStatus *api.SdStatusResponse) (*big.Int, error)

// 2. If user had enough Eth
if minUtility.Cmp(maxUtility) >= 0 {
msg := fmt.Sprintf("Do not had enough ETH bond to utility\n")
return nil, errors.New(msg)
return nil, errors.New("Do not had enough ETH bond to utility")
}

// Set maxSd to pool available
Expand Down Expand Up @@ -147,7 +146,7 @@ Maximum utilization amount: %s

func PromptChooseSelfBondAmount(sdStatus *api.SdStatusResponse) (*big.Int, error) {

totalCollateral := new(big.Int).Add(sdStatus.SdCollateralCurrentAmount, sdStatus.SdUtilizerLatestBalance)
totalCollateral := new(big.Int).Add(sdStatus.SdCollateralCurrentAmount, sdStatus.SdUtilizedBalance)

amountToCollateralRemain := new(big.Int).Sub(sdStatus.SdCollateralRequireAmount, totalCollateral)

Expand Down
2 changes: 1 addition & 1 deletion stader/guardian/collector/operator-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (collector *OperatorCollector) Collect(channel chan<- prometheus.Metric) {
channel <- prometheus.MustNewConstMetric(collector.TotalSDUtilizedInterest, prometheus.GaugeValue, state.StaderNetworkDetails.OperatorSDInterest)
channel <- prometheus.MustNewConstMetric(collector.SdCollateralPct, prometheus.GaugeValue, state.StaderNetworkDetails.SdCollateralPct)
channel <- prometheus.MustNewConstMetric(collector.LockedEth, prometheus.GaugeValue, state.StaderNetworkDetails.LockedEth)
channel <- prometheus.MustNewConstMetric(collector.HealthFactor, prometheus.GaugeValue, float64(state.StaderNetworkDetails.HealthFactor.Int64()))
channel <- prometheus.MustNewConstMetric(collector.HealthFactor, prometheus.GaugeValue, state.StaderNetworkDetails.HealthFactor)
channel <- prometheus.MustNewConstMetric(collector.TotalSDUtilizationPosition, prometheus.GaugeValue, float64(state.StaderNetworkDetails.OperatorSDUtilizationPosition))

Check failure on line 205 in stader/guardian/collector/operator-collector.go

View workflow job for this annotation

GitHub Actions / build

unnecessary conversion (unconvert)
channel <- prometheus.MustNewConstMetric(collector.TotalSDSelfBond, prometheus.GaugeValue, float64(state.StaderNetworkDetails.OperatorSDSelfBond))

Check failure on line 206 in stader/guardian/collector/operator-collector.go

View workflow job for this annotation

GitHub Actions / build

unnecessary conversion (unconvert)
}
Expand Down
2 changes: 1 addition & 1 deletion stader/guardian/collector/state-locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewMetricsCacheContainer() *MetricsCacheContainer {
OperatorSDSelfBond: 0,
SdCollateralPct: 0,
LockedEth: 0,
HealthFactor: big.NewInt(0),
HealthFactor: 0,
StaderQueuedValidators: big.NewInt(0),
},
},
Expand Down

0 comments on commit 04e3834

Please sign in to comment.