config.gno
2.70 Kb ยท 117 lines
1package personal_world
2
3import (
4 "chain"
5 "chain/runtime"
6 "chain/banker"
7
8 "gno.land/p/nt/ufmt"
9 "gno.land/r/akkadia/admin"
10)
11
12const (
13 SetFeeCollectorBPSEvent = "SetFeeCollectorBPS"
14 SetListLimitEvent = "SetListLimit"
15 SetBatchLimitEvent = "SetBatchLimit"
16)
17
18var (
19 feeCollectorBPS int = 500 // 5% (500 BPS)
20 listLimit int = 100 // Max items per list query
21 batchLimit int = 1000 // Max keys per batch query
22)
23
24// SetFeeCollectorBPS sets the feeCollector basis points (admin only)
25func SetFeeCollectorBPS(cur realm, bps int) {
26 caller := runtime.PreviousRealm().Address()
27 assertIsAdmin(caller)
28 if bps < 0 || bps > 10000 {
29 panic("bps must be between 0 and 10000")
30 }
31
32 oldBPS := feeCollectorBPS
33 feeCollectorBPS = bps
34
35 // Emit event
36 chain.Emit(
37 SetFeeCollectorBPSEvent,
38 "admin", caller.String(),
39 "oldBPS", ufmt.Sprintf("%d", oldBPS),
40 "newBPS", ufmt.Sprintf("%d", bps),
41 )
42}
43
44// GetFeeCollectorBPS returns the feeCollector BPS
45func GetFeeCollectorBPS() int {
46 return feeCollectorBPS
47}
48
49// SetListLimit sets the max items per list query (admin only)
50func SetListLimit(cur realm, limit int) {
51 caller := runtime.PreviousRealm().Address()
52 assertIsAdmin(caller)
53 if limit < 1 {
54 panic("limit must be at least 1")
55 }
56
57 oldLimit := listLimit
58 listLimit = limit
59
60 chain.Emit(
61 SetListLimitEvent,
62 "admin", caller.String(),
63 "oldLimit", ufmt.Sprintf("%d", oldLimit),
64 "newLimit", ufmt.Sprintf("%d", 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 caller := runtime.PreviousRealm().Address()
76 assertIsAdmin(caller)
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 "admin", caller.String(),
87 "oldLimit", ufmt.Sprintf("%d", oldLimit),
88 "newLimit", ufmt.Sprintf("%d", limit),
89 )
90}
91
92// GetBatchLimit returns the max keys per batch query
93func GetBatchLimit() int {
94 return batchLimit
95}
96
97func distributeFunds(amount int64) (int64, int64) {
98 // Calculate feeCollector share (BPS)
99 feeCollectorShare := (amount * int64(feeCollectorBPS)) / 10000
100 protocolShare := amount - feeCollectorShare
101
102 // Send funds to feeCollector and protocol
103 bnk := banker.NewBanker(banker.BankerTypeRealmSend)
104 realmAddr := runtime.CurrentRealm().Address()
105
106 if feeCollectorShare > 0 {
107 coins := chain.Coins{chain.Coin{"ugnot", feeCollectorShare}}
108 bnk.SendCoins(realmAddr, admin.GetFeeCollector(), coins)
109 }
110
111 if protocolShare > 0 {
112 coins := chain.Coins{chain.Coin{"ugnot", protocolShare}}
113 bnk.SendCoins(realmAddr, admin.GetProtocol(), coins)
114 }
115
116 return feeCollectorShare, protocolShare
117}