-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmooningsharks.clar
More file actions
169 lines (146 loc) · 5.51 KB
/
mooningsharks.clar
File metadata and controls
169 lines (146 loc) · 5.51 KB
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
165
166
167
168
169
;; Title: mooning-sharks
;; Author: SP1KMAA7TPZ5AZZ4W67X74MJNFKMN576604CWNBQS
;; Created With Charisma
;; https://charisma.rocks
;; Description:
;; Sharks riding the Nakamoto wave to the Moon
;; This contract implements the SIP-009 community-standard Non-Fungible Token trait
(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
;; Define the NFT's name
(define-non-fungible-token nft uint)
;; Keep track of the last minted token ID
(define-data-var last-token-id uint u0)
;; Define constants
(define-constant COLLECTION_LIMIT u20) ;; Limit to series of 20
(define-constant ENERGY_PER_NFT u100000) ;; 100k energy per NFT
(define-constant STX_PER_MINT u1000000) ;; 1 STX per MINT for DAO
(define-constant MAX_NFTS_PER_TX u4) ;; Maximum 4 NFTs per transaction
(define-constant OWNER 'SP1KMAA7TPZ5AZZ4W67X74MJNFKMN576604CWNBQS) ;; Collection creator
(define-constant CHA_AMOUNT (pow u10 u7)) ;; 10 CHA per mint to creator
(define-constant ERR_UNAUTHORIZED (err u100))
(define-constant ERR_NOT_TOKEN_OWNER (err u101))
(define-constant ERR_SOLD_OUT (err u300))
(define-constant ERR_INVALID_EDK (err u400))
(define-data-var base-uri (string-ascii 200) "https://charisma.rocks/api/v0/nfts/SP1KMAA7TPZ5AZZ4W67X74MJNFKMN576604CWNBQS.mooning-sharks/{id}.json")
;; Whitelisted contract addresses
(define-map whitelisted-edks principal bool)
(define-trait edk-trait
(
(tap (uint) (response (tuple (type (string-ascii 256)) (land-id uint) (land-amount uint) (energy uint)) uint))
)
)
;; Authorization check
(define-private (is-dao-or-extension)
(or (is-eq tx-sender 'SP2D5BGGJ956A635JG7CJQ59FTRFRB0893514EZPJ.dungeon-master) (contract-call? 'SP2D5BGGJ956A635JG7CJQ59FTRFRB0893514EZPJ.dungeon-master is-extension contract-caller))
)
(define-read-only (is-authorized)
(ok (asserts! (is-dao-or-extension) ERR_UNAUTHORIZED))
)
;; Whitelist functions
(define-public (set-whitelisted-edk (edk principal) (whitelisted bool))
(begin
(try! (is-authorized))
(ok (map-set whitelisted-edks edk whitelisted))
)
)
(define-read-only (is-whitelisted-edk (edk principal))
(default-to false (map-get? whitelisted-edks edk))
)
;; SIP-009 function: Get the last minted token ID.
(define-read-only (get-last-token-id)
(ok (var-get last-token-id))
)
;; SIP-009 function: Get link where token metadata is hosted
(define-read-only (get-token-uri (token-id uint))
(ok (some (var-get base-uri)))
)
;; Function to update the token URI
(define-public (set-token-uri (new-uri (string-ascii 200)))
(begin
(try! (is-authorized))
(ok (var-set base-uri new-uri))
)
)
;; SIP-009 function: Get the owner of a given token
(define-read-only (get-owner (token-id uint))
(ok (nft-get-owner? nft token-id))
)
;; SIP-009 function: Transfer NFT token to another owner.
(define-public (transfer (token-id uint) (sender principal) (recipient principal))
(begin
;; #[filter(sender)]
(asserts! (is-eq tx-sender sender) ERR_NOT_TOKEN_OWNER)
(nft-transfer? nft token-id sender recipient)
)
)
;; Mint a new NFT.
(define-private (mint (recipient principal))
;; Create the new token ID by incrementing the last minted ID.
(let ((token-id (+ (var-get last-token-id) u1)))
;; Ensure the collection stays within the limit.
(asserts! (< (var-get last-token-id) COLLECTION_LIMIT) ERR_SOLD_OUT)
;; Mint the NFT and send it to the given recipient.
(try! (nft-mint? nft token-id recipient))
;; 1 STX cost send to dungeon-master
(try! (stx-transfer? STX_PER_MINT tx-sender 'SP2D5BGGJ956A635JG7CJQ59FTRFRB0893514EZPJ.dungeon-master))
;; Mint 1 governance token to the OWNER
(try! (contract-call? 'SP2D5BGGJ956A635JG7CJQ59FTRFRB0893514EZPJ.dme000-governance-token dmg-mint CHA_AMOUNT OWNER))
;; Update the last minted token ID.
(var-set last-token-id token-id)
;; Return the newly minted NFT ID.
(ok token-id)
)
)
;; Mint multiple NFTs based on the count (1 to 4)
(define-private (mint-multiple (recipient principal) (count uint))
(if (is-eq count u1)
(mint recipient)
(if (is-eq count u2)
(begin
(try! (mint recipient))
(mint recipient)
)
(if (is-eq count u3)
(begin
(try! (mint recipient))
(try! (mint recipient))
(mint recipient)
)
(if (is-eq count u4)
(begin
(try! (mint recipient))
(try! (mint recipient))
(try! (mint recipient))
(mint recipient)
)
(err u500) ;; Invalid count
)
)
)
)
)
;; Quest logic
(define-public (tap (land-id uint) (edk-contract <edk-trait>))
(let
(
(tapped-out (unwrap-panic (contract-call? edk-contract tap land-id)))
(energy (get energy tapped-out))
(nfts-to-mint (min (/ energy ENERGY_PER_NFT) MAX_NFTS_PER_TX))
)
(asserts! (is-whitelisted-edk (contract-of edk-contract)) ERR_INVALID_EDK)
(mint-multiple tx-sender nfts-to-mint)
)
)
(define-read-only (get-untapped-amount (land-id uint) (user principal))
(let
(
(untapped-energy (unwrap-panic (contract-call? 'SP2ZNGJ85ENDY6QRHQ5P2D4FXKGZWCKTB2T0Z55KS.lands get-untapped-amount land-id user)))
(nfts-available (min (/ untapped-energy ENERGY_PER_NFT) MAX_NFTS_PER_TX))
)
nfts-available
)
)
;; Utility function to get the minimum of two uints
(define-private (min (a uint) (b uint))
(if (<= a b) a b)
)