|
14 | 14 | API_KEY_INDEX = 3 |
15 | 15 | NUM_API_KEYS = 5 |
16 | 16 |
|
| 17 | +# If you set this to something other than None, the script will use that account index instead of using the master account index. |
| 18 | +# This is useful if you have multiple accounts on the same L1 address or are the owner of a public pool. |
| 19 | +# You need to use the private key associated to the master account or the owner of the public pool to change the API keys. |
| 20 | +ACCOUNT_INDEX = None |
17 | 21 |
|
18 | 22 | async def main(): |
19 | 23 | # verify that the account exists & fetch account index |
20 | 24 | api_client = lighter.ApiClient(configuration=lighter.Configuration(host=BASE_URL)) |
21 | 25 | eth_acc = eth_account.Account.from_key(ETH_PRIVATE_KEY) |
22 | 26 | eth_address = eth_acc.address |
23 | 27 |
|
24 | | - try: |
25 | | - response = await lighter.AccountApi(api_client).accounts_by_l1_address( |
26 | | - l1_address=eth_address |
27 | | - ) |
28 | | - except lighter.ApiException as e: |
29 | | - if e.data.message == "account not found": |
30 | | - print(f"error: account not found for {eth_address}") |
31 | | - return |
| 28 | + if ACCOUNT_INDEX is not None: |
| 29 | + account_index = ACCOUNT_INDEX |
| 30 | + else: |
| 31 | + try: |
| 32 | + response = await lighter.AccountApi(api_client).accounts_by_l1_address(l1_address=eth_address) |
| 33 | + except lighter.ApiException as e: |
| 34 | + if e.data.message == "account not found": |
| 35 | + print(f"error: account not found for {eth_address}") |
| 36 | + return |
| 37 | + else: |
| 38 | + raise e |
| 39 | + |
| 40 | + if len(response.sub_accounts) > 1: |
| 41 | + for sub_account in response.sub_accounts: |
| 42 | + print(f"found accountIndex: {sub_account.index}") |
| 43 | + |
| 44 | + account = min(response.sub_accounts, key=lambda x: int(x.index)) |
| 45 | + account_index = account.index |
| 46 | + print(f"multiple accounts found, using the master account {account_index}") |
32 | 47 | else: |
33 | | - raise e |
| 48 | + account_index = response.sub_accounts[0].index |
34 | 49 |
|
35 | | - if len(response.sub_accounts) > 1: |
36 | | - for sub_account in response.sub_accounts: |
37 | | - print(f"found accountIndex: {sub_account.index}") |
38 | | - |
39 | | - print("multiple accounts found, using the first one") |
40 | | - account_index = response.sub_accounts[0].index |
41 | | - else: |
42 | | - account_index = response.sub_accounts[0].index |
43 | 50 |
|
44 | 51 | # create a private/public key pair for the new API key |
45 | 52 | # pass any string to be used as seed for create_api_key like |
|
0 commit comments