-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.maude
214 lines (161 loc) · 5.73 KB
/
tokens.maude
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
*** Modules defining the tokens type system.
*** Copyright (C) 2021 Massimiliano Mirelli
*** massimilianomirelli.mm@gmail.com
*** This program is free software; you can redistribute it and/or
*** modify it under the terms of the GNU General Public License
*** as published by the Free Software Foundation; either version 2
*** of the License, or (at your option) any later version.
*** This program is distributed in the hope that it will be useful,
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*** GNU General Public License for more details.
*** You should have received a copy of the GNU General Public License
*** along with this program; if not, write to the Free Software
*** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
fmod TOKENS is
--- token types
including BOOL .
including INT .
--- native token is unique (not a set) and it's free (it
--- can be transferred)
sort Token Free-Token Minted-Token .
subsort Minted-Token Free-Token < Token .
sort Native-Token .
subsort Native-Token < Free-Token .
op tauError : -> [Token] .
op dummyTau : Nat -> Free-Token .
--- _[_] has prec 21
op tau(_) : Nat -> Free-Token
[ctor prec 19 format (y! d d d o)] .
--- _[_] has prec 21
op _' : Free-Token -> Minted-Token
[ctor prec 20 format (d b! o)] .
op ethtau : -> Native-Token .
endfm
view Token from TRIV to TOKENS is
sort Elt to Token .
endv
view Free-Token from TRIV to TOKENS is
sort Elt to Free-Token .
endv
view Native-Token from TRIV to TOKENS is
sort Elt to Native-Token .
endv
view Minted-Token from TRIV to TOKENS is
sort Elt to Minted-Token .
endv
fmod TOKEN-SETS is
including TOKENS .
including SUBSET{Free-Token, Token} .
including SUBSET{Minted-Token, Token} .
op freeTokenSet : -> Set{Free-Token} .
eq freeTokenSet = tau(0), tau(1) .
op mintableTokenSet : -> Set{Minted-Token} .
eq mintableTokenSet = tau(0)', tau(1)' .
op allTokenSet : -> Set{Token} .
eq allTokenSet = ethtau, freeTokenSet, mintableTokenSet .
vars anyTau : Token .
vars anyTauSet curFTok : Set{Token} .
op filterFree : Set{Token} -> Set{Free-Token} .
eq filterFree(anyTauSet) =
$filterFree(anyTauSet, empty) .
op $filterFree : Set{Token} Set{Free-Token} ->
Set{Free-Token} .
eq $filterFree(empty, curFTok) = curFTok .
eq $filterFree((anyTauSet, anyTau), curFTok) =
if anyTau :: Free-Token
then
$filterFree(anyTauSet, (curFTok, anyTau))
else
$filterFree(anyTauSet, curFTok)
fi .
op filterMinted : Set{Token} -> Set{Minted-Token} .
eq filterMinted(anyTauSet) =
anyTauSet \ filterFree(anyTauSet) .
op getFirst : NeSet{Token} -> Token .
eq getFirst((anyTauSet, anyTau)) = anyTau .
endfm
fmod TOKEN-LISTS is
including TOKENS .
including SUBLIST{Free-Token, Token} .
including SUBLIST{Minted-Token, Token} .
op freeTokenList : -> List{Free-Token} .
eq freeTokenList = tau(0) | tau(1) .
op mintableTokenList : -> List{Minted-Token} .
eq mintableTokenList = tau(0)' | tau(1)' .
op allTokenList : -> List{Token} .
eq allTokenList = ethtau | freeTokenList |
mintableTokenList .
endfm
fmod TOKEN-MAP is
including TOKEN-SETS .
including MAP{Token, Float0+} .
including SET{Float0+} .
endfm
view PiFFun from MAP-THEORY
to TOKEN-MAP is
sort M to Map{Token, Float0+} .
sort E to Entry{Token, Float0+} .
sort DT to Token .
sort CT to Float0+ .
sort D to Set{Token} .
sort C to Set{Float0+} .
op emptyD to empty .
op emptyC to empty .
endv
fmod SUBTOKEN-FUNCTIONS is
--- importing agents
including AGENT-ID-SETS .
including FUNCTION{PiFFun} .
including SUBMAP{Free-Token, Float0+, PiFFun} .
including SUBMAP{Minted-Token, Float0+, PiFFun} .
including MAP{Free-Token, Pair{Token, Float0+}} .
--- pi_loan & pi_fund/free & price
------ (Free-Token -> Float0+) < (Token -> Float0+)
including MAP{Agent-Id, Map{Token, Float0+}} .
--- For increased type accuracy use this:
--- including MAP{Agent-Id, Map{Free-Token, Float0+}} .
including SET{Pair{Token, Float0+}} .
including SET{Map{Token, Float0+}} .
endfm
view PiLFun from MAP-THEORY
to SUBTOKEN-FUNCTIONS is
sort M to Map{Agent-Id, Map{Token, Float0+}} .
sort E to Entry{Agent-Id, Map{Token, Float0+}} .
sort DT to Agent-Id .
sort CT to Map{Token, Float0+} .
sort D to Set{Agent-Id} .
sort C to Set{Map{Token, Float0+}} .
op emptyD to empty .
op emptyC to empty .
endv
view PiMFun from MAP-THEORY
to SUBTOKEN-FUNCTIONS is
sort M to Map{Free-Token,
Pair{Token, Float0+}} .
sort E to Entry{Free-Token,
Pair{Token, Float0+}} .
sort DT to Token .
sort CT to Pair{Token, Float0+} .
sort D to Set{Token} .
sort C to Set{Pair{Token, Float0+}} .
op emptyD to empty .
op emptyC to empty .
endv
fmod HO-EXISTS-TEST is
extending HO-EXISTS{Token} .
var tau : Token .
op isFree : -> Func{Token, Bool} .
eq isFree[tau] = tau :: Free-Token .
endfm
--- NOTE: UNUSED
view TokenFun from MAP-THEORY to SUBTOKEN-FUNCTIONS is
sort M to Map{Token, Float0+} .
sort E to Entry{Token, Float0+} .
sort DT to Token .
sort CT to Float0+ .
sort D to Set{Token} .
sort C to Set{Float0+} .
op emptyD to empty .
op emptyC to empty .
endv