-
Notifications
You must be signed in to change notification settings - Fork 38
/
proposal.go
420 lines (341 loc) · 15.5 KB
/
proposal.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
package types
import (
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
bandprice "github.com/InjectiveLabs/sdk-go/bandchain/hooks/price"
bandoracle "github.com/InjectiveLabs/sdk-go/bandchain/oracle/types"
bandobi "github.com/bandprotocol/bandchain-packet/obi"
)
// constants
const (
ProposalTypeGrantBandOraclePrivilege string = "ProposalTypeGrantBandOraclePrivilege"
ProposalTypeRevokeBandOraclePrivilege string = "ProposalTypeRevokeBandOraclePrivilege"
ProposalTypeGrantPriceFeederOraclePrivilege string = "ProposalTypeGrantPriceFeederOraclePrivilege"
ProposalTypeRevokePriceFeederOraclePrivilege string = "ProposalTypeRevokePriceFeederOraclePrivilege"
ProposalAuthorizeBandOracleRequest string = "ProposalTypeAuthorizeBandOracleRequest"
ProposalUpdateBandOracleRequest string = "ProposalUpdateBandOracleRequest"
ProposalEnableBandIBC string = "ProposalTypeEnableBandIBC"
ProposalTypeGrantProviderPrivilege string = "ProposalTypeGrantProviderPrivilege"
ProposalTypeRevokeProviderPrivilege string = "ProposalTypeRevokeProviderPrivilege"
)
func init() {
gov.RegisterProposalType(ProposalTypeGrantBandOraclePrivilege)
gov.RegisterProposalTypeCodec(&GrantBandOraclePrivilegeProposal{}, "injective/GrantBandOraclePrivilegeProposal")
gov.RegisterProposalType(ProposalTypeRevokeBandOraclePrivilege)
gov.RegisterProposalTypeCodec(&RevokeBandOraclePrivilegeProposal{}, "injective/RevokeBandOraclePrivilegeProposal")
gov.RegisterProposalType(ProposalTypeGrantPriceFeederOraclePrivilege)
gov.RegisterProposalTypeCodec(&GrantPriceFeederPrivilegeProposal{}, "injective/GrantPriceFeederPrivilegeProposal")
gov.RegisterProposalType(ProposalTypeRevokePriceFeederOraclePrivilege)
gov.RegisterProposalTypeCodec(&RevokePriceFeederPrivilegeProposal{}, "injective/RevokePriceFeederPrivilegeProposal")
gov.RegisterProposalType(ProposalAuthorizeBandOracleRequest)
gov.RegisterProposalTypeCodec(&AuthorizeBandOracleRequestProposal{}, "injective/AuthorizeBandOracleRequestProposal")
gov.RegisterProposalType(ProposalEnableBandIBC)
gov.RegisterProposalTypeCodec(&EnableBandIBCProposal{}, "injective/EnableBandIBCProposal")
gov.RegisterProposalType(ProposalUpdateBandOracleRequest)
gov.RegisterProposalTypeCodec(&UpdateBandOracleRequestProposal{}, "injective/UpdateBandOracleRequestProposal")
gov.RegisterProposalType(ProposalTypeGrantProviderPrivilege)
gov.RegisterProposalTypeCodec(&GrantProviderPrivilegeProposal{}, "injective/GrantProviderPrivilegeProposal")
gov.RegisterProposalType(ProposalTypeRevokeProviderPrivilege)
gov.RegisterProposalTypeCodec(&RevokeProviderPrivilegeProposal{}, "injective/RevokeProviderPrivilegeProposal")
}
// Implements Proposal Interface
var _ gov.Content = &GrantBandOraclePrivilegeProposal{}
var _ gov.Content = &RevokeBandOraclePrivilegeProposal{}
var _ gov.Content = &GrantPriceFeederPrivilegeProposal{}
var _ gov.Content = &RevokePriceFeederPrivilegeProposal{}
var _ gov.Content = &AuthorizeBandOracleRequestProposal{}
var _ gov.Content = &UpdateBandOracleRequestProposal{}
var _ gov.Content = &EnableBandIBCProposal{}
var _ gov.Content = &GrantProviderPrivilegeProposal{}
var _ gov.Content = &RevokeProviderPrivilegeProposal{}
// GetTitle returns the title of this proposal.
func (p *GrantBandOraclePrivilegeProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *GrantBandOraclePrivilegeProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *GrantBandOraclePrivilegeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *GrantBandOraclePrivilegeProposal) ProposalType() string {
return ProposalTypeGrantBandOraclePrivilege
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *GrantBandOraclePrivilegeProposal) ValidateBasic() error {
for _, relayer := range p.Relayers {
if _, err := sdk.AccAddressFromBech32(relayer); err != nil {
return err
}
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *RevokeBandOraclePrivilegeProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *RevokeBandOraclePrivilegeProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *RevokeBandOraclePrivilegeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *RevokeBandOraclePrivilegeProposal) ProposalType() string {
return ProposalTypeRevokeBandOraclePrivilege
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *RevokeBandOraclePrivilegeProposal) ValidateBasic() error {
for _, relayer := range p.Relayers {
if _, err := sdk.AccAddressFromBech32(relayer); err != nil {
return err
}
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *GrantPriceFeederPrivilegeProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *GrantPriceFeederPrivilegeProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *GrantPriceFeederPrivilegeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *GrantPriceFeederPrivilegeProposal) ProposalType() string {
return ProposalTypeGrantPriceFeederOraclePrivilege
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *GrantPriceFeederPrivilegeProposal) ValidateBasic() error {
for _, relayer := range p.Relayers {
r, err := sdk.AccAddressFromBech32(relayer)
if err != nil {
return err
}
if r.Empty() {
return ErrEmptyRelayerAddr
}
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *RevokePriceFeederPrivilegeProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *RevokePriceFeederPrivilegeProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *RevokePriceFeederPrivilegeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *RevokePriceFeederPrivilegeProposal) ProposalType() string {
return ProposalTypeRevokePriceFeederOraclePrivilege
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *RevokePriceFeederPrivilegeProposal) ValidateBasic() error {
for _, relayer := range p.Relayers {
r, err := sdk.AccAddressFromBech32(relayer)
if err != nil {
return err
}
if r.Empty() {
return ErrEmptyRelayerAddr
}
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *GrantProviderPrivilegeProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *GrantProviderPrivilegeProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *GrantProviderPrivilegeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *GrantProviderPrivilegeProposal) ProposalType() string {
return ProposalTypeGrantProviderPrivilege
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *GrantProviderPrivilegeProposal) ValidateBasic() error {
if p.Provider == "" {
return ErrEmptyProvider
}
for _, relayer := range p.Relayers {
r, err := sdk.AccAddressFromBech32(relayer)
if err != nil {
return err
}
if r.Empty() {
return ErrEmptyRelayerAddr
}
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *RevokeProviderPrivilegeProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *RevokeProviderPrivilegeProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *RevokeProviderPrivilegeProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *RevokeProviderPrivilegeProposal) ProposalType() string {
return ProposalTypeRevokeProviderPrivilege
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *RevokeProviderPrivilegeProposal) ValidateBasic() error {
if p.Provider == "" {
return ErrEmptyProvider
}
if strings.Contains(p.Provider, providerDelimiter) {
return ErrInvalidProvider
}
if len(p.Relayers) == 0 {
return ErrEmptyRelayerAddr
}
for _, relayer := range p.Relayers {
r, err := sdk.AccAddressFromBech32(relayer)
if err != nil {
return err
}
if r.Empty() {
return ErrEmptyRelayerAddr
}
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *AuthorizeBandOracleRequestProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *AuthorizeBandOracleRequestProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *AuthorizeBandOracleRequestProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *AuthorizeBandOracleRequestProposal) ProposalType() string {
return ProposalTypeRevokePriceFeederOraclePrivilege
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *AuthorizeBandOracleRequestProposal) ValidateBasic() error {
if p.Request.OracleScriptId <= 0 {
return sdkerrors.Wrapf(ErrInvalidBandIBCRequest, "AuthorizeBandOracleRequestProposal: Oracle script id (%d) must be positive.", p.Request.OracleScriptId)
}
if len(p.Request.Symbols) == 0 {
return sdkerrors.Wrap(ErrBadSymbolsCount, "AuthorizeBandOracleRequestProposal")
}
requestCallData := bandprice.Input{
Symbols: p.Request.Symbols,
Multiplier: BandPriceMultiplier,
}
callData := bandobi.MustEncode(requestCallData)
if len(callData) > bandoracle.MaxDataSize {
return bandoracle.WrapMaxError(bandoracle.ErrTooLargeCalldata, len(callData), bandoracle.MaxDataSize)
}
if p.Request.MinCount <= 0 {
return sdkerrors.Wrapf(bandoracle.ErrInvalidMinCount, "AuthorizeBandOracleRequestProposal: Minimum validator count (%d) must be positive.", p.Request.MinCount)
}
if p.Request.AskCount <= 0 {
return sdkerrors.Wrapf(bandoracle.ErrInvalidAskCount, "AuthorizeBandOracleRequestProposal: Request validator count (%d) must be positive.", p.Request.AskCount)
}
if p.Request.AskCount < p.Request.MinCount {
return sdkerrors.Wrapf(bandoracle.ErrInvalidAskCount, "AuthorizeBandOracleRequestProposal: Request validator count (%d) must not be less than sufficient validator count (%d).", p.Request.AskCount, p.Request.MinCount)
}
if !p.Request.FeeLimit.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "AuthorizeBandOracleRequestProposal: Invalid Fee Limit (%s)", p.Request.GetFeeLimit().String())
}
if p.Request.PrepareGas <= 0 {
return sdkerrors.Wrapf(bandoracle.ErrInvalidOwasmGas, "AuthorizeBandOracleRequestProposal: Invalid Prepare Gas (%d)", p.Request.GetPrepareGas())
}
if p.Request.ExecuteGas <= 0 {
return sdkerrors.Wrapf(bandoracle.ErrInvalidOwasmGas, "AuthorizeBandOracleRequestProposal: Invalid Execute Gas (%d)", p.Request.ExecuteGas)
}
if p.Request.PrepareGas+p.Request.ExecuteGas > bandoracle.MaximumOwasmGas {
return sdkerrors.Wrapf(bandoracle.ErrInvalidOwasmGas, "AuthorizeBandOracleRequestProposal: Sum of prepare gas and execute gas (%d) exceeds Maximum gas (%d)", (p.Request.PrepareGas + p.Request.ExecuteGas), bandoracle.MaximumOwasmGas)
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *EnableBandIBCProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *EnableBandIBCProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *EnableBandIBCProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *EnableBandIBCProposal) ProposalType() string {
return ProposalEnableBandIBC
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *EnableBandIBCProposal) ValidateBasic() error {
if p.BandIbcParams.IbcRequestInterval == 0 {
return ErrBadRequestInterval
}
if p.BandIbcParams.IbcSourceChannel == "" {
return sdkerrors.Wrap(ErrInvalidBandIBCRequest, "AuthorizeBandOracleRequestProposal: IBC Source Chanel must not be empty.")
}
if p.BandIbcParams.IbcVersion == "" {
return sdkerrors.Wrap(bandoracle.ErrInvalidVersion, "AuthorizeBandOracleRequestProposal: IBC Version must not be empty.")
}
return gov.ValidateAbstract(p)
}
// GetTitle returns the title of this proposal.
func (p *UpdateBandOracleRequestProposal) GetTitle() string {
return p.Title
}
// GetDescription returns the description of this proposal.
func (p *UpdateBandOracleRequestProposal) GetDescription() string {
return p.Description
}
// ProposalRoute returns router key of this proposal.
func (p *UpdateBandOracleRequestProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns proposal type of this proposal.
func (p *UpdateBandOracleRequestProposal) ProposalType() string {
return ProposalUpdateBandOracleRequest
}
// ValidateBasic returns ValidateBasic result of this proposal.
func (p *UpdateBandOracleRequestProposal) ValidateBasic() error {
if p.DeleteRequestId == 0 && p.UpdateOracleRequest == nil {
return ErrInvalidBandIBCUpdateRequest
}
if p.DeleteRequestId > 0 && p.UpdateOracleRequest != nil {
return sdkerrors.Wrapf(ErrInvalidBandIBCUpdateRequest, "cannot update requestID %T and delete reqeustID %T at same time", p.UpdateOracleRequest.RequestId, p.DeleteRequestId)
}
if p.UpdateOracleRequest != nil && len(p.UpdateOracleRequest.Symbols) > 0 {
requestCallData := bandprice.Input{
Symbols: p.UpdateOracleRequest.Symbols,
Multiplier: BandPriceMultiplier,
}
callData := bandobi.MustEncode(requestCallData)
if len(callData) > bandoracle.MaxDataSize {
return bandoracle.WrapMaxError(bandoracle.ErrTooLargeCalldata, len(callData), bandoracle.MaxDataSize)
}
}
if p.UpdateOracleRequest != nil && p.UpdateOracleRequest.AskCount > 0 && p.UpdateOracleRequest.MinCount > 0 && p.UpdateOracleRequest.AskCount < p.UpdateOracleRequest.MinCount {
return sdkerrors.Wrapf(bandoracle.ErrInvalidAskCount, "UpdateBandOracleRequestProposal: Request validator count (%d) must not be less than sufficient validator count (%d).", p.UpdateOracleRequest.AskCount, p.UpdateOracleRequest.MinCount)
}
if p.UpdateOracleRequest != nil && p.UpdateOracleRequest.FeeLimit != nil && !p.UpdateOracleRequest.FeeLimit.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "UpdateBandOracleRequestProposal: Invalid Fee Limit (%s)", p.UpdateOracleRequest.GetFeeLimit().String())
}
if p.UpdateOracleRequest != nil && p.UpdateOracleRequest.PrepareGas > 0 && p.UpdateOracleRequest.ExecuteGas > 0 && p.UpdateOracleRequest.PrepareGas+p.UpdateOracleRequest.ExecuteGas > bandoracle.MaximumOwasmGas {
return sdkerrors.Wrapf(bandoracle.ErrInvalidOwasmGas, "UpdateBandOracleRequestProposal: Sum of prepare gas and execute gas (%d) exceeds Maximum gas (%d)", (p.UpdateOracleRequest.PrepareGas + p.UpdateOracleRequest.ExecuteGas), bandoracle.MaximumOwasmGas)
}
return gov.ValidateAbstract(p)
}