-
Notifications
You must be signed in to change notification settings - Fork 105
/
percentages.go
148 lines (129 loc) · 4.47 KB
/
percentages.go
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
package pdao
import (
"fmt"
"github.com/rocket-pool/rocketpool-go/utils/eth"
"github.com/rocket-pool/smartnode/shared/services/gas"
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
"github.com/urfave/cli"
)
func getRewardsPercentages(c *cli.Context) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c).WithReady()
if err != nil {
return err
}
defer rp.Close()
// Check for Houston
houston, err := rp.IsHoustonDeployed()
if err != nil {
return fmt.Errorf("error checking if Houston has been deployed: %w", err)
}
if !houston.IsHoustonDeployed {
fmt.Println("This command cannot be used until Houston has been deployed.")
return nil
}
// Get all PDAO settings
response, err := rp.PDAOGetRewardsPercentages()
if err != nil {
return err
}
// Print the settings
fmt.Printf("Node Operators: %.2f%% (%s)\n", eth.WeiToEth(response.Node)*100, response.Node.String())
fmt.Printf("Oracle DAO: %.2f%% (%s)\n", eth.WeiToEth(response.OracleDao)*100, response.OracleDao.String())
fmt.Printf("Protocol DAO: %.2f%% (%s)\n", eth.WeiToEth(response.ProtocolDao)*100, response.ProtocolDao.String())
return nil
}
func proposeRewardsPercentages(c *cli.Context) error {
// Get RP client
rp, err := rocketpool.NewClientFromCtx(c).WithReady()
if err != nil {
return err
}
defer rp.Close()
// Check for Houston
houston, err := rp.IsHoustonDeployed()
if err != nil {
return fmt.Errorf("error checking if Houston has been deployed: %w", err)
}
if !houston.IsHoustonDeployed {
fmt.Println("This command cannot be used until Houston has been deployed.")
return nil
}
// Check for the raw flag
rawEnabled := c.Bool("raw")
// Get the node op percent
nodeString := c.String("node")
if nodeString == "" {
if rawEnabled {
nodeString = cliutils.Prompt("Please enter the new rewards allocation for node operators (as an 18-decimal-fixed-point-integer (wei) value):", "^\\d+$", "Invalid amount")
} else {
nodeString = cliutils.Prompt("Please enter the new rewards allocation for node operators as a percentage from 0 to 1:", "^\\d+(\\.\\d+)?$", "Invalid amount")
}
}
nodePercent, err := parseFloat(c, "node-percent", nodeString, true)
if err != nil {
return err
}
// Get the oDAO percent
odaoString := c.String("odao")
if odaoString == "" {
if rawEnabled {
odaoString = cliutils.Prompt("Please enter the new rewards allocation for the Oracle DAO (as an 18-decimal-fixed-point-integer (wei) value):", "^\\d+$", "Invalid amount")
} else {
odaoString = cliutils.Prompt("Please enter the new rewards allocation for the Oracle DAO as a percentage from 0 to 1:", "^\\d+(\\.\\d+)?$", "Invalid amount")
}
}
odaoPercent, err := parseFloat(c, "odao-percent", odaoString, true)
if err != nil {
return err
}
// Get the pDAO percent
pdaoString := c.String("pdao")
if pdaoString == "" {
if rawEnabled {
pdaoString = cliutils.Prompt("Please enter the new rewards allocation for the Protocol DAO treasury (as an 18-decimal-fixed-point-integer (wei) value):", "^\\d+$", "Invalid amount")
} else {
pdaoString = cliutils.Prompt("Please enter the new rewards allocation for the Protocol DAO treasury as a percentage from 0 to 1:", "^\\d+(\\.\\d+)?$", "Invalid amount")
}
}
pdaoPercent, err := parseFloat(c, "pdao-percent", pdaoString, true)
if err != nil {
return err
}
// Check submissions
canResponse, err := rp.PDAOCanProposeRewardsPercentages(nodePercent, odaoPercent, pdaoPercent)
if err != nil {
return err
}
if !canResponse.CanPropose {
fmt.Println("Cannot propose rewards precentages:")
if canResponse.IsRplLockingDisallowed {
fmt.Println("Please enable RPL locking using the command 'rocketpool node allow-rpl-locking' to raise proposals.")
}
return nil
}
// Assign max fee
err = gas.AssignMaxFeeAndLimit(canResponse.GasInfo, rp, c.Bool("yes"))
if err != nil {
return err
}
// Prompt for confirmation
if !(c.Bool("yes") || cliutils.Confirm("Are you sure you want to propose new rewards allocations?")) {
fmt.Println("Cancelled.")
return nil
}
// Submit
response, err := rp.PDAOProposeRewardsPercentages(nodePercent, odaoPercent, pdaoPercent, canResponse.BlockNumber)
if err != nil {
return err
}
fmt.Printf("Proposing new allocations...\n")
cliutils.PrintTransactionHash(rp, response.TxHash)
if _, err = rp.WaitForTransaction(response.TxHash); err != nil {
return err
}
// Log & return
fmt.Println("Proposal successfully created.")
return nil
}