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.

mint.gno

1.99 Kb · 54 lines
 1package guardians
 2
 3import (
 4	"chain"
 5	"chain/runtime/unsafe"
 6	"time"
 7	"gno.land/p/nt/ufmt/v0"
 8)
 9
10// Mint preserves the pilot's one-button, free-first split. Each allowance is
11// checked independently and exact payment/forwarding is atomic with minting.
12func Mint(cur realm, freeQuantity, paidQuantity, allowance int, unitPrice int64, proof string) {
13	if !cur.Previous().IsUserCall() {
14		panic("guardians: only direct user calls can mint")
15	}
16	if freeQuantity < 0 || freeQuantity > 1 || paidQuantity < 0 || paidQuantity > maxPublicMintBatch {
17		panic("guardians: invalid free/paid quantity")
18	}
19	assertMintQuantity(freeQuantity + paidQuantity)
20	caller := cur.Previous().Address()
21	now := time.Now().Unix()
22	if freeQuantity > 0 {
23		if !allowlistSaleOpenAt(now) {
24			panic("guardians: allowlist sale is not active")
25		}
26		if allowance != 1 || unitPrice != 0 || saleConfig.allowlistPrice != 0 || !VerifyAllowlist(caller, allowance, unitPrice, proof) {
27			panic("guardians: invalid free-mint proof")
28		}
29		assertSaleMint(freeQuantity, AllowlistMinted(caller), saleConfig.allowlistLimit)
30	} else if allowance != 0 || unitPrice != 0 || proof != "" {
31		panic("guardians: unexpected free-mint arguments")
32	}
33	if paidQuantity > 0 {
34		if !publicSaleOpenAt(now) {
35			panic("guardians: public sale is not active")
36		}
37		assertSaleMint(paidQuantity, PublicMinted(caller), saleConfig.publicLimit)
38	}
39	required := int64(0)
40	if paidQuantity > 0 {
41		required = requiredPayment(saleConfig.publicPrice, paidQuantity)
42	}
43	sent := unsafe.OriginSend()
44	assertExactPayment(sent, required)
45	mintAllocatedTokens(caller, freeQuantity, paidQuantity)
46	if freeQuantity > 0 {
47		allowlistMintedByWallet.Set(caller.String(), AllowlistMinted(caller)+freeQuantity)
48	}
49	if paidQuantity > 0 {
50		publicMintedByWallet.Set(caller.String(), PublicMinted(caller)+paidQuantity)
51	}
52	forwardPayment(cur, sent)
53	chain.Emit("Mint", "minter", caller.String(), "free", ufmt.Sprintf("%d", freeQuantity), "paid", ufmt.Sprintf("%d", paidQuantity), "payment", ufmt.Sprintf("%d", required))
54}