-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #782 from tellor-io/mode-chains-feeds
Mode chains feeds
- Loading branch information
Showing
20 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
84532, | ||
111, | ||
60808, | ||
919, | ||
} | ||
|
||
GNOSIS_CHAINS = {100, 10200} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from telliot_feeds.datafeed import DataFeed | ||
from telliot_feeds.queries.price.spot_price import SpotPrice | ||
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource | ||
from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource | ||
from telliot_feeds.sources.price.spot.curvefiprice import CurveFiUSDPriceSource | ||
from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource | ||
from telliot_feeds.sources.price_aggregator import PriceAggregator | ||
|
||
|
||
ezeth_usd_median_feed = DataFeed( | ||
query=SpotPrice(asset="EZETH", currency="USD"), | ||
source=PriceAggregator( | ||
asset="ezeth", | ||
currency="usd", | ||
algorithm="median", | ||
sources=[ | ||
CoinGeckoSpotPriceSource(asset="ezeth", currency="usd"), | ||
CurveFiUSDPriceSource(asset="ezeth", currency="usd"), | ||
CoinpaprikaSpotPriceSource(asset="ezeth-renzo-restaked-eth", currency="usd"), | ||
UniswapV3PriceSource(asset="ezeth", currency="usd"), | ||
], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from telliot_feeds.datafeed import DataFeed | ||
from telliot_feeds.queries.price.spot_price import SpotPrice | ||
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource | ||
from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource | ||
from telliot_feeds.sources.price.spot.kimexchange import kimexchangePriceSource | ||
from telliot_feeds.sources.price_aggregator import PriceAggregator | ||
|
||
mode_usd_median_feed = DataFeed( | ||
query=SpotPrice(asset="MODE", currency="USD"), | ||
source=PriceAggregator( | ||
asset="mode", | ||
currency="usd", | ||
algorithm="median", | ||
sources=[ | ||
CoinGeckoSpotPriceSource(asset="mode", currency="usd"), | ||
CoinpaprikaSpotPriceSource(asset="mode-mode", currency="usd"), | ||
kimexchangePriceSource(asset="mode", currency="usd"), | ||
], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from telliot_feeds.datafeed import DataFeed | ||
from telliot_feeds.queries.price.spot_price import SpotPrice | ||
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource | ||
from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource | ||
from telliot_feeds.sources.price.spot.curvefiprice import CurveFiUSDPriceSource | ||
from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource | ||
from telliot_feeds.sources.price_aggregator import PriceAggregator | ||
|
||
|
||
rseth_usd_median_feed = DataFeed( | ||
query=SpotPrice(asset="rsETH", currency="USD"), | ||
source=PriceAggregator( | ||
asset="rseth", | ||
currency="usd", | ||
algorithm="median", | ||
sources=[ | ||
CoinGeckoSpotPriceSource(asset="rseth", currency="usd"), | ||
CurveFiUSDPriceSource(asset="rseth", currency="usd"), | ||
CoinpaprikaSpotPriceSource(asset="rseth-rseth", currency="usd"), | ||
UniswapV3PriceSource(asset="rseth", currency="usd"), | ||
], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from telliot_feeds.datafeed import DataFeed | ||
from telliot_feeds.queries.price.spot_price import SpotPrice | ||
from telliot_feeds.sources.price.spot.coingecko import CoinGeckoSpotPriceSource | ||
from telliot_feeds.sources.price.spot.coinpaprika import CoinpaprikaSpotPriceSource | ||
from telliot_feeds.sources.price.spot.curvefiprice import CurveFiUSDPriceSource | ||
from telliot_feeds.sources.price.spot.uniswapV3 import UniswapV3PriceSource | ||
from telliot_feeds.sources.price_aggregator import PriceAggregator | ||
|
||
|
||
weeth_usd_median_feed = DataFeed( | ||
query=SpotPrice(asset="WEETH", currency="USD"), | ||
source=PriceAggregator( | ||
asset="weeth", | ||
currency="usd", | ||
algorithm="median", | ||
sources=[ | ||
CoinGeckoSpotPriceSource(asset="weeth", currency="usd"), | ||
CurveFiUSDPriceSource(asset="weeth", currency="usd"), | ||
CoinpaprikaSpotPriceSource(asset="weeth-wrapped-eeth", currency="usd"), | ||
UniswapV3PriceSource(asset="weeth", currency="usd"), | ||
], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from telliot_feeds.datafeed import DataFeed | ||
from telliot_feeds.queries.price.spot_price import SpotPrice | ||
from telliot_feeds.sources.wrseth_source import wrsETHSpotPriceSource | ||
|
||
|
||
wrseth_usd_feed = DataFeed( | ||
query=SpotPrice(asset="WRSETH", currency="USD"), source=wrsETHSpotPriceSource(asset="wrseth", currency="usd") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
from typing import Any | ||
|
||
import requests | ||
|
||
from telliot_feeds.dtypes.datapoint import datetime_now_utc | ||
from telliot_feeds.dtypes.datapoint import OptionalDataPoint | ||
from telliot_feeds.pricing.price_service import WebPriceService | ||
from telliot_feeds.pricing.price_source import PriceSource | ||
from telliot_feeds.utils.log import get_logger | ||
|
||
|
||
logger = get_logger(__name__) | ||
kim_map = { | ||
"mode": "0xdfc7c877a950e49d2610114102175a06c2e3167a", | ||
} | ||
|
||
|
||
class kimexchangePriceService(WebPriceService): | ||
"""Kim exchange Price Service in USD and ETH""" | ||
|
||
def __init__(self, **kwargs: Any) -> None: | ||
kwargs["name"] = "Kim exchange subgraph" | ||
kwargs["url"] = "https://api.goldsky.com/api/public" | ||
kwargs["timeout"] = 10.0 | ||
super().__init__(**kwargs) | ||
|
||
async def get_price(self, asset: str, currency: str) -> OptionalDataPoint[float]: | ||
"""Implement PriceServiceInterface | ||
This implementation gets the price from the Kim exchange subgraph | ||
https://api.goldsky.com/api/public/project_clmqdcfcs3f6d2ptj3yp05ndz/subgraphs/Algebra/0.0.1/gn | ||
""" | ||
|
||
asset = asset.lower() | ||
|
||
token = kim_map.get(asset, None) | ||
if not token: | ||
raise Exception("Asset not supported: {}".format(asset)) | ||
|
||
headers = { | ||
"Content-Type": "application/json", | ||
} | ||
|
||
query = "{bundles{maticPriceUSD}token" + f'(id: "{token}")' + "{ derivedMatic } }" | ||
|
||
json_data = {"query": query} | ||
|
||
request_url = self.url + "/project_clmqdcfcs3f6d2ptj3yp05ndz/subgraphs/Algebra/0.0.1/gn" | ||
|
||
with requests.Session() as s: | ||
try: | ||
r = s.post(request_url, headers=headers, json=json_data, timeout=self.timeout) | ||
res = r.json() | ||
data = {"response": res} | ||
|
||
except requests.exceptions.ConnectTimeout: | ||
logger.warning("Timeout Error, No prices retrieved from Kim exchange") | ||
return None, None | ||
|
||
except Exception: | ||
logger.warning("No prices retrieved from kim exchange") | ||
return None, None | ||
|
||
if "error" in data: | ||
logger.error(data) | ||
return None, None | ||
|
||
elif "response" in data: | ||
response = data["response"] | ||
|
||
try: | ||
token_price_eth = float(response["data"]["token"]["derivedMatic"]) | ||
eth_price_usd = float(response["data"]["bundles"][0]["maticPriceUSD"]) | ||
token_price = token_price_eth * eth_price_usd | ||
return token_price, datetime_now_utc() | ||
except KeyError as e: | ||
msg = "Error parsing MaverickV2 response: KeyError: {}".format(e) | ||
logger.critical(msg) | ||
return None, None | ||
|
||
else: | ||
raise Exception("Invalid response from get_url") | ||
|
||
|
||
@dataclass | ||
class kimexchangePriceSource(PriceSource): | ||
asset: str = "" | ||
currency: str = "" | ||
service: kimexchangePriceService = field(default_factory=kimexchangePriceService, init=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.