Skip to content

Commit

Permalink
Merge branch 'main' into bfp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tburm committed Aug 8, 2024
2 parents 1e72d4a + d88ea43 commit 53e9270
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 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.14",
version="0.1.15",
description="Synthetix protocol SDK",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down
4 changes: 4 additions & 0 deletions src/synthetix/perps/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DISABLED_MARKETS = {
8453: [6300],
84532: [6300],
}
17 changes: 15 additions & 2 deletions src/synthetix/perps/perps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
write_erc7412,
make_fulfillment_request,
)
from .constants import DISABLED_MARKETS


def unpack_market_configuration(config_data):
Expand Down Expand Up @@ -122,18 +123,23 @@ class Perps:
- PythERC7412Wrapper
:param Synthetix snx: An instance of the Synthetix class.
:param Pyth pyth: An instance of the Pyth class.
:param int | None default_account_id: The default ``account_id`` to use for transactions.
:param list | None : A list of market ids to disable.
:return: An instance of the Perps class.
:rtype: Perps
"""

def __init__(self, snx, default_account_id: int = None):
def __init__(self, snx, default_account_id: int = None, disabled_markets=None):
self.snx = snx
self.logger = snx.logger
self.erc7412_enabled = True

if disabled_markets is None and snx.network_id in DISABLED_MARKETS:
self.disabled_markets = DISABLED_MARKETS[snx.network_id]
else:
self.disabled_markets = disabled_markets if disabled_markets else []

# check if perps is deployed on this network
if "perpsFactory" in snx.contracts:
self.market_proxy = snx.contracts["perpsFactory"]["PerpsMarketProxy"][
Expand Down Expand Up @@ -292,6 +298,13 @@ def get_markets(self):
"""
market_ids = self.market_proxy.functions.getMarkets().call()

# filter disabled markets
market_ids = [
market_id
for market_id in market_ids
if market_id not in self.disabled_markets
]

# fetch and store the metadata
market_metadata = multicall_erc7412(
self.snx, self.market_proxy, "metadata", market_ids
Expand Down
9 changes: 9 additions & 0 deletions src/synthetix/pyth/pyth.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def _fetch_prices(self, feed_ids: [str], publish_time: int | None = None):
try:
response = requests.get(url, params, timeout=10)
if response.status_code != 200:
if response.text and "Price ids not found" in response.text:
self.logger.info(f"Removing missing price feeds: {response.text}")
feed_ids = [
feed_id
for feed_id in feed_ids
if feed_id not in response.text
]
return self._fetch_prices(feed_ids, publish_time=publish_time)

self.logger.error(f"Error fetching latest price data: {response.text}")
return None

Expand Down
7 changes: 6 additions & 1 deletion src/synthetix/synthetix.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class Synthetix:
:param int perps_account_id: A default ``account_id`` for perps transactions.
Setting a default will avoid the need to specify on each transaction. If
not specified, the first ``account_id`` will be used.
:param list perps_disabled_markets: A list of market ids to disable for perps
trading. This is useful for disabling markets that are deprecated, or to
limit the number of markets available for trading.
:param str tracking_code: Set a tracking code for trades.
:param str referrer: Set a referrer address for trades.
:param float max_price_impact: Max price impact setting for trades,
Expand All @@ -119,6 +122,7 @@ class Synthetix:
to increase the gas limit for transactions.
:param bool is_fork: Set to true if the chain is a fork. This will improve
the way price data is handled by requesting at the block timestamp.
:return: Synthetix class instance
:rtype: Synthetix
"""
Expand All @@ -133,6 +137,7 @@ def __init__(
network_id: int = None,
core_account_id: int = None,
perps_account_id: int = None,
perps_disabled_markets: list = None,
tracking_code: str = DEFAULT_TRACKING_CODE,
referrer: str = DEFAULT_REFERRER,
max_price_impact: float = DEFAULT_SLIPPAGE,
Expand Down Expand Up @@ -611,7 +616,7 @@ def wrap_eth(self, amount: float, submit: bool = False) -> str:

# reset nonce on internal transactions
self.nonce = self.web3.eth.get_transaction_count(self.address)
tx_params['nonce'] = self.nonce
tx_params["nonce"] = self.nonce

# simulate the transaction
tx_params = weth_contract.functions[fn_name](*tx_args).build_transaction(
Expand Down

0 comments on commit 53e9270

Please sign in to comment.