types.gno
2.72 Kb ยท 100 lines
1package halt
2
3// Halt levels define different states of system operation restriction.
4const (
5 HaltLevelNone HaltLevel = "NONE" // All operations enabled.
6 HaltLevelSafeMode HaltLevel = "SAFE_MODE" // All operations enabled except withdrawals.
7 HaltLevelEmergency HaltLevel = "EMERGENCY" // Only governance and withdrawal operations enabled.
8 HaltLevelComplete HaltLevel = "COMPLETE" // All operations disabled.
9)
10
11// Operation types representing individual contracts.
12const (
13 OpTypePool OpType = "pool"
14 OpTypePosition OpType = "position"
15 OpTypeProtocolFee OpType = "protocol_fee"
16 OpTypeRouter OpType = "router"
17 OpTypeStaker OpType = "staker"
18 OpTypeLaunchpad OpType = "launchpad"
19 OpTypeGovernance OpType = "governance"
20 OpTypeGovStaker OpType = "gov_staker"
21 OpTypeXGns OpType = "xgns"
22 OpTypeCommunityPool OpType = "community_pool"
23 OpTypeEmission OpType = "emission"
24 OpTypeWithdraw OpType = "withdraw"
25)
26
27var haltLevelDescriptions = map[HaltLevel]string{
28 HaltLevelNone: "All operations enabled",
29 HaltLevelSafeMode: "All operations enabled except withdrawals",
30 HaltLevelEmergency: "Only governance and withdrawal operations enabled",
31 HaltLevelComplete: "All operations disabled",
32}
33
34// HaltLevel represents current system halt state.
35type HaltLevel string
36
37// String returns the string representation of the halt level.
38func (h HaltLevel) String() string {
39 return string(h)
40}
41
42// Description returns a human-readable description of the halt level.
43func (h HaltLevel) Description() string {
44 desc, ok := haltLevelDescriptions[h]
45 if !ok {
46 return "Unknown halt level"
47 }
48
49 return desc
50}
51
52// IsValid returns true if the halt level is valid.
53func (h HaltLevel) IsValid() bool {
54 switch h {
55 case HaltLevelNone, HaltLevelSafeMode, HaltLevelEmergency, HaltLevelComplete:
56 return true
57 default:
58 return false
59 }
60}
61
62// OpType represents operation types that can be controlled independently.
63type OpType string
64
65var opTypes = map[OpType]bool{
66 OpTypePool: true,
67 OpTypePosition: true,
68 OpTypeProtocolFee: true,
69 OpTypeRouter: true,
70 OpTypeStaker: true,
71 OpTypeLaunchpad: true,
72 OpTypeGovernance: true,
73 OpTypeGovStaker: true,
74 OpTypeXGns: true,
75 OpTypeCommunityPool: true,
76 OpTypeEmission: true,
77 OpTypeWithdraw: true,
78}
79
80// String returns the string representation of the operation type.
81func (o OpType) String() string {
82 return string(o)
83}
84
85// IsValid returns true if the operation type is valid.
86func (o OpType) IsValid() bool {
87 _, ok := opTypes[o]
88
89 return ok
90}
91
92func OpTypes() []OpType {
93 allOpTypes := make([]OpType, 0, len(opTypes))
94
95 for op, _ := range opTypes {
96 allOpTypes = append(allOpTypes, op)
97 }
98
99 return allOpTypes
100}