|
| 1 | +import time |
| 2 | +import json |
| 3 | +import asyncio |
| 4 | +import lighter |
| 5 | +from utils import default_example_setup |
| 6 | + |
| 7 | + |
| 8 | +async def main(): |
| 9 | + client, api_client, _ = default_example_setup() |
| 10 | + tx_api = lighter.TransactionApi(api_client) |
| 11 | + |
| 12 | + err = client.check_client() |
| 13 | + if err is not None: |
| 14 | + print(f"CheckClient error: {err}") |
| 15 | + return |
| 16 | + |
| 17 | + auth, _ = client.create_auth_token_with_expiry() |
| 18 | + |
| 19 | + # create a public pool |
| 20 | + tx_info, response, err = await client.create_public_pool( |
| 21 | + operator_fee=100000, # 10% |
| 22 | + initial_total_shares=1_000_000, # 1000 USDC |
| 23 | + min_operator_share_rate=100, # 1% |
| 24 | + ) |
| 25 | + if err is not None: |
| 26 | + raise Exception(f'failed to create public pool {err}') |
| 27 | + tx_hash = response.tx_hash |
| 28 | + print(f"✅ send create public pool tx. hash: {tx_hash}") |
| 29 | + |
| 30 | + # fetch pool account index from tx hash |
| 31 | + pool_account_index = -1 |
| 32 | + for i in range(10): |
| 33 | + time.sleep(1) |
| 34 | + try: |
| 35 | + response = await tx_api.tx(by="hash", value=tx_hash) |
| 36 | + event_info_j = json.loads(response.event_info) |
| 37 | + pool_account_index = event_info_j['a'] |
| 38 | + except Exception as e: |
| 39 | + pass |
| 40 | + if pool_account_index != -1: |
| 41 | + break |
| 42 | + if pool_account_index == -1: |
| 43 | + raise Exception(f"failed to find pool account index for tx {tx_hash}") |
| 44 | + print(f"✅ pool account index: {pool_account_index}") |
| 45 | + |
| 46 | + # Note: ❗️operator_fee can only decrease |
| 47 | + # modify pool metadata |
| 48 | + tx_info, response, err = await client.update_public_pool( |
| 49 | + public_pool_index=pool_account_index, |
| 50 | + status=0, # 0 is active | 1 is frozen |
| 51 | + operator_fee=50000, # 5% |
| 52 | + min_operator_share_rate=1000, # 10% |
| 53 | + ) |
| 54 | + if err is not None: |
| 55 | + raise Exception(f'failed to create update pool {err}') |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + asyncio.run(main()) |
0 commit comments