Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

config.gno

2.59 Kb · 66 lines
 1package impl
 2
 3import (
 4	"gno.land/p/gnoswap/utils/v1"
 5)
 6
 7// SetMinMakingAmount sets the minimum input amount accepted for new orders.
 8func (l *limitOrderImpl) SetMinMakingAmount(_ int, rlm realm, minMakingAmount int64) {
 9	prev := l.assertIsAdminCall(0, rlm)
10
11	if minMakingAmount <= 0 {
12		panic(makeErrorWithDetails(errInvalidConfig, "minMakingAmount must be positive").Error())
13	}
14
15	config := l.store.GetConfig()
16	old := config.MinMakingAmount()
17	config.SetMinMakingAmount(minMakingAmount)
18
19	emitConfigUpdated(prev.Address(), prev.PkgPath(), "minMakingAmount", utils.FormatInt(old), utils.FormatInt(minMakingAmount))
20}
21
22// SetOrderDeadlines sets the positive duration range accepted for new orders.
23func (l *limitOrderImpl) SetOrderDeadlines(_ int, rlm realm, minDuration, maxDuration int64) {
24	prev := l.assertIsAdminCall(0, rlm)
25
26	if minDuration <= 0 || maxDuration < minDuration {
27		panic(makeErrorWithDetails(errInvalidConfig, "invalid order duration range").Error())
28	}
29
30	config := l.store.GetConfig()
31	oldMin, oldMax := config.MinOrderDuration(), config.MaxOrderDuration()
32	config.SetMinOrderDuration(minDuration)
33	config.SetMaxOrderDuration(maxDuration)
34
35	emitConfigUpdated(prev.Address(), prev.PkgPath(), "minOrderDuration", utils.FormatInt(oldMin), utils.FormatInt(minDuration))
36	emitConfigUpdated(prev.Address(), prev.PkgPath(), "maxOrderDuration", utils.FormatInt(oldMax), utils.FormatInt(maxDuration))
37}
38
39// SetMaxCleanupBatchSize bounds examined records, not just successful refunds.
40func (l *limitOrderImpl) SetMaxCleanupBatchSize(_ int, rlm realm, maxCleanupBatchSize int64) {
41	prev := l.assertIsAdminCall(0, rlm)
42
43	if maxCleanupBatchSize < 1 || maxCleanupBatchSize > maxCleanupBatchSizeLimit {
44		panic(makeErrorWithDetails(errInvalidConfig, "maxCleanupBatchSize must be in [1, "+utils.FormatInt(maxCleanupBatchSizeLimit)+"]").Error())
45	}
46
47	config := l.store.GetConfig()
48	old := config.MaxCleanupBatchSize()
49	config.SetMaxCleanupBatchSize(maxCleanupBatchSize)
50
51	emitConfigUpdated(prev.Address(), prev.PkgPath(), "maxCleanupBatchSize", utils.FormatInt(old), utils.FormatInt(maxCleanupBatchSize))
52}
53
54// SetMaxSlippageBps sets the slippage cap for new orders.
55func (l *limitOrderImpl) SetMaxSlippageBps(_ int, rlm realm, maxSlippageBps int64) {
56	prev := l.assertIsAdminCall(0, rlm)
57
58	config := l.store.GetConfig()
59
60	old := config.MaxSlippageBps()
61	if err := config.SetMaxSlippageBps(maxSlippageBps); err != nil {
62		panic(makeErrorWithDetails(errInvalidConfig, "maxSlippageBps must be in [0, 10000]").Error())
63	}
64
65	emitConfigUpdated(prev.Address(), prev.PkgPath(), "maxSlippageBps", utils.FormatInt(old), utils.FormatInt(maxSlippageBps))
66}