/
token-ssl-TwinsPig-AYTPG.clar
122 lines (122 loc) · 4.23 KB
/
token-ssl-TwinsPig-AYTPG.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
(impl-trait .trait-ownable.ownable-trait)
(impl-trait .trait-sip-010.sip-010-trait)
(define-fungible-token TwinsPig-AYTPG)
(define-data-var token-name (string-ascii 32) "TwinsPig-AYTPG (SSL)")
(define-data-var token-symbol (string-ascii 10) "TwinsPig")
(define-data-var token-uri (optional (string-utf8 256)) (some u"https://cdn.alexlab.co/metadata/token-ssl-TwinsPig-AYTPG.json"))
(define-data-var token-decimals uint u8)
(define-data-var contract-owner principal tx-sender)
(define-constant ERR-NOT-AUTHORIZED (err u1000))
(define-constant ERR-MINT-FAILED (err u6002))
(define-constant ERR-BURN-FAILED (err u6003))
(define-constant ERR-TRANSFER-FAILED (err u3000))
(define-constant ERR-NOT-SUPPORTED (err u6004))
(define-read-only (get-contract-owner)
(ok (var-get contract-owner))
)
(define-public (set-contract-owner (owner principal))
(begin
(try! (check-is-owner))
(ok (var-set contract-owner owner))
)
)
(define-private (check-is-owner)
(ok (asserts! (is-eq tx-sender (var-get contract-owner)) ERR-NOT-AUTHORIZED))
)
(define-public (set-name (new-name (string-ascii 32)))
(begin
(try! (check-is-owner))
(ok (var-set token-name new-name))
)
)
(define-public (set-symbol (new-symbol (string-ascii 10)))
(begin
(try! (check-is-owner))
(ok (var-set token-symbol new-symbol))
)
)
(define-public (set-decimals (new-decimals uint))
(begin
(try! (check-is-owner))
(ok (var-set token-decimals new-decimals))
)
)
(define-public (set-token-uri (new-uri (optional (string-utf8 256))))
(begin
(try! (check-is-owner))
(ok (var-set token-uri new-uri))
)
)
(define-read-only (get-total-supply)
;; least authority Issue D
ERR-NOT-SUPPORTED
)
(define-read-only (get-name)
(ok (var-get token-name))
)
(define-read-only (get-symbol)
(ok (var-get token-symbol))
)
(define-read-only (get-decimals)
(ok (var-get token-decimals))
)
(define-private (get-base-decimals)
(contract-call? 'SPXZB55NWTRQM02QYK7Z6K2PP7F279F640HAYTPG.TwinsPig get-decimals))
(define-read-only (get-balance (account principal))
(ok (/ (* (unwrap-panic (contract-call? 'SPXZB55NWTRQM02QYK7Z6K2PP7F279F640HAYTPG.TwinsPig get-balance account)) (pow-decimals)) (pow u10 (unwrap-panic (get-base-decimals)))))
)
(define-read-only (get-token-uri)
(ok (var-get token-uri))
)
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(begin
(asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED)
(contract-call? 'SPXZB55NWTRQM02QYK7Z6K2PP7F279F640HAYTPG.TwinsPig transfer (/ (* amount (pow u10 (unwrap-panic (get-base-decimals)))) (pow-decimals)) sender recipient memo)
)
)
(define-constant ONE_8 u100000000)
(define-private (pow-decimals)
(pow u10 (unwrap-panic (get-decimals)))
)
(define-read-only (fixed-to-decimals (amount uint))
(/ (* amount (pow-decimals)) ONE_8)
)
(define-private (decimals-to-fixed (amount uint))
(/ (* amount ONE_8) (pow-decimals))
)
(define-read-only (get-total-supply-fixed)
;; least authority Issue D
ERR-NOT-SUPPORTED
)
(define-read-only (get-balance-fixed (account principal))
(ok (decimals-to-fixed (unwrap-panic (get-balance account))))
)
(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(transfer (fixed-to-decimals amount) sender recipient memo)
)
(define-public (mint (amount uint) (recipient principal))
ERR-MINT-FAILED
)
(define-public (burn (amount uint) (sender principal))
ERR-BURN-FAILED
)
(define-public (mint-fixed (amount uint) (recipient principal))
(mint (fixed-to-decimals amount) recipient)
)
(define-public (burn-fixed (amount uint) (sender principal))
(burn (fixed-to-decimals amount) sender)
)
(define-private (check-err (result (response bool uint)) (prior (response bool uint)))
(match prior
ok-value result
err-value (err err-value)
)
)
(define-private (transfer-from-tuple (recipient { to: principal, amount: uint }))
(ok (unwrap! (transfer-fixed (get amount recipient) tx-sender (get to recipient) none) ERR-TRANSFER-FAILED))
)
(define-public (send-many (recipients (list 200 { to: principal, amount: uint})))
(fold check-err (map transfer-from-tuple recipients) (ok true))
)
(contract-call? .alex-vault-v1-1 set-approved-token .token-ssl-TwinsPig-AYTPG true)
(set-contract-owner .executor-dao)