Skip to content Search Apps Documentation Source Content Run Reset Eval Playground 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.

rooms source realm

Package rooms is the on-chain trade window.

Overview

Package rooms is the on-chain trade window.

Two parties share a room. Each one puts assets on their own side: native coins (GNOT and any other bank denom), GRC20 tokens from the registry at gno.land/r/nt/grc20reg/v0, and GRC721 NFTs from collections registered with this realm (see RegisterCollection). The realm holds the deposits.

Every change to the room raises its version. A party locks the room by naming the exact version they reviewed, so a lock can never apply to contents the party has not seen. When both sides hold a lock on the current version, the second lock swaps everything in the same transaction: the maker's side goes to the taker and the taker's side goes to the maker.

Until that moment each party can withdraw their own deposits, and either party can cancel the room, which returns every deposit to its owner. An expired room can no longer settle; its deposits stay withdrawable, and anyone may cancel it to send them home.

A maker can also turn a room into an offer (see Offer): their side plus an exact list of what they want in return. The first account allowed to take the other seat that puts in exactly that list completes the trade in one transaction (see Fill).

On settlement the realm keeps a service fee on coins and tokens (see fee.gno); NFTs, withdrawals and cancellations pay nothing.

Constants 4

const DefaultFeeBps, MaxFeeBps

1const (
2	// DefaultFeeBps is 0.5%.
3	DefaultFeeBps = 50
4	// MaxFeeBps caps the fee at 1%, whatever the admin sets.
5	MaxFeeBps = 100
6)
source

const StatusOpen, StatusSettled, StatusCancelled, statusFilling, KindCoin, KindToken, KindNFT, MaxAssetsPerSide, DefaultTTLMinutes, MinTTLMinutes, MaxTTLMinutes

 1const (
 2	StatusOpen      = "open"
 3	StatusSettled   = "settled"
 4	StatusCancelled = "cancelled"
 5
 6	// statusFilling holds a room for the length of one Fill, so nothing an
 7	// asset's own code runs during the transfers can change it.
 8	statusFilling = "filling"
 9
10	KindCoin  = "coin"
11	KindToken = "token"
12	KindNFT   = "nft"
13
14	// MaxAssetsPerSide bounds the work a settlement or refund can do.
15	MaxAssetsPerSide = 8
16
17	DefaultTTLMinutes = 24 * 60
18	MinTTLMinutes     = 10
19	MaxTTLMinutes     = 7 * 24 * 60
20)
source

const MaxTokenIDLen

1const MaxTokenIDLen = 64
source

MaxTokenIDLen bounds what a room stores per NFT.

const VerifyDelay

1const VerifyDelay = 24 * 60 * 60 // seconds
source

VerifyDelay is how long a new verification waits before it counts.

Functions 40

func AcceptAdmin

crossing Action
1func AcceptAdmin(cur realm)
source

AcceptAdmin completes a handover started with ProposeAdmin.

func Address

Action
1func Address() string
source

Address returns this realm's address: the spender to approve before DepositToken, and the account that holds deposits.

func Admin

Action
1func Admin() string
source

Admin returns the current admin address, or "" when there is none.

func BalancesJSON

Action
1func BalancesJSON(owner string, offset, limit int) string
source

BalancesJSON lists the registered GRC20 tokens that owner holds, with the balance and the allowance to this realm: a wallet's inventory in one query. A page covers limit registry entries (at most 50); read on while "more" is true.

func Cancel

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

Cancel closes an open room and returns every deposit to its owner. Either party may cancel at any time before settlement; once the room has expired, anyone may cancel it.

func CollectionsJSON

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

CollectionsJSON lists the GRC721 collections registered with rooms.

func DepositCoins

crossing Action
1func DepositCoins(cur realm, roomID uint64)
source

DepositCoins adds the coins sent with this call to the caller's side. It must be called directly from the depositing account (maketx call or a wallet MsgCall), because only then are the sent coins guaranteed to have reached this realm.

func DepositNFT

crossing Action
1func DepositNFT(cur realm, roomID uint64, collectionKey string, tokenID string)
source

DepositNFT moves one NFT of a registered collection from the caller to this realm and adds it to the caller's side. The caller must first approve this realm's address (see Address) for that token id, in the collection's realm.

func DepositToken

crossing Action
1func DepositToken(cur realm, roomID uint64, tokenKey string, amount int64)
source

DepositToken moves amount of a registered GRC20 token from the caller to this realm and adds it to the caller's side. The caller must first approve this realm's address (see Address) for at least amount.

func FeeBps

Action
1func FeeBps() uint64
source

FeeBps returns the rate a room opened now would get.

func Fill

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

Fill completes an offer: the caller takes the other seat, puts in exactly what the offer wants, and the room settles in this call. version is the version the caller reviewed. Coins in the offer must be attached to this call, from the caller's own account.

func IsVerified

Action
1func IsVerified(kind, denom string) bool
source

IsVerified reports whether an asset counts as verified now. denom is a coin denom, a registry key, or a collection key (with or without "#token id").

func Join

crossing Action
1func Join(cur realm, roomID uint64)
source

Join takes the open taker seat of a room.

func Lock

crossing Action
1func Lock(cur realm, roomID uint64, version uint64) string
source

