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.98 Kb · 85 lines
 1package limit
 2
 3// Config holds governance-controlled limit-order parameters.
 4type Config struct {
 5	executionFeeRate    int64 // snapshotted into each new order, bps of gross output
 6	maxSlippageBps      int64 // maximum slippage accepted for new orders
 7	minMakingAmount     int64 // minimum input amount accepted for new orders
 8	minOrderDuration    int64 // shortest allowed expiresAt - createdAt, in seconds
 9	maxOrderDuration    int64 // longest allowed expiresAt - createdAt, in seconds
10	maxCleanupBatchSize int64 // most orders one CleanupExpiredOrders call examines
11}
12
13// NewConfig returns a config with the given parameters.
14// Bounds are enforced by the implementation that stores it.
15func NewConfig(
16	executionFeeRate int64,
17	minMakingAmount int64,
18	minOrderDuration int64,
19	maxOrderDuration int64,
20	maxCleanupBatchSize int64,
21) *Config {
22	return &Config{
23		executionFeeRate:    executionFeeRate,
24		maxSlippageBps:      DefaultMaxSlippageBps,
25		minMakingAmount:     minMakingAmount,
26		minOrderDuration:    minOrderDuration,
27		maxOrderDuration:    maxOrderDuration,
28		maxCleanupBatchSize: maxCleanupBatchSize,
29	}
30}
31
32// Clone returns a copy of the config that shares no state with c.
33// Callers outside the storing realm read the config through it.
34func (c *Config) Clone() *Config {
35	return &Config{
36		executionFeeRate:    c.executionFeeRate,
37		maxSlippageBps:      c.maxSlippageBps,
38		minMakingAmount:     c.minMakingAmount,
39		minOrderDuration:    c.minOrderDuration,
40		maxOrderDuration:    c.maxOrderDuration,
41		maxCleanupBatchSize: c.maxCleanupBatchSize,
42	}
43}
44
45func (c *Config) ExecutionFeeRate() int64 { return c.executionFeeRate }
46
47// SetExecutionFeeRate sets the execution fee rate in basis points.
48// It returns ErrInvalidExecutionFeeRate outside [0, MaxExecutionFeeRate].
49func (c *Config) SetExecutionFeeRate(executionFeeRate int64) error {
50	if !isValidExecutionFeeRate(executionFeeRate) {
51		return ErrInvalidExecutionFeeRate
52	}
53
54	c.executionFeeRate = executionFeeRate
55
56	return nil
57}
58
59func (c *Config) MaxSlippageBps() int64 { return c.maxSlippageBps }
60
61// SetMaxSlippageBps sets the maximum slippage accepted for new orders.
62// It returns ErrInvalidSlippage outside [0, BpsDenominator].
63func (c *Config) SetMaxSlippageBps(maxSlippageBps int64) error {
64	if maxSlippageBps < 0 || maxSlippageBps > BpsDenominator {
65		return ErrInvalidSlippage
66	}
67
68	c.maxSlippageBps = maxSlippageBps
69
70	return nil
71}
72
73func (c *Config) MinMakingAmount() int64     { return c.minMakingAmount }
74func (c *Config) SetMinMakingAmount(v int64) { c.minMakingAmount = v }
75
76func (c *Config) MinOrderDuration() int64     { return c.minOrderDuration }
77func (c *Config) SetMinOrderDuration(v int64) { c.minOrderDuration = v }
78
79func (c *Config) MaxOrderDuration() int64     { return c.maxOrderDuration }
80func (c *Config) SetMaxOrderDuration(v int64) { c.maxOrderDuration = v }
81
82func (c *Config) MaxCleanupBatchSize() int64 { return c.maxCleanupBatchSize }
83func (c *Config) SetMaxCleanupBatchSize(maxCleanupBatchSize int64) {
84	c.maxCleanupBatchSize = maxCleanupBatchSize
85}