-
Notifications
You must be signed in to change notification settings - Fork 107
/
pdao.go
214 lines (187 loc) · 9.88 KB
/
pdao.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
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
package client
import (
"fmt"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/rocket-pool/node-manager-core/api/client"
"github.com/rocket-pool/node-manager-core/api/types"
"github.com/rocket-pool/rocketpool-go/v2/dao/protocol"
"github.com/rocket-pool/rocketpool-go/v2/rocketpool"
rptypes "github.com/rocket-pool/rocketpool-go/v2/types"
"github.com/rocket-pool/smartnode/v2/shared/types/api"
)
type PDaoRequester struct {
context *client.RequesterContext
}
func NewPDaoRequester(context *client.RequesterContext) *PDaoRequester {
return &PDaoRequester{
context: context,
}
}
func (r *PDaoRequester) GetName() string {
return "PDAO"
}
func (r *PDaoRequester) GetRoute() string {
return "pdao"
}
func (r *PDaoRequester) GetContext() *client.RequesterContext {
return r.context
}
// Claim / unlock bonds from a proposal
func (r *PDaoRequester) ClaimBonds(claims []api.ProtocolDaoClaimBonds) (*types.ApiResponse[types.DataBatch[api.ProtocolDaoClaimBondsData]], error) {
body := api.ProtocolDaoClaimBondsBody{
Claims: claims,
}
return client.SendPostRequest[types.DataBatch[api.ProtocolDaoClaimBondsData]](r, "claim-bonds", "ClaimBonds", body)
}
// Get the list of proposals with claimable / rewardable bonds, and the relevant indices for each one
func (r *PDaoRequester) GetClaimableBonds() (*types.ApiResponse[api.ProtocolDaoGetClaimableBondsData], error) {
return client.SendGetRequest[api.ProtocolDaoGetClaimableBondsData](r, "get-claimable-bonds", "GetClaimableBonds", nil)
}
// Propose a one-time spend of the Protocol DAO's treasury
func (r *PDaoRequester) OneTimeSpend(invoiceID string, recipient common.Address, amount *big.Int) (*types.ApiResponse[api.ProtocolDaoGeneralProposeData], error) {
args := map[string]string{
"invoice-id": invoiceID,
"recipient": recipient.Hex(),
"amount": amount.String(),
}
return client.SendGetRequest[api.ProtocolDaoGeneralProposeData](r, "one-time-spend", "OneTimeSpend", args)
}
// Defeat a proposal if it still has an challenge after voting has started
func (r *PDaoRequester) DefeatProposal(proposalID uint64, index uint64) (*types.ApiResponse[api.ProtocolDaoDefeatProposalData], error) {
args := map[string]string{
"id": fmt.Sprint(proposalID),
"index": fmt.Sprint(index),
}
return client.SendGetRequest[api.ProtocolDaoDefeatProposalData](r, "proposal/defeat", "DefeatProposal", args)
}
// Execute one or more proposals
func (r *PDaoRequester) ExecuteProposals(ids []uint64) (*types.ApiResponse[types.DataBatch[api.ProtocolDaoExecuteProposalData]], error) {
args := map[string]string{
"ids": client.MakeBatchArg(ids),
}
return client.SendGetRequest[types.DataBatch[api.ProtocolDaoExecuteProposalData]](r, "proposal/execute", "ExecuteProposals", args)
}
// Finalize a proposal if it's been vetoed by burning the proposer's bond
func (r *PDaoRequester) FinalizeProposal(proposalID uint64) (*types.ApiResponse[api.ProtocolDaoFinalizeProposalData], error) {
args := map[string]string{
"id": fmt.Sprint(proposalID),
}
return client.SendGetRequest[api.ProtocolDaoFinalizeProposalData](r, "proposal/finalize", "FinalizeProposal", args)
}
// Override a delegate's vote on a proposal
func (r *PDaoRequester) OverrideVoteOnProposal(proposalID uint64, voteDirection rptypes.VoteDirection) (*types.ApiResponse[api.ProtocolDaoVoteOnProposalData], error) {
args := map[string]string{
"id": fmt.Sprint(proposalID),
"vote": api.VoteDirectionNameMap[voteDirection],
}
return client.SendGetRequest[api.ProtocolDaoVoteOnProposalData](r, "proposal/override-vote", "OverrideVoteOnProposal", args)
}
// Vote on a proposal
func (r *PDaoRequester) VoteOnProposal(proposalID uint64, voteDirection rptypes.VoteDirection) (*types.ApiResponse[api.ProtocolDaoVoteOnProposalData], error) {
args := map[string]string{
"id": fmt.Sprint(proposalID),
"vote": api.VoteDirectionNameMap[voteDirection],
}
return client.SendGetRequest[api.ProtocolDaoVoteOnProposalData](r, "proposal/vote", "VoteOnProposal", args)
}
// Get the Protocol DAO proposals
func (r *PDaoRequester) Proposals() (*types.ApiResponse[api.ProtocolDaoProposalsData], error) {
return client.SendGetRequest[api.ProtocolDaoProposalsData](r, "proposals", "Proposals", nil)
}
// Propose a recurring spend of the Protocol DAO's treasury
func (r *PDaoRequester) RecurringSpend(contractName string, recipient common.Address, amountPerPeriod *big.Int, periodLength time.Duration, startTime time.Time, numberOfPeriods uint64) (*types.ApiResponse[api.ProtocolDaoGeneralProposeData], error) {
args := map[string]string{
"contract-name": contractName,
"recipient": recipient.Hex(),
"amount-per-period": amountPerPeriod.String(),
"period-length": periodLength.String(),
"start-time": startTime.Format(time.RFC3339),
"num-periods": fmt.Sprint(numberOfPeriods),
}
return client.SendGetRequest[api.ProtocolDaoGeneralProposeData](r, "recurring-spend", "RecurringSpend", args)
}
// Propose updating an existing recurring spend of the Protocol DAO's treasury
func (r *PDaoRequester) RecurringSpendUpdate(contractName string, recipient common.Address, amountPerPeriod *big.Int, periodLength time.Duration, numberOfPeriods uint64) (*types.ApiResponse[api.ProtocolDaoGeneralProposeData], error) {
args := map[string]string{
"contract-name": contractName,
"recipient": recipient.Hex(),
"amount-per-period": amountPerPeriod.String(),
"period-length": periodLength.String(),
"num-periods": fmt.Sprint(numberOfPeriods),
}
return client.SendGetRequest[api.ProtocolDaoGeneralProposeData](r, "recurring-spend-update", "RecurringSpendUpdate", args)
}
// Get the amount of minted RPL (and percentages) provided to node operators, the oDAO, and the pDAO at each rewards period
func (r *PDaoRequester) RewardsPercentages() (*types.ApiResponse[api.ProtocolDaoRewardsPercentagesData], error) {
return client.SendGetRequest[api.ProtocolDaoRewardsPercentagesData](r, "rewards-percentages", "RewardsPercentages", nil)
}
// Propose new RPL rewards percentages for node operators, the oDAO, and the pDAO at each rewards period
func (r *PDaoRequester) ProposeRewardsPercentages(node *big.Int, odao *big.Int, pdao *big.Int) (*types.ApiResponse[api.ProtocolDaoGeneralProposeData], error) {
args := map[string]string{
"node": node.String(),
"odao": odao.String(),
"pdao": pdao.String(),
}
return client.SendGetRequest[api.ProtocolDaoGeneralProposeData](r, "rewards-percentages/proposee", "ProposeRewardsPercentages", args)
}
// Propose inviting someone to the security council
func (r *PDaoRequester) InviteToSecurityCouncil(id string, address common.Address) (*types.ApiResponse[api.ProtocolDaoProposeInviteToSecurityCouncilData], error) {
args := map[string]string{
"id": id,
"address": address.Hex(),
}
return client.SendGetRequest[api.ProtocolDaoProposeInviteToSecurityCouncilData](r, "security/invite", "InviteToSecurityCouncil", args)
}
// Propose kicking someone from the security council
func (r *PDaoRequester) KickFromSecurityCouncil(address common.Address) (*types.ApiResponse[api.ProtocolDaoProposeKickFromSecurityCouncilData], error) {
args := map[string]string{
"address": address.Hex(),
}
return client.SendGetRequest[api.ProtocolDaoProposeKickFromSecurityCouncilData](r, "security/kick", "KickFromSecurityCouncil", args)
}
// Propose kicking multiple members from the security council
func (r *PDaoRequester) KickMultiFromSecurityCouncil(addresses []common.Address) (*types.ApiResponse[api.ProtocolDaoProposeKickMultiFromSecurityCouncilData], error) {
args := map[string]string{
"addresses": client.MakeBatchArg(addresses),
}
return client.SendGetRequest[api.ProtocolDaoProposeKickMultiFromSecurityCouncilData](r, "security/kick-multi", "KickMultiFromSecurityCouncil", args)
}
// Propose replacing someone on the security council with a new member to invite
func (r *PDaoRequester) ReplaceMemberOfSecurityCouncil(existingAddress common.Address, newID string, newAddress common.Address) (*types.ApiResponse[api.ProtocolDaoProposeReplaceMemberOfSecurityCouncilData], error) {
args := map[string]string{
"existing-address": existingAddress.Hex(),
"new-id": newID,
"new-address": newAddress.Hex(),
}
return client.SendGetRequest[api.ProtocolDaoProposeReplaceMemberOfSecurityCouncilData](r, "security/replace", "ReplaceMemberOfSecurityCouncil", args)
}
// Get the Protocol DAO settings
func (r *PDaoRequester) Settings() (*types.ApiResponse[api.ProtocolDaoSettingsData], error) {
return client.SendGetRequest[api.ProtocolDaoSettingsData](r, "settings", "Settings", nil)
}
// Propose updating one of the Protocol DAO settings
func (r *PDaoRequester) ProposeSetting(contractName rocketpool.ContractName, setting protocol.SettingName, value string) (*types.ApiResponse[api.ProtocolDaoProposeSettingData], error) {
args := map[string]string{
"contract": string(contractName),
"setting": string(setting),
"value": value,
}
return client.SendGetRequest[api.ProtocolDaoProposeSettingData](r, "setting/propose", "ProposeSetting", args)
}
// Initialize voting so the node can vote on Protocol DAO proposals
func (r *PDaoRequester) InitializeVoting() (*types.ApiResponse[api.ProtocolDaoInitializeVotingData], error) {
return client.SendGetRequest[api.ProtocolDaoInitializeVotingData](r, "initialize-voting", "InitializeVoting", nil)
}
// Set the delegate for voting on Protocol DAO proposals
func (r *PDaoRequester) SetVotingDelegate(delegate common.Address) (*types.ApiResponse[types.TxInfoData], error) {
args := map[string]string{
"delegate": delegate.Hex(),
}
return client.SendGetRequest[types.TxInfoData](r, "voting-delegate/set", "SetVotingDelegate", args)
}
// Get the address that's assigned as the delegate for voting on Protocol DAO proposals
func (r *PDaoRequester) GetCurrentVotingDelegate() (*types.ApiResponse[api.ProtocolDaoCurrentVotingDelegateData], error) {
return client.SendGetRequest[api.ProtocolDaoCurrentVotingDelegateData](r, "voting-delegate", "GetCurrentVotingDelegate", nil)
}