Skip to content

Commit

Permalink
Merge pull request #708 from tellor-io/CBETH-USD
Browse files Browse the repository at this point in the history
Add CBETH/USD feed
  • Loading branch information
0xSpuddy authored Sep 25, 2023
2 parents fc7b855 + acac07a commit 87bba58
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/telliot_feeds/feeds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from telliot_feeds.feeds.bct_usd_feed import bct_usd_median_feed
from telliot_feeds.feeds.brl_usd_feed import brl_usd_median_feed
from telliot_feeds.feeds.btc_usd_feed import btc_usd_median_feed
from telliot_feeds.feeds.cbeth_usd_feed import cbeth_usd_median_feed
from telliot_feeds.feeds.cny_usd_feed import cny_usd_median_feed
from telliot_feeds.feeds.comp_usd_feed import comp_usd_median_feed
from telliot_feeds.feeds.crv_usd_feed import crv_usd_median_feed
Expand Down Expand Up @@ -160,6 +161,7 @@
"wld-usd-spot": wld_usd_median_feed,
"sweth-usd-spot": sweth_usd_median_feed,
"diva-usd-spot": diva_usd_median_feed,
"cbeth-usd-spot": cbeth_usd_median_feed,
}

DATAFEED_BUILDER_MAPPING: Dict[str, DataFeed[Any]] = {
Expand Down
20 changes: 20 additions & 0 deletions src/telliot_feeds/feeds/cbeth_usd_feed.py
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.uniswapV3 import UniswapV3PriceSource
from telliot_feeds.sources.price_aggregator import PriceAggregator

cbeth_usd_median_feed = DataFeed(
query=SpotPrice(asset="CBETH", currency="USD"),
source=PriceAggregator(
asset="cbeth",
currency="usd",
algorithm="median",
sources=[
CoinGeckoSpotPriceSource(asset="cbeth", currency="usd"),
UniswapV3PriceSource(asset="cbeth", currency="usd"),
CoinpaprikaSpotPriceSource(asset="cbeth-coinbase-wrapped-staked-eth", currency="usd"),
],
),
)
1 change: 1 addition & 0 deletions src/telliot_feeds/queries/price/spot_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"OETH/ETH",
"WLD/USD",
"DIVA/USD",
"CBETH/USD",
]


Expand Down
8 changes: 7 additions & 1 deletion src/telliot_feeds/queries/query_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@

query_catalog.add_entry(
tag="diva-usd-spot",
title="diva/USD spot price",
title="DIVA/USD spot price",
q=SpotPrice(asset="diva", currency="usd"),
)

query_catalog.add_entry(
tag="cbeth-usd-spot",
title="CBETH/USD spot price",
q=SpotPrice(asset="cbeth", currency="usd"),
)
1 change: 1 addition & 0 deletions src/telliot_feeds/sources/price/spot/coingecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"sweth": "sweth",
"wld": "worldcoin",
"diva": "diva-protocol",
"cbeth": "coinbase-wrapped-staked-eth",
}


Expand Down
1 change: 1 addition & 0 deletions src/telliot_feeds/sources/price/spot/uniswapV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"pls": "0xa882606494d86804b5514e07e6bd2d6a6ee6d68a",
"ousd": "0x2a8e1e676ec238d8a992307b495b45b3feaa5e86",
"sweth": "0xf951e335afb289353dc249e82926178eac7ded78",
"cbeth": "0xbe9895146f7af43049ca1c1ae358b0541ea49704",
}


Expand Down
22 changes: 22 additions & 0 deletions tests/feeds/test_cbeth_usd_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import statistics

import pytest

from telliot_feeds.feeds.cbeth_usd_feed import cbeth_usd_median_feed


@pytest.mark.asyncio
async def test_cbeth_usd_median_feed(caplog):
"""Retrieve median STETH/USD price."""
v, _ = await cbeth_usd_median_feed.source.fetch_new_datapoint()

assert v is not None
assert v > 0
assert "sources used in aggregate: 3" in caplog.text.lower()
print(f"CBETH/USD Price: {v}")

# Get list of data sources from sources dict
source_prices = [source.latest[0] for source in cbeth_usd_median_feed.source.sources if source.latest[0]]

# Make sure error is less than decimal tolerance
assert (v - statistics.median(source_prices)) < 10**-6

0 comments on commit 87bba58

Please sign in to comment.