From 98a69dd0ae4fd099c4f82da932f42c33919d00e4 Mon Sep 17 00:00:00 2001 From: Felix Henneke Date: Fri, 4 Oct 2024 11:56:31 +0200 Subject: [PATCH] Revert "Merge pull request #64 from cowprotocol/use_multiple_price_fees_always" This reverts commit 21f1e64094d9373c779e8674478ede6174e2a67e, reversing changes made to a8814b2bcb95afe69dc37d051d46e36f66a59d54. --- src/price_providers/price_feed.py | 7 +++---- src/transaction_processor.py | 25 ++++++++++--------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/price_providers/price_feed.py b/src/price_providers/price_feed.py index fd86b96..afed5ee 100644 --- a/src/price_providers/price_feed.py +++ b/src/price_providers/price_feed.py @@ -18,14 +18,13 @@ def __init__(self, activate: bool): else: self.providers = [] - def get_price(self, price_params: dict) -> list[tuple[float, str]]: + def get_price(self, price_params: dict) -> tuple[float, str] | None: """Function iterates over list of price provider objects and attempts to get a price.""" - prices = [] for provider in self.providers: try: price = provider.get_price(price_params) if price is not None: - prices.append((price, provider.name)) + return price, provider.name except Exception as e: logger.error(f"Error getting price from provider {provider.name}: {e}") - return prices + return None diff --git a/src/transaction_processor.py b/src/transaction_processor.py index 5da76c1..c695b92 100644 --- a/src/transaction_processor.py +++ b/src/transaction_processor.py @@ -1,4 +1,3 @@ -import time from hexbytes import HexBytes from web3 import Web3 from src.helpers.blockchain_data import BlockchainData @@ -8,6 +7,7 @@ from src.helpers.helper_functions import read_sql_file, set_params from src.helpers.config import CHAIN_SLEEP_TIME, logger from src.fees.compute_fees import compute_all_fees_of_batch +import time class TransactionProcessor: @@ -193,7 +193,7 @@ def process_prices_for_tokens( token_imbalances: dict[str, int], block_number: int, tx_hash: str, - ) -> dict[str, list[tuple[float, str]]]: + ) -> dict[str, tuple[float, str]]: """Compute prices for tokens with non-null imbalances.""" prices = {} try: @@ -202,7 +202,8 @@ def process_prices_for_tokens( set_params(token_address, block_number, tx_hash) ) if price_data: - prices[token_address] = price_data + price, source = price_data + prices[token_address] = (price, source) except Exception as e: logger.error(f"Failed to process prices for transaction {tx_hash}: {e}") @@ -291,21 +292,15 @@ def handle_fees( ) def handle_prices( - self, - prices: dict[str, list[tuple[float, str]]], - tx_hash: str, - block_number: int, + self, prices: dict[str, tuple[float, str]], tx_hash: str, block_number: int ) -> None: """Function writes prices to table per token.""" try: - for token_address, list_of_prices in prices.items(): - for price, source in list_of_prices: - self.db.write_prices( - source, block_number, tx_hash, token_address, price - ) - self.log_message.append( - f"Token: {token_address}, Price: {price} ETH, Source: {source}" - ) + for token_address, (price, source) in prices.items(): + self.db.write_prices( + source, block_number, tx_hash, token_address, price + ) + self.log_message.append(f"Token: {token_address}, Price: {price} ETH") except Exception as err: logger.error(f"Error: {err}")