-
Notifications
You must be signed in to change notification settings - Fork 6
/
convexity.con
136 lines (123 loc) · 4.66 KB
/
convexity.con
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
(def convexity
(deploy
'(do
(import convex.trust :as trust)
(import currency.GBP :as GBP)
(import currency.USD :as USD)
(import currency.MYR :as MYR)
(import currency.CHF :as CHF)
(import currency.JPY :as JPY)
(import currency.EUR :as EUR)
(import currency.HKD :as HKD)
(import currency.VND :as VND)
(import currency.THB :as THB)
(def trust-monitor
(deploy (trust/build-whitelist {:controller *caller* :whitelist [*caller*]})))
(def registry
{GBP {:type :fungible
:symbol "GBP"
:name "Pound Sterling"
:description "UK National Currency"
:currency-symbol "£"
:decimals 2}
USD {:type :fungible
:symbol "USD"
:name "US Dollar"
:description "US National Currency"
:currency-symbol "$"
:decimals 2}
MYR {:type :fungible
:symbol "MYR"
:name "Malaysian Ringgit"
:description "Malaysian National Currency"
:currency-symbol "RM"
:decimals 2}
CHF {:type :fungible
:symbol "CHF"
:name "Swiss Franc"
:description "Swiss National Currency"
:currency-symbol "Fr."
:decimals 2}
JPY {:type :fungible
:symbol "JPY"
:name "Japanese Yen"
:description "Japanese National Currency"
:currency-symbol "¥"
:decimals 0}
EUR {:type :fungible
:symbol "EUR"
:name "Euro"
:description "European Union Currency"
:currency-symbol "€"
:decimals 2}
HKD {:type :fungible
:symbol "HKD"
:name "Hong Kong Dollar"
:description "Hong Kong Currency"
:currency-symbol "HK$"
:decimals 2}
VND {:type :fungible
:symbol "VND"
:name "Vietnamese Dong"
:description "Vietnamese National Currency"
:currency-symbol "₫"
:decimals 2}
THB {:type :fungible
:symbol "THB"
:name "Thai Baht"
:description "Thai National Currency"
:currency-symbol "฿"
:decimals 2}})
(defn all-assets
^{:callable? true
:doc
{:description "Returns a mapping of Address to metadata."}}
[]
registry)
(defn asset-metadata
^{:callable? true
:doc
{:signature [{:params [addr]}]
:description "Returns metadata for a particular Asset."}}
[addr]
(get registry (address addr)))
(defn register-asset
^{:callable? true
:doc
{:signature [{:params [addr metadata]}]
:description "Registers metadata for a particular Asset. Returns registry.
Metadata is an open map and its keys will be different depending on its type.
NOTE: It's very important to *always* set the `type` key.
A Fungible Asset might have these keys:
- name : string
- description : string
- type : keyword fungible | non-fungible
- symbol : string
- currency-symbol : string
- decimals : number"}}
[addr metadata]
(if (trust/trusted? trust-monitor *caller*)
(def registry (assoc registry (address addr) metadata))
(fail :unauthorized "You're not authorized to modify the registry.")))
;; TODO
(defn request-registry
^{:callable? true
:doc
{:signature [{:params [address metadata]}]
:description "Requests to register metadata for a particular Asset."}}
[addr metadata]
(def registry (assoc registry (address addr) metadata)))
(defn unregister-asset
^{:callable? true
:doc
{:signature [{:params [address]}]
:description "Unregisters metadata for a particular Asset."}}
[addr]
(if (trust/trusted? trust-monitor *caller*)
(def registry (dissoc registry (address addr)))
(fail :unauthorized "You're not authorized to modify the registry."))))))
(import asset.nft.tokens :as nft)
(call convexity (register-asset nft {:name "NFTs"
:description "Convex NFT Library"
:type :non-fungible}))
convexity