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

otc source realm

Package otc is an over-the-counter desk for GRC20 tokens against GNOT.

Overview

Package otc is an over-the-counter desk for GRC20 tokens against GNOT.

A maker escrows one side of a trade in this realm; a taker fills it with the other side, and both halves move in the same transaction or not at all. Every offer has exactly one GRC20 side and one GNOT side (R1), is filled in full or not at all (R8), and can be cancelled by its maker at any moment, paused or not (R10).

WHAT THE ADMIN CANNOT DO (A3). admin.gno sets fees within a constant cap, manages the token whitelist, pauses new offers and fills, and hands the role on. No function anywhere moves, freezes or cancels an escrow except Fill (to the taker) and Cancel (to the maker, called by the maker).

UPGRADES. A realm is immutable. If a bug is found the plan is: pause, deploy a new path (.../otc/v2), and keep this one readable so makers can still cancel here — which pause never blocks.

Constants 4

const EventOfferCreated, EventOfferFilled, EventOfferCancelled, EventAdminChanged, EventFeeChanged, EventFeeRecipientChanged, EventTokenChanged, EventPaused

 1const (
 2	EventOfferCreated        = "OfferCreated"
 3	EventOfferFilled         = "OfferFilled"
 4	EventOfferCancelled      = "OfferCancelled"
 5	EventAdminChanged        = "AdminChanged"
 6	EventFeeChanged          = "FeeChanged"
 7	EventFeeRecipientChanged = "FeeRecipientChanged"
 8	EventTokenChanged        = "TokenChanged"
 9	EventPaused              = "Paused"
10)
source

Events. Every one carries the offer id and the addresses involved.

const ErrPaused, ErrNotUser, ErrNoCoins, ErrBadPayment, ErrBadAmount, ErrBadExpiry, ErrBadAddress, ErrTakerIsMaker, ErrTokenNotListed, ErrTokenDisabled, ErrTokenUnknown, ErrTokenExists, ErrTooManyTokens, ErrNoOffer, ErrNotOpen, ErrNotMaker, ErrNotTaker, ErrOwnOffer, ErrExpired, ErrNotAdmin, ErrFeeAboveCap, ErrFeeToRealm

 1const (
 2	ErrPaused         = "otc: paused"
 3	ErrNotUser        = "otc: must be a direct user call"
 4	ErrNoCoins        = "otc: this call takes no coins"
 5	ErrBadPayment     = "otc: send exactly the required ugnot and nothing else"
 6	ErrBadAmount      = "otc: amounts must be positive"
 7	ErrBadExpiry      = "otc: expiry must be 0 or in the future"
 8	ErrBadAddress     = "otc: invalid address"
 9	ErrTakerIsMaker   = "otc: taker cannot be the maker"
10	ErrTokenNotListed = "otc: token not whitelisted"
11	ErrTokenDisabled  = "otc: token disabled"
12	ErrTokenUnknown   = "otc: token not in grc20reg"
13	ErrTokenExists    = "otc: token already whitelisted"
14	ErrTooManyTokens  = "otc: token whitelist is full"
15	ErrNoOffer        = "otc: no such offer"
16	ErrNotOpen        = "otc: offer is not open"
17	ErrNotMaker       = "otc: not maker"
18	ErrNotTaker       = "otc: offer is reserved for another taker"
19	ErrOwnOffer       = "otc: maker cannot fill own offer"
20	ErrExpired        = "otc: offer expired"
21	ErrNotAdmin       = "otc: not admin"
22	ErrFeeAboveCap    = "otc: fee above cap"
23	ErrFeeToRealm     = "otc: fee recipient cannot be the realm"
24)
source

Errors are short and stable so that tests and the frontend can match them.

const SellToken, SellGnot

1const (
2	SellToken Side = 1 // maker escrows the token, taker pays GNOT
3	SellGnot  Side = 2 // maker escrows GNOT, taker pays the token
4)
source

Functions 17

func AddToken

crossing Action
1func AddToken(cur realm, key string)
source

AddToken whitelists a token by its grc20reg key, enabled (W2).

func Cancel

crossing Action
1func Cancel(cur realm, id uint64)
source

Cancel returns the escrow to the maker. Only the maker can call it (R11), at any time, including after expiry and while paused (R10).

func CreateSellGnot

crossing Action
1func CreateSellGnot(cur realm, tokenKey string, tokenAmt int64, taker string, expiresAt int64) uint64
source

CreateSellGnot escrows the ugnot sent with the call and asks tokenAmt of the token for it. Only a direct user call may attach coins (S1). Returns the offer id.

func CreateSellToken

crossing Action
1func CreateSellToken(cur realm, tokenKey string, tokenAmt, gnotAmt int64, taker string, expiresAt int64) uint64
source

CreateSellToken escrows tokenAmt of the token and asks gnotAmt ugnot for it. The maker must first Approve this realm's address for exactly tokenAmt in the token's realm; only that amount is pulled (S4). Returns the offer id.

func Fill

crossing Action
1func Fill(cur realm, id uint64)
source

Fill takes an open offer in full (R8).

  • SellToken: attach exactly GnotAmt ugnot; direct user call only (S1).
  • SellGnot: attach nothing (S2) and first Approve this realm for exactly TokenAmt; the tokens go straight from the taker to the maker.

The fee comes off the GNOT side and goes to the fee recipient in the same call (F2, F3).

func GetConfig

Action
1func GetConfig() string
source

GetConfig returns the parameters and the whitelist as JSON.

func GetOffer

Action
1func GetOffer(id uint64) string
source

GetOffer returns one offer as JSON, public or private.

func ListByMaker

Action
1func ListByMaker(addr string, offset, limit int) string
source

ListByMaker returns every offer of one maker, private and closed ones included, newest first.

func ListOpen

Action
1func ListOpen(offset, limit int) string
source

ListOpen returns open public offers, newest first (S9).

func Render

1func Render(path string) string
source

Render serves "" (stats and the first page), "page/N" and "offer/ID".

func SetFeeBps

crossing Action
1func SetFeeBps(cur realm, bps int64)
source

SetFeeBps sets the default fee for NEW offers (F4, F5).

func SetGnomicFee

crossing Action
1func SetGnomicFee(cur realm, enabled bool, bps int64)
source

SetGnomicFee turns the reduced GNOMIC fee on or off and sets it (F6).

func SetPaused

crossing Action
1func SetPaused(cur realm, p bool)
source

SetPaused blocks or allows new offers and fills. It never blocks Cancel (A2, R10).

func SetTokenEnabled

crossing Action
1func SetTokenEnabled(cur realm, key string, enabled bool)
source

SetTokenEnabled switches new offers on a token on or off. Open offers on a disabled token can still be filled and cancelled (W2).

func TransferAdmin

crossing Action
1func TransferAdmin(cur realm, to address)
source

TransferAdmin hands the admin role to another address.

Types 3

type Offer

struct
 1type Offer struct {
 2	ID        uint64
 3	Maker     address
 4	Taker     address // empty = public (R4), set = private (R5)
 5	Side      Side
 6	TokenKey  string // grc20reg key (W3)
 7	TokenAmt  int64  // base units of the token
 8	GnotAmt   int64  // ugnot
 9	FeeBps    int64  // copied at creation, never changed (F4, I4)
10	ExpiresAt int64  // unix seconds, 0 = none (R9)
11	CreatedAt int64
12	Status    Status
13}
source

Offer is one escrowed trade: exactly one GRC20 side and one GNOT side (R1).

type Side

ident
1type Side int
source

Side says which half of the offer the maker escrowed.

Methods on Side

func String

method on Side
1func (s Side) String() string
source

type Status

ident
1type Status int
source

Status is Open until the offer is filled or cancelled. Both are terminal (R12).

Methods on Status

func String

method on Status
1func (s Status) String() string
source

Imports 9

Source Files 7