From 50dfb493b0b7140d65b3faeec8bbf89df7762db7 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 26 Mar 2024 12:56:48 -0400 Subject: [PATCH] mirror runs once if polling <= 0 --- src/dexorder/bin/mirror.py | 25 +++++++++++++++++++++++-- src/dexorder/configuration/schema.py | 5 +++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/dexorder/bin/mirror.py b/src/dexorder/bin/mirror.py index 83ec09a..14fb2cc 100644 --- a/src/dexorder/bin/mirror.py +++ b/src/dexorder/bin/mirror.py @@ -1,3 +1,17 @@ +""" +python -m dexorder.bin.mirror creates new pools on the rpc_url chain that mimic the tokens and prices of original +pools on a different mirror_source_rpc_url chain. + +[config] +rpc_url= +mirror_source_rpc_url = +mirror_pools = +mirror_env = [address on rpc_url chain where MirrorEnv contract is deployed. If None, then discovered from deployment] +metadata = [if set, then a metadata.json file for the mock chain is written to this location] +polling = [seconds between price updates. If zero or negative, prices are updated once and the process exits] +""" + + import asyncio import logging import os @@ -105,7 +119,8 @@ async def main(): if config.mirror_source_rpc_url is None: log.error('Must configure mirror_source_rpc_url') return - delay = config.polling if config.polling > 0 else 1 + delay = max(0.010, config.polling) + update_once = config.polling <= 0 global source_w3 source_w3 = await create_w3(config.mirror_source_rpc_url) pools = (config.mirror_pools or []) @@ -173,7 +188,10 @@ async def main(): mirror_pools.append((mirror_addr, mirror_inverted)) await write_metadata(pools, mirror_pools) - log.info(f'Updating pools every {delay} seconds') + if update_once: + log.info(f'Updating pools once') + else: + log.info(f'Updating pools every {delay} seconds') delay = timedelta(seconds=delay) to_update = pools while True: @@ -188,6 +206,9 @@ async def main(): if isinstance(result, Exception): log.debug(f'Could not update {pool}: {result}') failed.append(pool) + if update_once and not failed: + log.info('mirror completed') + break to_update = failed if failed else pools sleep = (wake_up - now()).total_seconds() if sleep > 0: diff --git a/src/dexorder/configuration/schema.py b/src/dexorder/configuration/schema.py index 98f3af5..064bcaa 100644 --- a/src/dexorder/configuration/schema.py +++ b/src/dexorder/configuration/schema.py @@ -17,6 +17,8 @@ class Config: db_url: Optional[str] = 'postgresql://dexorder:redroxed@localhost/dexorder' dump_sql: bool = False redis_url: Optional[str] = 'redis://localhost:6379' + + metadata: Optional[str] = None ohlc_dir: Optional[str] = None # if empty string or None, then OHLC's are not saved to disk concurrent_rpc_connections: int = 4 @@ -33,6 +35,5 @@ class Config: walker_flush_interval: float = 300 mirror_source_rpc_url: Optional[str] = None # source RPC for original pools - mirror_env: Optional[str] = None mirror_pools: list[str] = field(default_factory=list) - metadata: Optional[str] = None + mirror_env: Optional[str] = None