Gno.land
| 1 | package otc |
| 2 | |
| 3 | import ( |
| 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). |
| 14 | func 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). |
| 31 | func 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). |
| 41 | func 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). |
| 49 | func 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. |
| 60 | func 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). |
| 75 | func 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. |
| 82 | func 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 | |
| 92 | func requireAdmin(cur realm) { |
| 93 | requireNoCoins() |
| 94 | if cur.Previous().Address() != admin { |
| 95 | panic(ErrNotAdmin) // S7 |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | func requireFee(bps int64) { |
| 100 | if bps < 0 || bps > feeCapBps { |
| 101 | panic(ErrFeeAboveCap) |
| 102 | } |
| 103 | } |
| Function | Parameters |
|---|---|
| AddToken | (key string) |
| SetTokenEnabled | (key string, enabled bool) |
| SetFeeBps | (bps int64) |
| SetGnomicFee | (enabled bool, bps int64) |
| SetFeeRecipient | (to string) |
| SetPaused | (p bool) |
| TransferAdmin | (to string) |
| CreateSellToken | (tokenKey string, tokenAmt int64, gnotAmt int64, taker string, expiresAt int64) |
| CreateSellGnot | (tokenKey string, tokenAmt int64, taker string, expiresAt int64) |
| Fill | (id uint64) |
| Cancel | (id uint64) |
| RealmAddress | () |
Gnomic OTC
Escrowed GRC20 ⇄ GNOT offers, filled in full and atomically.
| Volume | Fees | Filled | Open (public) | Fee | |---|---|---|---|---| | 100 GNOT | 0.1 GNOT | 2 | 2 | 0.3% (GNOMIC 0.1%) |
Open offers
| ID | Side | Token | Amount | GNOT | Maker | Expires | |---|---|---|---|---|---|---| | 10 | SellToken | GNOMIC | 800 | 800 | g12t2q70…pmvd | expired 2026-10-09 06:28 UTC | | 8 | SellToken | GNOMIC | 769 | 769 | g1l0tdzd…583g | never |
| Function | Caller | Age |
|---|---|---|
| CreateSellToken | g12t2q70…xepmvd | 12d ago |
| Cancel | g12t2q70…xepmvd | 12d ago |
| CreateSellToken | g12t2q70…xepmvd | 12d ago |
| Cancel | g1axehvc…kc4n7v | 13d ago |
| CreateSellToken | g1l0tdzd…xu583g | 15d ago |
| Cancel | g15d7uqd…v0vmvp | 15d ago |
| Fill | g13q7zpu…dh4378 | 15d ago |
| CreateSellToken | g1l0tdzd…xu583g | 16d ago |
| Cancel | g1l0tdzd…xu583g | 16d ago |
| CreateSellToken | g1l0tdzd…xu583g | 16d ago |
| Cancel | g1l0tdzd…xu583g | 16d ago |
| CreateSellToken | g1l0tdzd…xu583g | 16d ago |