config.gno
2.29 Kb ยท 82 lines
1package governance
2
3import "errors"
4
5// Config represents the configuration of the governor contract
6// All parameters in this struct can be modified through governance.
7type Config struct {
8 // VotingStartDelay is the delay before voting starts after proposal creation (in seconds)
9 VotingStartDelay int64
10 // VotingPeriod is the duration during which votes are collected (in seconds)
11 VotingPeriod int64
12 // VotingWeightSmoothingDuration is the period over which voting weight is averaged
13 // for proposal creation and cancellation threshold calculations (in seconds)
14 VotingWeightSmoothingDuration int64
15 // Quorum is the percentage of total GNS supply required for proposal approval
16 Quorum int64
17 // ProposalCreationThreshold is the minimum average voting weight required to create a proposal
18 ProposalCreationThreshold int64
19 // ExecutionDelay is the waiting period after voting ends before a proposal can be executed (in seconds)
20 ExecutionDelay int64
21 // ExecutionWindow is the time window during which an approved proposal can be executed (in seconds)
22 ExecutionWindow int64
23}
24
25func (c Config) IsValid(currentTime int64) error {
26 if c.VotingStartDelay < 0 {
27 return errors.New("votingStartDelay cannot be negative")
28 }
29
30 if c.VotingPeriod < 0 {
31 return errors.New("votingPeriod cannot be negative")
32 }
33
34 if c.ExecutionDelay < 0 {
35 return errors.New("executionDelay cannot be negative")
36 }
37
38 if c.ExecutionWindow < 0 {
39 return errors.New("executionWindow cannot be negative")
40 }
41
42 if c.VotingWeightSmoothingDuration < 0 {
43 return errors.New("votingWeightSmoothingDuration cannot be negative")
44 }
45
46 if c.ProposalCreationThreshold < 0 {
47 return errors.New("proposalCreationThreshold cannot be negative")
48 }
49
50 if c.Quorum < 0 || c.Quorum > 100 {
51 return errors.New("quorum must be between 0 and 100")
52 }
53
54 sum := int64(0)
55
56 sum += c.VotingStartDelay
57 if sum < 0 {
58 return errors.New("votingStartDelay cannot be negative")
59 }
60
61 sum += c.VotingPeriod
62 if sum < 0 {
63 return errors.New("votingPeriod cannot be negative")
64 }
65
66 sum += c.ExecutionDelay
67 if sum < 0 {
68 return errors.New("executionDelay cannot be negative")
69 }
70
71 sum += c.ExecutionWindow
72 if sum < 0 {
73 return errors.New("executionWindow cannot be negative")
74 }
75
76 sum += currentTime
77 if sum < 0 {
78 return errors.New("total delay cannot be negative")
79 }
80
81 return nil
82}