config.gno
3.24 Kb ยท 124 lines
1package halt
2
3// HaltConfig stores halt state for each operation type.
4type HaltConfig map[OpType]bool
5
6// IsHalted returns true if the specified operation is halted, false otherwise.
7// Returns false if operation type is not found in configuration.
8func (c HaltConfig) IsHalted(op OpType) bool {
9 halted, exists := c[op]
10 if !exists {
11 return false
12 }
13
14 return halted
15}
16
17// Clone creates a deep copy of the halt configuration and returns it.
18func (c HaltConfig) Clone() HaltConfig {
19 clone := make(HaltConfig)
20
21 for op, option := range c {
22 clone[op] = option
23 }
24
25 return clone
26}
27
28// get retrieves halt state for the specified operation type.
29//
30// Errors:
31// - errOpTypeNotFound: the specified operation type does not exist in the config
32func (c HaltConfig) get(op OpType) (bool, error) {
33 enabled, exists := c[op]
34 if !exists {
35 return false, makeErrorWithDetails(errOpTypeNotFound, op.String())
36 }
37
38 return enabled, nil
39}
40
41// set updates halt state for the specified operation type.
42// Returns error if operation type is invalid.
43func (c HaltConfig) set(op OpType, enabled bool) error {
44 if !op.IsValid() {
45 return makeErrorWithDetails(errInvalidOpType, op.String())
46 }
47
48 c[op] = enabled
49
50 return nil
51}
52
53// newNoneConfig creates configuration with all operations enabled (no halts).
54func newNoneConfig() HaltConfig {
55 return HaltConfig{
56 OpTypePool: false,
57 OpTypePosition: false,
58 OpTypeProtocolFee: false,
59 OpTypeRouter: false,
60 OpTypeStaker: false,
61 OpTypeLaunchpad: false,
62 OpTypeGovernance: false,
63 OpTypeGovStaker: false,
64 OpTypeXGns: false,
65 OpTypeCommunityPool: false,
66 OpTypeEmission: false,
67 OpTypeWithdraw: false,
68 }
69}
70
71// newSafeModeConfig creates configuration for safe mode with only withdrawals halted.
72func newSafeModeConfig() HaltConfig {
73 return HaltConfig{
74 OpTypePool: false,
75 OpTypePosition: false,
76 OpTypeProtocolFee: false,
77 OpTypeRouter: false,
78 OpTypeStaker: false,
79 OpTypeLaunchpad: false,
80 OpTypeGovernance: false,
81 OpTypeGovStaker: false,
82 OpTypeXGns: false,
83 OpTypeCommunityPool: false,
84 OpTypeEmission: false,
85 OpTypeWithdraw: true,
86 }
87}
88
89// newEmergencyConfig creates configuration for emergency mode with most operations halted.
90// Only governance and withdraw operations remain enabled for emergency recovery.
91func newEmergencyConfig() HaltConfig {
92 return HaltConfig{
93 OpTypePool: true,
94 OpTypePosition: true,
95 OpTypeProtocolFee: true,
96 OpTypeRouter: true,
97 OpTypeStaker: true,
98 OpTypeLaunchpad: true,
99 OpTypeGovernance: false,
100 OpTypeGovStaker: true,
101 OpTypeXGns: true,
102 OpTypeCommunityPool: true,
103 OpTypeEmission: true,
104 OpTypeWithdraw: false,
105 }
106}
107
108// newCompleteConfig creates configuration with all operations halted for complete lockdown.
109func newCompleteConfig() HaltConfig {
110 return HaltConfig{
111 OpTypePool: true,
112 OpTypePosition: true,
113 OpTypeProtocolFee: true,
114 OpTypeRouter: true,
115 OpTypeStaker: true,
116 OpTypeLaunchpad: true,
117 OpTypeGovernance: true,
118 OpTypeGovStaker: true,
119 OpTypeXGns: true,
120 OpTypeCommunityPool: true,
121 OpTypeEmission: true,
122 OpTypeWithdraw: true,
123 }
124}