diff --git a/src/setup.py b/src/setup.py index a225f4a..e9c9d53 100644 --- a/src/setup.py +++ b/src/setup.py @@ -2,7 +2,7 @@ setup( name="synthetix", - version="0.1.21", + version="0.1.22", description="Synthetix protocol SDK", long_description=open("README.md").read(), long_description_content_type="text/markdown", @@ -24,6 +24,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ], python_requires=">=3.8", include_package_data=True, diff --git a/src/synthetix/contracts/contracts.py b/src/synthetix/contracts/contracts.py index 6bce72c..8482893 100644 --- a/src/synthetix/contracts/contracts.py +++ b/src/synthetix/contracts/contracts.py @@ -1,6 +1,5 @@ import os import json -import glob import zlib import requests from web3 import Web3 diff --git a/src/synthetix/perps/perps.py b/src/synthetix/perps/perps.py index a3d5307..80654df 100644 --- a/src/synthetix/perps/perps.py +++ b/src/synthetix/perps/perps.py @@ -1,7 +1,7 @@ """Modules for interacting with Synthetix Perps.""" import time -from eth_utils import encode_hex, decode_hex +from eth_utils import encode_hex from ..utils import ether_to_wei, wei_to_ether from ..utils.multicall import ( call_erc7412, @@ -1157,10 +1157,8 @@ def settle_order( elif expiration_time < now_time: raise ValueError(f"Order has expired for account {account_id}") else: - self.logger.info(f"Order is ready to be settled") + self.logger.info("Order is ready to be settled") - # get fresh prices to provide to the oracle - market_name = self._resolve_market(order["market_id"], None)[1] # prepare the transaction tx_tries = 0 while tx_tries < max_tx_tries: @@ -1741,9 +1739,9 @@ def settle_order( min_publish_delay = self.market_meta[market_id]["system_config"][ "pyth_publish_time_min" ] - max_publish_delay = self.market_meta[market_id]["system_config"][ - "pyth_publish_time_max" - ] + # max_publish_delay = self.market_meta[market_id]["system_config"][ + # "pyth_publish_time_max" + # ] commitment_time = order["commitment_time"] publish_time = commitment_time + min_publish_delay diff --git a/src/synthetix/spot/spot.py b/src/synthetix/spot/spot.py index f49f629..4c5c998 100644 --- a/src/synthetix/spot/spot.py +++ b/src/synthetix/spot/spot.py @@ -7,7 +7,6 @@ from web3.constants import ADDRESS_ZERO from typing import Literal import time -import requests class Spot: diff --git a/src/synthetix/synthetix.py b/src/synthetix/synthetix.py index c9af491..3fe9d21 100644 --- a/src/synthetix/synthetix.py +++ b/src/synthetix/synthetix.py @@ -5,7 +5,6 @@ from web3.constants import ADDRESS_ZERO from web3.types import TxParams from .constants import ( - DEFAULT_NETWORK_ID, DEFAULT_TRACKING_CODE, DEFAULT_SLIPPAGE, DEFAULT_GAS_MULTIPLIER, @@ -13,7 +12,6 @@ DEFAULT_GQL_ENDPOINT_RATES, DEFAULT_PRICE_SERVICE_ENDPOINT, DEFAULT_REFERRER, - DEFAULT_TRACKING_CODE, ) from .utils import wei_to_ether, ether_to_wei from .contracts import load_contracts @@ -296,12 +294,11 @@ def _load_contracts(self): marketdata_contract.functions.allProxiedMarketSummaries().call() ) except Exception as e: + self.logger.error(f"Error loading markets: {e}") allmarketsdata = [] markets = { - market[2] - .decode("utf-8") - .strip("\x00")[1:-4]: { + market[2].decode("utf-8").strip("\x00")[1:-4]: { "market_address": market[0], "asset": market[1].decode("utf-8").strip("\x00"), "key": market[2], @@ -349,11 +346,13 @@ def _load_contracts(self): # load multicall contract if ( "system" in self.contracts - and "trusted_multicall_forwarder" in self.contracts["system"] + and "oracle_manager" in self.contracts["system"] + and "trusted_multicall_forwarder" + in self.contracts["system"]["oracle_manager"] ): - mc_definition = self.contracts["system"]["trusted_multicall_forwarder"][ - "TrustedMulticallForwarder" - ] + mc_definition = self.contracts["system"]["oracle_manager"][ + "trusted_multicall_forwarder" + ]["TrustedMulticallForwarder"] mc_address = w3.to_checksum_address(mc_definition["address"]) multicall = w3.eth.contract(mc_address, abi=mc_definition["abi"]) diff --git a/src/synthetix/utils/multicall.py b/src/synthetix/utils/multicall.py index c62fdd3..7085b31 100644 --- a/src/synthetix/utils/multicall.py +++ b/src/synthetix/utils/multicall.py @@ -1,6 +1,4 @@ from eth_typing import HexStr -import requests -import base64 from web3.exceptions import ContractCustomError from web3._utils.abi import get_abi_output_types from eth_abi import decode, encode @@ -44,7 +42,8 @@ def decode_erc7412_oracle_data_required_error(snx, error): output_types = ["address", "bytes", "uint256"] try: address, data, fee = decode(output_types, error_data) - except: + except Exception as e: + snx.logger.debug(f"Error decoding OracleDataRequired error: {e}") address, data = decode(output_types[:2], error_data) fee = 0 @@ -62,8 +61,8 @@ def decode_erc7412_oracle_data_required_error(snx, error): feed_ids = [encode_hex(raw_feed_id) for raw_feed_id in raw_feed_ids] return address, feed_ids, fee, (update_type, staleness_tolerance, raw_feed_ids) - except: - pass + except Exception as e: + snx.logger.debug(f"Error decoding OracleDataRequired error: {e}") try: output_types_oracle = ["uint8", "uint64", "bytes32"] @@ -72,8 +71,8 @@ def decode_erc7412_oracle_data_required_error(snx, error): feed_ids = [encode_hex(raw_feed_id)] raw_feed_ids = [raw_feed_id] return address, feed_ids, fee, (update_type, publish_time, raw_feed_ids) - except: - pass + except Exception as e: + snx.logger.debug(f"Error decoding OracleDataRequired error: {e}") raise Exception("Error data can not be decoded") @@ -149,8 +148,8 @@ def aggregate_erc7412_price_requests(snx, error, requests=None): snx, error.data ) update_type = args[0] - except: - pass + except Exception as e: + snx.logger.debug(f"Error decoding OracleDataRequired error: {e}") if update_type: requests.pyth_address = address @@ -174,15 +173,16 @@ def aggregate_erc7412_price_requests(snx, error, requests=None): "message" in error.args[0] and "nonce" in error.args[0]["message"].lower() ) - except: + except Exception as e: + snx.logger.debug(f"Error: {e}") is_nonce_error = False if is_nonce_error: - snx.logger.debug(f"Error is related to nonce, resetting nonce") + snx.logger.debug("Error is related to nonce, resetting nonce") snx.nonce = snx.web3.eth.get_transaction_count(snx.address) return requests else: - snx.logger.debug(f"Error is not related to oracle data") + snx.logger.debug("Error is not related to oracle data") raise error return requests