Lock records that the caller agrees to swap the room exactly as it is at version. It fails if the room has changed since. When the other side already holds a lock on the same version, this call settles the room and returns "settled"; otherwise it returns "locked".

func NFTJSON

Action
1func NFTJSON(collectionKey string, tokenID string) string
source

NFTJSON describes one NFT of a registered collection: who owns it, and whether this realm is approved to move it. null when the collection is not registered or the token does not exist.

func Offer

crossing Action
1func Offer(cur realm, roomID uint64, version uint64, want string) uint64
source

Offer turns the room into an offer for exactly want, on the room as it is at version. want lists one asset per line, at most 8:

Example
1coin <amount> <denom>
2token <amount> <grc20reg key>
3nft 1 <collection key>#<token id>

Amounts are in base units. Returns the new version, which the taker fills.

func Open

crossing Action
1func Open(cur realm, counterparty string, ttlMinutes int) uint64
source

Open creates a room with the caller as maker and returns its id. The room takes only verified assets (see Verify). counterparty is the taker's address, or "" to leave the seat open for the first account that calls Join. ttlMinutes is how long the room can settle; 0 means 24 hours, and the allowed range is 10 minutes to 7 days.

func OpenMarket

crossing Action
1func OpenMarket(cur realm, counterparty string, ttlMinutes int) uint64
source

OpenMarket is Open for a room that takes any registered asset, verified or not. Both parties trade unverified assets at their own risk; the app says so in every view of such a room.

func OwnedJSON

Action
1func OwnedJSON(owner string, offset, limit int) string
source

OwnedJSON lists the NFTs owner holds in registered collections that can be listed (those registered with their enumerable view), at most 20 per collection, and whether this realm is approved for each. A page covers limit collections; read on while "more" is true.

func ProposeAdmin

crossing Action
1func ProposeAdmin(cur realm, next string)
source

ProposeAdmin names the next admin; the change happens when that address calls AcceptAdmin. Pass "" to withdraw a proposal.

func RegisterCollection

crossing Action
1func RegisterCollection(cur realm, token *grc721.Token, list *enumerable.Enumerable) string
source

RegisterCollection makes a GRC721 collection tradable in rooms and returns its key. Only the collection's own realm can register it, once; list is its enumerable view, or nil. A collection's realm also lets owners approve this realm (see Address) for one token id, as its own Approve does; DepositNFT spends that approval.

Example
1key := rooms.RegisterCollection(cross(cur), Token, List)

func Render

1func Render(path string) string
source

Render shows the realm on gnoweb: the home page lists recent rooms, and room/<id> shows one room. Every value that comes from a caller goes through sanitize before it reaches the markdown.

func RoomJSON

Action
1func RoomJSON(id uint64) string
source

RoomJSON returns one room, or null when it does not exist.

func RoomsOfJSON

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

RoomsOfJSON lists the rooms where addr is maker or taker, newest first.

func SetFee

crossing Action
1func SetFee(cur realm, bps uint64)
source

SetFee sets the rate for rooms opened from now on, in basis points (50 is 0.5%), at most MaxFeeBps. Rooms already open keep their rate.

func SetPaused

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

SetPaused stops or resumes new activity.

func SetTreasury

crossing Action
1func SetTreasury(cur realm, to string)
source

SetTreasury names the account that receives fees from now on.

func StatsJSON

Action
1func StatsJSON() string
source

StatsJSON returns counters and the settled volume per asset.

func TokenJSON

Action
1func TokenJSON(key string, owner string) string
source

TokenJSON describes one registered token and, when owner is given, the owner's balance and current allowance to this realm.

func TokensJSON

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

TokensJSON lists GRC20 tokens from the registry that rooms accept.

func Treasury

Action
1func Treasury() string
source

Treasury returns the account that receives fees, or "" when fees are off.

func Unlock

crossing Action
1func Unlock(cur realm, roomID uint64)
source

Unlock withdraws the caller's lock on the current version.

func Unverify

crossing Action
1func Unverify(cur realm, kind, key, reason string)
source

Unverify removes a verification at once. Ordinary rooms stop accepting the asset, and those that hold it can no longer settle; deposits stay withdrawable. reason is public.

func VerifiedJSON

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

VerifiedJSON lists verifications, counted or still waiting, with their public reasons.

func Verify

crossing Action
1func Verify(cur realm, kind, key, reason string)
source

Verify makes a coin denom, a registered GRC20 token or a registered NFT collection acceptable in ordinary rooms from VerifyDelay from now. kind is coin, token or nft; key is the denom, the registry key or the collection key. reason is public: say why this asset is safe to trade.

func WithdrawCoins

crossing Action
1func WithdrawCoins(cur realm, roomID uint64, denom string, amount int64)
source

WithdrawCoins returns amount of denom from the caller's side to the caller. It works while the room is open, also after it has expired or while the realm is paused.

func WithdrawNFT

crossing Action
1func WithdrawNFT(cur realm, roomID uint64, collectionKey string, tokenID string)
source

WithdrawNFT returns one NFT from the caller's side to the caller. Same rules as WithdrawCoins: it works while the room is open, also after it has expired or while the realm is paused.

func WithdrawToken

crossing Action
1func WithdrawToken(cur realm, roomID uint64, tokenKey string, amount int64)
source

WithdrawToken returns amount of a GRC20 token from the caller's side to the caller. Same rules as WithdrawCoins.

Dependencies

Source Files 10