diff --git a/bin/show-address b/bin/show-address index a8c0fe22..85544f94 100755 --- a/bin/show-address +++ b/bin/show-address @@ -28,4 +28,4 @@ account_info: typing.Optional[mango.AccountInfo] = mango.AccountInfo.load(contex if account_info is None: raise Exception(f"No account found at address: {args.address}") -print(converter(account_info)) +mango.output(converter(account_info)) diff --git a/mango/accountinfoconverter.py b/mango/accountinfoconverter.py index 3d176119..d5ee449a 100644 --- a/mango/accountinfoconverter.py +++ b/mango/accountinfoconverter.py @@ -18,6 +18,8 @@ from decimal import Decimal +from solana.publickey import PublicKey + from .account import Account from .accountinfo import AccountInfo from .addressableaccount import AddressableAccount @@ -27,10 +29,12 @@ from .layouts import layouts from .lotsizeconverter import NullLotSizeConverter from .openorders import OpenOrders +from .orderbookside import PerpOrderBookSide from .perpeventqueue import PerpEventQueue from .perpmarketdetails import PerpMarketDetails from .serumeventqueue import SerumEventQueue -from .tokenbank import NodeBank, RootBank +from .token import Instrument, Token +from .tokenbank import NodeBank, RootBank, TokenBank # # 🥭 build_account_info_converter function @@ -69,5 +73,15 @@ def perp_market_details_loader(account_info: AccountInfo) -> PerpMarketDetails: group: Group = Group.load(context, group_address) return PerpMarketDetails.parse(account_info, group) return perp_market_details_loader + elif account_type_upper == "PERPORDERBOOKSIDE": + class __FakePerpMarketDetails(PerpMarketDetails): + def __init__(self) -> None: + self.base_instrument = Instrument("UNKNOWNBASE", "Unknown Base", Decimal(0)) + self.quote_token = TokenBank(Token("UNKNOWNQUOTE", "Unknown Quote", + Decimal(0), PublicKey(0)), PublicKey(0)) + self.base_lot_size = Decimal(1) + self.quote_lot_size = Decimal(1) + + return lambda account_info: PerpOrderBookSide.parse(account_info, __FakePerpMarketDetails()) raise Exception(f"Could not find AccountInfo converter for type {account_type}.") diff --git a/mango/arguments.py b/mango/arguments.py index 98f5cfaa..52e1fad8 100644 --- a/mango/arguments.py +++ b/mango/arguments.py @@ -14,6 +14,7 @@ # [Email](mailto:hello@blockworks.foundation) import argparse +import collections import enum import json import jsons @@ -52,7 +53,11 @@ def output(obj: typing.Any) -> None: print(json.dumps(jsons.dump(obj, strip_attr=("data", "logger", "lot_size_converter", "tokens", "tokens_by_index", "slots", "base_tokens", "base_tokens_by_index", "oracles", "oracles_by_index", "spot_markets", "spot_markets_by_index", "perp_markets", "perp_markets_by_index", "shared_quote_token", "liquidity_incentive_token"), key_transformer=jsons.KEY_TRANSFORMER_CAMELCASE), sort_keys=True, indent=4)) else: - print(obj) + if isinstance(obj, collections.Sequence) and not isinstance(obj, str): + for item in obj: + print(item) + else: + print(obj) # # 🥭 parse_args