-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathpublic_pool_create_modify.py
More file actions
59 lines (50 loc) · 1.79 KB
/
Copy pathpublic_pool_create_modify.py
File metadata and controls
59 lines (50 loc) · 1.79 KB
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
import time
import json
import asyncio
import lighter
from utils import default_example_setup
async def main():
client, api_client, _ = default_example_setup()
tx_api = lighter.TransactionApi(api_client)
err = client.check_client()
if err is not None:
print(f"CheckClient error: {err}")
return
auth, _ = client.create_auth_token_with_expiry()
# create a public pool
tx_info, response, err = await client.create_public_pool(
operator_fee=100000, # 10%
initial_total_shares=1_000_000, # 1000 USDC
min_operator_share_rate=100, # 1%
)
if err is not None:
raise Exception(f'failed to create public pool {err}')
tx_hash = response.tx_hash
print(f"✅ send create public pool tx. hash: {tx_hash}")
# fetch pool account index from tx hash
pool_account_index = -1
for i in range(10):
time.sleep(1)
try:
response = await tx_api.tx(by="hash", value=tx_hash)
event_info_j = json.loads(response.event_info)
pool_account_index = event_info_j['a']
except Exception as e:
pass
if pool_account_index != -1:
break
if pool_account_index == -1:
raise Exception(f"failed to find pool account index for tx {tx_hash}")
print(f"✅ pool account index: {pool_account_index}")
# Note: ❗️operator_fee can only decrease
# modify pool metadata
tx_info, response, err = await client.update_public_pool(
public_pool_index=pool_account_index,
status=0, # 0 is active | 1 is frozen
operator_fee=50000, # 5%
min_operator_share_rate=1000, # 10%
)
if err is not None:
raise Exception(f'failed to create update pool {err}')
if __name__ == "__main__":
asyncio.run(main())