Skip to content

Commit

Permalink
Next fix test ci utils (#134)
Browse files Browse the repository at this point in the history
* fix circular import

* gg
  • Loading branch information
azurwastaken authored Jul 4, 2024
1 parent 14ede4a commit b8de02f
Show file tree
Hide file tree
Showing 26 changed files with 104 additions and 100 deletions.
4 changes: 0 additions & 4 deletions sdk/pragma/common/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
from .asset_config import AssetConfig


__all__ = [AssetConfig]
12 changes: 0 additions & 12 deletions sdk/pragma/common/configs/asset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pydantic import BaseModel

from pragma.common.types.types import DECIMALS
from pragma.common.types.currency import Currency
from pragma.common.exceptions import UnsupportedAssetError

from pathlib import Path
Expand All @@ -22,17 +21,6 @@ class AssetConfig(BaseModel):
coingecko_id: Optional[str] = None
abstract: Optional[bool] = False

def as_currency(self) -> Currency:
"""
Return a Currency object from the AssetConfig.
"""

return Currency(
id_=self.ticker,
decimals=self.decimals,
is_abstract_currency=self.abstract,
)

@classmethod
def from_yaml(cls, path: str) -> List[Self]:
with open(path, "r") as file:
Expand Down
30 changes: 15 additions & 15 deletions sdk/pragma/common/fetchers/fetchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
from .gateio import GateioFetcher

__all__ = [
BinanceFetcher,
BitstampFetcher,
BybitFetcher,
CoinbaseFetcher,
DefillamaFetcher,
GeckoTerminalFetcher,
HuobiFetcher,
IndexFetcher,
IndexCoopFetcher,
KucoinFetcher,
OkxFetcher,
PropellerFetcher,
StarknetAMMFetcher,
MEXCFetcher,
GateioFetcher,
"BinanceFetcher",
"BitstampFetcher",
"BybitFetcher",
"CoinbaseFetcher",
"DefillamaFetcher",
"GeckoTerminalFetcher",
"HuobiFetcher",
"IndexFetcher",
"IndexCoopFetcher",
"KucoinFetcher",
"OkxFetcher",
"PropellerFetcher",
"StarknetAMMFetcher",
"MEXCFetcher",
"GateioFetcher",
]
7 changes: 4 additions & 3 deletions sdk/pragma/common/fetchers/fetchers/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from aiohttp import ClientSession

from pragma.common.configs import AssetConfig
from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.pair import Pair
from pragma.common.types.entry import SpotEntry
from pragma.common.exceptions import PublisherFetchError
Expand Down Expand Up @@ -63,7 +64,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair1 = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair1) as resp:
Expand All @@ -80,7 +81,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair2 = self.format_url(
Pair(
pair.quote_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair2) as resp:
Expand Down
7 changes: 4 additions & 3 deletions sdk/pragma/common/fetchers/fetchers/bybit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from aiohttp import ClientSession

from pragma.common.configs import AssetConfig
from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.pair import Pair
from pragma.common.types.entry import SpotEntry
from pragma.common.exceptions import PublisherFetchError
Expand Down Expand Up @@ -57,7 +58,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair1 = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair1) as resp:
Expand All @@ -73,7 +74,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url2 = self.format_url(
Pair(
pair.quote_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url2) as resp:
Expand Down
5 changes: 3 additions & 2 deletions sdk/pragma/common/fetchers/fetchers/gateio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from aiohttp import ClientSession

from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.entry import SpotEntry
from pragma.common.types.pair import Pair
from pragma.common.exceptions import PublisherFetchError
Expand Down Expand Up @@ -57,7 +58,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair1 = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair1) as resp:
Expand All @@ -73,7 +74,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair2 = self.format_url(
Pair(
pair.quote_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair2) as resp:
Expand Down
5 changes: 3 additions & 2 deletions sdk/pragma/common/fetchers/fetchers/gecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from aiohttp import ClientSession

from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.entry import SpotEntry
from pragma.common.types.pair import Pair
from pragma.common.exceptions import PublisherFetchError
Expand Down Expand Up @@ -116,7 +117,7 @@ async def operate_usd_hop(self, pair: Pair, session) -> SpotEntry:
pair1_url = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USD").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USD")),
)
)

Expand All @@ -137,7 +138,7 @@ async def operate_usd_hop(self, pair: Pair, session) -> SpotEntry:
pair2_url = self.format_url(
Pair(
pair.quote_currency,
AssetConfig.from_ticker("USD").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USD")),
)
)
async with session.get(pair2_url, headers=self.headers) as resp2:
Expand Down
5 changes: 3 additions & 2 deletions sdk/pragma/common/fetchers/fetchers/huobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aiohttp import ClientSession

from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.pair import Pair
from pragma.common.types.entry import SpotEntry
from pragma.common.exceptions import PublisherFetchError
Expand Down Expand Up @@ -56,7 +57,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair1 = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair1) as resp:
Expand All @@ -72,7 +73,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair2 = self.format_url(
Pair(
pair.quote_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair2) as resp:
Expand Down
5 changes: 3 additions & 2 deletions sdk/pragma/common/fetchers/fetchers/indexcoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from aiohttp import ClientSession

from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.pair import Pair
from pragma.common.types.entry import SpotEntry
from pragma.common.fetchers.fetchers.index import AssetQuantities
Expand Down Expand Up @@ -70,8 +71,8 @@ def fetch_quantities(self, index_address) -> List[AssetQuantities]:
return [
AssetQuantities(
pair=Pair(
AssetConfig.from_ticker(symbol).as_currency(),
AssetConfig.from_ticker("USD").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker(symbol)),
Currency.from_asset_config(AssetConfig.from_ticker("USD")),
),
quantities=quantities,
)
Expand Down
5 changes: 3 additions & 2 deletions sdk/pragma/common/fetchers/fetchers/kucoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aiohttp import ClientSession

from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.pair import Pair
from pragma.common.types.entry import SpotEntry
from pragma.common.exceptions import PublisherFetchError
Expand Down Expand Up @@ -53,7 +54,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair1 = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair1) as resp:
Expand All @@ -69,7 +70,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair2 = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair2) as resp:
Expand Down
5 changes: 3 additions & 2 deletions sdk/pragma/common/fetchers/fetchers/mexc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from aiohttp import ClientSession

