/
welshcorgicoin-token.clar
84 lines (67 loc) · 2.04 KB
/
welshcorgicoin-token.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
(define-constant ERR-UNAUTHORIZED u1)
(define-constant ERR-YOU-POOR u2)
(define-fungible-token welshcorgicoin)
(define-data-var token-uri (optional (string-utf8 256)) none)
(define-constant contract-creator tx-sender)
(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)
;; SIP-010 Standard
(define-public (transfer (amount uint) (from principal) (to principal) (memo (optional (buff 34))))
(begin
(asserts! (is-eq from tx-sender)
(err ERR-UNAUTHORIZED))
(ft-transfer? welshcorgicoin amount from to)
)
)
(define-read-only (get-name)
(ok "Welshcorgicoin")
)
(define-read-only (get-symbol)
(ok "WELSH")
)
(define-read-only (get-decimals)
(ok u6)
)
(define-read-only (get-balance (user principal))
(ok (ft-get-balance welshcorgicoin user)
)
)
(define-read-only (get-total-supply)
(ok (ft-get-supply welshcorgicoin)
)
)
(define-public (set-token-uri (value (string-utf8 256)))
(if
(is-eq tx-sender contract-creator)
(ok (var-set token-uri (some value)))
(err ERR-UNAUTHORIZED)
)
)
(define-read-only (get-token-uri)
(ok (var-get token-uri)
)
)
;; send-many
(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)
)
)
;; The Great $WELSH TGE / Total 10B
(begin
(try! (ft-mint? welshcorgicoin u10000000000000000 contract-creator))
)