Skip to content

Commit 9a3eb8e

Browse files
committed
feat: multi-msg generator
1 parent 1297b40 commit 9a3eb8e

File tree

1 file changed

+380
-0
lines changed

1 file changed

+380
-0
lines changed

_test/multi_msg_generator.ipynb

Lines changed: 380 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,380 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "600b6cee-59be-4817-be50-2a6ac0969106",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from string import Template \n",
11+
"\n",
12+
"from datetime import timezone \n",
13+
"import datetime "
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 2,
19+
"id": "6be7faf1-8c9e-4d07-a9af-ba9af0de0070",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"ADDR_GSA = \"g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4\"\n",
24+
"ADDR_LP01 = \"g1jqpr8r5akez83kp7ers0sfjyv2kgx45qa9qygd\"\n",
25+
"ADDR_LP02 = \"g126yz2f34qdxaqxelmky40dym379q0vw3yzhyrq\"\n",
26+
"ADDR_TR01 = \"g1wgdjecn5lylgvujzyspfzvhjm6qn4z8xqyyxdn\"\n",
27+
"\n",
28+
"ADDR_POOL = \"g1ee305k8yk0pjz443xpwtqdyep522f9g5r7d63w\"\n",
29+
"ADDR_POS = \"g1htpxzv2dkplvzg50nd8fswrneaxmdpwn459thx\"\n",
30+
"ADDR_STAKER = \"g13h5s9utqcwg3a655njen0p89txusjpfrs3vxp8\"\n",
31+
"ADDR_ROUTER = \"g1ernz3lj85hnn3ucug73ymgkhqdv2lg8e4yd48e\"\n",
32+
"ADDR_GOV = \"g1wj5lwwmkru3ky6dh2zztanrcj2ups8g0pfe8cu\"\n",
33+
"\n",
34+
"TX_EXPIRE = 9999999999"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 3,
40+
"id": "d9a73750-4014-4980-9ae8-5d6e8a31a1e0",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"# def deployer()"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"id": "4ca8146c-5126-44e8-aacc-25b91703b8a9",
51+
"metadata": {},
52+
"outputs": [],
53+
"source": []
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 4,
58+
"id": "3c65e446-26c3-44d7-b1b8-5a1f8c157516",
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"t = Template('{\"@type\":\"/vm.m_call\",\"caller\":\"$caller\",\"send\":\"$send\",\"pkg_path\":\"$pkg_path\",\"func\":\"$func\",\"args\":$args}')\n",
63+
"tna = Template('{\"@type\":\"/vm.m_call\",\"caller\":\"$caller\",\"send\":\"$send\",\"pkg_path\":\"$pkg_path\",\"func\":\"$func\"}')"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": 21,
69+
"id": "8ca0ce1f-5861-4dc6-b725-eaa9a2c8c8a7",
70+
"metadata": {},
71+
"outputs": [],
72+
"source": [
73+
"gsa_msgs = \"\"\n",
74+
"lp01_msgs = \"\"\n",
75+
"lp02_msgs = \"\"\n",
76+
"tr01_msgs = \"\""
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 39,
82+
"id": "383891f2-6da2-427c-b9db-b206e6d4ac3f",
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"def faucet_approve(msgs, caller, pkg_path, spender, amount):\n",
87+
" msg = tna.substitute(caller=caller, send='', pkg_path=pkg_path, func='FaucetL')\n",
88+
" msgs += msg\n",
89+
" msgs += \",\"\n",
90+
" \n",
91+
" msg = t.substitute(caller=caller, send='', pkg_path=pkg_path, func='Approve', args=f'[\"{spender}\",\"{amount}\"]')\n",
92+
" msgs += msg\n",
93+
" msgs += \",\"\n",
94+
" \n",
95+
" return msgs\n",
96+
"\n",
97+
"def approve(msgs, caller, pkg_path, spender, amount):\n",
98+
" msg = t.substitute(caller=caller, send='', pkg_path=pkg_path, func='Approve', args=f'[\"{spender}\",\"{amount}\"]')\n",
99+
" msgs += msg\n",
100+
" msgs += \",\"\n",
101+
" \n",
102+
" return msgs\n",
103+
"\n",
104+
"lp01_msgs = faucet_approve(lp01_msgs, ADDR_LP01, \"gno.land/r/foo\", ADDR_POOL, 50000000000)\n",
105+
"lp01_msgs = faucet_approve(lp01_msgs, ADDR_LP01, \"gno.land/r/bar\", ADDR_POOL, 50000000000)\n",
106+
"lp01_msgs = faucet_approve(lp01_msgs, ADDR_LP01, \"gno.land/r/baz\", ADDR_POOL, 50000000000)\n",
107+
"lp01_msgs = faucet_approve(lp01_msgs, ADDR_LP01, \"gno.land/r/qux\", ADDR_POOL, 50000000000)\n",
108+
"lp01_msgs = approve(lp01_msgs, ADDR_LP01, \"gno.land/r/wugnot\", ADDR_POOL, 50000000000)\n",
109+
"\n",
110+
"lp02_msgs = faucet_approve(lp02_msgs, ADDR_LP02, \"gno.land/r/foo\", ADDR_POOL, 50000000000)\n",
111+
"lp02_msgs = faucet_approve(lp02_msgs, ADDR_LP02, \"gno.land/r/bar\", ADDR_POOL, 50000000000)\n",
112+
"lp02_msgs = faucet_approve(lp02_msgs, ADDR_LP02, \"gno.land/r/baz\", ADDR_POOL, 50000000000)\n",
113+
"lp02_msgs = faucet_approve(lp02_msgs, ADDR_LP02, \"gno.land/r/qux\", ADDR_POOL, 50000000000)\n",
114+
"lp02_msgs = approve(lp02_msgs, ADDR_LP02, \"gno.land/r/wugnot\", ADDR_POOL, 50000000000)\n",
115+
"\n",
116+
"tr01_msgs = faucet_approve(tr01_msgs, ADDR_TR01, \"gno.land/r/foo\", ADDR_POOL, 50000000000)\n",
117+
"tr01_msgs = faucet_approve(tr01_msgs, ADDR_TR01, \"gno.land/r/bar\", ADDR_POOL, 50000000000)\n",
118+
"tr01_msgs = faucet_approve(tr01_msgs, ADDR_TR01, \"gno.land/r/baz\", ADDR_POOL, 50000000000)\n",
119+
"tr01_msgs = faucet_approve(tr01_msgs, ADDR_TR01, \"gno.land/r/qux\", ADDR_POOL, 50000000000)\n",
120+
"tr01_msgs = approve(tr01_msgs, ADDR_TR01, \"gno.land/r/wugnot\", ADDR_POOL, 50000000000)\n",
121+
"\n",
122+
"\n",
123+
"gsa_msgs = faucet_approve(gsa_msgs, ADDR_GSA, \"gno.land/r/foo\", ADDR_POOL, 50000000000)\n",
124+
"gsa_msgs = faucet_approve(gsa_msgs, ADDR_GSA, \"gno.land/r/bar\", ADDR_POOL, 50000000000)\n",
125+
"gsa_msgs = faucet_approve(gsa_msgs, ADDR_GSA, \"gno.land/r/baz\", ADDR_POOL, 50000000000)\n",
126+
"gsa_msgs = faucet_approve(gsa_msgs, ADDR_GSA, \"gno.land/r/qux\", ADDR_POOL, 50000000000)\n",
127+
"gsa_msgs = faucet_approve(gsa_msgs, ADDR_GSA, \"gno.land/r/gns\", ADDR_POOL, 50000000000)\n",
128+
"\n",
129+
"gsa_msgs = approve(gsa_msgs, ADDR_GSA, \"gno.land/r/gns\", ADDR_POOL, 50000000000)\n",
130+
"gsa_msgs = approve(gsa_msgs, ADDR_GSA, \"gno.land/r/wugnot\", ADDR_STAKER, 50000000000)"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": 41,
136+
"id": "71983033-2dee-4982-bf9e-b93638af09d8",
137+
"metadata": {},
138+
"outputs": [],
139+
"source": [
140+
"multi_msg_01 = lp01_msgs[:-1]\n",
141+
"multi_msg_01 = f'\"msg\":[{multi_msg_01}]'\n",
142+
"multi_msg_01 = '{' + multi_msg_01 + ',\"fee\":{\"gas_wanted\":\"9000000\",\"gas_fee\":\"1ugnot\"},\"signatures\":null,\"memo\":\"\"}'\n",
143+
"\n",
144+
"multi_msg_02 = lp02_msgs[:-1]\n",
145+
"multi_msg_02 = f'\"msg\":[{multi_msg_02}]'\n",
146+
"multi_msg_02 = '{' + multi_msg_02 + ',\"fee\":{\"gas_wanted\":\"9000000\",\"gas_fee\":\"1ugnot\"},\"signatures\":null,\"memo\":\"\"}'\n",
147+
"\n",
148+
"multi_msg_03 = tr01_msgs[:-1]\n",
149+
"multi_msg_03 = f'\"msg\":[{multi_msg_03}]'\n",
150+
"multi_msg_03 = '{' + multi_msg_03 + ',\"fee\":{\"gas_wanted\":\"9000000\",\"gas_fee\":\"1ugnot\"},\"signatures\":null,\"memo\":\"\"}'\n",
151+
"\n",
152+
"\n",
153+
"multi_msg_04 = gsa_msgs[:-1]\n",
154+
"multi_msg_04 = f'\"msg\":[{multi_msg_04}]'\n",
155+
"multi_msg_04 = '{' + multi_msg_04 + ',\"fee\":{\"gas_wanted\":\"9000000\",\"gas_fee\":\"1ugnot\"},\"signatures\":null,\"memo\":\"\"}'\n",
156+
"\n",
157+
"lp01_msgs = \"\"\n",
158+
"lp02_msgs = \"\"\n",
159+
"tr01_msgs = \"\"\n",
160+
"gsa_msgs = \"\"\n",
161+
"\n",
162+
"with open(\"multi_msg_01.txt\", \"w\") as f:\n",
163+
" f.write(multi_msg_01)\n",
164+
" \n",
165+
"with open(\"multi_msg_02.txt\", \"w\") as f:\n",
166+
" f.write(multi_msg_02)\n",
167+
" \n",
168+
"with open(\"multi_msg_03.txt\", \"w\") as f:\n",
169+
" f.write(multi_msg_03)\n",
170+
" \n",
171+
"with open(\"multi_msg_04.txt\", \"w\") as f:\n",
172+
" f.write(multi_msg_04)"
173+
]
174+
},
175+
{
176+
"cell_type": "code",
177+
"execution_count": 8,
178+
"id": "fe3f09fa-249b-470e-90b5-2c0c8aef747f",
179+
"metadata": {},
180+
"outputs": [],
181+
"source": [
182+
"def pool_init(msgs, caller):\n",
183+
" msg = tna.substitute(caller=caller, send='', pkg_path='gno.land/r/pool', func='InitManual')\n",
184+
" msgs += msg\n",
185+
" msgs += \",\"\n",
186+
" \n",
187+
" return msgs\n",
188+
" \n",
189+
"gsa_msgs = pool_init(gsa_msgs, ADDR_GSA)"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": 9,
195+
"id": "45ec520c-b0f3-4f0b-9d9f-fda2a8fde3c5",
196+
"metadata": {},
197+
"outputs": [],
198+
"source": [
199+
"def pool_create(msgs, caller, tokenA, tokenB, fee, sqrtX96):\n",
200+
" msg = t.substitute(caller=caller, send='', pkg_path='gno.land/r/pool', func='CreatePool', args=f'[\"{tokenA}\",\"{tokenB}\",\"{fee}\",\"{sqrtX96}\"]')\n",
201+
" msgs += msg\n",
202+
" msgs += \",\"\n",
203+
" \n",
204+
" return msgs\n",
205+
"\n",
206+
"gsa_msgs = pool_create(gsa_msgs, ADDR_GSA, \"gnot\", \"gno.land/r/bar\", 100, 101729702841318637793976746270)\n",
207+
"gsa_msgs = pool_create(gsa_msgs, ADDR_GSA, \"gno.land/r/bar\", \"gno.land/r/baz\", 100, 101729702841318637793976746270)\n",
208+
"gsa_msgs = pool_create(gsa_msgs, ADDR_GSA, \"gno.land/r/baz\", \"gno.land/r/qux\", 100, 101729702841318637793976746270)\n",
209+
"\n",
210+
"gsa_msgs = pool_create(gsa_msgs, ADDR_GSA, \"gnot\", \"gno.land/r/bar\", 500, 101729702841318637793976746270)\n",
211+
"gsa_msgs = pool_create(gsa_msgs, ADDR_GSA, \"gno.land/r/bar\", \"gno.land/r/baz\", 500, 101729702841318637793976746270)\n",
212+
"gsa_msgs = pool_create(gsa_msgs, ADDR_GSA, \"gno.land/r/baz\", \"gno.land/r/qux\", 500, 101729702841318637793976746270)"
213+
]
214+
},
215+
{
216+
"cell_type": "code",
217+
"execution_count": 10,
218+
"id": "b1e91bc5-1850-4abe-a95d-5aac9da5a37e",
219+
"metadata": {},
220+
"outputs": [],
221+
"source": [
222+
"def position_mint(msgs, caller, send, tokenA, tokenB, fee, minTick, maxTick, maxA, maxB, minA, minB): \n",
223+
" msg = t.substitute(caller=caller, send=send, pkg_path='gno.land/r/position', func='Mint', args=f'[\"{tokenA}\",\"{tokenB}\",\"{fee}\",\"{minTick}\",\"{maxTick}\",\"{maxA}\",\"{maxB}\",\"{minA}\",\"{minB}\",\"{TX_EXPIRE}\"]')\n",
224+
" msgs += msg\n",
225+
" msgs += \",\"\n",
226+
"\n",
227+
" return msgs\n",
228+
"\n",
229+
" \n",
230+
"lp01_msgs = position_mint(lp01_msgs, ADDR_LP01, \"10000000ugnot\", \"gnot\", \"gno.land/r/bar\", 100, 4000, 6000, 10000000, 10000000, 0, 0)\n",
231+
"lp02_msgs = position_mint(lp02_msgs, ADDR_LP02, \"\", \"gno.land/r/bar\", \"gno.land/r/baz\", 100, 4000, 6000, 10000000, 10000000, 0, 0)\n",
232+
"lp02_msgs = position_mint(lp02_msgs, ADDR_LP02, \"\", \"gno.land/r/baz\", \"gno.land/r/qux\", 100, 4000, 6000, 10000000, 10000000, 0, 0)\n",
233+
"\n",
234+
"lp01_msgs = position_mint(lp01_msgs, ADDR_LP01, \"10000000ugnot\", \"gnot\", \"gno.land/r/bar\", 500, 4000, 6000, 10000000, 10000000, 0, 0)\n",
235+
"lp02_msgs = position_mint(lp02_msgs, ADDR_LP02, \"\", \"gno.land/r/bar\", \"gno.land/r/baz\", 500, 4000, 6000, 10000000, 10000000, 0, 0)\n",
236+
"lp02_msgs = position_mint(lp02_msgs, ADDR_LP02, \"\", \"gno.land/r/baz\", \"gno.land/r/qux\", 500, 4000, 6000, 10000000, 10000000, 0, 0)"
237+
]
238+
},
239+
{
240+
"cell_type": "code",
241+
"execution_count": 11,
242+
"id": "703d1455-08a9-4510-8d1b-9da78dc24a09",
243+
"metadata": {},
244+
"outputs": [],
245+
"source": [
246+
"def staker_create(msgs, caller, send, targetPath, rewardToken, rewardAmount, startTime, endTime):\n",
247+
" msg = t.substitute(caller=caller, send=send, pkg_path='gno.land/r/staker', func='CreateExternalIncentive', args=f'[\"{targetPath}\",\"{rewardToken}\",\"{rewardAmount}\",\"{startTime}\",\"{endTime}\"]')\n",
248+
" msgs += msg\n",
249+
" msgs += \",\"\n",
250+
" \n",
251+
" return msgs\n",
252+
"\n",
253+
" \n",
254+
"dt = datetime.datetime.now(timezone.utc) \n",
255+
"utc_time = dt.replace(tzinfo=timezone.utc) \n",
256+
"utc_timestamp = utc_time.timestamp() \n",
257+
"\n",
258+
"incentive_start = utc_timestamp\n",
259+
"incentive_end = incentive_start + 100\n",
260+
"\n",
261+
"gsa_msgs = staker_create(gsa_msgs, ADDR_GSA, \"\", \"gno.land/r/bar:gnot:10\", \"gno.land/r/obl\", \"10000000000\", incentive_start, incentive_end)"
262+
]
263+
},
264+
{
265+
"cell_type": "code",
266+
"execution_count": 12,
267+
"id": "1d2df3eb-e451-4d76-9ced-b04f09075f17",
268+
"metadata": {},
269+
"outputs": [],
270+
"source": [
271+
"def staker_stake(msgs, caller, tokenId):\n",
272+
" msg = t.substitute(caller=caller, send='', pkg_path='gno.land/r/gnft', func='Approve', args=f'[\"{ADDR_STAKER}\",\"{tokenId}\"]')\n",
273+
" msgs += msg\n",
274+
" msgs += \",\"\n",
275+
" \n",
276+
" msg = t.substitute(caller=caller, send='', pkg_path='gno.land/r/staker', func='StakeToken', args=f'[\"{tokenId}\"]')\n",
277+
" msgs += msg\n",
278+
" msgs += \",\"\n",
279+
" \n",
280+
" return msgs\n",
281+
" \n",
282+
" \n",
283+
"lp01_msgs = staker_stake(lp01_msgs, ADDR_LP01, 1)\n",
284+
"lp02_msgs = staker_stake(lp02_msgs, ADDR_LP02, 2)"
285+
]
286+
},
287+
{
288+
"cell_type": "code",
289+
"execution_count": 13,
290+
"id": "a3e43c08-5cb6-4b2d-9cfc-db4edb528d85",
291+
"metadata": {},
292+
"outputs": [],
293+
"source": [
294+
"def pool_set_protocol_fee(msgs, caller, feeA, feeB): \n",
295+
" msg = t.substitute(caller=caller, send='', pkg_path='gno.land/r/pool', func='SetFeeProtocol', args=f'[\"{feeA}\",\"{feeB}\"]')\n",
296+
" msgs += msg\n",
297+
" msgs += \",\"\n",
298+
" \n",
299+
" return msgs\n",
300+
" \n",
301+
" \n",
302+
"gsa_msgs = pool_set_protocol_fee(gsa_msgs, ADDR_GSA, 6, 8)"
303+
]
304+
},
305+
{
306+
"cell_type": "code",
307+
"execution_count": 28,
308+
"id": "73e9e677-99c6-4f2a-b980-a91fb4e3d2cb",
309+
"metadata": {},
310+
"outputs": [],
311+
"source": [
312+
"def router_swap(msgs, caller, send, tokenIn, tokenOut, amountSpecified, swapType, strRoutes, strQuotes, swapResultLimit):\n",
313+
" msg = t.substitute(caller=caller, send=send, pkg_path='gno.land/r/router', func='SwapRoute', args=f'[\"{tokenIn}\",\"{tokenOut}\",\"{amountSpecified}\",\"{swapType}\",\"{strRoutes}\",\"{strQuotes}\",\"{swapResultLimit}\"]')\n",
314+
" msgs += msg\n",
315+
" msgs += \",\"\n",
316+
" \n",
317+
" return msgs\n",
318+
"\n",
319+
" \n",
320+
"tr01_msgs = router_swap(tr01_msgs, ADDR_TR01, \"\", \"gno.land/r/bar\", \"gno.land/r/baz\", 123456, \"EXACT_IN\", \"gno.land/r/bar:gno.land/r/baz:100\", \"100\", 200000)\n",
321+
"tr01_msgs = router_swap(tr01_msgs, ADDR_TR01, \"100000000ugnot\", \"gnot\", \"gno.land/r/qux\", 987654, \"EXACT_OUT\", \"gnot:gno.land/r/bar:100*POOL*gno.land/r/bar:gno.land/r/baz:100*POOL*gno.land/r/baz:gno.land/r/qux:100,gnot:gno.land/r/bar:500*POOL*gno.land/r/bar:gno.land/r/baz:500*POOL*gno.land/r/baz:gno.land/r/qux:500\", \"40,60\", 654321)"
322+
]
323+
},
324+
{
325+
"cell_type": "code",
326+
"execution_count": 30,
327+
"id": "80075f54-d4f1-488c-a1d1-2e6fd83e508c",
328+
"metadata": {},
329+
"outputs": [],
330+
"source": [
331+
"def position_collect(msgs, caller, tokenId, recipient, amount0, amount1):\n",
332+
" msg = t.substitute(caller=caller, send='', pkg_path='gno.land/r/position', func='Collect', args=f'[\"{tokenId}\",\"{recipient}\",\"{amount0}\",\"{amount1}\"]')\n",
333+
" msgs += msg\n",
334+
" msgs += \",\"\n",
335+
" \n",
336+
" return msgs\n",
337+
" \n",
338+
"\n",
339+
"lp01_msgs = position_collect(lp01_msgs, ADDR_LP01, 1, ADDR_LP01, 1000000, 1000000)\n",
340+
"lp01_msgs = position_collect(lp01_msgs, ADDR_LP02, 2, ADDR_LP01, 1000000, 1000000)"
341+
]
342+
},
343+
{
344+
"cell_type": "code",
345+
"execution_count": 16,
346+
"id": "9a4bc660-4a16-4c5c-9487-70f7ee745517",
347+
"metadata": {},
348+
"outputs": [],
349+
"source": [
350+
"def staker_unstake(msgs, caller, tokenId):\n",
351+
" msg = t.substitute(caller=caller, send='', pkg_path='gno.land/r/staker', func='UnstakeToken', args=f'[\"{tokenId}\"]')\n",
352+
" msgs += msg\n",
353+
" msgs += \",\"\n",
354+
" \n",
355+
" return msgs"
356+
]
357+
}
358+
],
359+
"metadata": {
360+
"kernelspec": {
361+
"display_name": "Python 3 (ipykernel)",
362+
"language": "python",
363+
"name": "python3"
364+
},
365+
"language_info": {
366+
"codemirror_mode": {
367+
"name": "ipython",
368+
"version": 3
369+
},
370+
"file_extension": ".py",
371+
"mimetype": "text/x-python",
372+
"name": "python",
373+
"nbconvert_exporter": "python",
374+
"pygments_lexer": "ipython3",
375+
"version": "3.9.10"
376+
}
377+
},
378+
"nbformat": 4,
379+
"nbformat_minor": 5
380+
}

0 commit comments

Comments
 (0)