← Back to Realms

Realm

gno.land/r/g1t2kg2vtr3fukg43eujkn6x53gfdyakhngt4sfd/gnofly/nfts/market/bazaar/v1/gnofly

Overview

Realm Path
gno.land/r/g1t2kg2vtr3fukg43eujkn6x53gfdyakhngt4sfd/gnofly/nfts/market/bazaar/v1/gnofly
Exported Functions
19
State Entries
35
Source Files
7
Total Package Entries
71

Exported Functions

19 exported functions

State

35 state entries

Source Code

FILES
bazaar.gno
go
1package gnofly
2
3import (
4	"strconv"
5
6	"chain"
7
8	bazaar "gno.land/r/g1n4pl5uc4yt5r96m9w6fmdznx3x0jyg8l6arhmt/bazaar/bazaarv5"
9
10	"gno.land/r/g1t2kg2vtr3fukg43eujkn6x53gfdyakhngt4sfd/gnofly/nfts/planes"
11)
12
13// Bazaar (bazaar.gnomi.fun) lists the collections registered on its factory,
14// bazaarv5. This realm registers itself there with Init: the factory takes
15// its path as the collection (slug: the last element, "gnofly") and sends the
16// site's List, Buy and Cancel here. Its fee on a sale is read from the factory
17// at each Buy.
18
19const (
20	// What Bazaar shows for the collection: the planes realm's.
21	collectionName   = "gnofly planes"
22	collectionSymbol = "PLANE"
23	collectionCover  = "https://gnofly.xyz/nft/collections/planes/777.png"
24	collectionSupply = 777
25	// The planes realm's mint price, 77 GNOT: shown by Bazaar, never charged
26	// here (planes are minted on the planes realm).
27	collectionMintPrice = int64(77_000_000)
28)
29
30// registered is set once Init has registered this realm on Bazaar's factory:
31// only then does it report its minted count there.
32var registered bool
33
34// Init registers this realm on Bazaar's factory. The factory requires the
35// slug "gnofly" reserved first, with Reserve, by the wallet calling Init; it
36// must be an admin of the game realm here too: the gnofly wallet. Once only.
37func Init(cur realm) {
38	userOf(0, cur)
39	assertAdmin(0, cur)
40	if registered {
41		panic(errRegistered)
42	}
43	registered = true
44	bazaar.Register(cross(cur), collectionName, collectionSymbol, collectionCover,
45		collectionSupply, collectionMintPrice, planes.RoyaltyBps())
46	noteMinted(0, cur)
47	chain.Emit("Registered", "slug", slug)
48}
49
50// noteMinted reports the planes minted so far to Bazaar's factory, which
51// shows the count. Nothing before Init: the factory does not know this realm.
52func noteMinted(_ int, rlm realm) {
53	if registered {
54		bazaar.NoteMinted(cross(rlm), Minted())
55	}
56}
57
58// bazaarFee is what Bazaar takes on a sale at price between seller and
59// buyer: its ProtocolBps less the better holder discount of the two, never
60// below zero. Of it, GenesisShareBps goes to its genesis sink, the rest to its
61// protocol sink. All read from the factory now: its admin sets them.
62func bazaarFee(price int64, seller, buyer address) (genesis, protocol int64) {
63	discount := bazaar.HolderDiscount(seller.String())
64	if d := bazaar.HolderDiscount(buyer.String()); d > discount {
65		discount = d
66	}
67	bps := bazaar.ProtocolBps() - discount
68	if bps <= 0 {
69		return 0, 0
70	}
71	fee := price * bps / 10_000
72	genesis = fee * bazaar.GenesisShareBps() / 10_000
73	return genesis, fee - genesis
74}
75
76// Registered reports whether Init has registered this realm on Bazaar.
77func Registered() bool { return registered }
78
79// itoa64 is strconv.FormatInt in base 10.
80func itoa64(n int64) string { return strconv.FormatInt(n, 10) }
81

Raw Package Data

Raw JSON data