Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/synthetix/contracts/contracts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import json
import glob
import zlib
import requests
from web3 import Web3
Expand Down
12 changes: 5 additions & 7 deletions src/synthetix/perps/perps.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/synthetix/spot/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from web3.constants import ADDRESS_ZERO
from typing import Literal
import time
import requests


class Spot:
Expand Down
17 changes: 8 additions & 9 deletions src/synthetix/synthetix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
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,
DEFAULT_GQL_ENDPOINT_PERPS,
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
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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"])
Expand Down
24 changes: 12 additions & 12 deletions src/synthetix/utils/multicall.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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"]
Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading