Smart Contract
FlowtyAddressVerifiers
A.befbaccb5032a457.FlowtyAddressVerifiers
1import FlowtyDrops from 0xbefbaccb5032a457
2
3/*
4This contract contains implementations of the FlowtyDrops.AddressVerifier struct interface
5*/
6access(all) contract FlowtyAddressVerifiers {
7 /*
8 The AllowAll AddressVerifier allows any address to mint without any verification
9 */
10 access(all) struct AllowAll: FlowtyDrops.AddressVerifier {
11 access(all) var maxPerMint: Int
12
13 access(all) view fun canMint(addr: Address, num: Int, totalMinted: Int, data: {String: AnyStruct}): Bool {
14 return num <= self.maxPerMint
15 }
16
17 access(all) view fun getMaxPerMint(addr: Address?, totalMinted: Int, data: {String: AnyStruct}): Int? {
18 return self.maxPerMint
19 }
20
21 access(Mutate) fun setMaxPerMint(_ value: Int) {
22 self.maxPerMint = value
23 }
24
25 init(maxPerMint: Int) {
26 pre {
27 maxPerMint > 0: "maxPerMint must be greater than 0"
28 }
29
30 self.maxPerMint = maxPerMint
31 }
32 }
33
34 /*
35 The AllowList Verifier only lets a configured set of addresses participate in a drop phase. The number
36 of mints per address is specified to allow more granular control of what each address is permitted to do.
37 */
38 access(all) struct AllowList: FlowtyDrops.AddressVerifier {
39 access(self) let allowedAddresses: {Address: Int}
40
41 access(all) view fun canMint(addr: Address, num: Int, totalMinted: Int, data: {String: AnyStruct}): Bool {
42 if let allowedMints = self.allowedAddresses[addr] {
43 return allowedMints >= num + totalMinted
44 }
45
46 return false
47 }
48
49 access(all) view fun remainingForAddress(addr: Address, totalMinted: Int): Int? {
50 if let allowedMints = self.allowedAddresses[addr] {
51 return allowedMints - totalMinted
52 }
53 return nil
54 }
55
56 access(all) view fun getMaxPerMint(addr: Address?, totalMinted: Int, data: {String: AnyStruct}): Int? {
57 return addr != nil ? self.remainingForAddress(addr: addr!, totalMinted: totalMinted) : nil
58 }
59
60 access(Mutate) fun setAddress(addr: Address, value: Int) {
61 self.allowedAddresses[addr] = value
62 }
63
64 access(Mutate) fun removeAddress(addr: Address) {
65 self.allowedAddresses.remove(key: addr)
66 }
67
68 init(allowedAddresses: {Address: Int}) {
69 self.allowedAddresses = allowedAddresses
70 }
71 }
72}