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.82 Kb · 50 lines
 1package guardians_pilot_v1
 2
 3import (
 4	"chain"
 5	"chain/runtime/unsafe"
 6	"gno.land/p/nt/ufmt/v0"
 7)
 8
 9// Mint applies an explicit free/paid split in one atomic direct-user call.
10// The caller reviews the split and payment in Adena before signing.
11func Mint(cur realm, freeQuantity, paidQuantity, allowance int, unitPrice int64, proof string) {
12	if !cur.Previous().IsUserCall() {
13		panic("guardians: only direct user calls can mint")
14	}
15	if SalePhase() != salePhaseOpen {
16		panic("guardians: sale is not active")
17	}
18	if freeQuantity < 0 || freeQuantity > 1 || paidQuantity < 0 || paidQuantity > 3 {
19		panic("guardians: invalid free/paid quantity")
20	}
21	quantity := freeQuantity + paidQuantity
22	assertMintQuantity(quantity)
23	caller := cur.Previous().Address()
24	if freeQuantity > 0 {
25		if allowance != 1 || unitPrice != 0 || !VerifyAllowlist(caller, allowance, unitPrice, proof) {
26			panic("guardians: invalid free-mint proof")
27		}
28		assertSaleMint(freeQuantity, AllowlistMinted(caller), saleConfig.allowlistLimit)
29	} else if allowance != 0 || unitPrice != 0 || proof != "" {
30		panic("guardians: unexpected free-mint arguments")
31	}
32	if paidQuantity > 0 {
33		assertSaleMint(paidQuantity, PublicMinted(caller), saleConfig.publicLimit)
34	}
35	required := int64(0)
36	if paidQuantity > 0 {
37		required = requiredPayment(saleConfig.publicPrice, paidQuantity)
38	}
39	sent := unsafe.OriginSend()
40	assertExactPayment(sent, required)
41	mintTokens(caller, quantity)
42	if freeQuantity > 0 {
43		allowlistMintedByWallet.Set(caller.String(), AllowlistMinted(caller)+freeQuantity)
44	}
45	if paidQuantity > 0 {
46		publicMintedByWallet.Set(caller.String(), PublicMinted(caller)+paidQuantity)
47	}
48	forwardPayment(cur, sent)
49	chain.Emit("PilotMint", "minter", caller.String(), "free", ufmt.Sprintf("%d", freeQuantity), "paid", ufmt.Sprintf("%d", paidQuantity), "payment", ufmt.Sprintf("%d", required))
50}