/
kangaroo.clar
114 lines (95 loc) · 3.3 KB
/
kangaroo.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
;; ---------------------------------------------------------
;; SIP-10 Fungible Token Contract
;; ---------------------------------------------------------
;; (use-trait sip-010-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)
(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)
(define-constant SUPPLY u42000000000000)
(define-fungible-token kangaroo SUPPLY)
(define-constant contract-owner tx-sender)
(define-constant err-owner-only (err u100))
;; ---------------------------------------------------------
;; Constants/Variables
;; ---------------------------------------------------------
(define-data-var token-uri (optional (string-utf8 256)) none)
;; ---------------------------------------------------------
;; Errors
;; ---------------------------------------------------------
(define-constant ERR_UNAUTHORIZED (err u100))
;; ---------------------------------------------------------
;; SIP-10 Functions
;; ---------------------------------------------------------
(define-public (transfer
(amount uint)
(sender principal)
(recipient principal)
(memo (optional (buff 34)))
)
(begin
;; #[filter(amount, recipient)]
(asserts! (is-eq tx-sender sender) ERR_UNAUTHORIZED)
(try! (ft-transfer? kangaroo amount sender recipient))
(match memo to-print (print to-print) 0x)
(ok true)
)
)
(define-read-only (get-balance (owner principal))
(ok (ft-get-balance kangaroo owner))
)
(define-read-only (get-name)
(ok "Kangaroo the Jumping Coin")
)
(define-read-only (get-symbol)
(ok "$ROO")
)
(define-read-only (get-decimals)
(ok u6)
)
(define-read-only (get-total-supply)
(ok (ft-get-supply kangaroo))
)
(define-read-only (get-token-uri)
(ok (var-get token-uri)
)
)
(define-public (set-token-uri (value (string-utf8 256)))
;; #[filter(value)]
(if (is-eq tx-sender contract-owner)
(ok (var-set token-uri (some value)))
(err ERR_UNAUTHORIZED)
)
)
(define-public (mint (amount uint))
(begin
(asserts! (is-eq tx-sender contract-owner) err-owner-only)
(ft-mint? kangaroo amount contract-owner)
)
)
;; ---------------------------------------------------------
;; Utility Functions
;; ---------------------------------------------------------
(define-public (send-many (recipients (list 200 { to: principal, amount: uint, memo: (optional (buff 34)) })))
(fold check-err (map send-token recipients) (ok true))
)
(define-private (check-err (result (response bool uint)) (prior (response bool uint)))
(match prior ok-value result err-value (err err-value))
)
(define-private (send-token (recipient { to: principal, amount: uint, memo: (optional (buff 34)) }))
(send-token-with-memo (get amount recipient) (get to recipient) (get memo recipient))
)
(define-private (send-token-with-memo (amount uint) (to principal) (memo (optional (buff 34))))
(let ((transferOk (try! (transfer amount tx-sender to memo))))
(ok transferOk)
)
)
(define-private (send-stx (recipient principal) (amount uint))
(begin
(try! (stx-transfer? amount tx-sender (as-contract recipient)))
(ok true) ;; Return success
)
)
;; ---------------------------------------------------------
;; Mint
;; ---------------------------------------------------------
(begin
(try! (ft-mint? kangaroo SUPPLY contract-owner))
)