From 966e4e74a69e07ec28b7e1541ffbb9157a851154 Mon Sep 17 00:00:00 2001 From: Evolve Date: Sun, 30 Jul 2023 21:20:54 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=201.6.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Checkpoint image now supports custom asset types (SPOT/FUTURE/OPTION) --- empiric-package/empiric/core/types.py | 2 ++ empiric-package/empiric/publisher/assets.py | 11 +++++++++++ empiric-package/empiric/publisher/types.py | 9 +++++++++ empiric-package/pyproject.toml | 2 +- pyproject.toml | 2 +- stagecoach/jobs/publishers/checkpoint/Dockerfile | 2 +- stagecoach/jobs/publishers/checkpoint/app.py | 7 ++++--- 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/empiric-package/empiric/core/types.py b/empiric-package/empiric/core/types.py index a033d03dd..d909acdc8 100644 --- a/empiric-package/empiric/core/types.py +++ b/empiric-package/empiric/core/types.py @@ -55,6 +55,8 @@ } RPC_CLIENT = FullNodeClient(node_url=RPC_URLS[NETWORK]) +AssetType = Literal["SPOT", "FUTURE", "OPTION"] + # aggregation mode enum @unique diff --git a/empiric-package/empiric/publisher/assets.py b/empiric-package/empiric/publisher/assets.py index 30bb2477a..bc1cf16d0 100644 --- a/empiric-package/empiric/publisher/assets.py +++ b/empiric-package/empiric/publisher/assets.py @@ -1,7 +1,9 @@ from typing import Dict, List, Tuple, Union from empiric.core.utils import key_for_asset +from empiric.core.types import AssetType from typing_extensions import TypedDict +from empiric.publisher.types import UnsupportedAssetError class EmpiricSpotAsset(TypedDict): @@ -88,6 +90,15 @@ class EmpiricOnchainAsset(TypedDict): for asset in EMPIRIC_ALL_ASSETS } +# TODO: Add support for option asset type +def get_asset_spec_for_pair_id_by_type(pair_id: str, asset_type: AssetType) -> EmpiricAsset: + if asset_type == "SPOT": + return get_spot_asset_spec_for_pair_id(pair_id) + elif asset_type == "FUTURE": + return get_future_asset_spec_for_pair_id(pair_id) + else: + raise UnsupportedAssetError("Only SPOT & FUTURE are supported for now.") + def get_spot_asset_spec_for_pair_id(pair_id: str) -> EmpiricSpotAsset: if pair_id not in _EMPIRIC_ASSET_BY_KEY: diff --git a/empiric-package/empiric/publisher/types.py b/empiric-package/empiric/publisher/types.py index 42383e1f2..513887f95 100644 --- a/empiric-package/empiric/publisher/types.py +++ b/empiric-package/empiric/publisher/types.py @@ -29,3 +29,12 @@ def __init__(self, message: str): def serialize(self): return self.message + +class UnsupportedAssetError: + message: str + + def __init__(self, message: str): + self.message = message + + def serialize(self): + return self.message \ No newline at end of file diff --git a/empiric-package/pyproject.toml b/empiric-package/pyproject.toml index a678f01bd..55aa3669b 100644 --- a/empiric-package/pyproject.toml +++ b/empiric-package/pyproject.toml @@ -7,7 +7,7 @@ profile = "black" [tool.poetry] name = "empiric-network" -version = "1.6.9" +version = "1.6.10" authors = ["Pragma "] description = "Core package for rollup-native Pragma Oracle" readme = "README.md" diff --git a/pyproject.toml b/pyproject.toml index db746061c..f0fe59215 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pragma" -version = "1.6.9" +version = "1.6.10" description = "Pragma, the leading Oracle on zkRollups." authors = ["0xevolve "] license = "MIT" diff --git a/stagecoach/jobs/publishers/checkpoint/Dockerfile b/stagecoach/jobs/publishers/checkpoint/Dockerfile index 53a2e0cc3..a56d1616f 100644 --- a/stagecoach/jobs/publishers/checkpoint/Dockerfile +++ b/stagecoach/jobs/publishers/checkpoint/Dockerfile @@ -4,7 +4,7 @@ RUN yum install -y gcc python-devel gmp-devel git RUN python -m pip install --upgrade pip -RUN pip install empiric-network==1.6.8 typeguard==2.13.3 +RUN pip install empiric-network==1.6.10 typeguard==2.13.3 COPY app.py ${LAMBDA_TASK_ROOT} diff --git a/stagecoach/jobs/publishers/checkpoint/app.py b/stagecoach/jobs/publishers/checkpoint/app.py index f24e51753..caf9f72c7 100644 --- a/stagecoach/jobs/publishers/checkpoint/app.py +++ b/stagecoach/jobs/publishers/checkpoint/app.py @@ -5,7 +5,7 @@ import boto3 from empiric.core.logger import get_stream_logger from empiric.core.utils import currency_pair_to_pair_id -from empiric.publisher.assets import get_spot_asset_spec_for_pair_id +from empiric.publisher.assets import get_asset_spec_for_pair_id_by_type from empiric.publisher.client import EmpiricPublisherClient logger = get_stream_logger() @@ -13,10 +13,11 @@ SECRET_NAME = os.environ["SECRET_NAME"] NETWORK = os.environ["NETWORK"] ASSETS = os.environ["ASSETS"] +ASSET_TYPE = os.environ.get("ASSET_TYPE", "SPOT") def handler(event, context): - assets = [get_spot_asset_spec_for_pair_id(asset) for asset in ASSETS.split(",")] + assets = [get_asset_spec_for_pair_id_by_type(asset, ASSET_TYPE) for asset in ASSETS.split(",")] invocation = asyncio.run(_handler(assets)) return { "result": invocation, @@ -41,7 +42,7 @@ async def _handler(assets): account_address = int(os.environ.get("ACCOUNT_ADDRESS")) pairs = [ - currency_pair_to_pair_id(*p["pair"]) for p in assets if p["type"] == "SPOT" + currency_pair_to_pair_id(*p["pair"]) for p in assets if p["type"] == ASSET_TYPE ] publisher_client = EmpiricPublisherClient(