-
Notifications
You must be signed in to change notification settings - Fork 13
/
stacksocean-art.clar
126 lines (107 loc) · 3.95 KB
/
stacksocean-art.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
(impl-trait 'SP2V1F1QA2X5HEMADTY9YGBG6ES3Q1Y95435A329C.nft-trait.nft-trait)
;; Non Fungible Token, using sip-009
(define-non-fungible-token stacksocean-art uint)
;; Constants
(define-constant err-no-more-nfts u300)
(define-constant err-invalid-user u500)
(define-constant err-mint u600)
(define-constant COMM u250)
(define-constant COMM1 u100)
(define-constant DEPLOYER tx-sender)
(define-constant MAIN 'SP2V1F1QA2X5HEMADTY9YGBG6ES3Q1Y95435A329C)
(define-constant COMM_ADDR 'SP3ZRDNS9NXNVD1P0QNZ6STBC4B6XT0RXHA4F6APV)
(define-constant COMM_ADDR1 'SPVDTWPB2AHT63385BT3JENEM68VNFMGWADVDKWD)
(define-constant COMM_ADDR2 'SP1P1A6VNW2M05JB7FHG6EBBH1ZAB05XWRZABN1ZG)
;; Internal variables
(define-data-var mint-limit uint u5)
(define-data-var last-id uint u1)
(define-data-var total-price uint u5000000)
(define-data-var artist-address principal 'SP67RWGFXKEYFW3P16M15WR2Z3JV1M17V5FC06Q5)
(define-data-var ipfs-root (string-ascii 80) "ipfs://ipfs/QmNMwWZULwpG7AZrLrPwGXMeYspBEAjoamtYSaqxjhTQqz/")
(define-data-var ipfs-change-enabled bool true)
(define-private (mint-many (orders (list 10 bool)))
(let (
(last-nft-id (var-get last-id))
(enabled (asserts! (<= last-nft-id (var-get mint-limit)) (err err-no-more-nfts)))
(art-addr (var-get artist-address))
(id-reached (fold mint-many-iter orders last-nft-id))
(price (* (var-get total-price) (- id-reached last-nft-id)))
(total-commission (/ (* price COMM) u10000))
(total-commission1 (/ (* price COMM) u10000))
(total-commission2 (/ (* price COMM1) u10000))
(total-artist (- price (+ total-commission total-commission1 total-commission2)))
)
(if (or (is-eq tx-sender art-addr) (is-eq tx-sender MAIN))
(var-set last-id id-reached)
(begin
(var-set last-id id-reached)
(try! (stx-transfer? total-artist tx-sender (var-get artist-address)))
(try! (stx-transfer? total-commission tx-sender COMM_ADDR))
(try! (stx-transfer? total-commission1 tx-sender COMM_ADDR1))
(try! (stx-transfer? total-commission2 tx-sender COMM_ADDR2))
)
)
(ok id-reached)
)
)
(define-private (mint-many-iter (ignore bool) (next-id uint))
(if (<= next-id (var-get mint-limit))
(begin
(unwrap! (nft-mint? stacksocean-art next-id tx-sender) next-id)
(+ next-id u1)
)
next-id
)
)
(define-public (claim)
(mint-many (list true))
)
(define-public (claim-five)
(mint-many (list true true true true true))
)
(define-public (claim-ten)
(mint-many (list true true true true true true true true true true))
)
(define-public (set-artist-address (address principal))
(begin
(asserts! (is-eq tx-sender DEPLOYER) (err err-invalid-user))
(ok (var-set artist-address address))
)
)
(define-public (set-price (price uint))
(begin
(asserts! (is-eq tx-sender DEPLOYER) (err err-invalid-user))
(ok (var-set total-price price))
)
)
(define-public (set-ipfs-root (new-ipfs-root (string-ascii 80)))
(begin
(asserts! (and (var-get ipfs-change-enabled) (is-eq tx-sender DEPLOYER)) (err err-invalid-user))
(ok (var-set ipfs-root new-ipfs-root))
)
)
(define-public (freeze-ipfs-root)
(begin
(asserts! (and (var-get ipfs-change-enabled) (is-eq tx-sender DEPLOYER)) (err err-invalid-user))
(ok (var-set ipfs-change-enabled false))
)
)
(define-public (set-mint-limit (new-limit uint))
(begin
(asserts! (is-eq tx-sender DEPLOYER) (err err-invalid-user))
(ok (var-set mint-limit new-limit))
)
)
(define-public (transfer (token-id uint) (sender principal) (recipient principal))
(begin
(asserts! (is-eq tx-sender sender) (err err-invalid-user))
(nft-transfer? stacksocean-art token-id sender recipient)
)
)
;; read-only functions
(define-read-only (get-owner (token-id uint))
(ok (nft-get-owner? stacksocean-art token-id)))
(define-read-only (get-last-token-id)
(ok (- (var-get last-id) u1)))
(define-read-only (get-token-uri (token-id uint))
(ok (some (concat (concat (var-get ipfs-root) "{id}") ".json"))))