|
| 1 | +import asyncio |
| 2 | +from decimal import Decimal |
| 3 | +from typing import Any, List, Tuple |
| 4 | + |
| 5 | +import pyinjective.constant as constant |
| 6 | +from pyinjective.async_client import AsyncClient |
| 7 | +from pyinjective.constant import Network |
| 8 | +from pyinjective.core.market import SpotMarket, DerivativeMarket, BinaryOptionMarket |
| 9 | + |
| 10 | + |
| 11 | +def find_metadata_inconsistencies(network: Network) -> Tuple[List[Any]]: |
| 12 | + client = AsyncClient(network, insecure=False) |
| 13 | + |
| 14 | + spot_markets = asyncio.get_event_loop().run_until_complete(client.all_spot_markets()) |
| 15 | + derivative_markets = asyncio.get_event_loop().run_until_complete(client.all_derivative_markets()) |
| 16 | + binary_option_markets = asyncio.get_event_loop().run_until_complete(client.all_binary_option_markets()) |
| 17 | + all_tokens = asyncio.get_event_loop().run_until_complete(client.all_tokens()) |
| 18 | + |
| 19 | + markets_not_found = [] |
| 20 | + markets_with_diffs = [] |
| 21 | + peggy_denoms_not_found = [] |
| 22 | + peggy_denoms_with_diffs = [] |
| 23 | + |
| 24 | + for config_key in constant.mainnet_config: |
| 25 | + if config_key.startswith("0x"): |
| 26 | + denom = constant.Denom.load_market(network=network.string(), market_id=config_key) |
| 27 | + if config_key in spot_markets: |
| 28 | + market: SpotMarket = spot_markets[config_key] |
| 29 | + if (market.base_token.decimals != denom.base |
| 30 | + or market.quote_token.decimals != denom.quote |
| 31 | + or market.min_price_tick_size != Decimal(str(denom.min_price_tick_size)) |
| 32 | + or market.min_quantity_tick_size != Decimal(str(denom.min_quantity_tick_size))): |
| 33 | + markets_with_diffs.append([ |
| 34 | + {"denom-market": config_key, "base_decimals": denom.base, "quote_decimals": denom.quote, |
| 35 | + "min_quantity_tick_size": denom.min_quantity_tick_size, |
| 36 | + "min_price_tick_size": denom.min_price_tick_size}, |
| 37 | + {"newer-market": market.id, "base_decimals": market.base_token.decimals, |
| 38 | + "quote_decimals": market.quote_token.decimals, |
| 39 | + "min_quantity_tick_size": float(market.min_quantity_tick_size), |
| 40 | + "min_price_tick_size": float(market.min_price_tick_size), "ticker": market.ticker}, |
| 41 | + ]) |
| 42 | + elif config_key in derivative_markets: |
| 43 | + market: DerivativeMarket = derivative_markets[config_key] |
| 44 | + if (market.quote_token.decimals != denom.quote |
| 45 | + or market.min_price_tick_size != Decimal(str(denom.min_price_tick_size)) |
| 46 | + or market.min_quantity_tick_size != Decimal(str(denom.min_quantity_tick_size))): |
| 47 | + markets_with_diffs.append([ |
| 48 | + {"denom-market": config_key, "quote_decimals": denom.quote, |
| 49 | + "min_quantity_tick_size": denom.min_quantity_tick_size, |
| 50 | + "min_price_tick_size": denom.min_price_tick_size}, |
| 51 | + {"newer-market": market.id, "quote_decimals": market.quote_token.decimals, |
| 52 | + "min_quantity_tick_size": float(market.min_quantity_tick_size), |
| 53 | + "min_price_tick_size": float(market.min_price_tick_size), "ticker": market.ticker}, |
| 54 | + ]) |
| 55 | + elif config_key in binary_option_markets: |
| 56 | + market: BinaryOptionMarket = binary_option_markets[config_key] |
| 57 | + if (market.quote_token.decimals != denom.quote |
| 58 | + or market.min_price_tick_size != Decimal(str(denom.min_price_tick_size)) |
| 59 | + or market.min_quantity_tick_size != Decimal(str(denom.min_quantity_tick_size))): |
| 60 | + markets_with_diffs.append([ |
| 61 | + {"denom-market": config_key, "quote_decimals": denom.quote, |
| 62 | + "min_quantity_tick_size": denom.min_quantity_tick_size, |
| 63 | + "min_price_tick_size": denom.min_price_tick_size}, |
| 64 | + {"newer-market": market.id, "quote_decimals": market.quote_token.decimals, |
| 65 | + "min_quantity_tick_size": float(market.min_quantity_tick_size), |
| 66 | + "min_price_tick_size": float(market.min_price_tick_size), "ticker": market.ticker}, |
| 67 | + ]) |
| 68 | + else: |
| 69 | + markets_not_found.append({"denom-market": config_key, "description": denom.description}) |
| 70 | + |
| 71 | + elif config_key == "DEFAULT": |
| 72 | + continue |
| 73 | + else: |
| 74 | + # the configuration is a token |
| 75 | + peggy_denom, decimals = constant.Denom.load_peggy_denom(network=network.string(), symbol=config_key) |
| 76 | + if config_key in all_tokens: |
| 77 | + token = all_tokens[config_key] |
| 78 | + if (token.denom != peggy_denom |
| 79 | + or token.decimals != decimals): |
| 80 | + peggy_denoms_with_diffs.append([ |
| 81 | + {"denom_token": config_key, "peggy_denom": peggy_denom, "decimals": decimals}, |
| 82 | + {"newer_token": token.symbol, "peggy_denom": token.denom, "decimals": token.decimals} |
| 83 | + ]) |
| 84 | + else: |
| 85 | + peggy_denoms_not_found.append( |
| 86 | + {"denom_token": config_key, "peggy_denom": peggy_denom, "decimals": decimals}) |
| 87 | + |
| 88 | + return markets_with_diffs, markets_not_found, peggy_denoms_with_diffs, peggy_denoms_not_found |
| 89 | + |
| 90 | + |
| 91 | +def print_metadata_mismatches(network: Network): |
| 92 | + markets_with_diffs, markets_not_found, peggy_denoms_with_diffs, peggy_denoms_not_found = find_metadata_inconsistencies( |
| 93 | + network=network) |
| 94 | + |
| 95 | + for diff_pair in markets_with_diffs: |
| 96 | + print(f"{diff_pair[0]}\n{diff_pair[1]}") |
| 97 | + print(f"\n\n") |
| 98 | + for missing_market in markets_not_found: |
| 99 | + print(f"{missing_market}") |
| 100 | + print(f"\n\n") |
| 101 | + for diff_token in peggy_denoms_with_diffs: |
| 102 | + print(f"{diff_token[0]}\n{diff_token[1]}") |
| 103 | + print(f"\n\n") |
| 104 | + for missing_peggy in peggy_denoms_not_found: |
| 105 | + print(f"{missing_peggy}") |
0 commit comments