-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstackswap-gold-pass-v1b.clar
164 lines (138 loc) · 5.14 KB
/
stackswap-gold-pass-v1b.clar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
;; use the SIP090 interface (testnet)
;;live (impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
;;test (impl-trait 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.nft-trait.nft-trait)
(impl-trait .nft-trait.nft-trait)
(define-non-fungible-token Stackswap-Gold-Pass uint)
;; Storage
(define-map token-count principal uint)
;; Define Constants
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-SOLD-OUT (err u300))
(define-constant ERR-WRONG-COMMISSION (err u301))
(define-constant ERR-NOT-AUTHORIZED (err u401))
(define-constant ERR-NOT-FOUND (err u404))
(define-constant ERR-METADATA-FROZEN (err u505))
(define-constant ERR-MINT-ALREADY-SET (err u506))
(define-constant ERR-LISTING (err u507))
(define-constant ERR-MINT-PASS-LIMIT-REACHED (err u109))
(define-constant ERR-ADD-MINT-PASS (err u110))
;; Define Variables
(define-data-var last-id uint u0)
(define-data-var metadata-frozen bool false)
(define-data-var base-uri (string-ascii 80) "ipfs://QmQtSMAPvKFEr11VfKio2NHqwayJk4CTUkfmkxgXTR7Q2w")
(define-constant contract-uri "ipfs://QmQtSMAPvKFEr11VfKio2NHqwayJk4CTUkfmkxgXTR7Q2w")
(define-data-var gold-pass-limit uint u10000)
;; whitelist address -> # they can mint
(define-map mint-pass principal uint)
;; Token count for account
(define-read-only (get-balance (account principal))
(default-to u0
(map-get? token-count account)))
(define-private (trnsfr (id uint) (sender principal) (recipient principal))
(match (nft-transfer? Stackswap-Gold-Pass id sender recipient)
success
(let
((sender-balance (get-balance sender))
(recipient-balance (get-balance recipient)))
(map-set token-count
sender
(- sender-balance u1))
(map-set token-count
recipient
(+ recipient-balance u1))
(ok success))
error (err error)))
;; SIP009: Transfer token to a specified principal
(define-public (transfer (id uint) (sender principal) (recipient principal))
(begin
(asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED)
(asserts! (is-sender-owner id) ERR-NOT-AUTHORIZED)
(trnsfr id sender recipient)))
;; SIP009: Get the owner of the specified token ID
(define-read-only (get-owner (id uint))
;; Make sure to replace Stackswap-Gold-Pass
(ok (nft-get-owner? Stackswap-Gold-Pass id)))
;; SIP009: Get the last token ID
(define-read-only (get-last-token-id)
(ok (var-get last-id)))
;; SIP009: Get the token URI. You can set it to any other URI
(define-read-only (get-token-uri (id uint))
(ok (some (var-get base-uri))))
(define-read-only (get-contract-uri)
(ok contract-uri))
;; Mint new NFT
;; can only be called from the Mint
(define-public (mint (new-owner principal))
(let ((next-id (+ u1 (var-get last-id))))
(asserts! (< (var-get last-id) (var-get gold-pass-limit)) ERR-SOLD-OUT)
(match (nft-mint? Stackswap-Gold-Pass next-id new-owner)
success
(let (
(current-balance (get-balance new-owner))
(mintPassBalance (get-mint-pass-balance contract-caller))
)
(begin
(asserts! (> mintPassBalance u0) ERR-MINT-PASS-LIMIT-REACHED)
(map-set mint-pass contract-caller (- mintPassBalance u1))
(var-set last-id next-id)
(map-set token-count
new-owner
(+ current-balance u1)
)
(ok true)))
error (err (* error u10000)))))
(define-public (batch-mint (entries (list 200 principal)))
(fold check-err
(map mint entries)
(ok true)
)
)
(define-private (is-sender-owner (id uint))
(let ((owner (unwrap! (nft-get-owner? Stackswap-Gold-Pass id) false)))
(or (is-eq tx-sender owner) (is-eq contract-caller owner))))
;; Set base uri
(define-public (set-base-uri (new-base-uri (string-ascii 80)))
(begin
(asserts! (is-eq contract-caller CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
(asserts! (not (var-get metadata-frozen)) ERR-METADATA-FROZEN)
(var-set base-uri new-base-uri)
(ok true)))
;; Freeze metadata
(define-public (freeze-metadata)
(begin
(asserts! (is-eq contract-caller CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
(var-set metadata-frozen true)
(ok true)))
;; Set pass limit
(define-public (set-pass-limit (limit uint))
(begin
(asserts! (is-eq contract-caller CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
(var-set gold-pass-limit limit)
(ok true)))
(define-read-only (get-mint-pass-balance (account principal))
(default-to u0
(map-get? mint-pass account)
)
)
(define-public (set-mint-pass (account principal) (limit uint))
(begin
(asserts! (is-eq contract-caller CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
(ok (map-set mint-pass account limit))
)
)
(define-public (batch-set-mint-pass (entries (list 200 {account: principal, limit: uint})))
(fold check-err
(map set-mint-pass-helper entries)
(ok true)
)
)
(define-private (set-mint-pass-helper (entry {account: principal, limit: uint}))
(set-mint-pass (get account entry) (get limit entry))
)
(define-private (check-err (result (response bool uint)) (prior (response bool uint)))
(match prior
ok-value result
err-value (err err-value)
)
)
(map-set mint-pass 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275 u2)