Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dependency on fees when computing prices #58

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/transaction_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def process_single_transaction(
) = self.process_fees_for_transaction(tx_hash)

# Compute Prices
if self.process_prices:
if self.process_prices and self.process_imbalances:
prices = self.process_prices_for_tokens(
token_imbalances, protocol_fees, network_fees, block_number, tx_hash
token_imbalances, block_number, tx_hash
)

# Write to database iff no errors in either computations
Expand Down Expand Up @@ -189,23 +189,19 @@ def process_fees_for_transaction(
def process_prices_for_tokens(
self,
token_imbalances: dict[str, int],
protocol_fees: dict[str, tuple[str, int]],
network_fees: dict[str, tuple[str, int]],
block_number: int,
tx_hash: str,
) -> dict[str, tuple[float, str]]:
"""Compute prices for tokens with non-null imbalances."""
prices = {}
try:
slippage = calculate_slippage(token_imbalances, protocol_fees, network_fees)
for token_address in slippage.keys():
if slippage[token_address] != 0:
price_data = self.price_providers.get_price(
set_params(token_address, block_number, tx_hash)
)
if price_data:
price, source = price_data
prices[token_address] = (price, source)
for token_address in token_imbalances.keys():
price_data = self.price_providers.get_price(
set_params(token_address, block_number, tx_hash)
)
if 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}")

Expand Down
Loading