config.gno
6.97 Kb · 178 lines
1package impl
2
3import (
4 pdca "gno.land/p/gnoswap/order/dca/v0"
5 ufmt "gno.land/p/nt/ufmt/v0"
6)
7
8// SetOrderLimits sets the minimum input per execution
9// and the maximum executions per order.
10// Existing orders are unaffected. Admin or governance only.
11func (d *dcaOrderImpl) SetOrderLimits(_ int, rlm realm, minAmountPerExecution int64, maxExecutionCount int64) {
12 prev := d.assertIsAdminCall(0, rlm)
13
14 if minAmountPerExecution <= 0 {
15 panic(makeErrorWithDetails(
16 errInvalidConfig,
17 ufmt.Sprintf("minAmountPerExecution(%d) must be positive", minAmountPerExecution),
18 ).Error())
19 }
20
21 if maxExecutionCount <= 0 || maxExecutionCount > maxExecutionCountLimit {
22 panic(makeErrorWithDetails(
23 errInvalidConfig,
24 ufmt.Sprintf("maxExecutionCount(%d) must be in [1, %d]", maxExecutionCount, maxExecutionCountLimit),
25 ).Error())
26 }
27
28 config := d.store.GetConfig()
29 previousMinAmountPerExecution := config.MinAmountPerExecution()
30 previousMaxExecutionCount := config.MaxExecutionCount()
31 config.SetMinAmountPerExecution(minAmountPerExecution)
32 config.SetMaxExecutionCount(maxExecutionCount)
33
34 emitConfigUpdated(prev.Address(), prev.PkgPath(), "minAmountPerExecution", previousMinAmountPerExecution, minAmountPerExecution)
35 emitConfigUpdated(prev.Address(), prev.PkgPath(), "maxExecutionCount", previousMaxExecutionCount, maxExecutionCount)
36}
37
38// AddAllowedInterval allows new orders to use interval.
39// Admin or governance only.
40func (d *dcaOrderImpl) AddAllowedInterval(_ int, rlm realm, interval int64) {
41 prev := d.assertIsAdminCall(0, rlm)
42
43 if interval < minAllowedInterval || interval > maxAllowedInterval {
44 panic(makeErrorWithDetails(
45 errInvalidInterval,
46 ufmt.Sprintf("interval(%d) must be in [%d, %d]", interval, minAllowedInterval, maxAllowedInterval),
47 ).Error())
48 }
49
50 if err := d.store.GetConfig().AddAllowedInterval(interval); err != nil {
51 panic(makeErrorWithDetails(errInvalidInterval, ufmt.Sprintf("interval(%d): %s", interval, err.Error())).Error())
52 }
53
54 emitAllowedIntervalUpdated(prev.Address(), prev.PkgPath(), interval, true)
55}
56
57// RemoveAllowedInterval stops new orders from using interval.
58// Existing orders and groups of that interval keep running.
59// At least one interval must stay allowed. Admin or governance only.
60func (d *dcaOrderImpl) RemoveAllowedInterval(_ int, rlm realm, interval int64) {
61 prev := d.assertIsAdminCall(0, rlm)
62
63 config := d.store.GetConfig()
64 if len(config.AllowedIntervals()) == 1 && config.IsAllowedInterval(interval) {
65 panic(makeErrorWithDetails(errInvalidConfig, "at least one interval must stay allowed").Error())
66 }
67
68 if err := config.RemoveAllowedInterval(interval); err != nil {
69 panic(makeErrorWithDetails(errInvalidInterval, ufmt.Sprintf("interval(%d): %s", interval, err.Error())).Error())
70 }
71
72 emitAllowedIntervalUpdated(prev.Address(), prev.PkgPath(), interval, false)
73}
74
75// SetMinExecutionGapRate sets the minimum gap between a group's executions,
76// in basis points of its interval. Admin or governance only.
77func (d *dcaOrderImpl) SetMinExecutionGapRate(_ int, rlm realm, minExecutionGapRate int64) {
78 prev := d.assertIsAdminCall(0, rlm)
79
80 if minExecutionGapRate < 0 || minExecutionGapRate > pdca.BasisPointDenominator {
81 panic(makeErrorWithDetails(
82 errInvalidConfig,
83 ufmt.Sprintf("minExecutionGapRate(%d) must be in [0, %d]", minExecutionGapRate, pdca.BasisPointDenominator),
84 ).Error())
85 }
86
87 config := d.store.GetConfig()
88 previousMinExecutionGapRate := config.MinExecutionGapRate()
89 config.SetMinExecutionGapRate(minExecutionGapRate)
90
91 emitConfigUpdated(prev.Address(), prev.PkgPath(), "minExecutionGapRate", previousMinExecutionGapRate, minExecutionGapRate)
92}
93
94// SetMaxPoolPriceDeviationRate sets how far, in basis points of price, a pool's
95// price may sit on the favorable side of its swap price limit and still be
96// quoted (0 to 10000; 0 disables the check). Admin or governance only.
97func (d *dcaOrderImpl) SetMaxPoolPriceDeviationRate(_ int, rlm realm, maxPoolPriceDeviationRate int64) {
98 prev := d.assertIsAdminCall(0, rlm)
99
100 if maxPoolPriceDeviationRate < 0 || maxPoolPriceDeviationRate > pdca.BasisPointDenominator {
101 panic(makeErrorWithDetails(
102 errInvalidConfig,
103 ufmt.Sprintf("maxPoolPriceDeviationRate(%d) must be in [0, %d]", maxPoolPriceDeviationRate, pdca.BasisPointDenominator),
104 ).Error())
105 }
106
107 config := d.store.GetConfig()
108 previousMaxPoolPriceDeviationRate := config.MaxPoolPriceDeviationRate()
109 config.SetMaxPoolPriceDeviationRate(maxPoolPriceDeviationRate)
110
111 emitConfigUpdated(
112 prev.Address(),
113 prev.PkgPath(),
114 "maxPoolPriceDeviationRate",
115 previousMaxPoolPriceDeviationRate,
116 maxPoolPriceDeviationRate,
117 )
118}
119
120// SetMaxPairPriceLimitAge sets how long, in seconds, a pair price limit stays
121// usable after the pool manager set it (60 to 604800). A quote or round under
122// an older limit finds no eligible pool, so rounds stop when the manager stops
123// refreshing limits instead of trading at a stale price. Admin or governance only.
124func (d *dcaOrderImpl) SetMaxPairPriceLimitAge(_ int, rlm realm, maxPairPriceLimitAge int64) {
125 prev := d.assertIsAdminCall(0, rlm)
126
127 if maxPairPriceLimitAge < minMaxPairPriceLimitAge || maxPairPriceLimitAge > maxMaxPairPriceLimitAge {
128 panic(makeErrorWithDetails(
129 errInvalidConfig,
130 ufmt.Sprintf("maxPairPriceLimitAge(%d) must be in [%d, %d]", maxPairPriceLimitAge, minMaxPairPriceLimitAge, maxMaxPairPriceLimitAge),
131 ).Error())
132 }
133
134 config := d.store.GetConfig()
135 previousMaxPairPriceLimitAge := config.MaxPairPriceLimitAge()
136 config.SetMaxPairPriceLimitAge(maxPairPriceLimitAge)
137
138 emitConfigUpdated(prev.Address(), prev.PkgPath(), "maxPairPriceLimitAge", previousMaxPairPriceLimitAge, maxPairPriceLimitAge)
139}
140
141// SetMaxClaimBatchSize caps the orders one ClaimGroupOrders call examines.
142// Admin or governance only.
143func (d *dcaOrderImpl) SetMaxClaimBatchSize(_ int, rlm realm, maxClaimBatchSize int64) {
144 prev := d.assertIsAdminCall(0, rlm)
145
146 if maxClaimBatchSize <= 0 || maxClaimBatchSize > maxClaimBatchSizeLimit {
147 panic(makeErrorWithDetails(
148 errInvalidConfig,
149 ufmt.Sprintf("maxClaimBatchSize(%d) must be in [1, %d]", maxClaimBatchSize, maxClaimBatchSizeLimit),
150 ).Error())
151 }
152
153 config := d.store.GetConfig()
154 previousMaxClaimBatchSize := config.MaxClaimBatchSize()
155 config.SetMaxClaimBatchSize(maxClaimBatchSize)
156
157 emitConfigUpdated(prev.Address(), prev.PkgPath(), "maxClaimBatchSize", previousMaxClaimBatchSize, maxClaimBatchSize)
158}
159
160// SetSlotStep sets the spacing of the slot offsets new orders may use
161// at interval. Existing groups keep their slot.
162// Admin or governance only.
163func (d *dcaOrderImpl) SetSlotStep(_ int, rlm realm, interval int64, slotStep int64) {
164 prev := d.assertIsAdminCall(0, rlm)
165
166 config := d.store.GetConfig()
167 assertIsAllowedInterval(config, interval)
168 previousSlotStep := config.SlotStep(interval)
169
170 if err := config.SetSlotStep(interval, slotStep); err != nil {
171 panic(makeErrorWithDetails(
172 errInvalidSlotStep,
173 ufmt.Sprintf("slotStep(%d) must be a positive divisor of interval(%d)", slotStep, interval),
174 ).Error())
175 }
176
177 emitSlotStepChanged(prev.Address(), prev.PkgPath(), interval, previousSlotStep, slotStep)
178}