Repository navigation
Expand file tree
/
Copy pathstatus.go
More file actions
225 lines (190 loc) · 7.48 KB
/
Copy pathstatus.go
File metadata and controls
225 lines (190 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package minipool
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/rocket-pool/rocketpool-go/types"
"github.com/rocket-pool/rocketpool-go/utils/eth"
"github.com/urfave/cli"
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
"github.com/rocket-pool/smartnode/shared/types/api"
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
"github.com/rocket-pool/smartnode/shared/utils/hex"
"github.com/rocket-pool/smartnode/shared/utils/math"
)
const colorReset string = "\033[0m"
const colorRed string = "\033[31m"
const colorYellow string = "\033[33m"
func getStatus(c *cli.Context) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c)
if err != nil {
return err
}
defer rp.Close()
// Check and assign the EC status
err = cliutils.CheckClientStatus(rp)
if err != nil {
return err
}
// Get minipool statuses
status, err := rp.MinipoolStatus()
if err != nil {
return err
}
// Get minipools by status
statusMinipools := map[string][]api.MinipoolDetails{}
refundableMinipools := []api.MinipoolDetails{}
withdrawableMinipools := []api.MinipoolDetails{}
closeableMinipools := []api.MinipoolDetails{}
finalisedMinipools := []api.MinipoolDetails{}
for _, minipool := range status.Minipools {
if !minipool.Finalised {
// Add to status list
statusName := minipool.Status.Status.String()
if _, ok := statusMinipools[statusName]; !ok {
statusMinipools[statusName] = []api.MinipoolDetails{}
}
statusMinipools[statusName] = append(statusMinipools[statusName], minipool)
// Add to actionable lists
if minipool.RefundAvailable {
refundableMinipools = append(refundableMinipools, minipool)
}
if minipool.WithdrawalAvailable {
withdrawableMinipools = append(withdrawableMinipools, minipool)
}
if minipool.CloseAvailable {
closeableMinipools = append(closeableMinipools, minipool)
}
} else {
finalisedMinipools = append(finalisedMinipools, minipool)
}
}
// Return if there aren't any minipools
if len(status.Minipools) == 0 {
fmt.Println("The node does not have any minipools yet.")
return nil
}
// Return if all minipools are finalized and they are hidden
if len(status.Minipools) == len(finalisedMinipools) && !c.Bool("include-finalized") {
fmt.Println("All of this node's minipools have been finalized.\nTo show finalized minipools, re-run this command with the `-f` flag.")
return nil
}
// Print minipool details by status
for _, statusName := range types.MinipoolStatuses {
minipools, ok := statusMinipools[statusName]
if !ok {
continue
}
fmt.Printf("%d %s minipool(s):\n", len(minipools), statusName)
if statusName == "Withdrawable" {
fmt.Println("(Withdrawal may not be available until after withdrawal delay)")
}
fmt.Println("")
// Minipools
for _, minipool := range minipools {
if !minipool.Finalised || c.Bool("include-finalized") {
printMinipoolDetails(minipool, status.LatestDelegate)
}
}
fmt.Println("")
}
// Handle finalized minipools
if c.Bool("include-finalized") {
fmt.Printf("%d finalized minipool(s):\n", len(finalisedMinipools))
fmt.Println("")
// Minipools
for _, minipool := range finalisedMinipools {
printMinipoolDetails(minipool, status.LatestDelegate)
}
} else {
fmt.Printf("%d finalized minipool(s) (hidden)\n", len(finalisedMinipools))
fmt.Println("")
}
fmt.Println("")
// Print actionable minipool details
if len(refundableMinipools) > 0 {
fmt.Printf("%d minipool(s) have refunds available:\n", len(refundableMinipools))
for _, minipool := range refundableMinipools {
fmt.Printf("- %s (%.6f ETH to claim)\n", minipool.Address.Hex(), math.RoundDown(eth.WeiToEth(minipool.Node.RefundBalance), 6))
}
fmt.Println("")
}
if len(closeableMinipools) > 0 {
fmt.Printf("%d dissolved minipool(s) can be closed once Beacon Chain withdrawals are enabled:\n", len(closeableMinipools))
for _, minipool := range closeableMinipools {
fmt.Printf("- %s (%.6f ETH to claim)\n", minipool.Address.Hex(), math.RoundDown(eth.WeiToEth(minipool.Balances.ETH), 6))
}
fmt.Println("")
}
// Return
return nil
}
func printMinipoolDetails(minipool api.MinipoolDetails, latestDelegate common.Address) {
fmt.Printf("--------------------\n")
fmt.Printf("\n")
// Main details
fmt.Printf("Address: %s\n", minipool.Address.Hex())
if minipool.Penalties == 0 {
fmt.Println("Penalties: 0")
} else if minipool.Penalties < 3 {
fmt.Printf("%sStrikes: %d%s\n", colorYellow, minipool.Penalties, colorReset)
} else {
fmt.Printf("%sInfractions: %d%s\n", colorRed, minipool.Penalties, colorReset)
}
fmt.Printf("Status updated: %s\n", minipool.Status.StatusTime.Format(TimeFormat))
fmt.Printf("Node fee: %f%%\n", minipool.Node.Fee*100)
fmt.Printf("Node deposit: %.6f ETH\n", math.RoundDown(eth.WeiToEth(minipool.Node.DepositBalance), 6))
// Queue position
if minipool.Queue.Position != 0 {
fmt.Printf("Queue position: %d\n", minipool.Queue.Position)
}
// RP ETH deposit details - prelaunch & staking minipools
if minipool.Status.Status == types.Prelaunch || minipool.Status.Status == types.Staking {
totalRewards := big.NewInt(0).Add(&minipool.NodeShareOfETHBalance, minipool.Node.RefundBalance)
if minipool.User.DepositAssigned {
fmt.Printf("RP ETH assigned: %s\n", minipool.User.DepositAssignedTime.Format(TimeFormat))
fmt.Printf("RP deposit: %.6f ETH\n", math.RoundDown(eth.WeiToEth(minipool.User.DepositBalance), 6))
} else {
fmt.Printf("RP ETH assigned: no\n")
}
fmt.Printf("Minipool Balance (EL): %.6f ETH\n", math.RoundDown(eth.WeiToEth(minipool.Balances.ETH), 6))
fmt.Printf("Your portion: %.6f ETH\n", math.RoundDown(eth.WeiToEth(&minipool.NodeShareOfETHBalance), 6))
fmt.Printf("Available refund: %.6f ETH\n", math.RoundDown(eth.WeiToEth(minipool.Node.RefundBalance), 6))
fmt.Printf("Total EL rewards: %.6f ETH\n", math.RoundDown(eth.WeiToEth(totalRewards), 6))
}
// Validator details - prelaunch and staking minipools
if minipool.Status.Status == types.Prelaunch ||
minipool.Status.Status == types.Staking {
fmt.Printf("Validator pubkey: %s\n", hex.AddPrefix(minipool.ValidatorPubkey.Hex()))
fmt.Printf("Validator index: %d\n", minipool.Validator.Index)
if minipool.Validator.Exists {
if minipool.Validator.Active {
fmt.Printf("Validator active: yes\n")
} else {
fmt.Printf("Validator active: no\n")
}
fmt.Printf("Beacon balance (CL): %.6f ETH\n", math.RoundDown(eth.WeiToEth(&minipool.Validator.Balance), 6))
fmt.Printf("Your portion: %.6f ETH\n", math.RoundDown(eth.WeiToEth(&minipool.Validator.NodeBalance), 6))
} else {
fmt.Printf("Validator seen: no\n")
}
}
// Withdrawal details - withdrawable minipools
if minipool.Status.Status == types.Withdrawable {
fmt.Printf("Withdrawal available: yes\n")
}
// Delegate details
if minipool.UseLatestDelegate {
fmt.Printf("Use latest delegate: yes\n")
} else {
fmt.Printf("Use latest delegate: no\n")
}
fmt.Printf("Delegate address: %s\n", cliutils.GetPrettyAddress(minipool.Delegate))
fmt.Printf("Rollback delegate: %s\n", cliutils.GetPrettyAddress(minipool.PreviousDelegate))
fmt.Printf("Effective delegate: %s\n", cliutils.GetPrettyAddress(minipool.EffectiveDelegate))
if minipool.EffectiveDelegate != latestDelegate {
fmt.Printf("%s*Minipool can be upgraded to delegate %s!%s\n", colorYellow, latestDelegate.Hex(), colorReset)
}
fmt.Printf("\n")
}