From 1f3585bd19d68a7885f26229ecf3373aa846b29a Mon Sep 17 00:00:00 2001 From: Shubh Agarwal Date: Wed, 31 Jul 2024 20:26:01 -0400 Subject: [PATCH] addressed review --- src/coingecko_pricing.py | 11 ++++------- src/daemon.py | 10 +--------- src/helper_functions.py | 6 ++++++ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/coingecko_pricing.py b/src/coingecko_pricing.py index ca1ca3c..f3cf5fd 100644 --- a/src/coingecko_pricing.py +++ b/src/coingecko_pricing.py @@ -8,10 +8,10 @@ coingecko_api_key = os.getenv("COINGECKO_API_KEY") - -def load_cleaned_token_list(file_path): - with open(file_path, "r") as f: - return json.load(f) +# Load the coingecko token list +cleaned_token_list_path = "src/coingecko_tokens_list/filtered_coingecko_list.json" +with open(cleaned_token_list_path, "r") as f: + cleaned_token_list = json.load(f) def get_token_id_by_address(cleaned_token_list, token_address): @@ -58,9 +58,6 @@ def get_price(web3: Web3, block_number: int, token_address: str, tx_hash: str): Function returns coingecko price for a token address, closest to and at least as large as the block timestamp for a given tx hash. """ - cleaned_token_list = load_cleaned_token_list( - "src/coingecko_tokens_list/filtered_coingecko_list.json" - ) # Coingecko doesn't store ETH address, which occurs commonly in imbalances. if Web3.to_checksum_address(token_address) == NATIVE_ETH_TOKEN_ADDRESS: return 1.0 diff --git a/src/daemon.py b/src/daemon.py index cdc5ea6..dee2e69 100644 --- a/src/daemon.py +++ b/src/daemon.py @@ -9,9 +9,7 @@ from sqlalchemy import text from sqlalchemy.engine import Engine from src.imbalances_script import RawTokenImbalances -from src.helper_functions import ( - get_finalized_block_number, -) +from src.helper_functions import get_finalized_block_number, read_sql_file from src.config import ( initialize_connections, CHAIN_SLEEP_TIME, @@ -21,12 +19,6 @@ from src.coingecko_pricing import get_price -def read_sql_file(file_path: str) -> str: - """This function reads an SQL file and returns its content in string format""" - with open(file_path, "r") as file: - return file.read() - - def get_start_block( chain_name: str, solver_slippage_connection: Engine, web3: Web3 ) -> int: diff --git a/src/helper_functions.py b/src/helper_functions.py index 016bd9f..25e77ce 100644 --- a/src/helper_functions.py +++ b/src/helper_functions.py @@ -65,3 +65,9 @@ def get_finalized_block_number(web3: Web3) -> int: Get the number of the most recent finalized block. """ return web3.eth.block_number - 67 + + +def read_sql_file(file_path: str) -> str: + """This function reads a file (SQL) and returns its content as a string.""" + with open(file_path, "r") as file: + return file.read()