@@ -130,6 +130,12 @@ type NodeCollector struct {
130130 // Megapool refund value
131131 megapoolRefundValue * prometheus.Desc
132132
133+ // Megapool beacon balance
134+ megapoolBeaconBalance * prometheus.Desc
135+
136+ // Megapool node share of beacon balance
137+ megapoolNodeShareofBeaconBalance * prometheus.Desc
138+
133139 // Megapool node bond
134140 megapoolNodeBond * prometheus.Desc
135141
@@ -142,8 +148,8 @@ type NodeCollector struct {
142148 // Megapool queue bond
143149 megapoolQueueBond * prometheus.Desc
144150
145- // Megapool rewards split
146- megapoolRewardsSplit * prometheus.Desc
151+ // Megapool pending rewards
152+ megapoolPendingRewards * prometheus.Desc
147153
148154 // Megapool active validator count
149155 megapoolActiveValidatorCount * prometheus.Desc
@@ -270,10 +276,18 @@ func NewNodeCollector(rp *rocketpool.RocketPool, bc *services.BeaconClientManage
270276 "The low ETH balance threshold" ,
271277 nil , nil ,
272278 ),
279+ megapoolBeaconBalance : prometheus .NewDesc (prometheus .BuildFQName (namespace , subsystem , "megapool_beacon_balance" ),
280+ "The Megapool beacon balance" ,
281+ nil , nil ,
282+ ),
273283 megapoolEthBalance : prometheus .NewDesc (prometheus .BuildFQName (namespace , subsystem , "megapool_eth_balance" ),
274284 "The Megapool ETH balance" ,
275285 nil , nil ,
276286 ),
287+ megapoolNodeShareofBeaconBalance : prometheus .NewDesc (prometheus .BuildFQName (namespace , subsystem , "megapool_node_share_of_beacon_balance" ),
288+ "The Megapool node share of beacon balance" ,
289+ nil , nil ,
290+ ),
277291 nodeDebt : prometheus .NewDesc (prometheus .BuildFQName (namespace , subsystem , "node_debt" ),
278292 "The Node debt" ,
279293 nil , nil ,
@@ -290,6 +304,10 @@ func NewNodeCollector(rp *rocketpool.RocketPool, bc *services.BeaconClientManage
290304 "The Megapool queue bond" ,
291305 nil , nil ,
292306 ),
307+ megapoolPendingRewards : prometheus .NewDesc (prometheus .BuildFQName (namespace , subsystem , "megapool_pending_rewards" ),
308+ "The Megapool pending rewards" ,
309+ []string {"type" }, nil ,
310+ ),
293311 megapoolRefundValue : prometheus .NewDesc (prometheus .BuildFQName (namespace , subsystem , "megapool_refund_value" ),
294312 "The Megapool refund value" ,
295313 nil , nil ,
@@ -371,6 +389,7 @@ func (collector *NodeCollector) Describe(channel chan<- *prometheus.Desc) {
371389 channel <- collector .megapoolValidatorCount
372390 channel <- collector .megapoolNodeExpressTicketCount
373391 channel <- collector .megapoolRefundValue
392+ channel <- collector .megapoolPendingRewards
374393 channel <- collector .megapoolNodeBond
375394 channel <- collector .megapoolUserCapital
376395 channel <- collector .megapoolAssignedValue
@@ -380,6 +399,8 @@ func (collector *NodeCollector) Describe(channel chan<- *prometheus.Desc) {
380399 channel <- collector .megapoolStandardQueueSize
381400 channel <- collector .megapoolExpressQueueSize
382401 channel <- collector .megapoolQueueBond
402+ channel <- collector .megapoolBeaconBalance
403+ channel <- collector .megapoolNodeShareofBeaconBalance
383404}
384405
385406// Collect the latest metric values and pass them to Prometheus
@@ -435,7 +456,12 @@ func (collector *NodeCollector) Collect(channel chan<- prometheus.Metric) {
435456 megapoolBeaconBalanceTotal := big .NewInt (0 )
436457 megapoolStandardQueueSize := float64 (0 )
437458 megapoolExpressQueueSize := float64 (0 )
438-
459+ megapoolPendingRewardsNode := float64 (0 )
460+ megapoolPendingRewardsVoter := float64 (0 )
461+ megapoolPendingRewardsPDAO := float64 (0 )
462+ megapoolPendingRewardsReth := float64 (0 )
463+ megapoolBeaconBalance := float64 (0 )
464+ nodeShareofBeaconBalance := float64 (0 )
439465 // Get the cumulative claimed and unclaimed RPL rewards
440466 wg .Go (func () error {
441467 //legacyClaimNodeAddress := collector.cfg.Smartnode.GetLegacyClaimNodeAddress()
@@ -590,11 +616,26 @@ func (collector *NodeCollector) Collect(channel chan<- prometheus.Metric) {
590616 return nil
591617 }
592618
593- // // Load the megapool contract
594- // mp, err := megapool.NewMegaPoolV1(collector.rp, collector.nodeAddress, nil)
595- // if err != nil {
596- // return fmt.Errorf("Error loading megapool contract: %w", err)
597- // }
619+ // Calculate the expected megapool address
620+ megapoolAddress , err := megapool .GetMegapoolExpectedAddress (collector .rp , collector .nodeAddress , nil )
621+ if err != nil {
622+ return fmt .Errorf ("Error getting megapool expected address: %w" , err )
623+ }
624+
625+ // Load the megapool contract
626+ mp , err := megapool .NewMegaPoolV1 (collector .rp , megapoolAddress , nil )
627+ if err != nil {
628+ return fmt .Errorf ("Error loading megapool contract: %w" , err )
629+ }
630+
631+ mpPendingRewards , err := mp .CalculatePendingRewards (nil )
632+ if err != nil {
633+ return fmt .Errorf ("Error getting megapool pending rewards: %w" , err )
634+ }
635+ megapoolPendingRewardsNode = eth .WeiToEth (mpPendingRewards .NodeRewards )
636+ megapoolPendingRewardsVoter = eth .WeiToEth (mpPendingRewards .VoterRewards )
637+ megapoolPendingRewardsPDAO = eth .WeiToEth (mpPendingRewards .ProtocolDAORewards )
638+ megapoolPendingRewardsReth = eth .WeiToEth (mpPendingRewards .RethRewards )
598639
599640 // Iterate over the megapool pubkeys
600641 for _ , pubkey := range megapoolPubkeys {
@@ -607,6 +648,16 @@ func (collector *NodeCollector) Collect(channel chan<- prometheus.Metric) {
607648 }
608649 }
609650
651+ megapoolBeaconBalance = eth .WeiToEth (megapoolBeaconBalanceTotal )
652+ // rewards = beacon balance total - node bond - user capital
653+ rewardsBeaconBalance := big .NewInt (0 ).Sub (megapoolBeaconBalanceTotal , megapoolDetails .NodeBond )
654+ rewardsBeaconBalance = big .NewInt (0 ).Sub (rewardsBeaconBalance , megapoolDetails .UserCapital )
655+ rewardsSplit , err := mp .CalculateRewards (rewardsBeaconBalance , nil )
656+ if err != nil {
657+ return fmt .Errorf ("Error calculating megapool rewards: %w" , err )
658+ }
659+ nodeShareofBeaconBalance = eth .WeiToEth (rewardsSplit .NodeRewards .Add (rewardsSplit .NodeRewards , megapoolDetails .NodeBond ))
660+
610661 // Get the queue details
611662 megapoolExpressQueueSizeInt , err := deposit .GetExpressQueueLength (collector .rp , nil )
612663 if err != nil {
@@ -866,6 +917,10 @@ func (collector *NodeCollector) Collect(channel chan<- prometheus.Metric) {
866917 collector .megapoolAssignedValue , prometheus .GaugeValue , megapoolAssignedValue )
867918 channel <- prometheus .MustNewConstMetric (
868919 collector .megapoolActiveValidatorCount , prometheus .GaugeValue , megapoolActiveValidatorCount )
920+ channel <- prometheus .MustNewConstMetric (
921+ collector .megapoolBeaconBalance , prometheus .GaugeValue , megapoolBeaconBalance )
922+ channel <- prometheus .MustNewConstMetric (
923+ collector .megapoolNodeShareofBeaconBalance , prometheus .GaugeValue , nodeShareofBeaconBalance )
869924 channel <- prometheus .MustNewConstMetric (
870925 collector .megapoolLockedValidatorCount , prometheus .GaugeValue , megapoolLockedValidatorCount )
871926 channel <- prometheus .MustNewConstMetric (
@@ -876,6 +931,15 @@ func (collector *NodeCollector) Collect(channel chan<- prometheus.Metric) {
876931 collector .megapoolExpressQueueSize , prometheus .GaugeValue , megapoolExpressQueueSize )
877932 channel <- prometheus .MustNewConstMetric (
878933 collector .megapoolQueueBond , prometheus .GaugeValue , megapoolQueueBond )
934+ channel <- prometheus .MustNewConstMetric (
935+ collector .megapoolPendingRewards , prometheus .GaugeValue , megapoolPendingRewardsNode , "node" )
936+ channel <- prometheus .MustNewConstMetric (
937+ collector .megapoolPendingRewards , prometheus .GaugeValue , megapoolPendingRewardsVoter , "voter" )
938+ channel <- prometheus .MustNewConstMetric (
939+ collector .megapoolPendingRewards , prometheus .GaugeValue , megapoolPendingRewardsReth , "reth" )
940+ channel <- prometheus .MustNewConstMetric (
941+ collector .megapoolPendingRewards , prometheus .GaugeValue , megapoolPendingRewardsPDAO , "pdao" )
942+
879943}
880944
881945// Log error messages
0 commit comments