from pragma.common.configs.asset_config import AssetConfig
from pragma.common.types.currency import Currency
from pragma.common.types.pair import Pair
from pragma.common.types.entry import SpotEntry
from pragma.common.exceptions import PublisherFetchError
Expand Down Expand Up @@ -57,7 +58,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair1 = self.format_url(
Pair(
pair.base_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair1) as resp:
Expand All @@ -73,7 +74,7 @@ async def operate_usdt_hop(self, pair: Pair, session) -> SpotEntry:
url_pair2 = self.format_url(
Pair(
pair.quote_currency,
AssetConfig.from_ticker("USDT").as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker("USDT")),
)
)
async with session.get(url_pair2) as resp:
Expand Down
6 changes: 3 additions & 3 deletions sdk/pragma/common/fetchers/future_fetchers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .okx import OkxFutureFetcher

__all__ = [
BinanceFutureFetcher,
ByBitFutureFetcher,
OkxFutureFetcher,
"BinanceFutureFetcher",
"ByBitFutureFetcher",
"OkxFutureFetcher",
]
11 changes: 6 additions & 5 deletions sdk/pragma/common/fetchers/hop_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Dict, Optional
from pragma.common.types.currency import Currency
from pragma.common.types.pair import Pair
from pragma.common.configs.asset_config import AssetConfig
from pydantic.dataclasses import dataclass
Expand Down Expand Up @@ -26,16 +27,16 @@ def get_hop_pair(self, pair: Pair) -> Optional[Pair]:

return Pair(
pair.base_currency,
AssetConfig.from_ticker(new_currency_id).as_currency(),
Currency.from_asset_config(AssetConfig.from_ticker(new_currency_id)),
)


class TestHopHandler(unittest.TestCase):
def setUp(self):
self.usdt = AssetConfig.from_ticker("USDT").as_currency()
self.usdc = AssetConfig.from_ticker("USDC").as_currency()
self.eth = AssetConfig.from_ticker("ETH").as_currency()
self.btc = AssetConfig.from_ticker("BTC").as_currency()
self.usdt = Currency.from_asset_config(AssetConfig.from_ticker("USDT"))
self.usdc = Currency.from_asset_config(AssetConfig.from_ticker("USDC"))
self.eth = Currency.from_asset_config(AssetConfig.from_ticker("ETH"))
self.btc = Currency.from_asset_config(AssetConfig.from_ticker("BTC"))

self.hop_handler = HopHandler(
hopped_currencies={"USDC": "USDT", "USDT": "ETH", "ETH": "BTC"}
Expand Down
21 changes: 0 additions & 21 deletions sdk/pragma/common/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
from .types import Environment, AggregationMode, DataTypes, ExecutionConfig
from .client import PragmaClient
from .currency import Currency
from .entry import Entry, SpotEntry, FutureEntry, BaseEntry
from .pair import Pair
from .asset import Asset

__all__ = [
Environment,
AggregationMode,
DataTypes,
ExecutionConfig,
PragmaClient,
Currency,
Entry,
SpotEntry,
FutureEntry,
BaseEntry,
Pair,
Asset,
]
2 changes: 1 addition & 1 deletion sdk/pragma/common/types/asset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional, Union


from pragma.common.types import DataTypes
from pragma.common.types.types import DataTypes
from pragma.common.utils import str_to_felt


Expand Down
15 changes: 11 additions & 4 deletions sdk/pragma/common/types/currency.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List, Optional

from typing import List, Optional, Self

from pragma.common.utils import str_to_felt
from pragma.common.types.types import ADDRESS, DECIMALS
Expand All @@ -14,13 +13,13 @@ class Currency:

def __init__(
self,
id_: str,
currency_id: str,
decimals: DECIMALS,
is_abstract_currency: bool,
starknet_address: Optional[ADDRESS] = None,
ethereum_address: Optional[ADDRESS] = None,
):
self.id = id_
self.id = currency_id

self.decimals = decimals

Expand All @@ -36,6 +35,14 @@ def __init__(
ethereum_address = 0
self.ethereum_address = ethereum_address

@classmethod
def from_asset_config(cls, config: "AssetConfig") -> Self:
return cls(
currency_id=config.ticker,
decimals=config.decimals,
is_abstract_currency=config.abstract,
)

def serialize(self) -> List[str]:
return [
self.id,
Expand Down
3 changes: 2 additions & 1 deletion sdk/pragma/common/types/entry.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

import abc

from pydantic.dataclasses import dataclass
from typing import Dict, List, Optional, Tuple, Union

from pragma.common.types.types import DataTypes, UnixTimestamp
from pragma.common.types.pair import Pair
from pragma.common.utils import felt_to_str, str_to_felt
from pragma.onchain.types import OracleResponse
from pragma.onchain.types.types import OracleResponse


class Entry(abc.ABC):
Expand Down
Loading

0 comments on commit b8de02f

Please sign in to comment.