admin.gno
1.32 Kb · 56 lines
1package gnogle_market2
2
3import (
4 "chain"
5 "strconv"
6
7 "gno.land/p/nt/ufmt/v0"
8)
9
10// ClaimAdmin assigns the market admin (one-time). Admin controls the platform fee.
11func ClaimAdmin(cur realm) {
12 if admin != zeroAddr {
13 panic("admin already claimed")
14 }
15 admin = cur.Previous().Address()
16 chain.Emit("ClaimAdmin", "admin", admin.String())
17}
18
19// SetFeeBps sets the platform fee on secondary sales (e.g. 250 = 2.5%). Admin only.
20func SetFeeBps(cur realm, bps int64) {
21 assertAdmin(cur)
22 if bps < 0 || bps > maxFeeBps {
23 panic(ufmt.Sprintf("feeBps must be between 0 and %d", maxFeeBps))
24 }
25 feeBps = bps
26 chain.Emit("SetFee", "bps", strconv.FormatInt(bps, 10))
27}
28
29// WithdrawFees sends accrued platform fees to addr. Admin only.
30func WithdrawFees(cur realm, addr address) int64 {
31 assertAdmin(cur)
32 if !addr.IsValid() {
33 panic("invalid address")
34 }
35 amount := feePot
36 if amount <= 0 {
37 return 0
38 }
39 feePot = 0
40 payout(cur, addr, amount)
41 chain.Emit("WithdrawFees", "to", addr.String(), "amount", strconv.FormatInt(amount, 10))
42 return amount
43}
44
45func assertAdmin(cur realm) {
46 if admin == zeroAddr {
47 panic("admin not set; call ClaimAdmin first")
48 }
49 if cur.Previous().Address() != admin {
50 panic("unauthorized: admin only")
51 }
52}
53
54func Admin() address { return admin }
55func FeeBps() int64 { return feeBps }
56func FeePot() int64 { return feePot }