Smart Contract

FlunksWhitelistMinter

A.807c3d470888cc48.FlunksWhitelistMinter

Deployed

1w ago
Feb 19, 2026, 10:24:09 AM UTC

Dependents

0 imports
1// SPDX-License-Identifier: UNLICENSED
2
3import Flunks from 0x807c3d470888cc48
4import FungibleToken from 0xf233dcee88fe0abe
5import NonFungibleToken from 0x1d7e57aa55817448
6import DapperUtilityCoin from 0xead892083b3e2c6c
7
8pub contract FlunksWhitelistMinter {
9
10  pub event ContractInitialized()
11
12  pub let AdminStoragePath: StoragePath
13  pub var privateSalePrice: UFix64
14  pub var publicSalePrice: UFix64
15
16  access(self) var whitelistedAccounts: {Address: UInt64}
17
18  pub fun mintPrivateNFTWithDUC(buyer: Address, setID: UInt64, paymentVault: @FungibleToken.Vault, merchantAccount: Address, numberOfTokens: UInt64) {
19    pre {
20      FlunksWhitelistMinter.whitelistedAccounts[buyer]! >= 1:
21        "Requesting account is not whitelisted"
22      numberOfTokens <= 2:
23        "purchaseAmount too large"
24      FlunksWhitelistMinter.whitelistedAccounts[buyer]! >= numberOfTokens:
25        "purchaseAmount exeeds allowed whitelist spots"
26      paymentVault.balance >= UFix64(numberOfTokens) * FlunksWhitelistMinter.privateSalePrice:
27        "Insufficient payment amount."
28      paymentVault.getType() == Type<@DapperUtilityCoin.Vault>():
29        "payment type not DapperUtilityCoin.Vault."
30    }
31
32    let admin = self.account.borrow<&Flunks.Admin>(from: Flunks.AdminStoragePath)
33      ?? panic("Could not borrow a reference to the Flunks Admin")
34
35    let set = admin.borrowSet(setID: setID)
36    // Check set availability
37    if (set.getAvailableTemplateIDs().length == 0) { panic("set is empty") }
38    // Check set eligibility
39    if (set.locked) { panic("Set is locked") }
40    if (set.isPublic) { panic("Cannot mint public set with mintPrivateNFTWithDUC") }
41
42    // Get DUC receiver reference of Flunks merchant account
43    let merchantDUCReceiverRef = getAccount(merchantAccount).getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
44      assert(merchantDUCReceiverRef.borrow() != nil, message: "Missing or mis-typed merchant DUC receiver")
45    // Deposit DUC to Flunks merchant account DUC Vault (it's then forwarded to the main DUC contract afterwards)
46    merchantDUCReceiverRef.borrow()!.deposit(from: <-paymentVault)
47
48    // Get buyer collection public to receive Flunks
49    let recipient = getAccount(buyer)
50    let NFTReceiver = recipient.getCapability(Flunks.CollectionPublicPath)
51      .borrow<&{NonFungibleToken.CollectionPublic}>()
52      ?? panic("Could not get receiver reference to the NFT Collection")
53
54    // Mint Flunks NFTs per purchaseAmount
55    var mintCounter = numberOfTokens
56    while(mintCounter > 0) {
57      admin.mintNFT(recipient: NFTReceiver, setID: setID)
58      mintCounter = mintCounter - 1
59    }
60
61    // Empty whitelist spot
62    if (FlunksWhitelistMinter.whitelistedAccounts[buyer]! - numberOfTokens == 0) {
63      FlunksWhitelistMinter.whitelistedAccounts.remove(key: buyer)
64    } else {
65      FlunksWhitelistMinter.whitelistedAccounts[buyer] = FlunksWhitelistMinter.whitelistedAccounts[buyer]! - numberOfTokens
66    }
67  }
68
69  pub fun mintPublicNFTWithDUC(buyer: Address, setID: UInt64, paymentVault: @FungibleToken.Vault, merchantAccount: Address, numberOfTokens: UInt64) {
70    pre {
71      numberOfTokens <= 4:
72        "purchaseAmount too large"
73      paymentVault.balance >= UFix64(numberOfTokens) * FlunksWhitelistMinter.publicSalePrice:
74        "Insufficient payment amount."
75      paymentVault.getType() == Type<@DapperUtilityCoin.Vault>():
76        "payment type not DapperUtilityCoin.Vault."
77    }
78
79    let admin = self.account.borrow<&Flunks.Admin>(from: Flunks.AdminStoragePath)
80      ?? panic("Could not borrow a reference to the Flunks Admin")
81
82    let set = admin.borrowSet(setID: setID)
83    // Check set availability
84    if (set.getAvailableTemplateIDs().length == 0) { panic("set is empty") }
85    // Check set eligibility
86    if (set.locked) { panic("Set is locked") }
87    if (!set.isPublic) { panic("Cannot mint private set with mintPublicNFTWithDUC") }
88
89    // Get DUC receiver reference of Flunks merchant account
90    let merchantDUCReceiverRef = getAccount(merchantAccount).getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
91      assert(merchantDUCReceiverRef.borrow() != nil, message: "Missing or mis-typed merchant DUC receiver")
92    // Deposit DUC to Flunks merchant account DUC Vault (it's then forwarded to the main DUC contract afterwards)
93    merchantDUCReceiverRef.borrow()!.deposit(from: <-paymentVault)
94
95    // Get buyer collection public to receive Flunks
96    let recipient = getAccount(buyer)
97    let NFTReceiver = recipient.getCapability(Flunks.CollectionPublicPath)
98      .borrow<&{NonFungibleToken.CollectionPublic}>()
99      ?? panic("Could not get receiver reference to the NFT Collection")
100
101    // Mint Flunks NFTs per purchaseAmount
102    var mintCounter = numberOfTokens
103    while(mintCounter > 0) {
104      admin.mintNFT(recipient: NFTReceiver, setID: setID)
105      mintCounter = mintCounter - 1
106    }
107  }
108
109  pub resource Admin {
110    pub fun addWhiteListAddress(address: Address, amount: UInt64) {
111      pre {
112        amount <= 10:
113          "Unable to allocate more than 10 whitelist spots"
114        FlunksWhitelistMinter.whitelistedAccounts[address] == nil:
115          "Provided Address is already whitelisted"
116      }
117      FlunksWhitelistMinter.whitelistedAccounts[address] = amount
118    }
119
120    pub fun removeWhiteListAddress(address: Address) {
121      pre {
122        FlunksWhitelistMinter.whitelistedAccounts[address] != nil:
123          "Provided Address is not whitelisted"
124      }
125      FlunksWhitelistMinter.whitelistedAccounts.remove(key: address)
126    }
127
128    pub fun pruneWhitelist() {
129      FlunksWhitelistMinter.whitelistedAccounts = {}
130    }
131
132    pub fun updateWhiteListAddressAmount(address: Address, amount: UInt64) {
133      pre {
134        FlunksWhitelistMinter.whitelistedAccounts[address] != nil:
135          "Provided Address is not whitelisted"
136      }
137      FlunksWhitelistMinter.whitelistedAccounts[address] = amount
138    }
139
140    pub fun updatePrivateSalePrice(price: UFix64) {
141      FlunksWhitelistMinter.privateSalePrice = price
142    }
143
144    pub fun updatePublicSalePrice(price: UFix64) {
145      FlunksWhitelistMinter.publicSalePrice = price
146    }
147  }
148
149  pub fun getWhitelistedAccounts(): {Address: UInt64} {
150    return FlunksWhitelistMinter.whitelistedAccounts
151  }
152
153  init() {
154    self.AdminStoragePath = /storage/FlunksWhitelistMinterAdmin
155
156    self.privateSalePrice = 250.00
157    self.publicSalePrice = 250.00
158
159    self.whitelistedAccounts = {}
160
161    let admin <- create Admin()
162    self.account.save(<-admin, to: self.AdminStoragePath)
163
164    emit ContractInitialized()
165  }
166}