mango-explorer/bin/show-wrapped-sol

43 lines
1.6 KiB
Plaintext
Raw Normal View History

2021-06-02 12:03:46 -07:00
#!/usr/bin/env pyston3
import argparse
import logging
import os
import sys
2021-06-02 12:03:46 -07:00
sys.path.insert(0, os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')))
import mango # nopep8
2021-06-02 12:03:46 -07:00
parser = argparse.ArgumentParser(description="Shows all Wrapped SOL accounts for the wallet.")
mango.Context.add_context_command_line_parameters(parser)
2021-06-02 12:03:46 -07:00
parser.add_argument("--id-file", type=str, default="id.json",
help="file containing the JSON-formatted wallet private key")
parser.add_argument("--log-level", default=logging.WARNING, type=lambda level: getattr(logging, level),
help="level of verbosity to log (possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL)")
parser.add_argument("--overwrite", action="store_true", default=False,
help="overwrite the ID file, if it exists (use with care!)")
args = parser.parse_args()
logging.getLogger().setLevel(args.log_level)
logging.warning(mango.WARNING_DISCLAIMER_TEXT)
2021-06-02 12:03:46 -07:00
id_filename = args.id_file
if not os.path.isfile(id_filename):
logging.error(f"Wallet file '{id_filename}' is not present.")
sys.exit(1)
wallet = mango.Wallet.load(id_filename)
context = mango.Context.from_context_command_line_parameters(args)
2021-06-02 12:03:46 -07:00
lookups = mango.TokenLookup.default_lookups()
2021-06-02 12:03:46 -07:00
wrapped_sol = lookups.find_by_symbol("SOL")
token_accounts = mango.TokenAccount.fetch_all_for_owner_and_token(context, wallet.address, wrapped_sol)
2021-06-02 12:03:46 -07:00
if len(token_accounts) == 0:
print("No wrapped SOL accounts.")
2021-06-02 12:03:46 -07:00
else:
print(f"{wrapped_sol.name}:")
for account in token_accounts:
print(f" {account.address}: {account.value}")