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

types.gno

2.33 Kb · 82 lines
 1package otc
 2
 3// Side says which half of the offer the maker escrowed.
 4type Side int
 5
 6const (
 7	SellToken Side = 1 // maker escrows the token, taker pays GNOT
 8	SellGnot  Side = 2 // maker escrows GNOT, taker pays the token
 9)
10
11func (s Side) String() string {
12	switch s {
13	case SellToken:
14		return "SellToken"
15	case SellGnot:
16		return "SellGnot"
17	}
18	return "unknown"
19}
20
21// Status is Open until the offer is filled or cancelled. Both are terminal
22// (R12).
23type Status int
24
25const (
26	Open      Status = 1
27	Filled    Status = 2
28	Cancelled Status = 3
29)
30
31func (s Status) String() string {
32	switch s {
33	case Open:
34		return "Open"
35	case Filled:
36		return "Filled"
37	case Cancelled:
38		return "Cancelled"
39	}
40	return "unknown"
41}
42
43// Offer is one escrowed trade: exactly one GRC20 side and one GNOT side (R1).
44type Offer struct {
45	ID        uint64
46	Maker     address
47	Taker     address // empty = public (R4), set = private (R5)
48	Side      Side
49	TokenKey  string // grc20reg key (W3)
50	TokenAmt  int64  // base units of the token
51	GnotAmt   int64  // ugnot
52	FeeBps    int64  // copied at creation, never changed (F4, I4)
53	ExpiresAt int64  // unix seconds, 0 = none (R9)
54	CreatedAt int64
55	Status    Status
56}
57
58// Errors are short and stable so that tests and the frontend can match them.
59const (
60	ErrPaused         = "otc: paused"
61	ErrNotUser        = "otc: must be a direct user call"
62	ErrNoCoins        = "otc: this call takes no coins"
63	ErrBadPayment     = "otc: send exactly the required ugnot and nothing else"
64	ErrBadAmount      = "otc: amounts must be positive"
65	ErrBadExpiry      = "otc: expiry must be 0 or in the future"
66	ErrBadAddress     = "otc: invalid address"
67	ErrTakerIsMaker   = "otc: taker cannot be the maker"
68	ErrTokenNotListed = "otc: token not whitelisted"
69	ErrTokenDisabled  = "otc: token disabled"
70	ErrTokenUnknown   = "otc: token not in grc20reg"
71	ErrTokenExists    = "otc: token already whitelisted"
72	ErrTooManyTokens  = "otc: token whitelist is full"
73	ErrNoOffer        = "otc: no such offer"
74	ErrNotOpen        = "otc: offer is not open"
75	ErrNotMaker       = "otc: not maker"
76	ErrNotTaker       = "otc: offer is reserved for another taker"
77	ErrOwnOffer       = "otc: maker cannot fill own offer"
78	ErrExpired        = "otc: offer expired"
79	ErrNotAdmin       = "otc: not admin"
80	ErrFeeAboveCap    = "otc: fee above cap"
81	ErrFeeToRealm     = "otc: fee recipient cannot be the realm"
82)