~cytrogen/evi-run

ref: 7feec6fc5e0e3a97d110a3cf8691b6165e2e2080 evi-run/bot/utils/solana_funcs.py -rw-r--r-- 1.2 KiB
7feec6fc — Bendy Fixed a web search issue. DEX analytics is separated into a separate agent. Some other tool routing errors have been fixed. 5 months ago
                                                                                
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
from solana.rpc.async_api import AsyncClient
from solana.rpc.types import Pubkey, TokenAccountOpts
from solders.keypair import Keypair


async def get_balances(secret: list, client: AsyncClient):
    list_balances = []
    keypair = Keypair.from_bytes(bytes(secret))
    public_key = str(keypair.pubkey())

    balance_lamports = await client.get_balance(Pubkey.from_string(public_key))
    list_balances.append(str(balance_lamports.value / 1_000_000_000) + ' SOL')
    try:
        tokens_balances = await client.get_token_accounts_by_owner(owner=Pubkey.from_string(public_key),
                                                  opts=TokenAccountOpts(program_id=Pubkey.from_string(
                                                      'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA')),
                                                  )
        for token in tokens_balances.value:
            b = bytes(token.account.data)
            mint = Pubkey.from_bytes(b[0:32])
            amount = int.from_bytes(b[64:72], "little")
            list_balances.append(str(amount) + ' ' + f'{str(mint)[:4]}...{str(mint)[-4:]}')
    except Exception as e:
        print(e)
        pass

    return list_balances, public_key