Search Apps Documentation Source Content File Folder Download Copy Actions Download

config.gno

2.02 Kb · 94 lines
 1package personal_world
 2
 3import (
 4	"chain"
 5	"strconv"
 6
 7	"gno.land/p/akkadia/v0/accesscontrol"
 8	"gno.land/r/akkadia/v0/admin"
 9)
10
11const (
12	SetFeeCollectorBPSEvent = "SetFeeCollectorBPS"
13	SetListLimitEvent       = "SetListLimit"
14	SetBatchLimitEvent      = "SetBatchLimit"
15
16	maxFeeCollectorBPS    = int(10000)
17	minPriceMultiplierBPS = int64(1000)
18)
19
20var (
21	feeCollectorBPS int = 500  // 5% (500 BPS)
22	listLimit       int = 100  // Max items per list query
23	batchLimit      int = 1000 // Max keys per batch query
24)
25
26// SetFeeCollectorBPS sets the feeCollector basis points (admin only)
27func SetFeeCollectorBPS(cur realm, bps int) {
28	assertNotFrozen()
29	accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
30	if bps < 0 || bps > maxFeeCollectorBPS {
31		panic("fee collector BPS must be between 0 and 10000")
32	}
33
34	oldBPS := feeCollectorBPS
35	feeCollectorBPS = bps
36
37	// Emit event
38	chain.Emit(
39		SetFeeCollectorBPSEvent,
40		"oldBPS", strconv.Itoa(oldBPS),
41		"newBPS", strconv.Itoa(bps),
42	)
43}
44
45// GetFeeCollectorBPS returns the feeCollector BPS
46func GetFeeCollectorBPS() int {
47	return feeCollectorBPS
48}
49
50// SetListLimit sets the max items per list query (admin only)
51func SetListLimit(cur realm, limit int) {
52	assertNotFrozen()
53	accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
54	if limit < 1 {
55		panic("limit must be at least 1")
56	}
57
58	oldLimit := listLimit
59	listLimit = limit
60
61	chain.Emit(
62		SetListLimitEvent,
63		"oldLimit", strconv.Itoa(oldLimit),
64		"newLimit", strconv.Itoa(limit),
65	)
66}
67
68// GetListLimit returns the max items per list query
69func GetListLimit() int {
70	return listLimit
71}
72
73// SetBatchLimit sets the max keys per batch query (admin only)
74func SetBatchLimit(cur realm, limit int) {
75	assertNotFrozen()
76	accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
77	if limit < 1 {
78		panic("limit must be at least 1")
79	}
80
81	oldLimit := batchLimit
82	batchLimit = limit
83
84	chain.Emit(
85		SetBatchLimitEvent,
86		"oldLimit", strconv.Itoa(oldLimit),
87		"newLimit", strconv.Itoa(limit),
88	)
89}
90
91// GetBatchLimit returns the max keys per batch query
92func GetBatchLimit() int {
93	return batchLimit
94}