-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.leo
403 lines (354 loc) · 11.9 KB
/
main.leo
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
// ARC20.
record Balance {
// The Aleo balance.
owner: address,
gates: u64,
amount: u64,
}
// Mandatory Functions
@program
function approve(owner: address, amount_owner: u64, spender: address, amount_desired : u64 )-> bool {
let response_approve:bool = false;
if amount_owner >= amount_desired {
response_approve = true;
}
return response_approve;
}
@program
function test_approve(owner: address, amount_owner: u64, spender: address, amount_desired : u64 )-> bool {
let response_approve:bool = false;
if amount_owner >= amount_desired {
response_approve = true;
}
// Test
let test_bool_approve: bool = false;
let approve_bool: bool = true;
if response_approve == approve_bool {
test_bool_approve = true;
}
return test_bool_approve;
}
@program
// The allowance() function returns the token amount remaining, which the spender is currently allowed to withdraw from the owner's account.
// This function must returns uint256 remaining, but for 'test' the amount is a parameter.
function allowance(owner: address, spender: address, balance_owner: Balance, amount_remaining : u64 )-> u64 {
// return 1 if the amount is valid and 0 otherwise
let response:u64 = 0u64;
//let amount_owner: u64 = balance_owner.amount;
if amount_remaining < balance_owner.amount {
response = amount_remaining;
}
return response;
}
@program
function test_allowance(owner: address, spender: address, balance_owner: Balance, amount_remaining : u64 )-> bool {
// return 1 if the amount is valid and 0 otherwise
let response:u64 = 0u64;
if amount_remaining < balance_owner.amount {
response = amount_remaining;
}
// Test
let test_allowance_bool: bool = false;
let test_response:u64 = 78u64;
if test_response == response {
test_allowance_bool = true;
}
return test_allowance_bool;
}
@program
function transfer_from(from_balance: Balance, from:address, to_address: address, to_gates: u64, to_amount: u64, amount: u64) -> (Balance, address, u64, u64) {
let difference: u64 = from_balance.amount - amount;
let remaining: Balance = Balance {
owner: from,
gates: from_balance.gates,
amount: difference,
};
let increment: u64 = to_amount + amount;
// Output the sender's change record and the receiver's record.
return (remaining, to_address, increment, to_gates );
}
@program
function test_transfer_from(from_balance: Balance, from: address, to_address: address, to_gates: u64, to_amount: u64, amount: u64) -> bool {
let difference: u64 = from_balance.amount - amount;
let remaining: Balance = Balance {
owner: from,
gates: from_balance.gates,
amount: difference,
};
let increment: u64 = to_amount + amount;
// Test
let transferred: Balance = Balance {
owner: to_address,
gates: to_gates,
amount: increment,
};
let test_remaining: Balance = Balance {
owner: aleo1ht2a9q0gsd38j0se4t9lsfulxgqrens2vgzgry3pkvs93xrrzu8s892zn7,
gates: 0u64,
amount: 20u64,
};
let test_transferred: Balance = Balance {
owner: aleo1mgfq6g40l6zkhsm063n3uhr43qk5e0zsua5aszeq5080dsvlcvxsn0rrau,
gates: 0u64,
amount: 35u64,
};
//remaining ( from );
let test_owner_from: bool = false;
let test_gates_from: bool = false;
let test_amount_from: bool = false;
//transferred ( to );
let test_owner_to: bool = false;
let test_gates_to: bool = false;
let test_amount_to: bool = false;
//remaining ( from );
if test_remaining.owner == remaining.owner{
test_owner_from = true;
}
if test_remaining.gates == remaining.gates{
test_gates_from = true;
}
if test_remaining.amount == remaining.amount{
test_amount_from = true;
}
let test_remaining_final: bool = false;
if test_owner_from == true{
if test_gates_from == true{
if test_amount_from == true{
test_remaining_final = true;
}
}
}
//transferred ( to );
if test_transferred.owner == transferred.owner{
test_owner_to = true;
}
if test_transferred.gates == transferred.gates{
test_gates_to = true;
}
if test_transferred.amount == transferred.amount{
test_amount_to = true;
}
let test_transferred_final: bool = false;
if test_owner_to == true{
if test_gates_to == true{
if test_amount_to == true{
test_transferred_final = true;
}
}
}
let test_final:bool = false;
if test_transferred_final == true{
if test_remaining_final == true{
test_final = true;
}
}
return test_final;
}
@program
function balance_of(owner_balance: Balance) -> u64 {
let amount_balance: u64 = owner_balance.amount;
let minimun: u64 = 0u64;
let return_balance:u64 = 0u64;
if amount_balance >= minimun{
return_balance = amount_balance;
}
return return_balance;
}
@program
function test_balance_of(owner_balance: Balance) -> bool {
let amount_balance: u64 = owner_balance.amount;
let minimun: u64 = 0u64;
let return_balance:u64 = 0u64;
if amount_balance >= minimun{
return_balance = amount_balance;
}
// Test
let test_balance_of_bool: bool = false;
if return_balance == 269u64{
test_balance_of_bool = true;
}
return test_balance_of_bool;
}
@program
function total_supply(amount_supply: u64) -> u64 {
let zero: u64 = 0u64;
let return_supply:u64 = amount_supply;
return_supply = return_supply + zero;
return return_supply;
}
@program
function test_total_supply(amount_supply: u64) -> bool {
let zero: u64 = 0u64;
let return_supply:u64 = amount_supply;
return_supply = return_supply + zero;
// Test
let test_total_supply_bool: bool = false;
if return_supply == 1729u64{
test_total_supply_bool = true;
}
return test_total_supply_bool;
}
@program
function transfer(to_balance: Balance, to: address, amount: u64) -> Balance {
let increment_amount: u64 = to_balance.amount + amount;
let transferred: Balance = Balance {
owner: to,
gates: to_balance.gates,
amount: increment_amount,
};
return transferred;
}
@program
function test_transfer(to_balance: Balance, to: address, amount: u64) -> bool {
let increment_amount: u64 = to_balance.amount + amount;
let transferred: Balance = Balance {
owner: to,
gates: to_balance.gates,
amount: increment_amount,
};
// Test
let test_transferred: Balance = Balance {
owner: aleo1ht2a9q0gsd38j0se4t9lsfulxgqrens2vgzgry3pkvs93xrrzu8s892zn7,
gates: 0u64,
amount: 30u64,
};
// test_to);
let test_owner_to: bool = false;
let test_gates_to: bool = false;
let test_amount_to: bool = false;
if test_transferred.owner == transferred.owner{
test_owner_to = true;
}
if test_transferred.gates == transferred.gates{
test_gates_to = true;
}
if test_transferred.amount == transferred.amount{
test_amount_to = true;
}
let test_transferred_final: bool = false;
if test_owner_to == true {
if test_gates_to == true {
if test_amount_to == true {
test_transferred_final = true;
}
}
}
return test_transferred_final;
}
// Optional functions
// Name Returns the name of the token.
// Symbol Returns the symbol of the token, usually a shorter version of the name.
// Decimals Returns the number of decimals used to get its user representation.
// Let's assume we have user A and user B. A has 1000 tokens and want to give permission to B to spend 100 of them.
// A will call approve(address(B), 100)
// B will check how many tokens A gave him permission to use by calling allowance(address(A), address(B))
// B will send to his account these tokens by calling transferFrom(address(A), address(B), 100)
@program
function decimals(quantity_decimals: u64) -> u64 {
// Decimals Returns the number of decimals used to get its user representation.
// For example, if decimals equals 2, a balance of 505 tokens should be displayed to a user as 5.05 (505 / 10 ** 2).
// Tokens usually opt for a value of 18,
let zero: u64 = 0u64;
let return_quantity_decimals: u64 = 0u64;
return_quantity_decimals = quantity_decimals + zero;
return return_quantity_decimals;
}
@program
// Return four letters 'A' 'L' 'E' 'O' in ascii mode.
// The parameter `is_dummmy` only exists for syntax purposes.
function name(is_dummmy: u64) -> (u64,u64,u64,u64) {
let letter_A: u64 = 65u64;
let letter_L: u64 = 76u64;
let letter_E: u64 = 69u64;
let letter_O: u64 = 79u64;
let zero: u64 = 0u64;
is_dummmy = zero + is_dummmy;
letter_A = letter_A + zero;
letter_L = letter_L + zero;
letter_E = letter_E + zero;
letter_O = letter_O + zero;
return (letter_A, letter_L, letter_E, letter_O) ;
}
@program
// Return four letters 'L' 'E' 'O' in ascii mode.
// The parameter `is_dummmy` only exists for syntax purposes.
function symbol(is_dummmy: u64) -> (u64,u64,u64) {
let letter_L: u64 = 76u64;
let letter_E: u64 = 69u64;
let letter_O: u64 = 79u64;
let zero: u64 = 0u64;
is_dummmy = zero + is_dummmy;
letter_L = letter_L + zero;
letter_E = letter_E + zero;
letter_O = letter_O + zero;
return (letter_L, letter_E, letter_O);
}
@program
// This function tests if it is valid to return a quantity of decimals different from a specified number.
function test_decimals(quantity_decimals: u64) -> bool {
let zero: u64 = 0u64;
let return_quantity_decimals: u64 = 0u64;
return_quantity_decimals = quantity_decimals + zero;
let test_quantity_decimals: u64 = 8u64;
let test_decimals_bool: bool = false;
if test_quantity_decimals == return_quantity_decimals {
test_decimals_bool = true;
}
return test_decimals_bool;
}
@program
// This function tests if it is valid to return a Name different from "ALEO".
// The parameter `is_dummmy` only exists for syntax purposes.
function test_name(is_dummmy: u64) -> bool {
let letter_A: u64 = 65u64;
let letter_L: u64 = 76u64;
let letter_E: u64 = 69u64;
let letter_O: u64 = 79u64;
let zero: u64 = 0u64;
is_dummmy = zero + is_dummmy;
letter_A = letter_A + zero;
letter_L = letter_L + zero;
letter_E = letter_E + zero;
letter_O = letter_O + zero;
let test_letter_A: u64 = 65u64;
let test_letter_L: u64 = 76u64;
let test_letter_E: u64 = 69u64;
let test_letter_O: u64 = 79u64;
let test_name_bool: bool = false;
if test_letter_A == letter_A {
if test_letter_L == letter_L {
if test_letter_E == letter_E {
if test_letter_O == letter_O {
test_name_bool = true;
}
}
}
}
return test_name_bool;
}
@program
// This function tests if it is valid to return a Symbol different from "LEO".
// The parameter `is_dummmy` only exists for syntax purposes.
function test_symbol(is_dummmy: u64) -> bool {
let letter_L: u64 = 76u64;
let letter_E: u64 = 69u64;
let letter_O: u64 = 79u64;
let zero: u64 = 0u64;
let pepe: u64 = 8u64;
is_dummmy = zero + is_dummmy;
letter_L = letter_L + zero;
letter_E = letter_E + zero;
letter_O = letter_O + zero;
let test_letter_L: u64 = 76u64;
let test_letter_E: u64 = 69u64;
let test_letter_O: u64 = 79u64;
let test_symbol_bool: bool = false;
if test_letter_L == letter_L {
if test_letter_E == letter_E {
if test_letter_O == letter_O {
test_symbol_bool = true;
}
}
}
return test_symbol_bool;
}