-
Notifications
You must be signed in to change notification settings - Fork 13
/
TEST-W-P.clar
147 lines (118 loc) · 4.18 KB
/
TEST-W-P.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
(impl-trait 'SP39HFKW38EPPPRQ1R52GK02WCN8314DQAQHF6EZ6.nft-trait.nft-trait)
;; Non Fungible Token, using sip-009
(define-non-fungible-token TEST-W-P uint)
;; Storage
(define-map tokens-count
principal
uint)
;; Constants
(define-constant ERR-ALL-MINTED u101)
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-NOT-AUTHORIZED u401)
(define-constant ERR-MINT-NOT-ENABLED (err u1004))
(define-constant MINT-LIMIT u5)
;; Internal variables
(define-data-var last-id uint u0)
(define-data-var uri-prefix (string-ascii 256) "")
(define-data-var cost-per-mint uint u1000000)
(define-data-var commission-per-mint uint u0000000)
(define-data-var payout uint u0)
(define-data-var ipfs-full-metadata (string-ascii 500) "https://ipfs.io/ipfs/QmZKR7yNZmjDC2ExGu275oynEkuzUxP6NHDAv8xAfydbZM")
(define-data-var ipfs-root (string-ascii 200) "https://ipfs.io/ipfs/QmZKR7yNZmjDC2ExGu275oynEkuzUxP6NHDAv8xAfydbZM")
(define-data-var artist-address principal 'SP3PAV4GYANANYC3EBWQZ6V2XV6J9ABXJSAV3NH6Q)
(define-data-var minting-enabled bool true)
(define-public (claim)
(mint tx-sender))
;; Gets the amount of tokens owned by the specified address.
(define-private (balance-of (account principal))
(default-to u0 (map-get? tokens-count account)))
;; Internal - Register token
(define-private (mint (new-owner principal))
(let (
(next-id (+ u1 (var-get last-id)))
(count (var-get last-id))
)
(asserts! (is-eq (var-get minting-enabled) true) ERR-MINT-NOT-ENABLED)
(asserts! (< count MINT-LIMIT) (err ERR-ALL-MINTED))
(match (stx-transfer? (var-get cost-per-mint) tx-sender (as-contract tx-sender))
success (begin
(try! (nft-mint? TEST-W-P next-id new-owner))
(var-set last-id next-id)
(var-set payout (var-get cost-per-mint) )
(try! (as-contract (stx-transfer? (var-get cost-per-mint) (as-contract tx-sender) (var-get artist-address))))
(ok next-id)
)
error (err error)
)
)
)
;; Public functions
;; Allows contract owner to change mint price
(define-public (set-cost-per-mint (value uint))
(if (is-eq tx-sender CONTRACT-OWNER)
(ok (var-set cost-per-mint value))
(err ERR-NOT-AUTHORIZED)
)
)
;; Allows contract owner to change mint price
(define-public (set-commission-per-mint (value uint))
(if (is-eq tx-sender CONTRACT-OWNER)
(ok (var-set commission-per-mint value))
(err ERR-NOT-AUTHORIZED)
)
)
;; Allows contract owner to change artist address if need be
(define-public (set-artist-address (value principal))
(if (is-eq tx-sender CONTRACT-OWNER)
(ok (var-set artist-address value))
(err ERR-NOT-AUTHORIZED)
)
)
;; Turn minting on
(define-public (set-minting-enabled)
(if (is-eq tx-sender CONTRACT-OWNER)
(ok (var-set minting-enabled true))
(err ERR-NOT-AUTHORIZED)
)
)
;; Turn minting off
(define-public (set-minting-disabled)
(if (is-eq tx-sender CONTRACT-OWNER)
(ok (var-set minting-enabled false))
(err ERR-NOT-AUTHORIZED)
)
)
;; Transfers tokens to a specified principal.
(define-public (transfer (token-id uint) (sender principal) (recipient principal))
(if (and
(is-eq tx-sender sender))
;; Make sure to replace MY-OWN-NFT
(match (nft-transfer? TEST-W-P token-id sender recipient)
success (ok success)
error (err error))
(err u500)))
;; Transfers stx from contract to contract owner
(define-public (transfer-stx (address principal) (amount uint))
(if (is-eq tx-sender CONTRACT-OWNER)
(as-contract (stx-transfer? amount (as-contract tx-sender) address))
(err ERR-NOT-AUTHORIZED)
)
)
;; Gets the owner of the specified token ID.
(define-read-only (get-owner (token-id uint))
(ok (nft-get-owner? TEST-W-P token-id)))
;; Gets mint price
(define-read-only (get-mint-price)
(ok (var-get cost-per-mint)))
;; Gets the owner of the specified token ID.
(define-read-only (get-last-token-id)
(ok (var-get last-id)))
(define-read-only (get-contract-metadata)
(ok (some (var-get ipfs-full-metadata)))
)
(define-read-only (get-token-uri (token-id uint))
(ok (some (concat (var-get ipfs-root) "_metadata.json")))
)
(begin
(try! (mint (var-get artist-address)))
)