Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

admin.gno

2.51 Kb · 103 lines
  1package otc
  2
  3import (
  4	"chain"
  5	"strconv"
  6
  7	"gno.land/r/nt/grc20reg/v0"
  8)
  9
 10// The admin's whole reach (A1). None of these touches an offer or an escrow
 11// (A3); every one refuses coins (S2) and emits an event.
 12
 13// AddToken whitelists a token by its grc20reg key, enabled (W2).
 14func AddToken(cur realm, key string) {
 15	requireAdmin(cur)
 16	if grc20reg.Get(key) == nil {
 17		panic(ErrTokenUnknown)
 18	}
 19	if tokens.Has(key) {
 20		panic(ErrTokenExists)
 21	}
 22	if tokens.Size() >= maxTokens {
 23		panic(ErrTooManyTokens)
 24	}
 25	tokens.Set(key, true)
 26	chain.Emit(EventTokenChanged, "token", key, "enabled", "true")
 27}
 28
 29// SetTokenEnabled switches new offers on a token on or off. Open offers on a
 30// disabled token can still be filled and cancelled (W2).
 31func SetTokenEnabled(cur realm, key string, enabled bool) {
 32	requireAdmin(cur)
 33	if !tokens.Has(key) {
 34		panic(ErrTokenNotListed)
 35	}
 36	tokens.Set(key, enabled)
 37	chain.Emit(EventTokenChanged, "token", key, "enabled", strconv.FormatBool(enabled))
 38}
 39
 40// SetFeeBps sets the default fee for NEW offers (F4, F5).
 41func SetFeeBps(cur realm, bps int64) {
 42	requireAdmin(cur)
 43	requireFee(bps)
 44	feeBps = bps
 45	chain.Emit(EventFeeChanged, "fee_bps", strconv.FormatInt(bps, 10))
 46}
 47
 48// SetGnomicFee turns the reduced GNOMIC fee on or off and sets it (F6).
 49func SetGnomicFee(cur realm, enabled bool, bps int64) {
 50	requireAdmin(cur)
 51	requireFee(bps)
 52	gnomicFeeOn = enabled
 53	gnomicFee = bps
 54	chain.Emit(EventFeeChanged,
 55		"gnomic_fee_enabled", strconv.FormatBool(enabled),
 56		"gnomic_fee_bps", strconv.FormatInt(bps, 10))
 57}
 58
 59// SetFeeRecipient changes where fees go.
 60func SetFeeRecipient(cur realm, to address) {
 61	requireAdmin(cur)
 62	if !to.IsValid() {
 63		panic(ErrBadAddress)
 64	}
 65	if to == realmAddr {
 66		panic(ErrFeeToRealm)
 67	}
 68	old := feeRecipient
 69	feeRecipient = to
 70	chain.Emit(EventFeeRecipientChanged, "old", old.String(), "new", to.String())
 71}
 72
 73// SetPaused blocks or allows new offers and fills. It never blocks Cancel
 74// (A2, R10).
 75func SetPaused(cur realm, p bool) {
 76	requireAdmin(cur)
 77	paused = p
 78	chain.Emit(EventPaused, "paused", strconv.FormatBool(p))
 79}
 80
 81// TransferAdmin hands the admin role to another address.
 82func TransferAdmin(cur realm, to address) {
 83	requireAdmin(cur)
 84	if !to.IsValid() || to == realmAddr {
 85		panic(ErrBadAddress)
 86	}
 87	old := admin
 88	admin = to
 89	chain.Emit(EventAdminChanged, "old", old.String(), "new", to.String())
 90}
 91
 92func requireAdmin(cur realm) {
 93	requireNoCoins()
 94	if cur.Previous().Address() != admin {
 95		panic(ErrNotAdmin) // S7
 96	}
 97}
 98
 99func requireFee(bps int64) {
100	if bps < 0 || bps > feeCapBps {
101		panic(ErrFeeAboveCap)
102	}
103}