-
Notifications
You must be signed in to change notification settings - Fork 18
/
run.sh
executable file
Β·261 lines (236 loc) Β· 15.7 KB
/
run.sh
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
#!/bin/bash
# First check that Leo is installed.
if ! command -v leo &> /dev/null
then
echo "leo is not installed."
exit
fi
echo "
We will be playing the role of two parties.
The private key and address of the bank.
private_key: APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD
address: aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a
The private key and address of the user.
private_key: APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc
address: aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg
"
echo "
Let's make some bank transactions. We'll take the role of the bank and issue 100 tokens to the user. We swap the private key into .env and run the issue transition function. The inputs are simply the recipient of the issuance and the amount.
echo '
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD
' > .env
leo run issue aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 100u64
"
# Swap in the private key of the bank to .env.
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD
" > .env
# Have the bank issue 100 tokens to the user.
leo run issue aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 100u64
echo "
###############################################################################
######## ########
######## Step 0: Initialize 100 tokens for aleo1zeklp...v46ngg ########
######## ########
######## ----------------------------------------- ########
######## | ACTION | AMOUNT | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Issuing | 100 | ########
######## ----------------------------------------- ########
######## | Depositing | 0 | ########
######## ----------------------------------------- ########
######## | Withdrawing | 0 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | WALLET | aleo1zeklp...v46ngg | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 100 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | BANK | aleo1t0uer...f6st7a | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 0 | ########
######## ----------------------------------------- ########
######## | Periods | 0 | ########
######## ----------------------------------------- ########
######## | Interest Rate | 12.34% | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | TOTAL BALANCE | 100 | ########
######## ----------------------------------------- ########
######## ########
###############################################################################
"
echo "
Now, let's have the user deposit 50 of their tokens with the bank. We'll take the role of the user and call the deposit function, having the user use the output record that was issued to them by the bank. The inputs are the output record from the issue transition and the amount the user wishes to deposit.
echo '
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc
' > .env
leo run deposit '{
owner: aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg.private,
amount: 100u64.private,
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
}' 50u64
"
# Swap in the private key of the user to .env.
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp75cpr5NNQpVWc5mfsD9Uf2wg6XvHknf82iwB636q3rtc
" > .env
# Have the user deposit 50 tokens into the bank.
leo run deposit "{
owner: aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg.private,
amount: 100u64.private,
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
}" 50u64
echo "
You'll see that the output contains a new private record belonging to the user with 50 credits, and a finalize deposit function taking the arguments (bank address, amount) that will update a public mapping with 50 credits. This information is queryable on-chain.
"
echo "
###############################################################################
######## ########
######## Step 1: aleo1zeklp...v46ngg deposits 50 tokens ########
######## ########
######## ----------------------------------------- ########
######## | ACTION | AMOUNT | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Issuing | 0 | ########
######## ----------------------------------------- ########
######## | Depositing | 50 | ########
######## ----------------------------------------- ########
######## | Withdrawing | 0 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | WALLET | aleo1zeklp...v46ngg | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 50 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | BANK | aleo1t0uer...f6st7a | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 50 | ########
######## ----------------------------------------- ########
######## | Periods | 0 | ########
######## ----------------------------------------- ########
######## | Interest Rate | 12.34% | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | TOTAL BALANCE | 100 | ########
######## ----------------------------------------- ########
######## ########
###############################################################################
"
echo "
With the 50 token deposit, let's say 15 periods of time pass with compounding interest at a rate of 12.34% on the principal amount.
###############################################################################
######## ########
######## Step 2: Wait 15 periods ########
######## ########
######## ----------------------------------------- ########
######## | ACTION | AMOUNT | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Issuing | 0 | ########
######## ----------------------------------------- ########
######## | Depositing | 0 | ########
######## ----------------------------------------- ########
######## | Withdrawing | 0 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | WALLET | aleo1zeklp...v46ngg | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 50 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | BANK | aleo1t0uer...f6st7a | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 266 | ########
######## ----------------------------------------- ########
######## | Periods | 15 | ########
######## ----------------------------------------- ########
######## | Interest Rate | 12.34% | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | TOTAL BALANCE | 316 | ########
######## ----------------------------------------- ########
######## ########
###############################################################################
"
echo "
Now, let's have the bank withdraw all tokens after 15 periods. Let's switch to the bank role, and call the withdraw transition function. The inputs are the recipient's address, amount, rate, and periods.
echo '
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD
' > .env
leo run withdraw aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 50u64 1234u64 15u64
"
# Swap in the private key of the bank to .env.
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpHtqVWT6fSHgUMNxsuVf7eaR6id2cj7TieKY1Z8CP5rCD
" > .env
# Have the bank withdraw all of the user's tokens with compound interest over 15 periods at 12.34%.
leo run withdraw aleo1zeklp6dd8e764spe74xez6f8w27dlua3w7hl4z2uln03re52egpsv46ngg 50u64 1234u64 15u64
echo "
You'll see here the withdrawal function creates a new private record for the user containing all 266 withdrawn tokens, and then calls the finalize withdraw function with arguments (address, amount), which will update the public balance of the bank back to 0. The public mapping will be queryable on-chain.
"
echo "
###############################################################################
######## ########
######## Step 3: Withdraw tokens of aleo1zeklp...v46ngg w/ interest ########
######## ########
######## ----------------------------------------- ########
######## | ACTION | AMOUNT | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Issuing | 0 | ########
######## ----------------------------------------- ########
######## | Depositing | 0 | ########
######## ----------------------------------------- ########
######## | Withdrawing | 266 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | WALLET | aleo1zeklp...v46ngg | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 316 | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | BANK | aleo1t0uer...f6st7a | ########
######## ----------------------------------------- ########
######## ----------------------------------------- ########
######## | Balance | 0 | ########
######## ----------------------------------------- ########
######## | Periods | 15 | ########
######## ----------------------------------------- ########
######## | Interest Rate | 12.34% | ########
######## ----------------------------------------- ########
######## ########
######## ----------------------------------------- ########
######## | TOTAL BALANCE | 316 | ########
######## ----------------------------------------- ########
######## ########
###############################################################################
"