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.

v2 source realm

Package markets is realm v2 of 67: fully collateralized markets on Gno with a service fee, two-sided expiring quotes,...

Overview

Package markets is realm v2 of 67: fully collateralized markets on Gno with a service fee, two-sided expiring quotes, limits, pauses, a resolution window, void refunds and an abandonment exit. It does not discover outcomes: each market trusts its pinned oracle, and a guardian can cancel a proposal for 24 hours before anyone can make it final.

Money only leaves through Claim (to the holder who calls) and WithdrawSurplus (to the market's fixed treasury, after it is final). Nothing can pause them.

Constants 2

const scale, maxInt64, MaxFeePpm, MinPricePpm, MaxPricePpm, DisputeWindow, AbandonAfter, minQuoteTTL, maxQuoteTTL, maxMinSpread, maxHistory

 1const (
 2	scale    int64 = 1000000
 3	maxInt64 int64 = 9223372036854775807
 4
 5	// MaxFeePpm caps every market's service fee rate θ at 0.07. A rate is fixed
 6	// when a market is listed and can never change.
 7	MaxFeePpm int64 = 70000
 8	// Each side's price stays inside 0.03 to 0.97; outside it the quoter pauses.
 9	MinPricePpm int64 = 30000
10	MaxPricePpm int64 = 970000
11	// DisputeWindow is how long a proposed outcome waits before anyone can make
12	// it final; the guardian can cancel it in that time.
13	DisputeWindow int64 = 24 * 60 * 60
14	// AbandonAfter: if no outcome is final this long after trading ends, anyone
15	// can void the market and every holder takes a refund.
16	AbandonAfter int64 = 60 * 24 * 60 * 60
17
18	minQuoteTTL  int64 = 5 * 60
19	maxQuoteTTL  int64 = 7 * 24 * 60 * 60
20	maxMinSpread int64 = 100000
21	maxHistory         = 96
22)
source

const StateOpen, StatePaused, StateProposed, StateFinal

1const (
2	StateOpen     = "open"
3	StatePaused   = "paused"
4	StateProposed = "proposed"
5	StateFinal    = "final"
6)
source

Market states. A market moves between open and paused, from either to proposed, and from proposed to final. A cancelled proposal returns it to paused; abandonment takes an open or paused market to final (Void).

Functions 34

func AcceptRole

crossing Action
1func AcceptRole(cur realm, role string)
source

AcceptRole completes a handover started by ProposeRole.

func BindingHash

Action
1func BindingHash(question, rules string) string
source

Hash UTF-8 length-framed text, shared exactly with the backend source binding.

func Buy

crossing Action
1func Buy(cur realm, id, outcome string, microShares, expectedPricePpm int64)
source

Buy creates a position after exact payment of cost plus fee, within the limits, and only while the market's escrow covers its larger side. expectedPricePpm is the price of the chosen outcome that the buyer reviewed. A buyer may sign with a session key: the position is always the account's.

func CancelProposal

crossing Action
1func CancelProposal(cur realm, id string)
source

CancelProposal lets the guardian reject a proposed outcome within the dispute window. The market returns to paused; the oracle can propose again.

func Claim

crossing Action
1func Claim(cur realm, id string) int64
source

Claim settles the caller's position in a final market and deletes it. On Yes or No each winning micro-share pays one ugnot; on Void the holder gets back the cost and the fee they paid. A losing position closes with zero.

func CreateMarket

crossing Action
1func CreateMarket(cur realm, id, question, rules, conditionID, yesTokenID, noTokenID, yesLabel, noLabel string, tradingEndsAt, yesPricePpm, noPricePpm, feePpm int64, oracle, treasury address, topic string)
source

CreateMarket freezes every field used to match an external result, the fee rate, the oracle and the treasury. Nothing but the quote and the limits can change later. The administrator chooses the terms; the lister must use the listing terms.

func Fee

Action
1func Fee(microShares, pricePpm, feePpm int64) int64
source

Fee is the service fee in ugnot for microShares at pricePpm and rate feePpm: θ × shares × price × (1 − price) GNOT, rounded up to the ugnot. It is computed exactly as ceil(microShares × feePpm × price × (10^6 − price) / 10^18).

func Finalize

crossing Action
1func Finalize(cur realm, id string)
source

Finalize makes a proposed outcome final once the dispute window has passed. Anyone can call it.

func Fund

crossing Action
1func Fund(cur realm, id string)
source

Fund adds reserve capital to one market. It backs that market's sales and returns to the market's treasury only after the market is final.

func MarketJSON

Action
1func MarketJSON(id string) string
source

MarketJSON returns one market with its quote history.

func MarketsJSON

Action
1func MarketsJSON() string
source

MarketsJSON returns every market in creation order as one JSON array.

func Pause

crossing Action
1func Pause(cur realm, id string)
source

Pause stops new purchases in one market, or with id "" in every market. The quoter (also with a session key), the guardian and the administrator can pause; only the administrator resumes. Claims are never paused.

func PositionJSON

Action
1func PositionJSON(id string, owner address) string
source

PositionJSON returns one open position; an empty one if the owner holds nothing there or has claimed.

func PositionsJSON

Action
1func PositionsJSON(owner address) string
source

PositionsJSON returns the owner's open positions in market creation order. Claimed positions are gone; their record is in the Claimed events.

func ProposeOutcome

crossing Action
1func ProposeOutcome(cur realm, id, conditionID, rulesHash, yesTokenID, noTokenID, outcome, evidenceHash string)
source

ProposeOutcome records the oracle's Yes, No or Void with the market's entire source binding and an evidence hash. Trading stops at once. After the dispute window anyone can make it final; within it the guardian can cancel. A Polymarket 50-50 result is proposed as Void.

func ProposeRole

crossing Action
1func ProposeRole(cur realm, role string, next address)
source

ProposeRole starts a two-step handover of "admin", "quoter", "guardian" or "lister". The proposed address accepts from its own direct call, so a mistyped address cannot take a role.

func Quote

Action
1func Quote(id, outcome string, microShares int64) (costUgnot, feeUgnot int64)
source

Quote returns the exact cost and fee for buying microShares of an outcome at the current price. A buyer sends cost + fee.

func Render

1func Render(path string) string
source

Render draws the realm's public page on gnoweb: the market list at the root and one page per market at ":<id>". It is informational; the app reads JSON.

func Resume

crossing Action
1func Resume(cur realm, id string)
source

Resume reopens one paused market, or with id "" lifts the realm-wide pause.

func RevokeRole

crossing Action
1func RevokeRole(cur realm, role string)
source

RevokeRole empties the quoter, guardian or lister role at once, for a lost or stolen key. The administrator role can only be handed over.

func SetLimits

crossing Action
1func SetLimits(cur realm, id string, maxTradeMicroShares, maxHolderMicroShares, maxSideMicroShares int64)
source

SetLimits changes one market's purchase limits, or with id "" the limits new markets start with.

func SetListingTerms

crossing Action
1func SetListingTerms(cur realm, oracle, treasury address, feePpm int64)
source

SetListingTerms fixes the oracle, treasury and fee rate every market listed by the lister must carry. A lister key can then only add markets on these terms; it can never choose who settles them or where their surplus goes.

func SetQuote

crossing Action
1func SetQuote(cur realm, id string, yesPricePpm, noPricePpm, expectedVersion int64)
source

SetQuote publishes both prices while trading is open or paused. The quoter may sign it with a session key. expectedVersion refuses a quote made from a stale view. The same prices again only renew the quote's time, so the keeper can keep an unchanged quote from expiring without a new version.

func SetSettings

crossing Action
1func SetSettings(cur realm, quoteTTLSeconds, minimumSpreadPpm, maxExposureMicroShares int64)
source

SetSettings changes the quote lifetime, the minimum spread and the realm-wide exposure cap. They apply to new quotes and purchases only.

func Surplus

Action
1func Surplus(id string) (collateralUgnot, feesUgnot int64)
source

Surplus returns what WithdrawSurplus would send now: collateral and fees. It is zero for a market that is not final.

func VoidAbandoned

crossing Action
1func VoidAbandoned(cur realm, id string)
source

VoidAbandoned voids a market that is still unsettled AbandonAfter trading ended. Anyone can call it; every holder then takes back what they paid.

func WithdrawSurplus

crossing Action
1func WithdrawSurplus(cur realm, id string) int64
source

WithdrawSurplus sends what a final market no longer owes anyone to its fixed treasury: the escrow above unclaimed payouts or refunds, and on Yes or No the fees. Anyone can call it; the destination was fixed at listing.

func QuoteHistory

Action
1func QuoteHistory(id string) []QuotePoint
source

QuoteHistory returns a detached copy of the published quotes.

Types 4

type Limits

struct
1type Limits struct {
2	MaxTradeMicroShares  int64 `json:"maxTradeMicroShares"`
3	MaxHolderMicroShares int64 `json:"maxHolderMicroShares"`
4	MaxSideMicroShares   int64 `json:"maxSideMicroShares"`
5}
source

Limits bound new purchases. They never affect claims.

type Market

struct
 1type Market struct {
 2	ID          string `json:"id"`
 3	Question    string `json:"question"`
 4	Rules       string `json:"rules"`
 5	RulesHash   string `json:"rulesHash"`
 6	ConditionID string `json:"conditionId"`
 7	YesTokenID  string `json:"yesTokenId"`
 8	NoTokenID   string `json:"noTokenId"`
 9	// The outcomes' names as Polymarket shows them, in token order: "Yes" and
10	// "No", or two teams. Yes and No below always mean the first and second token.
11	YesLabel  string  `json:"yesLabel"`
12	NoLabel   string  `json:"noLabel"`
13	Oracle    address `json:"oracle"`
14	Treasury  address `json:"treasury"`
15	Topic     string  `json:"topic"` // the 67 topic it is shown under, fixed at listing
16	FeePpm    int64   `json:"feePpm"`
17	CreatedAt int64   `json:"createdAt"`
18	// TradingEndsAt is set at listing, before the source event.
19	TradingEndsAt int64 `json:"tradingEndsAt"`
20	AbandonAt     int64 `json:"abandonAt"`
21
22	YesPricePpm  int64 `json:"yesPricePpm"`
23	NoPricePpm   int64 `json:"noPricePpm"`
24	QuoteVersion int64 `json:"quoteVersion"`
25	QuotedAt     int64 `json:"quotedAt"`
26
27	State        string `json:"state"`
28	Outcome      string `json:"outcome"` // proposed or final: Yes, No or Void
29	EvidenceHash string `json:"evidenceHash"`
30	ProposedAt   int64  `json:"proposedAt"`
31	FinalizedAt  int64  `json:"finalizedAt"`
32
33	// EscrowUgnot is the collateral: reserve plus purchase costs, less payouts,
34	// refunds and withdrawn surplus. FeesUgnot is held apart from it.
35	EscrowUgnot        int64 `json:"escrowUgnot"`
36	FeesUgnot          int64 `json:"feesUgnot"`
37	ReserveUgnot       int64 `json:"reserveUgnot"`
38	CostUgnot          int64 `json:"costUgnot"`
39	FeesCollectedUgnot int64 `json:"feesCollectedUgnot"`
40	YesMicroShares     int64 `json:"yesMicroShares"`
41	NoMicroShares      int64 `json:"noMicroShares"`
42	PaidUgnot          int64 `json:"paidUgnot"`
43	RefundedCostUgnot  int64 `json:"refundedCostUgnot"`
44	RefundedFeesUgnot  int64 `json:"refundedFeesUgnot"`
45	WithdrawnUgnot     int64 `json:"withdrawnUgnot"`
46
47	MaxTradeMicroShares  int64 `json:"maxTradeMicroShares"`
48	MaxHolderMicroShares int64 `json:"maxHolderMicroShares"`
49	MaxSideMicroShares   int64 `json:"maxSideMicroShares"`
50
51	Holders     int64 `json:"holders"` // positions not yet settled
52	VolumeUgnot int64 `json:"volumeUgnot"`
53	Trades      int64 `json:"trades"`
54}
source

All amounts are integer ugnot. One million micro-shares is one share; a winning micro-share pays one ugnot (one whole share pays one GNOT).

type Position

struct
1type Position struct {
2	YesMicroShares int64 `json:"yesMicroShares"`
3	NoMicroShares  int64 `json:"noMicroShares"`
4	SpentUgnot     int64 `json:"spentUgnot"`
5	FeeUgnot       int64 `json:"feeUgnot"`
6}
source

Position is an open holding. It is deleted when its holder claims, so the storage it used is released; the Claimed event keeps the record.

type QuotePoint

struct
1type QuotePoint struct {
2	At          int64 `json:"at"`
3	YesPricePpm int64 `json:"yesPricePpm"`
4	NoPricePpm  int64 `json:"noPricePpm"`
5	Version     int64 `json:"version"`
6}
source

QuotePoint records one published quote, in block-time order.

Dependencies

Source Files 4