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.

Playground

gnomod.toml

module = "gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia4/types/v2"
gno = "0.9"

[addpkg]
  creator = "g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06"
  height = 1236212
  max_deposit = "5000000ugnot"

types.gno

// Package types holds the value types shared by core, the minters, the
// market and the readers. Every type is plain data (no pointers into realm
// state), so passing one across a realm boundary hands over a copy and
// never a capability.
package types

import (
	"errors"
)

// State is a collection's lifecycle (design §4.1):
//
//	Draft -> Scheduled -> Minting -> Closed -> Final
//
// Scheduled->Minting and Minting->Closed happen by block height; core
// reports the effective state and materializes it on the next write.
type State int

const (
	StateDraft State = iota
	StateScheduled
	StateMinting
	StateClosed
	StateFinal
)

func (s State) String() string {
	switch s {
	case StateDraft:
		return "draft"
	case StateScheduled:
		return "scheduled"
	case StateMinting:
		return "minting"
	case StateClosed:
		return "closed"
	case StateFinal:
		return "final"
	}
	return "unknown"
}

// MaxUnitPrice caps every price (ugnot) so price*count and fee math stay
// far from int64 overflow: 1e15 ugnot = 1e9 GNOT.
const MaxUnitPrice = 1_000_000_000_000_000

// Payee receives Bps/10000 of a payment.
type Payee struct {
	Addr address
	Bps  int64
}

// CollectionSpec is what a minter asks core to create. Payees travel as
// "addr:bps,…" strings and are parsed by core, so core never stores a slice
// allocated by another realm.
type CollectionSpec struct {
	Name, Symbol, Description string
	EngineID, Params          string
	MaxSupply, RoyaltyBps     int64
	PrimaryPayees             string
	RoyaltyPayees             string
	// Soulbound makes the collection non-transferable, fixed at creation:
	// its tokens can never be transferred or approved (also not after
	// Final), the market never lists them, the owner may still burn one
	// after Final, and royaltyBps must be 0 (no secondary sales).
	Soulbound bool
}

// BeaconCommitted is the platform's commit-reveal beacon as a collection's
// randomness source (LaunchSpec.BeaconSource "" means the same).
const BeaconCommitted = "committed"

// Launch modes (LaunchSpec.Mode, CollectionInfo.Mode).
//
// ModeReveal ("") is the fair commit–reveal launch: the token map is fixed
// by the creator's secret, the beacon's (or a randomness provider's) value
// and the mint entropy, and stays hidden until Final.
//
// ModeOpen ("open") has no secrets at all: the salt is public from Launch
// (sha256("art|open|v1|" + chainId + "|" + cid)), so anyone can compute
// every token's art before minting. For badges, editions, event drops and
// 1/1s. An open collection has no commitment, no beacon or provider, no
// creator reserve, is never a fair launch (badge "open"), and its tokens
// still stay locked until Final, which anyone may call once the sale ended
// or sold out.
const (
	ModeReveal = ""
	ModeOpen   = "open"
)

// LaunchSpec freezes a collection's sale window and commitments (I-6).
//
// BeaconSource picks the second entropy source when UseBeacon is set:
// "" or BeaconCommitted for the platform beacon's commit-reveal, or the
// package path of an admin-approved randomness provider realm (e.g. a drand
// relay); it must be "" without UseBeacon.
//
// Mode is ModeReveal ("") or ModeOpen. An open launch needs RevealWindow 0,
// CreatorCommit "", UseBeacon false and BeaconSource "".
type LaunchSpec struct {
	StartHeight, EndHeight int64
	RevealWindow           int64 // blocks after close; core bounds it (0 in open mode)
	CreatorCommit          string
	UseBeacon              bool
	BeaconSource           string
	Mode                   string
}

// CollectionInfo is core's typed read model for other realms.
type CollectionInfo struct {
	ID, Name, Symbol, Description string
	Creator                       address
	Minter, EngineID, Params      string
	State                         State
	MaxSupply, Minted, Reserved   int64
	StartHeight, EndHeight        int64
	RevealDeadline                int64 // 0 before Launch
	RoyaltyBps                    int64
	Badge                         string   // provenance badge once Final
	Mode                          string   // ModeReveal ("") or ModeOpen; "" before Launch
	TraitTypes                    []string // the collection's trait types (a copy)
	Salt                          string   // final salt (hex); "" before Final
	Soulbound                     bool     // non-transferable (CollectionSpec.Soulbound)
}

// Fees are the protocol's fee parameters; core enforces hard caps.
type Fees struct {
	CreateFee    int64 // ugnot per collection
	PrimaryBps   int64 // of every primary sale
	SecondaryBps int64 // of every market sale
	Treasury     address
	EngineCapBps int64 // platform cap on engine-author fees (<= engine.MaxFeeBps)
}

// Phase kinds.
const (
	PhaseAllow  = "allow"
	PhasePublic = "public"
)

// Phase is one sale window. A fixed price has StartPrice == FloorPrice and
// no steps; a Dutch auction starts at StartPrice and drops StepAmount every
// StepBlocks until FloorPrice (design §4.5). WalletCap counts lifetime
// mints of the collection (I-9); 0 means no cap.
type Phase struct {
	Kind, Set              string
	StartHeight, EndHeight int64
	StartPrice, FloorPrice int64
	StepBlocks, StepAmount int64
	WalletCap              int64
}

// Validate checks a phase in isolation; the minter checks the set grammar
// and how phases relate to each other.
func (p Phase) Validate() error {
	switch p.Kind {
	case PhasePublic:
		if p.Set != "" {
			return errors.New("a public phase has no allowlist set")
		}
	case PhaseAllow:
		if p.Set == "" {
			return errors.New("an allow phase needs a set")
		}
	default:
		return errors.New("phase kind must be allow or public")
	}
	if p.StartHeight <= 0 || p.EndHeight < p.StartHeight {
		return errors.New("phase heights must satisfy 0 < start <= end")
	}
	if p.FloorPrice < 0 || p.StartPrice < p.FloorPrice || p.StartPrice > MaxUnitPrice {
		return errors.New("prices must satisfy 0 <= floor <= start <= MaxUnitPrice")
	}
	if p.StartPrice == p.FloorPrice {
		if p.StepBlocks != 0 || p.StepAmount != 0 {
			return errors.New("a fixed-price phase has no steps")
		}
	} else if p.StepBlocks <= 0 || p.StepAmount <= 0 {
		return errors.New("a Dutch phase needs positive stepBlocks and stepAmount")
	}
	if p.WalletCap < 0 {
		return errors.New("walletCap must be >= 0")
	}
	return nil
}

// Covers reports whether height h is inside the phase window.
func (p Phase) Covers(h int64) bool {
	return h >= p.StartHeight && h <= p.EndHeight
}

// PriceAt is the unit price at height h:
//
//	max(floor, start - floor((h-startH)/stepBlocks) * stepAmount)
//
// computed so that no intermediate value can overflow.
func (p Phase) PriceAt(h int64) int64 {
	if p.StartPrice == p.FloorPrice || h <= p.StartHeight {
		return p.StartPrice
	}
	steps := (h - p.StartHeight) / p.StepBlocks
	if steps > (p.StartPrice-p.FloorPrice)/p.StepAmount {
		return p.FloorPrice
	}
	price := p.StartPrice - steps*p.StepAmount
	if price < p.FloorPrice {
		return p.FloorPrice
	}
	return price
}