governance.gno
5.16 Kb · 175 lines
1package memba_collections
2
3import (
4 "chain"
5)
6
7// ── Market registry (DRAIN KEY) ─────────────────────────────────────────────
8
9// RegisterMarket authorizes a marketplace realm to call MarketTransfer. This
10// is a drain key: platformAdmin only, event-logged.
11func RegisterMarket(cur realm, market address) {
12 assertPlatformAdmin()
13 registeredMarkets.Set(market.String(), true)
14 chain.Emit("MarketRegistered", "market", market.String())
15}
16
17func UnregisterMarket(cur realm, market address) {
18 assertPlatformAdmin()
19 registeredMarkets.Remove(market.String())
20 chain.Emit("MarketUnregistered", "market", market.String())
21}
22
23// ── Pause ────────────────────────────────────────────────────────────────────
24
25func assertPauserOrAdmin() {
26 cr := caller()
27 if cr != pauser && cr != platformAdmin {
28 panic("pauser or platform admin only")
29 }
30}
31
32// Pause halts the whole registry. The fast pauser role OR platformAdmin.
33func Pause(cur realm) {
34 assertPauserOrAdmin()
35 paused = true
36 chain.Emit("Paused")
37}
38
39func Unpause(cur realm) {
40 assertPauserOrAdmin()
41 paused = false
42 chain.Emit("Unpaused")
43}
44
45// PauseCollection / UnpauseCollection pause a single collection. Collection
46// admin, pauser, or platformAdmin.
47func PauseCollection(cur realm, id string) {
48 c := mustGet(id)
49 cr := caller()
50 if cr != c.admin && cr != pauser && cr != platformAdmin {
51 panic("not authorized to pause collection")
52 }
53 c.paused = true
54 chain.Emit("CollectionPaused", "collectionID", id)
55}
56
57func UnpauseCollection(cur realm, id string) {
58 c := mustGet(id)
59 cr := caller()
60 if cr != c.admin && cr != pauser && cr != platformAdmin {
61 panic("not authorized to unpause collection")
62 }
63 c.paused = false
64 chain.Emit("CollectionUnpaused", "collectionID", id)
65}
66
67func IsPaused() bool { return paused }
68
69// ── Platform params (each change individually event-logged, E-1) ─────────────
70
71func SetCreateFee(cur realm, newFee int64) {
72 assertPlatformAdmin()
73 if newFee < 0 {
74 panic("negative fee")
75 }
76 old := createFee
77 createFee = newFee
78 chain.Emit("CreateFeeSet", "old", itoa(old), "new", itoa(newFee), "block", itoa(chainHeight()))
79}
80
81func SetPrimaryFeeBPS(cur realm, bps int64) {
82 assertPlatformAdmin()
83 if bps < 0 || bps > MaxPrimaryFeeBPS {
84 panic("primaryFeeBPS out of range")
85 }
86 old := primaryFeeBPS
87 primaryFeeBPS = bps
88 chain.Emit("PrimaryFeeBPSSet", "old", itoa(old), "new", itoa(bps), "block", itoa(chainHeight()))
89}
90
91func SetMaxCreatorRoyaltyBPS(cur realm, bps int64) {
92 assertPlatformAdmin()
93 if bps < 0 || bps > MaxRoyaltyBPS {
94 panic("maxCreatorRoyaltyBPS out of range")
95 }
96 old := maxCreatorRoyaltyBPS
97 maxCreatorRoyaltyBPS = bps
98 chain.Emit("MaxCreatorRoyaltyBPSSet", "old", itoa(old), "new", itoa(bps), "block", itoa(chainHeight()))
99}
100
101func SetFeeRecipient(cur realm, newRecip address) {
102 assertPlatformAdmin()
103 if newRecip == "" {
104 panic("empty fee recipient")
105 }
106 old := feeRecipient
107 feeRecipient = newRecip
108 chain.Emit("FeeRecipientSet", "old", old.String(), "new", newRecip.String(), "block", itoa(chainHeight()))
109}
110
111func AllowDenom(cur realm, denom string) {
112 assertPlatformAdmin()
113 if denom == "" {
114 panic("empty denom")
115 }
116 allowedDenoms.Set(denom, true)
117 chain.Emit("DenomAllowed", "denom", denom, "block", itoa(chainHeight()))
118}
119
120func DisallowDenom(cur realm, denom string) {
121 assertPlatformAdmin()
122 allowedDenoms.Remove(denom)
123 chain.Emit("DenomDisallowed", "denom", denom, "block", itoa(chainHeight()))
124}
125
126func SetPauser(cur realm, newPauser address) {
127 assertPlatformAdmin()
128 old := pauser
129 pauser = newPauser
130 chain.Emit("PauserSet", "old", old.String(), "new", newPauser.String())
131}
132
133// ── Platform admin 2-step transfer ──────────────────────────────────────────
134
135func TransferPlatformAdmin(cur realm, newAdmin address) {
136 assertPlatformAdmin()
137 pendingPlatformAdmin = newAdmin
138 chain.Emit("PlatformAdminTransferred", "pending", newAdmin.String())
139}
140
141func AcceptPlatformAdmin(cur realm) {
142 if caller() != pendingPlatformAdmin {
143 panic("not pending platform admin")
144 }
145 platformAdmin = pendingPlatformAdmin
146 pendingPlatformAdmin = ""
147 chain.Emit("PlatformAdminAccepted", "admin", platformAdmin.String())
148}
149
150// ForceSetCollectionAdmin is the platformAdmin break-glass for a lost or
151// compromised creator key. Event-logged.
152func ForceSetCollectionAdmin(cur realm, id string, newAdmin address) {
153 assertPlatformAdmin()
154 c := mustGet(id)
155 c.admin = newAdmin
156 c.pendingAdmin = ""
157 chain.Emit("ForceAdminSet", "collectionID", id, "newAdmin", newAdmin.String())
158}
159
160// ── Extensible per-collection metadata (DAO badge / flags) ──────────────────
161
162func SetCollectionMeta(cur realm, id, key, value string) {
163 assertPlatformAdmin()
164 c := mustGet(id)
165 c.meta.Set(key, value)
166 chain.Emit("CollectionMetaSet", "collectionID", id, "key", key, "value", value)
167}
168
169func GetCollectionMeta(id, key string) string {
170 c := mustGet(id)
171 if v, ok := c.meta.Get(key); ok {
172 return v.(string)
173 }
174 return ""
175}